Core models¶
Pydantic v2 data classes describing the physical network elements, the
configured faults and sources, the per-frequency results and the
ComplexNumber helper used throughout the package.
core_models ¶
Branch ¶
Bases: BaseModel
Represents a branch (conductor) connecting two buses within the network.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the branch. |
description |
Optional[str]
|
A brief description of the branch. |
type |
BranchType
|
The type of the branch. |
length |
float
|
The length of the branch. |
from_bus |
str
|
The name of the originating bus. |
to_bus |
str
|
The name of the destination bus. |
self_impedance |
Dict[float, ComplexNumber]
|
Self-impedance values mapped by frequency. |
mutual_impedance |
Dict[float, ComplexNumber]
|
Mutual-impedance values mapped by frequency. |
specific_earth_resistance |
float
|
The specific earth resistance associated with the branch. |
parallel_coefficient |
Optional[float]
|
The parallel coefficient between 0..1, if any. |
calculate_impedance ¶
Calculates self and mutual impedance for each frequency using the impedance formula.
Utilizes the external impedance_calculator to avoid storing non-pickleable functions.
The calculated impedance values are stored in the self_impedance and mutual_impedance attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequencies
|
List[float]
|
A list of frequencies at which to calculate impedance. |
required |
Source code in src/groundinsight/models/core_models.py
BranchType ¶
Bases: BaseModel
Represents the type of a branch, including its impedance formulas.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the branch type. |
description |
Optional[str]
|
A brief description of the branch type. |
grounding_conductor |
bool
|
Indicates whether the branch has a grounding wire or cable shield. |
self_impedance_formula |
str
|
The formula used to calculate self-impedance. |
mutual_impedance_formula |
str
|
The formula used to calculate mutual impedance. |
Bus ¶
Bases: BaseModel
Represents a grounding bus within the network.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the bus. |
description |
Optional[str]
|
A brief description of the bus. |
type |
BusType
|
The type of the bus. |
impedance |
Dict[float, ComplexNumber]
|
A mapping of frequency to impedance values. |
specific_earth_resistance |
float
|
The specific earth resistance associated with the bus. |
calculate_impedance ¶
Calculates impedance for each frequency using the impedance formula.
Utilizes the external impedance_calculator to avoid storing non-pickleable functions.
The calculated impedance values are stored in the impedance attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frequencies
|
List[float]
|
A list of frequencies at which to calculate impedance. |
required |
Source code in src/groundinsight/models/core_models.py
BusType ¶
Bases: BaseModel
Represents the type of a bus, including its default impedance formula.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the bus type. |
description |
Optional[str]
|
A brief description of the bus type. |
system_type |
str
|
The system type associated with the bus. e.g. 'Tower' or 'Substation' |
voltage_level |
float
|
The voltage level of the bus. |
impedance_formula |
str
|
The formula used to calculate groundingimpedance. |
ComplexNumber ¶
Bases: BaseModel
Represents a complex number with real and imaginary components to creat Pydantic models with complex Numbers.
Attributes:
| Name | Type | Description |
|---|---|---|
real |
float
|
The real part of the complex number. |
imag |
float
|
The imaginary part of the complex number. |
validate_complex
classmethod
¶
Validates and converts the input value to a ComplexNumber instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
The value to validate and convert. Can be a ComplexNumber, complex, float, int, dict, or str. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A dictionary with 'real' and 'imag' keys for ComplexNumber initialization. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input string cannot be parsed as a complex number. |
TypeError
|
If the input type is unsupported. |
Source code in src/groundinsight/models/core_models.py
Fault ¶
Bases: BaseModel
Represents a fault within the network.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the fault. |
description |
Optional[str]
|
A brief description of the fault. |
bus |
str
|
The name of the bus where the fault occurs. |
scalings |
Dict[float, float]
|
Scaling factors for sources at different frequencies. |
_active |
bool
|
Indicates whether the fault is active. |
Network ¶
Bases: BaseModel
Represents the entire electrical network.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the network. |
description |
Optional[str]
|
A brief description of the network. |
frequencies |
List[float]
|
A list of frequencies used in calculations. |
buses |
Dict[str, Bus]
|
A dictionary of buses in the network. |
branches |
Dict[str, Branch]
|
A dictionary of branches in the network. |
faults |
Dict[str, Fault]
|
A dictionary of faults in the network. |
sources |
Dict[str, Source]
|
A dictionary of sources in the network. |
results |
Dict[str, Result]
|
A dictionary of results per fault. |
paths |
Dict[str, Path]
|
A dictionary of paths within the network. |
active_fault |
Optional[str]
|
The name of the currently active fault. |
_electrical_network |
Optional[ElectricalNetwork]
|
A private attribute for the electrical network. |
add_branch ¶
Adds a branch to the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branch
|
Branch
|
The branch instance to add. |
required |
overwrite
|
bool
|
If True, overwrites an existing branch with the same name. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a branch with the same name already exists, or if the connected buses are not in the network. |
Source code in src/groundinsight/models/core_models.py
add_bus ¶
Adds a bus to the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bus
|
Bus
|
The bus instance to add. |
required |
overwrite
|
bool
|
If True, overwrites an existing bus with the same name. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a bus with the same name already exists and overwrite is False. |
Source code in src/groundinsight/models/core_models.py
add_fault ¶
Adds a fault to the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fault
|
Fault
|
The fault instance to add. |
required |
overwrite
|
bool
|
If True, overwrites an existing fault with the same name. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a fault with the same name already exists, or if the associated bus is not in the network. |
Source code in src/groundinsight/models/core_models.py
add_path ¶
Adds a path to the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The path instance to add. |
required |
add_source ¶
Adds a source to the network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Source
|
The source instance to add. |
required |
overwrite
|
bool
|
If True, overwrites an existing source with the same name. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a source with the same name already exists, or if the associated bus is not in the network. |
Source code in src/groundinsight/models/core_models.py
define_paths ¶
Identifies all paths from all sources to all faults in the network and adds them to the network's paths.
This method utilizes the PathFinder to locate paths and ensures that each path is unique
before adding it to the network.
Source code in src/groundinsight/models/core_models.py
res_all_impedances ¶
Returns a Polars DataFrame containing the grounding impedance and reduction factor for each fault, bus, and frequency.
The DataFrame includes grounding impedance magnitude and angle, as well as the reduction factor.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: A DataFrame containing grounding impedance and reduction factors. |
Notes
- Faults without results are skipped.
- Missing grounding impedance or reduction factor results are noted.
Source code in src/groundinsight/models/core_models.py
res_branches ¶
Returns a Polars DataFrame with branch results for the specified fault.
If no fault is specified, returns results for the active fault.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fault
|
Optional[str]
|
The name of the fault. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: A DataFrame containing branch results. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no active fault is set or if results for the specified fault are unavailable. |
Source code in src/groundinsight/models/core_models.py
res_buses ¶
Returns a Polars DataFrame with bus results for the specified fault.
If no fault is specified, returns results for the active fault.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fault
|
Optional[str]
|
The name of the fault. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pl.DataFrame: A DataFrame containing bus results. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no active fault is set or if results for the specified fault are unavailable. |
Source code in src/groundinsight/models/core_models.py
set_active_fault ¶
Sets the specified fault as active and deactivates all other faults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fault_name
|
str
|
The name of the fault to activate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the specified fault does not exist in the network. |
Source code in src/groundinsight/models/core_models.py
Path ¶
Bases: BaseModel
Represents the path between a source and a fault bus within the network.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the path. |
description |
Optional[str]
|
A brief description of the path. |
source |
str
|
The name of the source at the start of the path. |
fault |
str
|
The name of the fault at the end of the path. |
segments |
List[Branch]
|
A list of branches that make up the path. |
Result ¶
Bases: BaseModel
Represents the overall results of the network calculations.
Attributes:
| Name | Type | Description |
|---|---|---|
buses |
List[ResultBus]
|
A list of bus results. |
branches |
List[ResultBranch]
|
A list of branch results. |
reduction_factor |
Optional[ResultReductionFactor]
|
The reduction factor result, if any. |
grounding_impedance |
Optional[ResultGroundingImpedance]
|
The grounding impedance result, if any. |
fault |
str
|
The name of the active fault. |
ResultBranch ¶
Bases: BaseModel
Represents the result data for a branch after computations.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the branch. |
i_s |
float
|
Shield current in the branch. |
i_s_freq |
Dict[float, ComplexNumber]
|
Mapping of frequency to current values. |
ResultBus ¶
Bases: BaseModel
Represents the result data for a bus after running a fault calculation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the bus. |
uepr |
float
|
Earth potential rise at the bus. |
ia |
float
|
Current at the bus. |
uepr_freq |
Dict[float, ComplexNumber]
|
Mapping of frequency to voltage values. |
ia_freq |
Dict[float, ComplexNumber]
|
Mapping of frequency to current values. |
ResultGroundingImpedance ¶
Bases: BaseModel
Represents the grounding impedance results for a specific bus.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Optional[str]
|
The name of the grounding impedance result. |
fault_bus |
str
|
The bus where the fault occurred. |
value |
Dict[float, Optional[ComplexNumber]]
|
Mapping from frequency to grounding impedance. |
ResultReductionFactor ¶
Bases: BaseModel
Represents the reduction factor results for faults.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Optional[str]
|
The name of the reduction factor result. |
fault_bus |
str
|
The bus where the fault occurred. |
value |
Dict[float, Optional[float]]
|
Mapping from frequency to reduction factor. |
Source ¶
Bases: BaseModel
Represents a current source within the network.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the source. |
description |
Optional[str]
|
A brief description of the source. |
bus |
str
|
The name of the bus where the source is located. |
values |
Dict[float, ComplexNumber]
|
A mapping of frequency to current values. |