Skip to content

Commit

Permalink
fix: Removing default values for resistance and reactance for plexos
Browse files Browse the repository at this point in the history
  • Loading branch information
pesap committed Nov 5, 2024
1 parent 19cf8c6 commit 71429d9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/r2x/defaults/plexos_output.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
},
"plexos_property_map": {
"active_power": "Max Capacity",
"active_power_flow_limits_max": "Max Flow",
"active_power_flow_limits_min": "Min Flow",
"available": "Units",
"base_power": "Max Capacity",
"base_voltage": "Voltage",
Expand Down
4 changes: 3 additions & 1 deletion src/r2x/exporter/plexos.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from plexosdb import PlexosSQLite
from plexosdb.enums import ClassEnum, CollectionEnum
from r2x.exporter.utils import (
apply_flatten_key,
apply_pint_deconstruction,
apply_property_map,
apply_valid_properties,
Expand Down Expand Up @@ -228,6 +229,7 @@ def insert_component_properties(
export_records = get_export_records(
records,
partial(apply_operation_cost),
partial(apply_flatten_key, keys_to_flatten={"active_power_limits", "active_power_flow_limits"}),
partial(apply_property_map, property_map=property_map),
partial(apply_pint_deconstruction, unit_map=self.default_units),
partial(apply_valid_properties, valid_properties=collection_properties, add_name=True),
Expand Down Expand Up @@ -424,7 +426,7 @@ def add_lines(self) -> None:
# Adding Lines
# NOTE: The default line on Plexos is a `MonitoredLine` without category. If we need to add a category
# in the future, we will uncomment the line below with the pertinent category name.
# self.add_component_category(MonitoredLine, class_enum=ClassEnum.Line)
self.add_component_category(MonitoredLine, class_enum=ClassEnum.Line)
self.bulk_insert_objects(Line, class_enum=ClassEnum.Line, collection_enum=CollectionEnum.Lines)
self.insert_component_properties(Line, parent_class=ClassEnum.System, collection=CollectionEnum.Lines)
self.bulk_insert_objects(
Expand Down
6 changes: 3 additions & 3 deletions src/r2x/models/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class ACBranch(Branch):
# arc: Annotated[Arc, Field(description="The branch's connections.")]
from_bus: Annotated[ACBus, Field(description="Bus connected upstream from the arc.")]
to_bus: Annotated[ACBus, Field(description="Bus connected downstream from the arc.")]
r: Annotated[float, Field(description=("Resistance of the branch"))] = 0
x: Annotated[float, Field(description=("Reactance of the branch"))] = 0
b: Annotated[float, Field(description=("Shunt susceptance of the branch"))] = 0
r: Annotated[float | None, Field(description=("Resistance of the branch"))] = None
x: Annotated[float | None, Field(description=("Reactance of the branch"))] = None
b: Annotated[float | None, Field(description=("Shunt susceptance of the branch"))] = None
rating: Annotated[ActivePower, Field(ge=0, description="Thermal rating of the line.")] | None = None


Expand Down
9 changes: 7 additions & 2 deletions src/r2x/models/services.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Models related to services."""

from typing import Annotated
from typing import Annotated, Any

from pydantic import Field, NonNegativeFloat, PositiveFloat
from pydantic import Field, NonNegativeFloat, PositiveFloat, field_serializer

from r2x.enums import EmissionType, ReserveDirection, ReserveType
from r2x.models.core import MinMax, Service
Expand Down Expand Up @@ -103,3 +103,8 @@ def example(cls) -> "TransmissionInterface":
active_power_flow_limits=MinMax(-100, 100),
direction_mapping={"line-01": 1, "line-02": -2},
)

@field_serializer("active_power_flow_limits")
def serialize_active_power_limits(self, min_max: MinMax) -> dict[str, Any]:
if min_max is not None:
return {"min": min_max.min, "max": min_max.max}

0 comments on commit 71429d9

Please sign in to comment.