sgsPy
structurally guided sampling
Loading...
Searching...
No Matches

Functions

 sgspy.stratify.breaks.breaks.breaks (SpatialRaster rast, list[float|list[float]]|dict[str, list[float]] breaks, bool map=False, str filename='', int thread_count=8, dict driver_options=None, Optional[bool] plot=False, Optional[int] histogram_bins=None)
 This function conducts stratification on the raster given according to the user defined breaks.

Detailed Description

Function Documentation

◆ breaks()

sgspy.stratify.breaks.breaks.breaks ( SpatialRaster rast,
list[float | list[float]] | dict[str, list[float]] breaks,
bool map = False,
str filename = '',
int thread_count = 8,
dict driver_options = None,
Optional[bool] plot = False,
Optional[int] histogram_bins = None )

This function conducts stratification on the raster given according to the user defined breaks.

The breaks may be defined as a single list of ints or floats in the case of a raster with a single band. Or, they may be defined as a list of ints or floats where the index indicates the raster band. Or, they may be defined as a dict where the (str) key represents the raster band and the value is a list of ints or floats.

if the map parameter is given, an extra output band will be used which combines all stratifications from the previous bands used. A single value in the mapped output band corresponds to a single combination of values from the previous bands.

the filename parameter specifies an output file name. Right now the only file format excepted is GTiff (.tif).

the thread_count parameter specifies the number of threads which this function will utilize in the case where the raster is large and may not fit in memory. If the full raster can fit in memory and does not need to be processed in blocks, this argument will be ignored. The default is 8 threads, although the optimal number will depend significantly on the hardware being used and my be less or more than 8.

The driver_options parameter is used to specify creation options for a the output raster. See options for the Gtiff driver here: https://gdal.org/en/stable/drivers/raster/gtiff.html#creation-options The keys in the driver_options dict must be strings, the values are converted to string. The options must be valid for the driver corresponding to the filename, and if filename is not given they must be valid for the GTiff format, as that is the format used to store temporary raster files. Note that if this parameter is given, but filename is not and the raster fits entirely in memory, the driver_options parameter will be ignored.

Additionally, the 'plot' parameter determines whether a histogram plot will be made of the stratified bands. The histogram will be the distribution of each of the raster bands which had stratified bands made from them, with indicators on the break values. The 'histogram_bins' parameter indicates the number of bands in each of the plotted histograms.

Examples

rast = sgspy.SpatialRaster("multi_band_rast.tif")
srast = sgspy.stratify.breaks(rast, breaks={"band_name1": [3, 5, 11, 18]})

rast = sgspy.SpatialRaster("single_band_rast.tif")
srast = sgspy.stratify.breaks(rast, breaks=[20, 40, 60, 80], filename="breaks.tif", driver_options={"COMPRESS", "LZW"}))

rast = sgspy.SpatialRaster("multi_band_rast.tif")
srast = sgspy.stratify.breaks(rast, breaks={"band_name1": [3, 5, 11, 10], "band_name2": [20, 40, 60, 80]}, map=True)

rast = sgspy.SpatialRaster("multi_band_rast.tif")
srast = sgspy.stratify.breaks(rast, breaks=[[3, 5, 11, 18], [40, 60, 80], [2, 5]], plot=True)

Parameters

rast : SpatialRaster
raster data structure containing the raster to stratify

breaks : list[float | list[float]] | dict[str, list[float]],
user defined breaks to stratify

map : bool
whether to map the stratification of multiple raster bands onto a single band

filename : str
filename to write to or '' if no file should be written

thread_count : int
the number of threads to use when multithreading large images

driver_options : dict[]
the creation options as defined by GDAL which will be passed when creating output files

plot : optional[bool]
whether or not to plot a histogram of the values in the bands with indicators on the breaks

histogram_bins : Optional[int]
The number of bins in the plotted histogram.

Returns

a SpatialRaster object containing stratified raster bands.