Plot the carbon intensity time series - #112
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #112 +/- ##
=======================================
Coverage 81.80% 81.80%
=======================================
Files 14 14
Lines 687 687
=======================================
Hits 562 562
Misses 125 125 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Makes use of our 'output' and the 'forecast' to plot a timeseries of the CI alongside highlights for the CI of running now or running at the optimal time.
We may want to think about this a bit (it's a big package) and the version number is a guess, but let's get the tests running for now.
|
@andreww one way to handle matplotlib is by putting in as an optional dependency, in a |
Add coloured text giving mean carbon intensity for best and now start times. Make date format on x axis easer to read.
I was seeing a bunch of fractional seconds in the shell output, which is a bit ugly. Explicity set formatting to match our test cases.
This should also print a useful error if it's not installed
We just need to print out a message if --plot is passed.
Thanks - I did this. It ended up being a little fiddly because of the type testing but it seems to be working. Ready to merge? |
|
@andreww I don't see any interpolation here, running with Zooming in on the plots figure, I see a 30 min window highlighted, rather than 60 minutes (starting now, red): and the optimal time (green)
|
|
Ugh, yes, I see. I need to add the start and end times and interpolated values on the start and end of the series of points plotted in green and red. We must have this calculated somewhere - it'll be a case of getting it into the plotting function. Good spot. |
For plotting we were only including points for the optimal and now start time from within the dataset of point estimates (i.e. every 30 mins) even if the start or end time was not on one of these times. This means the plots missed time at the start or end of the projected run time for the red and green segments. This is fixed by adding two more fields to the CarbonIntensityAverageEstimate, the start_value and end_value which correspond to the forcast values from the start and end times. These are interpolated when calculating the integral for the average estimate anyway, we just store the data now. We then pick up and plot these data points at the start and end of the red and green segments. This adds information into the serialised output in JSON format and in the expected CarbonIntensityAverageEstimates in the test cases. Hence the test cases are updated.
|
Thanks again for the spot @abhidg - fixed now. |
@sadielbartholomew - a review would be useful. If I've managed to fix the issue @abhidg spotted (I think I have) then I think this is ready to be merged |
|
OK sure @andreww I will get that done with review submitted this afternoon. Thanks for your work on this, it will be a really cool feature! |
sadielbartholomew
left a comment
There was a problem hiding this comment.
Fantastic stuff, thanks @andreww! Works very well, as tested across various durations across the valid range and with a selection of curves from choosing random postcodes for location.
A few general questions before we merge (plus some in-line suggestions):
-
Why is there always a small gap before the curve is coloured red to indicate the 'immediate' start time? I would expect it to be red from the very leftmost point on the curve, but I might be missing something...
-
Overlapping of the immediate start curve region and the optimal one: I like how, if these overlap there is a different colour to indicate clearly enough that the red and green both cover that region (even if the khaki itself is a bit ugly!), like so:
However, there are cases where the optimal time is the immediate time (probably not too uncommon a case, since of about 10 runs I tried to test across duration and location inputs I saw this once), the whole thing is that colour which might be a bit confusing, i.e. if a user just sees this they can perhaps realise what is happening, but could easily not:
Maybe a good way to solve that is to have the crossover region as a hatched pattern over the other region e.g. green dots on the red? Alternatively, just use a key and include the colour of the overlap region.
Happy to bump this one (and e.g. the units formatting as mentioned in-line) to a new PR that I can quickly put in though, if you prefer, in the interests of getting this great work merged!
Co-authored-by: Sadie L. Bartholomew <sadie.bartholomew@ncas.ac.uk>
|
Thanks @sadielbartholomew - I'll merge this and open an issue for improvements re. units markup and styling the overlap. In terms of:
I think this is because I always plot the whole of the carbon intensity forecast which starts at the start of the "current" 30 min time window but the "now" time is always now. This means there could be up to 29 minutes of stale forecast in the plot. It wouldn't be too hard to trim this off but I'm not sure if it's more confusing to show the full forecast or have our initial point be different to what a naive reading of data on the front page of carbonintensity.org.uk says. |
|
Thanks @andreww for clarifying and merging. All good.
Now you've explained I think it's fine to leave as-is, I agree that it might be confusing likewise to some to trim it and that's also extra work. |




Just a proof of concept for now, but plots the CI forecast time series alongside our planned run times.
Currently looks like this:
I think the optimal and now plots (green and red, respectively) are 30 mins out. Or background data is 30 mins out. Anyhow, this is a start.