Skip to content

Commit 7214293

Browse files
committed
check for negative kv in check_valid_params
1 parent 8de850d commit 7214293

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed
-405 Bytes
Binary file not shown.

pygridsim/parameters.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ def get_param(params, name, default):
4545

4646
def check_valid_params(params, valid_params):
4747
# Invalid parameter handling
48-
for param in params:
49-
if param not in valid_params:
50-
raise KeyError(f"Parameter {param} is not supported")
48+
for key in params:
49+
if key not in valid_params:
50+
raise KeyError(f"Parameter {key} is not supported")
51+
if key in ["kV", "BasekV"] and params[key] < 0:
52+
raise ValueError("KV cannot be less than 0")
5153

5254
def make_load_node(load_params, load_type, count):
5355
"""
@@ -73,8 +75,6 @@ def make_load_node(load_params, load_type, count):
7375
setattr(load, attr, get_param(load_params, attr, random_param(load_type_param)))
7476
load.Daily = 'default'
7577

76-
if (load.kV) < 0:
77-
raise ValueError("Cannot have negative voltage in load")
7878
return load
7979

8080
def make_source_node(source_params, source_type):
@@ -101,9 +101,6 @@ def make_source_node(source_params, source_type):
101101
for imp in ["R0", "R1", "X0", "X1"]:
102102
setattr(source, imp, get_param(source_params, imp, defaults.IMPEDANCE))
103103

104-
if (source.BasekV) < 0:
105-
raise ValueError("Cannot have negative voltage in source")
106-
107104
return source
108105

109106
def make_pv(load_node, params, num_panels, count):
@@ -122,8 +119,6 @@ def make_pv(load_node, params, num_panels, count):
122119
pv.Phases = get_param(params, "phases", defaults.PHASES)
123120
pv.kV = get_param(params, "kV", random_param(defaults.SOLAR_PANEL_BASE_KV) * num_panels)
124121
# todo: inverter capacity?
125-
if (pv.kV) < 0:
126-
raise ValueError("Cannot have negative voltage for PVsystem")
127122

128123
def make_generator(params, gen_type, count):
129124
"""
@@ -142,7 +137,4 @@ def make_generator(params, gen_type, count):
142137
generator.Phases = get_param(params, "phases", defaults.PHASES)
143138
for attr in ["kV", "kW"]:
144139
gen_type_param = GENERATOR_CONFIGURATIONS[gen_type_obj][attr]
145-
setattr(generator, attr, get_param(params, attr, random_param(gen_type_param)))
146-
147-
if (generator.kV) < 0:
148-
raise ValueError("Cannot have negative voltage in generatorsource")
140+
setattr(generator, attr, get_param(params, attr, random_param(gen_type_param)))

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": 2922.164017017074,
4-
"load0": 130.76382218128552
3+
"source": 2275.42083457249,
4+
"load0": 174.86504811289413
55
},
66
"Losses": {
7-
"Active Power Loss": 742550.0603061075,
8-
"Reactive Power Loss": 1543879.3995447825
7+
"Active Power Loss": 331250.37737900193,
8+
"Reactive Power Loss": 688674.6517717106
99
}
1010
}

0 commit comments

Comments
 (0)