Skip to content

Commit

Permalink
Merge pull request #216 from openego/fixes/#202-fix-zensus-misc-witho…
Browse files Browse the repository at this point in the history
…ut-population

Fixes/#202 fix zensus misc without population
  • Loading branch information
ClaraBuettner authored Apr 16, 2021
2 parents 89c0f8a + a8db34b commit 6b75799
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,5 @@ Bug fixes
`#171 <https://github.com/openego/eGon-data/issues/171>`_
* Adjust names of demandregios nuts3 regions according to nuts version 2016
`#201 <https://github.com/openego/eGon-data/issues/201>`_
* Delete zensus buildings, apartments and households in unpopulated cells
`#202 <https://github.com/openego/eGon-data/issues/202>`_
8 changes: 4 additions & 4 deletions src/egon/data/datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ zensus_misc:
processed:
schema: "society"
path_table_map:
"csv_Haushalte_100m_Gitter.zip": "destatis_zensus_household_per_ha"
"csv_Gebaeude_100m_Gitter.zip": "destatis_zensus_building_per_ha"
"csv_Wohnungen_100m_Gitter.zip": "destatis_zensus_apartment_per_ha"
"csv_Haushalte_100m_Gitter.zip": "egon_destatis_zensus_household_per_ha"
"csv_Gebaeude_100m_Gitter.zip": "egon_destatis_zensus_building_per_ha"
"csv_Wohnungen_100m_Gitter.zip": "egon_destatis_zensus_apartment_per_ha"

map_zensus_vg250:
sources:
Expand Down Expand Up @@ -181,7 +181,7 @@ society_prognosis:
table: 'destatis_zensus_population_per_ha'
zensus_households:
schema: 'society'
table: 'destatis_zensus_household_per_ha'
table: 'egon_destatis_zensus_household_per_ha'
demandregio_population:
schema: 'society'
table: 'egon_demandregio_population'
Expand Down
7 changes: 6 additions & 1 deletion src/egon/data/importing/heat_demand_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,14 @@ def adjust_residential_heat_to_zensus(scenario):
"""
Adjust residential heat demands to fit to zensus population.
In some cases, Peta assigns residential heat demand to unpopulated cells.
This can be caused by the different population data used in Peta or
buildings in zenus cells without a population
(see :func:`egon.data.importing.zensus.adjust_zensus_misc`)
Residential heat demand in cells without zensus population is dropped.
Residential heat demand in cells with zensus population is scaled to meet
the formal overall residential heat demands.
the overall residential heat demands.
Parameters
----------
Expand Down
37 changes: 37 additions & 0 deletions src/egon/data/importing/zensus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,40 @@ def zensus_misc_to_postgres():
FOREIGN KEY (zensus_population_id)
REFERENCES {population_table}(id);"""
)

# Delete entries for unpopulated cells
adjust_zensus_misc()


def adjust_zensus_misc():
"""Deletes zensus households, buildings and aparments in unpopulated cells
Some unpopulated zensus cells are listed in the table of households,
buildings and/or aparments. This can be caused by missing population
information due to privacy or other special cases (e.g. holiday homes
are listed as buildings but are not permanently populated.)
In the follwong tasks of egon-data, only data of populated cells is used.
Returns
-------
None.
"""
# Get information from data configuration file
data_config = egon.data.config.datasets()
zensus_population_processed = data_config["zensus_population"]["processed"]
zensus_misc_processed = data_config["zensus_misc"]["processed"]

population_table = (
f"{zensus_population_processed['schema']}"
f".{zensus_population_processed['table']}"
)

for input_file, table in zensus_misc_processed["path_table_map"].items():
db.execute_sql(
f"""
DELETE FROM {zensus_population_processed['schema']}.{table} as b
WHERE b.zensus_population_id IN (
SELECT id FROM {population_table}
WHERE population < 0);"""
)

0 comments on commit 6b75799

Please sign in to comment.