imod.formats.rasterio.save#

imod.formats.rasterio.save(path, a, driver=None, nodata=nan, pattern=None, dtype=None)[source]#

Write a xarray.DataArray to one or more rasterio supported files

If the DataArray only has y and x dimensions, a single raster file is written, like the imod.rasterio.write function. This function is more general and also supports time and layer and other dimensions. It will split these up, give them their own filename according to the conventions in imod.util.path.compose, and write them each.

Parameters
  • path (str or Path) – Path to the raster file to be written. This function decides on the actual filename(s) using conventions, so it only takes the directory and name from this parameter.

  • a (xarray.DataArray) – DataArray to be written. It needs to have dimensions (‘y’, ‘x’), and optionally layer and time.

  • driver (str, optional) – Which GDAL format driver to use. The complete list is at https://gdal.org/drivers/raster/index.html. By default tries to guess from the file extension.

  • nodata (float, optional) – Nodata value in the saved raster files. Defaults to a value of nan.

  • pattern (str) – Format string which defines how to create the filenames. See examples.

Example

Consider a DataArray da that has dimensions ‘layer’, ‘y’ and ‘x’, with the ‘layer’ dimension consisting of layer 1 and 2:

save('path/to/head', da)

This writes the following two tif files: ‘path/to/head_l1.tif’ and ‘path/to/head_l2.tif’.

It is possible to generate custom filenames using a format string. The default filenames would be generated by the following format string:

save(“example”, pattern=”{name}_l{layer}{extension}”)

If you desire zero-padded numbers that show up neatly sorted in a file manager, you may specify:

save(“example”, pattern=”{name}_l{layer:02d}{extension}”)

In this case, a 0 will be padded for single digit numbers (‘1’ will become ‘01’).

To get a date with dashes, use the following pattern:

“{name}_{time:%Y-%m-%d}_l{layer}{extension}”