Skip to content

Commit 05910e8

Browse files
committed
fixes from sarah's comments: update docstrings, add _ to private functions, remove mutable types from function argument, etc
1 parent f1c5034 commit 05910e8

16 files changed

+170
-109
lines changed

pygridsim/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
__author__ = 'Angela Zhao'
66
__email__ = '[email protected]'
7-
__version__ = '0.1.0.0'
7+
__version__ = '0.1.0.dev0'
88

99
from pygridsim.core import PyGridSim as PyGridSim
3 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
731 Bytes
Binary file not shown.
46 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
150 Bytes
Binary file not shown.
22 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

pygridsim/core.py

Lines changed: 117 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
# -*- coding: utf-8 -*-
22
from altdss import altdss
3-
from pygridsim.parameters import make_load_node, make_source_node, make_generator, make_pv
3+
from pygridsim.parameters import _make_load_node, _make_source_node, _make_generator, _make_pv
44
from pygridsim.results import query_solution, export_results
5-
from pygridsim.lines import make_line
5+
from pygridsim.lines import _make_line
66

77
"""Main module."""
88

99
class PyGridSim:
1010
def __init__(self):
11-
"""
12-
Initialize OpenDSS/AltDSS engine. Creates an Empty Circuit
11+
"""Initialize OpenDSS engine.
12+
13+
Instantiate an OpenDSS circuit that user can build circuit components on. Stores numbers of circuit components
14+
to ensure unique naming of repeat circuit components
15+
16+
Attributes:
17+
num_loads (int): Number of loads in circuit so far.
18+
num_lines (int): Number of lines in circuit so far.
19+
num_transformers (int): Number of transformers in circuit so far.
20+
num_pv (int): Number of PV systems in circuit so far.
21+
num_generators (int): Number generators in circuit so far.
1322
"""
1423
self.num_loads = 0
1524
self.num_lines = 0
@@ -19,115 +28,163 @@ def __init__(self):
1928
altdss.ClearAll()
2029
altdss('new circuit.MyCircuit')
2130

22-
def add_load_nodes(self, load_type: str = "house", params = {}, num: int = 1):
23-
"""
24-
When the user wants to manually add nodes, or make nodes with varying parameters.
31+
def add_load_nodes(self, load_type: str = "house", params: dict[str, int] = None, num: int = 1):
32+
"""Adds Load Node(s) to circuit.
33+
34+
Allows the user to add num load nodes, either with customized parameters or using a default load_type.
2535
2636
Args:
27-
params: load parameters for these manual additions
28-
load_type: input as string, representing one of the load types
29-
lines: which nodes these new loads are connected to
30-
num (optional): number of loads to create with these parameters
31-
Return:
32-
List of load_nodes
37+
load_type (str, optional):
38+
Load type as a string, one of "house", "commercial", "industrial". Defaults to "house".
39+
params (dict[str, int], optional):
40+
Load parameters for these manual additions. Defaults to empty dictionary.
41+
num (int, optional):
42+
The number of loads to create with these parameters. Defaults to 1.
43+
44+
Returns:
45+
list[OpenDSS object]:
46+
A list of OpenDSS objects representing the load nodes created.
3347
"""
48+
params = params or dict()
3449
load_nodes = []
3550
for _ in range(num):
36-
make_load_node(params, load_type, self.num_loads)
51+
_make_load_node(params, load_type, self.num_loads)
3752
self.num_loads += 1
53+
3854
return load_nodes
3955

40-
def update_source(self, source_type: str = "turbine", params = {}):
41-
"""
42-
Adds a main voltage source if it doesn't exist, otherwise edits it
56+
def update_source(self, source_type: str = "turbine", params: dict[str, int] = None):
57+
"""Adds or updates source node in system.
58+
59+
If a Vsource node does not exist, it is created. Otherwise, its parameters are updated based on the provided values.
4360
4461
Args:
45-
source_type: source type as a string
46-
params: load parameters for these manual additions
47-
Return:
48-
List of source_nodes
49-
"""
50-
return make_source_node(params, source_type)
62+
source_type (str, optional):
63+
The type of the source (one of "turbine", "powerplant", "lvsub", "mvsub", "hvsub", "shvsub"). Defaults to "turbine".
64+
params (dict[str, int], optional):
65+
A dictionary of parameters to configure the source node. Defaults to None.
5166
52-
def add_PVSystem(self, load_nodes: list[str], params = {}, num_panels: int = 1):
67+
Returns:
68+
OpenDSS object:
69+
The OpenDSS object representing the source node.
5370
"""
54-
Specify a list of load nodes to add a PVsystem ("solar panel") to.
71+
params = params or dict()
72+
return _make_source_node(params, source_type)
73+
74+
def add_PVSystem(self, load_nodes: list[str], params: dict[str, int] = None, num_panels: int = 1):
75+
"""Adds a photovoltaic (PV) system to the specified load nodes.
76+
77+
Adds PV system with num_panels to each of the listed load nodes. Can be customized with parameters.
5578
5679
Args:
57-
load_nodes: which load nodes to add PVsystem to
58-
params: specify anything else about the PVsystem. otherwise defaults to typical solar panel
59-
num_panels: representing how many solar panels (to represent scale)
60-
Return:
61-
list of PVSystem objects
80+
load_nodes (list[str]):
81+
A list of node names where the PV system will be connected.
82+
params (dict[str, int], optional):
83+
A dictionary of additional parameters for the PV system. Defaults to None.
84+
num_panels (int, optional):
85+
The number of PV panels in the system. Defaults to 1.
86+
87+
Returns:
88+
list[DSS objects]:
89+
A list of OpenDSS objects representing the PV systems created.
6290
"""
91+
params = params or dict()
6392
if not load_nodes:
6493
raise ValueError("Need to enter load nodes to add PVSystem to")
94+
6595
PV_nodes = []
6696
for load in load_nodes:
67-
PV_nodes.append(make_pv(load, params, num_panels, self.num_pv))
97+
PV_nodes.append(_make_pv(load, params, num_panels, self.num_pv))
6898
self.num_pv += 1
99+
69100
return PV_nodes
70101

