add Fabians suggestion

This commit is contained in:
virio-andreyana 2023-09-23 18:39:11 +02:00
parent b2c19eda40
commit 01cd1bbb74
8 changed files with 36 additions and 99 deletions

View File

@ -20,11 +20,7 @@ if config["enable"].get("prepare_links_p_nom", False):
rule build_electricity_demand: rule build_electricity_demand:
params: params:
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
countries=config["countries"], countries=config["countries"],
load=config["load"], load=config["load"],
input: input:
@ -65,11 +61,7 @@ rule build_powerplants:
rule base_network: rule base_network:
params: params:
countries=config["countries"], countries=config["countries"],
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
lines=config["lines"], lines=config["lines"],
links=config["links"], links=config["links"],
transformers=config["transformers"], transformers=config["transformers"],
@ -152,11 +144,7 @@ if config["enable"].get("build_cutout", False):
rule build_cutout: rule build_cutout:
params: params:
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
cutouts=config["atlite"]["cutouts"], cutouts=config["atlite"]["cutouts"],
input: input:
regions_onshore=RESOURCES + "regions_onshore.geojson", regions_onshore=RESOURCES + "regions_onshore.geojson",
@ -220,6 +208,7 @@ rule build_ship_raster:
rule build_renewable_profiles: rule build_renewable_profiles:
params: params:
snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
renewable=config["renewable"], renewable=config["renewable"],
input: input:
base_network=RESOURCES + "networks/base.nc", base_network=RESOURCES + "networks/base.nc",
@ -310,6 +299,8 @@ rule build_hydro_profile:
if config["lines"]["dynamic_line_rating"]["activate"]: if config["lines"]["dynamic_line_rating"]["activate"]:
rule build_line_rating: rule build_line_rating:
params:
snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
input: input:
base_network=RESOURCES + "networks/base.nc", base_network=RESOURCES + "networks/base.nc",
cutout="cutouts/" cutout="cutouts/"

View File

@ -141,11 +141,7 @@ if not (config["sector"]["gas_network"] or config["sector"]["H2_retrofit"]):
rule build_heat_demands: rule build_heat_demands:
params: params:
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
input: input:
pop_layout=RESOURCES + "pop_layout_{scope}.nc", pop_layout=RESOURCES + "pop_layout_{scope}.nc",
regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}_{clusters}.geojson", regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}_{clusters}.geojson",
@ -167,11 +163,7 @@ rule build_heat_demands:
rule build_temperature_profiles: rule build_temperature_profiles:
params: params:
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
input: input:
pop_layout=RESOURCES + "pop_layout_{scope}.nc", pop_layout=RESOURCES + "pop_layout_{scope}.nc",
regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}_{clusters}.geojson", regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}_{clusters}.geojson",
@ -223,11 +215,7 @@ rule build_cop_profiles:
rule build_solar_thermal_profiles: rule build_solar_thermal_profiles:
params: params:
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
solar_thermal=config["solar_thermal"], solar_thermal=config["solar_thermal"],
input: input:
pop_layout=RESOURCES + "pop_layout_{scope}.nc", pop_layout=RESOURCES + "pop_layout_{scope}.nc",
@ -689,11 +677,7 @@ rule build_shipping_demand:
rule build_transport_demand: rule build_transport_demand:
params: params:
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
sector=config["sector"], sector=config["sector"],
input: input:
clustered_pop_layout=RESOURCES + "pop_layout_elec_s{simpl}_{clusters}.csv", clustered_pop_layout=RESOURCES + "pop_layout_elec_s{simpl}_{clusters}.csv",

View File

@ -55,11 +55,7 @@ rule make_summary:
params: params:
foresight=config["foresight"], foresight=config["foresight"],
costs=config["costs"], costs=config["costs"],
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
scenario=config["scenario"], scenario=config["scenario"],
RDIR=RDIR, RDIR=RDIR,
input: input:

View File

