Skip to content

Commit

Permalink
improved diagnostic.nominal_voltages_dont_match: reduced complexity a…
Browse files Browse the repository at this point in the history
…nd fixed false positives for swapped connectors. fixed bug in diagnostic_reports.report_no_ext_grid
  • Loading branch information
julffers committed Mar 23, 2017
1 parent 1617952 commit 6cb4134
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 51 deletions.
82 changes: 48 additions & 34 deletions pandapower/diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,25 +572,33 @@ def nominal_voltages_dont_match(net, nom_voltage_tolerance):
mv_bus_3w = []
lv_bus_3w = []
connectors_swapped_3w = []
min_v_pu = 1 - nom_voltage_tolerance
max_v_pu = 1 + nom_voltage_tolerance

for i, trafo in net.trafo.iterrows():
hv_bus_violation = False
lv_bus_violation = False
connectors_swapped = False
hv_bus_vn_kv = net.bus.vn_kv.at[trafo.hv_bus]
lv_bus_vn_kv = net.bus.vn_kv.at[trafo.lv_bus]
if ((trafo.vn_hv_kv > lv_bus_vn_kv * min_v_pu)
and ((trafo.vn_hv_kv < lv_bus_vn_kv * max_v_pu))
and ((trafo.vn_lv_kv > hv_bus_vn_kv * min_v_pu))
and ((trafo.vn_lv_kv < hv_bus_vn_kv * max_v_pu))):
hv_lv_swapped.append(i)

if (((trafo.vn_hv_kv > hv_bus_vn_kv * max_v_pu) or (trafo.vn_hv_kv < hv_bus_vn_kv * min_v_pu))
and (i not in hv_lv_swapped)):
hv_bus.append(i)

if (((trafo.vn_lv_kv > lv_bus_vn_kv * max_v_pu) or (trafo.vn_lv_kv < lv_bus_vn_kv * min_v_pu))
and (i not in hv_lv_swapped)):
lv_bus.append(i)
if abs(1-(trafo.vn_hv_kv / hv_bus_vn_kv)) > nom_voltage_tolerance:
hv_bus_violation = True
if abs(1-(trafo.vn_lv_kv / lv_bus_vn_kv)) > nom_voltage_tolerance:
lv_bus_violation = True
if hv_bus_violation and lv_bus_violation:
trafo_voltages = np.array(([trafo.vn_hv_kv, trafo.vn_lv_kv]))
bus_voltages = np.array([hv_bus_vn_kv, lv_bus_vn_kv])
trafo_voltages.sort()
bus_voltages.sort()
if all((abs(trafo_voltages - bus_voltages) / bus_voltages) < (nom_voltage_tolerance)):
connectors_swapped = True

if connectors_swapped:
hv_lv_swapped.append(i)
else:
if hv_bus_violation:
hv_bus.append(i)
if lv_bus_violation:
lv_bus.append(i)

if hv_bus:
trafo_results['hv_bus'] = hv_bus
Expand All @@ -602,31 +610,37 @@ def nominal_voltages_dont_match(net, nom_voltage_tolerance):
results['trafo'] = trafo_results

for i, trafo3w in net.trafo3w.iterrows():
hv_bus_violation = False
mv_bus_violation = False
lv_bus_violation = False
connectors_swapped = False
hv_bus_vn_kv = net.bus.vn_kv.at[trafo3w.hv_bus]
mv_bus_vn_kv = net.bus.vn_kv.at[trafo3w.mv_bus]
lv_bus_vn_kv = net.bus.vn_kv.at[trafo3w.lv_bus]

