Skip to content

Commit

Permalink
Merge pull request #320 from openego/features/#309-myopic-pypsaeur-el…
Browse files Browse the repository at this point in the history
…ectrical-timeseries

Features/#309 myopic pypsaeur electrical timeseries
  • Loading branch information
ulfmueller authored Sep 23, 2024
2 parents ad65d2f + 8cdfac9 commit 25dfd49
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 50 deletions.
15 changes: 9 additions & 6 deletions src/egon/data/datasets/demandregio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DemandRegio(Dataset):
def __init__(self, dependencies):
super().__init__(
name="DemandRegio",
version="0.0.8",
version="0.0.9",
dependencies=dependencies,
tasks=(
# clone_and_install, demandregio must be previously installed
Expand Down Expand Up @@ -476,6 +476,9 @@ def disagg_households_power(
# calculate demand per nuts3 in 2050
df = data.households_per_size(year=year) * power_per_HH

# scale to meet annual demand from NEP 2023, scenario B 2045
df *= 90400000 / df.sum().sum()

else:
print(
f"Electric demand per household size for scenario {scenario} "
Expand Down Expand Up @@ -633,7 +636,8 @@ def insert_cts_ind(scenario, year, engine, target_values):

if scenario == "eGon100RE":
ec_cts_ind2 = pd.read_csv(
"data_bundle_powerd_data/egon_demandregio_cts_ind.csv")
"data_bundle_powerd_data/egon_demandregio_cts_ind.csv"
)
ec_cts_ind2.to_sql(
targets["cts_ind_demand"]["table"],
engine,
Expand Down Expand Up @@ -752,10 +756,8 @@ def insert_cts_ind_demands():
# according to NEP 2021
# new consumers will be added seperatly
"eGon2035": {"CTS": 135300, "industry": 225400},
# CTS: reduce overall demand from demandregio (without traffic)
# by share of heat according to JRC IDEES, data from 2011
# industry: no specific heat demand, use data from demandregio
"eGon100RE": {"CTS": (1 - (5.96 + 6.13) / 154.64) * 125183.403},
# according to NEP 2023, scenario B 2045
"eGon100RE": {"CTS": 146700, "industry": 382900},
# no adjustments for status quo
"eGon2021": {},
"status2019": {},
Expand Down Expand Up @@ -914,6 +916,7 @@ def timeseries_per_wz():
for sector in ["CTS", "industry"]:
insert_timeseries_per_wz(sector, int(year))


def get_cached_tables():
"""Get cached demandregio tables and db-dump from former runs"""
data_config = egon.data.config.datasets()
Expand Down
133 changes: 89 additions & 44 deletions src/egon/data/datasets/pypsaeur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def download():

# Limit geopandas version
# our pypsa-eur version is not compatible to geopandas>1
#env["dependencies"] = [
# env["dependencies"] = [
# "geopandas>=0.11.0,<1" if x == "geopandas>=0.11.0" else x
# for x in env["dependencies"]
#]
# ]

# Write YAML file
with open(path_to_env, "w", encoding="utf8") as outfile:
Expand Down Expand Up @@ -182,18 +182,10 @@ def download():
/ "ENSPRESO_BIOMASS.xlsx",
)

if not (
filepath
/ "pypsa-eur"
/ "data"
/ "gem"
).exists():
(
filepath
/ "pypsa-eur"
/ "data"
/ "gem"
).mkdir(parents=True, exist_ok=True)
if not (filepath / "pypsa-eur" / "data" / "gem").exists():
(filepath / "pypsa-eur" / "data" / "gem").mkdir(
parents=True, exist_ok=True
)

r = requests.get(
"https://tubcloud.tu-berlin.de/s/LMBJQCsN6Ez5cN2/download/"
Expand All @@ -209,18 +201,10 @@ def download():
) as outfile:
outfile.write(r.content)

if not (
filepath
/ "pypsa-eur"
/ "data"
/ "gem"
).exists():
(
filepath
/ "pypsa-eur"
/ "data"
/ "gem"
).mkdir(parents=True, exist_ok=True)
if not (filepath / "pypsa-eur" / "data" / "gem").exists():
(filepath / "pypsa-eur" / "data" / "gem").mkdir(
parents=True, exist_ok=True
)

r = requests.get(
"https://tubcloud.tu-berlin.de/s/Aqebo3rrQZWKGsG/download/"
Expand Down Expand Up @@ -1368,7 +1352,7 @@ def overwrite_H2_pipeline_share():
)


def update_electrical_timeseries_germany(network):
def update_electrical_timeseries_germany(network, year):
"""Replace electrical demand time series in Germany with data from egon-data
Parameters
Expand All @@ -1387,9 +1371,72 @@ def update_electrical_timeseries_germany(network):
"input-pypsa-eur-sec/electrical_demand_timeseries_DE_eGon100RE.csv"
)

network.loads_t.p_set.loc[:, "DE1 0"] = (
df["residential_and_service"] + df["industry"]
).values
annual_demand = pd.Series(index=[2019, 2037])
annual_demand_industry = pd.Series(index=[2019, 2037])
# Define values from status2019 for interpolation
# Residential and service (in TWh)
annual_demand.loc[2019] = 124.71 + 143.26
# Industry (in TWh)
annual_demand_industry.loc[2019] = 241.925

# Define values from NEP 2023 scenario B 2037 for interpolation
# Residential and service (in TWh)
annual_demand.loc[2037] = 104 + 153.1
# Industry (in TWh)
annual_demand_industry.loc[2037] = 334.0

# Set interpolated demands for years between 2019 and 2045
if year < 2037:
# Calculate annual demands for year by linear interpolating between
# 2019 and 2037
# Done seperatly for industry and residential and service to fit
# to pypsa-eurs structure
annual_rate = (annual_demand.loc[2037] - annual_demand.loc[2019]) / (
2037 - 2019
)
annual_demand_year = annual_demand.loc[2019] + annual_rate * (
year - 2019
)

annual_rate_industry = (
annual_demand_industry.loc[2037] - annual_demand_industry.loc[2019]
) / (2037 - 2019)
annual_demand_year_industry = annual_demand_industry.loc[
2019
] + annual_rate_industry * (year - 2019)

# Scale time series for 100% scenario with the annual demands
# The shape of the curve is taken from the 100% scenario since the
# same weather and calender year is used there
network.loads_t.p_set.loc[:, "DE0 0"] = (
df["residential_and_service"]
/ df["residential_and_service"].sum()
* annual_demand_year
* 1e6
).values

network.loads_t.p_set.loc[:, "DE0 0 industry electricity"] = (
df["industry"]
/ df["industry"].sum()
* annual_demand_year_industry
* 1e6
).values

elif year == 2045:

network.loads_t.p_set.loc[:, "DE0 0"] = df["residential_and_service"]

network.loads_t.p_set.loc[:, "DE0 0 industry electricity"] = df[
"industry"
].values

else:
print(
"Scaling not implemented for years between 2037 and 2045 and beyond."
)
return

network.loads.loc["DE0 0 industry electricity", "p_set"] = 0.0

return network

Expand Down Expand Up @@ -1554,9 +1601,7 @@ def district_heating_shares(network):
)
network.mremove(
"Link",
network.links[
network.links.carrier==""
].index,
network.links[network.links.carrier == ""].index,
)

return network
Expand All @@ -1576,7 +1621,7 @@ def drop_new_gas_pipelines(network):
def drop_fossil_gas(network):
network.mremove(
"Generator",
network.generators[network.generators.carrier == "gas"].index
network.generators[network.generators.carrier == "gas"].index,
)

return network
Expand Down Expand Up @@ -1607,8 +1652,8 @@ def execute():
) as stream:
data_config = yaml.safe_load(stream)

for i in range(0, len(data_config['scenario']['planning_horizons'])):
for i in range(0, len(data_config["scenario"]["planning_horizons"])):

network_path = (
Path(".")
/ "run-pypsa-eur"
Expand All @@ -1631,25 +1676,25 @@ def execute():

network = update_heat_timeseries_germany(network)

network = update_electrical_timeseries_germany(network)
network = update_electrical_timeseries_germany(
network, year=data_config["scenario"]["planning_horizons"][i]
)

network = geothermal_district_heating(network)

network = h2_overground_stores(network)

network = drop_new_gas_pipelines(network)
if data_config['scenario']['planning_horizons'] >= 2045:

if data_config["scenario"]["planning_horizons"][i] >= 2045:

network = drop_biomass(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")

0 comments on commit 25dfd49

Please sign in to comment.