From d142d5a50b0a64bfbbc2e00a396abcaeecc5ee60 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 24 Jul 2024 10:54:15 +0200 Subject: [PATCH 01/10] aggregate curtailment into single curtailment generator per bus (#1177) * add curtailment generator mode * add documentation --- config/config.default.yaml | 5 +++-- doc/configtables/solving.csv | 1 + doc/release_notes.rst | 6 ++++++ scripts/solve_network.py | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index d1d13065..ab5bb043 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -786,6 +786,7 @@ solving: options: clip_p_max_pu: 1.e-2 load_shedding: false + curtailment_mode: false noisy_costs: true skip_iterations: true rolling_horizon: false @@ -830,7 +831,7 @@ solving: solver_options: highs-default: # refer to https://ergo-code.github.io/HiGHS/dev/options/definitions/ - threads: 4 + threads: 1 solver: "ipm" run_crossover: "off" small_matrix_value: 1e-6 @@ -841,7 +842,7 @@ solving: parallel: "on" random_seed: 123 gurobi-default: - threads: 4 + threads: 8 method: 2 # barrier crossover: 0 BarConvTol: 1.e-6 diff --git a/doc/configtables/solving.csv b/doc/configtables/solving.csv index 4cfb9065..d2e22c28 100644 --- a/doc/configtables/solving.csv +++ b/doc/configtables/solving.csv @@ -2,6 +2,7 @@ options,,, -- clip_p_max_pu,p.u.,float,To avoid too small values in the renewables` per-unit availability time series values below this threshold are set to zero. -- load_shedding,bool/float,"{'true','false', float}","Add generators with very high marginal cost to simulate load shedding and avoid problem infeasibilities. If load shedding is a float, it denotes the marginal cost in EUR/kWh." +-- curtailment_mode,bool/float,"{'true','false'}","Fixes the dispatch profiles of generators with time-varying p_max_pu by setting ``p_min_pu = p_max_pu`` and adds an auxiliary curtailment generator (with negative sign to absorb excess power) at every AC bus. This can speed up the solving process as the curtailment decision is aggregated into a single generator per region. Defaults to ``false``." -- noisy_costs,bool,"{'true','false'}","Add random noise to marginal cost of generators by :math:`\mathcal{U}(0.009,0,011)` and capital cost of lines and links by :math:`\mathcal{U}(0.09,0,11)`." -- skip_iterations,bool,"{'true','false'}","Skip iterating, do not update impedances of branches. Defaults to true." -- rolling_horizon,bool,"{'true','false'}","Switch for rule :mod:`solve_operations_network` whether to optimize the network in a rolling horizon manner, where the snapshot range is split into slices of size `horizon` which are solved consecutively. This setting has currently no effect on sector-coupled networks." diff --git a/doc/release_notes.rst b/doc/release_notes.rst index eb29ce4b..c38888a0 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -41,6 +41,12 @@ Upcoming Release * Enable parallelism in :mod:`determine_availability_matrix_MD_UA.py` and remove plots. This requires the use of temporary files. +* Added option ``solving: curtailment_mode``` which fixes the dispatch profiles + of generators with time-varying p_max_pu by setting ``p_min_pu = p_max_pu`` + and adds an auxiliary curtailment generator with negative sign (to absorb + excess power) at every AC bus. This can speed up the solving process as the + curtailment decision is aggregated into a single generator per region. + PyPSA-Eur 0.11.0 (25th May 2024) ===================================== diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 42ffe6be..a2391ea2 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -471,6 +471,22 @@ def prepare_network( p_nom=1e9, # kW ) + if solve_opts.get("curtailment_mode"): + n.add("Carrier", "curtailment", color="#fedfed", nice_name="Curtailment") + n.generators_t.p_min_pu = n.generators_t.p_max_pu + buses_i = n.buses.query("carrier == 'AC'").index + n.madd( + "Generator", + buses_i, + suffix=" curtailment", + bus=buses_i, + p_min_pu=-1, + p_max_pu=0, + marginal_cost=-0.1, + carrier="curtailment", + p_nom=1e6, + ) + if solve_opts.get("noisy_costs"): for t in n.iterate_components(): # if 'capital_cost' in t.df: From 8b1b1144d59d024add0ea2746d919a500bae3ba8 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 24 Jul 2024 11:01:00 +0200 Subject: [PATCH 02/10] cutouts: update zenodo repository version (#1176) --- config/config.default.yaml | 34 ++++++++++++--------------------- doc/configtables/atlite.csv | 2 +- doc/configtables/hydro.csv | 2 +- doc/configtables/lines.csv | 2 +- doc/configtables/offwind-ac.csv | 2 +- doc/configtables/offwind-dc.csv | 2 +- doc/configtables/onwind.csv | 2 +- doc/configtables/solar.csv | 2 +- doc/preparation.rst | 2 +- doc/release_notes.rst | 6 ++++++ rules/retrieve.smk | 2 +- scripts/build_cutout.py | 2 +- 12 files changed, 28 insertions(+), 32 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index ab5bb043..4641837e 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -134,35 +134,25 @@ electricity: # docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#atlite atlite: - default_cutout: europe-2013-era5 + default_cutout: europe-2013-sarah3-era5 nprocesses: 4 show_progress: false cutouts: # use 'base' to determine geographical bounds and time span from config # base: # module: era5 - europe-2013-era5: - module: era5 # in priority order + europe-2013-sarah3-era5: + module: [sarah, era5] # in priority order x: [-12., 42.] - y: [33., 72] + y: [33., 72.] dx: 0.3 dy: 0.3 time: ['2013', '2013'] - europe-2013-sarah: - module: [sarah, era5] # in priority order - x: [-12., 42.] - y: [33., 65] - dx: 0.2 - dy: 0.2 - time: ['2013', '2013'] - sarah_interpolate: false - sarah_dir: - features: [influx, temperature] # docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#renewable renewable: onwind: - cutout: europe-2013-era5 + cutout: europe-2013-sarah3-era5 resource: method: wind turbine: Vestas_V112_3MW @@ -181,7 +171,7 @@ renewable: excluder_resolution: 100 clip_p_max_pu: 1.e-2 offwind-ac: - cutout: europe-2013-era5 + cutout: europe-2013-sarah3-era5 resource: method: wind turbine: NREL_ReferenceTurbine_2020ATB_5.5MW @@ -197,7 +187,7 @@ renewable: excluder_resolution: 200 clip_p_max_pu: 1.e-2 offwind-dc: - cutout: europe-2013-era5 + cutout: europe-2013-sarah3-era5 resource: method: wind turbine: NREL_ReferenceTurbine_2020ATB_5.5MW @@ -213,7 +203,7 @@ renewable: excluder_resolution: 200 clip_p_max_pu: 1.e-2 offwind-float: - cutout: europe-2013-era5 + cutout: europe-2013-sarah3-era5 resource: method: wind turbine: NREL_ReferenceTurbine_5MW_offshore @@ -231,7 +221,7 @@ renewable: max_depth: 1000 clip_p_max_pu: 1.e-2 solar: - cutout: europe-2013-sarah + cutout: europe-2013-sarah3-era5 resource: method: pv panel: CSi @@ -246,7 +236,7 @@ renewable: excluder_resolution: 100 clip_p_max_pu: 1.e-2 solar-hsat: - cutout: europe-2013-sarah + cutout: europe-2013-sarah3-era5 resource: method: pv panel: CSi @@ -261,7 +251,7 @@ renewable: excluder_resolution: 100 clip_p_max_pu: 1.e-2 hydro: - cutout: europe-2013-era5 + cutout: europe-2013-sarah3-era5 carriers: [ror, PHS, hydro] PHS_max_hours: 6 hydro_max_hours: "energy_capacity_totals_by_country" # one of energy_capacity_totals_by_country, estimate_by_large_installations or a float @@ -295,7 +285,7 @@ lines: under_construction: 'keep' # 'zero': set capacity to zero, 'remove': remove, 'keep': with full capacity dynamic_line_rating: activate: false - cutout: europe-2013-era5 + cutout: europe-2013-sarah3-era5 correction_factor: 0.95 max_voltage_difference: false max_line_rating: false diff --git a/doc/configtables/atlite.csv b/doc/configtables/atlite.csv index 0b01005d..5e0d2bd0 100644 --- a/doc/configtables/atlite.csv +++ b/doc/configtables/atlite.csv @@ -3,7 +3,7 @@ default_cutout,--,str,"Defines a default cutout." nprocesses,--,int,"Number of parallel processes in cutout preparation" show_progress,bool,true/false,"Whether progressbar for atlite conversion processes should be shown. False saves time." cutouts,,, --- {name},--,"Convention is to name cutouts like ``--`` (e.g. ``europe-2013-era5``).","Name of the cutout netcdf file. The user may specify multiple cutouts under configuration ``atlite: cutouts:``. Reference is used in configuration ``renewable: {technology}: cutout:``. The cutout ``base`` may be used to automatically calculate temporal and spatial bounds of the network." +-- {name},--,"Convention is to name cutouts like ``--`` (e.g. ``europe-2013-sarah3-era5``).","Name of the cutout netcdf file. The user may specify multiple cutouts under configuration ``atlite: cutouts:``. Reference is used in configuration ``renewable: {technology}: cutout:``. The cutout ``base`` may be used to automatically calculate temporal and spatial bounds of the network." -- -- module,--,"Subset of {'era5','sarah'}","Source of the reanalysis weather dataset (e.g. `ERA5 `_ or `SARAH-2 `_)" -- -- x,°,"Float interval within [-180, 180]","Range of longitudes to download weather data for. If not defined, it defaults to the spatial bounds of all bus shapes." -- -- y,°,"Float interval within [-90, 90]","Range of latitudes to download weather data for. If not defined, it defaults to the spatial bounds of all bus shapes." diff --git a/doc/configtables/hydro.csv b/doc/configtables/hydro.csv index 790029d1..8903aa0f 100644 --- a/doc/configtables/hydro.csv +++ b/doc/configtables/hydro.csv @@ -1,5 +1,5 @@ ,Unit,Values,Description -cutout,--,Must be 'europe-2013-era5',Specifies the directory where the relevant weather data ist stored. +cutout,--,Must be 'europe-2013-sarah3-era5',Specifies the directory where the relevant weather data ist stored. carriers,--,"Any subset of {'ror', 'PHS', 'hydro'}","Specifies the types of hydro power plants to build per-unit availability time series for. 'ror' stands for run-of-river plants, 'PHS' represents pumped-hydro storage, and 'hydro' stands for hydroelectric dams." PHS_max_hours,h,float,Maximum state of charge capacity of the pumped-hydro storage (PHS) in terms of hours at full output capacity ``p_nom``. Cf. `PyPSA documentation `_. hydro_max_hours,h,"Any of {float, 'energy_capacity_totals_by_country', 'estimate_by_large_installations'}",Maximum state of charge capacity of the pumped-hydro storage (PHS) in terms of hours at full output capacity ``p_nom`` or heuristically determined. Cf. `PyPSA documentation `_. diff --git a/doc/configtables/lines.csv b/doc/configtables/lines.csv index 3707d4a6..79fa2e16 100644 --- a/doc/configtables/lines.csv +++ b/doc/configtables/lines.csv @@ -8,7 +8,7 @@ under_construction,--,"One of {'zero': set capacity to zero, 'remove': remove co reconnect_crimea,--,"true or false","Whether to reconnect Crimea to the Ukrainian grid" dynamic_line_rating,,, -- activate,bool,"true or false","Whether to take dynamic line rating into account" --- cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-era5') or reference an existing folder in the directory ``cutouts``. Source module must be ERA5.","Specifies the directory where the relevant weather data ist stored." +-- cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-sarah3-era5') or reference an existing folder in the directory ``cutouts``. Source module must be ERA5.","Specifies the directory where the relevant weather data ist stored." -- correction_factor,--,"float","Factor to compensate for overestimation of wind speeds in hourly averaged wind data" -- max_voltage_difference,deg,"float","Maximum voltage angle difference in degrees or 'false' to disable" -- max_line_rating,--,"float","Maximum line rating relative to nominal capacity without DLR, e.g. 1.3 or 'false' to disable" diff --git a/doc/configtables/offwind-ac.csv b/doc/configtables/offwind-ac.csv index b2533f04..9ba2fa7e 100644 --- a/doc/configtables/offwind-ac.csv +++ b/doc/configtables/offwind-ac.csv @@ -1,5 +1,5 @@ ,Unit,Values,Description -cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-era5') or reference an existing folder in the directory ``cutouts``. Source module must be ERA5.","Specifies the directory where the relevant weather data ist stored." +cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-sarah3-era5') or reference an existing folder in the directory ``cutouts``. Source module must be ERA5.","Specifies the directory where the relevant weather data ist stored." resource,,, -- method,--,"Must be 'wind'","A superordinate technology type." -- turbine,--,"One of turbine types included in `atlite `_. Can be a string or a dictionary with years as keys which denote the year another turbine model becomes available.","Specifies the turbine type and its characteristic power curve." diff --git a/doc/configtables/offwind-dc.csv b/doc/configtables/offwind-dc.csv index 7c537543..e55d8944 100644 --- a/doc/configtables/offwind-dc.csv +++ b/doc/configtables/offwind-dc.csv @@ -1,5 +1,5 @@ ,Unit,Values,Description -cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-era5') or reference an existing folder in the directory ``cutouts``. Source module must be ERA5.","Specifies the directory where the relevant weather data ist stored." +cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-sarah3-era5') or reference an existing folder in the directory ``cutouts``. Source module must be ERA5.","Specifies the directory where the relevant weather data ist stored." resource,,, -- method,--,"Must be 'wind'","A superordinate technology type." -- turbine,--,"One of turbine types included in `atlite `_. Can be a string or a dictionary with years as keys which denote the year another turbine model becomes available.","Specifies the turbine type and its characteristic power curve." diff --git a/doc/configtables/onwind.csv b/doc/configtables/onwind.csv index 3b09214b..a801d83c 100644 --- a/doc/configtables/onwind.csv +++ b/doc/configtables/onwind.csv @@ -1,5 +1,5 @@ ,Unit,Values,Description -cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-era5') or reference an existing folder in the directory ``cutouts``. Source module must be ERA5.","Specifies the directory where the relevant weather data ist stored." +cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-sarah3-era5') or reference an existing folder in the directory ``cutouts``. Source module must be ERA5.","Specifies the directory where the relevant weather data ist stored." resource,,, -- method,--,"Must be 'wind'","A superordinate technology type." -- turbine,--,"One of turbine types included in `atlite `_. Can be a string or a dictionary with years as keys which denote the year another turbine model becomes available.","Specifies the turbine type and its characteristic power curve." diff --git a/doc/configtables/solar.csv b/doc/configtables/solar.csv index 18587694..21d7c2e4 100644 --- a/doc/configtables/solar.csv +++ b/doc/configtables/solar.csv @@ -1,5 +1,5 @@ ,Unit,Values,Description -cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-era5') or reference an existing folder in the directory ``cutouts``. Source module can be ERA5 or SARAH-2.","Specifies the directory where the relevant weather data ist stored that is specified at ``atlite/cutouts`` configuration. Both ``sarah`` and ``era5`` work." +cutout,--,"Should be a folder listed in the configuration ``atlite: cutouts:`` (e.g. 'europe-2013-sarah3-era5') or reference an existing folder in the directory ``cutouts``. Source module can be ERA5 or SARAH-2.","Specifies the directory where the relevant weather data ist stored that is specified at ``atlite/cutouts`` configuration. Both ``sarah`` and ``era5`` work." resource,,, -- method,--,"Must be 'pv'","A superordinate technology type." -- panel,--,"One of {'Csi', 'CdTe', 'KANENA'} as defined in `atlite `_ . Can be a string or a dictionary with years as keys which denote the year another turbine model becomes available.","Specifies the solar panel technology and its characteristic attributes." diff --git a/doc/preparation.rst b/doc/preparation.rst index 06e8b19b..669f3392 100644 --- a/doc/preparation.rst +++ b/doc/preparation.rst @@ -16,7 +16,7 @@ using the ``retrieve*`` rules (:ref:`data`). Having downloaded the necessary data, - :mod:`build_shapes` generates GeoJSON files with shapes of the countries, exclusive economic zones and `NUTS3 `__ areas. -- :mod:`build_cutout` prepares smaller weather data portions from `ERA5 `__ for cutout ``europe-2013-era5`` and SARAH for cutout ``europe-2013-sarah``. +- :mod:`build_cutout` prepares smaller weather data portions from `ERA5 `__ for cutout ``europe-2013-sarah3-era5`` and SARAH for cutout ``europe-2013-sarah``. With these and the externally extracted ENTSO-E online map topology (``data/entsoegridkit``), it can build a base PyPSA network with the following rules: diff --git a/doc/release_notes.rst b/doc/release_notes.rst index c38888a0..b6c0db54 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -41,6 +41,12 @@ Upcoming Release * Enable parallelism in :mod:`determine_availability_matrix_MD_UA.py` and remove plots. This requires the use of temporary files. +* Updated pre-built `weather data cutouts + `__. These are now merged cutouts with + solar irradiation from the new SARAH-3 dataset while taking all other + variables from ERA5. Cutouts are now available for multiple years (2010, 2013, + 2019, and 2023). + * Added option ``solving: curtailment_mode``` which fixes the dispatch profiles of generators with time-varying p_max_pu by setting ``p_min_pu = p_max_pu`` and adds an auxiliary curtailment generator with negative sign (to absorb diff --git a/rules/retrieve.smk b/rules/retrieve.smk index 71b005ac..18b0ddd2 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -71,7 +71,7 @@ if config["enable"]["retrieve"] and config["enable"].get("retrieve_cutout", True rule retrieve_cutout: input: storage( - "https://zenodo.org/records/6382570/files/{cutout}.nc", + "https://zenodo.org/records/12791128/files/{cutout}.nc", ), output: protected("cutouts/" + CDIR + "{cutout}.nc"), diff --git a/scripts/build_cutout.py b/scripts/build_cutout.py index 1edb18ce..e8d6207c 100644 --- a/scripts/build_cutout.py +++ b/scripts/build_cutout.py @@ -103,7 +103,7 @@ if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake - snakemake = mock_snakemake("build_cutout", cutout="europe-2013-era5") + snakemake = mock_snakemake("build_cutout", cutout="europe-2013-sarah3-era5") configure_logging(snakemake) set_scenario_config(snakemake) From eab315291e502365db01e3058bd7487af2a0c48f Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 24 Jul 2024 13:19:57 +0200 Subject: [PATCH 03/10] remove {scope} wildcard (#1171) * remove {scope} wildcard * do not create removed files --- doc/release_notes.rst | 2 + doc/wildcards.rst | 7 ---- rules/build_sector.smk | 60 ++++++++------------------- scripts/build_cop_profiles.py | 19 +++------ scripts/build_hourly_heat_demand.py | 4 +- scripts/build_temperature_profiles.py | 6 +-- 6 files changed, 29 insertions(+), 69 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index b6c0db54..0aa97e5a 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -39,6 +39,8 @@ Upcoming Release * Bugfix: Impose minimum value of zero for district heating progress between current and future market share in :mod:`build_district_heat_share`. +* The ``{scope}`` wildcard was removed, since its outputs were not used. + * Enable parallelism in :mod:`determine_availability_matrix_MD_UA.py` and remove plots. This requires the use of temporary files. * Updated pre-built `weather data cutouts diff --git a/doc/wildcards.rst b/doc/wildcards.rst index f8e60e20..9ddb7b0a 100644 --- a/doc/wildcards.rst +++ b/doc/wildcards.rst @@ -142,13 +142,6 @@ The ``{sector_opts}`` wildcard is only used for sector-coupling studies. :widths: 10,20,10,10 :file: configtables/sector-opts.csv -.. _scope: - -The ``{scope}`` wildcard -======================== - -Takes values ``residential``, ``urban``, ``total``. - .. _planning_horizons: The ``{planning_horizons}`` wildcard diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 6614b163..139ced1f 100644 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -151,18 +151,18 @@ rule build_daily_heat_demand: snapshots=config_provider("snapshots"), drop_leap_day=config_provider("enable", "drop_leap_day"), input: - pop_layout=resources("pop_layout_{scope}.nc"), + pop_layout=resources("pop_layout_total.nc"), regions_onshore=resources("regions_onshore_elec_s{simpl}_{clusters}.geojson"), cutout=heat_demand_cutout, output: - heat_demand=resources("daily_heat_demand_{scope}_elec_s{simpl}_{clusters}.nc"), + heat_demand=resources("daily_heat_demand_total_elec_s{simpl}_{clusters}.nc"), resources: mem_mb=20000, threads: 8 log: - logs("build_daily_heat_demand_{scope}_{simpl}_{clusters}.loc"), + logs("build_daily_heat_demand_total_{simpl}_{clusters}.loc"), benchmark: - benchmarks("build_daily_heat_demand/{scope}_s{simpl}_{clusters}") + benchmarks("build_daily_heat_demand/total_s{simpl}_{clusters}") conda: "../envs/environment.yaml" script: @@ -175,16 +175,16 @@ rule build_hourly_heat_demand: drop_leap_day=config_provider("enable", "drop_leap_day"), input: heat_profile="data/heat_load_profile_BDEW.csv", - heat_demand=resources("daily_heat_demand_{scope}_elec_s{simpl}_{clusters}.nc"), + heat_demand=resources("daily_heat_demand_total_elec_s{simpl}_{clusters}.nc"), output: - heat_demand=resources("hourly_heat_demand_{scope}_elec_s{simpl}_{clusters}.nc"), + heat_demand=resources("hourly_heat_demand_total_elec_s{simpl}_{clusters}.nc"), resources: mem_mb=2000, threads: 8 log: - logs("build_hourly_heat_demand_{scope}_{simpl}_{clusters}.loc"), + logs("build_hourly_heat_demand_total_{simpl}_{clusters}.loc"), benchmark: - benchmarks("build_hourly_heat_demand/{scope}_s{simpl}_{clusters}") + benchmarks("build_hourly_heat_demand/total_s{simpl}_{clusters}") conda: "../envs/environment.yaml" script: @@ -196,19 +196,19 @@ rule build_temperature_profiles: snapshots=config_provider("snapshots"), drop_leap_day=config_provider("enable", "drop_leap_day"), input: - pop_layout=resources("pop_layout_{scope}.nc"), + pop_layout=resources("pop_layout_total.nc"), regions_onshore=resources("regions_onshore_elec_s{simpl}_{clusters}.geojson"), cutout=heat_demand_cutout, output: - temp_soil=resources("temp_soil_{scope}_elec_s{simpl}_{clusters}.nc"), - temp_air=resources("temp_air_{scope}_elec_s{simpl}_{clusters}.nc"), + temp_soil=resources("temp_soil_total_elec_s{simpl}_{clusters}.nc"), + temp_air=resources("temp_air_total_elec_s{simpl}_{clusters}.nc"), resources: mem_mb=20000, threads: 8 log: - logs("build_temperature_profiles_{scope}_{simpl}_{clusters}.log"), + logs("build_temperature_profiles_total_{simpl}_{clusters}.log"), benchmark: - benchmarks("build_temperature_profiles/{scope}_s{simpl}_{clusters}") + benchmarks("build_temperature_profiles/total_s{simpl}_{clusters}") conda: "../envs/environment.yaml" script: @@ -220,18 +220,10 @@ rule build_cop_profiles: heat_pump_sink_T=config_provider("sector", "heat_pump_sink_T"), input: 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"), temp_air_total=resources("temp_air_total_elec_s{simpl}_{clusters}.nc"), - temp_air_rural=resources("temp_air_rural_elec_s{simpl}_{clusters}.nc"), - temp_air_urban=resources("temp_air_urban_elec_s{simpl}_{clusters}.nc"), output: cop_soil_total=resources("cop_soil_total_elec_s{simpl}_{clusters}.nc"), - cop_soil_rural=resources("cop_soil_rural_elec_s{simpl}_{clusters}.nc"), - cop_soil_urban=resources("cop_soil_urban_elec_s{simpl}_{clusters}.nc"), cop_air_total=resources("cop_air_total_elec_s{simpl}_{clusters}.nc"), - cop_air_rural=resources("cop_air_rural_elec_s{simpl}_{clusters}.nc"), - cop_air_urban=resources("cop_air_urban_elec_s{simpl}_{clusters}.nc"), resources: mem_mb=20000, log: @@ -263,18 +255,18 @@ rule build_solar_thermal_profiles: drop_leap_day=config_provider("enable", "drop_leap_day"), solar_thermal=config_provider("solar_thermal"), input: - pop_layout=resources("pop_layout_{scope}.nc"), + pop_layout=resources("pop_layout_total.nc"), regions_onshore=resources("regions_onshore_elec_s{simpl}_{clusters}.geojson"), cutout=solar_thermal_cutout, output: - solar_thermal=resources("solar_thermal_{scope}_elec_s{simpl}_{clusters}.nc"), + solar_thermal=resources("solar_thermal_total_elec_s{simpl}_{clusters}.nc"), resources: mem_mb=20000, threads: 16 log: - logs("build_solar_thermal_profiles_{scope}_s{simpl}_{clusters}.log"), + logs("build_solar_thermal_profiles_total_s{simpl}_{clusters}.log"), benchmark: - benchmarks("build_solar_thermal_profiles/{scope}_s{simpl}_{clusters}") + benchmarks("build_solar_thermal_profiles/total_s{simpl}_{clusters}") conda: "../envs/environment.yaml" script: @@ -1024,32 +1016,14 @@ rule prepare_sector_network: "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"), temp_air_total=resources("temp_air_total_elec_s{simpl}_{clusters}.nc"), - temp_air_rural=resources("temp_air_rural_elec_s{simpl}_{clusters}.nc"), - temp_air_urban=resources("temp_air_urban_elec_s{simpl}_{clusters}.nc"), cop_soil_total=resources("cop_soil_total_elec_s{simpl}_{clusters}.nc"), - cop_soil_rural=resources("cop_soil_rural_elec_s{simpl}_{clusters}.nc"), - cop_soil_urban=resources("cop_soil_urban_elec_s{simpl}_{clusters}.nc"), cop_air_total=resources("cop_air_total_elec_s{simpl}_{clusters}.nc"), - cop_air_rural=resources("cop_air_rural_elec_s{simpl}_{clusters}.nc"), - cop_air_urban=resources("cop_air_urban_elec_s{simpl}_{clusters}.nc"), solar_thermal_total=lambda w: ( resources("solar_thermal_total_elec_s{simpl}_{clusters}.nc") if config_provider("sector", "solar_thermal")(w) else [] ), - solar_thermal_urban=lambda w: ( - resources("solar_thermal_urban_elec_s{simpl}_{clusters}.nc") - if config_provider("sector", "solar_thermal")(w) - else [] - ), - solar_thermal_rural=lambda w: ( - resources("solar_thermal_rural_elec_s{simpl}_{clusters}.nc") - if config_provider("sector", "solar_thermal")(w) - else [] - ), egs_potentials=lambda w: ( resources("egs_potentials_s{simpl}_{clusters}.csv") if config_provider("sector", "enhanced_geothermal", "enable")(w) diff --git a/scripts/build_cop_profiles.py b/scripts/build_cop_profiles.py index 2a47198b..a6d99947 100644 --- a/scripts/build_cop_profiles.py +++ b/scripts/build_cop_profiles.py @@ -21,20 +21,12 @@ Relevant Settings Inputs: ------- - ``resources//temp_soil_total_elec_s_.nc``: Soil temperature (total) time series. -- ``resources//temp_soil_rural_elec_s_.nc``: Soil temperature (rural) time series. -- ``resources//temp_soil_urban_elec_s_.nc``: Soil temperature (urban) time series. - ``resources//temp_air_total_elec_s_.nc``: Ambient air temperature (total) time series. -- ``resources//temp_air_rural_elec_s_.nc``: Ambient air temperature (rural) time series. -- ``resources//temp_air_urban_elec_s_.nc``: Ambient air temperature (urban) time series. Outputs: -------- - ``resources/cop_soil_total_elec_s_.nc``: COP (ground-sourced) time series (total). -- ``resources/cop_soil_rural_elec_s_.nc``: COP (ground-sourced) time series (rural). -- ``resources/cop_soil_urban_elec_s_.nc``: COP (ground-sourced) time series (urban). - ``resources/cop_air_total_elec_s_.nc``: COP (air-sourced) time series (total). -- ``resources/cop_air_rural_elec_s_.nc``: COP (air-sourced) time series (rural). -- ``resources/cop_air_urban_elec_s_.nc``: COP (air-sourced) time series (urban). References @@ -67,12 +59,11 @@ if __name__ == "__main__": set_scenario_config(snakemake) - for area in ["total", "urban", "rural"]: - for source in ["air", "soil"]: - source_T = xr.open_dataarray(snakemake.input[f"temp_{source}_{area}"]) + for source in ["air", "soil"]: + source_T = xr.open_dataarray(snakemake.input[f"temp_{source}_total"]) - delta_T = snakemake.params.heat_pump_sink_T - source_T + delta_T = snakemake.params.heat_pump_sink_T - source_T - cop = coefficient_of_performance(delta_T, source) + cop = coefficient_of_performance(delta_T, source) - cop.to_netcdf(snakemake.output[f"cop_{source}_{area}"]) + cop.to_netcdf(snakemake.output[f"cop_{source}_total"]) diff --git a/scripts/build_hourly_heat_demand.py b/scripts/build_hourly_heat_demand.py index c28860f3..8573a198 100644 --- a/scripts/build_hourly_heat_demand.py +++ b/scripts/build_hourly_heat_demand.py @@ -22,12 +22,12 @@ Inputs ------ - ``data/heat_load_profile_BDEW.csv``: Intraday heat profile for water and space heating demand for the residential and services sectors for weekends and weekdays. -- ``resources/daily_heat_demand__elec_s_.nc``: Daily heat demand per cluster. +- ``resources/daily_heat_demand_total_elec_s_.nc``: Daily heat demand per cluster. Outputs ------- -- ``resources/hourly_heat_demand__elec_s_.nc``: +- ``resources/hourly_heat_demand_total_elec_s_.nc``: """ from itertools import product diff --git a/scripts/build_temperature_profiles.py b/scripts/build_temperature_profiles.py index 493bd08f..8e07ee87 100644 --- a/scripts/build_temperature_profiles.py +++ b/scripts/build_temperature_profiles.py @@ -25,15 +25,15 @@ Relevant Settings Inputs ------ -- ``resources//pop_layout_.nc``: +- ``resources//pop_layout_total.nc``: - ``resources//regions_onshore_elec_s_.geojson``: - ``cutout``: Weather data cutout, as specified in config Outputs ------- -- ``resources/temp_soil__elec_s_.nc``: -- ``resources/temp_air__elec_s_.nc` +- ``resources/temp_soil_total_elec_s_.nc``: +- ``resources/temp_air_total_elec_s_.nc` """ import atlite From 0470f119cf34cc0b3d1cc17559a0f719f6b0e1ee Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 24 Jul 2024 15:31:46 +0200 Subject: [PATCH 04/10] base_network: use GeoSeries.voronoi_polygons instead of custom solution (#1172) * base_network: use GeoSeries.voronoi_polygons instead of custom solution * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * base_network: move voronoi calculations into separate function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * base_network: fix typo in function voronoi() * base_network: refine voronoi function * add release note [no ci] --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- doc/release_notes.rst | 3 ++ scripts/base_network.py | 80 ++++++++++++----------------------------- 2 files changed, 26 insertions(+), 57 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index 0aa97e5a..fa0473fc 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -55,6 +55,9 @@ Upcoming Release excess power) at every AC bus. This can speed up the solving process as the curtailment decision is aggregated into a single generator per region. +* In :mod:`base_network`, replace own voronoi polygon calculation function with + Geopandas `gdf.voronoi_polygons` method. + PyPSA-Eur 0.11.0 (25th May 2024) ===================================== diff --git a/scripts/base_network.py b/scripts/base_network.py index f87d666b..118e7dba 100644 --- a/scripts/base_network.py +++ b/scripts/base_network.py @@ -72,6 +72,7 @@ Creates the network topology from an ENTSO-E map extract, and create Voronoi sha """ import logging +import warnings from itertools import product import geopandas as gpd @@ -85,9 +86,9 @@ import shapely.wkt import yaml from _helpers import REGION_COLS, configure_logging, get_snapshots, set_scenario_config from packaging.version import Version, parse -from scipy import spatial from scipy.sparse import csgraph -from shapely.geometry import LineString, Point, Polygon +from scipy.spatial import KDTree +from shapely.geometry import LineString, Point PD_GE_2_2 = parse(pd.__version__) >= Version("2.2") @@ -118,7 +119,7 @@ def _find_closest_links(links, new_links, distance_upper_bound=1.5): querycoords = np.vstack( [new_links[["x1", "y1", "x2", "y2"]], new_links[["x2", "y2", "x1", "y1"]]] ) - tree = spatial.KDTree(treecoords) + tree = KDTree(treecoords) dist, ind = tree.query(querycoords, distance_upper_bound=distance_upper_bound) found_b = ind < len(links) found_i = np.arange(len(new_links) * 2)[found_b] % len(new_links) @@ -273,7 +274,7 @@ def _add_links_from_tyndp(buses, links, links_tyndp, europe_shape): return buses, links tree_buses = buses.query("carrier=='AC'") - tree = spatial.KDTree(tree_buses[["x", "y"]]) + tree = KDTree(tree_buses[["x", "y"]]) _, ind0 = tree.query(links_tyndp[["x1", "y1"]]) ind0_b = ind0 < len(tree_buses) links_tyndp.loc[ind0_b, "bus0"] = tree_buses.index[ind0[ind0_b]] @@ -788,59 +789,26 @@ def base_network( return n -def voronoi_partition_pts(points, outline): +def voronoi(points, outline, crs=4326): """ - Compute the polygons of a voronoi partition of `points` within the polygon - `outline`. Taken from - https://github.com/FRESNA/vresutils/blob/master/vresutils/graph.py. - - Attributes - ---------- - points : Nx2 - ndarray[dtype=float] - outline : Polygon - Returns - ------- - polygons : N - ndarray[dtype=Polygon|MultiPolygon] + Create Voronoi polygons from a set of points within an outline. """ - points = np.asarray(points) + pts = gpd.GeoSeries( + gpd.points_from_xy(points.x, points.y), + index=points.index, + crs=crs, + ) + voronoi = pts.voronoi_polygons(extend_to=outline).clip(outline) - if len(points) == 1: - polygons = [outline] - else: - xmin, ymin = np.amin(points, axis=0) - xmax, ymax = np.amax(points, axis=0) - xspan = xmax - xmin - yspan = ymax - ymin + # can be removed with shapely 2.1 where order is preserved + # https://github.com/shapely/shapely/issues/2020 + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=UserWarning) + pts = gpd.GeoDataFrame(geometry=pts) + voronoi = gpd.GeoDataFrame(geometry=voronoi) + joined = gpd.sjoin_nearest(pts, voronoi, how="right") - # to avoid any network positions outside all Voronoi cells, append - # the corners of a rectangle framing these points - vor = spatial.Voronoi( - np.vstack( - ( - points, - [ - [xmin - 3.0 * xspan, ymin - 3.0 * yspan], - [xmin - 3.0 * xspan, ymax + 3.0 * yspan], - [xmax + 3.0 * xspan, ymin - 3.0 * yspan], - [xmax + 3.0 * xspan, ymax + 3.0 * yspan], - ], - ) - ) - ) - - polygons = [] - for i in range(len(points)): - poly = Polygon(vor.vertices[vor.regions[vor.point_region[i]]]) - - if not poly.is_valid: - poly = poly.buffer(0) - - with np.errstate(invalid="ignore"): - poly = poly.intersection(outline) - - polygons.append(poly) - - return polygons + return joined.dissolve(by="Bus").squeeze() def build_bus_shapes(n, country_shapes, offshore_shapes, countries): @@ -870,9 +838,7 @@ def build_bus_shapes(n, country_shapes, offshore_shapes, countries): "name": onshore_locs.index, "x": onshore_locs["x"], "y": onshore_locs["y"], - "geometry": voronoi_partition_pts( - onshore_locs.values, onshore_shape - ), + "geometry": voronoi(onshore_locs, onshore_shape), "country": country, }, crs=n.crs, @@ -888,7 +854,7 @@ def build_bus_shapes(n, country_shapes, offshore_shapes, countries): "name": offshore_locs.index, "x": offshore_locs["x"], "y": offshore_locs["y"], - "geometry": voronoi_partition_pts(offshore_locs.values, offshore_shape), + "geometry": voronoi(offshore_locs, offshore_shape), "country": country, }, crs=n.crs, From 9b7831974fdefa5b89ab54bf2a537d192129bdc7 Mon Sep 17 00:00:00 2001 From: toniseibold Date: Mon, 15 Jul 2024 13:12:04 +0200 Subject: [PATCH 05/10] excluding emissions from sector ratios development [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci just changing the fillna function makes the whole PR cleaner --- scripts/build_industry_sector_ratios_intermediate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/build_industry_sector_ratios_intermediate.py b/scripts/build_industry_sector_ratios_intermediate.py index 5fe042ab..ebbabdb2 100644 --- a/scripts/build_industry_sector_ratios_intermediate.py +++ b/scripts/build_industry_sector_ratios_intermediate.py @@ -129,11 +129,12 @@ def build_industry_sector_ratios_intermediate(): ] today_sector_ratios_ct.loc[:, ~missing_mask] = today_sector_ratios_ct.loc[ :, ~missing_mask - ].fillna(0) + ].fillna(future_sector_ratios) intermediate_sector_ratios[ct] = ( today_sector_ratios_ct * (1 - fraction_future) + future_sector_ratios * fraction_future ) + intermediate_sector_ratios = pd.concat(intermediate_sector_ratios, axis=1) intermediate_sector_ratios.to_csv(snakemake.output.industry_sector_ratios) From 23ea16dc1401f8ac006bf658e6c5ddaec14cea9c Mon Sep 17 00:00:00 2001 From: Toni Seibold <153275395+toniseibold@users.noreply.github.com> Date: Mon, 29 Jul 2024 09:47:08 +0200 Subject: [PATCH 06/10] Lifetime of Gas Pipelines (#1162) * inf lifetime of gas pipelines avoids adding new links each planning horizon * p_nom_extendable for existing gas pipelines is set false if retrofitting to H2 is not allowed * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- scripts/add_brownfield.py | 8 -------- scripts/prepare_sector_network.py | 6 ++++-- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index 672f9e62..72dd1c88 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -89,10 +89,6 @@ def add_brownfield(n, n_p, year): # deal with gas network pipe_carrier = ["gas pipeline"] if snakemake.params.H2_retrofit: - # drop capacities of previous year to avoid duplicating - to_drop = n.links.carrier.isin(pipe_carrier) & (n.links.build_year != year) - n.mremove("Link", n.links.loc[to_drop].index) - # subtract the already retrofitted from today's gas grid capacity h2_retrofitted_fixed_i = n.links[ (n.links.carrier == "H2 pipeline retrofitted") @@ -115,10 +111,6 @@ def add_brownfield(n, n_p, year): index=pipe_capacity.index ).fillna(0) n.links.loc[gas_pipes_i, "p_nom"] = remaining_capacity - else: - new_pipes = n.links.carrier.isin(pipe_carrier) & (n.links.build_year == year) - n.links.loc[new_pipes, "p_nom"] = 0.0 - n.links.loc[new_pipes, "p_nom_min"] = 0.0 def disable_grid_expansion_if_limit_hit(n): diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index b86f9557..970a1a0a 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -1238,12 +1238,14 @@ def add_storage_and_grids(n, costs): gas_pipes["p_nom_min"] = 0.0 # 0.1 EUR/MWkm/a to prefer decommissioning to address degeneracy gas_pipes["capital_cost"] = 0.1 * gas_pipes.length + gas_pipes["p_nom_extendable"] = True else: gas_pipes["p_nom_max"] = np.inf gas_pipes["p_nom_min"] = gas_pipes.p_nom gas_pipes["capital_cost"] = ( gas_pipes.length * costs.at["CH4 (g) pipeline", "fixed"] ) + gas_pipes["p_nom_extendable"] = False n.madd( "Link", @@ -1252,14 +1254,14 @@ def add_storage_and_grids(n, costs): bus1=gas_pipes.bus1 + " gas", p_min_pu=gas_pipes.p_min_pu, p_nom=gas_pipes.p_nom, - p_nom_extendable=True, + p_nom_extendable=gas_pipes.p_nom_extendable, p_nom_max=gas_pipes.p_nom_max, p_nom_min=gas_pipes.p_nom_min, length=gas_pipes.length, capital_cost=gas_pipes.capital_cost, tags=gas_pipes.name, carrier="gas pipeline", - lifetime=costs.at["CH4 (g) pipeline", "lifetime"], + lifetime=np.inf, ) # remove fossil generators where there is neither From f5fe0d062c136c86c92717f9fc311c76786972de Mon Sep 17 00:00:00 2001 From: Micha Date: Mon, 29 Jul 2024 09:50:02 +0200 Subject: [PATCH 07/10] Rename ev battery master (#1116) * rename EV battery * add release note * adjust tech colors * fix for battery renaming in plot_summary --------- Co-authored-by: Fabian Neumann --- config/config.default.yaml | 2 +- doc/release_notes.rst | 2 ++ scripts/prepare_perfect_foresight.py | 2 +- scripts/prepare_sector_network.py | 8 ++++---- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/config/config.default.yaml b/config/config.default.yaml index 4641837e..f1ab5f31 100644 --- a/config/config.default.yaml +++ b/config/config.default.yaml @@ -1054,7 +1054,7 @@ plotting: V2G: '#e5ffa8' land transport EV: '#baf238' land transport demand: '#38baf2' - Li ion: '#baf238' + EV battery: '#baf238' # hot water storage water tanks: '#e69487' residential rural water tanks: '#f7b7a3' diff --git a/doc/release_notes.rst b/doc/release_notes.rst index fa0473fc..383287a6 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -10,6 +10,8 @@ Release Notes Upcoming Release ================ +* Renamed the carrier of batteries in BEVs from `battery storage` to `EV battery` and the corresponding bus carrier from `Li ion` to `EV battery`. This is to avoid confusion with stationary battery storage. + * Changed default assumptions about waste heat usage from PtX and fuel cells in district heating. The default value for the link efficiency scaling factor was changed from 100% to 25%. It can be set to other values in the configuration ``sector: use_TECHNOLOGY_waste_heat``. diff --git a/scripts/prepare_perfect_foresight.py b/scripts/prepare_perfect_foresight.py index c5e4caf9..efc95700 100644 --- a/scripts/prepare_perfect_foresight.py +++ b/scripts/prepare_perfect_foresight.py @@ -250,7 +250,7 @@ def adjust_stores(n): n.stores.loc[cyclic_i, "e_cyclic_per_period"] = True n.stores.loc[cyclic_i, "e_cyclic"] = False # non cyclic store assumptions - non_cyclic_store = ["co2", "co2 stored", "solid biomass", "biogas", "Li ion"] + non_cyclic_store = ["co2", "co2 stored", "solid biomass", "biogas", "EV battery"] co2_i = n.stores[n.stores.carrier.isin(non_cyclic_store)].index n.stores.loc[co2_i, "e_cyclic_per_period"] = False n.stores.loc[co2_i, "e_cyclic"] = False diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 970a1a0a..eaaf207d 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -1543,14 +1543,14 @@ def add_EVs( temperature, ): - n.add("Carrier", "Li ion") + n.add("Carrier", "EV battery") n.madd( "Bus", spatial.nodes, suffix=" EV battery", location=spatial.nodes, - carrier="Li ion", + carrier="EV battery", unit="MWh_el", ) @@ -1623,9 +1623,9 @@ def add_EVs( n.madd( "Store", spatial.nodes, - suffix=" battery storage", + suffix=" EV battery", bus=spatial.nodes + " EV battery", - carrier="battery storage", + carrier="EV battery", e_cyclic=True, e_nom=e_nom, e_max_pu=1, From 936b4903039873ceb2e7caeb1b61873096738427 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 29 Jul 2024 11:51:20 +0200 Subject: [PATCH 08/10] address groupby(axis=...) deprecation (#1182) --- scripts/build_retro_cost.py | 2 +- scripts/plot_validation_electricity_production.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build_retro_cost.py b/scripts/build_retro_cost.py index 52f545e9..44f4a738 100755 --- a/scripts/build_retro_cost.py +++ b/scripts/build_retro_cost.py @@ -890,7 +890,7 @@ def calculate_gain_utilisation_factor(heat_transfer_perm2, Q_ht, Q_gain): Calculates gain utilisation factor nu. """ # time constant of the building tau [h] = c_m [Wh/(m^2K)] * 1 /(H_tr_e+H_tb*H_ve) [m^2 K /W] - tau = c_m / heat_transfer_perm2.T.groupby(axis=1).sum().T + tau = c_m / heat_transfer_perm2.groupby().sum() alpha = alpha_H_0 + (tau / tau_H_0) # heat balance ratio gamma = (1 / Q_ht).mul(Q_gain.sum(axis=1), axis=0) diff --git a/scripts/plot_validation_electricity_production.py b/scripts/plot_validation_electricity_production.py index 5a68cfa5..f842bea3 100644 --- a/scripts/plot_validation_electricity_production.py +++ b/scripts/plot_validation_electricity_production.py @@ -70,7 +70,7 @@ if __name__ == "__main__": optimized = optimized[["Generator", "StorageUnit"]].droplevel(0, axis=1) optimized = optimized.rename(columns=n.buses.country, level=0) optimized = optimized.rename(columns=carrier_groups, level=1) - optimized = optimized.groupby(axis=1, level=[0, 1]).sum() + optimized = optimized.T.groupby(level=[0, 1]).sum().T data = pd.concat([historic, optimized], keys=["Historic", "Optimized"], axis=1) data.columns.names = ["Kind", "Country", "Carrier"] From e9e0a0da2064a242b0d731dc2218de0e6cbca190 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 29 Jul 2024 11:56:14 +0200 Subject: [PATCH 09/10] address fillna(method='{b|f}fill') deprecation (#1181) * address fillne(method='{b|f}fill') deprecation * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- scripts/add_electricity.py | 2 +- scripts/make_summary_perfect.py | 2 +- scripts/prepare_network.py | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/add_electricity.py b/scripts/add_electricity.py index 17e030b4..49510953 100755 --- a/scripts/add_electricity.py +++ b/scripts/add_electricity.py @@ -852,7 +852,7 @@ if __name__ == "__main__": fuel_price = pd.read_csv( snakemake.input.fuel_price, index_col=0, header=0, parse_dates=True ) - fuel_price = fuel_price.reindex(n.snapshots).fillna(method="ffill") + fuel_price = fuel_price.reindex(n.snapshots).ffill() else: fuel_price = None diff --git a/scripts/make_summary_perfect.py b/scripts/make_summary_perfect.py index 76bd4ad0..8e56e5d4 100644 --- a/scripts/make_summary_perfect.py +++ b/scripts/make_summary_perfect.py @@ -631,7 +631,7 @@ def calculate_co2_emissions(n, label, df): weightings = n.snapshot_weightings.generators.mul( n.investment_period_weightings["years"] .reindex(n.snapshots) - .fillna(method="bfill") + .bfill() .fillna(1.0), axis=0, ) diff --git a/scripts/prepare_network.py b/scripts/prepare_network.py index 00cb00bf..382e633d 100755 --- a/scripts/prepare_network.py +++ b/scripts/prepare_network.py @@ -137,9 +137,7 @@ def add_emission_prices(n, emission_prices={"co2": 0.0}, exclude_co2=False): def add_dynamic_emission_prices(n): co2_price = pd.read_csv(snakemake.input.co2_price, index_col=0, parse_dates=True) co2_price = co2_price[~co2_price.index.duplicated()] - co2_price = ( - co2_price.reindex(n.snapshots).fillna(method="ffill").fillna(method="bfill") - ) + co2_price = co2_price.reindex(n.snapshots).ffill().bfill() emissions = ( n.generators.carrier.map(n.carriers.co2_emissions) / n.generators.efficiency From 4c1ec3559dc91ecb1dea4d32d2e593c530a549d2 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 31 Jul 2024 11:53:20 +0200 Subject: [PATCH 10/10] some small adjustments to run as single node model (#1183) * some small adjustments to run as single node model * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- scripts/cluster_gas_network.py | 3 +++ scripts/prepare_sector_network.py | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/cluster_gas_network.py b/scripts/cluster_gas_network.py index 6d4e6c48..b95c4580 100755 --- a/scripts/cluster_gas_network.py +++ b/scripts/cluster_gas_network.py @@ -58,6 +58,9 @@ def build_clustered_gas_network(df, bus_regions, length_factor=1.25): # drop pipes within the same region df = df.loc[df.bus1 != df.bus0] + if df.empty: + return df + # recalculate lengths as center to center * length factor df["length"] = df.apply( lambda p: length_factor diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index eaaf207d..5b28c1b4 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -2775,10 +2775,11 @@ def add_industry(n, costs): ) domestic_navigation = pop_weighted_energy_totals.loc[ - nodes, "total domestic navigation" + nodes, ["total domestic navigation"] ].squeeze() international_navigation = ( - pd.read_csv(snakemake.input.shipping_demand, index_col=0).squeeze() * nyears + pd.read_csv(snakemake.input.shipping_demand, index_col=0).squeeze(axis=1) + * nyears ) all_navigation = domestic_navigation + international_navigation p_set = all_navigation * 1e6 / nhours @@ -3946,12 +3947,11 @@ if __name__ == "__main__": snakemake = mock_snakemake( "prepare_sector_network", - # configfiles="test/config.overnight.yaml", simpl="", opts="", - clusters="37", - ll="v1.0", - sector_opts="730H-T-H-B-I-A-dist1", + clusters="1", + ll="vopt", + sector_opts="", planning_horizons="2050", )