odc.geo.xr.to_cog

odc.geo.xr.to_cog(geo_im, blocksize=None, ovr_blocksize=None, overviews=None, overview_resampling=None, overview_levels=None, use_windowed_writes=False, intermediate_compression=False, tags=None, **extra_rio_opts)[source]

Compress xarray.DataArray into Cloud Optimized GeoTiff bytes in memory.

This function doesn’t write to disk, it compresses in RAM, which is useful for saving data to S3 or other cloud object stores.

Parameters:
  • geo_im (DataArray) – xarray.DataArray with crs

  • blocksize (Optional[int]) – Size of internal tiff tiles (512x512 pixels)

  • ovr_blocksize (Optional[int]) – Size of internal tiles in overview images (defaults to blocksize)

  • overviews (Optional[Iterable[DataArray]]) – Write pre-computed overviews if supplied

  • overview_resampling (Optional[str]) – Use this resampling when computing overviews

  • overview_levels (Optional[List[int]]) – List of shrink factors to compute overiews for: [2,4,8,16,32]

  • nodata – Set nodata flag to this value if supplied, by default nodata is read from the attributes of the input array (geo_im.attrs['nodata']).

  • use_windowed_writes (bool) – Write image block by block (might need this for large images)

  • intermediate_compression (Union[bool, str, Dict[str, Any]]) – Configure compression settings for first pass write , default is no compression

  • tags (Optional[Dict[str, Any]]) – Dictionary of tags to write into the output file. These are written as GDAL Metadata items in the GeoTIFF file.

  • extra_rio_opts – Any other option is passed to rasterio.open

Return type:

bytes

Returns:

In-memory GeoTiff file as bytes