Skip to content

Commit

Permalink
Merge pull request #390 from openego/grid_run_new_v
Browse files Browse the repository at this point in the history
Branch wich produces succesfull 98% of german grids
  • Loading branch information
mltja authored Apr 3, 2023
2 parents f98aa79 + eb8d0b7 commit 0d9288b
Show file tree
Hide file tree
Showing 12 changed files with 808 additions and 108 deletions.
2 changes: 2 additions & 0 deletions ding0/config/config_calc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ frequency = 50
# LV nominal voltage: unit: V
lv_nominal_voltage = 400

# LV standard line: unit: -
lv_standard_line = NAYY 4x1x150

# LV grids (house holds): unit: -
apartment_house_branch_ratio = 1.5
Expand Down
4 changes: 4 additions & 0 deletions ding0/config/config_db_tables.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ egon_industrial_sites = demand.egon_industrial_sites
egon_osm_ind_load_curves_individual = demand.egon_osm_ind_load_curves_individual
osm_landuse = openstreetmap.osm_landuse
# Generators
# Renewable
generators_pv = supply.egon_power_plants_pv
generators_pv_rooftop = supply.egon_power_plants_pv_roof_building
generators_wind = supply.egon_power_plants_wind
generators_biomass = supply.egon_power_plants_biomass
generators_water = supply.egon_power_plants_hydro
# Conventional
generators_combustion = supply.egon_power_plants_combustion
generators_gsgk = supply.egon_power_plants_gsgk
# Weather cells
weather_cells = supply.egon_era5_weather_cells

