Skip to content

Commit

Permalink
Merge pull request #782 from openego/fixes/#781-fix-heat-demand-time-…
Browse files Browse the repository at this point in the history
…series

Fixes/#781 fix heat demand time series
  • Loading branch information
ClaraBuettner committed Jul 28, 2022
2 parents 303730c + 4448641 commit 1a0b1e8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,8 @@ Bug Fixes
`#776 <https://github.com/openego/eGon-data/issues/776>`_
* Fix model load timeseries in motorized individual travel
`#830 <https://github.com/openego/eGon-data/issues/830>`_
* Fix final demand of heat demand timeseries
`#781 <https://github.com/openego/eGon-data/issues/781>`_

.. _PR #692: https://github.com/openego/eGon-data/pull/692
.. _#343: https://github.com/openego/eGon-data/issues/343
Expand Down
93 changes: 76 additions & 17 deletions src/egon/data/datasets/heat_demand_timeseries/HTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,14 +999,14 @@ def profile_generator(aggregation_level):
heat_profile_dist : pandas.DataFrame
if aggreation_level = 'district'
heat profiles for every distric heating id
normalized heat profiles for every distric heating id
else
0
heat_profile_idp : pandas.DataFrame
if aggreation_level = 'district'
heat profiles for every mv grid bus_id
normalized heat profiles for every mv grid bus_id
else
heat profiles for every zensus_poppulation_id
normalized heat profiles for every zensus_poppulation_id
"""

annual_demand, idp_df, selected_profiles = profile_selector()
Expand Down Expand Up @@ -1077,6 +1077,7 @@ def profile_generator(aggregation_level):
right_on=mv_grid_ind.index,
how="inner",
)

heat_profile_idp.sort_values("bus_id", inplace=True)
heat_profile_idp.set_index("bus_id", inplace=True)
heat_profile_idp.drop("key_0", axis=1, inplace=True)
Expand Down Expand Up @@ -1160,28 +1161,34 @@ def residential_demand_scale(aggregation_level):
h = h_value()
h = h.reset_index(drop=True)

district_heating = psycop_df_AF(
"demand.egon_map_zensus_district_heating_areas"
)

district_heating = district_heating.pivot_table(
values="area_id", index="zensus_population_id", columns="scenario"
)

mv_grid = psycop_df_AF("boundaries.egon_map_zensus_grid_districts")

mv_grid_ind = mv_grid.loc[
mv_grid.index.difference(district_heating.index), :
]
mv_grid_ind = mv_grid_ind.reset_index()

scenarios = ["eGon2035", "eGon100RE"]

residential_dist_profile = pd.DataFrame()
residential_individual_profile = pd.DataFrame()
residential_zensus_profile = pd.DataFrame()

for scenario in scenarios:

district_heating = db.select_dataframe(
f"""
SELECT * FROM
demand.egon_map_zensus_district_heating_areas
WHERE scenario = '{scenario}'
"""
)

district_heating = district_heating.pivot_table(
values="area_id", index="zensus_population_id", columns="scenario"
)

mv_grid_ind = mv_grid[
~mv_grid.zensus_population_id.isin(district_heating.index)
]

mv_grid_ind = mv_grid_ind.reset_index()

if aggregation_level == "district":

scenario_ids = district_heating[scenario]
Expand Down Expand Up @@ -1265,6 +1272,7 @@ def residential_demand_scale(aggregation_level):
heat_demand_profile_dist
)

# Individual supplied heat demand time series
district_grid = pd.merge(
mv_grid_ind[["bus_id", "zensus_population_id"]],
annual_demand[["zensus_population_id", "Station", scenario]],
Expand Down Expand Up @@ -1797,10 +1805,60 @@ def demand_profile_generator(aggregation_level="district"):
residential_demand_zensus,
) = residential_demand_scale(aggregation_level)

# Compare with target value
target = db.select_dataframe(
"""
SELECT scenario, SUM(demand) as demand
FROM demand.egon_peta_heat
WHERE sector = 'residential'
GROUP BY (scenario)
""",
index_col="scenario",
)

check_residential = (
(
residential_demand_dist.groupby("scenario").sum().sum(axis=1)
+ residential_demand_grid.groupby("scenario").sum().sum(axis=1)
)
- target.demand
) / target.demand

assert (
check_residential.abs().max() < 0.01
), f"""Unexpected deviation between target value and distributed
residential heat demand: {check_residential}
"""

CTS_demand_dist, CTS_demand_grid, CTS_demand_zensus = CTS_demand_scale(
aggregation_level
)

# Compare with target value
target_cts = db.select_dataframe(
"""
SELECT scenario, SUM(demand) as demand
FROM demand.egon_peta_heat
WHERE sector = 'service'
GROUP BY (scenario)
""",
index_col="scenario",
)

check_cts = (
(
CTS_demand_dist.groupby("scenario").sum().sum(axis=1)
+ CTS_demand_grid.groupby("scenario").sum().sum(axis=1)
)
- target_cts.demand
) / target_cts.demand

assert (
check_cts.abs().max() < 0.01
), f"""Unexpected deviation between target value and distributed
service heat demand: {check_residential}
"""

# store demand timeseries for pypsa-eur-sec on national level
store_national_profiles(
residential_demand_grid,
Expand All @@ -1809,6 +1867,7 @@ def demand_profile_generator(aggregation_level="district"):
CTS_demand_dist,
)


if aggregation_level == "district":
total_demands_dist = pd.concat(
[residential_demand_dist, CTS_demand_dist]
Expand Down Expand Up @@ -1923,7 +1982,7 @@ class HeatTimeSeries(Dataset):
def __init__(self, dependencies):
super().__init__(
name="HeatTimeSeries",
version="0.0.6",
version="0.0.7",
dependencies=dependencies,
tasks=(demand_profile_generator),
)

0 comments on commit 1a0b1e8

Please sign in to comment.