How to use ding0?

Examples

We provide two examples of how to use Ding0 along with two example for analysis of resulting data. The first example shows how Ding0 is applied to a single medium-voltage grid district. Grid topology for the medium- and low-voltage grid level is generated and saved to a file (.pkl). The analysis script takes data generated in the first example and produces exemplary key figures and plots.

The second example shows how to generate a larger number of grid topology data sets. As the current data source sometimes produces unuseful data or leads to program execution interruptions, grids that cannot be created are excluded from grid topology generation. This is enable by setting failsafe= to True. The according analysis script provides exemplary plots for data of multiple grid districts.

High-level functions

Run ding0

Check out run_ding0() as high-level function which is also used in the example.

For larger calculation (parallelization)

To generate data for a larger area consider to parallelize execution of Ding0 as done in the parallelization example.

Analysis of grid data

Plot results

The plot_mv_topology() allows plots of the MV grid including grid topology with line loadings and node voltages. You can simply fire it using an MVGrid instance or pass argument export_figures=True to run_ding0() to export some key plots. The plotting allows to draw a background map. For this function, the package contextily is needed which is not included in the standard ding0 installation. If you want to use this feature, you can simply install it by

pip3 install contextily

See plotting function for a detailed description of possible modes and parameters.

Example plot:

_images/mvgd_plot_example1.png

Export key figures

We provide a set of functions to export key figures of the generated data. The following assumes a Ding0 network is generated as follows:

from egoio.tools import db
from ding0.core import NetworkDing0

engine = db.connection(readonly=True)
session = sessionmaker(bind=engine)()

network = NetworkDing0(name='network')
network.run_ding0(
    session=session,
    mv_grid_districts_no=[3040])

Extract key information about medium and low voltage grid topology.

from ding0.tools.results import calculate_mvgd_stats

# statistical key figures of medium voltage grid
mv_stats = calculate_mvgd_stats(network)

# statistical key figures of medium voltage grid
lv_stats = calculate_lvgd_stats(network)

Information about power flows and voltage levels from final approving power flow analysis can be obtained from calculate_mvgd_voltage_current_stats() and calculate_lvgd_voltage_current_stats().

If a large number of grid districts is involved consider to parallelize the execution by

mv_stats,
 lvgd_stat
 mv_nodes,
 mv_edges,
 lv_nodes,
 lv_edges = parallel_running_stats(
    districts_list = mv_grid_districts,
    n_of_processes = n_of_processes,
    n_of_districts = n_of_districts,
    source = 'pkl',
    mode = '')

Data is read from file and returned in six tables.

Furthermore, the function to_dataframe() allows to get tabular information about nodes and edges of the grid topology representing graph.

nodes, edges = network.to_dataframe()

Compare data versions

Data generated by different versions of Ding0 or different input data can be easily compared. Load datasets designated for comparison and pass to dataframe_equal().

network_a = load_nd_from_pickle(filename='filename_a.pkl')
network_b = load_nd_from_pickle(filename='filename_b.pkl')

passed, msg = dataframe_equal(network_a, network_b)

Explanation of key figures

Parameter Description Unit
km_cable Cumulative length of underground cables km

CSV file export

Ding0 objects are exported in csv files.

Lines