Expand Down
113 changes: 55 additions & 58 deletions ding0/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,21 +757,35 @@ def import_lv_load_areas_and_build_new_lv_districts(
graph = build_graph_from_ways(ways_sql_df)
# Get nodes to remove from graph (per buffer polygon).
# "outlier_nodes_list" is a list of lists
outlier_nodes_list = graph_nodes_outside_buffer_polys(graph, ways_sql_df, buffer_poly_list)
outlier_nodes_list = graph_nodes_outside_buffer_polys(
graph, ways_sql_df, buffer_poly_list
)

# If no osm ways data could be found create synthetic graph.
inner_node_list = list(set(graph.nodes()) - set(outlier_nodes_list[0]))
build_synthetic_graph = False
if len(inner_node_list) < 1:
logger.warning(
f"No graph found in origin polygon of MV {mv_grid_district}, "
f"LA {id_db}. Build synthetic graph"
)
build_synthetic_graph = True
else:
build_synthetic_graph = True
# If no osm ways data could be found create synthetic graph.
# or no inner_nodes_are_found
if build_synthetic_graph:
# Create synthetic graph with one street node instead.
graph, node_id = create_simple_synthetic_graph(geo_load_area)
# No outlier nodes in synthetic graph, nested list must be empty.
outlier_nodes_list = [[]]
logger.warning(f'ways_sql_df.empty. No ways found in '
f'MV {mv_grid_district}, LA {id_db} '
f'Build synthetic graph instead.')
logger.warning(
f"ways_sql_df.empty. No ways found in "
f"MV {mv_grid_district}, LA {id_db} "
f"Build synthetic graph instead."
)

# Inner_node_list define nodes without buffer.
inner_node_list = list(set(graph.nodes()) - set(outlier_nodes_list[0]))

if len(inner_node_list) < 1:
logger.warning(f'No graph found in origin polygon of MV {mv_grid_district}, LA {id_db}.')
continue
Expand Down Expand Up @@ -1238,45 +1252,61 @@ def import_generators(self, session, debug=False):
:meth:`~.core.NetworkDing0.connect_generators`
"""

def import_res_generators():
def import_generators():
"""
Imports renewable (res) generators
"""
generators = db_io.get_res_generators(self.orm, session, list(mv_grid_districts_dict.values())[0])
logger.debug(f"Import {generators.shape[0]} renewable generators.")
for id_db, row in generators.iterrows():
ren_generators = db_io.get_res_generators(self.orm, session, list(
mv_grid_districts_dict.values())[0])
conv_generators = db_io.get_conv_generators(self.orm, session, list(
mv_grid_districts_dict.values())[0])
generators = pd.concat([ren_generators, conv_generators]).reset_index(
drop=True).to_dict(orient="index")

logger.debug(f"Import {len(generators)} renewable generators.")
for id_db, row in generators.items():

# look up MV grid
mv_grid_district_id = row['subst_id']
mv_grid = mv_grid_districts_dict[mv_grid_district_id].mv_grid

if pd.notna(row["building_id"]):
building_id = int(row["building_id"])
else:
building_id = None
for key, value in row.items():
if pd.isna(value):
row[key] = None
elif key in ['voltage_level', 'w_id', 'building_id']:
row[key] = int(value)
elif key in ['electrical_capacity']:
row[key] = float(value)
elif key in ["gens_id"]:
row[key] = str(value)
elif key in ["geom"]:
row[key] = wkt_loads(value)

# create generator object
if row['generation_type'] in ['solar', 'wind']:
generator = GeneratorFluctuatingDing0(
id_db=id_db,
mv_grid=mv_grid,
capacity=float(row['electrical_capacity']),
capacity=row['electrical_capacity'],
type=row['generation_type'],
subtype=row['generation_subtype'],
v_level=int(row['voltage_level']),
weather_cell_id=int(row['w_id']),
building_id=building_id,
geo_data=wkt_loads(row['geom'])
v_level=row['voltage_level'],
weather_cell_id=row['w_id'],
building_id=row['building_id'],
gens_id=row['gens_id'],
geo_data=row['geom']
)
else:
generator = GeneratorDing0(
id_db=id_db,
mv_grid=mv_grid,
capacity=float(row['electrical_capacity']),
capacity=row['electrical_capacity'],
type=row['generation_type'],
subtype=row['generation_subtype'],
v_level=int(row['voltage_level']),
building_id=building_id,
geo_data=wkt_loads(row['geom'])
v_level=row['voltage_level'],
building_id=row['building_id'],
gens_id=row['gens_id'],
geo_data=row['geom'],
)

# MV generators
Expand All @@ -1289,35 +1319,6 @@ def import_res_generators():
else:
ValueError("False voltage level")

def import_conv_generators():
"""
Imports conventional (conv) generators
"""
generators = db_io.get_conv_generators(self.orm, session, list(mv_grid_districts_dict)[0])

for id_db, row in generators.iterrows():

# look up MV grid
mv_grid_district_id = row['subst_id']
mv_grid = mv_grid_districts_dict[mv_grid_district_id].mv_grid

# create generator object
generator = GeneratorDing0(id_db=id_db,
name=row['name'],
geo_data=wkt_loads(row['geom']),
mv_grid=mv_grid,
capacity=row['capacity'],
type=row['fuel'],
subtype='unknown',
v_level=int(row['voltage_level']))

# add generators to graph
if generator.v_level in [4, 5]:
mv_grid.add_generator(generator)
# there's only one conv. geno with v_level=6 -> connect to MV grid
elif generator.v_level in [6]:
generator.v_level = 5
mv_grid.add_generator(generator)

# get ding0s' standard CRS (SRID)
srid = str(int(cfg_ding0.get('geo', 'srid')))
Expand All @@ -1332,11 +1333,7 @@ def import_conv_generators():
lv_grid_districts_dict, \
lv_stations_dict = self.get_mvgd_lvla_lvgd_obj_from_id()

# import renewable generators
import_res_generators()

# import conventional generators
import_conv_generators()
import_generators()

logger.info('=====> Generators imported')

Expand Down Expand Up @@ -1505,7 +1502,7 @@ def import_orm(self, session):

orm = {}
data_source = self.config['input_data_source']['input_data']
engine = database.engine()
engine = database.get_engine()

def write_table_in_dict(orm, engine, name, table_str):
table_list = table_str.split(".")
Expand Down
1 change: 1 addition & 0 deletions ding0/core/network/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ def __init__(self, **kwargs):
self.v_level = kwargs.get('v_level', None)

self.building_id = kwargs.get('building_id', None)
self.gens_id = kwargs.get('gens_id', None)

@property
def network(self):
Expand Down
Loading

0 comments on commit 0d9288b

Please sign in to comment.