Skip to content

Commit

Permalink
Merge pull request #990 from openego/features/#987-add-distribution-r…
Browse files Browse the repository at this point in the history
…ural-heatpumps

Features/#987 add distribution rural heatpumps
  • Loading branch information
ClaraBuettner committed Nov 1, 2022
2 parents 416f543 + b86b545 commit 832d378
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ Changed
`#856 <https://github.com/openego/eGon-data/issues/856>`_
* Introduce carrier name 'others'
`#819 <https://github.com/openego/eGon-data/issues/819>`_
* Add rural heat pumps per medium voltage grid district
`#987 <https://github.com/openego/eGon-data/issues/987>`_


Bug Fixes
Expand Down
28 changes: 26 additions & 2 deletions src/egon/data/datasets/heat_demand_timeseries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def create_district_heating_profile_python_like(scenario="eGon2035"):

annual_demand = db.select_dataframe(
f"""
SELECT a.zensus_population_id, demand/c.count as per_building , area_id FROM
SELECT a.zensus_population_id, demand/c.count as per_building , area_id, demand as demand_total FROM
demand.egon_peta_heat a
INNER JOIN (
SELECT * FROM demand.egon_map_zensus_district_heating_areas
Expand Down Expand Up @@ -353,6 +353,20 @@ def create_district_heating_profile_python_like(scenario="eGon2035"):
)
)

diff = (
slice_df.groupby("day").sum()[range(24)].sum().sum()
- annual_demand[
annual_demand.area_id == area
].demand_total.sum()
) / (
annual_demand[annual_demand.area_id == area].demand_total.sum()
)

assert (
abs(diff) < 0.02
), f"""Deviation of residential heat demand time
series for district heating grid {str(area)} is {diff}"""

hh = np.concatenate(
slice_df.groupby("day").sum()[range(24)].values
).ravel()
Expand Down Expand Up @@ -613,7 +627,7 @@ def create_individual_heating_profile_python_like(scenario="eGon2035"):

annual_demand = db.select_dataframe(
f"""
SELECT a.zensus_population_id, demand/c.count as per_building, bus_id
SELECT a.zensus_population_id, demand/c.count as per_building, demand as demand_total, bus_id
FROM demand.egon_peta_heat a
Expand Down Expand Up @@ -719,6 +733,16 @@ def create_individual_heating_profile_python_like(scenario="eGon2035"):
slice_df.groupby("day").sum()[range(24)].values
).ravel()

diff = (
slice_df.groupby("day").sum()[range(24)].sum().sum()
- annual_demand[annual_demand.bus_id == grid].demand_total.sum()
) / (annual_demand[annual_demand.bus_id == grid].demand_total.sum())

assert (
abs(diff) < 0.02
), f"""Deviation of residential heat demand time
series for mv grid {str(grid)} is {diff}"""

