edisgo.tools package¶
edisgo.tools.config module¶
This file is part of eDisGo, a python package for distribution network analysis and optimization.
It is developed in the project open_eGo: https://openegoproject.wordpress.com
eDisGo lives on github: https://github.com/openego/edisgo/ The documentation is available on RTD: http://edisgo.readthedocs.io
Based on code by oemof developing group
This module provides a highlevel layer for reading and writing config files.
- class edisgo.tools.config.Config(**kwargs)[source]¶
Bases:
object
Container for all configurations.
- Parameters
config_path (None or str or :dict) –
Path to the config directory. Options are:
- ’default’ (default)
If config_path is set to ‘default’, the provided default config files are used directly.
- str
If config_path is a string, configs will be loaded from the directory specified by config_path. If the directory does not exist, it is created. If config files don’t exist, the default config files are copied into the directory.
- dict
A dictionary can be used to specify different paths to the different config files. The dictionary must have the following keys:
’config_db_tables’
’config_grid’
’config_grid_expansion’
’config_timeseries’
Values of the dictionary are paths to the corresponding config file. In contrast to the other options, the directories and config files must exist and are not automatically created.
- None
If config_path is None, configs are loaded from the edisgo default config directory ($HOME$/.edisgo). If the directory does not exist, it is created. If config files don’t exist, the default config files are copied into the directory.
Default: “default”.
from_json (bool) – Set to True to load config data from json file. In that case the json file is assumed to be located in path specified through config_path. Per default this is set to False in which case config data is loaded from cfg files. Default: False.
json_filename (str) – Filename of the json file. If None, it is loaded from file with name “configs.json”. Default: None.
from_zip_archive (bool) – Set to True to load json config file from zip archive. Default: False.
Notes
The Config object can be used like a dictionary. See example on how to use it.
Examples
Create Config object from default config files
>>> from edisgo.tools.config import Config >>> config = Config()
Get reactive power factor for generators in the MV network
>>> config['reactive_power_factor']['mv_gen']
- from_cfg(config_path=None)[source]¶
Load config files.
- edisgo.tools.config.load_config(filename, config_dir=None, copy_default_config=True)[source]¶
Loads the specified config file.
- Parameters
filename (str) – Config file name, e.g. ‘config_grid.cfg’.
config_dir (str, optional) – Path to config file. If None uses default edisgo config directory specified in config file ‘config_system.cfg’ in section ‘user_dirs’ by subsections ‘root_dir’ and ‘config_dir’. Default: None.
copy_default_config (bool) – If True copies a default config file into config_dir if the specified config file does not exist. Default: True.
- edisgo.tools.config.get(section, key)[source]¶
Returns the value of a given key of a given section of the main config file.
- edisgo.tools.config.get_default_config_path()[source]¶
Returns the basic edisgo config path. If it does not yet exist it creates it and copies all default config files into it.
- Returns
Path to default edisgo config directory specified in config file ‘config_system.cfg’ in section ‘user_dirs’ by subsections ‘root_dir’ and ‘config_dir’.
- Return type
edisgo.tools.geo module¶
- edisgo.tools.geo.proj2equidistant(srid)[source]¶
Transforms to equidistant projection (epsg:3035).
- Parameters
srid (int) – Spatial reference identifier of geometry to transform.
- Return type
- edisgo.tools.geo.proj2equidistant_reverse(srid)[source]¶
Transforms back from equidistant projection to given projection.
- Parameters
srid (int) – Spatial reference identifier of geometry to transform.
- Return type
- edisgo.tools.geo.proj_by_srids(srid1, srid2)[source]¶
Transforms from specified projection to other specified projection.
- Parameters
- Return type
Notes
Projections often used are conformal projection (epsg:4326), equidistant projection (epsg:3035) and spherical mercator projection (epsg:3857).
- edisgo.tools.geo.calc_geo_lines_in_buffer(grid_topology, bus, grid, buffer_radius=2000, buffer_radius_inc=1000)[source]¶
Determines lines that are at least partly within buffer around given bus.
If there are no lines, the buffer specified in buffer_radius is successively extended by buffer_radius_inc until lines are found.
- Parameters
grid_topology (
Topology
) –bus (pandas.Series) – Data of origin bus the buffer is created around. Series has same rows as columns of
buses_df
.grid (
Grid
) – Grid whose lines are searched.buffer_radius (float, optional) – Radius in m used to find connection targets. Default: 2000.
buffer_radius_inc (float, optional) – Radius in m which is incrementally added to buffer_radius as long as no target is found. Default: 1000.
- Returns
List of lines in buffer (meaning close to the bus) sorted by the lines’ representatives.
- Return type
- edisgo.tools.geo.calc_geo_dist_vincenty(grid_topology, bus_source, bus_target, branch_detour_factor=1.3)[source]¶
Calculates the geodesic distance between two buses in km.
The detour factor in config_grid is incorporated in the geodesic distance.
- Parameters
- Returns
Distance in km.
- Return type
- edisgo.tools.geo.find_nearest_bus(point, bus_target)[source]¶
Finds the nearest bus in bus_target to a given point.
- Parameters
point (shapely.Point) – Point to find nearest bus for.
bus_target (pandas.DataFrame) – Dataframe with candidate buses and their positions given in ‘x’ and ‘y’ columns. The dataframe has the same format as
buses_df
.
- Returns
Tuple that contains the name of the nearest bus and its distance.
- Return type
- edisgo.tools.geo.find_nearest_conn_objects(grid_topology, bus, lines, conn_diff_tolerance=0.0001)[source]¶
Searches all lines for the nearest possible connection object per line.
It picks out 1 object out of 3 possible objects: 2 line-adjacent buses and 1 potentially created branch tee on the line (using perpendicular projection). The resulting stack (list) is sorted ascending by distance from bus.
- Parameters
grid_topology (
Topology
) –bus (pandas.Series) – Data of bus to connect. Series has same rows as columns of
buses_df
.lines (list(str)) – List of line representatives from index of
lines_df
.conn_diff_tolerance (float, optional) – Threshold which is used to determine if 2 objects are at the same position. Default: 0.0001.
- Returns
List of connection objects. Each object is represented by dict with representative, shapely object and distance to node.
- Return type
edisgo.tools.geopandas_helper module¶
- class edisgo.tools.geopandas_helper.GeoPandasGridContainer(crs, grid_id, grid, buses_gdf, generators_gdf, loads_gdf, storage_units_gdf, transformers_gdf, lines_gdf)[source]¶
Bases:
object
Grids geo data for all components with information about their geolocation.
- Parameters
crs (str) – Coordinate Reference System of the geometry objects.
grid (
Grid
) – Matching grid objectbuses_gdf (geopandas.GeoDataFrame) – GeoDataframe with all buses in the Grid. See
buses_df
for more information.generators_gdf (geopandas.GeoDataFrame) – GeoDataframe with all generators in the Grid. See
generators_df
for more information.loads_gdf (geopandas.GeoDataFrame) – GeoDataframe with all loads in the Grid. See
loads_df
for more information.storage_units_gdf (geopandas.GeoDataFrame) – GeoDataframe with all storage units in the Grid. See
storage_units_df
for more information.transformers_gdf (geopandas.GeoDataFrame) – GeoDataframe with all transformers in the Grid. See
transformers_df
for more information.lines_gdf (geopandas.GeoDataFrame) – GeoDataframe with all lines in the Grid. See
loads_df
for more information.
- edisgo.tools.geopandas_helper.to_geopandas(grid_obj)[source]¶
Translates all DataFrames with geolocations within a Grid class to GeoDataFrames.
- Parameters
grid_obj (
Grid
) – Grid object to transform.- Returns
Data container with the grids geo data for all components with information about their geolocation.
- Return type
edisgo.tools.logger module¶
- edisgo.tools.logger.setup_logger(file_name=None, log_dir=None, loggers=None, stream_output=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, debug_message=False, reset_loggers=False)[source]¶
Setup different loggers with individual logging levels and where to write output.
The following table from python ‘Logging Howto’ shows you when which logging level is used.
Level
When it’s used
DEBUG
Detailed information, typically of interest only when diagnosing problems.
INFO
Confirmation that things are working as expected.
WARNING
An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.
ERROR
Due to a more serious problem, the software has not been able to perform some function.
CRITICAL
A serious error, indicating that the program itself may be unable to continue running.
- Parameters
file_name (str or None) –
Specifies file name of file logging information is written to. Possible options are:
- None (default)
Saves log file with standard name %Y_%m_%d-%H:%M:%S_edisgo.log.
- str
Saves log file with the specified file name.
log_dir (str or None) –
Specifies directory log file is saved to. Possible options are:
- None (default)
Saves log file in current working directory.
- ”default”
Saves log file into directory configured in the configs.
- str
Saves log file into the specified directory.
loggers (None or list(dict)) –
- None
Configuration as shown in the example below is used. Configures root logger with file and stream level warning and the edisgo logger with file and stream level debug.
- list(dict)
List of dicts with the logger configuration. Each dictionary must contain the following keys and corresponding values:
- ’name’
Specifies name of the logger as string, e.g. ‘root’ or ‘edisgo’.
- ’file_level’
Specifies file logging level. Possible options are:
- ”debug”
Logs logging messages with logging level logging.DEBUG and above.
- ”info”
Logs logging messages with logging level logging.INFO and above.
- ”warning”
Logs logging messages with logging level logging.WARNING and above.
- ”error”
Logs logging messages with logging level logging.ERROR and above.
- ”critical”
Logs logging messages with logging level logging.CRITICAL.
- None
No logging messages are logged.
- ’stream_level’
Specifies stream logging level. Possible options are the same as for file_level.
stream_output (stream) – Default sys.stdout is used. sys.stderr is also possible.
debug_message (bool) – If True the handlers of every configured logger is printed.
reset_loggers (bool) – If True the handlers of all loggers are cleared before configuring the loggers.
Examples
>>> setup_logger( >>> loggers=[ >>> {"name": "root", "file_level": "warning", "stream_level": "warning"}, >>> {"name": "edisgo", "file_level": "info", "stream_level": "info"} >>> ] >>> )
edisgo.tools.networkx_helper module¶
- edisgo.tools.networkx_helper.translate_df_to_graph(buses_df, lines_df, transformers_df=None)[source]¶
Translate DataFrames to networkx Graph Object.
- Parameters
buses_df (pandas.DataFrame) – Dataframe with all buses to use as Graph nodes. For more information about the Dataframe see
buses_df
.lines_df (pandas.DataFrame) – Dataframe with all lines to use as Graph branches. For more information about the Dataframe see
lines_df
transformers_df (pandas.DataFrame, optional) – Dataframe with all transformers to use as additional Graph nodes. For more information about the Dataframe see
transformers_df
- Returns
Graph representation of the grid as networkx Ordered Graph, where lines are represented by edges in the graph, and buses and transformers are represented by nodes.
- Return type
edisgo.tools.plots module¶
- edisgo.tools.plots.histogram(data, **kwargs)[source]¶
Function to create histogram, e.g. for voltages or currents.
- Parameters
data (pandas.DataFrame) – Data to be plotted, e.g. voltage or current (v_res or i_res from
network.results.Results
). Index of the dataframe must be a pandas.DatetimeIndex.timeindex (pandas.Timestamp or list(pandas.Timestamp) or None, optional) – Specifies time steps histogram is plotted for. If timeindex is None all time steps provided in data are used. Default: None.
directory (
str
or None, optional) – Path to directory the plot is saved to. Is created if it does not exist. Default: None.filename (
str
or None, optional) – Filename the plot is saved as. File format is specified by ending. If filename is None, the plot is shown. Default: None.color (
str
or None, optional) – Color used in plot. If None it defaults to blue. Default: None.alpha (
float
, optional) – Transparency of the plot. Must be a number between 0 and 1, where 0 is see through and 1 is opaque. Default: 1.title (
str
or None, optional) – Plot title. Default: None.x_label (
str
, optional) – Label for x-axis. Default: “”.y_label (
str
, optional) – Label for y-axis. Default: “”.normed (
bool
, optional) – Defines if histogram is normed. Default: False.x_limits (
tuple
or None, optional) – Tuple with x-axis limits. First entry is the minimum and second entry the maximum value. Default: None.y_limits (
tuple
or None, optional) – Tuple with y-axis limits. First entry is the minimum and second entry the maximum value. Default: None.fig_size (
str
ortuple
, optional) –- Size of the figure in inches or a string with the following options:
’a4portrait’
’a4landscape’
’a5portrait’
’a5landscape’
Default: ‘a5landscape’.
binwidth (
float
) – Width of bins. Default: None.
- edisgo.tools.plots.get_grid_district_polygon(config, subst_id=None, projection=4326)[source]¶
Get MV network district polygon from oedb for plotting.
- edisgo.tools.plots.mv_grid_topology(edisgo_obj, timestep=None, line_color=None, node_color=None, line_load=None, grid_expansion_costs=None, filename=None, arrows=False, grid_district_geom=True, background_map=True, voltage=None, limits_cb_lines=None, limits_cb_nodes=None, xlim=None, ylim=None, lines_cmap='inferno_r', title='', scaling_factor_line_width=None, curtailment_df=None, **kwargs)[source]¶
Plot line loading as color on lines.
Displays line loading relative to nominal capacity.
- Parameters
edisgo_obj (
EDisGo
) –timestep (pandas.Timestamp) – Time step to plot analysis results for. If timestep is None maximum line load and if given, maximum voltage deviation, is used. In that case arrows cannot be drawn. Default: None.
line_color (
str
or None) –Defines whereby to choose line colors (and implicitly size). Possible options are:
’loading’ Line color is set according to loading of the line. Loading of MV lines must be provided by parameter line_load.
’expansion_costs’ Line color is set according to investment costs of the line. This option also effects node colors and sizes by plotting investment in stations and setting node_color to ‘storage_integration’ in order to plot storage size of integrated storage units. Grid expansion costs must be provided by parameter grid_expansion_costs.
None (default) Lines are plotted in black. Is also the fallback option in case of wrong input.
node_color (
str
or None) –Defines whereby to choose node colors (and implicitly size). Possible options are:
’technology’ Node color as well as size is set according to type of node (generator, MV station, etc.).
’voltage’ Node color is set according to maximum voltage at each node. Voltages of nodes in MV network must be provided by parameter voltage.
’voltage_deviation’ Node color is set according to voltage deviation from 1 p.u.. Voltages of nodes in MV network must be provided by parameter voltage.
’storage_integration’ Only storage units are plotted. Size of node corresponds to size of storage.
None (default) Nodes are not plotted. Is also the fallback option in case of wrong input.
’curtailment’ Plots curtailment per node. Size of node corresponds to share of curtailed power for the given time span. When this option is chosen a dataframe with curtailed power per time step and node needs to be provided in parameter curtailment_df.
’charging_park’ Plots nodes with charging stations in red.
line_load (pandas.DataFrame or None) – Dataframe with current results from power flow analysis in A. Index of the dataframe is a pandas.DatetimeIndex, columns are the line representatives. Only needs to be provided when parameter line_color is set to ‘loading’. Default: None.
grid_expansion_costs (pandas.DataFrame or None) – Dataframe with network expansion costs in kEUR. See grid_expansion_costs in
Results
for more information. Only needs to be provided when parameter line_color is set to ‘expansion_costs’. Default: None.filename (
str
) – Filename to save plot under. If not provided, figure is shown directly. Default: None.arrows (
Boolean
) – If True draws arrows on lines in the direction of the power flow. Does only work when line_color option ‘loading’ is used and a time step is given. Default: False.grid_district_geom (
Boolean
) – If True network district polygon is plotted in the background. This also requires the geopandas package to be installed. Default: True.background_map (
Boolean
) – If True map is drawn in the background. This also requires the contextily package to be installed. Default: True.voltage (pandas.DataFrame) – Dataframe with voltage results from power flow analysis in p.u.. Index of the dataframe is a pandas.DatetimeIndex, columns are the bus representatives. Only needs to be provided when parameter node_color is set to ‘voltage’. Default: None.
limits_cb_lines (
tuple
) – Tuple with limits for colorbar of line color. First entry is the minimum and second entry the maximum value. Only needs to be provided when parameter line_color is not None. Default: None.limits_cb_nodes (
tuple
) – Tuple with limits for colorbar of nodes. First entry is the minimum and second entry the maximum value. Only needs to be provided when parameter node_color is not None. Default: None.xlim (
tuple
) – Limits of x-axis. Default: None.ylim (
tuple
) – Limits of y-axis. Default: None.lines_cmap (
str
) – Colormap to use for lines in case line_color is ‘loading’ or ‘expansion_costs’. Default: ‘inferno_r’.title (
str
) – Title of the plot. Default: ‘’.scaling_factor_line_width (
float
or None) – If provided line width is set according to the nominal apparent power of the lines. If line width is None a default line width of 2 is used for each line. Default: None.curtailment_df (pandas.DataFrame) – Dataframe with curtailed power per time step and node. Columns of the dataframe correspond to buses and index to the time step. Only needs to be provided if node_color is set to ‘curtailment’.
legend_loc (str) – Location of legend. See matplotlib legend location options for more information. Default: ‘upper left’.
- edisgo.tools.plots.color_map_color(value, vmin, vmax, cmap_name='coolwarm')[source]¶
Get matching color for a value on a matplotlib color map.
- edisgo.tools.plots.plot_plotly(edisgo_obj, grid=None, line_color='relative_loading', node_color='voltage_deviation', line_result_selection='max', node_result_selection='max', selected_timesteps=None, center_coordinates=False, pseudo_coordinates=False, node_selection=False)[source]¶
Draws a plotly html figure.
- Parameters
edisgo_obj (
EDisGo
) – Selected edisgo_obj to get plotting information from.grid (
Grid
) – Grid to plot. If None, the MVGrid of the edisgo_obj is plotted. Default: None.line_color (str or None) –
Defines whereby to choose line colors. Possible options are:
- ’loading’
Line color is set according to loading of the line.
- ’relative_loading’ (default)
Line color is set according to relative loading of the line.
- ’reinforce’
Line color is set according to investment costs of the line.
- None
Line color is black. This is also the fallback, in case other options fail.
node_color (str or None) –
Defines whereby to choose node colors. Possible options are:
- ’adjacencies’
Node color as well as size is set according to the number of direct neighbors.
- ’voltage_deviation’ (default)
Node color is set according to voltage deviation from 1 p.u..
- None
Line color is black. This is also the fallback, in case other options fail.
line_result_selection (str) –
Defines which values are shown for the load of the lines:
- ’min’
Minimal line load of all time steps.
- ’max’ (default)
Maximal line load of all time steps.
node_result_selection (str) –
Defines which values are shown for the voltage of the nodes:
- ’min’
Minimal node voltage of all time steps.
- ’max’ (default)
Maximal node voltage of all time steps.
selected_timesteps (pandas.Timestamp or list(pandas.Timestamp) or None) –
Selected time steps to show results for.
- None (default)
All time steps are used.
list(pandas.Timestamp) or pandas.Timestamp Selected time steps are used.
center_coordinates (bool) – Enables the centering of the coordinates. If True the transformer node is set to the coordinates x=0 and y=0. Else, the coordinates from the HV/MV-station of the MV grid are used. Default: False.
pseudo_coordinates (bool) – Enable pseudo coordinates for the plotted grid. Default: False.
node_selection (bool or list(str)) – Only plot selected nodes. Default: False.
- Returns
Plotly figure with branches and nodes.
- Return type
- edisgo.tools.plots.chosen_graph(edisgo_obj, selected_grid)[source]¶
Get the matching networkx graph from a chosen grid.
- Parameters
- Returns
Tuple with the first entry being the networkx graph of the selected grid and the second entry the grid to use as root node. See
draw_plotly()
for more information.- Return type
(networkx.Graph,
Grid
or bool)
- edisgo.tools.plots.plot_dash_app(edisgo_objects, debug=False)[source]¶
Generates a jupyter dash app from given eDisGo object(s).
- Parameters
edisgo_objects (
EDisGo
or dict[str,EDisGo
]) – eDisGo objects to show in plotly dash app. In the case of multiple edisgo objects pass a dictionary with the eDisGo objects as values and the respective eDisGo object names as keys.debug (bool) –
Debugging for the dash app:
- False (default)
Disable debugging for the dash app.
- True
Enable debugging for the dash app.
- Returns
Jupyter dash app.
- Return type
JupyterDash
- edisgo.tools.plots.plot_dash(edisgo_objects, mode='inline', debug=False, port=8050)[source]¶
Shows the generated jupyter dash app from given eDisGo object(s).
- Parameters
edisgo_objects (
EDisGo
or dict[str,EDisGo
]) – eDisGo objects to show in plotly dash app. In the case of multiple edisgo objects pass a dictionary with the eDisGo objects as values and the respective eDisGo object names as keys.mode (str) –
Display mode
- ”inline” (default)
Jupyter lab inline plotting.
- ”jupyterlab”
Plotting in own Jupyter lab tab.
- ”external”
Plotting in own browser tab.
debug (bool) – If True, enables debugging of the jupyter dash app.
port (int) – Port which the app uses. Default: 8050.
edisgo.tools.powermodels_io module¶
- edisgo.tools.powermodels_io.to_powermodels(pypsa_net)[source]¶
Convert pypsa network to network dictionary format, using the pypower structure as an intermediate steps
powermodels network dictionary: https://lanl-ansi.github.io/PowerModels.jl/stable/network-data/
pypower caseformat: https://github.com/rwl/PYPOWER/blob/master/pypower/caseformat.py
- Parameters
pypsa_net –
- Returns
- edisgo.tools.powermodels_io.add_storage_from_edisgo(edisgo_obj, psa_net, pm_dict)[source]¶
Read static storage data (position and capacity) from eDisGo and export to Powermodels dict
- edisgo.tools.powermodels_io.pypsa2ppc(psa_net)[source]¶
Converter from pypsa data structure to pypower data structure
adapted from pandapower’s pd2ppc converter
- edisgo.tools.powermodels_io.ppc2pm(ppc, psa_net)[source]¶
converter from pypower datastructure to powermodels dictionary,
adapted from pandapower to powermodels converter: https://github.com/e2nIEE/pandapower/blob/develop/pandapower/converter/powermodels/to_pm.py
- Parameters
ppc –
- Returns
edisgo.tools.preprocess_pypsa_opf_structure module¶
- edisgo.tools.preprocess_pypsa_opf_structure.preprocess_pypsa_opf_structure(edisgo_grid, psa_network, hvmv_trafo=False)[source]¶
Prepares pypsa network for OPF problem.
adds line costs
adds HV side of HV/MV transformer to network
moves slack to HV side of HV/MV transformer
- Parameters
edisgo_grid (
EDisGo
) –psa_network (pypsa.Network) –
hvmv_trafo (
Boolean
) – If True, HV side of HV/MV transformer is added to buses and Slack generator is moved to HV side.
- edisgo.tools.preprocess_pypsa_opf_structure.aggregate_fluct_generators(psa_network)[source]¶
Aggregates fluctuating generators of same type at the same node.
Iterates over all generator buses. If multiple fluctuating generators are attached, they are aggregated by type.
- Parameters
psa_network (pypsa.Network) –
edisgo.tools.tools module¶
- edisgo.tools.tools.select_worstcase_snapshots(edisgo_obj)[source]¶
Select two worst-case snapshots from time series
Two time steps in a time series represent worst-case snapshots. These are
- Maximum Residual Load: refers to the point in the time series where the
(load - generation) achieves its maximum.
- Minimum Residual Load: refers to the point in the time series where the
(load - generation) achieves its minimum.
These two points are identified based on the generation and load time series. In case load or feed-in case don’t exist None is returned.
- Parameters
edisgo_obj (
EDisGo
) –- Returns
Dictionary with keys ‘min_residual_load’ and ‘max_residual_load’. Values are corresponding worst-case snapshots of type pandas.Timestamp.
- Return type
- edisgo.tools.tools.calculate_relative_line_load(edisgo_obj, lines=None, timesteps=None)[source]¶
Calculates relative line loading for specified lines and time steps.
Line loading is calculated by dividing the current at the given time step by the allowed current.
- Parameters
edisgo_obj (
EDisGo
) –lines (list(str) or None, optional) – Line names/representatives of lines to calculate line loading for. If None, line loading is calculated for all lines in the network. Default: None.
timesteps (pandas.Timestamp or list(pandas.Timestamp) or None, optional) – Specifies time steps to calculate line loading for. If timesteps is None, all time steps power flow analysis was conducted for are used. Default: None.
- Returns
Dataframe with relative line loading (unitless). Index of the dataframe is a pandas.DatetimeIndex, columns are the line representatives.
- Return type
- edisgo.tools.tools.calculate_line_reactance(line_inductance_per_km, line_length, num_parallel)[source]¶
Calculates line reactance in Ohm.
- edisgo.tools.tools.calculate_line_resistance(line_resistance_per_km, line_length, num_parallel)[source]¶
Calculates line resistance in Ohm.
- edisgo.tools.tools.calculate_line_susceptance(line_capacitance_per_km, line_length, num_parallel)[source]¶
Calculates line shunt susceptance in Siemens.
- edisgo.tools.tools.calculate_apparent_power(nominal_voltage, current, num_parallel)[source]¶
Calculates apparent power in MVA from given voltage and current.
- edisgo.tools.tools.drop_duplicated_indices(dataframe, keep='first')[source]¶
Drop rows of duplicate indices in dataframe.
- Parameters
dataframe (pandas.DataFrame) – handled dataframe
keep (str) – indicator of row to be kept, ‘first’, ‘last’ or False, see pandas.DataFrame.drop_duplicates() method
- edisgo.tools.tools.drop_duplicated_columns(df, keep='first')[source]¶
Drop columns of dataframe that appear more than once.
- Parameters
df (pandas.DataFrame) – Dataframe of which columns are dropped.
keep (str) – Indicator of whether to keep first (‘first’), last (‘last’) or none (False) of the duplicated columns. See drop_duplicates() method of pandas.DataFrame.
- edisgo.tools.tools.select_cable(edisgo_obj, level, apparent_power)[source]¶
Selects suitable cable type and quantity using given apparent power.
Cable is selected to be able to carry the given apparent_power, no load factor is considered. Overhead lines are not considered in choosing a suitable cable.
- Parameters
- Returns
pandas.Series – Series with attributes of selected cable as in equipment data and cable type as series name.
int – Number of necessary parallel cables.
- edisgo.tools.tools.assign_feeder(edisgo_obj, mode='mv_feeder')[source]¶
Assigns MV or LV feeder to each bus and line, depending on the mode.
The feeder name is written to a new column mv_feeder or lv_feeder in
Topology
’sbuses_df
andlines_df
. The MV respectively LV feeder name corresponds to the name of the first bus in the respective feeder.
- edisgo.tools.tools.get_path_length_to_station(edisgo_obj)[source]¶
Determines path length from each bus to HV-MV station.
The path length is written to a new column path_length_to_station in buses_df dataframe of
Topology
class.- Parameters
edisgo_obj (
EDisGo
) –- Returns
Series with bus name in index and path length to station as value.
- Return type
- edisgo.tools.tools.assign_voltage_level_to_component(df, buses_df)[source]¶
Adds column with specification of voltage level component is in.
The voltage level (‘mv’ or ‘lv’) is determined based on the nominal voltage of the bus the component is connected to. If the nominal voltage is smaller than 1 kV, voltage level ‘lv’ is assigned, otherwise ‘mv’ is assigned.
- Parameters
df (pandas.DataFrame) – Dataframe with component names in the index. Only required column is column ‘bus’, giving the name of the bus the component is connected to.
buses_df (pandas.DataFrame) – Dataframe with bus information. Bus names are in the index. Only required column is column ‘v_nom’, giving the nominal voltage of the voltage level the bus is in.
- Returns
Same dataframe as given in parameter df with new column ‘voltage_level’ specifying the voltage level the component is in (either ‘mv’ or ‘lv’).
- Return type
- edisgo.tools.tools.get_weather_cells_intersecting_with_grid_district(edisgo_obj)[source]¶
Get all weather cells that intersect with the grid district.
- edisgo.tools.tools.get_directory_size(start_dir)[source]¶
Calculates the size of all files within the start path.
Walks through all files and sub-directories within a given directory and calculate the sum of size of all files in the directory. See: https://stackoverflow.com/a/1392549/13491957
- edisgo.tools.tools.get_files_recursive(path, files=None)[source]¶
Recursive function to get all files in a given path and its sub directories.
- edisgo.tools.tools.add_line_susceptance(edisgo_obj, mode='mv_b')[source]¶
Adds line susceptance information in Siemens to lines in existing grids.
- Parameters
edisgo_obj (
EDisGo
) – EDisGo object to which line susceptance information is added.mode (str) –
Defines how the susceptance is added:
- ’no_b’
Susceptance is set to 0 for all lines.
- ’mv_b’ (Default)
Susceptance is for the MV lines set according to the equipment parameters and for the LV lines it is set to zero.
- ’all_b’
Susceptance is for the MV lines set according to the equipment parameters and for the LV lines 0.25 uF/km is chosen.
- Return type