stems.io.rasterio_ module

Rasterio IO helpers

stems.io.rasterio_.DEFAULT_RASTERIO_DRIVER = 'GTiff'

Default Rasterio driver format

stems.io.rasterio_.RASTERIO_ATTR_WHITELIST = ('nodatavals',)

Attributes to keep from output of xarray.open_rasterio

stems.io.rasterio_.xarray_to_rasterio(xarr, path, driver='GTiff', crs=None, transform=None, nodata=None, **meta)[source]

Save a DataArray to a rasterio/GDAL dataset :param xarr: 2D or 3D DataArray to save. Shape is assumed to be

(width, height, ) for 2D or (count, width, height, ) for 3D arrays

Parameters
  • path (str or Path) – Save DataArray to this file path

  • driver (str, optional) – Rasterio dataset driver

  • crs (str, dict, or rasterio.crs.CRS, optional) – Optionally, provide CRS information about xarr. Will try to read from xarr if not provided

  • transform (affine.Affine, optional) – Optionally, provide affine transform information about xarr. Will try to read from xarr if not provided

  • nodata (int or float, optional) – No data value to set

  • **meta – Additional keyword arguments to rasterio.open(). Useful for specifying block sizes, color interpretation, and other metadata.

Returns

path – Saved file path

Return type

Path

Raises

ValueError – Raised if xarr is not 2D or 3D