Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Primarily this package will leverage open street parcels, road network to build
You can install this package from `main` branch using following command.

```bash
pip install "nrel-shift @ git+https://github.com/NREL-Distribution-Suites/shift.git@main"
pip install "nrel-shift"
```

```{toctree}
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/mapping_phases.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ upon which equipment is used by equipment mapper.
```python
from shift import TransformerPhaseMapperModel, TransformerTypes, BalancedPhaseMapper, add_phase_mapper_to_plot
from gdm import DistributionTransformer
from gdm.quantities import PositiveApparentPower
from gdm.quantities import ApparentPower

mapper = [
TransformerPhaseMapperModel(
tr_name=el.name,
tr_type=TransformerTypes.SPLIT_PHASE,
tr_capacity=PositiveApparentPower(
tr_capacity=ApparentPower(
25,
"kilova",
),
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/mapping_voltages.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ using transformer voltages.

```python
from shift import TransformerVoltageMapper, TransformerVoltageModel, add_voltage_mapper_to_plot
from gdm.quantities import PositiveVoltage
from gdm.quantities import Voltage
from gdm import DistributionTransformer

voltage_mapper = TransformerVoltageMapper(
new_graph,
xfmr_voltage=[
TransformerVoltageModel(
name=el.name,
voltages=[PositiveVoltage(7.2, "kilovolt"), PositiveVoltage(120, "volt")],
voltages=[Voltage(7.2, "kilovolt"), Voltage(120, "volt")],
)
for _, _, el in new_graph.get_edges()
if el.edge_type is DistributionTransformer
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "nrel-shift"
version = "0.4.1"
version = "0.5.0"
description = "Framework for developing synthetic distribution feeder model."
readme = "README.md"
requires-python = ">=3.10"
Expand All @@ -25,7 +25,7 @@ dependencies = [
"scikit-learn",
"plotly",
"geopy",
"grid-data-models~=2.0.1",
"grid-data-models~=2.1.0",
"importlib-metadata",
]

Expand Down
10 changes: 4 additions & 6 deletions src/shift/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum

from pydantic import BaseModel, Field, ConfigDict, model_validator
from gdm.quantities import PositiveVoltage, PositiveApparentPower, PositiveDistance
from gdm.quantities import Voltage, ApparentPower, Distance
from gdm.distribution.components import (
DistributionLoad,
DistributionSolar,
Expand Down Expand Up @@ -60,9 +60,7 @@ class TransformerVoltageModel(BaseComponent):
"""Interface for transformer voltage model."""

name: Annotated[str, Field(..., description="Name of the transformer.")]
voltages: Annotated[
list[PositiveVoltage], Field(..., description="List of transformer voltages.")
]
voltages: Annotated[list[Voltage], Field(..., description="List of transformer voltages.")]


class TransformerTypes(str, Enum):
Expand All @@ -81,7 +79,7 @@ class TransformerPhaseMapperModel(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
tr_name: str
tr_type: TransformerTypes
tr_capacity: PositiveApparentPower
tr_capacity: ApparentPower
location: Location


Expand Down Expand Up @@ -116,7 +114,7 @@ class EdgeModel(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
name: Annotated[str, Field(..., description="Name of the node.")]
edge_type: Annotated[VALID_EDGE_TYPES, Field(..., description="Edge type.")]
length: Annotated[Optional[PositiveDistance], Field(None, description="Length of edge.")]
length: Annotated[Optional[Distance], Field(None, description="Length of edge.")]

@model_validator(mode="after")
def validate_fields(self):
Expand Down
6 changes: 3 additions & 3 deletions src/shift/mapper/base_voltage_mapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from functools import cached_property

from gdm.quantities import PositiveVoltage
from gdm.quantities import Voltage

from shift.graph.distribution_graph import DistributionGraph

Expand All @@ -24,10 +24,10 @@ def __init__(self, graph: DistributionGraph):

@abstractmethod
@cached_property
def node_voltage_mapping(self) -> dict[str, PositiveVoltage]:
def node_voltage_mapping(self) -> dict[str, Voltage]:
"""Returns dictionary mapping node name to line to ground voltage.

Returns
-------
dict[str, tuple[PositiveVoltage, PositiveVoltage]]
dict[str, tuple[Voltage, Voltage]]
"""
16 changes: 8 additions & 8 deletions src/shift/mapper/edge_equipment_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from infrasys.component import Component
from gdm.dataset.dataset_system import DatasetSystem
from gdm.quantities import PositiveApparentPower, PositiveCurrent, PositiveVoltage
from gdm.quantities import ApparentPower, Current, Voltage
from gdm.distribution.components import (
DistributionTransformer,
DistributionBranchBase,
Expand Down Expand Up @@ -58,10 +58,10 @@ def __init__(
self.phase_mapper = phase_mapper
super().__init__(graph)

def _get_load_power(self, load_equipment: LoadEquipment) -> PositiveApparentPower:
def _get_load_power(self, load_equipment: LoadEquipment) -> ApparentPower:
"""Internal method to return total load power."""

return PositiveApparentPower(
return ApparentPower(
sum(
[
math.sqrt(
Expand All @@ -76,7 +76,7 @@ def _get_load_power(self, load_equipment: LoadEquipment) -> PositiveApparentPowe
"kilova",
)

def _get_served_load(self, from_node: str, to_node: str) -> PositiveApparentPower:
def _get_served_load(self, from_node: str, to_node: str) -> ApparentPower:
"""Internal method to get load served downward from this edge."""
dfs_graph = self.graph.get_dfs_tree()
parent_node = from_node if dfs_graph.has_edge(from_node, to_node) else to_node
Expand All @@ -88,7 +88,7 @@ def _get_served_load(self, from_node: str, to_node: str) -> PositiveApparentPowe
and DistributionLoad in x.assets
)
)
served_load = PositiveApparentPower(0, "kilova")
served_load = ApparentPower(0, "kilova")
for node in load_nodes:
equipment = self.node_asset_equipment_mapping[node.name][DistributionLoad]
if not isinstance(equipment, LoadEquipment):
Expand All @@ -98,7 +98,7 @@ def _get_served_load(self, from_node: str, to_node: str) -> PositiveApparentPowe
return served_load

def _get_closest_transformer_equipment(
self, capacity: PositiveApparentPower, num_phase: int, voltages: list[PositiveVoltage]
self, capacity: ApparentPower, num_phase: int, voltages: list[Voltage]
) -> Component:
"""Internal method to return transformer equipment by capacity."""

Expand Down Expand Up @@ -131,7 +131,7 @@ def filter_func(x: DistributionTransformerEquipment):
return sorted(trs, key=lambda x: x.windings[0].rated_power)[0]

def _get_closest_branch_equipment(
self, type_: Type[Component], current: PositiveCurrent, num_phase: int
self, type_: Type[Component], current: Current, num_phase: int
) -> Component:
"""Internal method to return closest conductor equipment."""
if issubclass(type_, MatrixImpedanceBranchEquipment):
Expand Down Expand Up @@ -197,7 +197,7 @@ def edge_equipment_mapping(self) -> dict[str, Component]:

edge_equipment_mapper[edge.name] = self._get_closest_branch_equipment(
EQUIPMENT_TO_CLASS_TYPE[edge.edge_type],
PositiveCurrent(current, "ampere"),
Current(current, "ampere"),
num_phase,
)
return edge_equipment_mapper
8 changes: 4 additions & 4 deletions src/shift/mapper/transformer_voltage_mapper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from functools import cached_property
from typing import Callable

from gdm.quantities import PositiveVoltage
from gdm.quantities import Voltage
from gdm.distribution.components import DistributionTransformer

import networkx as nx
Expand Down Expand Up @@ -49,7 +49,7 @@ def _update_mapper_by_func(
self,
nodes: list[str],
xfmr: TransformerVoltageModel,
mapper: dict[str, PositiveVoltage],
mapper: dict[str, Voltage],
compare_func: Callable,
):
"""Internal function to update voltage mapper."""
Expand All @@ -60,8 +60,8 @@ def _update_mapper_by_func(
mapper[node] = compare_func(xfmr.voltages)

@cached_property
def node_voltage_mapping(self) -> dict[str, PositiveVoltage]:
node_voltages: dict[str, PositiveVoltage] = {}
def node_voltage_mapping(self) -> dict[str, Voltage]:
node_voltages: dict[str, Voltage] = {}
dfs_tree = self.graph.get_dfs_tree()
xfmrs_in_mapper = [xfmr.name for xfmr in self.xfmr_voltage]
edges = self.graph.get_edges(filter_func=lambda x: x.name in xfmrs_in_mapper)
Expand Down
6 changes: 3 additions & 3 deletions src/shift/system_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
VoltageTypes,
Phase,
)
from gdm.quantities import PositiveVoltage
from gdm.quantities import Voltage
import numpy as np

from shift.data_model import (
Expand Down Expand Up @@ -126,9 +126,9 @@ def _add_branch(self, from_node: str, to_node: str, edge_data: EdgeModel):
self._system.add_component(edge)

@staticmethod
def _get_wdg_voltages(tr_equipment: DistributionTransformerEquipment) -> PositiveVoltage:
def _get_wdg_voltages(tr_equipment: DistributionTransformerEquipment) -> Voltage:
"""Internal method to return winding phase voltages."""
return PositiveVoltage(
return Voltage(
[
wdg.rated_voltage.to("kilovolt").magnitude
/ (
Expand Down
11 changes: 3 additions & 8 deletions src/shift/utils/split_network_edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
from geopy.distance import geodesic
import numpy as np
from infrasys.quantities import Distance
from gdm.quantities import PositiveDistance

from shift.data_model import GeoLocation


def get_distance_between_points(
from_point: GeoLocation, to_point: GeoLocation
) -> PositiveDistance:
def get_distance_between_points(from_point: GeoLocation, to_point: GeoLocation) -> Distance:
"""Returns distance betwee two geo points.

Parameters
Expand All @@ -25,12 +22,10 @@ def get_distance_between_points(

Returns
-------
PositiveDistance
Distance
"""

return PositiveDistance(
geodesic(*[reversed(point) for point in [from_point, to_point]]).m, "m"
)
return Distance(geodesic(*[reversed(point) for point in [from_point, to_point]]).m, "m")


def split_network_edges(graph: nx.Graph, split_length: Distance) -> nx.Graph:
Expand Down
2 changes: 1 addition & 1 deletion tests/models/p1rhs7_1247.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/models/p1rhs7_1247.json.bak

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
DistributionLoad,
)
from infrasys import Location
from gdm.quantities import PositiveDistance
from gdm.quantities import Distance

from shift import DistributionGraph, NodeModel, EdgeModel
from shift.exceptions import (
Expand Down Expand Up @@ -41,7 +41,7 @@ def distribution_graph():
node_1,
node_3,
edge_data=EdgeModel(
name="line-2", edge_type=DistributionBranchBase, length=PositiveDistance(1, "m")
name="line-2", edge_type=DistributionBranchBase, length=Distance(1, "m")
),
)

Expand Down Expand Up @@ -70,9 +70,7 @@ def test_edge_addition():
node_1 = NodeModel(name="node_1", location=Location(x=1, y=1))
node_2 = NodeModel(name="node_2", location=Location(x=1, y=2))
graph.add_nodes([node_1, node_2])
edge_data = EdgeModel(
name="line-1", edge_type=DistributionBranchBase, length=PositiveDistance(1, "m")
)
edge_data = EdgeModel(name="line-1", edge_type=DistributionBranchBase, length=Distance(1, "m"))
graph.add_edge(
node_1.name,
node_2.name,
Expand Down Expand Up @@ -115,7 +113,7 @@ def test_adding_edge_that_already_exists(distribution_graph):
"node_1",
"node_3",
edge_data=EdgeModel(
name="line-1", edge_type=DistributionBranchBase, length=PositiveDistance(1, "m")
name="line-1", edge_type=DistributionBranchBase, length=Distance(1, "m")
),
)

Expand Down