cats icon indicating copy to clipboard operation
cats copied to clipboard

Plot the carbon intensity time series

Open andreww opened this issue 1 year ago • 3 comments

Just a proof of concept for now, but plots the CI forecast time series alongside our planned run times.

Currently looks like this:

cats_plot

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.

andreww avatar Aug 23 '24 15:08 andreww

Codecov Report

:x: Patch coverage is 19.29825% with 46 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 81.80%. Comparing base (e792cff) to head (286d81b). :warning: Report is 40 commits behind head on main.

Files with missing lines Patch % Lines
cats/plotting.py 10.20% 44 Missing :warning:
cats/__init__.py 50.00% 2 Missing :warning:
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           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Aug 23 '24 15:08 codecov[bot]

@andreww one way to handle matplotlib is by putting in as an optional dependency, in a plots group as an example. Then if users want the plotting functionality they can use pip install 'climate-aware-task-scheduler[plots]'

abhidg avatar Feb 25 '25 10:02 abhidg

@andreww one way to handle matplotlib is by putting in as an optional dependency, in a plots group as an example. Then if users want the plotting functionality they can use pip install 'climate-aware-task-scheduler[plots]'

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 avatar Feb 25 '25 11:02 andreww

@andreww I don't see any interpolation here, running with cats -d 60 --loc OX1 --plot, I get this output:


The.____ ..... __ .... ________ . ______...
.. /  __)...../  \....(__    __).)  ____)....
..|  /......./    \......|  |...(  (___........
..| |limate./  ()  \ware.|  |ask.\___  \cheduler
..|  \__...|   __   |....|  |....____)  )....
...\    )..|  (..)  |....|  |...(      (..

WARNING:root:config file not found
WARNING:root:Unspecified carbon intensity forecast service, using carbonintensity.org.uk

Best job start time                       = 2025-06-08 10:40:44
Carbon intensity if job started now       = 76.08 gCO2eq/kWh
Carbon intensity at optimal time          = 63.87 gCO2eq/kWh

Zooming in on the plots figure, I see a 30 min window highlighted, rather than 60 minutes (starting now, red): Screenshot 2025-06-06 at 15 15 15

and the optimal time (green)

Screenshot 2025-06-06 at 15 16 14

abhidg avatar Jun 06 '25 14:06 abhidg

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.

andreww avatar Jun 06 '25 14:06 andreww

Thanks again for the spot @abhidg - fixed now.

andreww avatar Jun 13 '25 16:06 andreww

@andreww @abhidg would a second review be useful at this stage, so we can get this merged - unless this is waiting on other work / something else?

sadielbartholomew avatar Jun 23 '25 10:06 sadielbartholomew

@andreww @abhidg would a second review be useful at this stage, so we can get this merged - unless this is waiting on other work / something else?

@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

andreww avatar Jun 23 '25 11:06 andreww

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 avatar Jun 23 '25 14:06 sadielbartholomew

Thanks @sadielbartholomew - I'll merge this and open an issue for improvements re. units markup and styling the overlap. In terms of:

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...

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.

andreww avatar Jun 24 '25 08:06 andreww

Thanks @andreww for clarifying and merging. All good.

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.

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.

sadielbartholomew avatar Jun 24 '25 10:06 sadielbartholomew