geovalidate.ConstantClassSampler¶
-
class geovalidate.ConstantClassSampler(n_per_class=
100, quasi_random=None, random_state=None)[source]¶ Sample exactly n_per_class points from each class.
Accepts a
geopandas.GeoSeries/geopandas.GeoDataFramepaired with a labels vector, or a rasterio dataset paired with a 2-D numpy array of class labels read from the desired band.- Parameters:¶
Examples
GeoDataFrame path:
pts = ConstantClassSampler(n_per_class=50).sample( gdf.geometry, gdf["lc_class"] )Raster path – read the band yourself, pass it as labels:
with rasterio.open("landcover.tif") as ds: pts = ConstantClassSampler(n_per_class=50).sample(ds, ds.read(1))-
__init__(n_per_class=
100, quasi_random=None, random_state=None)[source]¶
Methods
__init__([n_per_class, quasi_random, ...])Get metadata routing of this object.
get_params([deep])Get parameters for this estimator.
sample(geometry[, labels])Generate balanced 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)[source]¶ Generate balanced class samples.
- Parameters:¶
- geometry : GeoSeries | GeoDataFrame | rasterio.DatasetReader | path-like¶
Spatial source. For the raster path a
DatasetReader(or file path) is used for its transform / CRS / nodata metadata only – no band is read from it here.- labels : array-like of shape (n,) or 2-D ndarray, required¶
Class label for each geometry (GDF path) or a 2-D numpy array of integer class labels with shape
(nrows, ncols)(raster path, e.g.ds.read(1)).
- Returns:¶
Columns:
geometry,class_label.- Return type:¶