Table 1 line.csv
Field type Description Unit
edge_name str unambiguous name of edge n/a
grid_id_db int unambiguous id_db of corresponding grid (MVgrid-id if MV-edge, LVgrid-id if LV-edge n/a
type_kind str   n/a
type_name str   n/a
node1 str id_db of first node n/a
node2 str id_db of second node n/a
length float length of line km
U_n float nominal voltage kV
R float   Ohm/km
C float   uF/km
L float   mH/km
I_max_th float   A
run_id int time and date of table generation yyyyMMddhhmmss

LV-Branchtees

Table 2 lv_branchtee.csv
Field type Description Unit
id_db str unambiguous name: ‘LVCableDistributorDing0_LV_#lvgridid#_#ascendingnumber#’ n/a
LV_grid_id_db int unambiguous id_db of LV-Grid n/a
geom None geometric coordinates n/a
run_id int time and date of table generation yyyyMMddhhmmss

LV-Generators

Table 3 lv_generator.csv
Field type Description Unit
id_db str unambiguous name: ‘LVGeneratorDing0_LV_#lvgridid#_#ascendingnumber#’ n/a
LV_grid_id_db int unambiguous id_db of LV-Grid n/a
geom wkt geometric coordinates WGS84 POINT
type str type of generation {solar; biomass}
subtype str subtype of generation: {solar_roof_mounted, unknown; biomass} n/a
v_level int voltage level of generator  
nominal_capacity float nominal capacity  
run_id int time and date of table generation yyyyMMddhhmmss

LV-Grids

Table 4 lv_grid.csv
Field type Description Unit
id_db str unambiguous name: ‘LVGridDing0_LV_#lvgridid#_#lvgridid#’ n/a
LV_grid_id int unambiguous number of LV-Grid n/a
geom wkt geometric coordinates WGS84 MULTIPOLYGON
population int population in LV-Grid ?
voltage_nom float voltage level of grid kV
run_id int time and date of table generation yyyyMMddhhmmss

LV-Loads

Table 5 lv_load.csv
Field type Description Unit
id_db str unambiguous name: ‘LVLoadDing0_LV_#lvgridid#_#ascendingnumber#’ n/a
LV_grid_id_db int unambiguous id_db of LV-Grid n/a
geom None geometric coordinates n/a
consumption {‘’str’’: float} type of load {residential, agricultural, industrial} and corresponding consumption n/a
run_id int time and date of table generation yyyyMMddhhmmss

LV-Stations

Table 6 lvmv_station.csv
Field type Description Unit
id_db str unambiguous name: ‘LVStationDing0_MV_#mvgridid#_#lvgridid#’ n/a
LV_grid_id_db int unambiguous id_db of LV-Grid n/a
geom wkt geometric coordinates WGS84 POINT
run_id int time and date of table generation yyyyMMddhhmmss

LV-Transformers

Table 7 lv_transformer.csv
Field type Description Unit
id_db str unambiguous name: ‘TransformerDing0_LV_#mvgridid#_#lvgridid#’ n/a
LV_grid_id_db int unambiguous id_db of LV-Grid n/a
geom wkt geometric coordinates WGS84 POINT
voltage_op float   kV
S_nom float nominal apparent power kVA
X float   Ohm
R float   Ohm
run_id int time and date of table generation yyyyMMddhhmmss

LV-Grids

Table 8 mvlv_mapping.csv
Field type Description Unit
LV_grid_id int unambiguous number of LV-Grid n/a
MV_grid_id int unambiguous number of MV-Grid n/a
LV_grid_id_db int unambiguous id_db of LV-Grid n/a
MV_grid_id_db int unambiguous id_db of MV-Grid n/a
run_id int time and date of table generation yyyyMMddhhmmss

MV-Branchtees

Table 9 mv_branchtee.csv
Field type Description Unit
id_db str unambiguous name: ‘MVCableDistributorDing0_MV_#mvgridid#_#ascendingnumber#’ n/a
MV_grid_id_db int unambiguous id_db of MV-Grid n/a
geom wkt geometric coordinates WGS84 POINT
run_id int time and date of table generation yyyyMMddhhmmss

MV-Generators

Table 10 mv_generator.csv
Field type Description Unit
id_db str unambiguous name: ‘MVGeneratorDing0_MV_#mvgridid#_#ascendingnumber#’ n/a
MV_grid_id_db int unambiguous id_db of MV-Grid n/a
geom wkt geometric coordinates WGS84 POINT
type str type of generation: {solar; biomass} n/a
subtype str subtype of generation: {solar_ground_mounted, solar_roof_mounted, unknown; biomass, biogas} n/a
v_level int voltage level of generator  
nominal_capacity float nominal capacity  
run_id int time and date of table generation yyyyMMddhhmmss

MV-Grids

Table 11 mv_grid.csv
Field type Description Unit
id_db str unambiguous name: ‘MVGridDing0_MV_#mvgridid#_#mvgridid#’ n/a
MV_grid_id int unambiguous number of LV-Grid n/a
geom wkt geometric coordinates WGS84 MULTIPOLYGON
population int population in LV-Grid ?
voltage_nom float voltage level of grid kV
run_id int time and date of table generation yyyyMMddhhmmss

MV-Loads

Table 12 mv_load.csv
Field type Description Unit
id_db str unambiguous name: ‘MVLoadDing0_MV_#mvgridid#_#ascendingnumber#’ n/a
MV_grid_id_db int unambiguous id_db of MV-Grid n/a
geom wkt geometric coordinates WGS84 POLYGON
consumption {‘’str’’: float} type of load {retail, residential, agricultural, industrial} and corresponding consumption n/a
is_aggregated boolean True if load is aggregated load, else False n/a
run_id int time and date of table generation yyyyMMddhhmmss

MV-Stations

Table 13 mvhv_station.csv
Field type Description Unit
id_db str unambiguous name: ‘MVStationDing0_MV_#mvgridid#_#mvgridid#’ n/a
MV_grid_id_db int unambiguous id_db of MV-Grid n/a
geom wkt geometric coordinates WGS84 POINT
run_id int time and date of table generation yyyyMMddhhmmss

MV-Transformers

Table 14 lv_transformer.csv
Field type Description Unit
id_db str unambiguous name: ‘TransformerDing0_MV_#mvgridid#_#mvgridid#’ n/a
MV_grid_id_db int unambiguous id_db of LV-Grid n/a
geom wkt geometric coordinates WGS84 POINT
voltage_op float   kV
S_nom float nominal apparent power kVA
X float   Ohm
R float   Ohm
run_id int time and date of table generation yyyyMMddhhmmss