Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenMeinecke authored Jan 18, 2024
2 parents ea93e96 + 6191198 commit 922ebc4
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ Change Log
- [ADDED] option to use a second tap changer for the trafo element
- [CHANGED] parameters of function merge_internal_net_and_equivalent_external_net()
- [FIXED] :code:`convert_format.py`: update the attributes of the characteristic objects to match the new characteristic
- [FIXED] fixed the wrong id numbers for pypower powerflow algorithms fdxb and fdbx
- [FIXED] additional arguments from mpc saved to net._options: create "_options" if it does not exist
- [CHANGED] cim2pp: extracted getting default classes, added generic setting datatypes from CGMES XMI schema
- [ADDED] function :code:`getOTDF` to obtain Outage Transfer Distribution Factors, that can be used to analyse outages using the DC approximation of the power system
- [CHANGED] DFData datasource behavior to enable timeseries calculation with time-dependent nonnumeric data (ConstControl)
- [ADDED] function :code:`outage_results_OTDF` to obtain the matrix of results for all outage scenarios, with rows as outage scenarios and columns as branch power flows in that scenario

- [FIXED] add some safeguards for TDPF to avoid numerical issues in some cases
- [ADDED] the function :code:`run_contingency` can raise a captured error if parameter :code:`raise_errors` is passed

