pypsa-eur/scripts/solve_operations_network.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.6 KiB
Python
Raw Permalink Normal View History

# -*- coding: utf-8 -*-
2024-02-19 15:21:48 +00:00
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors
#
2021-09-14 14:37:41 +00:00
# SPDX-License-Identifier: MIT
"""
2019-08-11 20:34:18 +00:00
Solves linear optimal dispatch in hourly resolution using the capacities of
previous capacity expansion in rule :mod:`solve_network`.
"""
2023-10-08 09:20:36 +00:00
Add logging to logfiles to all snakemake workflow scripts. (#102) * Add logging to logfiles to all snakemake workflow scripts. * Fix missing quotation marks in Snakefile. * Apply suggestions from code review Co-Authored-By: Fabian Neumann <fabian.neumann@outlook.de> * Apply suggestions from code review Co-Authored-By: Fabian Neumann <fabian.neumann@outlook.de> * doc: fix _ec_ filenames in docs * Allow logging message format to be specified in config.yaml. * Add logging for Snakemake rule 'retrieve_databundle '. * Add limited logging to STDERR only for retrieve_*.py scripts. * Import progressbar module only on demand. * Fix logging to file and enable concurrent printing to STDERR for most scripts. * Add new 'logging_format' option to Travis CI test config.yaml. * Add missing parenthesis (bug fix) and cross-os compatible paths. * Fix typos in messages. * Use correct log files for logging (bug fix). * doc: fix line references * config: logging_format in all configs * doc: add doc for logging_format * environment: update to powerplantmatching 0.4.3 * doc: update line references for tutorial.rst * Change logging configuration scheme for config.yaml. * Add helper function for doing basic logging configuration. * Add logpath for prepare_links_p_nom rule. * Outsource basic logging configuration for all scripts to _helper submodule. * Update documentation for changed config.yaml structure. Instead of 'logging_level' and 'logging_format', now 'logging' with subcategories is used. * _helpers: Change configure_logging signature.
2019-11-28 07:22:52 +00:00
import logging
2018-03-13 09:47:47 +00:00
import numpy as np
import pypsa
2023-08-15 13:02:41 +00:00
from _helpers import (
configure_logging,
set_scenario_config,
update_config_from_wildcards,
2023-08-15 13:02:41 +00:00
)
from solve_network import prepare_network, solve_network
logger = logging.getLogger(__name__)
if __name__ == "__main__":
if "snakemake" not in globals():
Introduce mocksnakemake which acutally parses Snakefile (#107) * rewrite mocksnakemake for parsing real Snakefile * continue add function to scripts * going through all scripts, setting new mocksnakemake * fix plotting scripts * fix build_country_flh * fix build_country_flh II * adjust config files * fix make_summary for tutorial network * create dir also for output * incorporate suggestions * consistent import of mocksnakemake * consistent import of mocksnakemake II * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/plot_network.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/plot_network.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * Update scripts/retrieve_databundle.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * use pathlib for mocksnakemake * rename mocksnakemake into mock_snakemake * revert change in data * Update scripts/_helpers.py Co-Authored-By: euronion <42553970+euronion@users.noreply.github.com> * remove setting logfile in mock_snakemake, use Path in configure_logging * fix fallback path and base_dir fix return type of make_io_accessable * reformulate mock_snakemake * incorporate suggestion, fix typos * mock_snakemake: apply absolute paths again, add assertion error *.py: make hard coded io path accessable for mock_snakemake * retrieve_natura_raster: use snakemake.output for fn_out * include suggestion * Apply suggestions from code review Co-Authored-By: Jonas Hörsch <jonas.hoersch@posteo.de> * linting, add return ad end of file * Update scripts/plot_p_nom_max.py Co-Authored-By: Jonas Hörsch <jonas.hoersch@posteo.de> * Update scripts/plot_p_nom_max.py fixes #112 Co-Authored-By: Jonas Hörsch <jonas.hoersch@posteo.de> * plot_p_nom_max: small correction * config.tutorial.yaml fix snapshots end * use techs instead of technology * revert try out from previous commit, complete replacing * change clusters -> clusts in plot_p_nom_max due to wildcard constraints of clusters * change clusters -> clusts in plot_p_nom_max due to wildcard constraints of clusters II
2019-12-09 20:29:15 +00:00
from _helpers import mock_snakemake
2022-06-30 06:39:03 +00:00
snakemake = mock_snakemake(
"solve_operations_network",
configfiles="test/config.electricity.yaml",
opts="",
clusters="5",
ll="v1.5",
sector_opts="",
planning_horizons="",
)
configure_logging(snakemake)
2023-08-15 13:02:41 +00:00
set_scenario_config(snakemake)
update_config_from_wildcards(snakemake.config, snakemake.wildcards)
solve_opts = snakemake.params.options
np.random.seed(solve_opts.get("seed", 123))
n = pypsa.Network(snakemake.input.network)
n.optimize.fix_optimal_capacities()
n = prepare_network(n, solve_opts, config=snakemake.config)
Squashed commit of the following: commit a2b82195b872bae11a9e247c53756ca3ae512362 Author: Fabian Neumann <fabian.neumann@outlook.de> Date: Fri Aug 30 16:13:36 2024 +0200 minor adjustments commit 4f9eb04fec4534abbef10fedd4d9b5c34f064670 Merge: 7b525a51 bf2d82a3 Author: Fabian Neumann <fabian.neumann@outlook.de> Date: Fri Aug 30 16:08:58 2024 +0200 Merge branch 'master' into master commit 7b525a515a36a4ebb248280546583ac843f6b277 Merge: d9033374 a357ba11 Author: danielelerede-oet <daniele.lerede@openenergytransition.org> Date: Mon Aug 26 13:21:06 2024 +0200 Merge branch 'master' into master commit d9033374e4bf0bb70df0828743b9aab69c0cbb27 Author: danielelerede-oet <daniele.lerede@openenergytransition.org> Date: Mon Aug 26 10:34:27 2024 +0200 Update scripts/solve_network.py Co-authored-by: Fabian Neumann <fabian.neumann@outlook.de> commit 98e6c5b0f152ca7e064b3c80be26f50040628388 Author: danielelerede-oet <daniele.lerede@openenergytransition.org> Date: Mon Aug 26 10:34:21 2024 +0200 Update scripts/solve_network.py Co-authored-by: Fabian Neumann <fabian.neumann@outlook.de> commit be19a2ba2401a2815c09e74d2add24461b3fe2aa Author: danielelerede-oet <daniele.lerede@openenergytransition.org> Date: Mon Aug 26 10:34:15 2024 +0200 Update scripts/solve_operations_network.py Co-authored-by: Fabian Neumann <fabian.neumann@outlook.de> commit 8093eaa399cfea62d1ef93ec4ed5ed46bf5dcc6d Author: danielelerede-oet <daniele.lerede@openenergytransition.org> Date: Mon Aug 26 10:34:08 2024 +0200 Update scripts/solve_network.py Co-authored-by: Fabian Neumann <fabian.neumann@outlook.de> commit 746d1761accbe44d3a851430b94844fe3ab43d72 Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed Aug 21 15:29:12 2024 +0000 [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci commit f46fdee7f7ceeb9040ee73123fa4a3bd1aa14a56 Author: Daniele Lerede <daniele.lerede@openenergytransition.org> Date: Wed Aug 21 17:11:32 2024 +0200 fix solve_operations_network
2024-08-30 14:15:34 +00:00
n = solve_network(
n,
config=snakemake.config,
params=snakemake.params,
solving=snakemake.params.solving,
log_fn=snakemake.log.solver,
)
n.meta = dict(snakemake.config, **dict(wildcards=dict(snakemake.wildcards)))
n.export_to_netcdf(snakemake.output[0])