Skip to content

Commit

Permalink
Merge branch 'develop' of gitlab:pp/pandapower into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenMeinecke committed Dec 4, 2017
2 parents 3e79a0b + e98f5d9 commit 5fde397
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
6 changes: 3 additions & 3 deletions pandapower/build_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,15 @@ def _calc_tap_from_dataframe(net, trafo_df):
INPUT:
**net** - The pandapower format network
**trafo** (Dataframe) - The dataframe in pd_net["structure"]["trafo"]
which contains transformer calculation values.
OUTPUT:
**vn_hv_kv** (1d array, float) - The adusted high voltages
**vn_lv_kv** (1d array, float) - The adjusted low voltages
**trafo_shift** (1d array, float) - phase shift angle
"""
Expand Down Expand Up @@ -679,7 +679,7 @@ def _calc_xward_parameter(net, ppc):
def _gather_branch_switch_info(bus, branch_id, branch_type, net):
# determine at which end the switch is located
# 1 = to-bus/lv-bus; 0 = from-bus/hv-bus

branch_id = int(branch_id)
if branch_type == "l":
branch_bus = net["line"]["to_bus"].at[branch_id]
is_to_bus = int(branch_bus == bus)
Expand Down
8 changes: 7 additions & 1 deletion pandapower/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,13 @@ def from_excel(filename, convert=True):

if not os.path.isfile(filename):
raise UserWarning("File %s does not exist!" % filename)
xls = pd.ExcelFile(filename).parse(sheetname=None)
try:
# pandas < 0.21
xls = pd.ExcelFile(filename).parse(sheetname=None)
except:
# pandas 0.21
xls = pd.ExcelFile(filename).parse(sheet_name=None)

try:
net = from_dict_of_dfs(xls)
restore_all_dtypes(net, xls["dtypes"])
Expand Down
17 changes: 11 additions & 6 deletions pandapower/test/api/test_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ def test_boolean(self, test_net, diag_params, report_methods):
net.sgen.loc[3, 'in_service'] = '0.0'
net.sgen.loc[4, 'in_service'] = 1
net.gen.loc[0, 'in_service'] = '1'
net.load.loc[0, 'in_service'] = 10
net.line.loc[0, 'in_service'] = -1
net.load.loc[0, 'in_service'] = '10'
net.line.loc[0, 'in_service'] = '-1'
net.bus.loc[0, 'in_service'] = 'no'
net.trafo.loc[0, 'in_service'] = 'True'
net.trafo3w.loc[0, 'in_service'] = None
Expand All @@ -206,7 +206,7 @@ def test_boolean(self, test_net, diag_params, report_methods):
net.switch.loc[2, 'closed'] = False
net.switch.loc[3, 'closed'] = 'False'
net.switch.loc[4, 'closed'] = None
net.switch.loc[5, 'closed'] = 10
net.switch.loc[5, 'closed'] = '10'

check_result = pp.invalid_values(net)
if check_result:
Expand All @@ -216,9 +216,14 @@ def test_boolean(self, test_net, diag_params, report_methods):
assert diag_results[check_function] == \
{'bus': [(0, 'in_service', 'no', 'boolean')],
'gen': [(0, 'in_service', '1', 'boolean')],
'sgen': [(2, 'in_service', '0', 'boolean'), (3, 'in_service', '0.0', 'boolean')],
'switch': [(1, 'closed', 'False', 'boolean'), (3, 'closed', 'False', 'boolean'),
(4, 'closed', 'None', 'boolean'), (5, 'closed', 10, 'boolean')],
'line': [(0, 'in_service', '-1', 'boolean')],
'load': [(0, 'in_service', '10', 'boolean')],
'sgen': [(2, 'in_service', '0', 'boolean'),
(3, 'in_service', '0.0', 'boolean')],
'switch': [(1, 'closed', 'False', 'boolean'),
(3, 'closed', 'False', 'boolean'),
(4, 'closed', 'None', 'boolean'),
(5, 'closed', '10', 'boolean')],
'trafo': [(0, 'in_service', 'True', 'boolean')],
'trafo3w': [(0, 'in_service', 'nan', 'boolean')]}

Expand Down
16 changes: 8 additions & 8 deletions pandapower/test/consistency_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def consistency_checks(net, rtol=1e-5):
indices_consistent(net)
branch_loss_consistent_with_bus_feed_in(net, rtol)
element_power_consistent_with_bus_power(net, rtol)

def indices_consistent(net):
for element in ["bus", "load", "ext_grid", "sgen", "trafo", "trafo3w", "line", "shunt",
for element in ["bus", "load", "ext_grid", "sgen", "trafo", "trafo3w", "line", "shunt",
"ward", "xward", "impedance", "gen", "dcline"]:
e_idx = net[element].index
res_idx = net["res_" + element].index
Expand All @@ -43,12 +43,12 @@ def branch_loss_consistent_with_bus_feed_in(net, rtol=1e-5):
bus_surplus_p = -net.res_bus.p_kw.sum()
bus_surplus_q = -net.res_bus.q_kvar.sum()

branch_loss_p = net.res_line.pl_kw.sum() + net.res_trafo.pl_kw.sum() + \
net.res_trafo3w.pl_kw.sum() + net.res_impedance.pl_kw.sum() + \
net.res_dcline.pl_kw.sum()
branch_loss_q = net.res_line.ql_kvar.sum() + net.res_trafo.ql_kvar.sum() + \
net.res_trafo3w.ql_kvar.sum() + net.res_impedance.ql_kvar.sum() + \
net.res_dcline.q_to_kvar.sum() + net.res_dcline.q_from_kvar.sum()
branch_loss_p = net.res_line.pl_kw.values.sum() + net.res_trafo.pl_kw.values.sum() + \
net.res_trafo3w.pl_kw.values.sum() + net.res_impedance.pl_kw.values.sum() + \
net.res_dcline.pl_kw.values.sum()
branch_loss_q = net.res_line.ql_kvar.values.sum() + net.res_trafo.ql_kvar.values.sum() + \
net.res_trafo3w.ql_kvar.values.sum() + net.res_impedance.ql_kvar.values.sum() + \
net.res_dcline.q_to_kvar.values.sum() + net.res_dcline.q_from_kvar.values.sum()

assert allclose(bus_surplus_p, branch_loss_p, rtol=rtol)
assert allclose(bus_surplus_q, branch_loss_q, rtol=rtol)
Expand Down
15 changes: 8 additions & 7 deletions pandapower/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,8 @@ def adapt_switches(net, element, offset=0):
switches = net.switch[net.switch.et == element[0]] # element[0] == "l" for "line", ect.
new_index = [net[element].index.get_loc(ix) + offset
for ix in switches.element.values]
net.switch.loc[switches.index, "element"] = new_index
if len(new_index):
net.switch.loc[switches.index, "element"] = new_index

for element, table in net.items():
if element.startswith("_") or element.startswith("res"):
Expand Down Expand Up @@ -1458,23 +1459,23 @@ def get_connected_buses(net, buses, consider=("l", "s", "t", "t3"), respect_swit

if "t" in consider:
in_service_constr = net.trafo.in_service if respect_in_service else True
opened_trafos = set(net.switch.loc[(~net.switch.closed) & (net.switch.et == "l")
opened_trafos = set(net.switch.loc[(~net.switch.closed) & (net.switch.et == "t")
].element.unique()) if respect_switches else {}
connected_hvb_trafos = set(net.trafo.index[
(net.trafo.hv_bus.isin(buses)) & ~net.trafo.index.isin(opened_trafos) &
(in_service_constr)])
connected_lvb_trafos = set(net.trafo.index[
(net.trafo.lv_bus.isin(buses)) & ~net.trafo.index.isin(opened_trafos) &
(in_service_constr)])
cb |= set(net.trafo[net.trafo.index.isin(connected_lvb_trafos)].lv_bus)
cb |= set(net.trafo[net.trafo.index.isin(connected_hvb_trafos)].hv_bus)
cb |= set(net.trafo.loc[connected_lvb_trafos].hv_bus.values)
cb |= set(net.trafo.loc[connected_hvb_trafos].lv_bus.values)

# Gives the lv mv and hv buses of a 3 winding transformer
if "t3" in consider:
ct3 = get_connected_elements(net, "trafo3w", buses, respect_switches, respect_in_service)
cb |= set(net.trafo3w[net.trafo3w.index.isin(ct3)].lv_bus)
cb |= set(net.trafo3w[net.trafo3w.index.isin(ct3)].mv_bus)
cb |= set(net.trafo3w[net.trafo3w.index.isin(ct3)].hv_bus)
cb |= set(net.trafo3w.loc[ct3].hv_bus.values)
cb |= set(net.trafo3w.loc[ct3].mv_bus.values)
cb |= set(net.trafo3w.loc[ct3].lv_bus.values)

if respect_in_service:
cb -= set(net.bus[~net.bus.in_service].index)
Expand Down
5 changes: 4 additions & 1 deletion pandapower/topology/create_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ def create_nxgraph(net, respect_switches=True, include_lines=True, include_trafo
if notravbuses is not None:
for b in notravbuses:
for i in list(mg[b].keys()):
del mg[b][i]
try:
del mg[b][i] #networkx versions < 2.0
except:
del mg._adj[b][i] #networkx versions 2.0
mg.remove_nodes_from(net.bus[~net.bus.in_service].index)
return mg
2 changes: 1 addition & 1 deletion pandapower/topology/graph_searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def find_graph_characteristics(g, roots, characteristics):
char_dict["notn1_areas"][grandparent].update(set(curr_notn1_area[:]))
else:
char_dict["notn1_areas"][grandparent] = set(curr_notn1_area[:])
curr_notn1_area.clear()
del curr_notn1_area[:]
notn1_area_start = None

return {key: char_dict[key] for key in characteristics}
Expand Down

0 comments on commit 5fde397

Please sign in to comment.