Network.contiguityweights(graph=True, weightings=None)[source]

Create a contiguity based W object.

graph : bool

{True, False} controls whether the W is generated using the spatial representation or the graph representation.

weightings : dict

Dict of lists of weightings for each edge.

W : pysal.lib.weights.weights.W

A PySAL W Object representing the binary adjacency of the network.


Instantiate an instance of a network.

>>> import pysal.explore.spaghetti as spgh
>>> from pysal.lib import examples
>>> import pysal.explore.esda
>>> import numpy as np
>>> ntw = spgh.Network(examples.get_path('streets.shp'))

Snap point observations to the network with attribute information.

>>> ntw.snapobservations(examples.get_path('crimes.shp'),
...                      'crimes', attribute=True)

Find counts per netowrk edge.

>>> counts = ntw.count_per_edge(ntw.pointpatterns['crimes']
...                             .obs_to_edge, graph=False)
>>> counts[(50, 165)]

Create a contiguity based W object.

>>> w = ntw.contiguityweights(graph=False)

Using the W object, access to ESDA functionality is provided. First, a vector of attributes is created for all edges with observations.

>>> w = ntw.contiguityweights(graph=False)
>>> edges = w.neighbors.keys()
>>> y = np.zeros(len(edges))
>>> for i, e in enumerate(edges):
...     if e in counts.keys():
...         y[i] = counts[e]
>>> y[3]

Next, a standard call ot Moran is made and the result placed into res.

>>> res = pysal.explore.esda.moran.Moran(y, w, permutations=99)
>>> type(res)
<class 'pysal.explore.esda.moran.Moran'>