Skip to content

Commit 2f10794

Browse files
committed
remove docstrings of private functions, change results.py functions to be private
1 parent 141e512 commit 2f10794

File tree

6 files changed

+9
-83
lines changed

6 files changed

+9
-83
lines changed

pygridsim/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
from altdss import altdss
33
from pygridsim.parameters import _make_load_node, _make_source_node, _make_generator, _make_pv
4-
from pygridsim.results import query_solution, export_results
4+
from pygridsim.results import _query_solution, _export_results
55
from pygridsim.lines import _make_line
66

77
"""Main module."""
@@ -173,10 +173,10 @@ def results(self, queries: list[str], export_path = ""):
173173
"""
174174
results = {}
175175
for query in queries:
176-
results[query] = query_solution(query)
176+
results[query] = _query_solution(query)
177177

178178
if (export_path):
179-
export_results(results, export_path)
179+
_export_results(results, export_path)
180180

181181
return results
182182

pygridsim/lines.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
from dss.enums import LineUnits
88

99
def _get_kv(node_name):
10-
"""
11-
Given a string of a node that exists, fetch its kV or raise error if doesn't exist
12-
"""
1310
if node_name == "source" and node_name in altdss.Vsource:
1411
return altdss.Vsource[node_name].BasekV
1512
elif "load" in node_name and node_name in altdss.Load:
@@ -20,16 +17,6 @@ def _get_kv(node_name):
2017
raise KeyError("Invalid src or dst name")
2118

2219
def _make_line(src, dst, line_type, count, params = {}, transformer = True):
23-
"""
24-
Add a line between src and dst
25-
26-
Args:
27-
src: where line starts (node)
28-
dst: where line end (node)
29-
params (optional): any non-default parameters to use. Params can also include transformer params like XHL, Conns
30-
Returns:
31-
Line object that was created
32-
"""
3320
_check_valid_params(params, defaults.VALID_LINE_TRANSFORMER_PARAMS)
3421
line_type_obj = _get_enum_obj(LineType, line_type)
3522
line = altdss.Line.new('line' + str(count))

pygridsim/parameters.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,13 @@ def _get_enum_obj(enum_class, enum_val):
2020
return enum_obj
2121

2222
def _random_param(range):
23-
"""
24-
Given the range of a normal parameter (i.e. normal load for a house), uniformly select value.
25-
In case the value is not a range and just a value, just return that value
26-
27-
Args:
28-
[lower_bound, upper_bound]; range of typical value
29-
Return:
30-
Randomly selected value in range
31-
"""
3223
if type(range) is not list:
3324
return range
3425

3526
[max, min] = range
3627
return random.random() * (max - min) + min
3728

3829
def _get_param(params, name, default):
39-
"""
40-
Get param or use default
41-
"""
4230
if name in params:
4331
return params[name]
4432
else:
@@ -55,18 +43,6 @@ def _check_valid_params(params, valid_params):
5543
raise ValueError("KV cannot be less than 0")
5644

5745
def _make_load_node(load_params, load_type, count):
58-
"""
59-
Make a load node with the parmeters given, filling in with defaults for
60-
any undefined but required parameter. Parse through the parameters, potentially throwing errors and warnings if
61-
one of the parameter names is invalid.
62-
63-
Args:
64-
load_params: any specified parameters to override default ones
65-
load_type: LoadType representing type of load, house, commercial, industrial
66-
count: how many loads have already been made, to not use repeat names
67-
Return:
68-
load object
69-
"""
7046
_check_valid_params(load_params, defaults.VALID_LOAD_PARAMS)
7147
load_type_obj = _get_enum_obj(LoadType, load_type)
7248

@@ -81,16 +57,6 @@ def _make_load_node(load_params, load_type, count):
8157
return load
8258

8359
def _make_source_node(source_params, source_type):
84-
"""
85-
Make a source node with the parmeters given, filling in with defaults for
86-
any undefined but required parameter. Parse through the parameters, potentially throwing errors and warnings if
87-
one of the parameter names is invalid. Note that this updates the source node if one already exists
88-
89-
Args:
90-
source_params: any specified parameters to override default ones
91-
Return:
92-
source object
93-
"""
9460
_check_valid_params(source_params, defaults.VALID_SOURCE_PARAMS)
9561
source_type_obj = _get_enum_obj(SourceType, source_type)
9662

@@ -107,30 +73,13 @@ def _make_source_node(source_params, source_type):
10773
return source
10874

10975
def _make_pv(load_node, params, num_panels, count):
110-
"""
111-
Make a PV at the load node given, scaling kV by the number of solar panels
112-
113-
Args:
114-
load_node: which load to add PVsystem to
115-
params: any customized parameters
116-
num_panels: representation of how many solar panels this PVsystem includes
117-
count: how many pv already made, to not run into duplicates
118-
"""
11976
_check_valid_params(params, defaults.VALID_PV_PARAMS)
12077
pv : PVSystem = altdss.PVSystem.new('pv' + str(count))
12178
pv.Bus1 = load_node
12279
pv.Phases = _get_param(params, "phases", defaults.PHASES)
12380
pv.kV = _get_param(params, "kV", _random_param(defaults.SOLAR_PANEL_BASE_KV) * num_panels)
12481

12582
def _make_generator(params, gen_type, count):
126-
"""
127-
Make a generator in the circuit
128-
129-
Args:
130-
params: any customized parameters
131-
gen_type: type of generator (small, large, industrial) in string
132-
count: how many generators already made, to not run into duplicates
133-
"""
13483
_check_valid_params(params, defaults.VALID_GENERATOR_PARAMS)
13584
gen_type_obj = _get_enum_obj(GeneratorType, gen_type)
13685

pygridsim/results.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@
55
from altdss import altdss
66
import json
77

8-
def query_solution(query):
9-
"""
10-
Given a query, return the query result or indicate it is invalid
11-
12-
Args:
13-
query: a query for the solve function
14-
Return:
15-
Query result or the string "Invalid" if the query is not supported
16-
"""
8+
def _query_solution(query):
179
match query:
1810
case "Voltages":
1911
bus_vmags = {}
@@ -32,6 +24,6 @@ def query_solution(query):
3224
case _:
3325
return "Invalid"
3426

35-
def export_results(results, path):
27+
def _export_results(results, path):
3628
with open(path, "w") as json_file:
3729
json.dump(results, json_file, indent=4)

sim.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"Voltages": {
3-
"source": 1523.4068912046298,
4-
"load0": 187.13882108513008
3+
"source": 1722.6218596951128,
4+
"load0": 222.38058356537
55
},
66
"Losses": {
7-
"Active Power Loss": 160914.96444476524,
8-
"Reactive Power Loss": 334569.1340276267
7+
"Active Power Loss": 201075.15204291482,
8+
"Reactive Power Loss": 418081.9257259038
99
}
1010
}

tests/test_circuit.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def test_003_one_source_one_load_exhaustive(self):
6161
circuit.add_load_nodes(num=1, load_type=load_type.value)
6262
circuit.add_lines([("source", "load0")], line_type.value)
6363
circuit.solve()
64-
#print("LineType:", line_type, "SourceType", source_type, "LoadType", load_type)
65-
#print(circuit.results(["Voltages", "Losses"]))
6664
circuit.clear()
6765

6866

0 commit comments

Comments
 (0)