Merge pull request #251 from PyPSA/cf-sector-opts

option to specify any config through sector opts with CF+<label>+<value>
This commit is contained in:
lisazeyen 2022-07-26 15:53:49 +02:00 committed by GitHub
commit 530e453eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 6 deletions

View File

@ -11,7 +11,7 @@ import yaml
import numpy as np import numpy as np
from add_existing_baseyear import add_build_year_to_new_assets from add_existing_baseyear import add_build_year_to_new_assets
from helper import override_component_attrs from helper import override_component_attrs, update_config_with_sector_opts
from solve_network import basename from solve_network import basename
@ -123,6 +123,8 @@ if __name__ == "__main__":
planning_horizons=2030, planning_horizons=2030,
) )
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)
print(snakemake.input.network_p) print(snakemake.input.network_p)
logging.basicConfig(level=snakemake.config['logging_level']) logging.basicConfig(level=snakemake.config['logging_level'])

View File

@ -13,7 +13,7 @@ import pypsa
import yaml import yaml
from prepare_sector_network import prepare_costs, define_spatial from prepare_sector_network import prepare_costs, define_spatial
from helper import override_component_attrs from helper import override_component_attrs, update_config_with_sector_opts
from types import SimpleNamespace from types import SimpleNamespace
spatial = SimpleNamespace() spatial = SimpleNamespace()
@ -463,6 +463,8 @@ if __name__ == "__main__":
logging.basicConfig(level=snakemake.config['logging_level']) logging.basicConfig(level=snakemake.config['logging_level'])
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)
options = snakemake.config["sector"] options = snakemake.config["sector"]
opts = snakemake.wildcards.sector_opts.split('-') opts = snakemake.wildcards.sector_opts.split('-')

View File

@ -1,7 +1,9 @@
import os import os
import yaml
import pytz import pytz
import pandas as pd import pandas as pd
from pathlib import Path from pathlib import Path
from snakemake.utils import update_config
from pypsa.descriptors import Dict from pypsa.descriptors import Dict
from pypsa.components import components, component_attrs from pypsa.components import components, component_attrs
@ -125,3 +127,17 @@ def generate_periodic_profiles(dt_index, nodes, weekly_profile, localize=None):
week_df = week_df.tz_localize(localize) week_df = week_df.tz_localize(localize)
return week_df return week_df
def parse(l):
if len(l) == 1:
return yaml.safe_load(l[0])
else:
return {l.pop(0): parse(l)}
def update_config_with_sector_opts(config, sector_opts):
for o in sector_opts.split("-"):
if o.startswith("CF:"):
l = o.split("+")[1:]
update_config(config, parse(l))

View File

@ -7,6 +7,7 @@ import matplotlib.pyplot as plt
plt.style.use('ggplot') plt.style.use('ggplot')
from prepare_sector_network import co2_emissions_year from prepare_sector_network import co2_emissions_year
from helper import update_config_with_sector_opts
#consolidate and rename #consolidate and rename
def rename_techs(label): def rename_techs(label):
@ -438,6 +439,8 @@ if __name__ == "__main__":
from helper import mock_snakemake from helper import mock_snakemake
snakemake = mock_snakemake('plot_summary') snakemake = mock_snakemake('plot_summary')
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)
n_header = 4 n_header = 4
plot_costs() plot_costs()

View File

@ -14,7 +14,7 @@ from scipy.stats import beta
from vresutils.costdata import annuity from vresutils.costdata import annuity
from build_energy_totals import build_eea_co2, build_eurostat_co2, build_co2_totals from build_energy_totals import build_eea_co2, build_eurostat_co2, build_co2_totals
from helper import override_component_attrs, generate_periodic_profiles from helper import override_component_attrs, generate_periodic_profiles, update_config_with_sector_opts
from networkx.algorithms.connectivity.edge_augmentation import k_edge_augmentation from networkx.algorithms.connectivity.edge_augmentation import k_edge_augmentation
from networkx.algorithms import complement from networkx.algorithms import complement
@ -2339,6 +2339,8 @@ if __name__ == "__main__":
logging.basicConfig(level=snakemake.config['logging_level']) logging.basicConfig(level=snakemake.config['logging_level'])
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)
options = snakemake.config["sector"] options = snakemake.config["sector"]
opts = snakemake.wildcards.sector_opts.split('-') opts = snakemake.wildcards.sector_opts.split('-')

View File

@ -11,7 +11,7 @@ from pypsa.linopf import network_lopf, ilopf
from vresutils.benchmark import memory_logger from vresutils.benchmark import memory_logger
from helper import override_component_attrs from helper import override_component_attrs, update_config_with_sector_opts
import logging import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -290,6 +290,8 @@ if __name__ == "__main__":
logging.basicConfig(filename=snakemake.log.python, logging.basicConfig(filename=snakemake.log.python,
level=snakemake.config['logging_level']) level=snakemake.config['logging_level'])
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)
tmpdir = snakemake.config['solving'].get('tmpdir') tmpdir = snakemake.config['solving'].get('tmpdir')
if tmpdir is not None: if tmpdir is not None:
from pathlib import Path from pathlib import Path