geovalidate.StratifiedClassSampler¶
-
class geovalidate.StratifiedClassSampler(n_samples=
500, quasi_random=None, random_state=None)[source]¶ Sample n_samples points total, allocated proportionally across classes.
When weights are provided the allocation for each class is proportional to the sum of the weight values within that class. The integer counts are resolved by the largest-remainder (Hamilton) method so the total equals n_samples exactly.
When weights are omitted the sampler falls back to uniform random sampling over the full union of all class geometries and then assigns labels by spatial containment – equivalent to
PointSampler.- Parameters:¶
Examples
GeoDataFrame path:
pts = StratifiedClassSampler(n_samples=500).sample( gdf.geometry, gdf["lc_class"], gdf["area_ha"] )Raster path – read bands yourself:
with rasterio.open("landcover.tif") as ds: pts = StratifiedClassSampler(n_samples=500).sample( ds, ds.read(1), ds.read(2) # class band, value band )-
__init__(n_samples=
500, quasi_random=None, random_state=None)[source]¶
Methods
__init__([n_samples, quasi_random, random_state])Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
sample(geometry[, labels, weights])Generate proportionally allocated class samples.
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, labels=
None, weights=None)[source]¶ Generate proportionally allocated class samples.
- Parameters:¶
- geometry : GeoSeries | GeoDataFrame | rasterio.DatasetReader | path-like¶
- labels : array-like of shape (n,) or 2-D ndarray, required¶
Class label per geometry (GDF) or 2-D integer class array (raster).
- weights : array-like of shape (n,) or 2-D ndarray, optional¶
Per-geometry weight (GDF) or 2-D value array (raster). When None, falls back to uniform random sampling.
- Returns:¶
Columns:
geometry,class_label.- Return type:¶