@ -17,11 +17,7 @@ rule build_electricity_production:
The data is used for validation of the optimization results. The data is used for validation of the optimization results.
""" """
params: params:
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
countries=config["countries"], countries=config["countries"],
output: output:
RESOURCES + "historical_electricity_production.csv", RESOURCES + "historical_electricity_production.csv",
@ -39,11 +35,7 @@ rule build_cross_border_flows:
The data is used for validation of the optimization results. The data is used for validation of the optimization results.
""" """
params: params:
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
countries=config["countries"], countries=config["countries"],
input: input:
network=RESOURCES + "networks/base.nc", network=RESOURCES + "networks/base.nc",
@ -63,11 +55,7 @@ rule build_electricity_prices:
The data is used for validation of the optimization results. The data is used for validation of the optimization results.
""" """
params: params:
snapshots={ snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]},
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
},
countries=config["countries"], countries=config["countries"],
output: output:
RESOURCES + "historical_electricity_prices.csv", RESOURCES + "historical_electricity_prices.csv",

View File

@ -709,11 +709,7 @@ def base_network(
transformers = _set_electrical_parameters_transformers(transformers, config) transformers = _set_electrical_parameters_transformers(transformers, config)
links = _set_electrical_parameters_links(links, config, links_p_nom) links = _set_electrical_parameters_links(links, config, links_p_nom)
converters = _set_electrical_parameters_converters(converters, config) converters = _set_electrical_parameters_converters(converters, config)
snapshots = { snapshots = snakemake.params.snapshots
"start": config["snapshots"]["start"],
"end": config["snapshots"]["end"],
"inclusive": config["snapshots"]["inclusive"],
}
n = pypsa.Network() n = pypsa.Network()
n.name = "PyPSA-Eur" n.name = "PyPSA-Eur"

View File

@ -148,11 +148,7 @@ if __name__ == "__main__":
) )
configure_logging(snakemake) configure_logging(snakemake)
snapshots = { snapshots = snakemake.params.snapshots
"start": snakemake.config["snapshots"]["start"],
"end": snakemake.config["snapshots"]["end"],
"inclusive": snakemake.config["snapshots"]["inclusive"],
}
n = pypsa.Network(snakemake.input.base_network) n = pypsa.Network(snakemake.input.base_network)
time = pd.date_range(freq="h", **snapshots) time = pd.date_range(freq="h", **snapshots)

View File

@ -211,11 +211,7 @@ if __name__ == "__main__":
correction_factor = params.get("correction_factor", 1.0) correction_factor = params.get("correction_factor", 1.0)
capacity_per_sqkm = params["capacity_per_sqkm"] capacity_per_sqkm = params["capacity_per_sqkm"]
p_nom_max_meth = params.get("potential", "conservative") p_nom_max_meth = params.get("potential", "conservative")
snapshots = { snapshots = snakemake.params.snapshots
"start": snakemake.config["snapshots"]["start"],
"end": snakemake.config["snapshots"]["end"],
"inclusive": snakemake.config["snapshots"]["inclusive"],
}
if isinstance(params.get("corine", {}), list): if isinstance(params.get("corine", {}), list):
params["corine"] = {"grid_codes": params["corine"]} params["corine"] = {"grid_codes": params["corine"]}

View File

