Skip to content

Add workshop draft #58

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

Closed
wants to merge 1 commit into from
Closed
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
Empty file added workshop/__init__.py
Empty file.
73 changes: 73 additions & 0 deletions workshop/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Definitions:

- Feeder branch: A branch that connects a substation to a distribution network.
- Route: A path of nodes with a single feeder branch.


"""

from power_grid_model_ds import Grid
from power_grid_model_ds._core.model.arrays import LineArray, NodeArray

# NodeArray.station_name?


class NoCandidateNodesError(Exception):
"""Exception raised when no candidate nodes are found for a new substation."""


def build_new_substation(grid: Grid, location: tuple[float, float]) -> None:
"""Build a new substation at the given location.

(Create a substation node at the given location)
"""


def get_all_routes(grid: Grid, substation_node: NodeArray) -> list[NodeArray]:
"""Get all routes that originate from a given substation node."""


def transfer_routes(grid: Grid, old_substation: NodeArray, new_substation: NodeArray) -> None:
"""Migrate a subset of the routes of the old substation to the new substation.
Each route can be migrated fully or partially.

"""
routes = get_all_routes(grid, old_substation)
for route in routes:
try:
connection_point = find_connection_point(route, old_substation, new_substation)

Check failure on line 39 in workshop/routes.py

View workflow job for this annotation

GitHub Actions / check-code-quality

Ruff (F841)

workshop/routes.py:39:13: F841 Local variable `connection_point` is assigned to but never used
except NoCandidateNodesError:
continue

connect_to_route(grid, route, new_substation)


def find_connection_point(route: NodeArray, old_substation: NodeArray, new_substation: NodeArray) -> NodeArray:
"""Calculate the connection point for the new route.
This should be the geographically closest node to the new substation.

Should raise NoCandidateNodesError if all nodes in the route are geographically closer to the old substation.
"""


def connect_to_route(grid: Grid, connection_point: NodeArray, new_substation: NodeArray) -> None:
"""Connect the new substation node to the connection point.

1. Create a new line that connects the two nodes
2. Deactivate the line that connects the connection point to the old substation
"""


def optimize_route_transfer(grid: Grid, connection_point: NodeArray) -> None:
"""Attempt to optimize the route transfer moving the naturally open point (NOP) upstream towards the old substation.
This way, the new substation will take over more nodes of the original route.

Note that a node cannot be taken over if that results in a capacity issue on the grid.
"""


def check_for_capacity_issues(grid: Grid) -> tuple[NodeArray, LineArray]:
"""Check for capacity issues on the grid.
Return the nodes and lines that with capacity issues.
"""
Loading