71-
def add_generator(self, num: int = 1, gen_type: str = "small", params = {}):
72-
"""
73-
Specify parameters for a generator to add to the circuit
74-
102+
def add_generator(self, num: int = 1, gen_type: str = "small", params: dict[str, int] = None):
103+
"""Adds generator(s) to the system.
104+
75105
Args:
76-
num: number of generators
77-
gen_type: specify the generator type (small, large, industrial)
78-
params: specify anything else about the generator.
79-
Return:
80-
list of generator objects
106+
num (int, optional):
107+
The number of generator units to add. Defaults to 1.
108+
gen_type (str, optional):
109+
The type of generator (one of "small", "large", "industrial"). Defaults to "small".
110+
params (dict[str, int], optional):
111+
A dictionary of parameters to configure the generator. Defaults to None.
112+
113+
Returns:
114+
list[DSS objects]:
115+
A list of OpenDSS objects representing the generators created.
81116
"""
117+
params = params or dict()
82118
generators = []
83119
for _ in range(num):
84-
generators.append(make_generator(params, gen_type, count=self.num_generators))
120+
generators.append(_make_generator(params, gen_type, count=self.num_generators))
85121
self.num_generators += 1
122+
86123
return generators
87124

88125

89-
def add_lines(self, connections: list[tuple], line_type: str = "lv", params = {}, transformer: bool = True):
90-
"""
91-
Specify all lines that the user wants to add. If redundant lines, doesn't add anything
126+
def add_lines(self, connections: list[tuple], line_type: str = "lv", params: dict[str, int] = None, transformer: bool = True):
127+
"""Adds lines to the system.
128+
129+
Adds electrical lines according to the given connections. Users can specify the parameters of the lines or otherwise use given line type options.
92130
93131
Args:
94-
connections: a list of new connections to add. Each item of the list follows the form (source1, load1)
95-
line_type: a string representing linetype if user wants to use preset parameters
96-
params: any custom parameters for lines or transformers
97-
transformer: whether or not to include a transformer, default yes
132+
connections (list[tuple]):
133+
A list of tuples defining the connections between nodes.
134+
line_type (str, optional):
135+
The type of line (one of "lv", "mv", "hv"). Defaults to "lv".
136+
params (dict[str, int], optional):
137+
A dictionary of parameters to configure the lines. Defaults to None.
138+
transformer (bool, optional):
139+
Whether to include a transformer in the connection. Defaults to True.
140+
141+
Returns:
142+
None
98143
"""
144+
params = params or dict()
99145
for src, dst in connections:
100-
make_line(src, dst, line_type, self.num_lines, params, transformer)
146+
_make_line(src, dst, line_type, self.num_lines, params, transformer)
101147
self.num_lines += 1
102148

103149
def solve(self):
104-
"""
105-
Initialize "solve" mode in AltDSS, then allowing the user to query various results on the circuit
150+
"""Solves the OpenDSS circuit.
151+
152+
Initializes "solve" mode in OpenDSS, which then allows the user to query results on the circuit.
153+
154+
Returns:
155+
None
106156
"""
107157
altdss.Solution.Solve()
108158

109159
def results(self, queries: list[str], export_path = ""):
110-
"""
111-
Allow the user to query for many results at once instead of learning how to manually query
160+
"""Gets simulation results based on specified queries.
161+
162+
Allows the user to query for many results at once by providing a list of desired queries.
112163
113164
Args:
114-
queries: List of queries to fetch the result of
115-
export_path: if specified, exports result to this string
116-
Return:
117-
Results for each query, in a dictionary
165+
queries (list[str]):
166+
A list of queries to the circuit ("Voltages", "Losses", "TotalPower")
167+
export_path (str, optional):
168+
The file path to export results. If empty, results are not exported. Defaults to "".
169+
170+
Returns:
171+
dict:
172+
A dictionary containing the fetched simulation results.
118173
"""
119174
results = {}
120175
for query in queries:
121176
results[query] = query_solution(query)
177+
122178
if (export_path):
123179
export_results(results, export_path)
180+
124181
return results
125182

126183
def clear(self):
127-
"""
128-
Must call after we are done using the circuit, or will cause re-creation errors.
184+
"""Clears the OpenDSS circuit.
129185
130-
We only work with one circuit at a time, can only have one PyGridSim object at a time.
186+
Returns:
187+
None
131188
"""
132189
altdss.ClearAll()
133190
self.num_loads = 0

0 commit comments

Comments
 (0)