示例#1
0
def get_bus_bus_switch_indices_from_csv(switch_table, node_table, error_type=ValueError):
    """ Returns a list of indices of bus-bus-switches from csv tables. """
    for nodeX in ["nodeA", "nodeB"]:
        missing_nodeX = switch_table[~switch_table[nodeX].isin(node_table.id)]
        if len(missing_nodeX):
            message = "At Switches " + str(["%s" % name for name in missing_nodeX.id]) + \
                " %s " % nodeX + str(["%s" % name for name in missing_nodeX[nodeX]]) + \
                " do not occur in Node table."
            raise ValueError(message)
    idx_nodeA = idx_in_2nd_array(switch_table.nodeA.values, node_table.id.values)
    idx_nodeB = idx_in_2nd_array(switch_table.nodeB.values, node_table.id.values)

    aux_nodeA = np.array(node_table.type[idx_nodeA] == "auxiliary")
    aux_nodeB = np.array(node_table.type[idx_nodeB] == "auxiliary")

    double_aux = switch_table.id[aux_nodeA & aux_nodeB]
    if len(double_aux):
        message = "Both side auxiliary nodes at Switches " + str([
            "%s" % name for name in double_aux])
        if error_type is None or error_type is False:
            logger.debug(message)
        else:
            raise error_type(message)

    return list(switch_table.index[~(aux_nodeA | aux_nodeB)])
def test_idx_in_2nd_array():
    arr1 = np.array([1, 6, 4.6, 3.4, 6, 1, "Hallo", "hallo", "Hallo"])
    arr2 = np.array([8, 4, 1, 2, 5, 5.6, 4.6, "Hallo", "hallo", 6, 3.4])

    expected_res = np.array([2, 9, 6, 10, 9, 2, 7, 8, 7])
    res = sb.idx_in_2nd_array(arr1, arr2)
    assert all(res == expected_res)

    arr2[-1] = 4.7
    expected_res[3] = 1
    res = sb.idx_in_2nd_array(arr1, arr2, match=False)
    assert all(res == expected_res)

    try:
        sb.idx_in_2nd_array(arr1, arr2, match=True)
        except_ = False
    except ValueError:
        except_ = True
    assert except_
示例#3
0
def get_absolute_profiles_from_relative_profiles(net,
                                                 element,
                                                 multiplying_column,
                                                 relative_profiles=None,
                                                 profile_column="profile",
                                                 profile_suffix=None,
                                                 time_as_index=False,
                                                 **kwargs):
    """
    Returns a DataFrame with profiles for the given element (e.g. loads or sgens). The profiles
    values are calculated by multiplying the relative profiles given by relative_profiles
    (or if not given, from net["profiles"]) with the values in net[element][multiplying_column].

    INPUT:
        **net** (pandapowerNet) - pandapower net

        **element** (str) - element type for which absolute profiles are calculated. Possible are
        "load", "gen", "sgen" or "storage".

        **multiplying_column** (str) - column name within net[element].columns which should be
        multiplied with the relative profiles. Usual multiply_columns are 'p_mw' or 'q_mvar'.
        Additional Feature: If multiplying_column is not a string, the relative profiles are not
        multiplied with net[element][multiplying_column] but with 'multiplying_column' itself.

    OPTIONAL:
        **relative_profiles** (DataFrame, None) - DataFrame of relative profiles as input. If None,
        net["profiles"] is considered.

        **profile_column** (str, "profile") - Name of the column which contains information about
        which element is assigned to which profile. In SimBench grids, this information is
        given in the column "profile". For that reason, 'profile' is the default.

        **profile_suffix** (str, None) - For the case that different profiles are given for p and q,
        these can be distinguished by a suffix. For loads this can be "_pload" and "_qload",
        which will be automatically assumed, if profile_suffix is None.

        **time_as_index** (bool, False) - If True, the returned DataFrame has
        relative_profiles["time"] as index. If False, relative_profiles.index is used.

        ****kwargs** - key word arguments for merge_dataframes()

    OUTPUT:
        **output_profiles** (DataFrame) - calculated absolute profiles
    """
    # --- use net.profiles if relative_profiles is None
    if relative_profiles is None:
        if element in ["load", "storage"]:
            relative_profiles = net.profiles[element]
        elif element in ["gen", "sgen"]:
            # Since RES and Powerplants can be converted to pandapower as both, gen or sgen, both
            # are considered together
            relative_profiles = merge_dataframes(
                [net.profiles["powerplants"], net.profiles["renewables"]],
                **kwargs)
        else:
            raise ValueError("element %s is unknown." % str(element))

    # --- set index
    index = relative_profiles[
        "time"] if time_as_index else relative_profiles.index
    if "time" in relative_profiles:
        del relative_profiles["time"]

    # --- do profile_suffix assumptions if profile_suffix is None
    if profile_suffix is None:
        if element == "load":
            if multiplying_column == "p_mw":
                profile_suffix = "_pload"
            elif multiplying_column == "q_mvar":
                profile_suffix = "_qload"
        profile_suffix = "" if profile_suffix is None else profile_suffix

    # --- get relative profiles with respect to each element index
    if profile_column in net[element].columns:
        applied_profiles = net[element][profile_column] + profile_suffix
    else:  # missing profile column
        logger.warning(
            "In %s table, profile column '%s' is missing. Scalings of 1 are assumed."
            % (element, profile_column))
        missing_col_handling = "missing_col_handling"
        applied_profiles = pd.Series([missing_col_handling] *
                                     net[element].shape[0],
                                     index=net[element].index)
        relative_profiles[missing_col_handling] = 1

    # nan profile handling
    if applied_profiles.isnull().any():
        logger.debug("There are nan profiles. Scalings of 1 are assumed.")
        nan_profile_handling = "nan_profile_scaling"
        assert nan_profile_handling not in relative_profiles.columns
        applied_profiles.loc[applied_profiles.isnull()] = nan_profile_handling
        relative_profiles[nan_profile_handling] = 1

    relative_output_profiles = relative_profiles.values[:,
                                                        idx_in_2nd_array(
                                                            applied_profiles.
                                                            values,
                                                            np.array(
                                                                relative_profiles
                                                                .columns))]

    # --- get factor to multiply with (consider additional feature of 'multiplying_column')
    if isinstance(multiplying_column, str):
        if multiplying_column in net[element].columns:
            factor = net[element][multiplying_column].values.reshape(1, -1)
        else:
            raise ValueError(
                "'multiplying_column' %s is not net[%s].columns." %
                (multiplying_column, element))
    else:
        factor = multiplying_column

    # --- multiply relative profiles with factor and return results
    output_profiles = pd.DataFrame(relative_output_profiles * factor,
                                   index=index,
                                   columns=net[element].index)
    return output_profiles