Skip to content

Commit

Permalink
Merge pull request #356 from pypsa-meets-earth/scenario_setup
Browse files Browse the repository at this point in the history
Include scenario management
  • Loading branch information
davide-f authored Jul 18, 2024
2 parents 9c3ec89 + 18a5cd7 commit 7f88c62
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 32 deletions.
87 changes: 62 additions & 25 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@ PYPSAEARTH_FOLDER = "pypsa-earth"
# convert country list according to the desired region
config["countries"] = create_country_list(config["countries"])

run = config["run"]

SDIR = config["summary_dir"] + config["run"]
RDIR = config["results_dir"] + config["run"]

SDIR = config["summary_dir"] + run["name"]
RDIR = config["results_dir"] + run["name"]
CDIR = config["costs_dir"]

config.update({"git_commit": get_last_commit_message(".")})
config.update({"submodule_commit": get_last_commit_message(PYPSAEARTH_FOLDER)})

RDIR_PE = run["name_subworkflow"] + "/" if run.get("name_subworkflow") else ""
CDIR_PE = RDIR_PE if not run.get("shared_cutouts") else ""

CUTOUTS_PATH = (
"cutouts/cutout-2013-era5-tutorial.nc"
if config["tutorial"]
else "cutouts/cutout-2013-era5.nc"
"cutouts/"
+ CDIR_PE
+ ("cutout-2013-era5-tutorial.nc" if config["tutorial"] else "cutout-2013-era5.nc")
)


Expand Down Expand Up @@ -166,7 +171,9 @@ if not config["custom_data"]["gas_network"]:
custom_gas_network=config["custom_data"]["gas_network"],
input:
regions_onshore=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
"resources/"
+ RDIR_PE
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
),
output:
clustered_gas_network="resources/gas_networks/gas_network_elec_s{simpl}_{clusters}.csv",
Expand Down Expand Up @@ -201,7 +208,9 @@ rule prepare_sector_network:
district_heat_share="resources/demand/heat/district_heat_share_{demand}_s{simpl}_{clusters}_{planning_horizons}.csv",
biomass_transport_costs="data/temp_hard_coded/biomass_transport_costs.csv",
shapes_path=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
"resources/"
+ RDIR_PE
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
),
pipelines="data_custom/pipelines.csv"
if config["custom_data"]["gas_network"]
Expand Down Expand Up @@ -249,7 +258,9 @@ rule add_export:
network=RDIR
+ "/prenetworks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_{sopts}_{planning_horizons}_{discountrate}_{demand}.nc",
shapes_path=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
"resources/"
+ RDIR_PE
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
),
output:
RDIR
Expand Down Expand Up @@ -277,7 +288,9 @@ rule override_respot:
for planning_horizons in config["scenario"]["planning_horizons"]
},
overrides="data/override_component_attrs",
network=pypsaearth("networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc"),
network=pypsaearth(
"networks/" + RDIR_PE + "elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc"
),
energy_totals="data/energy_totals_{demand}_{planning_horizons}.csv",
output:
RDIR
Expand All @@ -288,7 +301,7 @@ rule override_respot:

rule prepare_transport_data:
input:
network=pypsaearth("networks/elec_s{simpl}_{clusters}.nc"),
network=pypsaearth("networks/" + RDIR_PE + "elec_s{simpl}_{clusters}.nc"),
energy_totals_name="data/energy_totals_{demand}_{planning_horizons}.csv",
traffic_data_KFZ="data/emobility/KFZ__count",
traffic_data_Pkw="data/emobility/Pkw__count",
Expand Down Expand Up @@ -332,7 +345,7 @@ rule build_cop_profiles:

