diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b3b85e2bf..be04a191e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -204,6 +204,8 @@ Changed `#397 `_ * Rename columns gid to id `#169 `_ +* Remove upper version limit of pandas + `#383 `_ * Use random seed from CLI parameters for CHP and society prognosis functions `#351 `_ * Changed demand.egon_schmidt_industrial_sites - table and merged table (industrial_sites) @@ -212,6 +214,9 @@ Changed `#436 `_ * Adjust file path for industrial sites import `#397 `_ +* Rename columns subst_id to bus_id + `#335 `_ + Bug fixes --------- @@ -270,3 +275,6 @@ Bug fixes `#432 `_ * Add curl to prerequisites in the docs `#440 `_ +* Replace NAN by 0 to avoid empty p_set column in DB + `#414 `_ + diff --git a/setup.py b/setup.py index 50456e5e2..c981789b4 100755 --- a/setup.py +++ b/setup.py @@ -93,7 +93,7 @@ def read(*names, **kwargs): "netcdf4", "oedialect==0.0.8", "openpyxl", - "pandas>1.2.0,<1.3.0", + "pandas>1.2.0", "psycopg2", "pyaml", "rasterio", diff --git a/src/egon/data/datasets/electricity_demand/__init__.py b/src/egon/data/datasets/electricity_demand/__init__.py index 1c4fb5a8a..f0ab90558 100644 --- a/src/egon/data/datasets/electricity_demand/__init__.py +++ b/src/egon/data/datasets/electricity_demand/__init__.py @@ -16,7 +16,7 @@ class HouseholdElectricityDemand(Dataset): def __init__(self, dependencies): super().__init__( name="HouseholdElectricityDemand", - version="0.0.1", + version="0.0.2", dependencies=dependencies, tasks=(create_tables, distribute_household_demands) @@ -26,7 +26,7 @@ class CtsElectricityDemand(Dataset): def __init__(self, dependencies): super().__init__( name="CtsElectricityDemand", - version="0.0.1", + version="0.0.2", dependencies=dependencies, tasks=(distribute_cts_demands, insert_cts_load) diff --git a/src/egon/data/datasets/electricity_demand/temporal.py b/src/egon/data/datasets/electricity_demand/temporal.py index 29b421ad1..3ae8bc3b4 100644 --- a/src/egon/data/datasets/electricity_demand/temporal.py +++ b/src/egon/data/datasets/electricity_demand/temporal.py @@ -16,7 +16,7 @@ class EgonEtragoElectricityCts(Base): __tablename__ = "egon_etrago_electricity_cts" __table_args__ = {"schema": "demand"} - subst_id = Column(Integer, primary_key=True) + bus_id = Column(Integer, primary_key=True) scn_name = Column(String, primary_key=True) p_set = Column(ARRAY(Float)) q_set = Column(ARRAY(Float)) @@ -113,7 +113,7 @@ def calc_load_curves_cts(scenario): Returns ------- pandas.DataFrame - Demand timeseries of cts per substation id + Demand timeseries of cts per bus id """ @@ -138,7 +138,7 @@ def calc_load_curves_cts(scenario): demands_zensus = db.select_dataframe( f"""SELECT a.zensus_population_id, a.demand, b.vg250_nuts3 as nuts3, - c.subst_id + c.bus_id FROM {sources['zensus_electricity']['schema']}. {sources['zensus_electricity']['table']} a INNER JOIN @@ -168,10 +168,10 @@ def calc_load_curves_cts(scenario): # Calculate shares of cts branches per hvmv substation share_subst = demands_zensus.drop( - 'demand', axis=1).groupby('subst_id').mean() + 'demand', axis=1).groupby('bus_id').mean() # Calculate cts annual demand per hvmv substation - annual_demand_subst = demands_zensus.groupby('subst_id').demand.sum() + annual_demand_subst = demands_zensus.groupby('bus_id').demand.sum() # Return electrical load curves per hvmv substation return calc_load_curve(share_subst, annual_demand_subst) diff --git a/src/egon/data/datasets/electricity_demand_etrago.py b/src/egon/data/datasets/electricity_demand_etrago.py index eb3b694ef..cf3a30571 100644 --- a/src/egon/data/datasets/electricity_demand_etrago.py +++ b/src/egon/data/datasets/electricity_demand_etrago.py @@ -29,11 +29,11 @@ def demands_per_bus(scenario): # Select data on CTS electricity demands per bus cts_curves = db.select_dataframe( - f"""SELECT subst_id, p_set FROM + f"""SELECT bus_id, p_set FROM {sources['cts_curves']['schema']}. {sources['cts_curves']['table']} WHERE scn_name = '{scenario}'""", - index_col="subst_id", + index_col="bus_id", ) # Rename index @@ -187,7 +187,7 @@ class ElectricalLoadEtrago(Dataset): def __init__(self, dependencies): super().__init__( name="Electrical_load_etrago", - version="0.0.1", + version="0.0.2", dependencies=dependencies, tasks=(export_to_db,), ) diff --git a/src/egon/data/datasets/heat_etrago/__init__.py b/src/egon/data/datasets/heat_etrago/__init__.py index 758b694db..417661f3e 100644 --- a/src/egon/data/datasets/heat_etrago/__init__.py +++ b/src/egon/data/datasets/heat_etrago/__init__.py @@ -228,7 +228,7 @@ class HeatEtrago(Dataset): def __init__(self, dependencies): super().__init__( name="HeatEtrago", - version="0.0.2", + version="0.0.3", dependencies=dependencies, tasks=(buses, supply), ) diff --git a/src/egon/data/datasets/heat_etrago/power_to_heat.py b/src/egon/data/datasets/heat_etrago/power_to_heat.py index 726472125..0fb03a02a 100644 --- a/src/egon/data/datasets/heat_etrago/power_to_heat.py +++ b/src/egon/data/datasets/heat_etrago/power_to_heat.py @@ -301,7 +301,7 @@ def assign_electrical_bus(heat_pumps, multiple_per_mv_grid=False): # Select mv grid distrcits mv_grid_district = db.select_geodataframe( f""" - SELECT subst_id, geom FROM + SELECT bus_id, geom FROM {sources['egon_mv_grid_district']['schema']}. {sources['egon_mv_grid_district']['table']} """ @@ -339,7 +339,7 @@ def assign_electrical_bus(heat_pumps, multiple_per_mv_grid=False): # Assign power bus per zensus cell cells["power_bus"] = gpd.sjoin( cells, mv_grid_district, how="inner", op="intersects" - ).subst_id + ).bus_id # Calclate district heating demand per substaion demand_per_substation = pd.DataFrame( diff --git a/src/egon/data/datasets/heat_supply/__init__.py b/src/egon/data/datasets/heat_supply/__init__.py index a7d46b707..b742b3052 100644 --- a/src/egon/data/datasets/heat_supply/__init__.py +++ b/src/egon/data/datasets/heat_supply/__init__.py @@ -134,7 +134,7 @@ class HeatSupply(Dataset): def __init__(self, dependencies): super().__init__( name="HeatSupply", - version="0.0.1", + version="0.0.2", dependencies=dependencies, tasks=(create_tables, district_heating, individual_heating, potential_germany), diff --git a/src/egon/data/datasets/heat_supply/individual_heating.py b/src/egon/data/datasets/heat_supply/individual_heating.py index ca00a433c..726bf3739 100644 --- a/src/egon/data/datasets/heat_supply/individual_heating.py +++ b/src/egon/data/datasets/heat_supply/individual_heating.py @@ -124,7 +124,7 @@ def cascade_heat_supply_indiv(scenario, distribution_level, plotting=True): # Select residential heat demand per mv grid district and federal state heat_per_mv = db.select_geodataframe( f""" - SELECT d.subst_id as bus_id, SUM(demand) as demand, + SELECT d.bus_id as bus_id, SUM(demand) as demand, c.vg250_lan as state, d.geom FROM {sources['heat_demand']['schema']}. {sources['heat_demand']['table']} a @@ -133,17 +133,17 @@ def cascade_heat_supply_indiv(scenario, distribution_level, plotting=True): ON a.zensus_population_id = b.zensus_population_id JOIN {sources['map_vg250_grid']['schema']}. {sources['map_vg250_grid']['table']} c - ON b.subst_id = c.bus_id + ON b.bus_id = c.bus_id JOIN {sources['mv_grids']['schema']}. {sources['mv_grids']['table']} d - ON d.subst_id = c.bus_id + ON d.bus_id = c.bus_id WHERE scenario = '{scenario}' AND sector = 'residential' AND a.zensus_population_id NOT IN ( SELECT zensus_population_id FROM {sources['map_dh']['schema']}.{sources['map_dh']['table']} WHERE scenario = '{scenario}') - GROUP BY d.subst_id, vg250_lan, geom + GROUP BY d.bus_id, vg250_lan, geom """, index_col = 'bus_id') @@ -191,7 +191,7 @@ def plot_heat_supply(resulting_capacities): mv_grids = db.select_geodataframe( """ SELECT * FROM grid.egon_mv_grid_district - """, index_col='subst_id') + """, index_col='bus_id') for c in ['CHP', 'heat_pump']: mv_grids[c] = resulting_capacities[ diff --git a/src/egon/data/datasets/hh_demand_profiles.py b/src/egon/data/datasets/hh_demand_profiles.py index 63d2b9388..96e6ced0a 100644 --- a/src/egon/data/datasets/hh_demand_profiles.py +++ b/src/egon/data/datasets/hh_demand_profiles.py @@ -226,7 +226,7 @@ class EgonEtragoElectricityHouseholds(Base): __table_args__ = {"schema": "demand"} version = Column(String, primary_key=True) - subst_id = Column(Integer, primary_key=True) + bus_id = Column(Integer, primary_key=True) scn_name = Column(String, primary_key=True) p_set = Column(ARRAY(Float)) q_set = Column(ARRAY(Float)) @@ -235,7 +235,7 @@ class EgonEtragoElectricityHouseholds(Base): hh_demand_setup = partial( Dataset, name="HH Demand", - version="0.0.1", + version="0.0.2", dependencies=[], # Tasks are declared in pipeline as function is used multiple times with different args # To differentiate these tasks PythonOperator with specific id-names are used @@ -1451,7 +1451,7 @@ def mv_grid_district_HH_electricity_load( Returns ------- pd.DataFrame - Multiindexed dataframe with `timestep` and `subst_id` as indexers. + Multiindexed dataframe with `timestep` and `bus_id` as indexers. Demand is given in kWh. """ engine = db.engine() @@ -1459,7 +1459,7 @@ def mv_grid_district_HH_electricity_load( with db.session_scope() as session: cells_query = session.query( HouseholdElectricityProfilesInCensusCells, - MapZensusGridDistricts.subst_id, + MapZensusGridDistricts.bus_id, ).join( MapZensusGridDistricts, HouseholdElectricityProfilesInCensusCells.cell_id @@ -1481,7 +1481,7 @@ def mv_grid_district_HH_electricity_load( # Create aggregated load profile for each MV grid district mvgd_profiles_dict = {} - for grid_district, data in cells.groupby("subst_id"): + for grid_district, data in cells.groupby("bus_id"): mvgd_profile = get_load_timeseries( df_profiles=df_profiles, df_cell_demand_metadata=data, @@ -1494,7 +1494,7 @@ def mv_grid_district_HH_electricity_load( # Reshape data: put MV grid ids in columns to a single index column mvgd_profiles = mvgd_profiles.reset_index() - mvgd_profiles.columns = ["subst_id", "p_set"] + mvgd_profiles.columns = ["bus_id", "p_set"] # Add remaining columns mvgd_profiles["version"] = version diff --git a/src/egon/data/datasets/industry/__init__.py b/src/egon/data/datasets/industry/__init__.py index 748add113..01952b30d 100644 --- a/src/egon/data/datasets/industry/__init__.py +++ b/src/egon/data/datasets/industry/__init__.py @@ -351,7 +351,7 @@ class IndustrialDemandCurves(Dataset): def __init__(self, dependencies): super().__init__( name="Industrial_demand_curves", - version="0.0.3", + version="0.0.4", dependencies=dependencies, tasks=( create_tables, diff --git a/src/egon/data/datasets/industry/temporal.py b/src/egon/data/datasets/industry/temporal.py index c4de0d2c8..0dc1592b7 100644 --- a/src/egon/data/datasets/industry/temporal.py +++ b/src/egon/data/datasets/industry/temporal.py @@ -43,7 +43,7 @@ def identify_bus(load_curves, demand_area): # Select mv griddistrict griddistrict = db.select_geodataframe( - f"""SELECT subst_id, geom FROM + f"""SELECT bus_id, geom FROM {sources['egon_mv_grid_district']['schema']}. {sources['egon_mv_grid_district']['table']}""", geom_col="geom", @@ -86,7 +86,7 @@ def identify_bus(load_curves, demand_area): # Combine dataframes to bring loadcurves and bus id together curves_da = pd.merge( load_curves.T, - peak_bus[["subst_id", "id"]], + peak_bus[["bus_id", "id"]], left_index=True, right_on="id", ) @@ -165,7 +165,7 @@ def calc_load_curves_ind_osm(scenario): curves_da = identify_bus(load_curves, demand_area) # Group all load curves per bus - curves_bus = curves_da.drop(["id"], axis=1).groupby("subst_id").sum() + curves_bus = curves_da.drop(["id"], axis=1).fillna(0).groupby("bus_id").sum() # Initalize pandas.DataFrame for export to database load_ts_df = pd.DataFrame(index=curves_bus.index, columns=["p_set"]) @@ -288,7 +288,7 @@ def calc_load_curves_ind_sites(scenario): # Group all load curves per bus and wz curves_bus = ( - curves_da.groupby(["subst_id", "wz"]).sum().drop(["id"], axis=1) + curves_da.fillna(0).groupby(["bus_id", "wz"]).sum().drop(["id"], axis=1) ) # Initalize pandas.DataFrame for pf table load timeseries diff --git a/src/egon/data/datasets/mv_grid_districts.py b/src/egon/data/datasets/mv_grid_districts.py index 0371e39c1..8396e2c57 100644 --- a/src/egon/data/datasets/mv_grid_districts.py +++ b/src/egon/data/datasets/mv_grid_districts.py @@ -1,16 +1,63 @@ """ -Implements the methods for creating medium-voltage grid district areas from -HV-MV substation locations and municipality borders +Medium-voltage grid districts describe the area supplied by one MV grid -Methods are heavily inspired by `Hülk et al. (2017) -`_ -(section 2.3), but differ in detail. -Direct adjacency is preferred over proximity. For polygons of municipalities -without a substation inside it is iteratively checked for direct adjacent -other polygons that have a substation inside. Hence, MV grid districts grow -around a polygon with a substation inside. +Medium-voltage grid districts are defined by one polygon that represents the +supply area. Each MV grid district is connected to the HV grid via a single +substation. -See :func:`define_mv_grid_districts` for more details. +The methods used for identifying the MV grid districts are heavily inspired +by `Hülk et al. (2017) +`_ +(section 2.3), but the implementation differs in detail. +The main difference is that direct adjacency is preferred over proximity. +For polygons of municipalities +without a substation inside, it is iteratively checked for direct adjacent +other polygons that have a substation inside. Speaking visually, a MV grid +district grows around a polygon with a substation inside. + +The grid districts are identified using three data sources + +1. Polygons of municipalities (:class:`Vg250GemClean`) +2. HV-MV substations (:class:`EgonHvmvSubstation`) +3. HV-MV substation voronoi polygons (:class:`EgonHvmvSubstationVoronoi`) + +Fundamentally, it is assumed that grid districts (supply areas) often go +along borders of administrative units, in particular along the borders of +municipalities due to the concession levy. +Furthermore, it is assumed that one grid district is supplied via a single +substation and that locations of substations and grid districts are designed +for aiming least lengths of grid line and cables. + +With these assumptions, the three data sources from above are processed as +follows: + +* Find the number of substations inside each municipality +* Split municipalities with more than one substation inside + * Cut polygons of municipalities with voronoi polygons of respective + substations + * Assign resulting municipality polygon fragments to nearest substation +* Assign municipalities without a single substation to nearest substation in + the neighborhood +* Merge all municipality polygons and parts of municipality polygons to a + single polygon grouped by the assigned substation + +For finding the nearest substation, as already said, direct adjacency is +preferred over closest distance. This means, the nearest substation does not +necessarily have to be the closest substation in the sense of beeline distance. +But it is the substation definitely located in a neighboring polygon. This +prevents the algorithm to find solutions where a MV grid districts consists of +multi-polygons with some space in between. +Nevertheless, beeline distance still plays an important role, as the algorithm +acts in two steps + +1. Iteratively look for neighboring polygons until there are no further + polygons +2. Find a polygon to assign to by minimum beeline distance + +The second step is required in order to cover edge cases, such as islands. + +For understanding how this is implemented into separate functions, please +see :func:`define_mv_grid_districts`. """ from functools import partial @@ -81,7 +128,7 @@ class HvmvSubstPerMunicipality(Base): class VoronoiMunicipalityCutsBase(object): - subst_id = Column(Integer) + bus_id = Column(Integer) municipality_id = Column(Integer) voronoi_id = Column(Integer) ags_0 = Column(String) @@ -122,7 +169,7 @@ class MvGridDistrictsDissolved(Base): Sequence(f"{__tablename__}_id_seq", schema="grid"), primary_key=True, ) - subst_id = Column(Integer) + bus_id = Column(Integer) geom = Column(Geometry("MultiPolygon", 3035)) area = Column(Float) @@ -131,7 +178,7 @@ class MvGridDistricts(Base): __tablename__ = "egon_mv_grid_district" __table_args__ = {"schema": "grid"} - subst_id = Column(Integer, primary_key=True) + bus_id = Column(Integer, primary_key=True) geom = Column(Geometry("MultiPolygon", 3035)) area = Column(Float) @@ -262,7 +309,7 @@ def split_multi_substation_municipalities(): VoronoiMunicipalityCuts.municipality_id, VoronoiMunicipalityCuts.ags_0, VoronoiMunicipalityCuts.geom, - VoronoiMunicipalityCuts.subst_id, + VoronoiMunicipalityCuts.bus_id, VoronoiMunicipalityCuts.voronoi_id, ], q, @@ -298,7 +345,7 @@ def split_multi_substation_municipalities(): ).update( { "subst_count": cuts_substation_subquery.c.subst_count, - "subst_id": cuts_substation_subquery.c.bus_id, + "bus_id": cuts_substation_subquery.c.bus_id, "geom_sub": cuts_substation_subquery.c.geom_sub, }, synchronize_session="fetch", @@ -397,7 +444,7 @@ def assign_substation_municipality_fragments( with_substation, without_substation, strategy, session ): """ - Assign subst_id from next neighboring polygon to municipality fragment + Assign bus_id from next neighboring polygon to municipality fragment For parts municipalities without a substation inside their polygon the next municipality polygon part is found and assigned. @@ -427,7 +474,7 @@ def assign_substation_municipality_fragments( different in detail. """ # Determine nearest neighboring polygon that has a substation - columns_from_cut1_subst = ["subst_id", "subst_count", "geom_sub"] + columns_from_cut1_subst = ["bus_id", "subst_count", "geom_sub"] if strategy == "touches": neighboring_criterion = func.ST_Touches( @@ -526,14 +573,14 @@ def merge_polygons_to_grid_district(): # Step 1: Merge municipality parts cut by voronoi polygons according # to prior determined associated substation joined_municipality_parts = session.query( - VoronoiMunicipalityCutsAssigned.subst_id, + VoronoiMunicipalityCutsAssigned.bus_id, func.ST_Multi( func.ST_Union(VoronoiMunicipalityCutsAssigned.geom) ).label("geom"), func.sum(func.ST_Area(VoronoiMunicipalityCutsAssigned.geom)).label( "area" ), - ).group_by(VoronoiMunicipalityCutsAssigned.subst_id) + ).group_by(VoronoiMunicipalityCutsAssigned.bus_id) joined_municipality_parts_insert = ( MvGridDistrictsDissolved.__table__.insert().from_select( @@ -585,7 +632,7 @@ def merge_polygons_to_grid_district(): while True: previous_ids_length = len(already_assigned) with_substation = session.query( - MvGridDistrictsDissolved.subst_id, + MvGridDistrictsDissolved.bus_id, MvGridDistrictsDissolved.geom, MvGridDistrictsDissolved.id, ).subquery() @@ -615,7 +662,7 @@ def merge_polygons_to_grid_district(): # Step 4: Merge MV grid district parts # Forms one (multi-)polygon for each substation joined_mv_grid_district_parts = session.query( - MvGridDistrictsDissolved.subst_id, + MvGridDistrictsDissolved.bus_id, func.ST_Multi( func.ST_Buffer( func.ST_Buffer( @@ -625,7 +672,7 @@ def merge_polygons_to_grid_district(): ) ).label("geom"), func.sum(MvGridDistrictsDissolved.area).label("area"), - ).group_by(MvGridDistrictsDissolved.subst_id) + ).group_by(MvGridDistrictsDissolved.bus_id) joined_mv_grid_district_parts_insert = ( MvGridDistricts.__table__.insert().from_select( @@ -688,7 +735,7 @@ def nearest_polygon_with_substation( session.query( without_substation.c.id, func.ST_Multi(without_substation.c.geom).label("geom"), - with_substation.c.subst_id, + with_substation.c.bus_id, func.ST_Area(func.ST_Multi(without_substation.c.geom)).label( "area" ), @@ -718,7 +765,7 @@ def nearest_polygon_with_substation( # Take only one candidate polygon for assgning it nearest_neighbors = session.query( - all_nearest_neighbors.c.subst_id, + all_nearest_neighbors.c.bus_id, all_nearest_neighbors.c.geom, all_nearest_neighbors.c.area, ).distinct(all_nearest_neighbors.c.id) @@ -772,7 +819,7 @@ def define_mv_grid_districts(): mv_grid_districts_setup = partial( Dataset, name="MvGridDistricts", - version="0.0.1", + version="0.0.2", dependencies=[], tasks=(define_mv_grid_districts), ) diff --git a/src/egon/data/datasets/power_plants/__init__.py b/src/egon/data/datasets/power_plants/__init__.py index 90101eb0a..18af47734 100755 --- a/src/egon/data/datasets/power_plants/__init__.py +++ b/src/egon/data/datasets/power_plants/__init__.py @@ -48,7 +48,7 @@ class PowerPlants(Dataset): def __init__(self, dependencies): super().__init__( name="PowerPlants", - version="0.0.1", + version="0.0.2", dependencies=dependencies, tasks=( create_tables, @@ -509,7 +509,7 @@ def assign_bus_id(power_plants, cfg): power_plants.loc[power_plants_hv, "bus_id"] = gpd.sjoin( power_plants[power_plants.index.isin(power_plants_hv)], mv_grid_districts, - ).subst_id + ).bus_id # Assign power plants in ehv to ehv bus power_plants_ehv = power_plants[power_plants.voltage_level < 3].index diff --git a/src/egon/data/datasets/power_plants/pv_ground_mounted.py b/src/egon/data/datasets/power_plants/pv_ground_mounted.py index 9f8da5abd..84848f0c1 100644 --- a/src/egon/data/datasets/power_plants/pv_ground_mounted.py +++ b/src/egon/data/datasets/power_plants/pv_ground_mounted.py @@ -451,9 +451,9 @@ def build_additional_pv(potentials, pv, pow_per_area, con): """ # get MV grid districts - sql = "SELECT subst_id, geom FROM grid.egon_mv_grid_district" + sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" distr = gpd.GeoDataFrame.from_postgis(sql, con) - distr = distr.set_index("subst_id") + distr = distr.set_index("bus_id") # identify potential areas where there are no PV parks yet for index, pv in pv.iterrows(): @@ -910,9 +910,9 @@ def run_methodology( # 1) eGon2035 # get MV grid districts - sql = "SELECT subst_id, geom FROM grid.egon_mv_grid_district" + sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" distr = gpd.GeoDataFrame.from_postgis(sql, con) - distr = distr.set_index("subst_id") + distr = distr.set_index("bus_id") # assign pv_per_distr-power to districts distr["capacity"] = pd.Series() @@ -959,9 +959,9 @@ def run_methodology( # 2) eGon100RE # get MV grid districts - sql = "SELECT subst_id, geom FROM grid.egon_mv_grid_district" + sql = "SELECT bus_id, geom FROM grid.egon_mv_grid_district" distr = gpd.GeoDataFrame.from_postgis(sql, con) - distr = distr.set_index("subst_id") + distr = distr.set_index("bus_id") # assign pv_per_distr-power to districts distr["capacity"] = pd.Series() diff --git a/src/egon/data/datasets/power_plants/pv_rooftop.py b/src/egon/data/datasets/power_plants/pv_rooftop.py index b78d90a07..2d6d69eb9 100644 --- a/src/egon/data/datasets/power_plants/pv_rooftop.py +++ b/src/egon/data/datasets/power_plants/pv_rooftop.py @@ -79,7 +79,7 @@ def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"): demand = db.select_dataframe( f""" SELECT SUM(demand) as demand, - subst_id as bus_id, vg250_lan + b.bus_id, vg250_lan FROM {sources['electricity_demand']['schema']}. {sources['electricity_demand']['table']} a JOIN {sources['map_zensus_grid_districts']['schema']}. @@ -87,9 +87,9 @@ def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"): ON a.zensus_population_id = b.zensus_population_id JOIN {sources['map_grid_boundaries']['schema']}. {sources['map_grid_boundaries']['table']} c - ON c.bus_id = b.subst_id + ON c.bus_id = b.bus_id WHERE scenario = 'eGon2035' - GROUP BY (subst_id, vg250_lan) + GROUP BY (b.bus_id, vg250_lan) """ ) @@ -163,7 +163,7 @@ def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"): mv_grid_districts = db.select_geodataframe( f""" - SELECT subst_id as bus_id, ST_Centroid(geom) as geom + SELECT bus_id as bus_id, ST_Centroid(geom) as geom FROM {sources['egon_mv_grid_district']['schema']}. {sources['egon_mv_grid_district']['table']} """, diff --git a/src/egon/data/datasets/vg250_mv_grid_districts.py b/src/egon/data/datasets/vg250_mv_grid_districts.py index f8dcf25ed..d6f556b37 100644 --- a/src/egon/data/datasets/vg250_mv_grid_districts.py +++ b/src/egon/data/datasets/vg250_mv_grid_districts.py @@ -15,7 +15,7 @@ class Vg250MvGridDistricts(Dataset): def __init__(self, dependencies): super().__init__( name="Vg250MvGridDistricts", - version="0.0.0", + version="0.0.1", dependencies=dependencies, tasks=(mapping), ) @@ -62,7 +62,7 @@ def mapping(): # Select sources from database mv_grid_districts = db.select_geodataframe( f""" - SELECT subst_id as bus_id, ST_Centroid(geom) as geom + SELECT bus_id as bus_id, ST_Centroid(geom) as geom FROM {sources['egon_mv_grid_district']['schema']}. {sources['egon_mv_grid_district']['table']} """, diff --git a/src/egon/data/datasets/zensus_mv_grid_districts.py b/src/egon/data/datasets/zensus_mv_grid_districts.py index bf11b9229..7c8d98c79 100644 --- a/src/egon/data/datasets/zensus_mv_grid_districts.py +++ b/src/egon/data/datasets/zensus_mv_grid_districts.py @@ -17,7 +17,7 @@ class ZensusMvGridDistricts(Dataset): def __init__(self, dependencies): super().__init__( name="ZensusMvGridDistricts", - version="0.0.0", + version="0.0.1", dependencies=dependencies, tasks=(mapping), ) @@ -37,7 +37,7 @@ class MapZensusGridDistricts(Base): primary_key=True, index=True, ) - subst_id = Column(Integer, ForeignKey(MvGridDistricts.subst_id)) + bus_id = Column(Integer, ForeignKey(MvGridDistricts.bus_id)) def mapping(): @@ -64,7 +64,7 @@ def mapping(): ) grid_districts = db.select_geodataframe( - f"""SELECT subst_id, geom + f"""SELECT bus_id, geom FROM {cfg['sources']['egon_mv_grid_district']['schema']}. {cfg['sources']['egon_mv_grid_district']['table']}""", geom_col="geom", @@ -75,7 +75,7 @@ def mapping(): join = gpd.sjoin(zensus, grid_districts, how="inner", op="intersects") # Insert results to database - join[["zensus_population_id", "subst_id"]].to_sql( + join[["zensus_population_id", "bus_id"]].to_sql( cfg["targets"]["map"]["table"], schema=cfg["targets"]["map"]["schema"], con=db.engine(),