roseau.load_flow.utils.mixins
#
Module Contents#
Classes#
An identifiable object. |
|
Mixin for classes that can be serialized to and from JSON. |
|
A mixin class for objects which can be built from a catalogue. It adds the from_catalogue class method. |
- class JsonMixin#
Mixin for classes that can be serialized to and from JSON.
- abstract classmethod from_dict(data: JsonDict, *, include_results: bool = True) typing_extensions.Self #
Create an element from a dictionary created with
to_dict()
.Note
This method does not work on all classes that define it as some of them require additional information to be constructed. It can only be safely used on the ElectricNetwork, LineParameters and TransformerParameters classes.
- Parameters:
data – The dictionary containing the element’s data.
include_results – If True (default) and the results of the load flow are included in the dictionary, the results are also loaded into the element.
- Returns:
The constructed element.
- classmethod from_json(path: StrPath, *, include_results: bool = True) typing_extensions.Self #
Construct an element from a JSON file created with
to_json()
.Note
This method does not work on all classes that define it as some of them require additional information to be constructed. It can only be safely used on the ElectricNetwork, LineParameters and TransformerParameters classes.
- Parameters:
path – The path to the network data file.
include_results – If True (default) and the results of the load flow are included in the file, the results are also loaded into the element.
- Returns:
The constructed element.
- to_dict(*, include_results: bool = True) JsonDict #
Convert the element to a dictionary.
- Parameters:
include_results – If True (default), the results of the load flow are included in the dictionary. If no results are available, this option is ignored.
- Returns:
A JSON serializable dictionary with the element’s data.
- to_json(path: StrPath, *, include_results: bool = True) Path #
Save this element to a JSON file.
Warning
If the file exists, it will be overwritten.
- Parameters:
path – The path to the output file to write the network to.
include_results – If True (default), the results of the load flow are included in the JSON file. If no results are available, this option is ignored.
- Returns:
The expanded and resolved path of the written file.
- results_to_dict() JsonDict #
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]]}
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.
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, ...], "branches": [branch1_dict, branch2_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.
- class CatalogueMixin#
Bases:
Generic
[_T
]A mixin class for objects which can be built from a catalogue. It adds the from_catalogue class method.
- abstract classmethod catalogue_data() _T #
Get the catalogue data.
- abstract classmethod from_catalogue(**kwargs) typing_extensions.Self #
Build an instance from the catalogue.
- Keyword Arguments:
create. (Arguments that can be used to select the options of the instance to) –
- Returns:
The instance of the selected object.