Network.
contiguityweights
(graph=True, weightings=None)[源代码]¶创建基于连续性的w对象。
参数: |
|
---|---|
返回: |
|
实例
实例化网络实例。
>>> 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'))
使用属性信息将点观测捕捉到网络。
>>> ntw.snapobservations(examples.get_path('crimes.shp'),
... 'crimes', attribute=True)
查找每个Netowrk边缘的计数。
>>> counts = ntw.count_per_edge(ntw.pointpatterns['crimes']
... .obs_to_edge, graph=False)
>>> counts[(50, 165)]
4
创建基于连续性的w对象。
>>> w = ntw.contiguityweights(graph=False)
使用w对象,可以访问esda功能。首先,通过观察为所有边创建属性向量。
>>> 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]
3.0
接下来,发出一个标准的moran调用,并将结果放入 res.
>>> res = pysal.explore.esda.moran.Moran(y, w, permutations=99)
>>> type(res)
<class 'pysal.explore.esda.moran.Moran'>