<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Planar Point Patterns in PySAL
Author
Step1:  Creating Point Patterns
From lists
We can build a point pattern by using Python lists of coordinate pairs $(s_0, s_1,\ldots, s_m)$ as follows
Step2:  Thus $s_0 = (66.22, 32.54), \ s_{11}=(54.46, 8.48)$.
Step3:  From numpy arrays
Step4:  From shapefiles
This example uses 200 randomly distributed points within the counties of Virginia. Coordinates are for UTM zone 17 N.
Step5:  Attributes of PySAL Point Patterns
Step6:  Intensity Estimates
The intensity of a point process at point $s_i$ can be defined as
Step7:  Intensity based on convex hull
<ASSISTANT_TASK:>
Python Code:
import pysal.lib as ps
import numpy as np
from pysal.explore.pointpats import PointPattern
Explanation: Planar Point Patterns in PySAL
Author: Serge Rey &#115;&#106;&#115;&#114;&#101;&#121;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109; and Wei Kang &#119;&#101;&#105;&#107;&#97;&#110;&#103;&#57;&#48;&#48;&#57;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;
Introduction
This notebook introduces the basic PointPattern class in PySAL and covers the following:
What is a point pattern?
Creating Point Patterns
Attributes of Point Patterns
Intensity Estimates
Next steps
What is a point pattern?
We introduce basic terminology here and point the interested reader to more detailed references on the underlying theory of the statistical analysis of point patterns.
Points and Event Points
To start we consider a series of point locations, $(s_1, s_2, \ldots, s_n)$ in a study region $\Re$. We limit our focus here to a two-dimensional space so that $s_j = (x_j, y_j)$ is the spatial coordinate pair for point location $j$.
We will be interested in two different types of points.
Event Points
Event Points are locations where something of interest has occurred. The term event is very general here and could be used to represent a wide variety of phenomena. Some examples include:
locations of individual plants of a certain species
archeological sites
addresses of disease cases
locations of crimes
the distribution of neurons
among many others.
It is important to recognize that in the statistical analysis of point patterns the interest extends beyond the observed point pattern at hand.
The observed patterns are viewed as realizations from some underlying spatial stochastic process.
Arbitrary Points
The second type of point we consider are those locations where the phenomena  of interest has not been observed. These go by various names such as "empty space" or "regular" points, and at first glance might seem less interesting to a spatial analayst. However, these types of points play a central role in a class of point pattern methods that we explore below.
Point Pattern Analysis
The analysis of event points focuses on a number of different characteristics of the collective spatial pattern that is observed. Often the pattern is jugded against the hypothesis of complete spatial randomness (CSR). That is, one assumes that the point events arise independently of one another and with constant probability across $\Re$, loosely speaking.
Of course, many of the empirical point patterns we encounter do not appear to be generated from such a simple stochastic process. The depatures from CSR can be due to two types of effects.
First order effects
For a point process, the first-order properties pertain to the intensity of the process across space. Whether and how the intensity of the point pattern varies within our study region are questions that assume center stage. Such variation in the itensity of the pattern of, say, addresses of individuals with a certain type of non-infectious disease may reflect the underlying population density. In other words, although the point pattern of disease cases may display variation in intensity in our study region, and thus violate the constant probability of an event condition, that spatial drift in the pattern intensity could be driven by an underlying covariate. 
Second order effects
The second channel by which departures from CSR can arise is through interaction and dependence between events in space. The canonical example being contagious diseases whereby the presence of an infected individual increases the probability of subsequent additional cases nearby.
When a pattern departs from expectation under CSR, this is suggestive that the underlying process may have some spatial structure that merits further investigation. Thus methods for detection of deviations from CSR and testing for alternative processes have given rise to a large literature in point pattern statistics.
Methods of Point Pattern Analysis in PySAL
The points module in PySAL implements basic methods of point pattern analysis organized into the following groups:
Point Processing
Centrography and Visualization
Quadrat Based Methods
Distance Based Methods
In the remainder of this notebook we shall focus on point processing.
End of explanation
points = [[66.22, 32.54], [22.52, 22.39], [31.01, 81.21],
          [9.47, 31.02],  [30.78, 60.10], [75.21, 58.93],
          [79.26,  7.68], [8.23, 39.93],  [98.73, 77.17],
          [89.78, 42.53], [65.19, 92.08], [54.46, 8.48]]
p1 = PointPattern(points)
p1.mbb
Explanation: Creating Point Patterns
From lists
We can build a point pattern by using Python lists of coordinate pairs $(s_0, s_1,\ldots, s_m)$ as follows:
End of explanation
p1.summary()
type(p1.points)
np.asarray(p1.points)
p1.mbb
Explanation: Thus $s_0 = (66.22, 32.54), \ s_{11}=(54.46, 8.48)$.
End of explanation
points = np.asarray(points)
points
p1_np = PointPattern(points)
p1_np.summary()
Explanation: From numpy arrays
End of explanation
f = ps.examples.get_path('vautm17n_points.shp')
fo = ps.io.open(f)
pp_va = PointPattern(np.asarray([pnt for pnt in fo]))
fo.close()
pp_va.summary()
Explanation: From shapefiles
This example uses 200 randomly distributed points within the counties of Virginia. Coordinates are for UTM zone 17 N.
End of explanation
pp_va.summary()
pp_va.points
pp_va.head()
pp_va.tail()
Explanation: Attributes of PySAL Point Patterns
End of explanation
pp_va.lambda_mbb
Explanation: Intensity Estimates
The intensity of a point process at point $s_i$ can be defined as:
$$\lambda(s_j) = \lim \limits_{|\mathbf{A}s_j| \to 0} \left { \frac{E(Y(\mathbf{A}s_j)}{|\mathbf{A}s_j|} \right }   $$
where $\mathbf{A}s_j$ is a small region surrounding location $s_j$ with area $|\mathbf{A}s_j|$, and $E(Y(\mathbf{A}s_j)$ is the expected number of event points in $\mathbf{A}s_j$. 
The intensity is the mean number of event points per unit of area at point $s_j$. 
Recall that one of the implications of CSR is that the intensity of the point process is constant in our study area $\Re$. In other words $\lambda(s_j) = \lambda(s_{j+1}) = \ldots = \lambda(s_n) = \lambda \ \forall s_j \in \Re$. Thus, if the area of $\Re$ = $|\Re|$ the expected number of event points in the study region is: $E(Y(\Re)) = \lambda |\Re|.$
In PySAL, the intensity is estimated by using a geometric object to encode the study region. We refer to this as the window, $W$. The reason for distinguishing between $\Re$ and $W$ is that the latter permits alternative definitions of the bounding object.
Intensity estimates are based on the following:
$$\hat{\lambda} = \frac{n}{|W|}$$
where $n$ is the number of points in the window $W$, and $|W|$ is the area of $W$.
Intensity based on minimum bounding box:
$$\hat{\lambda}{mbb} = \frac{n}{|W{mbb}|}$$
where $W_{mbb}$ is the minimum bounding box for the point pattern.
End of explanation
pp_va.lambda_hull
Explanation: Intensity based on convex hull:
$$\hat{\lambda}{hull} = \frac{n}{|W{hull}|}$$
where $W_{hull}$ is the convex hull for the point pattern.
End of explanation
<END_TASK>