diff --git a/Snakefile b/Snakefile index 91c48a00..55ae3d20 100644 --- a/Snakefile +++ b/Snakefile @@ -67,18 +67,29 @@ if config['enable'].get('retrieve_databundle', True): log: "logs/retrieve_databundle.log" script: 'scripts/retrieve_databundle.py' +if config["enable"].get('retrieve_opsd_load_data', True): + rule retrieve_load_data: + input: HTTP.remote("data.open-power-system-data.org/time_series/2019-06-05/time_series_60min_singleindex.csv", keep_local=True, static=True) + output: "data/load_raw.csv" + run: move(input[0], output[0]) -rule retrieve_load_data: - input: HTTP.remote("data.open-power-system-data.org/time_series/2019-06-05/time_series_60min_singleindex.csv", keep_local=True, static=True) - output: "data/load_raw.csv" - run: move(input[0], output[0]) + rule build_load_data: + input: "data/load_raw.csv" + output: "resources/load{weather_year}.csv" + log: "logs/build_load_data{weather_year}.log" + script: 'scripts/build_load_data.py' +if config["enable"].get('retrieve_artificial_load_data', False): + rule retrieve_artificial_load_data: + input: HTTP.remote("https://sandbox.zenodo.org/record/1089549/files/demand_hourly.csv", keep_local=True, static=True) + output: "data/load_artificial_raw.csv" + run: move(input[0], output[0]) -rule build_load_data: - input: "data/load_raw.csv" - output: "resources/load{weather_year}.csv" - log: "logs/build_load_data{weather_year}.log" - script: 'scripts/build_load_data.py' + rule build_artificial_load_data: + input: "data/load_artificial_raw.csv" + output: "resources/load{weather_year}.csv" + log: "logs/build_artificial_load_data{weather_year}.log" + script: "scripts/build_artificial_load_data.py" rule build_powerplants: diff --git a/config.default.yaml b/config.default.yaml index 45d664a2..b79f2559 100755 --- a/config.default.yaml +++ b/config.default.yaml @@ -29,6 +29,8 @@ enable: retrieve_cost_data: true build_cutout: false retrieve_cutout: true + retrieve_opsd_load_data: true + retrieve_artificial_load_data: false build_natura_raster: false retrieve_natura_raster: true custom_busmap: false diff --git a/config.tutorial.yaml b/config.tutorial.yaml index 2217f581..fcf53d46 100755 --- a/config.tutorial.yaml +++ b/config.tutorial.yaml @@ -30,6 +30,8 @@ enable: retrieve_cost_data: true build_cutout: false retrieve_cutout: true + retrieve_opsd_load_data: true + retrieve_artificial_load_data: false build_natura_raster: false retrieve_natura_raster: true custom_busmap: false diff --git a/scripts/build_artificial_load_data.py b/scripts/build_artificial_load_data.py new file mode 100755 index 00000000..c03bf9da --- /dev/null +++ b/scripts/build_artificial_load_data.py @@ -0,0 +1,47 @@ +# SPDX-FileCopyrightText: 2022 The PyPSA-Eur Authors +# +# SPDX-License-Identifier: MIT + +"""This rule downloads the load data""" + +import logging +logger = logging.getLogger(__name__) +from _helpers import configure_logging + +import pandas as pd + +if __name__ == "__main__": + + if 'snakemake' not in globals(): + from _helpers import mock_snakemake + snakemake = mock_snakemake('build_artificial_load_data', weather_year='') + + configure_logging(snakemake) + + weather_year = snakemake.wildcards.weather_year + if weather_year: + snapshots = dict( + start=weather_year, + end=str(int(weather_year)+1), + closed="left" + ) + else: + snapshots = snakemake.config['snapshots'] + snapshots = pd.date_range(freq='h', **snapshots) + + fixed_year = snakemake.config["load"].get("fixed_year", False) + years = slice(str(fixed_year), str(fixed_year)) if fixed_year else slice(snapshots[0], snapshots[-1]) + countries = snakemake.config['countries'] + + load = pd.read_csv( + snakemake.input[0], + index_col=0, + parse_dates=True + ).loc[snapshots, countries] + + assert not load.isna().any().any(), 'Load data contains nans.' + + if fixed_year: + load.index = load.index.map(lambda t: t.replace(year=snapshots.year[0])) + + load.to_csv(snakemake.output[0]) diff --git a/test/config.test1.yaml b/test/config.test1.yaml index 48b8216a..cfe7cf57 100755 --- a/test/config.test1.yaml +++ b/test/config.test1.yaml @@ -29,6 +29,8 @@ enable: retrieve_cost_data: true build_cutout: false retrieve_cutout: true + retrieve_opsd_load_data: true + retrieve_artificial_load_data: false build_natura_raster: false retrieve_natura_raster: true custom_busmap: false