Skip to content

renew statistics function for 'Final Energy [by Sector]|Transportation'#17

Merged
maxnutz merged 3 commits intomainfrom
15-new-variable-statistics-final-energy-by-sectortransportation
Mar 25, 2026
Merged

renew statistics function for 'Final Energy [by Sector]|Transportation'#17
maxnutz merged 3 commits intomainfrom
15-new-variable-statistics-final-energy-by-sectortransportation

Conversation

@maxnutz
Copy link
Copy Markdown
Owner

@maxnutz maxnutz commented Mar 25, 2026

Vehicle to Grid

  • Counterpart to BEV charger
  • does not need to be included, as evaluation is restricted to Load-Components.
flowchart LR;
    BUS_AT12_EV_battery(((AT12 EV battery)))
    BUS_AT12_EV_battery((AT12 EV battery))
    AT12_land_transport_EV(LOAD AT12 land transport EV) === BUS_AT12_EV_battery
    BUS_AT12_low_voltage-- AT12 BEV charger-2050 -->BUS_AT12_EV_battery
    BUS_AT12_EV_battery-- AT12 V2G-2050 -->BUS_AT12_low_voltage
    BUS_AT12_low_voltage((AT12 low voltage))
Loading

closes #15

Summary by Sourcery

Implement the Final_Energy_by_Sector__Transportation statistics function to return transportation-related load energy balances instead of a dummy value.

New Features:

  • Add computation of transportation final energy for relevant load carriers including land transport EV, fuel cell, oil, aviation kerosene, shipping methanol, and shipping oil.

Enhancements:

  • Update documentation to clarify that only Load components are evaluated and Vehicle-to-Grid flows are excluded from the transportation final energy statistic.

@maxnutz maxnutz linked an issue Mar 25, 2026 that may be closed by this pull request
7 tasks
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Mar 25, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the transportation final energy statistics helper to compute and return the actual energy balance for all relevant transportation load carriers instead of a dummy aggregated value, expanding the carrier set and returning the raw grouped result.

Sequence diagram for updated transportation final energy statistics computation

sequenceDiagram
    participant Caller
    participant Final_Energy_by_Sector__Transportation
    participant Network_n
    participant Statistics

    Caller->>Final_Energy_by_Sector__Transportation: call with Network_n
    Final_Energy_by_Sector__Transportation->>Network_n: access statistics
    Network_n->>Statistics: energy_balance(carrier=[land transport EV, land transport fuel cell, land transport oil, kerosene for aviation, shipping methanol, shipping oil], components=Load, groupby=[carrier, unit, country], direction=withdrawal)
    Statistics-->>Network_n: grouped energy balance by carrier, unit, country
    Network_n-->>Final_Energy_by_Sector__Transportation: res
    Final_Energy_by_Sector__Transportation-->>Caller: return res
Loading

Flow diagram for updated Final_Energy_by_Sector__Transportation statistics function

flowchart LR
    A[Input Network n] --> B[Call Final_Energy_by_Sector__Transportation]
    B --> C[Select carriers:<br>- land transport EV<br>- land transport fuel cell<br>- land transport oil<br>- kerosene for aviation<br>- shipping methanol<br>- shipping oil]
    C --> D[Call n.statistics.energy_balance<br>components: Load<br>carrier: selected list<br>groupby: carrier, unit, country<br>direction: withdrawal]
    D --> E[Receive grouped energy balance result]
    E --> F[Return res to caller]
Loading

File-Level Changes

Change Details Files
Replace dummy transportation final energy computation with real energy_balance query for transportation load carriers.
  • Remove placeholder documentation describing a dummy 0.0 MWh result and add notes about including all transportation-relevant carriers and excluding vehicle-to-grid due to Load-only evaluation.
  • Change the statistics call to use n.statistics.energy_balance with an expanded list of transportation carriers, including land transport oil and shipping oil in addition to the existing EV, fuel cell, kerosene, and shipping methanol carriers.
  • Return the direct grouped result from energy_balance instead of further grouping and summing over country and unit.
pypsa_validation_processing/statistics_functions.py

Assessment against linked issues

Issue Objective Addressed Explanation
#15 Implement the actual statistics extraction logic for Final_Energy_by_Sector__Transportation in statistics_functions.py to compute transportation final energy from the network (instead of returning a dummy value).
#15 Document the behavior of Final_Energy_by_Sector__Transportation to clarify that it aggregates transportation-relevant carriers for Load components (excluding Vehicle-to-Grid).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The function docstring and in-line comment still describe a summed result over carriers and units, but the implementation now returns the raw grouped-by-carrier frame; either restore the aggregation or update the documentation to match the new behavior.
  • Changing the return structure from a country/unit aggregate to a more granular country/unit/carrier grouping is a breaking API change for callers of this statistics function; consider whether you want to preserve the previous aggregation or clearly separate this into a new function or parameterized behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The function docstring and in-line comment still describe a summed result over carriers and units, but the implementation now returns the raw grouped-by-carrier frame; either restore the aggregation or update the documentation to match the new behavior.
- Changing the return structure from a country/unit aggregate to a more granular country/unit/carrier grouping is a breaking API change for callers of this statistics function; consider whether you want to preserve the previous aggregation or clearly separate this into a new function or parameterized behavior.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@maxnutz maxnutz merged commit 67a3b3f into main Mar 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Variable Statistics: Final Energy [by Sector]|Transportation

1 participant