diff --git a/rules/build_electricity.smk b/rules/build_electricity.smk index fd925d1f..4c6650bc 100644 --- a/rules/build_electricity.smk +++ b/rules/build_electricity.smk @@ -20,7 +20,7 @@ if config["enable"].get("prepare_links_p_nom", False): rule build_electricity_demand: params: - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config provider countries=config_provider("countries"), load=config_provider("load"), input: @@ -62,7 +62,7 @@ rule build_powerplants: rule base_network: params: countries=config_provider("countries"), - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config provider lines=config_provider("lines"), links=config_provider("links"), transformers=config_provider("transformers"), @@ -145,7 +145,7 @@ if config["enable"].get("build_cutout", False): rule build_cutout: params: - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config provider cutouts=config_provider("atlite", "cutouts"), input: regions_onshore=resources("regions_onshore.geojson"), @@ -259,7 +259,7 @@ else: rule build_renewable_profiles: params: - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config provider renewable=config_provider("renewable"), input: **opt, @@ -401,18 +401,22 @@ rule add_electricity: if str(fn).startswith("data/") }, base_network=resources("networks/base.nc"), - line_rating=resources("networks/line_rating.nc") - if config["lines"]["dynamic_line_rating"]["activate"] - else resources("networks/base.nc"), + line_rating=( + resources("networks/line_rating.nc") + if config["lines"]["dynamic_line_rating"]["activate"] + else resources("networks/base.nc") + ), tech_costs=COSTS, regions=resources("regions_onshore.geojson"), powerplants=resources("powerplants.csv"), hydro_capacities=ancient("data/bundle/hydro_capacities.csv"), geth_hydro_capacities="data/geth2015_hydro_capacities.csv", unit_commitment="data/unit_commitment.csv", - fuel_price=resources("monthly_fuel_price.csv") - if config["conventional"]["dynamic_fuel_price"] - else [], + fuel_price=( + resources("monthly_fuel_price.csv") + if config["conventional"]["dynamic_fuel_price"] + else [] + ), load=resources("load.csv"), nuts3_shapes=resources("nuts3_shapes.geojson"), ua_md_gdp="data/GDP_PPP_30arcsec_v3_mapped_default.csv", @@ -540,7 +544,8 @@ rule prepare_network: snapshots={ "resolution": config["snapshots"].get("resolution", False), "segmentation": config["snapshots"].get("segmentation", False), - }, # TODO: use config provider + }, + # TODO: use config provider links=config_provider("links"), lines=config_provider("lines"), co2base=config_provider("electricity", "co2base"), diff --git a/rules/build_sector.smk b/rules/build_sector.smk index f0081d32..aea16519 100644 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -94,7 +94,9 @@ rule build_gas_input_locations: regions_offshore=resources("regions_offshore_elec_s{simpl}_{clusters}.geojson"), output: gas_input_nodes=resources("gas_input_locations_s{simpl}_{clusters}.geojson"), - gas_input_nodes_simplified=resources("gas_input_locations_s{simpl}_{clusters}_simplified.csv"), + gas_input_nodes_simplified=resources( + "gas_input_locations_s{simpl}_{clusters}_simplified.csv" + ), resources: mem_mb=2000, log: @@ -124,7 +126,7 @@ rule cluster_gas_network: rule build_daily_heat_demand: params: - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider input: pop_layout=resources("pop_layout_{scope}.nc"), regions_onshore=resources("regions_onshore_elec_s{simpl}_{clusters}.geojson"), @@ -167,7 +169,7 @@ rule build_hourly_heat_demand: rule build_temperature_profiles: params: - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider input: pop_layout=resources("pop_layout_{scope}.nc"), regions_onshore=resources("regions_onshore_elec_s{simpl}_{clusters}.geojson"), @@ -219,7 +221,7 @@ rule build_cop_profiles: rule build_solar_thermal_profiles: params: - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO use config_provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO use config_provider solar_thermal=config_provider("solar_thermal"), input: pop_layout=resources("pop_layout_{scope}.nc"), @@ -287,7 +289,9 @@ rule build_biomass_potentials: biomass_potentials_all=resources( "biomass_potentials_all_s{simpl}_{clusters}_{planning_horizons}.csv" ), - biomass_potentials=resources("biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv"), + biomass_potentials=resources( + "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv" + ), threads: 1 resources: mem_mb=1000, @@ -707,7 +711,7 @@ rule build_shipping_demand: rule build_transport_demand: params: - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider sector=config_provider("sector"), input: clustered_pop_layout=resources("pop_layout_elec_s{simpl}_{clusters}.csv"), @@ -814,7 +818,9 @@ rule prepare_sector_network: network=resources("networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc"), energy_totals_name=resources("energy_totals.csv"), eurostat=input_eurostat, - pop_weighted_energy_totals=resources("pop_weighted_energy_totals_s{simpl}_{clusters}.csv"), + pop_weighted_energy_totals=resources( + "pop_weighted_energy_totals_s{simpl}_{clusters}.csv" + ), shipping_demand=resources("shipping_demand_s{simpl}_{clusters}.csv"), transport_demand=resources("transport_demand_s{simpl}_{clusters}.csv"), transport_data=resources("transport_data_s{simpl}_{clusters}.csv"), @@ -823,10 +829,14 @@ rule prepare_sector_network: co2_totals_name=resources("co2_totals.csv"), co2="data/bundle-sector/eea/UNFCCC_v23.csv", biomass_potentials=( - resources("biomass_potentials_s{simpl}_{clusters}_" - + "{}.csv".format(config["biomass"]["year"])) + resources( + "biomass_potentials_s{simpl}_{clusters}_" + + "{}.csv".format(config["biomass"]["year"]) + ) if config["foresight"] == "overnight" - else resources("biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv") + else resources( + "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv" + ) ), costs=( "data/costs_{}.csv".format(config["costs"]["year"]) @@ -840,9 +850,15 @@ rule prepare_sector_network: busmap=resources("busmap_elec_s{simpl}_{clusters}.csv"), clustered_pop_layout=resources("pop_layout_elec_s{simpl}_{clusters}.csv"), simplified_pop_layout=resources("pop_layout_elec_s{simpl}.csv"), - industrial_demand=resources("industrial_energy_demand_elec_s{simpl}_{clusters}_{planning_horizons}.csv"), - hourly_heat_demand_total=resources("hourly_heat_demand_total_elec_s{simpl}_{clusters}.nc"), - district_heat_share=resources("district_heat_share_elec_s{simpl}_{clusters}_{planning_horizons}.csv"), + industrial_demand=resources( + "industrial_energy_demand_elec_s{simpl}_{clusters}_{planning_horizons}.csv" + ), + hourly_heat_demand_total=resources( + "hourly_heat_demand_total_elec_s{simpl}_{clusters}.nc" + ), + district_heat_share=resources( + "district_heat_share_elec_s{simpl}_{clusters}_{planning_horizons}.csv" + ), temp_soil_total=resources("temp_soil_total_elec_s{simpl}_{clusters}.nc"), temp_soil_rural=resources("temp_soil_rural_elec_s{simpl}_{clusters}.nc"), temp_soil_urban=resources("temp_soil_urban_elec_s{simpl}_{clusters}.nc"), diff --git a/rules/collect.smk b/rules/collect.smk index 0fb19165..8a451d7a 100644 --- a/rules/collect.smk +++ b/rules/collect.smk @@ -24,7 +24,7 @@ rule cluster_networks: expand( resources("networks/elec_s{simpl}_{clusters}.nc"), **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), @@ -33,7 +33,7 @@ rule extra_components_networks: expand( resources("networks/elec_s{simpl}_{clusters}_ec.nc"), **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), @@ -42,7 +42,7 @@ rule prepare_elec_networks: expand( resources("networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc"), **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), @@ -52,7 +52,7 @@ rule prepare_sector_networks: RESULTS + "prenetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), @@ -61,7 +61,7 @@ rule solve_elec_networks: expand( RESULTS + "networks/elec_s{simpl}_{clusters}_ec_l{ll}_{opts}.nc", **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), @@ -71,7 +71,7 @@ rule solve_sector_networks: RESULTS + "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), @@ -81,7 +81,7 @@ rule solve_sector_networks_perfect: RESULTS + "maps/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}-costs-all_{planning_horizons}.pdf", **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), @@ -91,12 +91,12 @@ rule validate_elec_networks: RESULTS + "figures/.statistics_plots_elec_s{simpl}_{clusters}_ec_l{ll}_{opts}", **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), expand( RESULTS + "figures/.validation_{kind}_plots_elec_s{simpl}_{clusters}_ec_l{ll}_{opts}", **config["scenario"], run=config["run"]["name"], - kind=["production", "prices", "cross_border"] + kind=["production", "prices", "cross_border"], ), diff --git a/rules/postprocess.smk b/rules/postprocess.smk index 19dc34be..7e269688 100644 --- a/rules/postprocess.smk +++ b/rules/postprocess.smk @@ -162,7 +162,7 @@ rule make_summary: params: foresight=config_provider("foresight"), costs=config_provider("costs"), - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider scenario=config_provider("scenario"), RDIR=RDIR, input: @@ -174,7 +174,7 @@ rule make_summary: RESULTS + "postnetworks/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}_{planning_horizons}.nc", **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), costs=( "data/costs_{}.csv".format(config["costs"]["year"]) @@ -189,7 +189,7 @@ rule make_summary: RESULTS + "maps/elec_s{simpl}_{clusters}_l{ll}_{opts}_{sector_opts}-costs-all_{planning_horizons}.pdf", **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), h2_plot=expand( ( @@ -199,7 +199,7 @@ rule make_summary: else [] ), **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), ch4_plot=expand( ( @@ -209,7 +209,7 @@ rule make_summary: else [] ), **config["scenario"], - run=config["run"]["name"] + run=config["run"]["name"], ), output: nodal_costs=RESULTS + "csvs/nodal_costs.csv", diff --git a/rules/solve_myopic.smk b/rules/solve_myopic.smk index fac58456..7035f1c1 100644 --- a/rules/solve_myopic.smk +++ b/rules/solve_myopic.smk @@ -21,7 +21,9 @@ rule add_existing_baseyear: ), cop_soil_total=resources("cop_soil_total_elec_s{simpl}_{clusters}.nc"), cop_air_total=resources("cop_air_total_elec_s{simpl}_{clusters}.nc"), - existing_heating_distribution=resources("existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv"), + existing_heating_distribution=resources( + "existing_heating_distribution_elec_s{simpl}_{clusters}_{planning_horizons}.csv" + ), existing_solar="data/existing_infrastructure/solar_capacity_IRENA.csv", existing_onwind="data/existing_infrastructure/onwind_capacity_IRENA.csv", existing_offwind="data/existing_infrastructure/offwind_capacity_IRENA.csv", @@ -54,7 +56,7 @@ rule add_brownfield: "sector", "H2_retrofit_capacity_per_CH4" ), threshold_capacity=config_provider("existing_capacities", " threshold_capacity"), - snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider + snapshots={k: config["snapshots"][k] for k in ["start", "end", "inclusive"]}, # TODO: use config_provider carriers=config_provider("electricity", "renewable_carriers"), input: **{ diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 44b83e99..bd00a258 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -133,7 +133,7 @@ import numpy as np import pandas as pd import pypsa import seaborn as sns -from _helpers import configure_logging, update_p_nom_max, set_scenario_config +from _helpers import configure_logging, set_scenario_config, update_p_nom_max from add_electricity import load_costs from packaging.version import Version, parse from pypsa.clustering.spatial import ( diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 06aea9ec..b1161c19 100755 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -18,7 +18,7 @@ import numpy as np import pandas as pd import pypsa import xarray as xr -from _helpers import update_config_with_sector_opts, set_scenario_config +from _helpers import set_scenario_config, update_config_with_sector_opts from add_electricity import calculate_annuity, sanitize_carriers, sanitize_locations from build_energy_totals import build_co2_totals, build_eea_co2, build_eurostat_co2 from networkx.algorithms import complement diff --git a/scripts/retrieve_sector_databundle.py b/scripts/retrieve_sector_databundle.py index defc806c..f95986b4 100644 --- a/scripts/retrieve_sector_databundle.py +++ b/scripts/retrieve_sector_databundle.py @@ -13,8 +13,8 @@ from pathlib import Path from _helpers import ( configure_logging, progress_retrieve, - validate_checksum, set_scenario_config, + validate_checksum, ) logger = logging.getLogger(__name__) diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 5ca0ec82..b828bbd2 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -40,8 +40,8 @@ from _benchmark import memory_logger from _helpers import ( configure_logging, get_opt, - update_config_with_sector_opts, set_scenario_config, + update_config_with_sector_opts, ) from pypsa.descriptors import get_activity_mask from pypsa.descriptors import get_switchable_as_dense as get_as_dense