Skip to content

Commit

Permalink
Enable getting electricity time series for status quo for households …
Browse files Browse the repository at this point in the history
…and industry
  • Loading branch information
birgits committed Nov 18, 2023
1 parent 4dfc1d0 commit 2973cba
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 33 deletions.
59 changes: 28 additions & 31 deletions edisgo/io/timeseries_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,10 @@ def _get_demand_share():
db_table = egon_cts_heat_demand_building_share

with session_scope_egon_data(engine) as session:
query = session.query(db_table.building_id, db_table.profile_share,).filter(
query = session.query(
db_table.building_id,
db_table.profile_share,
).filter(
db_table.scenario == scenario,
db_table.bus_id == bus_id,
)
Expand Down Expand Up @@ -1080,7 +1083,10 @@ def _get_substation_profile():
db_table = egon_etrago_heat_cts

with session_scope_egon_data(engine) as session:
query = session.query(db_table.bus_id, db_table.p_set,).filter(
query = session.query(
db_table.bus_id,
db_table.p_set,
).filter(
db_table.scn_name == scenario,
db_table.bus_id == bus_id,
)
Expand Down Expand Up @@ -1126,7 +1132,6 @@ def _get_total_heat_demand_grid():
saio.register_schema("demand", engine)

if sector == "electricity":

from saio.demand import (
egon_cts_electricity_demand_building_share,
egon_etrago_electricity_cts,
Expand All @@ -1138,7 +1143,6 @@ def _get_total_heat_demand_grid():
df_demand_share = _get_demand_share()

elif sector == "heat":

from saio.demand import (
egon_cts_heat_demand_building_share,
egon_etrago_heat_cts,
Expand Down Expand Up @@ -1187,7 +1191,7 @@ def get_residential_electricity_profiles_per_building(building_ids, scenario, en
List of building IDs to retrieve electricity demand profiles for.
scenario : str
Scenario for which to retrieve demand data. Possible options
are 'eGon2035' and 'eGon100RE'.
are 'eGon2021', 'eGon2035' and 'eGon100RE'.
engine : :sqlalchemy:`sqlalchemy.Engine<sqlalchemy.engine.Engine>`
Database engine.
Expand Down Expand Up @@ -1216,30 +1220,21 @@ def _get_scaling_factors_of_zensus_cells(zensus_ids):
column factor.
"""
with session_scope_egon_data(engine) as session:
if scenario == "eGon2035":
query = session.query(
egon_household_electricity_profile_in_census_cell.cell_id,
egon_household_electricity_profile_in_census_cell.factor_2035.label(
"factor"
),
).filter(
egon_household_electricity_profile_in_census_cell.cell_id.in_(
zensus_ids
)
)
else:
query = session.query(
egon_household_electricity_profile_in_census_cell.cell_id,
egon_household_electricity_profile_in_census_cell.factor_2050.label(
"factor"
),
).filter(
egon_household_electricity_profile_in_census_cell.cell_id.in_(
zensus_ids
)
)
return pd.read_sql(query.statement, engine, index_col="cell_id")
if scenario == "eGon2021":
return pd.DataFrame(index=zensus_ids, data={"factor": 1.0})
else:
with session_scope_egon_data(engine) as session:
if scenario == "eGon2035":
query = session.query(
hh_profile.cell_id,
hh_profile.factor_2035.label("factor"),
).filter(hh_profile.cell_id.in_(zensus_ids))
else:
query = session.query(
hh_profile.cell_id,
hh_profile.factor_2050.label("factor"),
).filter(hh_profile.cell_id.in_(zensus_ids))
return pd.read_sql(query.statement, engine, index_col="cell_id")

def _get_profile_ids_of_buildings(building_ids):
"""
Expand Down Expand Up @@ -1298,7 +1293,9 @@ def _get_profiles(profile_ids):

saio.register_schema("demand", engine)
from saio.demand import (
egon_household_electricity_profile_in_census_cell,
egon_household_electricity_profile_in_census_cell as hh_profile,
)
from saio.demand import (
egon_household_electricity_profile_of_buildings,
iee_household_load_profiles,
)
Expand Down Expand Up @@ -1346,7 +1343,7 @@ def get_industrial_electricity_profiles_per_site(site_ids, scenario, engine):
List of industrial site and OSM IDs to retrieve electricity demand profiles for.
scenario : str
Scenario for which to retrieve demand data. Possible options
are 'eGon2035' and 'eGon100RE'.
are 'eGon2021', 'eGon2035' and 'eGon100RE'.
engine : :sqlalchemy:`sqlalchemy.Engine<sqlalchemy.engine.Engine>`
Database engine.
Expand Down
17 changes: 15 additions & 2 deletions tests/io/test_timeseries_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ def test_get_district_heating_heat_demand_profiles(self):

@pytest.mark.local
def test_get_cts_profiles_per_building(self):

edisgo_object = EDisGo(
ding0_grid=pytest.ding0_test_network_3_path, legacy_ding0_grids=False
)
Expand All @@ -251,7 +250,6 @@ def test_get_cts_profiles_per_building(self):

@pytest.mark.local
def test_get_cts_profiles_per_grid(self):

df = timeseries_import.get_cts_profiles_per_grid(
33535, "eGon2035", "heat", pytest.engine
)
Expand All @@ -270,6 +268,13 @@ def test_get_residential_electricity_profiles_per_building(self):
assert df.shape == (8760, 1)
assert np.isclose(df.loc[:, 442081].sum(), 3.20688, atol=1e-3)

# test with status quo
df = timeseries_import.get_residential_electricity_profiles_per_building(
[-1, 442081], "eGon2021", pytest.engine
)
assert df.shape == (8760, 1)
assert np.isclose(df.loc[:, 442081].sum(), 4.288845, atol=1e-3)

@pytest.mark.local
def test_get_industrial_electricity_profiles_per_site(self):
# test with one site and one OSM area
Expand All @@ -285,3 +290,11 @@ def test_get_industrial_electricity_profiles_per_site(self):
[541658], "eGon2035", pytest.engine
)
assert df.shape == (8760, 1)

# test with status quo
df = timeseries_import.get_industrial_electricity_profiles_per_site(
[1, 541658], "eGon2021", pytest.engine
)
assert df.shape == (8760, 2)
assert np.isclose(df.loc[:, 1].sum(), 31655.640, atol=1e-3)
assert np.isclose(df.loc[:, 541658].sum(), 2910.816, atol=1e-3)

0 comments on commit 2973cba

Please sign in to comment.