|
sgsPy
structurally guided sampling
|
Functions | |
| sgspy.sample.strat.strat.strat (SpatialRaster strat_rast, int num_samples, Optional[int] num_strata=None, int wrow=3, int wcol=3, Optional[int|str] band=None, str allocation="prop", Optional[list[float]] weights=None, Optional[SpatialRaster] mrast=None, Optional[int|str] mrast_band=None, str method="Queinnec", Optional[int|float] mindist=None, Optional[SpatialVector] existing=None, bool force=False, Optional[SpatialVector] access=None, Optional[str] layer_name=None, Optional[int|float] buff_inner=None, Optional[int|float] buff_outer=None, bool plot=False, str filename="") | |
| This function conducts stratified sampling using the stratified raster given. | |
| sgspy.sample.strat.strat.strat | ( | SpatialRaster | strat_rast, |
| int | num_samples, | ||
| Optional[int] | num_strata = None, | ||
| int | wrow = 3, | ||
| int | wcol = 3, | ||
| Optional[int | str] | band = None, | ||
| str | allocation = "prop", | ||
| Optional[list[float]] | weights = None, | ||
| Optional[SpatialRaster] | mrast = None, | ||
| Optional[int | str] | mrast_band = None, | ||
| str | method = "Queinnec", | ||
| Optional[int | float] | mindist = None, | ||
| Optional[SpatialVector] | existing = None, | ||
| bool | force = False, | ||
| Optional[SpatialVector] | access = None, | ||
| Optional[str] | layer_name = None, | ||
| Optional[int | float] | buff_inner = None, | ||
| Optional[int | float] | buff_outer = None, | ||
| bool | plot = False, | ||
| str | filename = "" ) |
This function conducts stratified sampling using the stratified raster given.
There are two methods employed to determine which pixels to sample:
The desired number of samples is given by num_samples.
IMPORTANT the num_strata argument is required only if the strat raster given is not the return value of a sgspy stratification function. If the strat raster given is the return value of an sgspy stratification function, then this value is automatically stored and used. The num_strata argument, if required, should be set to the value of the largest strata + 1. For example if the strata are [0, 1, 2, 3, 4] then num_strata should be 5. If the strata are [1, 2, 4] then num_strata should still be 5. If the strata are [0, 1, 2, 3] then num_strata should be 4.
The allocation parameter specifies the proportion of total samples will be distributed between each strata. The 'prop' method is the default, and attempts to allocate the samples proportionally according to their prevalence in the overall raster. The 'equal' method attempts to distribute the samples equally among strata. the 'manual' method requires that the weights parameter be given, and attempts to allocate according to the proportions given in the weights parameter. In the case where 'optim' allocation is used, an additional raster must be passed to the mrast parameter, and if that raster contains more than 1 band the mrast_band parameter must be given specifying which band. The optim method is specified by Gregoire and Valentine, and optimizes the desired proportions based on the proportion of each strata AND the within-strata variance in the specified raster band. https://doi.org/10.1201/9780203498880 Section 5.4.4.
The 'existing' parameter, if passed, must be a SpatialVector of type Point or MultiPoint. These points specify samples within an already-existing network. The SpatialVector may only have one layer. If the force parameter is set to True, every pixel in the existing sample will be added no matter what. if the force parameter is false, then the existing samples will be prioritized over other pixels in the same strata.
The 'access' parameter, if passed, must be a SpatialVector of type LineString or MultiLineString. buff_outer specifies the buffer distance around the geometry which is allowed to be included in the sampling, buff_inner specifies the geometry which is not allowed to be included in the sampling. buff_outer must be larger than buff_inner. For a multi-layer vector, layer_name must be specified.
rast = sgspy.SpatialRaster("raster.tif")
srast = sgspy.stratify.quantiles(rast, quantiles=5)
samples = sgspy.sample.strat(srast, num_samples=200) #uses Queinnec method with proportional allocation by default
srast = sgs.SpatialRaster("srast.tif") #srast not result of sgspy stratification function, num_strata arg necessary in sgspy.sample.strat samples = sgspy.sample.strat(srast, num_strata=5, num_samples=200)
rast = sgspy.SpatialRaster("raster.tif")
srast = sgspy.stratify.quantiles(rast, quantiles=5)
samples = sgspy.sample.strat(srast, num_samples=200, method="random", mindist=200, plot=True, filename="samples.shp")
rast = sgspy.SpatialRaster("raster.tif")
srast = sgspy.stratify.quantiles(rast, quantiles=5)
samples = sgspy.sample.strat(srast, num_samples=200, method="Queinnec", allocation="optim", mrast=rast)
rast = sgspy.SpatialRaster("raster.tif")
srast = sgspy.stratify.quantiles(rast, quantiles=5)
samples = sgspy.sample.strat(rast, num_samples=200, allocation="manual", weights=[0.1, 0.1, 0.2, 0.2, 0.4])
rast = sgspy.SpatialRaster("raster.tif")
access = sgspy.SpatialVector("access_network.shp")
srast = sgspy.stratify.quantiles(rast, quantiles=5)
samples = sgspy.sample.strat(rast, num_samples=200, allocation="equal", access=access, buff_inner=100, buff_outer=300)
rast = sgspy.SpatialRaster("raster.tif")
existng = sgspy.SpatialVector("existing_samples.shp")
srast = sgspy.stratify.quantiles(rast, quantiles=5)
samples = sgspy.sample.strat(rast, num_samples=200, allocation="prop", existing=existing, force=True)
strat_rast : SpatialRaster the raster to sample band : Optional[int | str]
the band within the strat_rast to use, required if strat_rast has more than 1 band, either a 0-indexed int value or the name of the band
num_samples : int
the desired number of samples
num_strata : Optional[int]
the value of the largest stratification in the strat_rast + 1
wrow : int
the number of rows to be considered in the focal window for the 'Queinnec' method
wcol : int
the number of columns to be considered in the focal window for the 'Queinnec' method
allocation : str
the allocation method to determine the number of samples per strata. One of 'prop', 'equal', 'optim', or 'manual'
weights : list[float]
the allocation percentages of each strata if the allocation method is 'manual'
mrast : SpatialRaster
the raster used to calculate 'optim' allocation if 'optim' allocation is used
mrast_band : str | int
specifies the band within mrast to use
method : str
the sampling method, either 'random', or 'Queinnec'
mindist : float
the minimum distance allowed between sample points
existing : SpatialVector
a vector of Point or Multipoint which are part of a pre-existing sample network
force : bool
whether to automatically include all points in the existing network or not
access : SpatialVector
a vector of LineString or MultiLineString geometries to sample near to
layer_name : str
the layer within 'access' to use for access buffering
buff_inner : float
the inner buffer around the access LineStrings, where samples should not occur
buff_outer : float
the outer buffer around the access LineStrings, The area in which samples must occur
plot : bool
whether or not to plot the output samples
filename : str
the output filename to write to if desired
a SpatialVector object containing point geometries of sample locations