Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct bug with repeated substation in TransformGrid._add_bus #384

Merged
merged 2 commits into from
Jan 29, 2021
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
7 changes: 5 additions & 2 deletions powersimdata/input/tests/test_transform_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,13 +506,15 @@ def test_add_bus(ct):
prev_max_bus = grid.bus.index.max()
prev_num_subs = len(grid.sub.index)
ct.ct["new_bus"] = [
# These two are buses at new locations
# These three are buses at new locations
{"lat": 40, "lon": 50.5, "zone_id": 2, "Pd": 0, "baseKV": 69},
{"lat": -40.5, "lon": -50, "zone_id": 201, "Pd": 10, "baseKV": 230},
# We want to test that we can add two new buses at the same lat/lon
{"lat": -40.5, "lon": -50, "zone_id": 201, "Pd": 5, "baseKV": 69},
# This one is at the lat/lon of an existing substation
{"lat": 36.0155, "lon": -114.738, "zone_id": 208, "Pd": 0, "baseKV": 345},
]
expected_interconnects = ("Eastern", "Western", "Western")
expected_interconnects = ("Eastern", "Western", "Western", "Western")
new_grid = TransformGrid(grid, ct.ct).get_grid()
assert len(new_grid.bus.index) == prev_num_buses + len(ct.ct["new_bus"])
for i, new_bus in enumerate(ct.ct["new_bus"]):
Expand All @@ -523,6 +525,7 @@ def test_add_bus(ct):
# Ensure that we still match with the other dataframes that matter
assert len(new_grid.bus) == len(new_grid.bus2sub)
assert len(new_grid.bus2sub.sub_id.unique()) == len(new_grid.sub)
# Even though we add three new buses, there are only two unique lat/lon pairs
assert len(new_grid.sub) == prev_num_subs + 2
assert new_grid.bus.index.dtype == grid.bus.index.dtype
assert new_grid.bus2sub.index.dtype == grid.bus2sub.index.dtype
Expand Down
2 changes: 1 addition & 1 deletion powersimdata/input/transform_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _add_bus(self):
index=[new_sub_id],
)
self.grid.sub = sub.append(new_row, sort=False)
latlon2sub[(lat, lon)] = new_sub_id
latlon2sub[(lat, lon)] = [new_sub_id]

def _add_dcline(self):
"""Adds HVDC line(s) to the grid"""
Expand Down