rule prepare_heat_data:
input:
network=pypsaearth("networks/elec_s{simpl}_{clusters}.nc"),
network=pypsaearth("networks/" + RDIR_PE + "elec_s{simpl}_{clusters}.nc"),
energy_totals_name="data/energy_totals_{demand}_{planning_horizons}.csv",
clustered_pop_layout="resources/population_shares/pop_layout_elec_s{simpl}_{clusters}_{planning_horizons}.csv",
temp_air_total="resources/temperatures/temp_air_total_elec_s{simpl}_{clusters}_{planning_horizons}.nc",
Expand Down Expand Up @@ -392,7 +405,9 @@ rule build_solar_thermal_profiles:
pop_layout_urban="resources/population_shares/pop_layout_urban_{planning_horizons}.nc",
pop_layout_rural="resources/population_shares/pop_layout_rural_{planning_horizons}.nc",
regions_onshore=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
"resources/"
+ RDIR_PE
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
),
cutout=pypsaearth(CUTOUTS_PATH),
output:
Expand All @@ -411,7 +426,7 @@ rule build_population_layouts:
params:
planning_horizons=config["scenario"]["planning_horizons"][0],
input:
nuts3_shapes=pypsaearth("resources/shapes/gadm_shapes.geojson"),
nuts3_shapes=pypsaearth("resources/" + RDIR_PE + "shapes/gadm_shapes.geojson"),
urban_percent="data/urban_percent.csv",
cutout=pypsaearth(CUTOUTS_PATH),
output:
Expand Down Expand Up @@ -444,7 +459,9 @@ rule build_clustered_population_layouts:
pop_layout_rural="resources/population_shares/pop_layout_rural_{planning_horizons}.nc",
gdp_layout="resources/gdp_shares/gdp_layout_{planning_horizons}.nc",
regions_onshore=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
"resources/"
+ RDIR_PE
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
),
cutout=pypsaearth(CUTOUTS_PATH),
output:
Expand All @@ -466,7 +483,9 @@ rule build_heat_demand:
pop_layout_urban="resources/population_shares/pop_layout_urban_{planning_horizons}.nc",
pop_layout_rural="resources/population_shares/pop_layout_rural_{planning_horizons}.nc",
regions_onshore=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
"resources/"
+ RDIR_PE
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
),
cutout=pypsaearth(CUTOUTS_PATH),
output:
Expand All @@ -489,7 +508,9 @@ rule build_temperature_profiles:
pop_layout_urban="resources/population_shares/pop_layout_urban_{planning_horizons}.nc",
pop_layout_rural="resources/population_shares/pop_layout_rural_{planning_horizons}.nc",
regions_onshore=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
"resources/"
+ RDIR_PE
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
),
cutout=pypsaearth(CUTOUTS_PATH),
output:
Expand Down Expand Up @@ -687,6 +708,10 @@ rule run_test:
config_pypsaearth["electricity"]["extendable_carriers"]["Store"] = []
config_pypsaearth["electricity"]["extendable_carriers"]["Link"] = []
config_pypsaearth["electricity"]["co2limit"] = 7.75e7
config_pypsaearth["run"] = {
"name": "tutorial",
"shared_cutouts": True,
}

