roseau.load_flow.network¶
This module defines the electrical network class.
Classes¶
Electrical network class. |
Module Contents¶
- class ElectricalNetwork(*, name='Network', buses, lines, transformers, switches, loads, sources, grounds, potential_refs, ground_connections=(), crs=None)¶
Electrical network class.
This class represents an electrical network, its elements, and their connections. After creating the network, the load flow solver can be run on it using the
solve_load_flow()method.- Parameters:
name (str) – The name of the network. Defaults to
"Network".buses (MapOrSeq[Bus]) – The buses of the network. Either a list of buses or a dictionary of buses with their IDs as keys. Buses are the nodes of the network. They connect other elements such as loads and sources. Buses can be connected together with branches.
lines (MapOrSeq[Line]) – The lines of the network. Either a list of lines or a dictionary of lines with their IDs as keys.
transformers (MapOrSeq[Transformer]) – The transformers of the network. Either a list of transformers or a dictionary of transformers with their IDs as keys.
switches (MapOrSeq[Switch]) – The switches of the network. Either a list of switches or a dictionary of switches with their IDs as keys.
loads (MapOrSeq[Load]) – The loads of the network. Either a list of loads or a dictionary of loads with their IDs as keys. There are three types of loads: constant power, constant current, and constant impedance.
sources (MapOrSeq[VoltageSource]) – The sources of the network. Either a list of sources or a dictionary of sources with their IDs as keys. A network must have at least one source. Note that two sources cannot be connected with a switch.
grounds (MapOrSeq[Ground]) – The grounds of the network. Either a list of grounds or a dictionary of grounds with their IDs as keys. LV networks typically have one ground element connected to the neutral of the main source bus (LV side of the MV/LV transformer). HV networks may have one or more grounds connected to the shunt components of their lines.
potential_refs (MapOrSeq[PotentialRef]) – The potential references of the network. Either a list of potential references or a dictionary of potential references with their IDs as keys. As the name suggests, this element defines the reference of potentials of the network. A potential reference per galvanically isolated section of the network is expected. A potential reference can be connected to a bus or to a ground.
ground_connections (MapOrSeq[GroundConnection]) – The ground connections of the network. Either a list of ground connections or a dictionary of ground connections with their IDs as keys. A ground connection connects a terminal’s phase to a ground element. It is typically used to model the connection of the neutral of buses to the ground. A groud connection can be ideal or have an impedance.
crs (CRSLike | None) – An optional Coordinate Reference System to use with geo data frames. Can be anything accepted by geopandas and pyproj, such as an authority string or WKT string.
- buses¶
Dictionary of buses of the network indexed by their IDs.
See also
buses_framefor a GeoDataFrame version of the buses.
- lines¶
Dictionary of lines of the network indexed by their IDs.
See also
lines_framefor a GeoDataFrame version of the lines.
- transformers¶
Dictionary of transformers of the network indexed by their IDs.
See also
transformers_framefor a GeoDataFrame version of the transformers.- Type:
- switches¶
Dictionary of switches of the network indexed by their IDs.
See also
switches_framefor a GeoDataFrame version of the switches.
- loads¶
Dictionary of loads of the network indexed by their IDs.
See also
loads_framefor a DataFrame version of the loads.- Type:
- sources¶
Dictionary of voltage sources of the network indexed by their IDs.
See also
sources_framefor a DataFrame version of the sources.- Type:
- grounds¶
Dictionary of grounds of the network indexed by their IDs.
See also
grounds_framefor a DataFrame version of the grounds.
- potential_refs¶
Dictionary of potential references of the network indexed by their IDs.
See also
potential_refs_framefor a DataFrame version of the potential references.- Type:
- ground_connections¶
Dictionary of ground connections of the network indexed by their IDs.
See also
ground_connections_framefor a DataFrame version of the ground connections.- Type:
- is_multi_phase: Final = True¶
Is the object multi-phase?
- property buses_frame: GeoDataFrame¶
The
busesof the network as a geo dataframe.- Return type:
- property lines_frame: GeoDataFrame¶
The
linesof the network as a geo dataframe.- Return type:
- property transformers_frame: GeoDataFrame¶
The
transformersof the network as a geo dataframe.- Return type:
- property switches_frame: GeoDataFrame¶
The
switchesof the network as a geo dataframe.- Return type:
- property grounds_frame: DataFrame¶
The
groundsof the network as a dataframe.See
ground_connections_framefor the connections to the ground.- Return type:
- property potential_refs_frame: DataFrame¶
The
potential referencesof the network as a dataframe.- Return type:
- property ground_connections_frame: DataFrame¶
The
ground connectionsof the network as a dataframe.- Return type:
- property short_circuits_frame: DataFrame¶
The short-circuits of the network as a dataframe.
- Return type:
- to_graph(*, respect_switches=True)¶
Create a networkx multi-graph from this electrical network.
The graph contains the geometries of the buses in the nodes data and the geometries and branch types in the edges data.
Note
This method requires networkx to be installed. You can install it with the
"graph"extra if you are using pip:pip install "roseau-load-flow[graph]".- Parameters:
respect_switches (bool) – Respect the switch state. If
True(default), open switches are not included in the graph. IfFalse, all switches are included regardless of their state.- Returns:
A networkx multi-graph representing the electrical network.
- Return type:
- property res_buses: DataFrame¶
The load flow results of the network buses.
- The results are returned as a dataframe with the following index:
bus_id: The id of the bus.
phase: The phase of the bus (in
{'a', 'b', 'c', 'n'}).
- and the following columns:
potential: The complex potential of the bus (in Volts) for the given phase.
- Return type:
- property res_lines: DataFrame¶
The load flow results of the network lines.
- The results are returned as a dataframe with the following index:
line_id: The id of the line.
phase: The phase of the line (in
{'a', 'b', 'c', 'n'}).
- and the following columns:
- current1: The complex current of the line (in Amps) for the given phase at the
first bus.
- current2: The complex current of the line (in Amps) for the given phase at the
second bus.
- power1: The complex power of the line (in VoltAmps) for the given phase at the
first bus.
- power2: The complex power of the line (in VoltAmps) for the given phase at the
second bus.
potential1: The complex potential (in Volts) for the given phase of the first bus.
potential2: The complex potential (in Volts) for the given phase of the second bus.
series_losses: The complex losses in the series and mutual impedances of the line (in VoltAmps) for the given phase.
- series_current: The complex current in the series impedance of the line (in Amps)
for the given phase.
violated: True, if the line loading exceeds the maximum loading for the given phase.
loading: The loading of the line (unitless) for the given phase.
max_loading: The maximal loading of the line (unitless) for the given phase.
ampacity: The ampacity of the line (in Amps) for the given phase.
Additional information can be easily computed from this dataframe. For example:
To get the active power losses, use the real part of the complex power losses
To get the total power losses, add the columns
powers1 + powers2To get the power losses in the shunt components of the line, subtract the series losses from the total power losses computed in the previous step:
(powers1 + powers2) - series_lossesTo get the currents in the shunt components of the line: - For the first bus, subtract the columns
current1 - series_current- For the second bus, add the columnsseries_current + current2
- Return type:
- property res_transformers: DataFrame¶
The load flow results of the network transformers.
- The results are returned as a dataframe with the following index:
transformer_id: The id of the transformer.
phase: The phase of the transformer (in
{'a', 'b', 'c', 'n'}).
- and the following columns:
current_hv: The complex current on the HV side of the transformer (in Amps) for the given phase.
current_lv: The complex current on the LV side of the transformer (in Amps) for the given phase.
power_hv: The complex power on the HV side of the transformer (in VoltAmps) for the given phase.
power_lv: The complex power on the LV side of the transformer (in VoltAmps) for the given phase.
potential_hv: The complex potential on the HV side of the transformer (in Volts) for the given phase.
potential_lv: The complex potential on the LV side of the transformer (in Volts) for the given phase.
max_loading: The maximal loading (unitless) of the transformer.
Note that values for missing phases are set to
nan. For example, a “Dyn” transformer has the phases “abc” on the HV side and “abcn” on the LV side, so the HV side values for current, power, and potential for phase “n” will benan.- Return type:
- property res_switches: DataFrame¶
The load flow results of the network switches.
- The results are returned as a dataframe with the following index:
switch_id: The id of the switch.
phase: The phase of the switch (in
{'a', 'b', 'c', 'n'}).
- and the following columns:
- current1: The complex current of the switch (in Amps) for the given phase at the
first bus.
- current2: The complex current of the switch (in Amps) for the given phase at the
second bus.
- power1: The complex power of the switch (in VoltAmps) for the given phase at the
first bus.
- power2: The complex power of the switch (in VoltAmps) for the given phase at the
second bus.
potential1: The complex potential of the first bus (in Volts) for the given phase.
potential2: The complex potential of the second bus (in Volts) for the given phase.
- Return type:
- property res_loads: DataFrame¶
The load flow results of the network loads.
- The results are returned as a dataframe with the following index:
load_id: The id of the load.
phase: The phase of the load (in
{'a', 'b', 'c', 'n'}).
- and the following columns:
type: The type of the load, can be
{'power', 'current', 'impedance'}.current: The complex current of the load (in Amps) for the given phase.
power: The complex power of the load (in VoltAmps) for the given phase.
potential: The complex potential of the load (in Volts) for the given phase.
- Return type:
- property res_loads_flexible_powers: DataFrame¶
The load flow results of the flexible powers of the “flexible” loads.
- The results are returned as a dataframe with the following index:
load_id: The id of the load.
phase: The element phases of the load (in
{'an', 'bn', 'cn', 'ab', 'bc', 'ca'}).
- and the following columns:
power: The complex flexible power of the load (in VoltAmps) for the given phase.
Note that the flexible powers are the powers that flow in the load elements and not in the lines. These are only different in case of delta loads. To access the powers that flow in the lines, use the
powercolumn from theres_loadsproperty instead.- Return type:
- property res_sources: DataFrame¶
The load flow results of the network sources.
- The results are returned as a dataframe with the following index:
source_id: The id of the source.
phase: The phase of the source (in
{'a', 'b', 'c', 'n'}).
- and the following columns:
type: The type of the source, can be
{'voltage'}.current: The complex current of the source (in Amps) for the given phase.
power: The complex power of the source (in VoltAmps) for the given phase.
potential: The complex potential of the source (in Volts) for the given phase.
- Return type:
- property res_grounds: DataFrame¶
The load flow results of the network grounds.
- The results are returned as a dataframe with the following index:
ground_id: The id of the ground.
- and the following columns:
potential: The complex potential of the ground (in Volts).
- Return type:
- property res_potential_refs: DataFrame¶
The load flow results of the network potential references.
- The results are returned as a dataframe with the following index:
potential_ref_id: The id of the potential reference.
- and the following columns:
- current: The complex current of the potential reference (in Amps). If the load flow
converged, this should be zero.
- Return type:
- property res_ground_connections: DataFrame¶
The load flow results of the network ground connections.
- The results are returned as a dataframe with the following index:
connection_id: The id of the ground connection.
- and the following columns:
current: The complex current passing through connection to the ground (in Amps).
- Return type:
- property res_buses_voltages: DataFrame¶
The load flow results of the complex voltages of the buses (V).
The voltage is phase-to-neutral if the bus has a neutral and phase-to-phase otherwise. The dataframe has a
phaseindex that will contain values like'an'for phase-to-neutral voltages and values like'ab'for phase-to-phase voltages.- The results are returned as a dataframe with the following index:
bus_id: The id of the bus.
phase: The phase of the bus (in
{'an', 'bn', 'cn', 'ab', 'bc', 'ca'}).
- and the following columns:
voltage: The complex voltage of the bus (in Volts) for the given phase.
violated: True if a voltage limit is not respected.
voltage_level: The voltage level of the bus.
min_voltage_level: The minimal voltage level of the bus.
max_voltage_level: The maximal voltage level of the bus.
nominal_voltage: The nominal voltage of the bus (in Volts).
- Return type:
- property res_buses_voltages_pp: DataFrame¶
The load flow results of the complex phase-to-phase voltages of the buses (V).
Only buses with two or more phases are considered.
- The results are returned as a dataframe with the following index:
bus_id: The id of the bus.
phase: The phase of the bus (in
{'ab', 'bc', 'ca'}).
- and the following columns:
voltage: The complex voltage of the bus (in Volts) for the given phase.
violated: True if a voltage limit is not respected.
voltage_level: The voltage level of the bus.
min_voltage_level: The minimal voltage level of the bus.
max_voltage_level: The maximal voltage level of the bus.
nominal_voltage: The nominal voltage of the bus (in Volts).
- Return type:
- property res_buses_voltages_pn: DataFrame¶
The load flow results of the complex phase-to-neutral voltages of the buses (V).
Only buses with a neutral are considered.
- The results are returned as a dataframe with the following index:
bus_id: The id of the bus.
phase: The phase of the bus (in
{'an', 'bn', 'cn'}).
- and the following columns:
voltage: The complex voltage of the bus (in Volts) for the given phase.
violated: True if a voltage limit is not respected.
voltage_level: The voltage level of the bus.
min_voltage_level: The minimal voltage level of the bus.
max_voltage_level: The maximal voltage level of the bus.
nominal_voltage: The nominal voltage of the bus (in Volts).
- Return type:
- property res_loads_voltages: DataFrame¶
The load flow results of the complex voltages of the loads (V).
- The results are returned as a dataframe with the following index:
load_id: The id of the load.
- phase: The phase of the load (in
{'an', 'bn', 'cn'}for wye loads and in {'ab', 'bc', 'ca'}for delta loads.).
- phase: The phase of the load (in
- and the following columns:
type: The type of the load, can be
{'power', 'current', 'impedance'}.svoltage: The complex voltage of the load (in Volts) for the given phase.
- Return type:
- property res_loads_voltages_pp: DataFrame¶
The load flow results of the complex phase-to-phase voltages of the loads (V).
Only loads with two or more phases are considered.
- The results are returned as a dataframe with the following index:
load_id: The id of the load.
phase: The phase of the load (in
{'ab', 'bc', 'ca'}).
- and the following columns:
type: The type of the load, can be
{'power', 'current', 'impedance'}.svoltage: The complex voltage of the load (in Volts) for the given phase.
- Return type:
- property res_loads_voltages_pn: DataFrame¶
The load flow results of the complex phase-to-phase voltages of the loads (V).
Only loads with a neutral are considered.
- The results are returned as a dataframe with the following index:
load_id: The id of the load.
phase: The phase of the load (in
{'an', 'bn', 'cn'}).
- and the following columns:
type: The type of the load, can be
{'power', 'current', 'impedance'}.svoltage: The complex voltage of the load (in Volts) for the given phase.
- Return type:
- property res_sources_voltages: DataFrame¶
The load flow results of the complex voltages of the sources (V).
- The results are returned as a dataframe with the following index:
source_id: The id of the source.
- phase: The phase of the source (in
{'an', 'bn', 'cn'}for wye sources and in {'ab', 'bc', 'ca'}for delta sources.).
- phase: The phase of the source (in
- and the following columns:
type: The type of the source, can be
{'voltage'}.voltage: The complex voltage of the source (in Volts) for the given phase.
- Return type:
- property res_sources_voltages_pp: DataFrame¶
The load flow results of the complex phase-to-phase voltages of the sources (V).
Only sources with two or more phases are considered.
- The results are returned as a dataframe with the following index:
source_id: The id of the source.
phase: The phase of the source (in
{'ab', 'bc', 'ca'}).
- and the following columns:
type: The type of the source, can be
{'voltage'}.voltage: The complex voltage of the source (in Volts) for the given phase.
- Return type:
- property res_sources_voltages_pn: DataFrame¶
The load flow results of the complex phase-to-neutral voltages of the sources (V).
Only sources with a neutral are considered.
- The results are returned as a dataframe with the following index:
source_id: The id of the source.
phase: The phase of the source (in
{'an', 'bn', 'cn'}).
- and the following columns:
type: The type of the source, can be
{'voltage'}.voltage: The complex voltage of the source (in Volts) for the given phase.
- Return type:
- classmethod from_dgs(path, use_name_as_id=False)¶
Construct an electrical network from json DGS file (PowerFactory).
Deprecated since version 0.13.0: This method is deprecated and will be removed in a future version. Use
from_dgs_file()which also accepts an encoding parameter instead.Only JSON format of DGS is currently supported. See the Data Exchange page for more information.
- Parameters:
- Returns:
The constructed network.
- Return type:
Self
- classmethod from_catalogue(name, load_point_name)¶
Create a network from the catalogue.
- Parameters:
- Returns:
The selected network
- Return type:
Self
- classmethod from_element(initial_bus, *, name='Network', crs=None)¶
Construct the network from only one element (bus) and add the others automatically.
- Parameters:
initial_bus (AbstractElement) – Any bus of the network. The network is constructed from this bus and all the elements connected to it. This is usually the main source bus of the network.
name (str) – The name of the network. Defaults to
"Network".crs (CRSLike | None) – An optional Coordinate Reference System to use with geo data frames. Can be anything accepted by geopandas and pyproj, such as an authority string or WKT string.
- Returns:
The network constructed from the given bus and all the elements connected to it.
- Return type:
Self
- solve_load_flow(max_iterations=20, tolerance=1e-06, warm_start=True, solver=_DEFAULT_SOLVER, solver_params=None)¶
Solve the load flow for this network.
To get the results of the load flow for the whole network, use the res_ properties on the network (e.g.
print(net.res_buses). To get the results for a specific element, use the res_ properties on the element (e.g.print(net.buses["bus1"].res_potentials).You need to activate the license before calling this method. You may set the environment variable
ROSEAU_LOAD_FLOW_LICENSE_KEYto your license key and it will be picked automatically when calling this method. See the License page for more information.- Parameters:
max_iterations (int) – The maximum number of allowed iterations.
tolerance (float) – Tolerance needed for the convergence.
warm_start (bool) – If true (the default), the solver is initialized with the potentials of the last successful load flow result (if any). Otherwise, the potentials are reset to their initial values.
solver (Solver) –
The name of the solver to use for the load flow. The options are:
newton: The classical Newton-Raphson method.newton_goldstein: The Newton-Raphson method with the Goldstein and Price linear search algorithm. It generally has better convergence properties than the classical Newton-Raphson method. This is the default.backward_forward: the Backward-Forward Sweep method. It usually executes faster than the other approaches but may exhibit weaker convergence properties. It does not support meshed networks or floating neutrals.
solver_params (JsonDict | None) – A dictionary of parameters used by the solver. Available parameters depend on the solver chosen. For more information, see the Solvers page.
- Returns:
The number of iterations performed and the residual error at the last iteration.
- Return type:
- property buses_clusters: list[set[Id]]¶
Clusters of buses connected by lines and switches.
Each cluster is a set of bus IDs.
This can be useful to isolate parts of the network for localized analysis. For example, to study a LV subnetwork of a MV feeder.
See also
Bus.get_connected_buses(): Get the buses in the same galvanically isolated section as a certain bus.
- classmethod dgs_export_definition_folder_path()¶
Returns the path to the DGS pfd file to use as “Export Definition Folder”.
- Return type:
- classmethod from_dgs_dict(data, /, use_name_as_id=False)¶
Construct an electrical network from a json DGS file (PowerFactory).
Only JSON format of DGS is currently supported. See the Data Exchange page for more information.
- Parameters:
- Returns:
The constructed network.
- Return type:
Self
- classmethod from_dgs_file(path, *, use_name_as_id=False, encoding=None)¶
Construct an electrical network from a json DGS file (PowerFactory).
Only JSON format of DGS is currently supported. See the Data Exchange page for more information.
- Parameters:
path (StrPath) – The path to the network DGS data file.
use_name_as_id (bool) – If True, use the name of the elements (the
loc_namefield) as their id. Otherwise, use the id from the DGS file (theFIDfield). Only use if you are sure the names are unique. Default is False.encoding (str | None) – The encoding of the file to be passed to the open function.
- Returns:
The constructed network.
- Return type:
Self
- classmethod get_catalogue(name=None, load_point_name=None)¶
Read a network dictionary from the catalogue.
- Parameters:
- Returns:
The dictionary containing the network data.
- Return type:
- property tool_data: roseau.load_flow.utils.tool_data.ToolData¶
Arbitrary JSON-serializable data for external tools.
The data is stored in a “tool” key in the network’s dictionary representation.
Usage:
Add a new tool data:
>>> en.tool_data.add("my-tool", {"version": "1.0"}) >>> en.tool_data.add("another-tool", {"project": "PV farm"}) >>> en.tool_data ToolData({'my-tool': {'version': '1.0'}, 'another-tool': {'project': 'PV farm'}}) >>> en.tool_data["my-tool"] {'version': '1.0'}
Update the data of an existing tool:
>>> en.tool_data.update("my-tool", {"author": "John Doe"}) >>> en.tool_data["my-tool"] {'version': '1.0', 'author': 'John Doe'}
Remove the data of a tool:
>>> en.tool_data.remove("my-tool") >>> "my-tool" in en.tool_data False >>> en.tool_data ToolData({'another-tool': {'project': 'PV farm'}})
Clear all tool data:
>>> en.tool_data.clear() >>> en.tool_data ToolData({})
- Return type:
roseau.load_flow.utils.tool_data.ToolData
- classmethod from_dict(data, *, include_results=True, copy=True)¶
Create an instance from a dictionary created with
to_dict().- Parameters:
data (JsonDict) – The dictionary containing the data.
include_results (bool) – If True (default) and the results of the load flow are included in the dictionary, the results are also loaded.
copy (bool) – If True (default), the input dictionary is deep-copied before processing so the original is never modified. Pass
Falsewhen the dictionary is a throwaway (e.g. freshly parsed from JSON) to avoid the copy overhead.
- Returns:
The constructed instance.
- Return type:
Self
- classmethod from_json(path, *, include_results=True)¶
Construct an instance from a JSON file created with
to_json().
- to_dict(*, include_results=True)¶
Convert the element to a dictionary.
- to_json(path, *, include_results=True, indent=True)¶
Save this element to a JSON file.
Warning
If the file exists, it will be overwritten.
- Parameters:
path (StrPath) – The path to the output file to write the network to.
include_results (bool) – If True (default), the results of the load flow are included in the JSON file. If no results are available, this option is ignored.
indent (bool) – If True (default), the JSON output is pretty-printed with 2-space indentation. Set to False for compact output.
- Returns:
The expanded and resolved path of the written file.
- Return type:
- results_to_dict(full=False)¶
Return the results of the element as a dictionary.
The results dictionary of an element contains the ID of the element, its phases, and the result. For example, bus.results_to_dict() returns a dictionary with the form:
{"id": "bus1", "phases": "an", "potentials": [[230.0, 0.0], [0.0, 0.0]]}
Note that complex values (like potentials in the example above) are stored as list of [real part, imaginary part] so that it is JSON-serializable
Using the full argument, bus.results_to_dict(full=True) leads to the following results:
{"id": "bus1", "phases": "an", "potentials": [[230.0, 0.0], [0.0, 0.0]], "voltages": [[230.0, 0.0]]}
The results dictionary of the network contains the results of all of its elements grouped by the element type. It has the form:
{ "buses": [bus1_dict, bus2_dict, ...], "lines": [line1_dict, line2_dict, ...], "transformers": [transformer1_dict, transformer2_dict, ...], "switches": [switch1_dict, switch2_dict, ...], "loads": [load1_dict, load2_dict, ...], "sources": [source1_dict, source2_dict, ...], "grounds": [ground1_dict, ground2_dict, ...], "potential_refs": [p_ref1_dict, p_ref2_dict, ...], }
where each dict is produced by the element’s results_to_dict() method.
- results_to_json(path, *, full=False, indent=True)¶
Write the results of the load flow to a json file.
Warning
If the file exists, it will be overwritten.
- Parameters:
path (StrPath) – The path to the output file to write the results to.
full (bool) – If True, all the results are added in the resulting dictionary, including results computed from other results (such as voltages that could be computed from potentials). False by default.
indent (bool) – If True (default), the JSON output is pretty-printed with 2-space indentation. Set to False for compact output.
- Returns:
The expanded and resolved path of the written file.
- Return type: