Skip to content

Commit

Permalink
WIP: converter PF -> pp validate results for vsc, bus_dc, line_dc
Browse files Browse the repository at this point in the history
  • Loading branch information
rbolgaryn committed Nov 5, 2023
1 parent 8979e11 commit 35ef588
Showing 1 changed file with 63 additions and 5 deletions.
68 changes: 63 additions & 5 deletions pandapower/converter/powerfactory/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _get_pf_results_balanced(net):
'res_switch' in net.keys() else pd.Series(dtype=np.float64)
pf_bus_vm = net.res_bus.pf_vm_pu.replace(0, np.nan)
pf_bus_va = net.res_bus.pf_va_degree
pf_bus_dc_vm = net.res_bus_dc.pf_vm_pu.replace(0, np.nan)
pf_ext_grid_p = net.res_ext_grid.pf_p
pf_ext_grid_q = net.res_ext_grid.pf_q
pf_gen_p = net.res_gen.pf_p if len(net.gen) > 0 else pd.Series([], dtype=np.float64)
Expand All @@ -44,16 +45,24 @@ def _get_pf_results_balanced(net):
pf_sgen_q = net.res_sgen.pf_q if len(net.sgen) > 0 else pd.Series([], dtype=np.float64)
pf_load_p = net.res_load.pf_p if len(net.load) > 0 else pd.Series([], dtype=np.float64)
pf_load_q = net.res_load.pf_q if len(net.load) > 0 else pd.Series([], dtype=np.float64)
pf_vsc_p = net.res_vsc.pf_p_mw if len(net.vsc) > 0 else pd.Series([], dtype=np.float64)
pf_vsc_q = net.res_vsc.pf_q_mvar if len(net.vsc) > 0 else pd.Series([], dtype=np.float64)
pf_vsc_p_dc = net.res_vsc.pf_p_dc_mw if len(net.vsc) > 0 else pd.Series([], dtype=np.float64)
pf_line_loading = net.res_line.pf_loading if len(net.line) > 0 else pd.Series([], dtype=np.float64)
pf_line_dc_loading = net.res_line_dc.pf_loading if len(net.line_dc) > 0 else pd.Series([], dtype=np.float64)
pf_trafo_loading = net.res_trafo.pf_loading if len(net.trafo) > 0 else pd.Series([], dtype=np.float64)
pf_trafo3w_loading = net.res_trafo3w.pf_loading if len(net.trafo3w) > 0 else pd.Series([], dtype=np.float64)

pf_results = {
"pf_bus_vm": pf_bus_vm, "pf_bus_va": pf_bus_va, "pf_ext_grid_p": pf_ext_grid_p,
"pf_ext_grid_q": pf_ext_grid_q, "pf_gen_p": pf_gen_p, "pf_gen_q": pf_gen_q,
"pf_ward_p": pf_ward_p, "pf_ward_q": pf_ward_q, "pf_xward_p": pf_xward_p,
"pf_xward_q": pf_xward_q, "pf_sgen_p": pf_sgen_p, "pf_sgen_q": pf_sgen_q,
"pf_load_p": pf_load_p, "pf_load_q": pf_load_q, "pf_line_loading": pf_line_loading,
"pf_bus_vm": pf_bus_vm, "pf_bus_va": pf_bus_va, "pf_bus_dc_vm": pf_bus_dc_vm,
"pf_ext_grid_p": pf_ext_grid_p, "pf_ext_grid_q": pf_ext_grid_q,
"pf_gen_p": pf_gen_p, "pf_gen_q": pf_gen_q,
"pf_ward_p": pf_ward_p, "pf_ward_q": pf_ward_q,
"pf_xward_p": pf_xward_p, "pf_xward_q": pf_xward_q,
"pf_sgen_p": pf_sgen_p, "pf_sgen_q": pf_sgen_q,
"pf_load_p": pf_load_p, "pf_load_q": pf_load_q,
"pf_vsc_p": pf_vsc_p, "pf_vsc_q": pf_vsc_q, "pf_vsc_p_dc": pf_vsc_p_dc,
"pf_line_loading": pf_line_loading, "pf_line_dc_loading": pf_line_dc_loading,
"pf_trafo_loading": pf_trafo_loading, "pf_trafo3w_loading": pf_trafo3w_loading,
'pf_switch_status': pf_switch_status
}
Expand Down Expand Up @@ -155,6 +164,7 @@ def _set_pf_results_balanced(net, pf_results):

net.res_bus["pf_vm_pu"] = pf_results["pf_bus_vm"]
net.res_bus["pf_va_degree"] = pf_results["pf_bus_va"]
net.res_bus_dc["pf_vm_pu"] = pf_results["pf_bus_dc_vm"]
net.res_ext_grid["pf_p"] = pf_results["pf_ext_grid_p"]
net.res_ext_grid["pf_q"] = pf_results["pf_ext_grid_q"]
net.res_gen["pf_p"] = pf_results["pf_gen_p"]
Expand All @@ -167,7 +177,11 @@ def _set_pf_results_balanced(net, pf_results):
net.res_sgen["pf_q"] = pf_results["pf_sgen_q"]
net.res_load["pf_p"] = pf_results["pf_load_p"]
net.res_load["pf_q"] = pf_results["pf_load_q"]
net.res_vsc["pf_p_mw"] = pf_results["pf_vsc_p"]
net.res_vsc["pf_q_mvar"] = pf_results["pf_vsc_q"]
net.res_vsc["pf_p_dc_mw"] = pf_results["pf_vsc_p_dc"]
net.res_line["pf_loading"] = pf_results["pf_line_loading"]
net.res_line_dc["pf_loading"] = pf_results["pf_line_dc_loading"]
net.res_trafo["pf_loading"] = pf_results["pf_trafo_loading"]
net.res_trafo3w["pf_loading"] = pf_results["pf_trafo3w_loading"]

