ODCExtensionDa.to_cog(blocksize: int | None = None, ovr_blocksize: int | None = None, overviews: Iterable[xr.DataArray] | None = None, overview_resampling: str | None = None, overview_levels: List[int] | None = None, use_windowed_writes: bool = False, intermediate_compression: bool | str | Dict[str, Any] = False, tags: Dict[str, Any] | None = None, **extra_rio_opts) bytes

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.

  • 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:



In-memory GeoTiff file as bytes