-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plot energy & carbon stacks #113
Conversation
# Filter out fuel types which are not in this grid | ||
renewable_fuels = [f for f in possible_renewable if f in energy_by_type] | ||
clean_fuels = [f for f in possible_clean if f in energy_by_type] | ||
carbon_fuels = [f for f in possible_carbon if f in energy_by_type] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe fuels = carbon_fuels + ['other' if 'other' in energy_ by_type' else []] + clean_fuels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why single out 'other' here? The all_possible
definition should get these in the right order, and line 31 should maintain order while dropping any that aren't present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously, I was thinking removing 31-33 and fuels = carbon_fuels + clean_fuels
, then I realize 'other' is not covered in this way. Nevermind, it's not critical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, unfortunately we don't have a good carbon intensity value for 'other' generators at the moment, so it's a nebulous category outside of 'clean' and 'carbon'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest flagging analysis of 'other' generators carbon emissions as a Zenhub issue for future work. Right now it appears that all 'other' generators have 0 carbon emissions, which I think is misleading.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
This type of bar plot contains key information that we would like to tell from our scenario results and they are beautifully generated. From this perspective, I would like bring @rouille and @kasparm into this conversation, given this is a common question for most of the plots currently in the spot check integration script. |
@BainanXia I was having similar thoughts. I wrote the single-scenario version first, and when I started writing the two-scenario version I started thinking that it wouldn't be too much work to make this one take 1 to n scenarios instead. Instead of having our dictionary of scenario-level results keyed by |
# Retrieve data and calculate summary statistics | ||
grid = scenario.state.get_grid() | ||
plant = grid.plant | ||
annual_plant_carbon = generate_carbon_stats(scenario).sum() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scenario.state.get_grid()
and scenario.state.get_pg()
are also called in generate_carbon_stats(scenario)
as well and assigned to variables with same name. I could see two options to avoid duplicated calls, a) pass those variables into generate_carbon_stats
, but this will affect the usage when the user calls generate_carbon_stats
independently, b) check whether grid
and pg
are already assigned in the scope, if not load them as usual, otherwise just use it or make a copy. Maybe there are better ways to handle this situation and I'm more than happy to learn.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this too. Perhaps this is a good use case for the ScenarioInfo object, and some more flexibility in the input arguments to some of our analysis functions. For each function that takes a Scenario object and will eventually load PG (big) and the Grid (a little slow to instantiate), perhaps we can make the input more flexible to also accept a ScenarioInfo object, and if it gets one, grabbing the PG/Grid from there instead of creating a new copy. Then the carbon bar plotting function could generate a ScenarioInfo object for each Scenario, and pass this object to e.g. generate_carbon_stats()
. We would have to be careful about memory management though, since after this line we never need a full-dimension PG again, but it will remain in memory unless we del
the ScenarioInfo
object.
I think that if it is not too much work, it is better to generalize to n scenarios. And if you have the analysis/plot for n, then you have it for 2. I don’t see any drawbacks. |
Looks great. |
# Drop fuels with zero energy (e.g. all offshore_wind scaled to 0 MW) | ||
energy_by_type[id] = raw_energy_by_type[raw_energy_by_type != 0] | ||
carbon_by_type[id] = raw_carbon_by_type[raw_energy_by_type != 0] | ||
# carbon multiplier is inverse of carbon intensity, to scale bar heights |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have very different scenarios being compared, and you base the carbon multiplier on the first scenario only, isn't it possible that the scaling could be suboptimal for the other scenarios? Wondering if carbon multiplier should be based on the average of the scenarios being considered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed that the bar plots look different depending on which scenario is selected first, due to the way carbon multiplier uses the first scenario listed only. When ratios of energy to emissions are very different in other scenarios being compared, this can create a situation where the first scenario selected has a large effect on the image that is generated:
I'd like to request a demo notebook (in the demos section) to showcase how to use this function. These are very nice looking plots and they will likely be a good type of bar plot (translated to Nivio) to show on the 'multiple scenario comparison' part of the website's dashboard. The functionality to show as may scenarios as you'd like side by side is very useful. |
@victoriahunt I can do that. Do we have a way of tracking which files/functions have associated demo notebooks? Down the road, if someone changes something in this script, but doesn't know to change the demo notebook, the two will drift apart. Maybe a comment or docstring at the top of files which have associated demos? |
We don't currently track this but you're right that we should. When there was the refactor /reorganization of PostREISE a while back where scripts got reorganized into different folders I realized a bit later that my demo notebooks didn't work because they imported functions using the old folder system, so I had to edit accordingly. Comment at top of file about associated demos seems smart. |
e8127c3
to
458f598
Compare
A demo notebook has been added, and the module points to it in a top-level comment. |
@@ -1,3 +1,6 @@ | |||
# This plotting module has a corresponding demo notebook in | |||
# PostREISE/postreise/plot/demo: plot_carbon_energy_carbon_stack.ipynb | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use an hyperlink here:
`demo notebook https://github.com/intvenlab/PostREISE/tree/develo/postreise/plot/demo/plot_carbon_energy_carbon_stack.ipynb`__
It anticipates the fact that the branch will be merge into develop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, directing to the folder path seems cleaner than directing to github. Plus, that would be a loooooong line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the comments are addressed. Thanks for being responsive!
Purpose
Integrate energy & carbon bar stacks into codebase.
What is the code doing
plot_single_scenario()
plots a single scenario.plot_two_scenarios()
plots two scenarios.Only fuels which are present in the grid (i.e. not 'geothermal' in Eastern) and generate a non-zero amount of energy (i.e. not 'wind_offshore' when we scale all generators to zero MW) are plotted. There are a few annotations with high-level statistics.
Time to review
Half an hour to an hour? I don't know how picky we need to be for plotting code. There are a few places where we could optimize the code for optimum DRY, but I think we can integrate these now and play around with refactoring later, if there are no glaring issues.