Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions src/erad/gdm_mapping.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
from contextlib import contextmanager

import gdm.distribution.components as gdc
import gdm.distribution.equipment as gde
from gdm.distribution.enums import LineType

from erad.enums import AssetTypes
from erad.models.asset_mapping import ComponentFilterModel

# Feature flag: when True, classify distribution MatrixImpedanceBranch components using
# equipment.construction (LineType) instead of the c_matrix threshold heuristic.
USE_CONSTRUCTION_ATTRIBUTE: bool = False


@contextmanager
def construction_attribute_enabled(enabled: bool = True):
"""Temporarily set USE_CONSTRUCTION_ATTRIBUTE within a `with` block."""
global USE_CONSTRUCTION_ATTRIBUTE
old = USE_CONSTRUCTION_ATTRIBUTE
USE_CONSTRUCTION_ATTRIBUTE = enabled
try:
yield
finally:
USE_CONSTRUCTION_ATTRIBUTE = old

asset_to_gdm_mapping = {
AssetTypes.switch: [
ComponentFilterModel(
Expand Down Expand Up @@ -40,10 +58,11 @@
),
ComponentFilterModel(
component_type=gdc.MatrixImpedanceBranch,
component_filter=lambda x: x.equipment.c_matrix[0, 0]
.to("microfarad/kilometer")
.magnitude
> 0.05
component_filter=lambda x: (
x.equipment.construction == LineType.UNDERGROUND
if USE_CONSTRUCTION_ATTRIBUTE
else x.equipment.c_matrix[0, 0].to("microfarad/kilometer").magnitude > 0.05
)
Comment on lines +61 to +65
and x.buses[0].rated_voltage.to("kilovolt").magnitude < 35.0,
),
],
Expand All @@ -57,10 +76,11 @@
),
ComponentFilterModel(
component_type=gdc.MatrixImpedanceBranch,
component_filter=lambda x: x.equipment.c_matrix[0, 0]
.to("microfarad/kilometer")
.magnitude
< 0.05
component_filter=lambda x: (
x.equipment.construction == LineType.OVERHEAD
if USE_CONSTRUCTION_ATTRIBUTE
else x.equipment.c_matrix[0, 0].to("microfarad/kilometer").magnitude < 0.05
)
and x.buses[0].rated_voltage.to("kilovolt").magnitude < 35.0,
),
],
Expand Down
Loading