any_raster_to_xr_ds

any_raster_to_xr_ds#

any_raster_to_xr_ds(function: Callable) Callable[source]#

Allows a function to ingest AnyRasterType and convert it into a xr.DataArray:

  • a path (Path, CloudPath or str)

  • a xarray.Dataset or a xarray.DataArray

  • a rasterio.DatasetWriter or rasterio.DatasetReader

  • rasterio dataset after reading, its array and metadata: (np.ndarray, dict)

Parameters:

function (Callable) – Function to decorate

Returns:

decorated function

Return type:

Callable

Examples

>>> # Create mock function
>>> @path_or_dst
>>> def fct(ds):
>>>     read(ds)
>>>
>>> # Test the two ways
>>> read1 = fct("path/to/raster.tif")
>>> with rasterio.open("path/to/raster.tif") as ds:
>>>     read2 = fct(ds)
>>>
>>> # Test
>>> read1 == read2
True