In addition to the unmarked point pattern, non-binary attributes might be associated with each point, leading to the so-called marked point pattern. The charactertistics of a marked point pattern are:
Unmarked point pattern can be modified to be a marked point pattern using the method add_marks while the method explode could decompose a marked point pattern into a sequence of unmarked point patterns. Both methods belong to the class PointPattern.
In [1]:
from pysal.explore.pointpats import PoissonPointProcess, PoissonClusterPointProcess, Window, poly_from_bbox, PointPattern
import pysal.lib as ps
from pysal.lib.cg import shapely_ext
%matplotlib inline
import matplotlib.pyplot as plt
In [2]:
# open the virginia polygon shapefile
va = ps.io.open(ps.examples.get_path("virginia.shp"))
polys = [shp for shp in va]
In [3]:
# Create the exterior polygons for VA from the union of the county shapes
state = shapely_ext.cascaded_union(polys)
# create window from virginia state boundary
window = Window(state.parts)
In [4]:
window.bbox
Out[4]:
In [5]:
window.centroid
Out[5]:
In [6]:
samples = PoissonPointProcess(window, 200, 1, conditioning=False, asPP=False)
In [7]:
csr = PointPattern(samples.realizations[0])
In [8]:
cx, cy = window.centroid
In [9]:
cx
Out[9]:
In [10]:
cy
Out[10]:
In [11]:
west = csr.points.x < cx
south = csr.points.y < cy
east = 1 - west
north = 1 - south
In [12]:
quad = 1 * east * north + 2 * west * north + 3 * west * south + 4 * east * south
In [13]:
type(quad)
Out[13]:
In [14]:
quad
Out[14]:
In [15]:
csr.add_marks([quad], mark_names=['quad'])
In [16]:
csr.df
Out[16]:
In [17]:
csr_q = csr.explode('quad')
In [18]:
len(csr_q)
Out[18]:
In [19]:
csr
Out[19]:
In [20]:
csr.summary()
In [21]:
plt.xlim?
In [22]:
plt.xlim()
for ppn in csr_q:
ppn.plot()
In [23]:
x0, y0, x1, y1 = csr.mbb
ylim = (y0, y1)
xlim = (x0, x1)
In [24]:
for ppn in csr_q:
ppn.plot()
plt.xlim(xlim)
plt.ylim(ylim)
In [ ]:
In [ ]: