-
Notifications
You must be signed in to change notification settings - Fork 0
Add node naming functionality #9
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
Changes from 1 commit
2a904aa
e733173
9ce8f7e
22e5cc1
8594034
ebe4d66
c180b8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,13 +27,23 @@ def __init__(self): | |
| self.num_transformers = 0 | ||
| self.num_pv = 0 | ||
| self.num_generators = 0 | ||
| self.nickname_to_name = {} | ||
|
amzhao16 marked this conversation as resolved.
|
||
| altdss.ClearAll() | ||
| altdss('new circuit.MyCircuit') | ||
|
|
||
| def _check_naming(self, name): | ||
| if name in self.nickname_to_name: | ||
| raise NameError("Provided name already assigned to a node") | ||
|
amzhao16 marked this conversation as resolved.
Outdated
|
||
| if name.startswith("load") or name.startswith( | ||
|
amzhao16 marked this conversation as resolved.
Outdated
|
||
| "generator") or name == "source" or name.startswith("pv"): | ||
| raise NameError( | ||
| "Cannot name nodes of the format 'component + __', ambiguity with internal names") | ||
|
amzhao16 marked this conversation as resolved.
Outdated
|
||
|
|
||
| def add_load_nodes(self, | ||
| load_type: str = "house", | ||
| params: dict[str, int] = None, | ||
| num: int = 1): | ||
| num: int = 1, | ||
| names: list[str] = None): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: add explicit typing:
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you recommend doing this with the "from typing import Optional" class? I'm not used to declaring typing with optional, and am getting "Call expression not allowed in type expressionPylancereportInvalidTypeForm" when doing it naively. |
||
| """Adds Load Node(s) to circuit. | ||
|
|
||
| Allows the user to add num load nodes, | ||
|
|
@@ -47,14 +57,24 @@ def add_load_nodes(self, | |
| Load parameters for these manual additions. Defaults to empty dictionary. | ||
| num (int, optional): | ||
| The number of loads to create with these parameters. Defaults to 1. | ||
| names (list(str), optional): | ||
| Up to num names to assign as shortcuts to the loads | ||
|
|
||
| Returns: | ||
| list[OpenDSS object]: | ||
| A list of OpenDSS objects representing the load nodes created. | ||
| """ | ||
| params = params or dict() | ||
| names = names or list() | ||
| if len(names) > num: | ||
| raise ValueError("Specified more names of loads than number of nodes") | ||
|
|
||
| load_nodes = [] | ||
| for _ in range(num): | ||
| for i in range(num): | ||
| if (len(names) > i): | ||
| self._check_naming(names[i]) | ||
| self.nickname_to_name[names[i]] = "load" + str(self.num_loads) | ||
|
|
||
| _make_load_node(params, load_type, self.num_loads) | ||
| self.num_loads += 1 | ||
|
|
||
|
|
@@ -106,12 +126,19 @@ def add_PVSystems(self, load_nodes: list[str], | |
|
|
||
| PV_nodes = [] | ||
| for load in load_nodes: | ||
| if (load in self.nickname_to_name): | ||
| self.nickname_to_name[load] | ||
|
amzhao16 marked this conversation as resolved.
Outdated
|
||
|
|
||
| PV_nodes.append(_make_pv(load, params, num_panels, self.num_pv)) | ||
| self.num_pv += 1 | ||
|
|
||
| return PV_nodes | ||
|
|
||
| def add_generators(self, num: int = 1, gen_type: str = "small", params: dict[str, int] = None): | ||
| def add_generators(self, | ||
| num: int = 1, | ||
| gen_type: str = "small", | ||
| params: dict[str, int] = None, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit add typing same as above |
||
| names: list[str] = None): | ||
| """Adds generator(s) to the system. | ||
|
|
||
| Args: | ||
|
|
@@ -121,14 +148,24 @@ def add_generators(self, num: int = 1, gen_type: str = "small", params: dict[str | |
| The type of generator (one of "small", "large", "industrial"). Defaults to "small". | ||
| params (dict[str, int], optional): | ||
| A dictionary of parameters to configure the generator. Defaults to None. | ||
| names (list(str), optional): | ||
| Up to num names to assign as shortcuts to the generators | ||
|
|
||
| Returns: | ||
| list[DSS objects]: | ||
| A list of OpenDSS objects representing the generators created. | ||
| """ | ||
| params = params or dict() | ||
| names = names or list() | ||
| if len(names) > num: | ||
| raise ValueError("Specified more names of generators than number of nodes") | ||
|
|
||
| generators = [] | ||
| for _ in range(num): | ||
| for i in range(num): | ||
| if (len(names) > i): | ||
| self._check_naming(names[i]) | ||
| self.nickname_to_name[names[i]] = "generator" + str(self.num_generators) | ||
|
|
||
| generators.append(_make_generator(params, gen_type, count=self.num_generators)) | ||
| self.num_generators += 1 | ||
|
|
||
|
|
@@ -159,6 +196,13 @@ def add_lines(self, | |
| """ | ||
| params = params or dict() | ||
| for src, dst in connections: | ||
| if (src in self.nickname_to_name): | ||
| src = self.nickname_to_name[src] | ||
| if (dst in self.nickname_to_name): | ||
| dst = self.nickname_to_name[dst] | ||
| if (src == dst): | ||
| raise ValueError("Tried to make a line between equivalent src and dst") | ||
|
|
||
| _make_line(src, dst, line_type, self.num_lines, params, transformer) | ||
| self.num_lines += 1 | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.