ding0.core package

Module contents

class ding0.core.NetworkDing0(**kwargs)[source]

Bases: object

Defines the DING0 Network - not a real grid but a container for the MV-grids. Contains the NetworkX graph and associated attributes.

This object behaves like a location to store all the constituent objects required to estimate the grid topology of a give set of shapes that need to be connected.

The most important function that defines ding0’s use case is initiated from this class i.e. run_ding0().

Parameters:
  • name (str) – A name given to the network. This defaults to Network.
  • run_id (str) – A unique identification number to identify different runs of Ding0. This is usually the date and the time in some compressed format. e.g. 201901010900.
mv_grid_districts[source]

Contains the MV Grid Districts where the topology has to be estimated A list of MVGridDistrictDing0 objects whose data is stored in the current instance of the NetworkDing0 Object. By default the list is empty. MV grid districts can be added by using the function add_mv_grid_district(). This is done within the function build_mv_grid_district() in the normal course upon calling run_ding0().

Type:list iterator
config

These are the configurations that are required for the construction of the network topology given the areas to be connected together. The configuration is imported by calling import_config(). The configurations are stored in text files within the ding0 package in the config folder. These get imported into a python dictionary-like configuration object.

Type:dict
pf_config

These are the configuration of the power flows that are run to ensure that the generated network is plausible and is capable of a reasonable amount of loading without causing any grid issues. This object cannot be set at inititation, it gets set by the function import_pf_config() which takes the configurations from :attr:_config and sets up the configurations for running power flow calculations.

Type:PFConfigDing0
static_data

Data such as electrical and mechanical properties of typical assets in the energy system are stored in ding0. These are used in many parts of ding0’s calculations. Data values:

  • Typical cable types, and typical line types’ electrical impedences,
    thermal ratings, operating voltage level.
  • Typical transformers types’ electrical impedences, voltage drops,
    thermal ratings, winding voltages
  • Typical LV grid topologies’ line types, line lengths and
    distribution
Type:dict
orm

The connection parameters to the OpenEnergy Platform and the tables and datasets required for the functioning of ding0

Type:dict
add_mv_grid_district(mv_grid_district)[source]

A method to add mv_grid_districts to the NetworkDing0 Object by adding it to the mv_grid_districts.

build_lv_grid_district(lv_load_area, lv_grid_districts, lv_stations)[source]

Instantiates and associates lv_grid_district incl grid and station.

The instantiation creates more or less empty objects including relevant data for transformer choice and grid creation

Parameters:
build_lv_grids()[source]

Builds LV grids for every non-aggregated LA in every MV grid district using model grids.

build_mv_grid_district(poly_id, subst_id, grid_district_geo_data, station_geo_data)[source]

Initiates single MV grid_district including station and grid

Parameters:
  • poly_id (int) – ID of grid_district according to database table. Also used as ID for created grid #TODO: check type
  • subst_id (int) – ID of station according to database table #TODO: check type
  • grid_district_geo_data (Shapely Polygon object) – Polygon of grid district, The geo-spatial polygon in the coordinate reference system with the SRID:4326 or epsg:4326, this is the project used by the ellipsoid WGS 84.
  • station_geo_data (Shapely Point object) – Point of station. The geo-spatial point in the coordinate reference system with the SRID:4326 or epsg:4326, this is the project used by the ellipsoid WGS 84.
Returns:

MVGridDistrictDing0

config

Getter for the configuration dictionary.

Returns:dict
connect_generators(debug=False)[source]

Connects generators (graph nodes) to grid (graph) for every MV and LV Grid District

Parameters:debug (bool, defaults to False) – If True, information is printed during process.
control_circuit_breakers(mode=None)[source]

Opens or closes all circuit breakers of all MV grids.

Parameters:mode (str) – Set mode=’open’ to open, mode=’close’ to close
export_mv_grid(session, mv_grid_districts)[source]

Exports MV grids to database for visualization purposes

Parameters:
export_mv_grid_new(session, mv_grid_districts)[source]

Exports MV grids to database for visualization purposes

Parameters:
get_mvgd_lvla_lvgd_obj_from_id()[source]

Build dict with mapping from:

Returns:
  • dict

    mv_grid_districts_dict:

    {
      mv_grid_district_id_1: mv_grid_district_obj_1,
      ...,
      mv_grid_district_id_n: mv_grid_district_obj_n
    }
    
  • dict

    lv_load_areas_dict:

    {
      lv_load_area_id_1: lv_load_area_obj_1,
      ...,
      lv_load_area_id_n: lv_load_area_obj_n
    }
    
  • dict

    lv_grid_districts_dict:

    {
      lv_grid_district_id_1: lv_grid_district_obj_1,
      ...,
      lv_grid_district_id_n: lv_grid_district_obj_n
    }
    
  • dict

    lv_stations_dict:

    {
      lv_station_id_1: lv_station_obj_1,
      ...,
      lv_station_id_n: lv_station_obj_n
    }
    
