Cleaning up modify_prenetwork#176
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
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_horizonas an explicit argument instead of re-parsing the Snakemake wildcard. - Updated some call sites to pass
planning_horizonthrough (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_bannow requiresplanning_horizon, but the main block still calls it without the new argument. This will raise aTypeErrorwhen running the rule; passplanning_horizonhere (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_fuelsnow takesplanning_horizon, but the call site still uses the old signature. This will crash at runtime; passplanning_horizoninto 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.
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>
|
@copilot apply changes based on the low confidence comments in this thread |
Agent-Logs-Url: https://github.com/PyPSA/pypsa-de/sessions/6935a000-d770-4f18-a69d-43a3884fbf8d Co-authored-by: lindnemi <56298440+lindnemi@users.noreply.github.com>
Fixed in commit 55c63a4 — both |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Hello @lindnemi, I have a small refactoring request for A possible solution is putting all buisness logic in # rules/pypsa-at/solve.smk ← AT-governed, edit freely
use rule upstream_rule as upstream_rule_at with:
input:
**rules.upstream_rule.input,
at_specific_data=resources("at_specific_data.csv"), # AT-specific stuff on top
script:
scirpts("pypsa-at/modifications.py") # import and runs the DE orcehstrator
ruleorder: upstream_rule_at > upstream_ruleBesides the downstream model extensibility, there are other reasons why this might be a good idea:
def new_boiler_ban(n): # uses snakemake from global scope
year = int(snakemake.wildcards.planning_horizons)
for ct in snakemake.params.fossil_boiler_ban:
# ...You may want to give it a thought. It would help us over at PyPSA-AT, but its not super critical right now. I just thought it might also be valuable input for PyPSA-Eur where more soft-forks exist and extendability is more of an issue. PS: the cherry on top would be a module without dash |
Changes proposed in this Pull Request
Calling
int(snakemake.wildcards.planning_horizonsmultiple times in the rulemodify_prenetwork.Using the convention of
planning_horizonand 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:
Changelog.md. not applicableIf applicable:
scripts/lib/validation. not applicabledoc/*.rstfiles. not applicable