Skip to content

Commit

Permalink
[CHANGED] from_ppc: no detect_trafo anymore
Browse files Browse the repository at this point in the history
[ADDED] networks: case300, cigre_network_mv with_der='all' der
  • Loading branch information
smeinecke committed Jan 23, 2017
1 parent 30e8c42 commit 20cf669
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 164 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Change Log
=============
- [CHANGED] from_ppc: no detect_trafo anymore
- [ADDED] networks: case118, case300, cigre_network_mv with_der='all' der

[1.1.1] - 2017-01-12
----------------------
Expand Down
7 changes: 6 additions & 1 deletion doc/networks/ieee.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ IEEE cases

.. note::

All IEEE case files were converted from PYPOWER
All IEEE case files were converted from `PYPOWER <https:/pypi.python.org/pypi/PYPOWER>`_.


Case 4gs
Expand Down Expand Up @@ -83,3 +83,8 @@ Case 118
---------

.. autofunction:: pandapower.networks.case118

Case 300
---------

.. autofunction:: pandapower.networks.case118
File renamed without changes
208 changes: 67 additions & 141 deletions pandapower/converter/pypower/from_ppc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
logger = logging.getLogger(__name__)


def from_ppc(ppc, f_hz=50, detect_trafo='vn_kv'):
def from_ppc(ppc, f_hz=50):
"""
This function converts pypower case files to pandapower net structure.
Expand All @@ -32,9 +32,6 @@ def from_ppc(ppc, f_hz=50, detect_trafo='vn_kv'):
**f_hz** - The frequency of the network.
**detect_trafo** - In case of 'vn_kv' trafos are detected by different bus voltages.
In case of 'ratio' trafos are detected by tap ratios != 0.
OUTPUT:
**net**
Expand Down Expand Up @@ -123,107 +120,61 @@ def from_ppc(ppc, f_hz=50, detect_trafo='vn_kv'):
from_bus = pp.get_element_index(net, 'bus', name=int(ppc['branch'][i, 0]))
to_bus = pp.get_element_index(net, 'bus', name=int(ppc['branch'][i, 1]))

if detect_trafo == 'vn_kv':
from_vn_kv = ppc['bus'][from_bus, 9]
to_vn_kv = ppc['bus'][to_bus, 9]
if from_vn_kv == to_vn_kv:
Zni = ppc['bus'][to_bus, 9]**2/baseMVA # ohm

pp.create_line_from_parameters(
net, from_bus=from_bus, to_bus=to_bus, length_km=1,
r_ohm_per_km=ppc['branch'][i, 2]*Zni, x_ohm_per_km=ppc['branch'][i, 3]*Zni,
c_nf_per_km=ppc['branch'][i, 4]/Zni/omega*1e9/2,
imax_ka=ppc['branch'][i, 5]/ppc['bus'][to_bus, 9], type='ol',
in_service=bool(ppc['branch'][i, 10]))
if (ppc['branch'][i, 8] != 0) | (ppc['branch'][i, 8] != 1):
logger.error('A line do not have a ratio but the '
'ratio of pypower branch %d (from_bus, to_bus)=(%d, %d) is '
'not zero.', i, ppc['branch'][i, 0], ppc['branch'][i, 1])
else:
if from_vn_kv > to_vn_kv:
hv_bus = from_bus
vn_hv_kv = from_vn_kv
lv_bus = to_bus
vn_lv_kv = to_vn_kv
tp_side = 'hv'
else:
hv_bus = to_bus
vn_hv_kv = to_vn_kv
lv_bus = from_bus
vn_lv_kv = from_vn_kv
tp_side = 'lv'
rk = ppc['branch'][i, 2]
xk = ppc['branch'][i, 3]
zk = (rk**2+xk**2)**0.5
sn = ppc['branch'][i, 5]*1e3
ratio_1 = 0 if ppc['branch'][i, 8] == 0 else (ppc['branch'][i, 8] - 1) * 100
i0_percent = -ppc['branch'][i, 4]*100*baseMVA*1e3/sn
if i0_percent < 0:
logger.error('A transformer always behaves inductive consumpting but the '
'susceptance of pypower branch %d (from_bus, to_bus)=(%d, %d) is '
'positive.', i, ppc['branch'][i, 0], ppc['branch'][i, 1])

pp.create_transformer_from_parameters(
net, hv_bus=hv_bus, lv_bus=lv_bus, sn_kva=sn, vn_hv_kv=vn_hv_kv,
vn_lv_kv=vn_lv_kv, vsc_percent=zk*sn/1e3, vscr_percent=rk*sn/1e3, pfe_kw=0,
i0_percent=i0_percent, shift_degree=ppc['branch'][i, 9],
tp_st_percent=abs(ratio_1) if ratio_1 else nan,
tp_pos=sign(ratio_1) if ratio_1 else nan,
tp_side=tp_side if ratio_1 else None, tp_mid=0 if ratio_1 else nan)

elif detect_trafo == 'ratio':
if ppc['branch'][i, 8] == 0:
Zni = ppc['bus'][to_bus, 9]**2/baseMVA # ohm

pp.create_line_from_parameters(
net, from_bus=from_bus, to_bus=to_bus, length_km=1,
r_ohm_per_km=ppc['branch'][i, 2]*Zni, x_ohm_per_km=ppc['branch'][i, 3]*Zni,
c_nf_per_km=ppc['branch'][i, 4]/Zni/omega*1e9/2,
imax_ka=ppc['branch'][i, 5]/ppc['bus'][to_bus, 9], type='ol',
in_service=bool(ppc['branch'][i, 10]))
from_vn_kv = ppc['bus'][from_bus, 9]
to_vn_kv = ppc['bus'][to_bus, 9]
if (from_vn_kv == to_vn_kv) & ((ppc['branch'][i, 8] == 0) | (ppc['branch'][i, 8] == 1)):
Zni = ppc['bus'][to_bus, 9]**2/baseMVA # ohm

pp.create_line_from_parameters(
net, from_bus=from_bus, to_bus=to_bus, length_km=1,
r_ohm_per_km=ppc['branch'][i, 2]*Zni, x_ohm_per_km=ppc['branch'][i, 3]*Zni,
c_nf_per_km=ppc['branch'][i, 4]/Zni/omega*1e9/2,
imax_ka=ppc['branch'][i, 5]/ppc['bus'][to_bus, 9], type='ol',
in_service=bool(ppc['branch'][i, 10]))

else:
if from_vn_kv >= to_vn_kv:
hv_bus = from_bus
vn_hv_kv = from_vn_kv
lv_bus = to_bus
vn_lv_kv = to_vn_kv
tp_side = 'hv'
else:
from_vn_kv = ppc['bus'][from_bus, 9]
to_vn_kv = ppc['bus'][to_bus, 9]
if from_vn_kv >= to_vn_kv:
hv_bus = from_bus
vn_hv_kv = from_vn_kv
lv_bus = to_bus
vn_lv_kv = to_vn_kv
tp_side = 'hv'
if from_vn_kv == to_vn_kv:
logger.debug('A transformer voltage is on both side the same.')
else:
hv_bus = to_bus
vn_hv_kv = to_vn_kv
lv_bus = from_bus
vn_lv_kv = from_vn_kv
tp_side = 'lv'
rk = ppc['branch'][i, 2]
xk = ppc['branch'][i, 3]
zk = (rk**2+xk**2)**0.5
sn = ppc['branch'][i, 5]*1e3
ratio_1 = (ppc['branch'][i, 8] - 1) * 100
i0_percent = ppc['branch'][i, 4]*100*baseMVA*1e3/sn
if i0_percent > 0:
logger.error('A transformer always behaves inductive consumpting but the '
'susceptance of pypower branch %d (from_bus, to_bus)=(%d, %d) is '
'positive', i, ppc['branch'][i, 0], ppc['branch'][i, 1])

pp.create_transformer_from_parameters(
net, hv_bus=hv_bus, lv_bus=lv_bus, sn_kva=sn, vn_hv_kv=vn_hv_kv,
vn_lv_kv=vn_lv_kv, vsc_percent=zk*sn/1e3, vscr_percent=rk*sn/1e3, pfe_kw=0,
i0_percent=i0_percent, shift_degree=ppc['branch'][i, 9],
tp_st_percent=abs(ratio_1) if ratio_1 else nan,
tp_pos=sign(ratio_1) if ratio_1 else nan,
tp_side=tp_side if ratio_1 else None, tp_mid=0 if ratio_1 else nan)
hv_bus = to_bus
vn_hv_kv = to_vn_kv
lv_bus = from_bus
vn_lv_kv = from_vn_kv
tp_side = 'lv'
if from_vn_kv == to_vn_kv:
logger.warn('The pypower branch %d (from_bus, to_bus)=(%d, %d) is considered as'
'a transformer because of a ratio != 0 | 1 but it connects the same'
' voltage level', i, ppc['branch'][i, 0], ppc['branch'][i, 1])
rk = ppc['branch'][i, 2]
xk = ppc['branch'][i, 3]
zk = (rk**2+xk**2)**0.5
sn = ppc['branch'][i, 5]*1e3
ratio_1 = 0 if ppc['branch'][i, 8] == 0 else (ppc['branch'][i, 8] - 1) * 100
i0_percent = -ppc['branch'][i, 4]*100*baseMVA*1e3/sn
if i0_percent < 0:
logger.error('A transformer always behaves inductive consumpting but the '
'susceptance of pypower branch %d (from_bus, to_bus)=(%d, %d) is '
'positive.', i, ppc['branch'][i, 0], ppc['branch'][i, 1])

pp.create_transformer_from_parameters(
net, hv_bus=hv_bus, lv_bus=lv_bus, sn_kva=sn, vn_hv_kv=vn_hv_kv,
vn_lv_kv=vn_lv_kv, vsc_percent=zk*sn/1e3, vscr_percent=rk*sn/1e3, pfe_kw=0,
i0_percent=i0_percent, shift_degree=ppc['branch'][i, 9],
tp_st_percent=abs(ratio_1) if ratio_1 else nan,
tp_pos=sign(ratio_1) if ratio_1 else nan,
tp_side=tp_side if ratio_1 else None, tp_mid=0 if ratio_1 else nan)
# unused data of ppc: rateB, rateC

# gencost, areas are currently unconverted

return net


def validate_from_ppc(ppc_net, pp_net, detect_trafo='vn_kv', max_diff_values={
def validate_from_ppc(ppc_net, pp_net, max_diff_values={
"vm_pu": 1e-6, "va_degree": 1e-5, "p_branch_kw": 1e-3, "q_branch_kvar": 1e-3, "p_gen_kw": 1e-3,
"q_gen_kvar": 1e-3}):
"""
Expand All @@ -238,9 +189,6 @@ def validate_from_ppc(ppc_net, pp_net, detect_trafo='vn_kv', max_diff_values={
OPTIONAL:
**detect_trafo** - In case of 'vn_kv' trafos are detected by different bus voltages.
In case of 'ratio' trafos are detected by tap ratios != 0.
**max_diff_values** - Dict of maximal allowed difference values. The keys must be
'vm_pu', 'va_degree', 'p_branch_kw', 'q_branch_kvar', 'p_gen_kw' and 'q_gen_kvar' and
the values floats.
Expand Down Expand Up @@ -329,48 +277,26 @@ def validate_from_ppc(ppc_net, pp_net, detect_trafo='vn_kv', max_diff_values={
for i in BRANCHES_uniq.index:
from_bus = pp.get_element_index(pp_net, 'bus', name=int(ppc_res['branch'][i, 0]))
to_bus = pp.get_element_index(pp_net, 'bus', name=int(ppc_res['branch'][i, 1]))
# detect_trafo == 'vn_kv'
if detect_trafo == 'vn_kv':
from_vn_kv = ppc_res['bus'][from_bus, 9]
to_vn_kv = ppc_res['bus'][to_bus, 9]
if from_vn_kv == to_vn_kv:
pp_res_branch = append(pp_res_branch, array(pp_net.res_line[
(pp_net.line.from_bus == from_bus) & (pp_net.line.to_bus == to_bus)]
[['p_from_kw', 'q_from_kvar', 'p_to_kw', 'q_to_kvar']]), 0)
else:
if from_vn_kv >= to_vn_kv:
hv_bus = from_bus
lv_bus = to_bus
pp_res_branch = append(pp_res_branch, array(pp_net.res_trafo[
(pp_net.trafo.hv_bus == hv_bus) & (pp_net.trafo.lv_bus == lv_bus)]
[['p_hv_kw', 'q_hv_kvar', 'p_lv_kw', 'q_lv_kvar']]), 0)
else:
hv_bus = to_bus
lv_bus = from_bus
pp_res_branch = append(pp_res_branch, array(pp_net.res_trafo[
(pp_net.trafo.hv_bus == hv_bus) & (pp_net.trafo.lv_bus == lv_bus)]
[['p_lv_kw', 'q_lv_kvar', 'p_hv_kw', 'q_hv_kvar']]), 0)
# detect_trafo == 'ratio'
elif detect_trafo == 'ratio':
if ppc_res['branch'][i, 8] == 0:
pp_res_branch = append(pp_res_branch, array(pp_net.res_line[
(pp_net.line.from_bus == from_bus) & (pp_net.line.to_bus == to_bus)]
[['p_from_kw', 'q_from_kvar', 'p_to_kw', 'q_to_kvar']]), 0)
from_vn_kv = ppc_res['bus'][from_bus, 9]
to_vn_kv = ppc_res['bus'][to_bus, 9]
if (from_vn_kv == to_vn_kv) & ((ppc_res['branch'][i, 8] == 0) |
(ppc_res['branch'][i, 8] == 1)):
pp_res_branch = append(pp_res_branch, array(pp_net.res_line[
(pp_net.line.from_bus == from_bus) & (pp_net.line.to_bus == to_bus)]
[['p_from_kw', 'q_from_kvar', 'p_to_kw', 'q_to_kvar']]), 0)
else:
if from_vn_kv >= to_vn_kv:
hv_bus = from_bus
lv_bus = to_bus
pp_res_branch = append(pp_res_branch, array(pp_net.res_trafo[
(pp_net.trafo.hv_bus == hv_bus) & (pp_net.trafo.lv_bus == lv_bus)]
[['p_hv_kw', 'q_hv_kvar', 'p_lv_kw', 'q_lv_kvar']]), 0)
else:
from_vn_kv = ppc_res['bus'][from_bus, 9]
to_vn_kv = ppc_res['bus'][to_bus, 9]
if from_vn_kv >= to_vn_kv:
hv_bus = from_bus
lv_bus = to_bus
pp_res_branch = append(pp_res_branch, array(pp_net.res_trafo[
(pp_net.trafo.hv_bus == hv_bus) & (pp_net.trafo.lv_bus == lv_bus)]
[['p_hv_kw', 'q_hv_kvar', 'p_lv_kw', 'q_lv_kvar']]), 0)
else:
hv_bus = to_bus
lv_bus = from_bus
pp_res_branch = append(pp_res_branch, array(pp_net.res_trafo[
(pp_net.trafo.hv_bus == hv_bus) & (pp_net.trafo.lv_bus == lv_bus)]
[['p_lv_kw', 'q_lv_kvar', 'p_hv_kw', 'q_hv_kvar']]), 0)
hv_bus = to_bus
lv_bus = from_bus
pp_res_branch = append(pp_res_branch, array(pp_net.res_trafo[
(pp_net.trafo.hv_bus == hv_bus) & (pp_net.trafo.lv_bus == lv_bus)]
[['p_lv_kw', 'q_lv_kvar', 'p_hv_kw', 'q_hv_kvar']]), 0)
pp_res_branch = pp_res_branch[1:, :]

# --- do the power flow result comparison
Expand Down
Binary file added pandapower/networks/ieee_case_pickles/case300.p
Binary file not shown.
19 changes: 19 additions & 0 deletions pandapower/networks/ieee_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,25 @@ def case118():
return case118


def case300():
"""
Calls the pickle file case300.p which data origin is `PYPOWER <https:/pypi.python.org/pypi/PYPOWER>`_.
Some more information about this network are given by `Washington <http://www2.ee.washington.edu/research/pstca/pf300/pg_tca300bus.htm>`_ and `Illinois University <http://icseg.iti.illinois.edu/ieee-300-bus-system/>`_.
RETURN:
**net** - Returns the required ieee network case300
EXAMPLE:
import pandapower.networks as pn
net = pn.case300()
"""
case300 = pp.from_pickle(os.path.join(_get_networks_path(), "ieee_case_pickles", "case300.p"))
return case300


if __name__ == "__main__":
import pandapower.networks as pn
net = pn.networks.case9()
2 changes: 1 addition & 1 deletion pandapower/test/converter/ppc_testgrids.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def case2_1():
# branch data
# fbus, tbus, r, x, b, rateA, rateB, rateC, ratio, angle, status, angmin, angmax
ppc["branch"] = array([
[3, 0, 0, 0.05, 0, 250, 250, 250, 0, 0, 1, -360, 360]
[3, 0, 0, 0.05, 0, 250, 250, 250, 1, 0, 1, -360, 360]
])
return ppc

Expand Down
25 changes: 4 additions & 21 deletions pandapower/test/converter/test_from_ppc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,11 @@ def test_from_ppc():
assert len(net_by_ppc.ext_grid) == len(net_by_code.ext_grid)
assert pp.nets_equal(net_by_ppc, net_by_code, check_only_results=True, tol=1.e-9)

# check detect_trafo
ppc2_4 = testgrids.case2_4()
net1 = from_ppc(ppc2_4, detect_trafo='vn_kv')
net2 = from_ppc(ppc2_4, detect_trafo='ratio')
assert type(net1) == type(net_by_code)
assert type(net2) == type(net_by_code)
assert len(net1.trafo) == 1
assert len(net1.line) == 0
assert len(net2.trafo) == 0
assert len(net2.line) == 1


def test_validate_from_ppc():
ppc = testgrids.case2_2()
net = testgrids.case2_2_by_code()
assert validate_from_ppc(ppc, net, max_diff_values=max_diff_values1,
detect_trafo='vn_kv')
assert validate_from_ppc(ppc, net, max_diff_values=max_diff_values1)


def test_ppc_testgrids():
Expand All @@ -67,19 +55,14 @@ def test_ppc_testgrids():

def test_pypower_cases():
# check pypower cases
name = ['case4gs', 'case6ww', 'case30', 'case30pwl', 'case30Q', 'case39', 'case118']
name = ['case4gs', 'case6ww', 'case30', 'case30pwl', 'case30Q', 'case39', 'case118', 'case300']
for i in name:
module = __import__('pypower.' + i)
submodule = getattr(module, i)
my_function = getattr(submodule, i)
ppc = my_function()
if i == 'case39':
net = from_ppc(ppc, f_hz=60, detect_trafo='ratio')
assert validate_from_ppc(ppc, net, max_diff_values=max_diff_values1,
detect_trafo='ratio')
else:
net = from_ppc(ppc, f_hz=60)
assert validate_from_ppc(ppc, net, max_diff_values=max_diff_values1)
net = from_ppc(ppc, f_hz=60)
assert validate_from_ppc(ppc, net, max_diff_values=max_diff_values1)
logger.debug('%s has been checked successfully.' % i)
# --- Because there is a pypower power flow failure in generator results in case9 (which is not
# in matpower) another max_diff_values must be used to receive an successful validation
Expand Down
Loading

0 comments on commit 20cf669

Please sign in to comment.