Skip to content

Commit

Permalink
Refactor import_tables to import_tables_from_oep for OEP database
Browse files Browse the repository at this point in the history
  • Loading branch information
joda9 committed Sep 18, 2024
1 parent 7c13649 commit 7563aef
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
4 changes: 2 additions & 2 deletions edisgo/io/dsm_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_profiles_per_industrial_load(
sites_ind_dsm_ts,
egon_osm_ind_load_curves_individual_dsm_timeseries,
egon_sites_ind_load_curves_individual_dsm_timeseries,
) = config.import_tables(
) = config.import_tables_from_oep(
engine,
[
"egon_demandregio_sites_ind_electricity_dsm_timeseries",
Expand Down Expand Up @@ -236,7 +236,7 @@ def get_profile_cts(
"""
config = Config()
(egon_etrago_electricity_cts_dsm_timeseries,) = config.import_tables(
(egon_etrago_electricity_cts_dsm_timeseries,) = config.import_tables_from_oep(
engine, ["egon_etrago_electricity_cts_dsm_timeseries"], "demand"
)

Expand Down
8 changes: 5 additions & 3 deletions edisgo/io/electromobility_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,9 @@ def simbev_config_from_oedb(
"""
config = Config()
(egon_ev_metadata,) = config.import_tables(engine, ["egon_ev_metadata"], "demand")
(egon_ev_metadata,) = config.import_tables_from_oep(
engine, ["egon_ev_metadata"], "demand"
)

with session_scope_egon_data(engine) as session:
query = session.query(egon_ev_metadata).filter(
Expand Down Expand Up @@ -1253,7 +1255,7 @@ def potential_charging_parks_from_oedb(
"""
config = Config()
(egon_emob_charging_infrastructure,) = config.import_tables(
(egon_emob_charging_infrastructure,) = config.import_tables_from_oep(
engine, ["egon_emob_charging_infrastructure"], "grid"
)

Expand Down Expand Up @@ -1311,7 +1313,7 @@ def charging_processes_from_oedb(
"""
config = Config()
egon_ev_mv_grid_district, egon_ev_trip = config.import_tables(
egon_ev_mv_grid_district, egon_ev_trip = config.import_tables_from_oep(
engine, ["egon_ev_mv_grid_district", "egon_ev_trip"], "demand"
)

Expand Down
2 changes: 1 addition & 1 deletion edisgo/io/generators_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ def _get_egon_chp_plants():
egon_chp_plants,
egon_power_plants,
egon_power_plants_pv_roof_building,
) = config.import_tables(
) = config.import_tables_from_oep(
engine,
["egon_chp_plants", "egon_power_plants", "egon_power_plants_pv_roof_building"],
"supply",
Expand Down
16 changes: 11 additions & 5 deletions edisgo/io/heat_pump_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,24 +268,30 @@ def _get_individual_heat_pump_capacity():
return np.sum(cap)

config = Config()
egon_district_heating_areas, egon_hp_capacity_buildings = config.import_tables(
(
egon_district_heating_areas,
egon_hp_capacity_buildings,
) = config.import_tables_from_oep(
engine, ["egon_district_heating_areas", "egon_hp_capacity_buildings"], "demand"
)
(
egon_district_heating,
egon_era5_weather_cells,
egon_individual_heating,
) = config.import_tables(
) = config.import_tables_from_oep(
engine,
["egon_district_heating", "egon_era5_weather_cells", "egon_individual_heating"],
"supply",
)
egon_map_zensus_mvgd_buildings, egon_map_zensus_weather_cell = config.import_tables(
(
egon_map_zensus_mvgd_buildings,
egon_map_zensus_weather_cell,
) = config.import_tables_from_oep(
engine,
["egon_map_zensus_mvgd_buildings", "egon_map_zensus_weather_cell"],
"boundaries",
)
egon_etrago_bus, egon_etrago_link = config.import_tables(
egon_etrago_bus, egon_etrago_link = config.import_tables_from_oep(
engine, ["egon_etrago_bus", "egon_etrago_link"], "grid"
)

Expand Down Expand Up @@ -608,7 +614,7 @@ def efficiency_resistive_heaters_oedb(scenario, engine):
"""
config = Config()
(egon_scenario_parameters,) = config.import_tables(
(egon_scenario_parameters,) = config.import_tables_from_oep(
engine, ["egon_scenario_parameters"], "scenario"
)

Expand Down
2 changes: 1 addition & 1 deletion edisgo/io/storage_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def home_batteries_oedb(
"""
config = Config()
(egon_home_batteries,) = config.import_tables(
(egon_home_batteries,) = config.import_tables_from_oep(
engine, ["egon_home_batteries"], "supply"
)

Expand Down
24 changes: 12 additions & 12 deletions edisgo/io/timeseries_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def feedin_oedb(
)

config = Config()
(egon_era5_renewable_feedin,) = config.import_tables(
(egon_era5_renewable_feedin,) = config.import_tables_from_oep(
engine, ["egon_era5_renewable_feedin"], "supply"
)

Expand Down Expand Up @@ -357,7 +357,7 @@ def cop_oedb(edisgo_object, engine, weather_cell_ids, timeindex=None):
)

config = Config()
(egon_era5_renewable_feedin,) = config.import_tables(
(egon_era5_renewable_feedin,) = config.import_tables_from_oep(
engine, ["egon_era5_renewable_feedin"], "supply"
)

Expand Down Expand Up @@ -655,7 +655,7 @@ def _get_zensus_cells_of_buildings(building_ids, engine):
"""
config = Config()
(egon_map_zensus_mvgd_buildings,) = config.import_tables(
(egon_map_zensus_mvgd_buildings,) = config.import_tables_from_oep(
engine, ["egon_map_zensus_mvgd_buildings"], "boundaries"
)

Expand Down Expand Up @@ -840,7 +840,7 @@ def _get_daily_demand_share(zensus_ids):
egon_heat_idp_pool,
egon_heat_timeseries_selected_profiles,
egon_peta_heat,
) = config.import_tables(
) = config.import_tables_from_oep(
engine,
[
"egon_daily_heat_demand_per_climate_zone",
Expand All @@ -850,7 +850,7 @@ def _get_daily_demand_share(zensus_ids):
],
"demand",
)
(egon_map_zensus_climate_zones,) = config.import_tables(
(egon_map_zensus_climate_zones,) = config.import_tables_from_oep(
engine, ["egon_map_zensus_climate_zones"], "boundaries"
)

Expand Down Expand Up @@ -941,7 +941,7 @@ def get_district_heating_heat_demand_profiles(district_heating_ids, scenario, en
"""
config = Config()
(egon_timeseries_district_heating,) = config.import_tables(
(egon_timeseries_district_heating,) = config.import_tables_from_oep(
engine, ["egon_timeseries_district_heating"], "demand"
)

Expand Down Expand Up @@ -996,7 +996,7 @@ def get_cts_profiles_per_building(edisgo_obj, scenario, sector, engine):
"""
config = Config()
(egon_map_zensus_mvgd_buildings,) = config.import_tables(
(egon_map_zensus_mvgd_buildings,) = config.import_tables_from_oep(
engine, ["egon_map_zensus_mvgd_buildings"], "boundaries"
)

Expand Down Expand Up @@ -1160,7 +1160,7 @@ def _get_total_heat_demand_grid():
(
egon_cts_electricity_demand_building_share,
egon_etrago_electricity_cts,
) = config.import_tables(
) = config.import_tables_from_oep(
engine,
[
"egon_cts_electricity_demand_building_share",
Expand All @@ -1179,7 +1179,7 @@ def _get_total_heat_demand_grid():
egon_cts_heat_demand_building_share,
egon_etrago_heat_cts,
egon_peta_heat,
) = config.import_tables(
) = config.import_tables_from_oep(
engine,
[
"egon_cts_heat_demand_building_share",
Expand All @@ -1188,7 +1188,7 @@ def _get_total_heat_demand_grid():
],
"demand",
)
(egon_map_zensus_grid_districts,) = config.import_tables(
(egon_map_zensus_grid_districts,) = config.import_tables_from_oep(
engine, ["egon_map_zensus_grid_districts"], "boundaries"
)
df_cts_substation_profiles = _get_substation_profile()
Expand Down Expand Up @@ -1335,7 +1335,7 @@ def _get_profiles(profile_ids):
hh_profile,
egon_household_electricity_profile_of_buildings,
iee_household_load_profiles,
) = config.import_tables(
) = config.import_tables_from_oep(
engine,
[
"egon_household_electricity_profile_in_census_cell",
Expand Down Expand Up @@ -1457,7 +1457,7 @@ def _get_load_curves_areas(site_ids):
(
egon_osm_ind_load_curves_individual,
egon_sites_ind_load_curves_individual,
) = config.import_tables(
) = config.import_tables_from_oep(
engine,
[
"egon_osm_ind_load_curves_individual",
Expand Down
4 changes: 2 additions & 2 deletions edisgo/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ def get_database_alias_dictionaries(self) -> tuple[dict[str, str], dict[str, str

return name_mapping, schema_mapping

def import_tables(
def import_tables_from_oep(
self, engine: sa.engine.Engine, table_names: list[str], schema_name: str
) -> list[sa.Table]:
"""
Imports tables from the database based on the provided table names and
Imports tables from the OEP database based on the provided table names and
schema name.
Parameters
Expand Down
2 changes: 1 addition & 1 deletion edisgo/tools/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def get_weather_cells_intersecting_with_grid_district(
weather_cells = pd.read_sql(sql=query.statement, con=query.session.bind).gid
else:
config = Config()
(egon_era5_weather_cells,) = config.import_tables(
(egon_era5_weather_cells,) = config.import_tables_from_oep(
engine, ["egon_era5_weather_cells"], "supply"
)

Expand Down

0 comments on commit 7563aef

Please sign in to comment.