if ((((trafo3w.vn_hv_kv > mv_bus_vn_kv * min_v_pu) and (trafo3w.vn_hv_kv < mv_bus_vn_kv * max_v_pu))
or ((trafo3w.vn_hv_kv > lv_bus_vn_kv * min_v_pu) and (trafo3w.vn_hv_kv < lv_bus_vn_kv * max_v_pu)))
and
(((trafo3w.vn_mv_kv > hv_bus_vn_kv * min_v_pu) and (trafo3w.vn_mv_kv < hv_bus_vn_kv * max_v_pu))
or ((trafo3w.vn_mv_kv > lv_bus_vn_kv * min_v_pu) and (trafo3w.vn_mv_kv < lv_bus_vn_kv * max_v_pu)))
and
(((trafo3w.vn_lv_kv > hv_bus_vn_kv * min_v_pu) and (trafo3w.vn_lv_kv < hv_bus_vn_kv * max_v_pu))
or ((trafo3w.vn_lv_kv > mv_bus_vn_kv * min_v_pu) and (trafo3w.vn_lv_kv < mv_bus_vn_kv * max_v_pu)))):
if abs(1-(trafo3w.vn_hv_kv / hv_bus_vn_kv)) > nom_voltage_tolerance:
hv_bus_violation = True
if abs(1-(trafo3w.vn_mv_kv / mv_bus_vn_kv)) > nom_voltage_tolerance:
mv_bus_violation = True
if abs(1-(trafo3w.vn_lv_kv / lv_bus_vn_kv)) > nom_voltage_tolerance:
lv_bus_violation = True
if hv_bus_violation and mv_bus_violation and lv_bus_violation:
trafo_voltages = np.array(([trafo3w.vn_hv_kv, trafo3w.vn_mv_kv, trafo3w.vn_lv_kv]))
bus_voltages = np.array([hv_bus_vn_kv, mv_bus_vn_kv, lv_bus_vn_kv])
trafo_voltages.sort()
bus_voltages.sort()
if all((abs(trafo_voltages - bus_voltages) / bus_voltages) < (nom_voltage_tolerance)):
connectors_swapped = True

if connectors_swapped:
connectors_swapped_3w.append(i)

if (((trafo3w.vn_hv_kv > hv_bus_vn_kv * max_v_pu) or (trafo3w.vn_hv_kv < hv_bus_vn_kv * min_v_pu))
and (i not in connectors_swapped_3w)):
hv_bus_3w.append(i)

if (((trafo3w.vn_mv_kv > mv_bus_vn_kv * max_v_pu) or (trafo3w.vn_mv_kv < mv_bus_vn_kv * min_v_pu))
and (i not in connectors_swapped_3w)):
mv_bus_3w.append(i)

if (((trafo3w.vn_lv_kv > lv_bus_vn_kv * max_v_pu) or (trafo3w.vn_lv_kv < lv_bus_vn_kv * min_v_pu))
and (i not in connectors_swapped_3w)):
lv_bus_3w.append(i)
else:
if hv_bus_violation:
hv_bus_3w.append(i)
if mv_bus_violation:
mv_bus_3w.append(i)
if lv_bus_violation:
lv_bus_3w.append(i)

if hv_bus_3w:
trafo3w_results['hv_bus'] = hv_bus_3w
Expand Down
14 changes: 7 additions & 7 deletions pandapower/diagnostic_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def report_wrong_switch_configuration(self):

def report_no_ext_grid(self):

if "no_external_grid" in self.diag_results:
if "no_ext_grid" in self.diag_results:
# message header
if self.compact_report:
logger.warning("no_external_grid:")
Expand All @@ -372,7 +372,7 @@ def report_no_ext_grid(self):
logger.warning("")

# message body
diag_result = self.diag_results["no_external_grid"]
diag_result = self.diag_results["no_ext_grid"]
if diag_result is True:
logger.warning("No ext_grid found. There has to be at least one ext_grid!")

Expand Down Expand Up @@ -451,7 +451,7 @@ def report_wrong_reference_system(self):
"system p_kw should be positive."
% (load, self.net.load.name.at[load],
self.net.load.p_kw.at[load]))

