(
    graph,
    radius=5,
    three=None,
    four=None,
    dead=None,
    degree="degree",
    distance=None,
    verbose=True,
)
return result
Calculates the proportion of intersection types for subgraph around each node if
    radius is set, or for whole graph, if ``radius=None``.

    Subgraph is generated around each node within set radius. If ``distance=None``,
    radius will define topological distance, otherwise it uses values in ``distance``
    attribute.

    Parameters
    ----------
    graph : networkx.Graph
        Graph representing street network.
        Ideally generated from GeoDataFrame using :func:`momepy.gdf_to_nx`
    radius: int
        Include all neighbors of distance <= radius from n
    three : str, optional
        attribute name for 3-way intersections proportion
    four : str, optional
        attribute name for 4-way intersections proportion
    dead : str, optional
        attribute name for deadends proportion
    degree : str
        name of attribute of node degree (:py:func:`momepy.node_degree`)
    distance : str, optional
        Use specified edge data key as distance.
        For example, setting ``distance=’weight’`` will use the edge ``weight`` to
        measure the distance from the node n.
    verbose : bool (default True)
        if True, shows progress bars in loops and indication of steps

    Returns
    -------
    Graph
        networkx.Graph if radius is set
    dict
        dict with proportions for graph if ``radius=None``

    Examples
    --------
    >>> network_graph = mm.proportion(network_graph, three='threeway', four='fourway', dead='deadends')  # noqa
Calculates the proportion of intersection types for subgraph around each node if
    radius is set, or for whole graph, if ``radius=None``.
Calculates the proportion of intersection types for subgraph around each node if radius is set or for whole graph if radius = None .
def proportion(
    graph,
    radius=5,
    three=None,
    four=None,
    dead=None,
    degree="degree",
    distance=None,
    verbose=True,
):
    """
    Calculates the proportion of intersection types for subgraph around each node if
    radius is set, or for whole graph, if ``radius=None``.

    Subgraph is generated around each node within set radius. If ``distance=None``,
    radius will define topological distance, otherwise it uses values in ``distance``
    attribute.

    Parameters
    ----------
    graph : networkx.Graph
        Graph representing street network.
        Ideally generated from GeoDataFrame using :func:`momepy.gdf_to_nx`
    radius: int
        Include all neighbors of distance <= radius from n
    three : str, optional
        attribute name for 3-way intersections proportion
    four : str, optional
        attribute name for 4-way intersections proportion
    dead : str, optional
        attribute name for deadends proportion
    degree : str
        name of attribute of node degree (:py:func:`momepy.node_degree`)
    distance : str, optional
        Use specified edge data key as distance.
        For example, setting ``distance=’weight’`` will use the edge ``weight`` to
        measure the distance from the node n.
    verbose : bool (default True)
        if True, shows progress bars in loops and indication of steps

    Returns
    -------
    Graph
        networkx.Graph if radius is set
    dict
        dict with proportions for graph if ``radius=None``

    Examples
    --------
    >>> network_graph = mm.proportion(network_graph, three='threeway', four='fourway', dead='deadends')  # noqa
    """
    if not three and not four and not dead:
        raise ValueError(
            "Nothing to calculate. Define names for at least one proportion to be "
            "calculated."
        )
    netx = graph.copy()

    if radius:
        for n in tqdm(netx, total=len(netx), disable=not verbose):
            sub = nx.ego_graph(
                netx, n, radius=radius, distance=distance
            )  # define subgraph of steps=radius
            counts = _proportion(sub, degree=degree)
            if three:
                netx.nodes[n][three] = counts[3] / len(sub)
            if four:
                netx.nodes[n][four] = counts[4] / len(sub)
            if dead:
                netx.nodes[n][dead] = counts[1] / len(sub)
        return netx

    # add example to docs explaining keys
    counts = _proportion(netx, degree=degree)
    result = {}
    if three:
        result[three] = counts[3] / len(netx)
    if four:
        result[four] = counts[4] / len(netx)
    if dead:
        result[dead] = counts[1] / len(netx)

    return result
def proportion ( graph , radius = 5 , three = None , four = None , dead = None , degree = "degree" , distance = None , verbose = True , ) : if not three and not four and not dead : raise ValueError ( "Nothing to calculate. Define names for at least one proportion to be " "calculated." ) netx = graph . copy ( ) if radius : for n in tqdm ( netx , total = len ( netx ) , disable = not verbose ) : sub = nx . ego_graph ( netx , n , radius = radius , distance = distance ) # define subgraph of steps=radius counts = _proportion ( sub , degree = degree ) if three : netx . nodes [ n ] [ three ] = counts [ 3 ] / len ( sub ) if four : netx . nodes [ n ] [ four ] = counts [ 4 ] / len ( sub ) if dead : netx . nodes [ n ] [ dead ] = counts [ 1 ] / len ( sub ) return netx # add example to docs explaining keys counts = _proportion ( netx , degree = degree ) result = { } if three : result [ three ] = counts [ 3 ] / len ( netx ) if four : result [ four ] = counts [ 4 ] / len ( netx ) if dead : result [ dead ] = counts [ 1 ] / len ( netx ) return result