scenario-management: fix set_scenario_config function; apply config_provider to some direct inputs

This commit is contained in:
Fabian 2023-08-17 12:31:07 +02:00
parent 9d4ce430cc
commit 91eff472a7
5 changed files with 31 additions and 23 deletions

View File

@ -214,19 +214,19 @@ rule build_renewable_profiles:
corine=ancient("data/bundle/corine/g250_clc06_V18_5.tif"),
natura=lambda w: (
RESOURCES + "natura.tiff"
if config["renewable"][w.technology]["natura"]
if config_provider("renewable", w.technology, "natura")(w)
else []
),
gebco=ancient(
lambda w: (
"data/bundle/GEBCO_2014_2D.nc"
if config["renewable"][w.technology].get("max_depth")
if config_provider("renewable", w.technology)(w).get("max_depth")
else []
)
),
ship_density=lambda w: (
RESOURCES + "shipdensity_raster.tif"
if "ship_threshold" in config["renewable"][w.technology].keys()
if "ship_threshold" in config_provider("renewable", w.technology)(w).keys()
else []
),
country_shapes=RESOURCES + "country_shapes.geojson",
@ -238,7 +238,7 @@ rule build_renewable_profiles:
),
cutout=lambda w: "cutouts/"
+ CDIR
+ config["renewable"][w.technology]["cutout"]
+ config_provider("renewable", w.technology, "cutout")(w)
+ ".nc",
output:
profile=RESOURCES + "profile_{technology}.nc",

View File

@ -31,10 +31,12 @@ def mute_print():
def set_scenario_config(snakemake):
if "scenario_config" in snakemake.input:
with open(snakemake.input.scenario_config, "r") as f:
if snakemake.config["run"]["scenarios"]:
script_dir = Path(__file__).parent.resolve()
root_dir = script_dir.parent
with open(root_dir / snakemake.config["scenariofile"], "r") as f:
scenario_config = yaml.safe_load(f)
update_config(snakemake.config, scenario_config)
update_config(snakemake.config, scenario_config[snakemake.wildcards.run])
def configure_logging(snakemake, skip_handlers=False):

View File

@ -743,7 +743,7 @@ if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake("base_network")
snakemake = mock_snakemake("base_network", run="network2019")
configure_logging(snakemake)
set_scenario_config(snakemake)

View File

@ -68,8 +68,6 @@ def load_timeseries(fn, years, countries):
load : pd.DataFrame
Load time-series with UTC timestamps x ISO-2 countries
"""
logger.info(f"Retrieving load data from '{fn}'.")
return (
pd.read_csv(fn, index_col=0, parse_dates=[0])
.tz_localize(None)
@ -182,20 +180,26 @@ def manual_adjustment(load, fn_load):
Manual adjusted and interpolated load time-series with UTC
timestamps x ISO-2 countries
"""
if "MK" in load:
if "AL" not in load or load.AL.isnull().values.all():
load["AL"] = load["MK"] * (4.1 / 7.4)
if "RS" in load:
if "KV" not in load or load.KV.isnull().values.all():
load["KV"] = load["RS"] * (4.8 / 27.0)
if "ME" in load:
if "AL" not in load and "AL" in countries:
if "AL" not in load and "AL" in countries:
if "ME" in load:
load["AL"] = load.ME * (5.7 / 2.9)
if "MK" not in load and "MK" in countries:
load["MK"] = load.ME * (6.7 / 2.9)
if "BA" not in load and "BA" in countries:
elif "MK" in load:
load["AL"] = load["MK"] * (4.1 / 7.4)
if "MK" in countries:
if "MK" not in load or load.MK.isnull().sum() > len(load) / 2:
if "ME" in load:
load["MK"] = load.ME * (6.7 / 2.9)
if "BA" not in load and "BA" in countries:
if "ME" in load:
load["BA"] = load.HR * (11.0 / 16.2)
if "KV" not in load or load.KV.isnull().values.all():
if "RS" in load:
load["KV"] = load["RS"] * (4.8 / 27.0)
copy_timeslice(load, "GR", "2015-08-11 21:00", "2015-08-15 20:00", Delta(weeks=1))
copy_timeslice(load, "AT", "2018-12-31 22:00", "2019-01-01 22:00", Delta(days=2))
copy_timeslice(load, "CH", "2010-01-19 07:00", "2010-01-19 22:00", Delta(days=1))
@ -250,7 +254,7 @@ if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake("build_electricity_demand")
snakemake = mock_snakemake("build_electricity_demand", run="network2019")
configure_logging(snakemake)
set_scenario_config(snakemake)

View File

@ -200,7 +200,9 @@ if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake("build_renewable_profiles", technology="solar")
snakemake = mock_snakemake(
"build_renewable_profiles", technology="solar", run="network2019"
)
configure_logging(snakemake)
set_scenario_config(snakemake)