diff --git a/rules/build_electricity.smk b/rules/build_electricity.smk index c52404bf..dc5ce1c6 100644 --- a/rules/build_electricity.smk +++ b/rules/build_electricity.smk @@ -20,11 +20,7 @@ if config["enable"].get("prepare_links_p_nom", False): rule build_electricity_demand: params: - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, countries=config["countries"], load=config["load"], input: @@ -65,11 +61,7 @@ rule build_powerplants: rule base_network: params: countries=config["countries"], - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, lines=config["lines"], links=config["links"], transformers=config["transformers"], @@ -152,11 +144,7 @@ if config["enable"].get("build_cutout", False): rule build_cutout: params: - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, cutouts=config["atlite"]["cutouts"], input: regions_onshore=RESOURCES + "regions_onshore.geojson", @@ -220,6 +208,7 @@ rule build_ship_raster: rule build_renewable_profiles: params: + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, renewable=config["renewable"], input: base_network=RESOURCES + "networks/base.nc", @@ -310,6 +299,8 @@ rule build_hydro_profile: if config["lines"]["dynamic_line_rating"]["activate"]: rule build_line_rating: + params: + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, input: base_network=RESOURCES + "networks/base.nc", cutout="cutouts/" diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 53a19852..c148bc9f 100644 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -141,11 +141,7 @@ if not (config["sector"]["gas_network"] or config["sector"]["H2_retrofit"]): rule build_heat_demands: params: - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, input: pop_layout=RESOURCES + "pop_layout_{scope}.nc", regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}_{clusters}.geojson", @@ -167,11 +163,7 @@ rule build_heat_demands: rule build_temperature_profiles: params: - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, input: pop_layout=RESOURCES + "pop_layout_{scope}.nc", regions_onshore=RESOURCES + "regions_onshore_elec_s{simpl}_{clusters}.geojson", @@ -223,11 +215,7 @@ rule build_cop_profiles: rule build_solar_thermal_profiles: params: - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, solar_thermal=config["solar_thermal"], input: pop_layout=RESOURCES + "pop_layout_{scope}.nc", @@ -689,11 +677,7 @@ rule build_shipping_demand: rule build_transport_demand: params: - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, sector=config["sector"], input: clustered_pop_layout=RESOURCES + "pop_layout_elec_s{simpl}_{clusters}.csv", diff --git a/rules/postprocess.smk b/rules/postprocess.smk index 02ac219a..795ea1b1 100644 --- a/rules/postprocess.smk +++ b/rules/postprocess.smk @@ -55,11 +55,7 @@ rule make_summary: params: foresight=config["foresight"], costs=config["costs"], - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, scenario=config["scenario"], RDIR=RDIR, input: diff --git a/rules/validate.smk b/rules/validate.smk index 1c0fe10a..0fa1f607 100644 --- a/rules/validate.smk +++ b/rules/validate.smk @@ -17,11 +17,7 @@ rule build_electricity_production: The data is used for validation of the optimization results. """ params: - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, countries=config["countries"], output: RESOURCES + "historical_electricity_production.csv", @@ -39,11 +35,7 @@ rule build_cross_border_flows: The data is used for validation of the optimization results. """ params: - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, countries=config["countries"], input: network=RESOURCES + "networks/base.nc", @@ -63,11 +55,7 @@ rule build_electricity_prices: The data is used for validation of the optimization results. """ params: - snapshots={ - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - }, + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, countries=config["countries"], output: RESOURCES + "historical_electricity_prices.csv", diff --git a/scripts/base_network.py b/scripts/base_network.py index a176028f..372f9a20 100644 --- a/scripts/base_network.py +++ b/scripts/base_network.py @@ -709,11 +709,7 @@ def base_network( transformers = _set_electrical_parameters_transformers(transformers, config) links = _set_electrical_parameters_links(links, config, links_p_nom) converters = _set_electrical_parameters_converters(converters, config) - snapshots = { - "start": config["snapshots"]["start"], - "end": config["snapshots"]["end"], - "inclusive": config["snapshots"]["inclusive"], - } + snapshots = snakemake.params.snapshots n = pypsa.Network() n.name = "PyPSA-Eur" diff --git a/scripts/build_line_rating.py b/scripts/build_line_rating.py index 51c779e5..1767ebc8 100755 --- a/scripts/build_line_rating.py +++ b/scripts/build_line_rating.py @@ -148,11 +148,7 @@ if __name__ == "__main__": ) configure_logging(snakemake) - snapshots = { - "start": snakemake.config["snapshots"]["start"], - "end": snakemake.config["snapshots"]["end"], - "inclusive": snakemake.config["snapshots"]["inclusive"], - } + snapshots = snakemake.params.snapshots n = pypsa.Network(snakemake.input.base_network) time = pd.date_range(freq="h", **snapshots) diff --git a/scripts/build_renewable_profiles.py b/scripts/build_renewable_profiles.py index 1d3b9956..a8432219 100644 --- a/scripts/build_renewable_profiles.py +++ b/scripts/build_renewable_profiles.py @@ -211,11 +211,7 @@ if __name__ == "__main__": correction_factor = params.get("correction_factor", 1.0) capacity_per_sqkm = params["capacity_per_sqkm"] p_nom_max_meth = params.get("potential", "conservative") - snapshots = { - "start": snakemake.config["snapshots"]["start"], - "end": snakemake.config["snapshots"]["end"], - "inclusive": snakemake.config["snapshots"]["inclusive"], - } + snapshots = snakemake.params.snapshots if isinstance(params.get("corine", {}), list): params["corine"] = {"grid_codes": params["corine"]} diff --git a/scripts/prepare_network.py b/scripts/prepare_network.py index 30ac41bf..2a15cb0c 100755 --- a/scripts/prepare_network.py +++ b/scripts/prepare_network.py @@ -314,26 +314,22 @@ if __name__ == "__main__": # temporal averaging nhours_config = snakemake.params.snapshots.get("resolution", False) 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) # segments with package tsam time_seg_config = snakemake.params.snapshots.get("segmentation", False) 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"] n = apply_time_segmentation(n, time_seg, solver_name) - Co2L_config = snakemake.params.co2limit_enable and isinstance( - snakemake.params.co2limit, float - ) + Co2L_config = snakemake.params.co2limit_enable Co2L_wildcard, co2limit_wildcard = find_opt(opts, "Co2L") if Co2L_wildcard or Co2L_config: - if ( - co2limit_wildcard is not None - ): # TODO: what if you wat to determine the factor through the wildcard? + if co2limit_wildcard is not None: co2limit = co2limit_wildcard * snakemake.params.co2base add_co2limit(n, co2limit, Nyears) logger.info("Setting CO2 limit according to wildcard value.") @@ -341,14 +337,10 @@ if __name__ == "__main__": add_co2limit(n, snakemake.params.co2limit, Nyears) logger.info("Setting CO2 limit according to config value.") - CH4L_config = snakemake.params.gaslimit_enable and isinstance( - snakemake.params.gaslimit, float - ) + CH4L_config = snakemake.params.gaslimit_enable CH4L_wildcard, gaslimit_wildcard = find_opt(opts, "CH4L") if CH4L_wildcard or CH4L_config: - if ( - gaslimit_wildcard is not None - ): # TODO: what if you wat to determine the factor through the wildcard? + if gaslimit_wildcard is not None: gaslimit = gaslimit_wildcard * 1e6 add_gaslimit(n, gaslimit, Nyears) logger.info("Setting gas usage limit according to wildcard value.") @@ -375,20 +367,18 @@ if __name__ == "__main__": sel = c.df.carrier.str.contains(carrier) c.df.loc[sel, attr] *= factor - Ept_config = snakemake.params.costs["emission_prices"].get( - "co2_monthly_prices", False - ) - for o in opts: - 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) + emission_prices = snakemake.params.costs["emission_prices"] + Ept_config = emission_prices.get("co2_monthly_prices", False) + Ept_wildcard = "Ept" in opts + Ep_config = emission_prices.get("enable", False) 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: logger.info("Setting CO2 prices according to wildcard value.") add_emission_prices(n, dict(co2=co2_wildcard))