ding0.tools package¶
Submodules¶
ding0.tools.animation module¶
-
class
ding0.tools.animation.
AnimationDing0
(**kwargs)[source]¶ Bases:
object
Class for visual animation of the routing process (solving CVRP).
(basically a central place to store information about output file and count of saved images). Use argument ‘animation=True’ of method ‘NetworkDing0.mv_routing()’ to enable image export. The images are exported to ding0’s home dir which is usually ~/.ding0/ .
Subsequently, FFMPEG can be used to convert images to animation, e.g.
ffmpeg -r 5 -i mv-routing_ani_%04d.png -vframes 200 -r 15 -vcodec libx264 -y -an mv-routing_ani.mp4 -s 640x480See also
ding0.tools.config module¶
Based on code by oemof development team
This module provides a highlevel layer for reading and writing config files. The config file has to be of the following structure to be imported correctly.
[netCDF]
RootFolder = c://netCDF
FilePrefix = cd2_
[mySQL]
host = localhost
user = guest
password = root
database = znes
[SectionName]
OptionName = value
Option2 = value2
Based on code by oemof development team
-
ding0.tools.config.
get
(section, key)[source]¶ Returns the value of a given key of a given section of the main config file.
Parameters: Returns: float
– the value which will be casted to float, int or boolean. if no cast is successful, the raw string will be returned.See also
ding0.tools.debug module¶
-
ding0.tools.debug.
compare_graphs
(graph1, mode, graph2=None)[source]¶ Compares graph with saved one which is loaded via networkx’ gpickle
Parameters: - graph1 (networkx.graph) – First Ding0 MV graph for comparison
- graph2 (networkx.graph) – Second Ding0 MV graph for comparison. If a second graph is not provided it will be laoded from disk with hard-coded file name.
- mode ('write' or 'compare') –
- Returns –
ding0.tools.geo module¶
-
ding0.tools.geo.
calc_geo_branches_in_buffer
(node, mv_grid, radius, radius_inc, proj)[source]¶ Determines branches in nodes’ associated graph that are at least partly within buffer of radius from node.
If there are no nodes, the buffer is successively extended by radius_inc until nodes are found.
Parameters: - node (LVStationDing0, GeneratorDing0, or CableDistributorDing0) – origin node (e.g. LVStationDing0 object) with associated shapely object (attribute geo_data) in any CRS (e.g. WGS84)
- radius (float) – buffer radius in m
- radius_inc (float) – radius increment in m
- proj (
int
) – pyproj projection object: nodes’ CRS to equidistant CRS (e.g. WGS84 -> ETRS)
Returns: list
of NetworkX Graph Obj – List of branches (NetworkX branch objects)
-
ding0.tools.geo.
calc_geo_branches_in_polygon
(mv_grid, polygon, mode, proj)[source]¶ Calculate geographical branches in polygon.
For a given mv_grid all branches (edges in the graph of the grid) are tested if they are in the given polygon. You can choose different modes and projections for this operation.
Parameters: - mv_grid (
MVGridDing0
) – MV Grid object. Edges contained in mv_grid.graph_edges() are taken for the test. - polygon (Shapely Point object) – Polygon that contains edges.
- mode (
str
) – Choose between ‘intersects’ or ‘contains’. - proj (
int
) – EPSG code to specify projection
Returns: list
ofBranchDing0
objects – List of branches- mv_grid (
-
ding0.tools.geo.
calc_geo_centre_point
(node_source, node_target)[source]¶ Calculates the geodesic distance between node_source and node_target incorporating the detour factor specified in config_calc.cfg.
Parameters: - node_source (LVStationDing0, GeneratorDing0, or CableDistributorDing0) – source node, member of GridDing0.graph
- node_target (LVStationDing0, GeneratorDing0, or CableDistributorDing0) – target node, member of GridDing0.graph
Returns: float
– Distance in m.
-
ding0.tools.geo.
calc_geo_dist
(node_source, node_target)[source]¶ Calculates the geodesic distance between node_source and node_target incorporating the detour factor specified in
ding0/ding0/config/config_calc.cfg
.Parameters: - node_source (LVStationDing0, GeneratorDing0, or CableDistributorDing0) – source node, member of GridDing0.graph
- node_target (LVStationDing0, GeneratorDing0, or CableDistributorDing0) – target node, member of GridDing0.graph
Returns: float
– Distance in m
-
ding0.tools.geo.
calc_geo_dist_matrix
(nodes_pos)[source]¶ Calculates the geodesic distance between all nodes in nodes_pos incorporating the detour factor in config_calc.cfg.
For every two points/coord it uses geopy’s geodesic function. As default ellipsoidal model of the earth WGS-84 is used. For more options see
https://geopy.readthedocs.io/en/stable/index.html?highlight=geodesic#geopy.distance.geodesic
Parameters: nodes_pos (dict) – dictionary of nodes with positions, with x=longitude, y=latitude, and the following format:
{ 'node_1': (x_1, y_1), ..., 'node_n': (x_n, y_n) }
Returns: dict
–dictionary with distances between all nodes (in km), with the following format:
{ 'node_1': {'node_1': dist_11, ..., 'node_n': dist_1n}, ..., 'node_n': {'node_1': dist_n1, ..., 'node_n': dist_nn} }
ding0.tools.logger module¶
-
ding0.tools.logger.
create_dir
(dirpath)[source]¶ Create directory and report about it
Parameters: dirpath ( str
) – Directory including path
-
ding0.tools.logger.
create_home_dir
(ding0_path=None)[source]¶ Check if ~/.ding0 exists, otherwise create it
Parameters: ding0_path ( str
) – Path to store Ding0 related data (logging, etc)
ding0.tools.plots module¶
-
ding0.tools.plots.
plot_mv_topology
(grid, subtitle='', filename=None, testcase='load', line_color=None, node_color='type', limits_cb_lines=None, limits_cb_nodes=None, background_map=True)[source]¶ Draws MV grid graph using networkx
Parameters: - grid (
MVGridDing0
) – MV grid to plot. - subtitle (
str
) – Extend plot’s title by this string. - filename (
str
) – If provided, the figure will be saved and not displayed (default path: ~/.ding0/). A prefix is added to the file name. - testcase (
str
) –Defines which case is to be used. Refer to config_calc.cfg to see further assumptions for the cases. Possible options are:
- ’load’ (default) Heavy-load-flow case
- ’feedin’ Feedin-case
- line_color (
str
) –Defines whereby to choose line colors. Possible options are:
- ’loading’ Line color is set according to loading of the line in heavy load case. You can use parameter limits_cb_lines to adjust the color range.
- None (default) Lines are plotted in black. Is also the fallback option in case of wrong input.
- node_color (
str
) –Defines whereby to choose node colors. Possible options are:
- ’type’ (default) Node color as well as size is set according to type of node (generator, MV station, etc.). Is also the fallback option in case of wrong input.
- ’voltage’ Node color is set according to voltage deviation from 1 p.u.. You can use parameter limits_cb_nodes to adjust the color range.
- limits_cb_lines (
tuple
) – Tuple with limits for colorbar of line color. First entry is the minimum and second entry the maximum value. E.g. pass (0, 1) to adjust the colorbar to 0..100% loading. Default: None (min and max loading are used). - limits_cb_nodes (
tuple
) – Tuple with limits for colorbar of nodes. First entry is the minimum and second entry the maximum value. E.g. pass (0.9, 1) to adjust the colorbar to 90%..100% voltage. Default: None (min and max loading are used). - background_map (bool, optional) – If True, a background map is plotted (default: stamen toner light). The additional package contextily is needed for this functionality. Default: True
Note
WGS84 pseudo mercator (epsg:3857) is used as coordinate reference system (CRS). Therefore, the drawn graph representation may be falsified!
- grid (
ding0.tools.pypsa_io module¶
-
ding0.tools.pypsa_io.
append_bus_v_mag_set_df
(bus_v_mag_set_df, node, node_name=None)[source]¶ Fills bus v_mag_set data needed for power flow calculation
Parameters: - bus_v_mag_set_df (pandas.DataFrame) – Dataframe of buses with entries name, temp_id, v_mag_pu_set
- node (obj:node object of generator) –
- node_name (
str
) – Optional parameter for name of bus
Returns: bus_v_mag_set_df (pandas.DataFrame) – Dataframe of buses with entries name, temp_id, v_mag_pu_set
-
ding0.tools.pypsa_io.
append_buses_df
(buses_df, grid, node, node_name='')[source]¶ Appends buses to dataframe of buses in pypsa format.
Parameters: - buses_df (pandas.DataFrame) – Dataframe of buses with entries name, v_nom, geom, mv_grid_id, lv_grid_id, in_building
- grid (
GridDing0
) – - node –
- node_name (
str
) – name of node, per default is set to node.pypsa_bus_id
Returns: buses_df (pandas.DataFrame) – Dataframe of buses with entries name, v_nom, geom, mv_grid_id, lv_grid_id, in_building
-
ding0.tools.pypsa_io.
append_generator_pq_set_df
(conf, generator_pq_set_df, node)[source]¶ Fills generator pq_set data needed for power flow calculation
Parameters: - conf (
dict
) – dictionary with technical constants - generator_pq_set_df (pandas.DataFrame) – Dataframe of generators with entries name, temp_id, p_set and q_set
- node (obj:node object of generator) –
Returns: generator_pq_set_df (pandas.DataFrame) – Dataframe of generators with entries name, temp_id, p_set and q_set
- conf (
-
ding0.tools.pypsa_io.
append_generators_df
(generators_df, node, name_bus=None)[source]¶ Appends generator to dataframe of generators in pypsa format.
Parameters: - generators_df (pandas.DataFrame) – Dataframe of generators with entries name, bus, control, p_nom, type, weather_cell_id, subtype
- node – GeneratorDing0
- name_bus (
str
) – Optional parameter for name of bus
Returns: generators_df (pandas.DataFrame) – Dataframe of generators with entries name, bus, control, p_nom, type, weather_cell_id, subtype
-
ding0.tools.pypsa_io.
append_lines_df
(edge, lines_df, buses_df)[source]¶ Append edge to lines_df
Parameters: - edge – Edge of Ding0.Network graph
- lines_df (pandas.DataFrame) – Dataframe of lines with entries name, bus0, bus1, length, x, r, s_nom, num_parallel, type
- buses_df (pandas.DataFrame) – Dataframe of buses with entries name, v_nom, geom, mv_grid_id, lv_grid_id, in_building
Returns: lines_df (pandas.DataFrame) – Dataframe of lines with entries name, bus0, bus1, length, x, r, s_nom, num_parallel, type
-
ding0.tools.pypsa_io.
append_load_area_to_load_df
(sector, load_area, loads_df, name_bus, name_load, return_time_varying_data=False, **kwargs)[source]¶ Appends LVLoadArea or LVGridDistrict to dataframe of loads in pypsa format.
Parameters: - sector (str) – load sector: ‘agricultural’, ‘industrial’, ‘residential’ or ‘retail’
- load_are – LVGridDistrictDing0 or LVLoadAreaDing0, load area of which load is to be aggregated and added
- loads_df (pandas.DataFrame) – Dataframe of loads with entries name, bus, peak_load, annual_consumption and sector
- name_bus (
str
) – name of bus to which load is connected - name_load (
str
) – name of load - return_time_varying_data (
bool
) – Determines whether data for power flow calculation is exported as well - kwargs (list of conf, load_pq_set_df) – Both arguments have to be inserted if return_time_varying_data is True.
Returns: - loads_df (pandas.DataFrame) – Dataframe of loads with entries name, bus, peak_load, annual_consumption and sector
- load_pq_set_df (pandas.DataFrame) – Dataframe of loads with entries name, temp_id, p_set and q_set, only exported if return_time_varying_data is True
-
ding0.tools.pypsa_io.
append_load_areas_to_df
(loads_df, generators_df, node, return_time_varying_data=False, **kwargs)[source]¶ Appends lv load area (or single lv grid district) to dataframe of loads and generators. Also returns power flow time varying data if return_time_varying_data is True. Each sector (agricultural, industrial, residential, retail) is represented by own entry of load. Each generator in underlying grid districts is added as own entry. Generators and load are connected to BusBar of the respective grid (LVGridDing0 for LVStationDing0 and MVGridDing0 for LVLoadAreaCentreDing0)
Parameters: - loads_df (pandas.DataFrame) – Dataframe of loads with entries name, bus, peak_load, annual_consumption, sector
- generators_df (pandas.DataFrame) – Dataframe of generators with entries name, bus, control, p_nom, type, weather_cell_id, subtype
- node – Node, which is either LVStationDing0 or LVLoadAreaCentreDing0
- return_time_varying_data (
bool
) – Determines whether data for power flow calculation is exported as well - kwargs (list of conf, load_pq_set_df, generator_pq_set_df) – All three arguments have to be inserted if return_time_varying_data is True.
Returns: - loads_df (pandas.DataFrame) – Dataframe of loads with entries name, bus, peak_load, annual_consumption, sector
- generators_df (pandas.DataFrame) – Dataframe of generators with entries name, bus, control, p_nom, type, weather_cell_id, subtype
- load_pq_set_df (pandas.DataFrame) – Dataframe of loads with entries name, temp_id, p_set and q_set, only exported if return_time_varying_data is True
- generator_pq_set_df (pandas.DataFrame) – Dataframe of generators with entries name, temp_id, p_set and q_set, only exported if return_time_varying_data is True
-
ding0.tools.pypsa_io.
append_load_pq_set_df
(conf, load_pq_set_df, node, node_name=None, peak_load=None)[source]¶ Fills load pq_set data needed for power flow calculation
Parameters: - conf (
dict
) – dictionary with technical constants - load_pq_set_df (pandas.DataFrame) – Dataframe of loads with entries name, temp_id, p_set and q_set
- node (obj:node object of generator) –
- node_name (
str
) – Optional parameter for name of load - peak_load (
float
) – Optional parameter for peak_load
Returns: load_pq_set_df (pandas.DataFrame) – Dataframe of loads with entries name, temp_id, p_set and q_set
- conf (
-
ding0.tools.pypsa_io.
append_transformers_df
(transformers_df, trafo, type=nan, bus0=None, bus1=None)[source]¶ Appends transformer to dataframe of buses in pypsa format.
Parameters: - transformers_df (pandas.DataFrame) – Dataframe of trafos with entries name, bus0, bus1, x, r, s_nom, type
- trafo (:obj:TransformerDing0) – Transformer to be added
- type (
str
) – Optional parameter for type of transformer - bus0 (
str
) – Name of primary side bus. Defaults to None and is set to primary side of transformer station by default. - bus1 (
str
) – Name of secondary side bus. Defaults to None and is set to secondary side of transformer station by default.
Returns: transformers_df (pandas.DataFrame) – Dataframe of trafos with entries name, bus0, bus1, x, r, s_nom, type
-
ding0.tools.pypsa_io.
assign_bus_results
(grid, bus_data)[source]¶ Write results obtained from PF to graph
Parameters: - grid (
GridDing0
) – - bus_data (pandas.DataFrame) – DataFrame containing voltage levels obtained from PF analysis
- grid (
-
ding0.tools.pypsa_io.
assign_line_results
(grid, line_data)[source]¶ Write results obtained from PF to graph
Parameters: - grid (
GridDing0
) – - line_data (pandas.DataFrame) – DataFrame containing active/reactive at nodes obtained from PF analysis
- grid (
-
ding0.tools.pypsa_io.
circuit_breakers_to_df
(grid, components, component_data, open_circuit_breakers, return_time_varying_data=False)[source]¶ Appends circuit breakers to component dicts. If circuit breakers are open a virtual bus is added to the respective dataframe and bus1 of the line attached to the circuit breaker is set to the new virtual node.
Parameters: - grid (
GridDing0
) – - components (components:
dict
) – Dictionary of component Dataframes ‘Bus’, ‘Generator’, ‘Line’, ‘Load’, ‘Transformer’ - component_data (
dict
) – Dictionary of component Dataframes ‘Bus’, ‘Generator’, ‘Load’, needed for power flow calculations - open_circuit_breakers (
dict
) – Dictionary containing names of open circuit breakers - return_time_varying_data (
bool
) – States whether time varying data needed for power flow calculations are constructed as well. Set to True to run power flow, set to False to export network to csv.
Returns: - grid (
-
ding0.tools.pypsa_io.
create_powerflow_problem
(timerange, components)[source]¶ Create PyPSA network object and fill with data :param timerange: Time range to be analyzed by PF :type timerange: Pandas DatetimeIndex :param components: :type components: dict
Returns: network (PyPSA powerflow problem object)
-
ding0.tools.pypsa_io.
data_integrity
(components, components_data)[source]¶ Check grid data for integrity
Parameters:
-
ding0.tools.pypsa_io.
edges_to_dict_of_dataframes
(edges, lines_df, buses_df)[source]¶ Export edges to DataFrame
Parameters: - edges (
list
) – Edges of Ding0.Network graph - lines_df (pandas.DataFrame) – Dataframe of lines with entries name, bus0, bus1, length, x, r, s_nom, num_parallel, type
- buses_df (pandas.DataFrame) – Dataframe of buses with entries name, v_nom, geom, mv_grid_id, lv_grid_id, in_building
Returns: edges_dict (dict)
- edges (
-
ding0.tools.pypsa_io.
export_to_dir
(network, export_dir)[source]¶ Exports PyPSA network as CSV files to directory
Parameters: - network (:pypsa:pypsa.Network) –
- export_dir (
str
) – Sub-directory in output/debug/grid/ where csv Files of PyPSA network are exported to.
-
ding0.tools.pypsa_io.
fill_component_dataframes
(grid, buses_df, lines_df, transformer_df, generators_df, loads_df, only_export_mv=False, return_time_varying_data=False)[source]¶ Returns component and if necessary time varying data for power flow or csv export of inserted mv or lv grid
Parameters: - grid (
GridDing0
) – Grid that is exported - buses_df (pandas.DataFrame) – Dataframe of buses with entries name, v_nom, geom, mv_grid_id, lv_grid_id, in_building
- lines_df (pandas.DataFrame) – Dataframe of lines with entries name, bus0, bus1, length, x, r, s_nom, num_parallel, type_info
- transformer_df (pandas.DataFrame) – Dataframe of trafos with entries name, bus0, bus1, x, r, s_nom, type
- generators_df (pandas.DataFrame) – Dataframe of generators with entries name, bus, control, p_nom, type, weather_cell_id, subtype
- loads_df (pandas.DataFrame) – Dataframe of loads with entries name, bus, peak_load, annual_consumption, sector
- only_export_mv (
bool
) – - return_time_varying_data (
bool
) – States whether time varying data needed for power flow calculations are constructed as well. Set to True to run power flow, set to False to export network to csv.
Returns: - grid (
-
ding0.tools.pypsa_io.
fill_mvgd_component_dataframes
(mv_grid_district, buses_df, generators_df, lines_df, loads_df, transformer_df, only_export_mv=False, return_time_varying_data=False)[source]¶ Returns component and if necessary time varying data for power flow or csv export of inserted mv grid district
Parameters: - mv_grid_district (
MVGridDistrictDing0
) – - buses_df (pandas.DataFrame) – Dataframe of buses with entries name, v_nom, geom, mv_grid_id, lv_grid_id, in_building
- lines_df (pandas.DataFrame) – Dataframe of lines with entries name, bus0, bus1, length, x, r, s_nom, num_parallel, type
- transformer_df (pandas.DataFrame) – Dataframe of trafos with entries name, bus0, bus1, x, r, s_nom, type
- generators_df (pandas.DataFrame) – Dataframe of generators with entries name, bus, control, p_nom, type, weather_cell_id, subtype
- loads_df (pandas.DataFrame) – Dataframe of loads with entries name, bus, peak_load, annual_consumption, sector
- only_export_mv (
bool
) – Bool that determines export modes for grid district, if True only mv grids are exported with lv grids aggregated at respective station, if False lv grids are fully exported - return_time_varying_data (
bool
) – States whether time varying data needed for power flow calculations are constructed as well. Set to True to run power flow, set to False to export network to csv.
Returns: - mv_components (
dict
) – Dictionary of component Dataframes ‘Bus’, ‘Generator’, ‘Line’, ‘Load’, ‘Transformer’, ‘Switch’ - network_df (pandas.DataFrame) – Dataframe of network containing name, srid, geom and population
- mv_component_data (
dict
) – Dictionary of component Dataframes ‘Bus’, ‘Generator’, ‘Load’, needed for power flow calculations
- mv_grid_district (
-
ding0.tools.pypsa_io.
init_pypsa_network
(time_range_lim)[source]¶ Instantiate PyPSA network :param time_range_lim:
Returns: - network (PyPSA network object) – Contains powerflow problem
- snapshots (iterable) – Contains snapshots to be analyzed by powerplow calculation
-
ding0.tools.pypsa_io.
initialize_component_dataframes
()[source]¶ Initializes and returns empty component dataframes
Returns: - buses_df (pandas.DataFrame) – Dataframe of buses with entries name, v_nom, geom, mv_grid_id, lv_grid_id, in_building
- lines_df (pandas.DataFrame) – Dataframe of lines with entries name, bus0, bus1, length, x, r, s_nom, num_parallel, type
- transformer_df (pandas.DataFrame) – Dataframe of trafos with entries name, bus0, bus1, x, r, s_nom, type
- generators_df (pandas.DataFrame) – Dataframe of generators with entries name, bus, control, p_nom, type, weather_cell_id, subtype
- loads_df (pandas.DataFrame) – Dataframe of loads with entries name, bus, peak_load, annual_consumption, sector
-
ding0.tools.pypsa_io.
nodes_to_dict_of_dataframes
(grid, nodes, buses_df, generators_df, loads_df, transformer_df, only_export_mv=False, return_time_varying_data=False)[source]¶ Creates dictionary of dataframes containing grid nodes and transformers
Parameters: - grid (
GridDing0
) – - nodes (
list
of ding0 grid components objects) – Nodes of the grid graph - buses_df (pandas.DataFrame) – Dataframe of buses with entries name, v_nom, geom, mv_grid_id, lv_grid_id, in_building
- generators_df (pandas.DataFrame) – Dataframe of generators with entries name, bus, control, p_nom, type, weather_cell_id, subtype
- loads_df (pandas.DataFrame) – Dataframe of loads with entries name,bus,peak_load, annual_consumption, sector
- transformer_df (pandas.DataFrame) – Dataframe of trafos with entries name, bus0, bus1, x, r, s_nom, type
- only_export_mv (
bool
) – Bool that indicates whether only mv grid should be exported, per default lv grids are exported too - return_time_varying_data (
bool
) – Set to True when running power flow. Then time varying data are returned as well.
Returns: - components (dict of pandas.DataFrame) – DataFrames contain components attributes. Dict is keyed by components type
- component_data (
dict
) – Dictionary of component Dataframes ‘Bus’, ‘Generator’, ‘Load’, needed for power flow calculations, only exported when return_time_varying_data is True empty dict otherwise.
- grid (
-
ding0.tools.pypsa_io.
process_pf_results
(network)[source]¶ Parameters: network (pypsa.Network) – Returns: - bus_data (pandas.DataFrame) – Voltage level results at buses
- line_data (pandas.DataFrame) – Resulting apparent power at lines
-
ding0.tools.pypsa_io.
run_powerflow_onthefly
(components, components_data, grid, export_pypsa_dir=None, debug=False, export_result_dir=None)[source]¶ Run powerflow to test grid stability
- Two cases are defined to be tested here:
- load case
- feed-in case
Parameters: - components (dict of pandas.DataFrame) –
- components_data (dict of pandas.DataFrame) –
- grid (
GridDing0
) – - export_pypsa_dir (
str
) – Sub-directory in output/debug/grid/ where csv Files of PyPSA network are exported to. Export is omitted if argument is empty. - debug (
bool
) – - export_result_dir (
str
) – Directory where csv Files of power flow results are exported to. Export is omitted if argument is empty.
-
ding0.tools.pypsa_io.
select_and_append_load_area_trafos
(aggregated_load_area, node_name, transformer_df)[source]¶ Selects the right trafos for aggregrated load areas and appends them to the transformer dataframe.
Parameters: - aggregated_load_area (LVLoadAreaDing0) – Aggregated load area to be appended
- node_name (str) – Name of LV side bus for appending LV load area
- transformer_df (pandas.DataFrame) – Transformer dataframe of network
Returns: pandas.DataFrame – Transformer dataframe of network with appended transformers
ding0.tools.results module¶
-
ding0.tools.results.
calculate_lvgd_stats
(nw)[source]¶ LV Statistics for an arbitrary network
Parameters: nw ( list
of NetworkDing0) – The MV grid(s) to be studiedReturns: lvgd_stats (pandas.DataFrame) – Dataframe containing several statistical numbers about the LVGD
-
ding0.tools.results.
calculate_lvgd_voltage_current_stats
(nw)[source]¶ LV Voltage and Current Statistics for an arbitrary network
Note
Aggregated Load Areas are excluded.
Parameters: nw ( list
of NetworkDing0) – The MV grid(s) to be studiedReturns: - pandas.DataFrame – nodes_df : Dataframe containing voltage, respectively current, statis for every critical node, resp. every critical station, in every LV grid in nw.
- pandas.DataFrame – lines_df : Dataframe containing current statistics for every critical line, in every LV grid in nw.
-
ding0.tools.results.
calculate_mvgd_stats
(nw)[source]¶ MV Statistics for an arbitrary network
Parameters: nw ( list
of NetworkDing0) – The MV grid(s) to be studiedReturns: mvgd_stats (pandas.DataFrame) – Dataframe containing several statistical numbers about the MVGD
-
ding0.tools.results.
calculate_mvgd_voltage_current_stats
(nw)[source]¶ MV Voltage and Current Statistics for an arbitrary network
Parameters: nw ( list
of NetworkDing0) – The MV grid(s) to be studiedReturns: - pandas.DataFrame – nodes_df : Dataframe containing voltage statistics for every node in the MVGD
- pandas.DataFrame – lines_df : Dataframe containing voltage statistics for every edge in the MVGD
-
ding0.tools.results.
concat_nd_pickles
(self, mv_grid_districts)[source]¶ Read multiple pickles, join nd objects and save to file
Parameters: mv_grid_districts ( list
) – Ints describing MV grid districts
-
ding0.tools.results.
export_data_to_oedb
(session, srid, lv_grid, lv_gen, lv_cd, mvlv_stations, mvlv_trafos, lv_loads, mv_grid, mv_gen, mv_cd, hvmv_stations, hvmv_trafos, mv_loads, lines, mvlv_mapping)[source]¶
-
ding0.tools.results.
export_data_tocsv
(path, run_id, lv_grid, lv_gen, lv_cd, lv_stations, mvlv_trafos, lv_loads, mv_grid, mv_gen, mv_cb, mv_cd, mv_stations, hvmv_trafos, mv_loads, lines, mapping)[source]¶
-
ding0.tools.results.
export_network
(nw, mode='')[source]¶ Export all nodes and lines of the network nw as DataFrames
Parameters: Returns: - pandas.DataFrame – nodes_df : Dataframe containing nodes and its attributes
- pandas.DataFrame – lines_df : Dataframe containing lines and its attributes
-
ding0.tools.results.
init_mv_grid
(mv_grid_districts=[3545], filename='ding0_tests_grids_1.pkl')[source]¶ Runs ding0 over the districtis selected in mv_grid_districts
It also writes the result in filename. If filename = False, then the network is not saved.
Parameters: Returns: NetworkDing0 – The created MV network.
-
ding0.tools.results.
load_nd_from_pickle
(filename=None, path='')[source]¶ Use pickle to save the whole nd-object to disc
Parameters: Returns: nd (NetworkDing0) – Ding0 grid container object
-
ding0.tools.results.
lv_grid_generators_bus_bar
(nd)[source]¶ Calculate statistics about generators at bus bar in LV grids
Parameters: nd (ding0.NetworkDing0) – Network container object Returns: lv_stats (dict) – Dict with keys of LV grid repr() on first level. Each of the grids has a set of statistical information about its topology
-
ding0.tools.results.
parallel_running_stats
(districts_list, n_of_processes, n_of_districts=1, source='pkl', mode='', critical=False, save_csv=False, save_path='')[source]¶ Organize parallel runs of ding0 to calculate stats
The function take all districts in a list and divide them into n_of_processes parallel processes. For each process, the assigned districts are given to the function process_runs() with arguments n_of_districts, source, mode, and critical
Parameters: - districts_list (
list
of int) – List with all districts to be run. - n_of_processes (
int
) – Number of processes to run in parallel - n_of_districts (
int
) – Number of districts to be run in each cluster given as argument to process_stats() - source (
str
) – If ‘pkl’, pickle files are read. Otherwise, ding0 is run over the districts. - mode (
str
) – If ‘MV’, medium voltage stats are calculated. If ‘LV’, low voltage stats are calculated. If empty, medium and low voltage stats are calculated. - critical (bool) – If True, critical nodes and branches are returned
- path (
str
) – path to save the pkl and csv files
Returns: - DataFrame – mv_stats: MV stats in a DataFrame. If mode==’LV’, then DataFrame is empty.
- DataFrame – lv_stats: LV stats in a DataFrame. If mode==’MV’, then DataFrame is empty.
- DataFrame – mv_crit_nodes: MV critical nodes stats in a DataFrame. If mode==’LV’, then DataFrame is empty. If critical==False, then DataFrame is empty.
- DataFrame – mv_crit_edges: MV critical edges stats in a DataFrame. If mode==’LV’, then DataFrame is empty. If critical==False, then DataFrame is empty.
- DataFrame – lv_crit_nodes: LV critical nodes stats in a DataFrame. If mode==’MV’, then DataFrame is empty. If critical==False, then DataFrame is empty.
- DataFrame – lv_crit_edges: LV critical edges stats in a DataFrame. If mode==’MV’, then DataFrame is empty. If critical==False, then DataFrame is empty.
See also
- districts_list (
-
ding0.tools.results.
plot_generation_over_load
(stats, plotpath)[source]¶ Plot of generation over load
-
ding0.tools.results.
plot_km_cable_vs_line
(stats, plotpath)[source]¶ Parameters: - stats –
- plotpath –
Returns:
-
ding0.tools.results.
process_stats
(mv_districts, n_of_districts, source, mode, critical, filename, output)[source]¶ Generates stats dataframes for districts in mv_districts.
If source==’ding0’, then runned districts are saved to a pickle named filename+str(n_of_districts[0])+’_to_’+str(n_of_districts[-1])+’.pkl’
Parameters: - districts_list (
list
of int) – List with all districts to be run. - n_of_districts (
int
) – Number of districts to be run in each cluster - source (
str
) – If ‘pkl’, pickle files are read. If ‘ding0’, ding0 is run over the districts. - mode (
str
) – If ‘MV’, medium voltage stats are calculated. If ‘LV’, low voltage stats are calculated. If empty, medium and low voltage stats are calculated. - critical (bool) – If True, critical nodes and branches are returned
- filename (
str
) – filename prefix for saving pickles - output –
outer variable where the output is stored as a tuple of 6 lists:
* mv_stats: MV stats DataFrames. If mode=='LV', then DataFrame is empty. * lv_stats: LV stats DataFrames. If mode=='MV', then DataFrame is empty. * mv_crit_nodes: MV critical nodes stats DataFrames. If mode=='LV', then DataFrame is empty. If critical==False, then DataFrame is empty. * mv_crit_edges: MV critical edges stats DataFrames. If mode=='LV', then DataFrame is empty. If critical==False, then DataFrame is empty. * lv_crit_nodes: LV critical nodes stats DataFrames. If mode=='MV', then DataFrame is empty. If critical==False, then DataFrame is empty. * lv_crit_edges: LV critical edges stats DataFrames. If mode=='MV', then DataFrame is empty. If critical==False, then DataFrame is empty.
- districts_list (
-
ding0.tools.results.
save_nd_to_pickle
(nd, path='', filename=None)[source]¶ Use pickle to save the whole nd-object to disc
The network instance is entirely pickled to a file.
Parameters: - nd (NetworkDing0) – Ding0 grid container object
- path (
str
) – Absolute or relative path where pickle should be saved. Default is ‘’ which means pickle is save to PWD
ding0.tools.tests module¶
-
ding0.tools.tests.
dataframe_equal
(network_one, network_two)[source]¶ Compare two networks and returns True if they are identical
Parameters: - network_one (
GridDing0
) – - network_two (
GridDing0
) –
Returns: - bool – True if both networks are identical, False otherwise.
- str – A message explaining the result.
- network_one (
-
ding0.tools.tests.
init_files_for_tests
(mv_grid_districts=[3545], filename='ding0_tests_grids_1.pkl')[source]¶ Runs ding0 over the districtis selected in mv_grid_districts and writes the result in filename.
Parameters:
-
ding0.tools.tests.
manual_ding0_test
(mv_grid_districts=[3545], filename='ding0_tests_grids_1.pkl')[source]¶ Compares a new run of ding0 over districts and an old one saved in filename.
Parameters:
-
ding0.tools.tests.
update_stats_test_data
(path, pkl_file=None, pkl_path='')[source]¶ If changes in electrical data have been made, run this function to update the saved test data in folder. Test are run on mv_grid_district 460. :param path: directory where testdata ist stored. Normally: …ding0/tests/core/network/testdata :param pkl_file: string of pkl-file of network; optionally, if None new Network is initiated. :return:
ding0.tools.tools module¶
-
ding0.tools.tools.
create_poly_from_source
(source_point, left_m, right_m, up_m, down_m)[source]¶ Create a rectangular polygon given a source point and the number of meters away from the source point the edges have to be.
Parameters: - source_point (Shapely Point object) – The start point in WGS84 or epsg 4326 coordinates
- left_m (
float
) – The distance from the source at which the left edge should be. - right_m (
float
) – The distance from the source at which the right edge should be. - up_m (
float
) – The distance from the source at which the upper edge should be. - down_m (
float
) – The distance from the source at which the lower edge should be.
-
ding0.tools.tools.
get_cart_dest_point
(source_point, east_meters, north_meters)[source]¶ Get the WGS84 point in the coordinate reference system epsg 4326 at in given a cartesian form of input i.e. providing the position of the destination point in relative meters east and meters north from the source point. If the source point is (0, 0) and you would like the coordinates of a point that lies 5 meters north and 3 meters west of the source, the bearing in degrees is hard to find on the fly. This function allows the input as follows: >>> get_cart_dest_point(source_point, -3, 5) # west is negative east
Parameters: - source_point (Shapely Point object) – The start point in WGS84 or epsg 4326 coordinates
- east_meters (
float
) – Meters to the east of source, negative number means west - north_meters (
float
) – Meters to the north of source, negative number means south
Returns: Shapely Point object – The point in WGS84 or epsg 4326 coordinates at the destination which is north_meters north of the source and east_meters east of source.
-
ding0.tools.tools.
get_dest_point
(source_point, distance_m, bearing_deg)[source]¶ Get the WGS84 point in the coordinate reference system epsg 4326 at a distance (in meters) from a source point in a given bearing (in degrees) (0 degrees being North and clockwise is positive).
Parameters: - source_point (Shapely Point object) – The start point in WGS84 or epsg 4326 coordinates
- distance_m (
float
) – Distance of destination point from source in meters - bearing_deg (
float
) – Bearing of destination point from source in degrees, 0 degrees being North and clockwise is positive.
Returns: Shapely Point object – The point in WGS84 or epsg 4326 coordinates at the destination which is distance meters away from the source_point in the bearing provided
-
ding0.tools.tools.
merge_two_dicts
(x, y)[source]¶ Given two dicts, merge them into a new dict as a shallow copy.
Parameters: Notes
This function was originally proposed by http://stackoverflow.com/questions/38987/how-to-merge-two-python-dictionaries-in-a-single-expression
Credits to Thomas Vander Stichele. Thanks for sharing ideas!
Returns: dict
– Merged dictionary keyed by top-level keys of both dicts
ding0.tools.validation module¶
-
ding0.tools.validation.
compare_grid_impedances
(nw1, nw2)[source]¶ Compare if two grids have the same impedances.
Parameters: - nw1 – Network 1
- nw2 – Network 2
Returns: Bool – True if network elements have same impedances.
-
ding0.tools.validation.
get_line_and_trafo_dict
(nw)[source]¶ Get dictionaries of line and transformer data (in order to compare two networks)
Parameters: nw – Network Returns: - Dictionary – mv_branches_dict
- Dictionary – lv_branches_dict
- Dictionary – lv_transformer_dict
-
ding0.tools.validation.
validate_generation
(session, nw)[source]¶ Validate if total generation of a grid in a pkl file is what expected.
Parameters: - session (sqlalchemy.orm.session.Session) – Database session
- nw – The network
Returns: - DataFrame – compare_by_level
- DataFrame – compare_by_type
-
ding0.tools.validation.
validate_load_areas
(session, nw)[source]¶ Validate if total load of a grid in a pkl file is what expected from load areas
Parameters: - session (sqlalchemy.orm.session.Session) – Database session
- nw – The network
Returns: - DataFrame – compare_by_la
- Bool – True if data base IDs of LAs are the same as the IDs in the grid
-
ding0.tools.validation.
validate_lv_districts
(session, nw)[source]¶ Validate if total load of a grid in a pkl file is what expected from LV districts
Parameters: - session (sqlalchemy.orm.session.Session) – Database session
- nw – The network
Returns: - DataFrame – compare_by_district
- DataFrame – compare_by_loads