@ -314,26 +314,22 @@ if __name__ == "__main__":
# temporal averaging # temporal averaging
nhours_config = snakemake.params.snapshots.get("resolution", False) nhours_config = snakemake.params.snapshots.get("resolution", False)
nhours_wildcard = get_opt(opts, r"^\d+h$") nhours_wildcard = get_opt(opts, r"^\d+h$")
if nhours_wildcard is not None or isinstance(nhours_config, str): nhours = nhours_wildcard or nhours_config
nhours = nhours_wildcard or nhours_config if nhours:
n = average_every_nhours(n, nhours) n = average_every_nhours(n, nhours)
# segments with package tsam # segments with package tsam
time_seg_config = snakemake.params.snapshots.get("segmentation", False) time_seg_config = snakemake.params.snapshots.get("segmentation", False)
time_seg_wildcard = get_opt(opts, r"^\d+seg$") time_seg_wildcard = get_opt(opts, r"^\d+seg$")
if time_seg_wildcard is not None or isinstance(time_seg_config, str): time_seg = time_seg_wildcard or time_seg_config
time_seg = time_seg_wildcard or time_seg_config if time_seg:
solver_name = snakemake.config["solving"]["solver"]["name"] solver_name = snakemake.config["solving"]["solver"]["name"]
n = apply_time_segmentation(n, time_seg, solver_name) n = apply_time_segmentation(n, time_seg, solver_name)
Co2L_config = snakemake.params.co2limit_enable and isinstance( Co2L_config = snakemake.params.co2limit_enable
snakemake.params.co2limit, float
)
Co2L_wildcard, co2limit_wildcard = find_opt(opts, "Co2L") Co2L_wildcard, co2limit_wildcard = find_opt(opts, "Co2L")
if Co2L_wildcard or Co2L_config: if Co2L_wildcard or Co2L_config:
if ( if co2limit_wildcard is not None:
co2limit_wildcard is not None
): # TODO: what if you wat to determine the factor through the wildcard?
co2limit = co2limit_wildcard * snakemake.params.co2base co2limit = co2limit_wildcard * snakemake.params.co2base
add_co2limit(n, co2limit, Nyears) add_co2limit(n, co2limit, Nyears)
logger.info("Setting CO2 limit according to wildcard value.") logger.info("Setting CO2 limit according to wildcard value.")
@ -341,14 +337,10 @@ if __name__ == "__main__":
add_co2limit(n, snakemake.params.co2limit, Nyears) add_co2limit(n, snakemake.params.co2limit, Nyears)
logger.info("Setting CO2 limit according to config value.") logger.info("Setting CO2 limit according to config value.")
CH4L_config = snakemake.params.gaslimit_enable and isinstance( CH4L_config = snakemake.params.gaslimit_enable
snakemake.params.gaslimit, float
)
CH4L_wildcard, gaslimit_wildcard = find_opt(opts, "CH4L") CH4L_wildcard, gaslimit_wildcard = find_opt(opts, "CH4L")
if CH4L_wildcard or CH4L_config: if CH4L_wildcard or CH4L_config:
if ( if gaslimit_wildcard is not None:
gaslimit_wildcard is not None
): # TODO: what if you wat to determine the factor through the wildcard?
gaslimit = gaslimit_wildcard * 1e6 gaslimit = gaslimit_wildcard * 1e6
add_gaslimit(n, gaslimit, Nyears) add_gaslimit(n, gaslimit, Nyears)
logger.info("Setting gas usage limit according to wildcard value.") logger.info("Setting gas usage limit according to wildcard value.")
@ -375,20 +367,18 @@ if __name__ == "__main__":
sel = c.df.carrier.str.contains(carrier) sel = c.df.carrier.str.contains(carrier)
c.df.loc[sel, attr] *= factor c.df.loc[sel, attr] *= factor
Ept_config = snakemake.params.costs["emission_prices"].get( emission_prices = snakemake.params.costs["emission_prices"]
"co2_monthly_prices", False Ept_config = emission_prices.get("co2_monthly_prices", False)
) Ept_wildcard = "Ept" in opts
for o in opts: Ep_config = emission_prices.get("enable", False)
if "Ept" in o or Ept_config:
logger.info(
"Setting time dependent emission prices according spot market price"
)
add_dynamic_emission_prices(n)
Ept_config = True
Ep_config = snakemake.params.costs["emission_prices"].get("enable", False)
Ep_wildcard, co2_wildcard = find_opt(opts, "Ep") Ep_wildcard, co2_wildcard = find_opt(opts, "Ep")
if (Ep_wildcard or Ep_config) and not Ept_config:
if Ept_wildcard or Ept_config:
logger.info(
"Setting time dependent emission prices according spot market price"
)
add_dynamic_emission_prices(n)
elif Ep_wildcard or Ep_config:
if co2_wildcard is not None: if co2_wildcard is not None:
logger.info("Setting CO2 prices according to wildcard value.") logger.info("Setting CO2 prices according to wildcard value.")
add_emission_prices(n, dict(co2=co2_wildcard)) add_emission_prices(n, dict(co2=co2_wildcard))