geovalidate.PoissonSampler¶
-
class geovalidate.PoissonSampler(n_expected=
None, bandwidth=None, kernel='gaussian', interpolation='linear', random_state=None)[source]¶ Inhomogeneous Poisson point process sampler.
The number of returned points is random – N ~ Poisson(∫∫_W λ(x,y) dA). Set n_expected to control the expected count; the sampler computes the normalisation constant K = ∫∫_W λ dA internally and derives scale = n_expected / K. When n_expected is None the raw integral of the intensity surface sets E[N].
Four ways to specify the intensity surface λ(x,y) are accepted by
sample():callable
f(x, y) -> array– intensity in points per unit area. Receives two 1-D NumPy arrays of x and y coordinates and must return a 1-D array of the same length. Lewis-Shedler thinning is used.rasterio.DatasetReader or 2-D ndarray – pixel image. With
interpolation='nearest'the pixel-selection algorithm is used. Withinterpolation='linear'bilinear interpolation + Lewis-Shedler thinning.1-D numeric array / Series (when geometry is a GeoSeries / GeoDataFrame of Polygons) – per-feature values burned into a 512-cell raster aligned to geometry. E.g.
sample(df.geometry, df.population).GeoSeries / GeoDataFrame of Points / (N, 2) ndarray – an observed point pattern; a kernel-density estimate of its intensity is used.
- Parameters:¶
- n_expected : float or None¶
Expected number of points per call to
sample(). Internally converted to a scale factor via scale = n_expected / K, where K is the normalisation constant of the intensity surface. When None the raw integral K sets E[N].- bandwidth : float or None¶
Kernel bandwidth for KDE mode, in the same units as the CRS.
Noneapplies Scott’s rule.- kernel : str¶
Kernel for KDE mode. Passed to
sklearn.neighbors.KernelDensity; typical values are'gaussian'(default),'tophat','epanechnikov'.- interpolation : {'nearest', 'linear'}¶
Pixel-interpolation strategy for raster input.
'nearest'uses the pixel-selection algorithm (fast).'linear'uses bilinear interpolation + Lewis-Shedler thinning.- random_state : int or None¶
-
__init__(n_expected=
None, bandwidth=None, kernel='gaussian', interpolation='linear', random_state=None)[source]¶
Methods
__init__([n_expected, bandwidth, kernel, ...])Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
sample(geometry, intensity)Generate an inhomogeneous Poisson point pattern inside geometry.
set_params(**params)Set the parameters of this estimator.
- get_metadata_routing()[source]¶
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
- Returns:¶
routing – A
MetadataRequestencapsulating routing information.- Return type:¶
MetadataRequest
- sample(geometry, intensity)[source]¶
Generate an inhomogeneous Poisson point pattern inside geometry.
- Parameters:¶
- geometry : shapely.Geometry | GeoSeries | GeoDataFrame | None¶
Sampling window. CRS is inferred automatically from GeoSeries / GeoDataFrame input. Pass
Nonewhen intensity is a rasterio DatasetReader – the window and CRS are then taken directly from the raster.- intensity : callable | DatasetReader | ndarray (2-D) | array-like (1-D) | GeoSeries | ndarray (N, 2)¶
Intensity surface (points per unit area):
callable
f(x, y)– receives two 1-D NumPy arrays and must return a 1-D array of intensities at those locations.rasterio.DatasetReader – first band used. geometry may be
Noneto use the full raster extent.2-D ndarray – pixel values, rows=north->south, columns=west->east, domain aligned to geometry’s bounding box.
1-D numeric array / Series (when geometry contains Polygons) – per-feature intensity values burned into a raster. E.g.
sample(df.geometry, df.population).GeoSeries / GeoDataFrame of Points / (N, 2) ndarray – a KDE is fitted and used as the intensity.
- Returns:¶
Column:
geometry(Point objects).- Return type:¶