imod.formats.idf.save#
- imod.formats.idf.save(path, a, nodata=1e+20, pattern=None, dtype=<class 'numpy.float32'>)[source]#
Write a xarray.DataArray to one or more IDF files
If the DataArray only has
yandxdimensions, a single IDF file is written. This function is more general and also supportstimeandlayerdimensions. It will split these up, give them their own filename according to the conventions inimod.util.path.compose, and write them each.- Parameters:
path (str or Path) – Path to the IDF file to be written. This function decides on the actual filename(s) using conventions.
a (xarray.DataArray) – DataArray to be written. It needs to have dimensions (‘y’, ‘x’), and optionally
layerandtime.nodata (float, optional) – Nodata value in the saved IDF files. Xarray uses nan values to represent nodata, but these tend to work unreliably in iMOD(FLOW). Defaults to a value of 1.0e20.
pattern (str) – Format string which defines how to create the filenames. See examples.
dtype (type,
{np.float32, np.float64}, default isnp.float32.) – Whether to write single precision (np.float32) or double precision (np.float64) IDF files.
Example
Consider a DataArray
dathat has dimensions('layer', 'y', 'x'), with the layer dimension consisting of layer 1 and 2:>>> imod.idf.save('path/to/head', da)
This writes the following two IDF files:
path/to/head_l1.idfandpath/to/head_l2.idf.To disable adding coordinates to the files, specify
pattern="{name}":>>> imod.idf.save('path/to/head', da, pattern="{name}")
The “.idf” extension will always be added automatically.
It is possible to generate custom filenames using a format string. The default filenames would be generated by the following format string:
>>> imod.idf.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:
>>> imod.idf.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:
>>> pattern="{name}_{time:%Y-%m-%d}_l{layer}{extension}"