e2nIEE / pandapower
Showing 11 of 30 files from the diff.

@@ -166,7 +166,7 @@
Loading
166 166
        else:
167 167
            dodfs[item] = value
168 168
        # save dtypes
169 -
        for column, dtype in value.dtypes.iteritems():
169 +
        for column, dtype in value.dtypes.items():
170 170
            dtypes.append((item, column, str(dtype)))
171 171
    dodfs["dtypes"] = pd.DataFrame(dtypes, columns=["element", "column", "dtype"])
172 172
    if include_parameters and len(parameters) > 0:

@@ -8,7 +8,7 @@
Loading
8 8
from pandapower.pf.ppci_variables import _get_pf_variables_from_ppci
9 9
from pandapower.pf.run_newton_raphson_pf import _get_numba_functions, _get_Y_bus
10 10
from pandapower.run import _passed_runpp_parameters
11 -
from pandapower.auxiliary import _init_runpp_options
11 +
from pandapower.auxiliary import _init_runpp_options, _add_dcline_gens
12 12
import uuid
13 13
14 14
try:
@@ -292,15 +292,13 @@
Loading
292 292
293 293
294 294
def _ensure_unique_boundary_bus_names(net, boundary_buses):
295 -
    """ This function possibly changes the bus names of the boundaries buses to ensure
296 -
        that the names are unique.
295 +
    """ This function ad a unique name to each bounary bus. The original 
296 +
        boundary bus names are retained.
297 297
    """
298 -
    idx_dupl_null = net.bus.index[net.bus.name.duplicated(
299 -
        keep=False) | net.bus.name.isnull()]
300 -
    idx_add_names = set(boundary_buses) & set(idx_dupl_null)
301 -
    if len(idx_add_names):
302 -
        net.bus.name.loc[idx_add_names] = ["Boundary bus " + str(uuid.uuid1()) for _ in
303 -
                                           idx_add_names]
298 +
    assert "name_equivalent" not in net.bus.columns.tolist()
299 +
    net.bus["name_equivalent"] = "uuid"
300 +
    net.bus.name_equivalent.loc[boundary_buses] = ["Boundary bus " + str(uuid.uuid1()) for _ in
301 +
                                                   boundary_buses]
304 302
305 303
306 304
def drop_assist_elms_by_creating_ext_net(net, elms=None):
@@ -318,6 +316,9 @@
Loading
318 316
                                     elm].index.intersection(target_elm_idx)
319 317
            net["res_"+elm].drop(res_target_elm_idx, inplace=True)
320 318
319 +
    if "name_equivalent" in net.bus.columns.tolist():
320 +
        net.bus.drop(columns=["name_equivalent"], inplace=True)
321 +
321 322
322 323
def build_ppc_and_Ybus(net):
323 324
    """ This function build ppc and gets the Ybus of given network without
@@ -524,7 +525,17 @@
Loading
524 525
    checks the given network. If the network does not meet conditions,
525 526
    the program will report an error.
526 527
    """
527 -
    pass
528 +
    # --- check invative elements
529 +
    if net.res_bus.vm_pu.isnull().any():
530 +
        logger.info("There are some inactive buses. It is suggested to remove "
531 +
                    "them using 'pandapower.drop_inactive_elements()' "
532 +
                    "before starting the grid equivalent calculation.")
533 +
    # --- check dcline
534 +
    if "dcline" in net and len(net.dcline.query("in_service")) > 0:
535 +
        _add_dcline_gens(net)
536 +
        dcline_index = net.dcline.index.values
537 +
        net.dcline.loc[dcline_index, 'in_service'] = False
538 +
        logger.info(f"replaced dcline {dcline_index} by gen elements")
528 539
    # --- condition 1: shift_degree of transformers must be 0.
529 540
    # if not np.allclose(net.trafo.shift_degree.values, 0) & \
530 541
    #         np.allclose(net.trafo3w.shift_mv_degree.values, 0) & \

@@ -32,7 +32,6 @@
Loading
32 32
import numpy as np
33 33
import pandas as pd
34 34
import scipy as sp
35 -
import six
36 35
from packaging import version
37 36
38 37
from pandapower.pypower.idx_brch import F_BUS, T_BUS, BR_STATUS
@@ -85,7 +84,7 @@
Loading
85 84
        return self.copy(), self._allow_invalid_attributes
86 85
87 86
    def __dir__(self):
88 -
        return list(six.iterkeys(self))
87 +
        return list(self.keys())
89 88
90 89
    def __setstate__(self, state):
91 90
        mapping, allow_invalid_attributes = state
@@ -224,7 +223,7 @@
Loading
224 223
            'register').
225 224
        """
