Skip to content

New Variable statistics function for Final Energy [by Carrier]|Coal#55

Draft
maxnutz wants to merge 2 commits intomainfrom
44-new-variable-statistics-final-energy-by-carriercoal
Draft

New Variable statistics function for Final Energy [by Carrier]|Coal#55
maxnutz wants to merge 2 commits intomainfrom
44-new-variable-statistics-final-energy-by-carriercoal

Conversation

@maxnutz
Copy link
Copy Markdown
Owner

@maxnutz maxnutz commented Apr 28, 2026

Goal

Introduces a new statistics function for IAMC-variaöble Final Energy [by Carrier]|Coal

Definition: Energy consumption of coal excluding transmission/distribution losses

To Dos:

  • Write your pypsa-statistics and add it as a separate function to statistics_functions.py (please note the naming and structural conventions!)
  • add a comprehensive docstring to your function
  • add the mapping variable_name <> function_name to mapping.default.yaml (and your personal mapping-file)
  • Add a testing routine for your Function to tests/ - stick to the testing-README
  • make sure, that the newest version of main is merged into your feature Branch

Validation

variable PyPSA-output IAMC Energy Balance Difference % 🟢 🟡 🟠 🔴
Final Energy [by Carrier]|Coal 73 824 78 330 -6.10% 🟠 in range, but energy balance processing is wrong
  • energy balance processing is getting value 14402.1384 locally
  • in energy balance tool, the respective value gets 78 330 - there seems to be an inconsistency between online tool and API data or/and an inconsistency in aggregation of IAMC Energy Balance

Summary by Sourcery

Add support for computing and mapping IAMC variable Final Energy [by Carrier]|Coal based on network statistics.

New Features:

  • Introduce a Final_Energy_by_Carrier__Coal statistics function that derives coal final energy consumption from network withdrawals.
  • Register the Final Energy [by Carrier]|Coal IAMC variable in the default mapping configuration.

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

sourcery-ai Bot commented Apr 28, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a new statistics function to compute IAMC variable 'Final Energy [by Carrier]|Coal' using PyPSA network withdrawals and wires it into the default IAMC-variable-to-function mapping.

Sequence diagram for computing Final Energy [by Carrier]|Coal

sequenceDiagram
    actor User
    participant IAMCProcessor
    participant MappingResolver
    participant statistics_functions
    participant pypsa_Network
    participant pandas

    User ->> IAMCProcessor: request Final_Energy_by_Carrier_Coal
    IAMCProcessor ->> MappingResolver: resolve variable_name Final Energy [by Carrier]|Coal
    MappingResolver -->> IAMCProcessor: Final_Energy_by_Carrier__Coal

    IAMCProcessor ->> statistics_functions: Final_Energy_by_Carrier__Coal(n, aggregate_per_year)
    statistics_functions ->> pypsa_Network: n.statistics.withdrawal(carrier=coal for industry, components=Load, aggregate_time=aggregate_per_year)
    pypsa_Network -->> statistics_functions: industry_withdrawal (pd.Series or pd.DataFrame)

    statistics_functions -->> IAMCProcessor: industry_withdrawal
    IAMCProcessor -->> pandas: optional postprocessing/aggregation
    pandas -->> IAMCProcessor: processed_series_or_dataframe

    IAMCProcessor -->> User: IAMC variable Final Energy [by Carrier]|Coal
Loading

File-Level Changes

Change Details Files
Introduce Final_Energy_by_Carrier__Coal statistics function for coal final energy by carrier.
  • Add Final_Energy_by_Carrier__Coal function with PyPSA Network dependency and aggregate_per_year switch.
  • Compute coal final energy using n.statistics.withdrawal filtered to 'coal for industry' Load component.
  • Return the computed withdrawal series/dataframe as the function result, mirroring the structure of existing statistics functions.
pypsa_validation_processing/statistics_functions.py
Register the new coal final energy variable-function mapping in the default config.
  • Map IAMC variable 'Final Energy [by Carrier]
Coal' to Final_Energy_by_Carrier__Coal in the default YAML mapping.

Assessment against linked issues

Issue Objective Addressed Explanation
#44 Implement a new statistics function Final_Energy_by_Carrier__Coal in statistics_functions.py for IAMC variable "Final Energy [by Carrier] Coal", following the project’s naming/structural conventions and including a comprehensive docstring.
#44 Add a mapping from IAMC variable name "Final Energy [by Carrier] Coal" to the new function name in mapping.default.yaml.
#44 Add a testing routine for the new Final_Energy_by_Carrier__Coal function under tests/ according to the testing README. The diff shows no additions or changes under tests/, and the PR checklist also leaves the testing task unchecked. There is no evidence that any test for the new function has been added.

Possibly linked issues

  • #New Variable Statistics: Final Energy [by Carrier]|Coal: They address the same new statistic: Final Energy [by Carrier]|Coal, adding its function and mapping.

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

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 Carrier]|Coal

1 participant