if not (slice_df[hour].empty or cts.empty):
entry = EgonEtragoTimeseriesIndividualHeating(
bus_id=int(grid),
Expand Down
39 changes: 20 additions & 19 deletions src/egon/data/datasets/heat_demand_timeseries/service_sector.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,22 @@ def cts_demand_per_aggregation_level(aggregation_level, scenario):

mv_grid_ind = db.select_dataframe(
f"""
SELECT bus_id, a.zensus_population_id
FROM boundaries.egon_map_zensus_grid_districts a
LEFT JOIN demand.egon_map_zensus_district_heating_areas b
ON a.zensus_population_id = b.zensus_population_id
SELECT bus_id, a.zensus_population_id
FROM boundaries.egon_map_zensus_grid_districts a
JOIN demand.egon_peta_heat c
ON a.zensus_population_id = c.zensus_population_id
WHERE b.scenario = '{scenario}'
AND c.scenario = '{scenario}'
WHERE c.scenario = '{scenario}'
AND c.sector = 'service'
"""
)

mv_grid_ind = mv_grid_ind[
~mv_grid_ind.zensus_population_id.isin(
district_heating.index.values
)
]
CTS_per_grid = pd.merge(
CTS_per_zensus,
mv_grid_ind,
Expand Down Expand Up @@ -284,26 +285,26 @@ def CTS_demand_scale(aggregation_level):

CTS_district = CTS_district.append(CTS_per_district)
CTS_district = CTS_district.sort_index()



mv_grid_ind = db.select_dataframe(
f"""
SELECT bus_id, a.zensus_population_id
FROM boundaries.egon_map_zensus_grid_districts a
LEFT JOIN demand.egon_map_zensus_district_heating_areas b
ON a.zensus_population_id = b.zensus_population_id
JOIN demand.egon_peta_heat c
ON a.zensus_population_id = c.zensus_population_id
WHERE b.scenario = '{scenario}'
AND c.scenario = '{scenario}'
WHERE c.scenario = '{scenario}'
AND c.sector = 'service'
"""
)

mv_grid_ind = mv_grid_ind[
~mv_grid_ind.zensus_population_id.isin(
district_heating.zensus_population_id.values
)
]

CTS_demands_grid = pd.merge(
demand,
mv_grid_ind[["bus_id", "zensus_population_id"]],
Expand Down Expand Up @@ -361,4 +362,4 @@ def CTS_demand_scale(aggregation_level):
CTS_zensus = CTS_zensus.set_index("bus_id")
CTS_zensus = CTS_zensus.sort_index()

return CTS_district, CTS_grid, CTS_zensus
return CTS_district, CTS_grid, CTS_zensus
23 changes: 15 additions & 8 deletions src/egon/data/datasets/heat_etrago/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,18 @@ def insert_buses(carrier, scenario):
SELECT ST_Centroid(geom) AS geom
FROM {sources['mv_grids']['schema']}.
{sources['mv_grids']['table']}
WHERE bus_id IN (
SELECT bus_id FROM
demand.egon_etrago_timeseries_individual_heating
WHERE scenario = '{scenario}')
WHERE bus_id IN
(SELECT DISTINCT bus_id
FROM boundaries.egon_map_zensus_grid_districts a
JOIN demand.egon_peta_heat b
ON a.zensus_population_id = b.zensus_population_id
WHERE b.scenario = '{scenario}'
AND b.zensus_population_id NOT IN (
SELECT zensus_population_id FROM
demand.egon_map_zensus_district_heating_areas
WHERE scenario = '{scenario}'
)
)
"""
)
heat_buses.geom = mv_grids.geom.to_crs(epsg=4326)
Expand Down Expand Up @@ -573,9 +581,9 @@ def buses():
"""

insert_buses("central_heat", scenario="eGon2035")
# insert_buses("rural_heat", scenario="eGon2035")
insert_buses("rural_heat", scenario="eGon2035")
insert_buses("central_heat", scenario="eGon100RE")
# insert_buses("rural_heat", scenario="eGon100RE")
insert_buses("rural_heat", scenario="eGon100RE")


def supply():
Expand All @@ -592,8 +600,7 @@ def supply():

insert_central_direct_heat(scenario="eGon2035")
insert_central_power_to_heat(scenario="eGon2035")
# Temporary drop everything related to rural heat
# insert_individual_power_to_heat(scenario="eGon2035")
insert_individual_power_to_heat(scenario="eGon2035")

# insert_rural_gas_boilers(scenario="eGon2035")
insert_central_gas_boilers(scenario="eGon2035")
Expand Down
5 changes: 2 additions & 3 deletions src/egon/data/datasets/heat_supply/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,13 @@ class HeatSupply(Dataset):
def __init__(self, dependencies):
super().__init__(
name="HeatSupply",
version="0.0.7",
version="0.0.8",
dependencies=dependencies,
tasks=(
create_tables,
{
district_heating,
# Temporary drop everything related to rural heat
# individual_heating,
individual_heating,
potential_germany,
},
),
Expand Down
2 changes: 1 addition & 1 deletion src/egon/data/datasets/heat_supply/individual_heating.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def cascade_per_technology(
max_size_individual_chp=0.05,
):

""" Add plants for individual heat.
"""Add plants for individual heat.
Currently only on mv grid district level.
Parameters
Expand Down

0 comments on commit 832d378

Please sign in to comment.