226 225
        return (
227 -
                isinstance(key, six.string_types) and
226 +
                isinstance(key, str) and
228 227
                not hasattr(cls, key)
229 228
        )
230 229
@@ -269,7 +268,7 @@
Loading
269 268
270 269
271 270
def _preserve_dtypes(df, dtypes):
272 -
    for item, dtype in list(dtypes.iteritems()):
271 +
    for item, dtype in list(dtypes.items()):
273 272
        if df.dtypes.at[item] != dtype:
274 273
            if (dtype == bool or dtype == np.bool_) and np.any(df[item].isnull()):
275 274
                raise UserWarning(f"Encountered NaN value(s) in a boolean column {item}! "

@@ -155,39 +155,39 @@
Loading
155 155
156 156
def _create_seperate_cost_tables(net, elements_to_deserialize):
157 157
    if _check_elements_to_deserialize('gen', elements_to_deserialize) and "cost_per_kw" in net.gen:
158 -
        for index, cost in net.gen.cost_per_kw.iteritems():
158 +
        for index, cost in net.gen.cost_per_kw.items():
159 159
            if not np.isnan(cost):
160 160
                create_poly_cost(net, index, "gen", cp1_eur_per_mw=cost * 1e3)
161 161
162 162
    if _check_elements_to_deserialize('sgen', elements_to_deserialize) and \
163 163
            "cost_per_kw" in net.sgen:
164 -
        for index, cost in net.sgen.cost_per_kw.iteritems():
164 +
        for index, cost in net.sgen.cost_per_kw.items():
165 165
            if not np.isnan(cost):
166 166
                create_poly_cost(net, index, "sgen", cp1_eur_per_kw=cost)
167 167
168 168
    if _check_elements_to_deserialize('ext_grid', elements_to_deserialize) and \
169 169
            "cost_per_kw" in net.ext_grid:
170 -
        for index, cost in net.ext_grid.cost_per_kw.iteritems():
170 +
        for index, cost in net.ext_grid.cost_per_kw.items():
171 171
            if not np.isnan(cost):
172 172
                create_poly_cost(net, index, "ext_grid", cp1_eur_per_kw=cost)
173 173
174 174
    if _check_elements_to_deserialize('gen', elements_to_deserialize) and \
175 175
            "cost_per_kvar" in net.gen:
176 -
        for index, cost in net.gen.cost_per_kvar.iteritems():
176 +
        for index, cost in net.gen.cost_per_kvar.items():
177 177
            if not np.isnan(cost):
178 178
                create_poly_cost(net, index, "ext_grid", cp1_eur_per_mw=0,
179 179
                                 cq1_eur_per_mvar=cost * 1e3)
180 180
181 181
    if _check_elements_to_deserialize('sgen', elements_to_deserialize) and \
182 182
            "cost_per_kvar" in net.sgen:
183 -
        for index, cost in net.sgen.cost_per_kvar.iteritems():
183 +
        for index, cost in net.sgen.cost_per_kvar.items():
184 184
            if not np.isnan(cost):
185 185
                create_poly_cost(net, index, "sgen", cp1_eur_per_mw=0,
186 186
                                 cq1_eur_per_mvar=cost * 1e3)
187 187
188 188
    if _check_elements_to_deserialize('ext_grid', elements_to_deserialize) and \
189 189
            "cost_per_kvar" in net.ext_grid:
190 -
        for index, cost in net.ext_grid.cost_per_kvar.iteritems():
190 +
        for index, cost in net.ext_grid.cost_per_kvar.items():
191 191
            if not np.isnan(cost):
192 192
                create_poly_cost(net, index, "ext_grid", cp1_eur_per_mw=0,
193 193
                                 cq1_eur_per_mvar=cost * 1e3)

@@ -2160,7 +2160,7 @@
Loading
2160 2160
        **max_i_ka** (value(s), False) - Data/Information how to set max_i_ka. If 'imp.sn_mva' is
2161 2161
        given, the sn_mva values of the impedances are considered.
2162 2162
    """
2163 -
    index = list(ensure_iterability(index)) if index is not None else list(net.line.index)
2163 +
    index = list(ensure_iterability(index)) if index is not None else list(net.impedance.index)
2164 2164
    max_i_ka = ensure_iterability(max_i_ka, len(index))
2165 2165
    new_index = []
2166 2166
    for (idx, imp), max_i in zip(net.impedance.loc[index].iterrows(), max_i_ka):

@@ -1,4 +1,5 @@
Loading
1 1
import pandapower as pp
2 +
import time
2 3
from pandapower.grid_equivalents.auxiliary import drop_internal_branch_elements, \
3 4
    _runpp_except_voltage_angles
4 5
import pandas as pd
@@ -12,9 +13,10 @@
Loading
12 13
logger = logging.getLogger(__name__)
13 14
14 15
15 -
def _calculate_ward_and_impedance_parameters(Ybus_eq, bus_lookups, power_eq=0):
16 +
def _calculate_ward_and_impedance_parameters(Ybus_eq, bus_lookups, show_computing_time, power_eq=0):
16 17
    """calculates the wards and equivalente impedance to represente the
17 18
    external network"""
19 +
    t_start = time.perf_counter()
18 20
    # --- calculate ward paramter
19 21
    b_buses_ppc = bus_lookups["bus_lookup_ppc"]["b_area_buses"]
20 22
    b_buses_pd = bus_lookups["bus_lookup_pd"]["b_area_buses"]
@@ -46,20 +48,29 @@
Loading
46 48
                    k += 1
47 49
                else:
48 50
                    impedance_parameter = impedance_parameter[:-1]
51 +
    t_end = time.perf_counter()
52 +
    if show_computing_time:
53 +
        logger.info("\"calculate_ward_and_impedance_parameters\" finished in %s seconds:" % round((
54 +
                    t_end-t_start), 2))
49 55
    return ward_parameter, impedance_parameter
50 56
51 57
52 -
def _calculate_xward_and_impedance_parameters(net_external, Ybus_eq, bus_lookups, power_eq=0):
58 +
def _calculate_xward_and_impedance_parameters(net_external, Ybus_eq, bus_lookups, 
59 +
                                              show_computing_time, power_eq=0):
53 60
    """calculates the xwards and the equivalent impedance"""
61 +
    t_start = time.perf_counter()
54 62
    xward_parameter, impedance_parameter = \
55 -
        _calculate_ward_and_impedance_parameters(Ybus_eq, bus_lookups)
63 +
        _calculate_ward_and_impedance_parameters(Ybus_eq, bus_lookups, False)
56 64
    xward_parameter["r_ohm"] = 0
57 65
    xward_parameter["x_ohm"] = -1/xward_parameter.shunt.values.imag / \
58 66
        net_external.sn_mva*net_external.bus.vn_kv[xward_parameter.bus_pd].values**2 #/2
59 67
        # np.square(net_external.bus.vn_kv[xward_parameter.bus_pd.values].values) / \
60 68
        # net_external.sn_mva/2
61 69
    xward_parameter["vm_pu"] = net_external.res_bus.vm_pu[xward_parameter.bus_pd.values].values
62 -
70 +
    t_end = time.perf_counter()
71 +
    if show_computing_time:
72 +
        logger.info("\"calculate_xward_and_impedance_parameters\" finished in %s seconds:" % round((
73 +
                    t_end-t_start), 2))
63 74
    return xward_parameter, impedance_parameter
64 75
65 76
@@ -99,7 +110,9 @@
Loading
99 110
100 111
def _replace_external_area_by_wards(net_external, bus_lookups, ward_parameter_no_power,
101 112
                                    impedance_parameter, ext_buses_with_xward,
102 -
                                    calc_volt_angles=True, runpp_fct=_runpp_except_voltage_angles):
113 +
                                    show_computing_time, calc_volt_angles=True,
114 +
                                    runpp_fct=_runpp_except_voltage_angles):
115 +
    t_start = time.perf_counter()
103 116
    """replaces the external networks by wards and equivalent impedance"""
104 117
    # --- drop all external elements
105 118
    e_buses_pd = bus_lookups["bus_lookup_pd"]["e_area_buses"]
@@ -172,12 +185,18 @@
Loading
172 185
                      net_external.bus.index.tolist()[-(len(ext_buses_with_xward)):])
173 186
    # net_external.ward.qs_mvar[i] = eq_power.q_mvar[
174 187
    #     net_external.ext_grid.bus == ward_parameter_no_power.bus_pd[i]]
188 +
    t_end = time.perf_counter()
189 +
    if show_computing_time:
190 +
        logger.info("\"replace_external_area_by_wards\" finished in %s seconds:" % round((
191 +
                    t_end-t_start), 2))
175 192
176 193
177 194
def _replace_external_area_by_xwards(net_external, bus_lookups, xward_parameter_no_power,
178 195
                                     impedance_parameter, ext_buses_with_xward,
179 -
                                     calc_volt_angles=True, runpp_fct=_runpp_except_voltage_angles):
196 +
                                     show_computing_time, calc_volt_angles=True, 
197 +
                                     runpp_fct=_runpp_except_voltage_angles):
180 198
    """replaces the external networks by xwards and equivalent impedance"""
199 +
    t_start = time.perf_counter()
181 200
    # --- drop all external elements
182 201
    e_buses_pd = bus_lookups["bus_lookup_pd"]["e_area_buses"]
183 202
    pp.drop_buses(net_external, e_buses_pd)
@@ -248,6 +267,11 @@
Loading
248 267
    if len(ext_buses_with_xward):
249 268
        pp.drop_buses(net_external,
250 269
                      net_external.bus.index.tolist()[-(len(ext_buses_with_xward)):])
270 +
    t_end = time.perf_counter()
271 +
    if show_computing_time:
272 +
        logger.info("\"replace_external_area_by_xwards\" finished in %s seconds:" % round((
273 +
                    t_end-t_start), 2))
274 +
251 275
252 276
def get_ppc_buses(net, buses, nogo_buses):
253 277
    """

@@ -14,7 +14,6 @@
Loading
14 14
from pandapower.pypower.idx_gen import GEN_BUS, QG, QMAX, QMIN, GEN_STATUS, VG
15 15
from pandapower.pypower.makeSbus import makeSbus
16 16
from scipy.sparse import csr_matrix, csgraph
17 -
from six import iteritems
18 17
19 18
from pandapower.auxiliary import ppException
20 19
from pandapower.pypower.bustypes import bustypes
@@ -427,7 +426,7 @@
Loading
427 426
        trafos_shift = dict(list(zip(list(zip(branch[brch_shift_mask, F_BUS].real.astype(int),
428 427
                                              branch[brch_shift_mask, T_BUS].real.astype(int))),
429 428
                                     branch[brch_shift_mask, SHIFT].real)))
430 -
        for trafo_ind, shift_degree in iteritems(trafos_shift):
429 +
        for trafo_ind, shift_degree in trafos_shift.items():
431 430
            neti = 0
432 431
            # if multiple reference nodes, find in which network trafo is located
433 432
            if len(ref) > 0:

@@ -155,7 +155,7 @@
Loading
155 155
    def append_boundary_buses_externals_per_zone(boundary_buses, boundaries, zone, other_zone_cols):
156 156
        """ iterate throw all boundaries which matches this_zone and add the other_zone_bus to
157 157
        boundary_buses """
158 -
        for idx, ozc in other_zone_cols.iteritems():
158 +
        for idx, ozc in other_zone_cols.items():
159 159
            other_zone = boundaries[zone_cols].values[idx, ozc]
160 160
            if isinstance(other_zone, np.generic):
161 161
                other_zone = other_zone.item()

@@ -101,6 +101,7 @@
Loading
101 101
def upload_sql_table(conn, cursor, table_name, table, index_name=None, timestamp=False, **id_columns):
102 102
    # index_name allows using a custom column for the table index and disregard the DataFrame index,
103 103
    # otherwise a <table_name>_id is used as index_name and DataFrame index is also uploaded to the database
104 +
    table = table.where(pd.notnull(table), None)
104 105
    if index_name is None:
105 106
        index_name = f"{table_name.split('.')[-1]}_id"
106 107
        index_type = match_sql_type(str(table.index.dtype))
@@ -331,7 +332,7 @@
Loading
331 332
        table_name = element if schema is None else f"{schema}.{element}"
332 333
        # None causes postgresql error, np.nan is better
333 334
        create_sql_table_if_not_exists(conn, cursor, table_name, grid_id_column, catalogue_table_name)
334 -
        upload_sql_table(conn=conn, cursor=cursor, table_name=table_name, table=element_table.replace(np.nan, None),
335 +
        upload_sql_table(conn=conn, cursor=cursor, table_name=table_name, table=element_table,
335 336
                         index_name=index_name, **id_columns)
336 337
        logger.debug(f"uploaded table {element}")
337 338
    return written_grid_id

@@ -272,9 +272,11 @@
Loading
272 272
                if net_zpbn[elm][c].dtype == np.number or net_zpbn[elm][c].dtype == np.int64:
273 273
                    other_cols_number |= {c}
274 274
                    other_cols -= {c}
275 -
                if net_zpbn[elm][c].dtype == bool:
275 +
                elif net_zpbn[elm][c].dtype == bool or set(elm_org[c].values) & {False, True}: # type-object can also be True of False
276 276
                    other_cols_bool |= {c}
277 277
                    other_cols -= {c}
278 +
                else:
279 +
                    pass
278 280
        if "integrated" in key:
279 281
            net_zpbn[elm].loc[elm_idx, list(other_cols_number)] = \
280 282
                elm_org[list(other_cols_number)][elm_org.bus.isin(all_external_buses)].sum(axis=0)
@@ -297,11 +299,11 @@
Loading
297 299
                    net_zpbn[elm].loc[elm_idx, list(other_cols_number)] = \
298 300
                        elm_org[list(other_cols_number)][elm_org.bus == bus].sum(axis=0)
299 301
                    net_zpbn[elm].loc[elm_idx, list(other_cols_bool)] = \
300 -
                        elm_org[list(other_cols_bool)][elm_org.bus == bus].values.sum() > 0
302 +
                        elm_org[list(other_cols_bool)][elm_org.bus == bus].values.sum(axis=0) > 0
301 303
                else:
302 304
                    net_zpbn[elm].loc[elm_idx, list(other_cols_bool | other_cols_number)] = \
303 305
                        elm_org[list(other_cols_bool | other_cols_number)][
304 -
                            elm_org.bus == bus].values[0]
306 +
                            elm_org.bus == bus].values[0] 
305 307
                    net_zpbn[elm].loc[elm_idx, list(other_cols)] = elm_org[list(other_cols)][
306 308
                        elm_org.bus == bus].values[0]
307 309
        elm_old = net_zpbn.bus.name[i].split("_")[0]

@@ -2,7 +2,6 @@
Loading
2 2
import pandapower.topology as top
3 3
import time
4 4
from copy import deepcopy
5 -
from pandapower.auxiliary import _add_dcline_gens
6 5
from pandapower.grid_equivalents.auxiliary import drop_assist_elms_by_creating_ext_net, \
7 6
    drop_internal_branch_elements, add_ext_grids_to_boundaries, \
8 7
    _ensure_unique_boundary_bus_names, match_controller_and_new_elements, \
@@ -47,88 +46,89 @@
Loading
47 46
48 47
        - despite 'adapt_va_degree', va_degree at the slack bus showed deviations within large grids
49 48
50 -
        - with large, real grids small deviations in the power flow results occured, in small grids
51 -
        the results fit perfectly
49 +
        - with large, real grids small deviations in the power flow results occured, in small grids \
50 +
            the results fit perfectly
52 51
53 52
    INPUT:
54 -
        **net** - The pandapower network including power flow results. Will
55 -
                not be changed during this function.
53 +
        **net** - The pandapower network including power flow results will not be changed during this function.
56 54
57 55
        **eq_type** (string) - type of the eqvalent network
58 56
59 57
            The following methods are available:
60 58
61 -
                - "rei": The idea of rei equivalent is to aggregate the power
62 -
                        and current injection of the external buses to one or
63 -
                        more fictitious radial, equivalent and independent
64 -
                        (rei) nodes. There are three types of the rei-node in
65 -
                        this routine, i.e. the reserved load, the reserved sgen
66 -
                        and the reserved gen (also ext_grid). According to the
67 -
                        demand, these elements (load, sgen and gen) are
68 -
                        considered in the function "_create_net_zpbn"
59 +
                - "rei": The idea of rei equivalent is to aggregate the power \
60 +
                        and current injection of the external buses to one or \
61 +
                        more fictitious radial, equivalent and independent \
62 +
                        (rei) nodes. There are three types of the rei-node in \
63 +
                        this routine, i.e. the reserved load, the reserved sgen \
64 +
                        and the reserved gen (also ext_grid). According to the \
65 +
                        demand, these elements (load, sgen and gen) are \
66 +
                        considered in the function "_create_net_zpbn" \
69 67
                        integrated or separately.
70 68
71 -
                - "ward": The ward-type equivalent represents the external
72 -
                        network with some equivalent impedance, shunts and
73 -
                        power injections at boundary buses. The equivalent
74 -
                        power injections represent the power of the elements
75 -
                        (load, sgen and gen), which are removed by the
69 +
                - "ward": The ward-type equivalent represents the external \
70 +
                        network with some equivalent impedance, shunts and \
71 +
                        power injections at boundary buses. The equivalent \
72 +
                        power injections represent the power of the elements \
73 +
                        (load, sgen and gen), which are removed by the \
76 74
                        equivalent calculation.
77 75
78 -
                - "xward": The xward equivalent is an extended variation of
79 -
                        the ward equivalent. Addition to the
80 -
                        ward-representation, a fictitious PV node (generator)
81 -
                        is added with zero active power injection at every
82 -
                        boundary bus. The voltage of the PV node is set
76 +
                - "xward": The xward equivalent is an extended variation of \
77 +
                        the ward equivalent. Addition to the \
78 +
                        ward-representation, a fictitious PV node (generator) \
79 +
                        is added with zero active power injection at every \
80 +
                        boundary bus. The voltage of the PV node is set \
83 81
                        according to the boundary bus voltage.
84 82
85 -
                ward/xward has two mothods to develop an equivalent circuits,
86 -
                i.e. the injection method and the admittance method. In the
87 -
                admittance method, all the bus power injections in the external
88 -
                networks are converted into shunt admittance before network
89 -
                equivalent. That is the only difference between these two
90 -
                methods. With the help of the function "adapt_net", these
83 +
                ward/xward has two mothods to develop an equivalent circuits, \
84 +
                i.e. the injection method and the admittance method. In the \
85 +
                admittance method, all the bus power injections in the external \
86 +
                networks are converted into shunt admittance before network \
87 +
                equivalent. That is the only difference between these two \
88 +
                methods. With the help of the function "adapt_net", these \
91 89
                methods are configurable.
92 90
93 -
        **boundary_buses** (iterable) - list of boundary bus indices, by which
94 -
            the original network are divided into two networks, i.e. an
91 +
        **boundary_buses** (iterable) - list of boundary bus indices, by which \
92 +
            the original network are divided into two networks, i.e. an \
95 93
            internal network and an external network.
96 94
97 -
        **internal_buses** (iterable) - list of bus indices, which are within
98 -
            the internal network. The program will add buses which are
99 -
            connected to this list of internal buses without passing boundary
100 -
            buses. If 'internal_buses' is an empty list or None, the whole
95 +
        **internal_buses** (iterable) - list of bus indices, which are within \
96 +
            the internal network. The program will add buses which are \
97 +
            connected to this list of internal buses without passing boundary \
98 +
            buses. If 'internal_buses' is an empty list or None, the whole \
101 99
            grid is treated as external network.
102 100
103 -
    OPTIONAL:
104 -
         **return_internal** (bool, True) - Reservation of the internal network
101 +
    OPTIONAL:  
102 +
        **return_internal** (bool, True) - Reservation of the internal network
105 103
106 -
             If True, the internal network is reserved in the final equivalent
104 +
             If True, the internal network is reserved in the final equivalent \
107 105
             network; otherwise only the external network is the output.
108 106
107 +
        **show_computing_time** (bool, False) - show computing time of each step
108 +
109 109
        **ward_type** (str, "ward_injection") - Type of ward and xward
110 110
111 -
            ward and xward proposed two mothods called the Ward Injection
112 -
            method and the Ward Admittance method to develop equivalent
113 -
            circuits. The only difference between these methods is that in
114 -
            the Ward Admittance method, all bus power in the external networks
111 +
            ward and xward proposed two mothods called the Ward Injection \
112 +
            method and the Ward Admittance method to develop equivalent \
113 +
            circuits. The only difference between these methods is that in \
114 +
            the Ward Admittance method, all bus power in the external networks \
115 115
            are converted into shunt admittances before network equivalent.
116 116
117 -
        **adapt_va_degree** (bool, None) - if True, in add_ext_grids_to_boundaries(), the va_degree
118 -
            of the additional ext_grids (if needed) at the boundary buses will be increased or
117 +
        **adapt_va_degree** (bool, None) - if True, in add_ext_grids_to_boundaries(), the va_degree \
118 +
            of the additional ext_grids (if needed) at the boundary buses will be increased or \
119 119
            decreased to values that minimize the difference to the given res_bus.va_degree values.
120 120
121 -
        **allow_net_change_for_convergence** (bool, False) - if the net doesn't converge at the
122 -
            first internal power flow, which is in add_ext_grids_to_boundaries(), and this parameter is
121 +
        **allow_net_change_for_convergence** (bool, False) - if the net doesn't converge at the \
122 +
            first internal power flow, which is in add_ext_grids_to_boundaries(), and this parameter is \
123 123
            True, the code tests if changes to unusual impedance values solve the divergence issue.
124 124
125 -
        **calculate_voltage_angles** (bool, True) - parameter passed to internal runpp() runs
125 +
        **calculate_voltage_angles** (bool, True) - parameter passed to internal runpp() runs.
126 126
        
127 -
        **retain_original_internal_indices** (bool, False) - if True, the element indices in 
127 +
        **retain_original_internal_indices** (bool, False) - if True, the element indices in \
128 128
            the internal net are retained; otherwise the indices will be reordered from 0. 
129 129
130 -
        ****kwargs** - key word arguments, such as sgen_separate, load_separate, gen_separate,
131 -
        group_name,
130 +
        ****kwargs** - key word arguments, such as sgen_separate, load_separate, gen_separate, \
131 +
        group_name.
132 132
133 133
    OUTPUT:
134 134
         **net_eq** - The equivalent network in pandapower format
@@ -137,18 +137,10 @@
Loading
137 137
138 138
    time_start = time.perf_counter()
139 139
    eq_type = eq_type.lower()
140 -
    check_network(net)
140 +
    net = deepcopy(net)
141 141
    if not len(boundary_buses):
142 142
        raise ValueError("No boundary buses are given.")
143 -
144 -
    net = deepcopy(net)
145 -
146 -
    if "dcline" in net and len(net.dcline.query("in_service")) > 0:
147 -
        _add_dcline_gens(net)
148 -
        dcline_index = net.dcline.index.values
149 -
        net.dcline.loc[dcline_index, 'in_service'] = False
150 -
        logger.info(f"replaced dcline {dcline_index} by gen elements")
151 -
143 +
    check_network(net)
152 144
    logger.info(eq_type + " equivalent calculation started")
153 145
154 146
    # --- determine interal buses, external buses, buses connected to boundary buses via
@@ -162,7 +154,7 @@
Loading
162 154
    return_internal &= bool(len(all_internal_buses))
163 155
164 156
    # --- ensure unique boundary bus names
165 -
    _ensure_unique_boundary_bus_names(net, boundary_buses)
157 +
    _ensure_unique_boundary_bus_names(net, boundary_buses_inclusive_bswitch)
166 158
167 159
    # --- check and create reference buses
168 160
    add_ext_grids_to_boundaries(net, boundary_buses, adapt_va_degree,
@@ -229,18 +221,21 @@
Loading
229 221
230 222
        # --- cacluate equivalent Ybus accourding to gaussian elimination
231 223
        Ybus_eq = _calculate_equivalent_Ybus(net_external,  bus_lookups,
232 -
                                             eq_type, check_validity=False)
224 +
                                             eq_type, show_computing_time,
225 +
                                             check_validity=False)
233 226
234 227
        if eq_type == "ward":
235 228
            # --- calculate equivalent impedance and wards
236 229
            ward_parameter_no_power, impedance_parameter = \
237 -
                _calculate_ward_and_impedance_parameters(Ybus_eq, bus_lookups)
230 +
                _calculate_ward_and_impedance_parameters(Ybus_eq, bus_lookups,
231 +
                                                         show_computing_time)
238 232
239 233
            # --- replace external network by equivalent elements
240 234
            _replace_external_area_by_wards(net_external, bus_lookups,
241 235
                                            ward_parameter_no_power,
242 236
                                            impedance_parameter,
243 237
                                            ext_buses_with_xward,
238 +
                                            show_computing_time,
244 239
                                            calc_volt_angles=calculate_voltage_angles,
245 240
                                            runpp_fct=runpp_fct)
246 241
        else:  # eq_type == "xward"
@@ -248,13 +243,15 @@
Loading
248 243
            xward_parameter_no_power, impedance_parameter = \
249 244
                _calculate_xward_and_impedance_parameters(net_external,
250 245
                                                          Ybus_eq,
251 -
                                                          bus_lookups)
246 +
                                                          bus_lookups,
247 +
                                                          show_computing_time)
