Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fixes/#989-mismatch-cts-bus-id' …
Browse files Browse the repository at this point in the history
…into local
  • Loading branch information
nailend committed Oct 19, 2022
2 parents b991505 + 555398c commit 353a31d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,9 @@ Bug Fixes
`#909 <https://github.com/openego/eGon-data/issues/909>`_
* Overwrite capacities for conventional power plants with data from nep list
`#403 <https://github.com/openego/eGon-data/issues/403>`_
* Mismatch of building bus_ids from cts_heat_demand_building_share
and mapping table
`#989 <https://github.com/openego/eGon-data/issues/989>`_

.. _PR #692: https://github.com/openego/eGon-data/pull/692
.. _#343: https://github.com/openego/eGon-data/issues/343
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@

from geoalchemy2 import Geometry
from geoalchemy2.shape import to_shape
from psycopg2.extensions import AsIs, register_adapter
from sqlalchemy import REAL, Column, Integer, String, func
from sqlalchemy.ext.declarative import declarative_base
import geopandas as gpd
Expand Down Expand Up @@ -1158,8 +1159,18 @@ def cts_buildings():
Cells with CTS demand, amenities and buildings do not change within
the scenarios, only the demand itself. Therefore scenario eGon2035
can be used universally to determine the cts buildings but not for
he demand share.
the demand share.
"""
# ========== Register np datatypes with SQLA ==========
def adapt_numpy_float64(numpy_float64):
return AsIs(numpy_float64)

def adapt_numpy_int64(numpy_int64):
return AsIs(numpy_int64)

register_adapter(np.float64, adapt_numpy_float64)
register_adapter(np.int64, adapt_numpy_int64)
# =====================================================

log.info("Start logging!")
# Buildings with amenities
Expand Down Expand Up @@ -1323,6 +1334,31 @@ def cts_buildings():
df_cts_buildings = df_cts_buildings.reset_index().rename(
columns={"index": "serial"}
)

# Fix #989
# Mismatched zensus population id
from saio.boundaries import egon_map_zensus_buildings_filtered_all

with db.session_scope() as session:
query = session.query(
egon_map_zensus_buildings_filtered_all.id,
egon_map_zensus_buildings_filtered_all.zensus_population_id,
).filter(
egon_map_zensus_buildings_filtered_all.id.in_(
df_cts_buildings.id.values
)
)

df_map_zensus_population_id = pd.read_sql(
query.statement, session.connection(), index_col=None
)

df_cts_buildings = pd.merge(
left=df_cts_buildings.drop(columns="zensus_population_id"),
right=df_map_zensus_population_id,
on="id",
)

# Write table to db for debugging and postprocessing
write_table_to_postgis(
df_cts_buildings,
Expand Down

0 comments on commit 353a31d

Please sign in to comment.