Add carbon emissions to statistics module#1149
Add carbon emissions to statistics module#1149gincrement wants to merge 19 commits intoPyPSA:masterfrom
Conversation
lkstrp
left a comment
There was a problem hiding this comment.
Thanks for another PR @gincrement !
Could you have a look on all failing checks?
There was a problem hiding this comment.
PR Overview
This PR adds a new carbon emissions calculation to the statistics module.
- Added a new function carbon_emissions in the statistics expressions module.
- Updated the overall statistics aggregation list to include carbon_emissions.
- Extended the test suite and example notebook to demonstrate the new functionality.
Reviewed Changes
| File | Description |
|---|---|
| pypsa/statistics/expressions.py | Adds the carbon_emissions function and refines port_efficiency. |
| test/test_statistics.py | Introduces a test for the new carbon emissions calculation. |
| examples/notebooks/statistics.ipynb | Updates example notebook to include carbon emissions example output. |
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
pypsa/statistics/expressions.py:1098
- The use of 'n.df(c)' appears non-standard compared to other parts of the module where static data is accessed. Verify that 'n.df(c)' is the intended accessor for carrier information, or consider using a consistent method such as 'n.static(c)'.
* n.df(c).carrier.map(n.carriers.co2_emissions)
FabianHofmann
left a comment
There was a problem hiding this comment.
nice idea to add this!
fneum
left a comment
There was a problem hiding this comment.
Looks mostly good apart from the comments raised already and one further question from me:
Is it really necessary to use the absolute value function for get_operation() and efficiency? Imagine the case where you're modelling an integrated BECCS power plant (without modelling the CO2 carrier specifically). Would the function then show net-negative emissions? Perhaps add a test for that case.
|
after notifying @gincrement that changing the |
fneum
left a comment
There was a problem hiding this comment.
I think it should match the corresponding global constraint:
e.g. looking at the net supply of the store/storage unit between initial and final state of charge.
Just returning the carbon emissions of the generators could be confusuing and would not be aligned with the global constraint. That should be avoided.
Even though the statistics function prints a warning, I think the stores and storage units implementation needs to be included before merging.
removed abs from efficiency and get_operation and increased coverate to all technologies
added co2 carrier, bus and load to test negative and positive flows
fneum
left a comment
There was a problem hiding this comment.
Another unit test would be good where emissions come from the net difference in state of charge of a Store / StorageUnit. Then, I'm fine for this to be merged.
See
PyPSA/pypsa/optimization/global_constraints.py
Lines 272 to 480 in 5031132
test/test_statistics.py
Outdated
| # add some co2 details | ||
| n.add("Carrier", "co2", co2_emissions=1) | ||
| n.add("Bus", "co2bus", carrier="co2", color="darkblue") | ||
| n.add("Load", "co2", bus="co2bus", carrier="co2") | ||
| n.dynamic('Load').p_set["co2"] = 0.0 | ||
| n.loads_t.p_set.at[n.loads_t.p_set.index[-1], 'co2'] = 10 | ||
| n.add("Generator", "co2purchase", bus="co2bus", carrier="co2", p_nom_extendable=True, capital_cost=10000, marginal_price=1, p_nom_max=2, efficiency=-1) | ||
| n.add("StorageUnit", "CO2storage", bus="co2bus", carrier="co2", p_nom_extendable=True, capital_cost=10000, standing_loss=0.1) |
There was a problem hiding this comment.
This should not be necessary. The ac_dc_network alone should produce a valid n.statistics.carbon_emissions() output, since one of its carriers ('gas') has specific emissions.
Closes #520
Changes proposed in this Pull Request
Checklist
doc.doc/release_notes.rstof the upcoming release is included.