252 248
253 249
            # --- replace external network by equivalent elements
254 250
            _replace_external_area_by_xwards(net_external, bus_lookups,
255 251
                                             xward_parameter_no_power,
256 252
                                             impedance_parameter,
257 253
                                             ext_buses_with_xward,
254 +
                                             show_computing_time,
258 255
                                             calc_volt_angles=calculate_voltage_angles,
259 256
                                             runpp_fct=runpp_fct)
260 257
        net_eq = net_external
@@ -381,9 +378,10 @@
Loading
381 378
        pass
382 379
383 380
    # --- fuse or combine the boundary buses in external and internal nets
381 +
    busname_col = "name_equivalent" if "name_equivalent" in merged_net.bus.columns.tolist() else "name"
384 382
    for bus in boundary_buses_inclusive_bswitch:
385 -
        name = merged_net.bus.name.loc[bus]
386 -
        target_buses = merged_net.bus.index[merged_net.bus.name == name]
383 +
        name = merged_net.bus[busname_col].loc[bus]
384 +
        target_buses = merged_net.bus.index[merged_net.bus[busname_col] == name]
387 385
        if len(target_buses) != 2:
388 386
            raise ValueError(
389 387
                "The code expects all boundary buses to occur double. One because "
@@ -443,10 +441,6 @@
Loading
443 441
        internal_buses = set(internal_buses)
444 442
445 443
    boundary_buses = set(boundary_buses)
446 -
    bb_buses = net.switch.element[(net.switch.et=="b") &
447 -
                                (net.switch.element.isin(boundary_buses)) &
448 -
                                (net.switch.bus.isin(boundary_buses))].tolist()
449 -
    boundary_buses -= set(bb_buses)
450 444
451 445
    unsupplied_buses = set(net.res_bus.index[net.res_bus.vm_pu.isnull()])
452 446
    unsupplied_boundary_buses = boundary_buses & unsupplied_buses
@@ -475,8 +469,7 @@
Loading
475 469
                    "bus-bus-switches. They could be the nodes on the same bus bar " +
476 470
                    "of the boundary buses. It is suggested to consider all these " +
477 471
                    "buses (the connected buses and the given boundary buses) " +
478 -
                    "as the boundary. You can use the function " +
479 -
                    "'get_connected_switch_buses' to find all these buses.")
472 +
                    "as the boundary. They are: %s:" % boundary_buses_inclusive_bswitch)
480 473
481 474
    # --- determine all internal buses
482 475
    all_internal_buses = set()
Files Coverage
pandapower 76.46%
setup.py 0.00%
Project Totals (189 files) 76.41%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading