pysal.explore.spaghetti.Network.count_per_edge

Network.count_per_edge(obs_on_network, graph=True)[source]

Compute the counts per edge.

Parameters:
obs_on_network : dict

Dict of observations on the network. {(edge):{pt_id:(coords)}} or {edge:[(coord),(coord),(coord)]}

Returns:
counts : dict

{(edge):count}

Examples

Note that this passes the obs_to_edge attribute of a point pattern snapped to the network.

>>> import pysal.explore.spaghetti as spgh
>>> ntw = spgh.Network(examples.get_path('streets.shp'))
>>> ntw.snapobservations(examples.get_path('crimes.shp'),
...                                           'crimes',
...                                           attribute=True)
>>> counts = ntw.count_per_edge(ntw.pointpatterns['crimes']
...                             .obs_to_edge, graph=False)
>>> counts[(140, 142)]
10
>>> s = sum([v for v in list(counts.values())])
>>> s
287