From 03bfc728a95050c5dcfe3d21a4d5995b23256c9f Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 25 Sep 2024 09:53:20 +0200 Subject: [PATCH 01/10] Do not scale heat demand time series in Germany The function is kept in case we want to use it again --- src/egon/data/datasets/pypsaeur/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index a1c2ed2e3..87d7557eb 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1685,7 +1685,6 @@ def execute(): scn_path.loc[year, "functions"] = [ drop_urban_decentral_heat, district_heating_shares, - update_heat_timeseries_germany, update_electrical_timeseries_germany, geothermal_district_heating, h2_overground_stores, @@ -1696,7 +1695,6 @@ def execute(): drop_biomass, drop_urban_decentral_heat, district_heating_shares, - update_heat_timeseries_germany, update_electrical_timeseries_germany, geothermal_district_heating, h2_overground_stores, From a4309f1cd762a1812d69f9dc50e0cde788f2a8a3 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 25 Sep 2024 10:10:25 +0200 Subject: [PATCH 02/10] Combine rural heat and urban decentral heat demands in drop_urban_decentral_heat This allows to not run update_heat_demand_timeseries and adjust_district_heating_share without losing any demands. --- src/egon/data/datasets/pypsaeur/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index 87d7557eb..1b0c4615c 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1564,10 +1564,20 @@ def drop_biomass(network): def drop_urban_decentral_heat(network): - carrier = "urban decentral" + carrier = "urban decentral heat" + # Add urban decentral heat demand to urban central heat demand + for country in network.loads.loc[ + network.loads.carrier==carrier, "bus"].str[:5]: + + network.loads_t.p_set[f"{country} rural heat"] += ( + network.loads_t.p_set[f"{country} {carrier}"] + ) + + # Drop componentents attached to urban decentral heat for c in network.iterate_components(): network.mremove(c.name, c.df[c.df.index.str.contains(carrier)].index) + return network From 2981111da2b6e77facf24a3332ddf1e0709da67c Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 25 Sep 2024 10:40:44 +0200 Subject: [PATCH 03/10] Use static p_set of urban decentral heat if time series are not available --- src/egon/data/datasets/pypsaeur/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index 1b0c4615c..f1bd4a616 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1570,9 +1570,17 @@ def drop_urban_decentral_heat(network): for country in network.loads.loc[ network.loads.carrier==carrier, "bus"].str[:5]: - network.loads_t.p_set[f"{country} rural heat"] += ( - network.loads_t.p_set[f"{country} {carrier}"] - ) + if f"{country} {carrier}" in network.loads_t.p_set.columns: + network.loads_t.p_set[f"{country} rural heat"] += ( + network.loads_t.p_set[f"{country} {carrier}"] + ) + else: + print(f"""No time series available for {country} {carrier}. + Using static p_set.""") + + network.loads_t.p_set[f"{country} rural heat"] += ( + network.loads.loc[f"{country} {carrier}", "p_set"] + ) # Drop componentents attached to urban decentral heat for c in network.iterate_components(): From eb0bcd8e776fe91c86007214c7617d46bddcf0aa Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 25 Sep 2024 10:45:35 +0200 Subject: [PATCH 04/10] Manipulate prenetworks depending on the foresight option If foresight is set to myopic in the pypsa-eur config, the manipulations are applied on all prenetworks on the pathway. If only one overnight scenario is created, the manipulations are only applied to this network --- src/egon/data/datasets/pypsaeur/__init__.py | 164 +++++++++++++------- 1 file changed, 105 insertions(+), 59 deletions(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index f1bd4a616..a22b1066e 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1677,79 +1677,125 @@ def execute(): ) as stream: data_config = yaml.safe_load(stream) - networks = pd.Series() - - for i in range(0, len(data_config["scenario"]["planning_horizons"])): - nc_file = pd.Series( - f"elec_s_{data_config['scenario']['clusters'][0]}" - f"_l{data_config['scenario']['ll'][0]}" - f"_{data_config['scenario']['opts'][0]}" - f"_{data_config['scenario']['sector_opts'][0]}" - f"_{data_config['scenario']['planning_horizons'][i]}.nc" + if data_config["foresight"] == "myopic": + + print("Adjusting scenarios on the myopic pathway...") + + networks = pd.Series() + + for i in range(0, len(data_config["scenario"]["planning_horizons"])): + nc_file = pd.Series( + f"elec_s_{data_config['scenario']['clusters'][0]}" + f"_l{data_config['scenario']['ll'][0]}" + f"_{data_config['scenario']['opts'][0]}" + f"_{data_config['scenario']['sector_opts'][0]}" + f"_{data_config['scenario']['planning_horizons'][i]}.nc" + ) + networks = networks._append(nc_file) + + scn_path = pd.DataFrame( + index=["2025", "2030", "2035", "2045"], + columns=["prenetwork", "functions"], ) - networks = networks._append(nc_file) - scn_path = pd.DataFrame( - index=["2025", "2030", "2035", "2045", "2050"], - columns=["prenetwork", "functions"], - ) + for year in scn_path.index: + scn_path.at[year, "prenetwork"] = networks[ + networks.str.contains(year) + ].values + + for year in ["2025", "2030", "2035"]: + scn_path.loc[year, "functions"] = [ + drop_urban_decentral_heat, + district_heating_shares, + update_electrical_timeseries_germany, + geothermal_district_heating, + h2_overground_stores, + drop_new_gas_pipelines, + ] - for year in scn_path.index: - scn_path.at[year, "prenetwork"] = networks[ - networks.str.contains(year) - ].values + scn_path.loc["2045", "functions"] = [ + drop_biomass, + drop_urban_decentral_heat, + district_heating_shares, + update_electrical_timeseries_germany, + geothermal_district_heating, + h2_overground_stores, + drop_new_gas_pipelines, + drop_fossil_gas, + # rual_heat_technologies, #To be defined + ] - for year in ["2025", "2030", "2035"]: - scn_path.loc[year, "functions"] = [ + scn_path.loc["2050", "functions"] = [ + drop_biomass, drop_urban_decentral_heat, district_heating_shares, + update_heat_timeseries_germany, update_electrical_timeseries_germany, geothermal_district_heating, h2_overground_stores, drop_new_gas_pipelines, + drop_fossil_gas, + rual_heat_technologies, ] - scn_path.loc["2045", "functions"] = [ - drop_biomass, - drop_urban_decentral_heat, - district_heating_shares, - update_electrical_timeseries_germany, - geothermal_district_heating, - h2_overground_stores, - drop_new_gas_pipelines, - drop_fossil_gas, - # rual_heat_technologies, #To be defined - ] + network_path = ( + Path(".") + / "run-pypsa-eur" + / "pypsa-eur" + / "results" + / data_config["run"]["name"] + / "prenetworks" + ) - scn_path.loc["2050", "functions"] = [ - drop_biomass, - drop_urban_decentral_heat, - district_heating_shares, - update_heat_timeseries_germany, - update_electrical_timeseries_germany, - geothermal_district_heating, - h2_overground_stores, - drop_new_gas_pipelines, - drop_fossil_gas, - rual_heat_technologies, - ] + for scn in scn_path.index: + path = network_path / scn_path.at[scn, "prenetwork"] + network = pypsa.Network(path) + network.year = int(scn) + for manipulator in scn_path.at[scn, "functions"]: + network = manipulator(network) + network.export_to_netcdf(path) - network_path = ( - Path(".") - / "run-pypsa-eur" - / "pypsa-eur" - / "results" - / data_config["run"]["name"] - / "prenetworks" - ) - - for scn in scn_path.index: - path = network_path / scn_path.at[scn, "prenetwork"] - network = pypsa.Network(path) - network.year = int(scn) - for manipulator in scn_path.at[scn, "functions"]: - network = manipulator(network) - network.export_to_netcdf(path) + else: + + print("Adjusting overnight scenario...") + + network_path = ( + Path(".") + / "run-pypsa-eur" + / "pypsa-eur" + / "results" + / data_config["run"]["name"] + / "prenetworks" + / f"elec_s_{data_config['scenario']['clusters'][0]}" + f"_l{data_config['scenario']['ll'][0]}" + f"_{data_config['scenario']['opts'][0]}" + f"_{data_config['scenario']['sector_opts'][0]}" + f"_{data_config['scenario']['planning_horizons'][0]}.nc" + ) + + network = pypsa.Network(network_path) + + network = drop_biomass(network) + + network = drop_urban_decentral_heat(network) + + network = district_heating_shares(network) + + network = update_heat_timeseries_germany(network) + + network = update_electrical_timeseries_germany(network) + + network = geothermal_district_heating(network) + + network = h2_overground_stores(network) + + network = drop_new_gas_pipelines(network) + + network = drop_fossil_gas(network) + + network = rual_heat_technologies(network) + + network.export_to_netcdf(network_path) else: print("Pypsa-eur is not executed due to the settings of egon-data") From 32930ddad434063d97efac09b896af814c2aef99 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 25 Sep 2024 10:47:32 +0200 Subject: [PATCH 05/10] Do not adjust district heating shares from pypsa-eur The function is kept in case we want to apply it again. --- src/egon/data/datasets/pypsaeur/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index a22b1066e..f24c139fb 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1706,7 +1706,6 @@ def execute(): for year in ["2025", "2030", "2035"]: scn_path.loc[year, "functions"] = [ drop_urban_decentral_heat, - district_heating_shares, update_electrical_timeseries_germany, geothermal_district_heating, h2_overground_stores, @@ -1716,7 +1715,6 @@ def execute(): scn_path.loc["2045", "functions"] = [ drop_biomass, drop_urban_decentral_heat, - district_heating_shares, update_electrical_timeseries_germany, geothermal_district_heating, h2_overground_stores, From cc6aedb0009042ad3d90425f051f10533971ae21 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 25 Sep 2024 10:49:02 +0200 Subject: [PATCH 06/10] Remove the year 2050 from the pathway It is not created with pypsa-eur and therefore creates problems. --- src/egon/data/datasets/pypsaeur/__init__.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index f24c139fb..77252efc3 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1723,19 +1723,6 @@ def execute(): # rual_heat_technologies, #To be defined ] - scn_path.loc["2050", "functions"] = [ - drop_biomass, - drop_urban_decentral_heat, - district_heating_shares, - update_heat_timeseries_germany, - update_electrical_timeseries_germany, - geothermal_district_heating, - h2_overground_stores, - drop_new_gas_pipelines, - drop_fossil_gas, - rual_heat_technologies, - ] - network_path = ( Path(".") / "run-pypsa-eur" From 176e9671e20a079718d273587abf7ec5dad320a8 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 25 Sep 2024 10:51:19 +0200 Subject: [PATCH 07/10] Use correct name for urban central heat bus in Germany --- src/egon/data/datasets/pypsaeur/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index 77252efc3..40cc67c33 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1478,8 +1478,8 @@ def geothermal_district_heating(network): network.add( "Generator", - f"DE1 0 urban central geo thermal {i}", - bus="DE1 0 urban central heat", + f"DE0 0 urban central geo thermal {i}", + bus="DE0 0 urban central heat", carrier="urban central geo thermal", p_nom_extendable=True, p_nom_max=row["potential [MW]"], From cdc2d80368159d3b3fe77ffc3aedac12392d2452 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 25 Sep 2024 14:44:48 +0200 Subject: [PATCH 08/10] Run prevoius adjustment explicitly only for overnight calculation for years beyond 2040. --- src/egon/data/datasets/pypsaeur/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index 40cc67c33..6c8dd277b 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1740,7 +1740,8 @@ def execute(): network = manipulator(network) network.export_to_netcdf(path) - else: + elif ((data_config["foresight"] == "overnight") + & (int(data_config['scenario']['planning_horizons'][0]) > 2040)): print("Adjusting overnight scenario...") @@ -1782,5 +1783,14 @@ def execute(): network.export_to_netcdf(network_path) + else: + print( + f"""Adjustments on prenetworks are not implemented for + foresight option {data_config['foresight']} and + year int(data_config['scenario']['planning_horizons'][0]. + Please check the pypsaeur.execute function. + """ + ) + else: print("Pypsa-eur is not executed due to the settings of egon-data") From 3c87c2adbc539e730f2183e4e258fe5c00830ad5 Mon Sep 17 00:00:00 2001 From: ClaraBuettner Date: Wed, 25 Sep 2024 14:48:03 +0200 Subject: [PATCH 09/10] Fix carrier name --- src/egon/data/datasets/pypsaeur/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index 6c8dd277b..874c0d363 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1584,7 +1584,7 @@ def drop_urban_decentral_heat(network): # Drop componentents attached to urban decentral heat for c in network.iterate_components(): - network.mremove(c.name, c.df[c.df.index.str.contains(carrier)].index) + network.mremove(c.name, c.df[c.df.index.str.contains("urban decentral")].index) return network From aee228efec62f1c367d69f3fd0cf65c0d617a75a Mon Sep 17 00:00:00 2001 From: ulfmueller Date: Wed, 25 Sep 2024 14:57:25 +0200 Subject: [PATCH 10/10] Update __init__.py --- src/egon/data/datasets/pypsaeur/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egon/data/datasets/pypsaeur/__init__.py b/src/egon/data/datasets/pypsaeur/__init__.py index 874c0d363..41094f9f4 100755 --- a/src/egon/data/datasets/pypsaeur/__init__.py +++ b/src/egon/data/datasets/pypsaeur/__init__.py @@ -1743,7 +1743,7 @@ def execute(): elif ((data_config["foresight"] == "overnight") & (int(data_config['scenario']['planning_horizons'][0]) > 2040)): - print("Adjusting overnight scenario...") + print("Adjusting overnight long-term scenario...") network_path = ( Path(".")