From 7334913e11f9e6c446153d7a72e594f6fb464e44 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 6 Mar 2023 15:07:09 +0100 Subject: [PATCH] add input file handling of pypsa-eur-sec rules using cutout --- Snakefile | 15 ++++++++++----- config.default.yaml | 2 +- scripts/build_clustered_population_layouts.py | 2 +- scripts/build_heat_demand.py | 3 +-- scripts/build_population_layouts.py | 2 +- scripts/build_renewable_profiles.py | 2 +- scripts/build_solar_thermal_profiles.py | 3 +-- scripts/build_temperature_profiles.py | 3 +-- 8 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Snakefile b/Snakefile index 80bd9206..5c1b240f 100644 --- a/Snakefile +++ b/Snakefile @@ -661,7 +661,8 @@ if config.get("retrieve_cost_data", True): rule build_population_layouts: input: nuts3_shapes='resources/' + RDIR + 'nuts3_shapes.geojson', - urban_percent="data/urban_percent.csv" + urban_percent="data/urban_percent.csv", + cutout="cutouts/" + CDIR + config["atlite"]["default_cutout"] + ".nc", output: pop_layout_total="resources/" + RDIR + "pop_layout_total.nc", pop_layout_urban="resources/" + RDIR + "pop_layout_urban.nc", @@ -677,7 +678,8 @@ rule build_clustered_population_layouts: pop_layout_total="resources/" + RDIR + "pop_layout_total.nc", pop_layout_urban="resources/" + RDIR + "pop_layout_urban.nc", pop_layout_rural="resources/" + RDIR + "pop_layout_rural.nc", - regions_onshore='resources/' + RDIR + 'regions_onshore_elec_s{simpl}_{clusters}.geojson' + regions_onshore='resources/' + RDIR + 'regions_onshore_elec_s{simpl}_{clusters}.geojson', + cutout="cutouts/" + CDIR + config["atlite"]["default_cutout"] + ".nc", output: clustered_pop_layout="resources/" + RDIR + "pop_layout_elec_s{simpl}_{clusters}.csv" resources: mem_mb=10000 @@ -755,7 +757,8 @@ else: rule build_heat_demands: input: pop_layout="resources/" + RDIR + "pop_layout_{scope}.nc", - regions_onshore="resources/" + RDIR + "regions_onshore_elec_s{simpl}_{clusters}.geojson" + regions_onshore="resources/" + RDIR + "regions_onshore_elec_s{simpl}_{clusters}.geojson", + cutout="cutouts/" + CDIR + config["atlite"]["default_cutout"] + ".nc", output: heat_demand="resources/" + RDIR + "heat_demand_{scope}_elec_s{simpl}_{clusters}.nc" resources: mem_mb=20000 @@ -767,7 +770,8 @@ rule build_heat_demands: rule build_temperature_profiles: input: pop_layout="resources/" + RDIR + "pop_layout_{scope}.nc", - regions_onshore="resources/" + RDIR + "regions_onshore_elec_s{simpl}_{clusters}.geojson" + regions_onshore="resources/" + RDIR + "regions_onshore_elec_s{simpl}_{clusters}.geojson", + cutout="cutouts/" + CDIR + config["atlite"]["default_cutout"] + ".nc", output: temp_soil="resources/" + RDIR + "temp_soil_{scope}_elec_s{simpl}_{clusters}.nc", temp_air="resources/" + RDIR + "temp_air_{scope}_elec_s{simpl}_{clusters}.nc", @@ -800,7 +804,8 @@ rule build_cop_profiles: rule build_solar_thermal_profiles: input: pop_layout="resources/" + RDIR + "pop_layout_{scope}.nc", - regions_onshore="resources/" + RDIR + "regions_onshore_elec_s{simpl}_{clusters}.geojson" + regions_onshore="resources/" + RDIR + "regions_onshore_elec_s{simpl}_{clusters}.geojson", + cutout="cutouts/" + CDIR + config["atlite"]["default_cutout"] + ".nc", output: solar_thermal="resources/" + RDIR + "solar_thermal_{scope}_elec_s{simpl}_{clusters}.nc", resources: mem_mb=20000 diff --git a/config.default.yaml b/config.default.yaml index ff0e9eef..0a72727c 100755 --- a/config.default.yaml +++ b/config.default.yaml @@ -138,7 +138,7 @@ electricity: atlite: - cutout: ../pypsa-eur/cutouts/europe-2013-era5.nc + default_cutout: europe-2013-era5 nprocesses: 4 show_progress: false # false saves time cutouts: diff --git a/scripts/build_clustered_population_layouts.py b/scripts/build_clustered_population_layouts.py index d3ab7cfa..515a1e9e 100644 --- a/scripts/build_clustered_population_layouts.py +++ b/scripts/build_clustered_population_layouts.py @@ -18,7 +18,7 @@ if __name__ == "__main__": clusters=48, ) - cutout = atlite.Cutout(snakemake.config["atlite"]["cutout"]) + cutout = atlite.Cutout(snakemake.input.cutout) clustered_regions = ( gpd.read_file(snakemake.input.regions_onshore) diff --git a/scripts/build_heat_demand.py b/scripts/build_heat_demand.py index 9f0ee609..2dfa0a18 100644 --- a/scripts/build_heat_demand.py +++ b/scripts/build_heat_demand.py @@ -25,8 +25,7 @@ if __name__ == "__main__": client = Client(cluster, asynchronous=True) time = pd.date_range(freq="h", **snakemake.config["snapshots"]) - cutout_config = snakemake.config["atlite"]["cutout"] - cutout = atlite.Cutout(cutout_config).sel(time=time) + cutout = atlite.Cutout(snakemake.input.cutout).sel(time=time) clustered_regions = ( gpd.read_file(snakemake.input.regions_onshore) diff --git a/scripts/build_population_layouts.py b/scripts/build_population_layouts.py index 9b508ac5..fb88b796 100644 --- a/scripts/build_population_layouts.py +++ b/scripts/build_population_layouts.py @@ -23,7 +23,7 @@ if __name__ == "__main__": logging.basicConfig(level=snakemake.config["logging"]["level"]) - cutout = atlite.Cutout(snakemake.config["atlite"]["cutout"]) + cutout = atlite.Cutout(snakemake.input.cutout) grid_cells = cutout.grid.geometry diff --git a/scripts/build_renewable_profiles.py b/scripts/build_renewable_profiles.py index f74aa2aa..29975197 100644 --- a/scripts/build_renewable_profiles.py +++ b/scripts/build_renewable_profiles.py @@ -220,7 +220,7 @@ if __name__ == "__main__": cluster = LocalCluster(n_workers=nprocesses, threads_per_worker=1) client = Client(cluster, asynchronous=True) - cutout = atlite.Cutout(snakemake.input["cutout"]) + cutout = atlite.Cutout(snakemake.input.cutout) regions = gpd.read_file(snakemake.input.regions) assert not regions.empty, ( f"List of regions in {snakemake.input.regions} is empty, please " diff --git a/scripts/build_solar_thermal_profiles.py b/scripts/build_solar_thermal_profiles.py index a819c94b..cf77ad89 100644 --- a/scripts/build_solar_thermal_profiles.py +++ b/scripts/build_solar_thermal_profiles.py @@ -27,8 +27,7 @@ if __name__ == "__main__": config = snakemake.config["solar_thermal"] time = pd.date_range(freq="h", **snakemake.config["snapshots"]) - cutout_config = snakemake.config["atlite"]["cutout"] - cutout = atlite.Cutout(cutout_config).sel(time=time) + cutout = atlite.Cutout(snakemake.input.cutout).sel(time=time) clustered_regions = ( gpd.read_file(snakemake.input.regions_onshore) diff --git a/scripts/build_temperature_profiles.py b/scripts/build_temperature_profiles.py index c709d692..28a8c8f0 100644 --- a/scripts/build_temperature_profiles.py +++ b/scripts/build_temperature_profiles.py @@ -25,8 +25,7 @@ if __name__ == "__main__": client = Client(cluster, asynchronous=True) time = pd.date_range(freq="h", **snakemake.config["snapshots"]) - cutout_config = snakemake.config["atlite"]["cutout"] - cutout = atlite.Cutout(cutout_config).sel(time=time) + cutout = atlite.Cutout(snakemake.input.cutout).sel(time=time) clustered_regions = ( gpd.read_file(snakemake.input.regions_onshore)