Skip to content

Cleaning up modify_prenetwork#176

Open
toniseibold wants to merge 5 commits intomainfrom
clean_up
Open

Cleaning up modify_prenetwork#176
toniseibold wants to merge 5 commits intomainfrom
clean_up

Conversation

@toniseibold
Copy link
Copy Markdown
Contributor

@toniseibold toniseibold commented May 8, 2026

Changes proposed in this Pull Request

Calling int(snakemake.wildcards.planning_horizons multiple times in the rule modify_prenetwork.
Using the convention of planning_horizon and passing it to functions as input instead of defining internal variables over and over again.

I needed to reuse the rule in a different workflow and wanted to hard code the planning horizon which is now much easier/cleaner to do.

Checklist

Required:

  • Changes are tested locally and behave as expected.
  • Code and workflow changes are documented. not applicable
  • A brief description of the changes has been added to Changelog.md. not applicable

If applicable:

  • Changes in configuration options are reflected in scripts/lib/validation. not applicable
  • For new data sources or versions, these instructions have been followed. not applicable
  • New rules are documented in the appropriate doc/*.rst files. not applicable

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to reduce repeated conversions of snakemake.wildcards.planning_horizons by introducing a single planning_horizon variable and passing it into helper functions in modify_prenetwork.py, aligning function signatures to a consistent pattern.

Changes:

  • Updated multiple helper functions to accept planning_horizon as an explicit argument instead of re-parsing the Snakemake wildcard.
  • Updated some call sites to pass planning_horizon through (e.g., first_technology_occurrence, add_wasserstoff_kernnetz, must_run, etc.).
  • Modified __main__ mock defaults (clusters/run) used for local execution.
Comments suppressed due to low confidence (2)

scripts/pypsa-de/modify_prenetwork.py:1436

  • new_boiler_ban now requires planning_horizon, but the main block still calls it without the new argument. This will raise a TypeError when running the rule; pass planning_horizon here (and keep the call sites consistent with the updated function signature).
    modify_mobility_demand(n, snakemake.input.modified_mobility_data)

    new_boiler_ban(n)

    fix_new_boiler_profiles(n)

scripts/pypsa-de/modify_prenetwork.py:1449

  • unravel_carbonaceous_fuels now takes planning_horizon, but the call site still uses the old signature. This will crash at runtime; pass planning_horizon into the function call.
    unravel_carbonaceous_fuels(n)

    unravel_gasbus(n, costs)


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/pypsa-de/modify_prenetwork.py Outdated
Comment on lines +1440 to +1444
@@ -1449,7 +1441,7 @@ def limit_cross_border_flows_ac(n, s_max_pu):

nuclear_generation_ban(n)

first_technology_occurrence(n)
first_technology_occurrence(n, planning_horizon)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed in commit 2551927coal_generation_ban and nuclear_generation_ban are now called with planning_horizon passed as the second argument.

Comment thread scripts/pypsa-de/modify_prenetwork.py Outdated
Comment thread scripts/pypsa-de/modify_prenetwork.py Outdated
Comment on lines 1413 to 1421
clusters=89,
opts="",
ll="vopt",
sector_opts="none",
planning_horizons="2025",
run="KN2045_Mix",
run="endogenous",
)

configure_logging(snakemake)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

i agree this should be reverted

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reverted in commit 2551927mock_snakemake defaults are back to clusters=27 / run="KN2045_Mix".

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…emake defaults

Agent-Logs-Url: https://github.com/PyPSA/pypsa-de/sessions/daa64e18-83c5-443f-8a7e-87596286617a

Co-authored-by: lindnemi <56298440+lindnemi@users.noreply.github.com>
@lindnemi
Copy link
Copy Markdown
Collaborator

lindnemi commented May 8, 2026

@copilot apply changes based on the low confidence comments in this thread

Copy link
Copy Markdown

Copilot AI commented May 8, 2026

@copilot apply changes based on the low confidence comments in this thread

Fixed in commit 55c63a4 — both new_boiler_ban and unravel_carbonaceous_fuels now receive planning_horizon as the second argument.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

@@ -1359,11 +1349,11 @@ def scale_capacity(n, scaling):
- scaling: A dictionary with scaling limits structured as
{year: {region: {carrier: limit}}}.
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.

4 participants