Author: Serge Rey sjsrey@gmail.com and Wei Kang weikang9009@gmail.com
One philosophy of applying inferential statistics to spatial data is to think in terms of spatial processes and their possible realizations. In this view, an observed map pattern is one of the possible patterns that might have been generated by a hypothesized process. In this notebook, we are going to regard point patterns as the outcome of point processes. There are three major types of point process, which will result in three types of point patterns:
We will investigate how to generate these point patterns via simulation (Data Generating Processes (DGP) is the correponding point process), and inspect how these resulting point patterns differ from each other visually. In Quadrat statistics notebook and distance statistics notebook, we will adpot some statistics to infer whether it is a Complete Spaital Randomness (CSR) process.
A python file named "process.py" contains several point process classes with which we can generate point patterns of different types.
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 numpy as np
#import matplotlib.pyplot as plt
Random point patterns are the outcome of CSR. CSR has two major characteristics:
It usually serves as the null hypothesis in testing whether a point pattern is the outcome of a random process.
There are two types of CSR:
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)
In [4]:
# create window from virginia state boundary
window = Window(state.parts)
In [5]:
# simulate a csr process in the same window (200 points, 1 realization)
# by specifying "asPP" false, we can generate a point series
# by specifying "conditioning" false, we can simulate a N-conditioned CSR
np.random.seed(5)
samples = PoissonPointProcess(window, 200, 1, conditioning=False, asPP=False)
samples
Out[5]:
In [6]:
samples.realizations[0] # simulated event points
Out[6]:
In [7]:
# build a point pattern from the simulated point series
pp_csr = PointPattern(samples.realizations[0])
pp_csr
Out[7]:
In [8]:
pp_csr.plot(window=True, hull=True, title='Random Point Pattern')
In [9]:
pp_csr.n
Out[9]:
In [10]:
# simulate a csr process in the same window (200 points, 1 realization)
# by specifying "asPP" false, we can generate a point series
# by specifying "conditioning" True, we can simulate a lamda-conditioned CSR
np.random.seed(5)
samples = PoissonPointProcess(window, 200, 1, conditioning=True, asPP=False)
samples
Out[10]:
In [11]:
samples.realizations[0] # simulated points
Out[11]:
In [12]:
# build a point pattern from the simulated point series
pp_csr = PointPattern(samples.realizations[0])
pp_csr
Out[12]:
In [13]:
pp_csr.plot(window=True, hull=True, title='Random Point Pattern')
In [14]:
pp_csr.n
Out[14]:
The simulated point pattern has $194$ events rather than the Possion mean $200$.
In [15]:
# simulate a csr process in the same window (200 points, 1 realization)
# by specifying "asPP" True, we can generate a point pattern
# by specifying "conditioning" false, we can simulate a N-conditioned CSR
np.random.seed(5)
samples = PoissonPointProcess(window, 200, 1, conditioning=False, asPP=True)
samples
Out[15]:
In [16]:
pp_csr = samples.realizations[0] # simulated point pattern
pp_csr
Out[16]:
In [17]:
pp_csr.plot(window=True, hull=True, title='Random Point Pattern')
In [18]:
pp_csr.n
Out[18]:
In [19]:
# simulate a csr process in the same window (200 points, 1 realization)
# by specifying "asPP" True, we can generate a point pattern
# by specifying "conditioning" True, we can simulate a lamda-conditioned CSR
np.random.seed(5)
samples = PoissonPointProcess(window, 200, 1, conditioning=True, asPP=True)
samples
Out[19]:
In [20]:
pp_csr = samples.realizations[0] # simulated point pattern
pp_csr
Out[20]:
In [21]:
pp_csr.plot(window=True, hull=True, title='Random Point Pattern')
In [22]:
pp_csr.n
Out[22]:
Clustered Patterns are more grouped than random patterns. Visually, we can observe more points at short distances. There are two sources of clustering:
We are going to focus on simulating correlated point process in this notebook. One example of correlated point process is Poisson cluster process. Two stages are involved in simulating a Poisson cluster process. First, parent events are simulted from a $\lambda$-conditioned or $N$-conditioned CSR. Second, $n$ offspring events for each parent event are simulated within a circle of radius $r$ centered on the parent. Offspring events are independently and identically distributed.
In [23]:
np.random.seed(5)
csamples = PoissonClusterPointProcess(window, 200, 10, 0.5, 1, asPP=True, conditioning=False)
csamples
Out[23]:
In [24]:
csamples.parameters #number of total events for each realization
Out[24]:
In [25]:
csamples.num_parents #number of parent events for each realization
Out[25]:
In [26]:
csamples.children # number of children events centered on each parent event
Out[26]:
In [27]:
pp_pcp = csamples.realizations[0]
pp_pcp
Out[27]:
In [28]:
pp_pcp.plot(window=True, hull=True, title='Clustered Point Pattern') #plot the first realization
It is obvious that there are several clusters in the above point pattern.
In [29]:
import numpy as np
np.random.seed(10)
csamples = PoissonClusterPointProcess(window, 200, 10, 0.5, 1, asPP=True, conditioning=True)
csamples
Out[29]:
In [30]:
csamples.parameters #number of events for the realization might not be equal to 200
Out[30]:
In [31]:
csamples.num_parents #number of parent events for the realization, not equal to 10
Out[31]:
In [32]:
csamples.children # number of children events centered on each parent event
Out[32]:
In [33]:
pp_pcp = csamples.realizations[0]
pp_pcp.plot(window=True, hull=True, title='Clustered Point Pattern')
In [34]:
np.random.seed(10)
csamples = PoissonClusterPointProcess(window, 200, 5, 0.5, 1, asPP=True)
pp_pcp = csamples.realizations[0]
pp_pcp.plot(window=True, hull=True, title='Clustered Point Pattern')
In [ ]: