예제 #1
0
def create_source_collection(net, sources=None, size=1., infofunc=None, picker=False,
                             orientation=(np.pi*7/6), **kwargs):
    """
    Creates a matplotlib patch collection of pandapipes sources.

    :param net: The pandapipes network
    :type net: pandapipesNet
    :param sources: The sources for which the collections are created. If None, all sources
                    connected to junctions that have junction_geodata entries are considered.
    :type sources: list, default None
    :param size: Patch size
    :type size: float, default 1.
    :param infofunc: infofunction for the patch element
    :type infofunc: function, default None
    :param picker: Picker argument passed to the patch collection
    :type picker: bool, default False
    :param orientation: Orientation of source collection. pi is directed downwards, increasing\
        values lead to clockwise direction changes.
    :type orientation: float, default np.pi*(7/6)
    :param kwargs: Keyword arguments are passed to the patch function
    :return: source_pc - patch collection, source_lc - line collection
    """
    sources = get_index_array(sources, net.source.index)
    if len(sources) == 0:
        return None
    infos = [infofunc(i) for i in range(len(sources))] if infofunc is not None else []
    node_coords = net.junction_geodata.loc[net.source.loc[sources, "junction"].values,
                                           ["x", "y"]].values
    source_pc, source_lc = _create_node_element_collection(
        node_coords, source_patches, size=size, infos=infos, orientation=orientation,
        picker=picker, repeat_infos=(1, 3), **kwargs)
    return source_pc, source_lc
예제 #2
0
def create_valve_collection(net, valves=None, size=5., junction_geodata=None, color='k',
                            infofunc=None, picker=False, fill_closed=True,
                            respect_valves=False, **kwargs):
    """
    Creates a matplotlib patch collection of pandapipes junction-junction valves. Valves are
    plotted in the center between two junctions with a "helper" line (dashed and thin) being drawn
    between the junctions as well.

    :param net: The pandapipes network
    :type net: pandapipesNet
    :param valves: The valves for which the collections are created. If None, all valves which have\
        entries in the respective junction geodata will be plotted.
    :type valves: list, default None
    :param size: Patch size
    :type size: float, default 5.
    :param junction_geodata: Coordinates to use for plotting. If None, net["junction_geodata"] is used.
    :type junction_geodata: pandas.DataFrame, default None
    :param colors: Color or list of colors for every valve
    :type colors: iterable, float, default None
    :param infofunc: infofunction for the patch element
    :type infofunc: function, default None
    :param picker: Picker argument passed to the patch collection
    :type picker: bool, default False
    :param fill_closed: If True, valves with parameter opened == False will be filled and those\
        with opened == True will have a white facecolor. Vice versa if False.
    :type fill_closed: bool, default True
    :param kwargs: Keyword arguments are passed to the patch function
    :return: lc - line collection, pc - patch collection

    """
    valves = get_index_array(
        valves, net.valve[net.valve.opened.values].index if respect_valves else net.valve.index)

    valve_table = net.valve.loc[valves]

    coords, valves_with_geo = coords_from_node_geodata(
        valves, valve_table.from_junction.values, valve_table.to_junction.values,
        junction_geodata if junction_geodata is not None else net["junction_geodata"], "valve",
        "Junction")

    if len(valves_with_geo) == 0:
        return None

    linewidths = kwargs.pop("linewidths", 2.)
    linewidths = kwargs.pop("linewidth", linewidths)
    linewidths = kwargs.pop("lw", linewidths)

    infos = list(np.repeat([infofunc(i) for i in range(len(valves_with_geo))], 2)) \
        if infofunc is not None else []
    filled = valve_table["opened"].values
    if fill_closed:
        filled = ~filled
    lc, pc = _create_complex_branch_collection(coords, valve_patches, size, infos,
                                               picker=picker, linewidths=linewidths, filled=filled,
                                               patch_facecolor=color, line_color=color,
                                               **kwargs)

    return lc, pc
예제 #3
0
def create_ext_grid_collection(net,
                               size=1.,
                               infofunc=None,
                               orientation=0,
                               picker=False,
                               ext_grids=None,
                               ext_grid_junctions=None,
                               **kwargs):
    """
    Creates a matplotlib patch collection of pandapipes ext_grid. Parameters
    ext_grids, ext_grid_junctions can be used to specify, which ext_grids the collection should be
    created for.

    :param net: The pandapipes network
    :type net: pandapipesNet
    :param size: Patch size
    :type size: float, default 1.
    :param infofunc: infofunction for the patch element
    :type infofunc: function, default None
    :param orientation: Orientation of ext_grid collection. 0 is directed upwards,
                        increasing values lead to clockwise direction changes.
    :type orientation: float, default 0
    :param picker: Picker argument passed to the patch collection
    :type picker: bool, default False
    :param ext_grids: The ext_grids for which the collections are created. If None, all ext_grids
                      which have the entry coords in ext_grid_geodata are considered.
    :type ext_grids: list, default None
    :param ext_grid_junctions: Junctions to be used as ext_grid locations
    :type ext_grid_junctions: np.ndarray, default None
    :param kwargs: Keyword arguments are passed to the patch function
    :return: ext_grid1 - patch collection, ext_grid2 - patch collection

    """
    ext_grids = get_index_array(ext_grids, net.ext_grid.index)
    if ext_grid_junctions is None:
        ext_grid_junctions = net.ext_grid.junction.loc[ext_grids].values
    else:
        if len(ext_grids) != len(ext_grid_junctions):
            raise ValueError(
                "Length mismatch between chosen ext_grids and ext_grid_junctions."
            )
    infos = [infofunc(ext_grid_idx)
             for ext_grid_idx in ext_grids] if infofunc is not None else []

    node_coords = net.junction_geodata.loc[ext_grid_junctions,
                                           ["x", "y"]].values
    ext_grid_pc, ext_grid_lc = _create_node_element_collection(
        node_coords,
        ext_grid_patches,
        size=size,
        infos=infos,
        orientation=orientation,
        picker=picker,
        hatch="XXX",
        **kwargs)
    return ext_grid_pc, ext_grid_lc
예제 #4
0
def create_sink_collection(net,
                           sinks=None,
                           size=1.,
                           infofunc=None,
                           picker=False,
                           orientation=np.pi,
                           **kwargs):
    """
    Creates a matplotlib patch collection of pandapipes sinks.

    :param net: The pandapipes network
    :type net: pandapipesNet
    :param sinks: The sinks for which the collections are created. If None, all sinks
                        connected to junctions that have junction_geodata entries are considered.
    :type sinks: list, default None
    :param size: patch size
    :type size: float, default 1
    :param infofunc: infofunction for the patch element
    :type infofunc: function, default None
    :param picker: picker argument passed to the patch collection
    :type picker: bool, default False
    :param orientation: orientation of sink collection. pi is directed downwards, increasing values\
        lead to clockwise direction changes.
    :type orientation: float, default np.pi
    :param kwargs: key word arguments are passed to the patch function
    :return: sink_pc - patch collection
             sink_lc - line collection
    """
    sinks = get_index_array(sinks, net.sink.index)
    if len(sinks) == 0:
        return None
    infos = [infofunc(i)
             for i in range(len(sinks))] if infofunc is not None else []
    node_coords = net.junction_geodata.loc[net.sink.loc[sinks,
                                                        "junction"].values,
                                           ['x', 'y']].values
    sink_pc, sink_lc = _create_node_element_collection(node_coords,
                                                       load_patches,
                                                       size=size,
                                                       infos=infos,
                                                       orientation=orientation,
                                                       picker=picker,
                                                       **kwargs)
    return sink_pc, sink_lc