Marked Point Pattern

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:

  • Location pattern of the events are of interest
  • Stochastic attribute attached to the events is of interest

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.

from pointpats import PoissonPointProcess, PoissonClusterPointProcess, Window, poly_from_bbox, PointPattern
import libpysal as ps
from libpysal.cg import shapely_ext
%matplotlib inline
import matplotlib.pyplot as plt
# open the virginia polygon shapefile
va = ps.io.open(ps.examples.get_path("virginia.shp"))
polys = [shp for shp in va]
# 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)
window.bbox
[-83.67526245117188, 36.541481018066406, -75.24258422851562, 39.45690155029297]
window.centroid
(-78.85183583334933, 37.51851209850039)
samples = PoissonPointProcess(window, 200, 1, conditioning=False, asPP=False)
csr = PointPattern(samples.realizations[0])
cx, cy = window.centroid
cx
-78.85183583334933
cy
37.51851209850039
west = csr.points.x < cx
south = csr.points.y < cy
east = 1 - west
north = 1 - south

Create an attribute named quad which has a value for each event.

quad = 1 * east * north +  2 * west * north + 3 * west * south + 4 * east * south
type(quad)
pandas.core.series.Series
quad
0      2
1      3
2      3
3      4
4      1
5      3
6      1
7      4
8      2
9      3
10     4
11     4
12     3
13     1
14     1
15     1
16     4
17     1
18     1
19     3
20     4
21     3
22     1
23     3
24     1
25     1
26     4
27     1
28     3
29     3
      ..
170    2
171    2
172    3
173    3
174    1
175    4
176    3
177    3
178    4
179    1
180    1
181    3
182    3
183    1
184    2
185    3
186    1
187    2
188    4
189    1
190    4
191    1
192    3
193    3
194    4
195    3
196    1
197    1
198    4
199    4
Length: 200, dtype: int64

Attach the attribute quad to the point pattern

csr.add_marks([quad], mark_names=['quad'])
csr.df
x y quad
0 -79.603948 37.791190 2
1 -80.079205 37.396681 3
2 -79.464397 36.625981 3
3 -76.437205 36.884895 4
4 -78.545956 37.992603 1
5 -80.241928 36.991135 3
6 -77.898430 37.716846 1
7 -76.498353 37.321863 4
8 -79.900184 37.854658 2
9 -81.102672 36.633735 3
10 -77.281811 36.976553 4
11 -77.083152 37.303132 4
12 -83.035154 36.618248 3
13 -77.997824 38.483939 1
14 -76.576682 37.932985 1
15 -77.048965 37.697935 1
16 -78.330254 37.421786 4
17 -78.420495 38.125428 1
18 -77.379883 38.801099 1
19 -82.102351 36.838275 3
20 -77.139652 36.681456 4
21 -81.411197 37.009286 3
22 -78.377109 38.110156 1
23 -82.348030 37.260970 3
24 -78.540305 37.759264 1
25 -78.708559 38.778273 1
26 -77.119341 37.441159 4
27 -77.532402 37.827257 1
28 -81.025392 36.963752 3
29 -81.234484 37.187202 3
... ... ... ...
170 -79.175687 38.412747 2
171 -79.466336 37.677601 2
172 -80.503082 36.784620 3
173 -79.654007 36.620456 3
174 -78.283744 38.436626 1
175 -76.917112 36.713404 4
176 -82.234255 36.978863 3
177 -81.012936 37.186895 3
178 -77.979839 36.758554 4
179 -77.979268 38.366633 1
180 -75.550882 37.940486 1
181 -81.031949 37.194569 3
182 -80.957128 37.150309 3
183 -77.766785 37.647643 1
184 -79.411096 37.705193 2
185 -80.691844 36.673324 3
186 -78.752009 38.137110 1
187 -79.160647 38.047687 2
188 -78.244262 37.137316 4
189 -77.641999 38.612349 1
190 -77.961376 37.257348 4
191 -77.664101 37.612087 1
192 -82.073349 37.151563 3
193 -80.029721 36.650720 3
194 -77.015099 36.892940 4
195 -81.938727 36.759000 3
196 -78.653617 38.637913 1
197 -78.353159 38.009389 1
198 -76.652473 36.918815 4
199 -76.806542 37.477773 4

200 rows × 3 columns

Explode a marked point pattern into a sequence of individual point patterns. Since the mark quad has 4 unique values, the sequence will be of length 4.

csr_q = csr.explode('quad')
len(csr_q)
4
csr
<pointpats.pointpattern.PointPattern at 0x1b2058a320>
csr.summary()
Point Pattern
200 points
Bounding rectangle [(-83.5775552379073,36.58477411642467), (-75.55088173741038,39.23835955804836)]
Area of window: 21.299463945585302
Intensity estimate for window: 9.389907676125041
           x          y  quad
0 -79.603948  37.791190     2
1 -80.079205  37.396681     3
2 -79.464397  36.625981     3
3 -76.437205  36.884895     4
4 -78.545956  37.992603     1

Plot the 4 individual sequences

plt.xlim?
plt.xlim()
for ppn in csr_q:
    ppn.plot()

png

png

png

png

png

Plot the 4 unmarked point patterns using the same axes for a convenient comparison of locations

x0, y0, x1, y1 = csr.mbb
ylim = (y0, y1)
xlim = (x0, x1)
for ppn in csr_q:
    ppn.plot()
    plt.xlim(xlim)
    plt.ylim(ylim)

png

png

png

png