import_config()[source]

Loads parameters from config files

Returns:dict – configuration key value pair dictionary
import_generators(session, debug=False)[source]

Imports renewable (res) and conventional (conv) generators

Parameters:

Note

Connection of generators is done later on in NetworkDing0’s method connect_generators()

import_lv_grid_districts(session, lv_stations)[source]

Imports all lv grid districts within given load area

Parameters:session (SQLAlchemy session object) – Database session
Returns:lv_grid_districts (pandas.DataFrame) – Table of lv_grid_districts
import_lv_load_areas(session, mv_grid_district, lv_grid_districts, lv_stations)[source]

Imports load_areas (load areas) from database for a single MV grid_district

Parameters:
  • session (SQLAlchemy session object) – Database session
  • mv_grid_district (MV grid_district/station (instance of MVGridDistrictDing0 class) for) – which the import of load areas is performed
  • lv_grid_districts (pandas.DataFrame) – LV grid districts within this mv_grid_district
  • lv_stations (pandas.DataFrame) – LV stations within this mv_grid_district
import_lv_stations(session)[source]

Import lv_stations within the given load_area

Parameters:session (SQLAlchemy session object) – Database session
Returns:lv_stations (pandas.DataFrame) – Table of lv_stations
import_mv_grid_districts(session, mv_grid_districts_no=None)[source]

Imports MV Grid Districts, HV-MV stations, Load Areas, LV Grid Districts and MV-LV stations, instantiates and initiates objects.

Parameters:
  • session (sqlalchemy.orm.session.Session) – Database session
  • mv_grid_districts (list of int) – List of MV grid_districts/stations (int) to be imported (if empty, all grid_districts & stations are imported)

See also

build_mv_grid_district()
used to instantiate MV grid_district objects
import_lv_load_areas()
used to import load_areas for every single MV grid_district
ding0.core.structure.regions.MVGridDistrictDing0.add_peak_demand()
used to summarize peak loads of underlying load_areas
import_orm()[source]

Import ORM classes names for the correct connection to open energy platform and access tables depending on input in config in self.config which is loaded from ‘config_db_tables.cfg’

Returns:obj: dict – key value pairs of names of datasets versus sqlalchmey maps to acess various tables where the datasets used to build grids are stored on the open energy platform.
import_pf_config()[source]

Creates power flow config class and imports config from file

Returns:PFConfigDing0
import_static_data()[source]

Imports static data into NetworkDing0 such as equipment.

Returns:obj: dict – Dictionary with equipment data
list_generators(session)[source]

List renewable (res) and conventional (conv) generators

Parameters:session (SQLAlchemy session object) – Database session
Returns:pandas.DataFrame – A table containing the generator data, the columns being: - subst_id, - la_id (load area id), - mv_lv_subst_id (id of the mv lv substation), - electrical_capacity - generation_type - generation_subtype - voltage_level - geospatial coordinates as Shapely Point object
list_load_areas(session, mv_districts)[source]

list load_areas (load areas) peak load from database for a single MV grid_district

Parameters:
list_lv_grid_districts(session, lv_stations)[source]

Imports all lv grid districts within given load area

Parameters:
Returns:

pandas.DataFrame – Pandas Data Frame Table of lv_grid_districts

metadata

Provide metadata on a Ding0 run

Parameters:run_id (str, (defaults to current date)) – Distinguish multiple versions of Ding0 data by a run_id. If not set it defaults to current date in the format YYYYMMDDhhmmss
Returns:dict – Metadata
mv_grid_districts()[source]

A generator for iterating over MV grid_districts

Returns:list iterator – A list iterator containing the MVGridDistrictDing0 objects.
mv_parametrize_grid(debug=False)[source]

Performs Parametrization of grid equipment of all MV grids.

Parameters:debug (:obj:bool, defaults to False) – If True, information is printed during process.
mv_routing(debug=False, animation=False)[source]

Performs routing on all MV grids.

Parameters:
  • debug (bool, default to False) – If True, information is printed while routing
  • animation (bool, default to False) – If True, images of route modification steps are exported during routing process. A new animation object is created.

See also

ding0.core.network.grids.MVGridDing0.routing()
for details on MVGridDing0 objects routing
ding0.tools.animation.AnimationDing0()
for details on animation function.
orm

Getter for the stored ORM configurations.

Returns:obj: dict
pf_config

Getter for the power flow calculation configurations.

Returns:PFConfigDing0
reinforce_grid()[source]

Performs grid reinforcement measures for all MV and LV grids

run_ding0(session, mv_grid_districts_no=None, debug=False, export_figures=False)[source]

Let DING0 run by shouting at this method (or just call it from NetworkDing0 instance). This method is a wrapper for the main functionality of DING0.

Parameters:
  • session (sqlalchemy.orm.session.Session) – Database session
  • mv_grid_districts_no (list of int objects.) – List of MV grid_districts/stations to be imported (if empty, all grid_districts & stations are imported)
  • debug (obj:bool, defaults to False) – If True, information is printed during process
  • export_figures (bool, defaults to False) – If True, figures are shown or exported (default path: ~/.ding0/) during run.
Returns:

msg (obj:str) – Message of invalidity of a grid district

Note

The steps performed in this method are to be kept in the given order since there are hard dependencies between them. Short description of all steps performed:

  • STEP 1: Import MV Grid Districts and subjacent objects

    Imports MV Grid Districts, HV-MV stations, Load Areas, LV Grid Districts and MV-LV stations, instantiates and initiates objects.

  • STEP 2: Import generators

    Conventional and renewable generators of voltage levels 4..7 are imported and added to corresponding grid.

  • STEP 3: Parametrize grid

    Parameters of MV grid are set such as voltage level and cable/line types according to MV Grid District’s characteristics.

  • STEP 4: Validate MV Grid Districts

    Tests MV grid districts for validity concerning imported data such as count of Load Areas.

  • STEP 5: Build LV grids

    Builds LV grids for every non-aggregated LA in every MV Grid District using model grids.

  • STEP 6: Build MV grids

    Builds MV grid by performing a routing on Load Area centres to build ring topology.

  • STEP 7: Connect MV and LV generators

    Generators are connected to grids, used approach depends on voltage level.

  • STEP 8: Relocate switch disconnectors in MV grid

    Switch disconnectors are set during routing process (step 6) according to the load distribution within a ring. After further modifications of the grid within step 6+7 they have to be relocated (note: switch disconnectors are called circuit breakers in DING0 for historical reasons).

  • STEP 9: Open all switch disconnectors in MV grid

    Under normal conditions, rings are operated in open state (half-rings). Furthermore, this is required to allow powerflow for MV grid.

  • STEP 10: Do power flow analysis of MV grid

    The technically working MV grid created in step 6 was extended by satellite loads and generators. It is finally tested again using powerflow calculation.

  • STEP 11: Reinforce MV grid

    MV grid is eventually reinforced persuant to results from step 11.

  • STEP 12: Close all switch disconnectors in MV grid

    The rings are finally closed to hold a complete graph (if the SDs are open, the edges adjacent to a SD will not be exported!)

run_powerflow(session=None, method='onthefly', only_calc_mv=True, export_pypsa=False, debug=False, export_result_dir=None)[source]

Performs power flow calculation for all MV grids

Parameters:
  • session (SQLAlchemy session object) – Database session
  • method (str) –

    Specify export method If method=’db’ grid data will be exported to database

    If method=’onthefly’ grid data will be passed to PyPSA directly (default)

  • export_pypsa (bool) – If True PyPSA networks will be exported as csv to output/debug/grid/<MV-GRID_NAME>/
  • debug (bool, defaults to False) – If True, information is printed during process
set_circuit_breakers(debug=False)[source]

Calculates the optimal position of the existing circuit breakers and relocates them within the graph for all MV grids.

Parameters:debug (bool, defaults to False) – If True, information is printed during process
static_data

Getter for the static data

Returns:obj: dict
to_csv(dir='', only_export_mv=False)[source]

Function to export network to csv. Converts network in dataframes which are adapted to pypsa format. Respectively saves files for network, buses, lines, transformers, loads and generators.

Parameters:
  • dir (str) – Directory to which network is saved.
  • only_export_mv (bool) – When True only mv topology is exported with aggregated lv grid districts
to_dataframe(only_export_mv=False)[source]

Function to export network to csv. Converts network in dataframes which are adapted to pypsa format. Respectively saves files for network, buses, lines, transformers, loads and generators.

Parameters:only_export_mv (bool) – When True only mv topology is exported with aggregated lv grid districts
to_dataframe_old()[source]

Todo: remove? or replace by part of to_csv() Export grid data to dataframes for statistical analysis.

The export to dataframe is similar to db tables exported by export_mv_grid_new.

Returns:pandas.DataFrame – Pandas Data Frame
validate_grid_districts()[source]

Method to check the validity of the grid districts. MV grid districts are considered valid if:

  1. The number of nodes of the graph should be greater than 1
  2. All the load areas in the grid district are NOT tagged as aggregated load areas.

Invalid MV grid districts are subsequently deleted from Network.