sieve(xds: Union[str, xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset,], sieve_thresh: int, connectivity: int = 4, dtype=<class 'numpy.uint8'>) Union[xarray.core.dataset.Dataset, xarray.core.dataarray.DataArray][source]

Sieving, overloads rasterio function with raster shaped like (1, h, w).


Your data is casted by force into np.uint8, so be sure that your data is classified.

>>> raster_path = "path\to\raster.tif"  # classified raster

>>> # Rewrite it
>>> sieved_xds = sieve(raster_path, sieve_thresh=20)

>>> # Write it
>>> raster_out = "path\to\raster_sieved.tif"
>>> write(sieved_xds, raster_out)
  • xds (PATH_XARR_DS) – Path to the raster or a rasterio dataset or a xarray

  • sieve_thresh (int) – Sieving threshold in pixels

  • connectivity (int) – Connectivity, either 4 or 8

  • dtype – Dtype of the xarray (if nodata is set, the xds.dtype is float whereas the values are meant to be ie in np.uint8)


Sieved xarray

Return type