elif element_type is "gens":
if self.compact_report:
logger.warning("gens %s: wrong reference system."
Expand All @@ -461,7 +461,7 @@ def report_wrong_reference_system(self):
logger.warning("Found gen %s: '%s' with p_kw = %s. In load reference "
"system p_kw should be negative."
% (gen, self.net.gen.name.at[gen], self.net.gen.p_kw.at[gen]))

elif element_type is "sgens":
if self.compact_report:
logger.warning("sgens %s: wrong reference system."
Expand All @@ -471,7 +471,7 @@ def report_wrong_reference_system(self):
logger.warning("Found sgen %s: '%s' with p_kw = %s. In load reference "
"system p_kw should be negative."
% (sgen, self.net.sgen.name.at[sgen], self.net.sgen.p_kw.at[sgen]))

# message summary
if not self.compact_report:
logger.warning("")
Expand All @@ -490,7 +490,7 @@ def report_wrong_reference_system(self):
"reference system, p_kw should be negative. If the intention "
"was to model a load, please use a load instead."
% (len(diag_result['sgens'])))

else:
logger.info("PASSED: power flow converges. No overload found.")

Expand Down Expand Up @@ -633,7 +633,7 @@ def report_parallel_switches(self):
# message summary
if not self.compact_report:
logger.warning("")
logger.warning("SUMMARY: %s occurences of parallel switches found."
logger.warning("SUMMARY: %s occurences of parallel switches found."
% len(diag_result))
else:
logger.info("PASSED: No parallel switches found.")
Expand Down
20 changes: 10 additions & 10 deletions pandapower/test/api/test_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ def test_nominal_voltages_dont_match(test_net, diag_params, report_methods):
assert report_check

net.trafo = copy.deepcopy(trafo_copy)
net.trafo.vn_hv_kv.at[0] *= 1.3
net.trafo.vn_lv_kv.at[0] *= 1.3
net.trafo.vn_hv_kv.at[0] *= 1.29
net.trafo.vn_lv_kv.at[0] *= 1.29
check_result = pp.nominal_voltages_dont_match(net, diag_params['nom_voltage_tolerance'])
if check_result:
diag_results = {check_function: check_result}
Expand All @@ -691,8 +691,8 @@ def test_nominal_voltages_dont_match(test_net, diag_params, report_methods):
assert report_check

net.trafo = copy.deepcopy(trafo_copy)
net.trafo.vn_hv_kv.at[0] *= 0.7
net.trafo.vn_lv_kv.at[0] *= 0.7
net.trafo.vn_hv_kv.at[0] *= 0.71
net.trafo.vn_lv_kv.at[0] *= 0.71
check_result = pp.nominal_voltages_dont_match(net, diag_params['nom_voltage_tolerance'])
if check_result:
diag_results = {check_function: check_result}
Expand Down Expand Up @@ -778,9 +778,9 @@ def test_nominal_voltages_dont_match(test_net, diag_params, report_methods):
assert report_check

net.trafo3w = copy.deepcopy(trafo3w_copy)
net.trafo3w.vn_hv_kv.at[0] *= 1.3
net.trafo3w.vn_mv_kv.at[0] *= 1.3
net.trafo3w.vn_lv_kv.at[0] *= 1.3
net.trafo3w.vn_hv_kv.at[0] *= 1.29
net.trafo3w.vn_mv_kv.at[0] *= 1.29
net.trafo3w.vn_lv_kv.at[0] *= 1.29
check_result = pp.nominal_voltages_dont_match(net, diag_params['nom_voltage_tolerance'])
if check_result:
diag_results = {check_function: check_result}
Expand All @@ -799,9 +799,9 @@ def test_nominal_voltages_dont_match(test_net, diag_params, report_methods):
assert report_check

net.trafo3w = copy.deepcopy(trafo3w_copy)
net.trafo3w.vn_hv_kv.at[0] *= 0.7
net.trafo3w.vn_mv_kv.at[0] *= 0.7
net.trafo3w.vn_lv_kv.at[0] *= 0.7
net.trafo3w.vn_hv_kv.at[0] *= 0.71
net.trafo3w.vn_mv_kv.at[0] *= 0.71
net.trafo3w.vn_lv_kv.at[0] *= 0.71
check_result = pp.nominal_voltages_dont_match(net, diag_params['nom_voltage_tolerance'])
if check_result:
diag_results = {check_function: check_result}
Expand Down

0 comments on commit 6cb4134

Please sign in to comment.