with open("./config.pypsa-earth.yaml", "w") as wfile:
yaml.dump(config_pypsaearth, wfile)
Expand All @@ -712,13 +737,17 @@ rule build_industrial_distribution_key: #default data
industry_database=config["custom_data"]["industry_database"],
input:
regions_onshore=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
"resources/"
+ RDIR_PE
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
),
clustered_pop_layout="resources/population_shares/pop_layout_elec_s{simpl}_{clusters}_{planning_horizons}.csv",
clustered_gdp_layout="resources/gdp_shares/gdp_layout_elec_s{simpl}_{clusters}_{planning_horizons}.csv",
industrial_database="data/industrial_database.csv",
shapes_path=pypsaearth(
"resources/bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
"resources/"
+ RDIR_PE
+ "bus_regions/regions_onshore_elec_s{simpl}_{clusters}.geojson"
),
output:
industrial_distribution_key="resources/demand/industrial_distribution_key_elec_s{simpl}_{clusters}_{planning_horizons}.csv",
Expand Down Expand Up @@ -813,10 +842,14 @@ if config["foresight"] == "myopic":
input:
network=RDIR
+ "/prenetworks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_{sopts}_{planning_horizons}_{discountrate}_{demand}_{h2export}export.nc",
powerplants=pypsaearth("resources/powerplants.csv"),
busmap_s=pypsaearth("resources/bus_regions/busmap_elec_s{simpl}.csv"),
powerplants=pypsaearth("resources/" + RDIR_PE + "powerplants.csv"),
busmap_s=pypsaearth(
"resources/" + RDIR_PE + "bus_regions/busmap_elec_s{simpl}.csv"
),
busmap=pypsaearth(
"resources/bus_regions/busmap_elec_s{simpl}_{clusters}.csv"
"resources/"
+ RDIR_PE
+ "bus_regions/busmap_elec_s{simpl}_{clusters}.csv"
),
clustered_pop_layout="resources/population_shares/pop_layout_elec_s{simpl}_{clusters}_{planning_horizons}.csv",
costs=CDIR
Expand Down Expand Up @@ -847,7 +880,7 @@ if config["foresight"] == "myopic":
def input_profile_tech_brownfield(w):
return {
f"profile_{tech}": pypsaearth(
f"resources/renewable_profiles/profile_{tech}.nc"
f"resources/" + RDIR_PE + "renewable_profiles/profile_{tech}.nc"
)
for tech in config["electricity"]["renewable_carriers"]
if tech != "hydro"
Expand Down Expand Up @@ -876,10 +909,14 @@ if config["foresight"] == "myopic":
# drop_leap_day=config["enable"]["drop_leap_day"],
carriers=config["electricity"]["renewable_carriers"],
input:
unpack(input_profile_tech_brownfield),
simplify_busmap=pypsaearth("resources/bus_regions/busmap_elec_s{simpl}.csv"),
# unpack(input_profile_tech_brownfield),
simplify_busmap=pypsaearth(
"resources/" + RDIR_PE + "bus_regions/busmap_elec_s{simpl}.csv"
),
cluster_busmap=pypsaearth(
"resources/bus_regions/busmap_elec_s{simpl}_{clusters}.csv"
"resources/"
+ RDIR_PE
+ "bus_regions/busmap_elec_s{simpl}_{clusters}.csv"
),
network=RDIR
+ "/prenetworks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}_{sopts}_{planning_horizons}_{discountrate}_{demand}_{h2export}export.nc",
Expand Down
6 changes: 5 additions & 1 deletion config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ results_dir: results/
summary_dir: results/
costs_dir: data/ #TODO change to the equivalent of technology data

run: test_run
run:
name: "test_run" # use this to keep track of runs with different settings
name_subworkflow: "" # scenario name of the pypsa-earth subworkflow
shared_cutouts: true # set to true to share the default cutout(s) across runs
# Note: value false requires build_cutout to be enabled

foresight: overnight

Expand Down
2 changes: 1 addition & 1 deletion scripts/copy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
f,
snakemake.params.summary_dir
+ "/"
+ snakemake.params.run
+ snakemake.params.run["name"]
+ "/configs/"
+ name,
)
6 changes: 5 additions & 1 deletion test/config.test1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ results_dir: results/
summary_dir: results/
costs_dir: data/ #TODO change to the equivalent of technology data

run: test1
run:
name: "tutorial" # use this to keep track of runs with different settings
name_subworkflow: "tutorial" # scenario name of the pypsa-earth subworkflow
shared_cutouts: true # set to true to share the default cutout(s) across runs
# Note: value false requires build_cutout to be enabled

foresight: overnight

Expand Down
9 changes: 6 additions & 3 deletions test/config.test_myopic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ results_dir: results/
summary_dir: results/
costs_dir: data/ #TODO change to the equivalent of technology data

run: test_myopic

run:
name: "test_myopic" # use this to keep track of runs with different settings
name_subworkflow: "tutorial" # scenario name of the pypsa-earth subworkflow
shared_cutouts: true # set to true to share the default cutout(s) across runs
# Note: value false requires build_cutout to be enabled
foresight: myopic

# option to disable the subworkflow to ease the analyses
disable_subworkflow: false
disable_subworkflow: true

scenario:
simpl: # only relevant for PyPSA-Eur
Expand Down

0 comments on commit 7f88c62

Please sign in to comment.