[2.13.1] - 2023-05-12
-------------------------------
Expand Down
3 changes: 3 additions & 0 deletions pandapower/contingency/contingency.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def run_contingency(net, nminus1_cases, pf_options=None, pf_options_nminus1=None
"""
# set up the dict for results and relevant variables
# ".get" in case the options have been set in pp.set_user_pf_options:
raise_errors = kwargs.get("raise_errors", False)
if "recycle" in kwargs: kwargs["recycle"] = False # so that we can be sure it doesn't happen
if pf_options is None: pf_options = net.user_pf_options.get("pf_options", net.user_pf_options)
if pf_options_nminus1 is None: pf_options_nminus1 = net.user_pf_options.get("pf_options_nminus1",
Expand Down Expand Up @@ -104,6 +105,8 @@ def run_contingency(net, nminus1_cases, pf_options=None, pf_options_nminus1=None
cause_element=element, cause_index=i)
except Exception as err:
logger.error(f"{element} {i} causes {err}")
if raise_errors:
raise err
finally:
net[element].at[i, 'in_service'] = True

Expand Down
2 changes: 1 addition & 1 deletion pandapower/pf/create_jacobian_tdpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def calc_r_theta(t_air_pu, a0, a1, a2, i_square_pu, p_loss_pu):
2019, pp. 1-6, doi: 10.1109/EEEIC.2019.8783234.
"""
t_rise_pu = a0 + a1 * i_square_pu + a2 * np.square(i_square_pu) - t_air_pu
r_theta_pu = t_rise_pu / p_loss_pu
r_theta_pu = t_rise_pu / np.where(p_loss_pu == 0, 1e-6, p_loss_pu)
return r_theta_pu


Expand Down
2 changes: 1 addition & 1 deletion pandapower/pf/runpf_pypower.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _get_options(options, **kwargs):
max_iteration = options["max_iteration"]

# algorithms implemented within pypower
algorithm_pypower_dict = {'nr': 1, 'fdbx': 2, 'fdxb': 3, 'gs': 4}
algorithm_pypower_dict = {'nr': 1, 'fdxb': 2, 'fdbx': 3, 'gs': 4}

ppopt = ppoption(ENFORCE_Q_LIMS=enforce_q_lims, PF_TOL=tolerance_mva,
PF_ALG=algorithm_pypower_dict[algorithm], **kwargs)
Expand Down
17 changes: 12 additions & 5 deletions pandapower/plotting/generic_geodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,32 @@ def coords_from_igraph(graph, roots, meshed=False, calculate_meshed=False):
return list(zip(*layout.coords))


def coords_from_nxgraph(mg=None):
def coords_from_nxgraph(mg=None, layout_engine='neato'):
"""
Create a list of generic coordinates from a networkx graph layout.
:param mg: The networkx graph on which the coordinates shall be based
:type mg: networkx.Graph
:param layout_engine: GraphViz Layout Engine for layouting a network. See https://graphviz.org/docs/layouts/
:type layout_engine: str
:return: coords - list of coordinates from the graph layout
"""
# workaround for bug in agraph
for u, v in mg.edges(data=False, keys=False):
for u, v in mg.edges(data=False):
if 'key' in mg[int(u)][int(v)]:
del mg[int(u)][int(v)]['key']
if 'key' in mg[int(u)][int(v)][0]:
del mg[int(u)][int(v)][0]['key']
# ToDo: Insert fallback layout for nxgraph
return list(zip(*(list(nx.drawing.nx_agraph.graphviz_layout(mg, prog='neato').values()))))
return list(zip(*(list(nx.drawing.nx_agraph.graphviz_layout(mg, prog=layout_engine).values()))))


def create_generic_coordinates(net, mg=None, library="igraph",
respect_switches=False,
geodata_table="bus_geodata",
buses=None,
overwrite=False):
overwrite=False,
layout_engine='neato'):
"""
This function will add arbitrary geo-coordinates for all buses based on an analysis of branches
and rings. It will remove out of service buses/lines from the net. The coordinates will be
Expand All @@ -174,6 +177,8 @@ def create_generic_coordinates(net, mg=None, library="igraph",
:type net: pandapowerNet
:param mg: Existing networkx multigraph, if available. Convenience to save computation time.
:type mg: networkx.Graph
:param respect_switches: respect switches in a network for generic coordinates
:type respect_switches: bool
:param library: "igraph" to use igraph package or "networkx" to use networkx package
:type library: str
:param geodata_table: table to write the generic geodatas to
Expand All @@ -182,6 +187,8 @@ def create_generic_coordinates(net, mg=None, library="igraph",
:type buses: list
:param overwrite: overwrite existing geodata
:type overwrite: bool
:param layout_engine: GraphViz Layout Engine for layouting a network. See https://graphviz.org/docs/layouts/
:type layout_engine: str
:return: net - pandapower network with added geo coordinates for the buses
:Example:
Expand All @@ -200,7 +207,7 @@ def create_generic_coordinates(net, mg=None, library="igraph",
include_out_of_service=True)
else:
nxg = copy.deepcopy(mg)
coords = coords_from_nxgraph(nxg)
coords = coords_from_nxgraph(nxg, layout_engine=layout_engine)
else:
raise ValueError("Unknown library %s - chose 'igraph' or 'networkx'" % library)
if len(coords):
Expand Down
3 changes: 2 additions & 1 deletion pandapower/pypower/newtonpf.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ def newtonpf(Ybus, Sbus, V0, ref, pv, pq, ppci, options, makeYbus=None):

if tdpf:
# update the R, g, b for the tdpf_lines, and the Y-matrices
branch[tdpf_lines, BR_R] = r = r_ref_pu * (1 + alpha_pu * (T - t_ref_pu))
# here: limit the change of the R to reflect a realistic range of values for T to avoid numerical issues
branch[tdpf_lines, BR_R] = r = r_ref_pu * (1 + alpha_pu * np.clip(np.nan_to_num(T - t_ref_pu), -50, 250 / T_base))
# todo expansion with SSC and VSC (that are not controllable)
Ybus, Yf, Yt = makeYbus(baseMVA, bus, branch)
g, b = calc_g_b(r, x)
Expand Down
9 changes: 6 additions & 3 deletions pandapower/topology/graph_searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def connected_components(mg, notravbuses=set()):


def calc_distance_to_bus(net, bus, respect_switches=True, nogobuses=None,
notravbuses=None, weight='weight'):
notravbuses=None, weight='weight', g=None):
"""
Calculates the shortest distance between a source bus and all buses connected to it.
Expand All @@ -110,6 +110,8 @@ def calc_distance_to_bus(net, bus, respect_switches=True, nogobuses=None,
**weight** (string, None) – Edge data key corresponding to the edge weight.
**g** (nx.MultiGraph, None) – MultiGraph of the network. If None, the graph will be created.
OUTPUT:
**dist** - Returns a pandas series with containing all distances to the source bus
in km. If weight=None dist is the topological distance (int).
Expand All @@ -120,8 +122,9 @@ def calc_distance_to_bus(net, bus, respect_switches=True, nogobuses=None,
dist = top.calc_distance_to_bus(net, 5)
"""
g = create_nxgraph(net, respect_switches=respect_switches, nogobuses=nogobuses,
notravbuses=notravbuses)
if g is None:
g = create_nxgraph(net, respect_switches=respect_switches, nogobuses=nogobuses,
notravbuses=notravbuses)
return pd.Series(nx.single_source_dijkstra_path_length(g, bus, weight=weight))


Expand Down

0 comments on commit 922ebc4

Please sign in to comment.