raster_tools.Raster.save_chunks#

Raster.save_chunks(prefix, *, per_band=False, ext=None, **save_kwargs)[source]#

Save each dask chunk to a separate raster file.

Useful for tile-based downstream pipelines where each chunk needs to live as its own file on disk.

Filenames are built as <prefix>_<row>_<col><ext> (or <prefix>_b<band>_<row>_<col><ext> when per_band=True), with row/col/band indices zero-padded to the width of the largest index so files sort lexicographically.

Parameters
  • prefix (str or os.PathLike) – Prefix used for every output file. May include directories (e.g. "tiles/dem"); missing directories are created.

  • per_band (bool, optional) – If False (default), write one multi-band file per spatial chunk – the returned array has shape (n_row_chunks, n_col_chunks). If True, write one single-band file per (band, row, col) leaf – the returned array has shape (nbands, n_row_chunks, n_col_chunks).

  • ext (str, optional) – File extension applied to every output. The leading dot is optional. The default (None) picks an extension based on the driver ("driver" keyword), falling back to ".tif" when no driver is given. Pass "" for no extension.

  • **save_kwargs – Forwarded verbatim to Raster.save() for each chunk. Use this to set compression, blocksize, overviews, etc.

Returns

chunks – Object-dtype array of Raster instances pointing at the written files (mirrors Raster.save()’s return type).

Return type

numpy.ndarray of Raster

Notes

Per-file creation options (compress, blocksize, predictor, …) and overviews are applied to each tile individually. For typical dask auto-chunked rasters (chunks of several thousand pixels per side), per-tile overviews are sensible. For very small chunks the auto-overview chain will be empty and no pyramids will be written.