Expand Down Expand Up @@ -386,6 +400,16 @@ def _validate_pf_conversion_balanced(net, in_both, all_diffs):
all_diffs["diff_vm"] = diff_vm
all_diffs["diff_va"] = diff_va

if len(net.bus_dc[net.bus_dc.in_service]) > 0:
bus_dc_idx = net.bus_dc.query('in_service').index
bus_dc_diff = net.res_bus_dc.loc[bus_dc_idx].pf_vm_pu - net.res_bus_dc.loc[
bus_dc_idx].vm_pu
bus_dc_id = abs(bus_dc_diff).abs().idxmax().astype('int64')
logger.info("Maximum bus_dc vm_pu difference between pandapower and powerfactory: %.1f "
"p.u. at bus_dc %d (%s)" % (
max(abs(bus_dc_diff)), bus_dc_id, net.bus_dc.at[bus_dc_id, 'name']))
all_diffs["bus_dc_diff"] = bus_dc_diff

if len(net.line[net.line.in_service]) > 0:
section_loadings = pd.concat([net.line[["name", "line_idx"]], net.res_line[
["loading_percent", "pf_loading"]]], axis=1)
Expand All @@ -401,6 +425,16 @@ def _validate_pf_conversion_balanced(net, in_both, all_diffs):
max(abs(line_diff)), line_id, net.line.at[line_id, 'name']))
all_diffs["line_diff"] = line_diff

if len(net.line_dc[net.line_dc.in_service]) > 0:
line_dc_idx = net.line_dc.query('in_service').index
line_dc_diff = net.res_line_dc.loc[line_dc_idx].pf_loading - net.res_line_dc.loc[
line_dc_idx].loading_percent
line_dc_id = abs(line_dc_diff).idxmax().astype('int64')
logger.info("Maximum line_dc loading difference between pandapower and powerfactory: %.1f "
"percent at line_dc %d (%s)" % (
max(abs(line_dc_diff)), line_dc_id, net.line_dc.at[line_dc_id, 'name']))
all_diffs["line_dc_diff"] = line_dc_diff

if len(net.trafo[net.trafo.in_service]) > 0:
trafo_idx = net.trafo.query('in_service').index
trafo_diff = net.res_trafo.loc[trafo_idx].pf_loading - net.res_trafo.loc[
Expand Down Expand Up @@ -428,6 +462,30 @@ def _validate_pf_conversion_balanced(net, in_both, all_diffs):
all_diffs["load_p_diff_is"] = load_p_diff_is
all_diffs["load_q_diff_is"] = load_q_diff_is

if len(net.vsc[net.vsc.in_service]) > 0:
logger.debug('verifying vsc')
vsc_p_diff = net.res_vsc.pf_p_mw.replace(np.nan, 0) - net.res_vsc.p_mw
vsc_q_diff = net.res_vsc.pf_q_mvar.replace(np.nan, 0) - net.res_vsc.q_mvar
vsc_p_dc_diff = net.res_vsc.pf_p_dc_mw.replace(np.nan, 0) - net.res_vsc.p_dc_mw
vsc_p_diff_is = net.res_vsc.pf_p_mw.replace(np.nan, 0) * net.vsc.loc[
net.res_vsc.index, 'in_service'] - net.res_vsc.p_mw
vsc_q_diff_is = net.res_vsc.pf_q_mvar.replace(np.nan, 0) * net.vsc.loc[
net.res_vsc.index, 'in_service'] - net.res_vsc.q_mvar
vsc_p_dc_diff_is = net.res_vsc.pf_p_dc_mw.replace(np.nan, 0) * net.vsc.loc[
net.res_vsc.index, 'in_service'] - net.res_vsc.p_dc_mw
logger.info("Maximum vsc AC reactive power difference between pandapower and powerfactory: "
"%.1f Mvar, in service only: %.1f Mvar" % (max(abs(vsc_q_diff)),
max(abs(vsc_q_diff_is))))
logger.info("Maximum vsc AC active power difference between pandapower and powerfactory: "
"%.1f MW, in service only: %.1f MW" % (max(abs(vsc_p_diff)),
max(abs(vsc_p_diff_is))))
logger.info("Maximum vsc DC active power difference between pandapower and powerfactory: "
"%.1f MW, in service only: %.1f MW" % (max(abs(vsc_p_dc_diff)),
max(abs(vsc_p_dc_diff_is))))
all_diffs["vsc_p_diff_is"] = vsc_p_diff_is
all_diffs["vsc_q_diff_is"] = vsc_q_diff_is
all_diffs["vsc_p_dc_diff_is"] = vsc_p_dc_diff_is

logger.debug('verifying ext_grid')
eg_oos = net.ext_grid[~net.ext_grid.in_service].index
ext_grid_p_diff = net.res_ext_grid.pf_p.replace(np.nan, 0).drop(eg_oos) - net.res_ext_grid.p_mw
Expand Down

0 comments on commit 35ef588

Please sign in to comment.