add statistics-function for variable Final Energy [by Sector]|Agriculture#18
Open
add statistics-function for variable Final Energy [by Sector]|Agriculture#18
Conversation
7 tasks
Contributor
Reviewer's GuideAdds a new statistics function to compute final energy consumption for the agriculture sector, wires it into the mapping configuration, and introduces a focused test suite mirroring the existing transportation-sector tests. Flow diagram for Final_Energy_by_Sector__Agriculture statistics functionflowchart TD
Start([Start Final_Energy_by_Sector__Agriculture])
InputN["Input n: pypsa.Network"]
DefineCarriers["Define carriers = [agriculture electricity, agriculture heat, agriculture machinery electric, agriculture machinery oil]"]
CallStats["Call n.statistics.energy_balance with\ncarrier=carriers\ngroupby=[carrier, unit, country]\ncomponents=Load\ndirection=withdrawal"]
GroupSum["Group result by [country, unit]\nand sum over all carriers"]
ReturnRes(["Return aggregated pd.Series res"])
Start --> InputN --> DefineCarriers --> CallStats --> GroupSum --> ReturnRes
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The docstring for
Final_Energy_by_Sector__Agriculturestill mentions "transportation sector" in the Returns description, which is misleading for this function and should be updated to refer to the agriculture sector. - In
Final_Energy_by_Sector__Agriculturethe notes mention thatagriculture machinery oilis also a carrier of Links and Buses, but the actual call usescomponents="Load"; consider either expanding the components argument or adjusting the note so it matches the implemented behavior. - The
test_numeric_valuesassertion can be simplified by directly usingpd.api.types.is_numeric_dtype(result.dtype)instead of combining it with explicit checks againstfloatandint, which are redundant for pandas dtypes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The docstring for `Final_Energy_by_Sector__Agriculture` still mentions "transportation sector" in the Returns description, which is misleading for this function and should be updated to refer to the agriculture sector.
- In `Final_Energy_by_Sector__Agriculture` the notes mention that `agriculture machinery oil` is also a carrier of Links and Buses, but the actual call uses `components="Load"`; consider either expanding the components argument or adjusting the note so it matches the implemented behavior.
- The `test_numeric_values` assertion can be simplified by directly using `pd.api.types.is_numeric_dtype(result.dtype)` instead of combining it with explicit checks against `float` and `int`, which are redundant for pandas dtypes.
## Individual Comments
### Comment 1
<location path="pypsa_validation_processing/statistics_functions.py" line_range="132-133" />
<code_context>
+
+ Notes
+ -----
+ Includes carriers ['agriculture electricity','agriculture heat','agriculture machinery electric',
+ 'agriculture machinery oil'] executed on Load-Components. agriculture machinery oil is also carrier
+ of Links and Buses, as Demand is assued fixed. _Timeseries of Agriculture demand are assumed
+ to be constant in PyPSA-EUR._
</code_context>
<issue_to_address>
**question:** Docstring mentions additional components for 'agriculture machinery oil' but implementation only uses Load.
Since `n.statistics.energy_balance` is called with `components="Load"`, this metric excludes Link/Bus usage of `agriculture machinery oil`. Please either adjust the wording about Links/Buses to avoid implying they are included here, or explicitly note that only load-side demand is captured by this statistic.
</issue_to_address>
### Comment 2
<location path="pypsa_validation_processing/statistics_functions.py" line_range="130-135" />
<code_context>
+ Notes
+ -----
+ Includes carriers ['agriculture electricity','agriculture heat','agriculture machinery electric',
+ 'agriculture machinery oil'] executed on Load-Components. agriculture machinery oil is also carrier
+ of Links and Buses, as Demand is assued fixed. _Timeseries of Agriculture demand are assumed
+ to be constant in PyPSA-EUR._
+ """
</code_context>
<issue_to_address>
**nitpick (typo):** Clean up spelling and capitalization in the docstring for clarity.
Specifically: change "assued" → "assumed", "Timeseries" → "time series", and capitalize "agriculture machinery oil" at the start of the sentence for consistency.
```suggestion
Notes
-----
Includes carriers ['agriculture electricity','agriculture heat','agriculture machinery electric',
'agriculture machinery oil'] executed on Load-Components. Agriculture machinery oil is also carrier
of Links and Buses, as Demand is assumed fixed. _Time series of Agriculture demand are assumed
to be constant in PyPSA-EUR._
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Agriculture includes carriers ['agriculture electricity','agriculture heat','agriculture machinery', 'agriculture machinery oil'] evaluated on Load-Components.
The carriers could be easily identified with
but as other functions are also based on hard-coded carrier names, it seems safer to also keep it static.
Summary by Sourcery
Add support for computing and exposing final energy consumption for the agriculture sector.
New Features:
Tests: