Work with iMOD MODFLOW models
Project description
Work with iMOD MODFLOW models in Python.
Documentation: https://deltares.gitlab.io/imod-python/
Source code: https://gitlab.com/deltares/imod-python
Getting started
In absence of actual documentation, here are some of the functions:
import imod
df = imod.ipf.load('wells.ipf')
imod.ipf.save('wells-out.ipf', df)
# get all calculated heads in a xarray DataArray
# with dimensions time, layer, y, x
da = imod.idf.load('path/to/results/head_*.idf')
Notes
The iMOD 4.1 release will crash on loading NaN nodata values. In earlier and later releases this is not an issue.
Implementation of imod.idf.load
Do a glob search on all files matching the input path, e.g. head_*.idf
For each IDF:
Gather all metadata from filename and IDF header
Load IDF array with np.memmap in r+ mode.
Set nodata to np.nan (changes input file, done to be compatible with xarray)
Load np.memmap into a dask.array
Combine metadata and dask.array into an xarray.DataArray
Combine the indivual DataArrays into one, adding time and layer dimensions as necessary.
With the current design, I’m not sure what the added benefit of using dask arrays is, and whether it should be removed. One possible benefit is that it is only possible to write to the DataArray after calling .load() on it first, which in this case still doesn’t load it into memory.
We can also still explore using the c copy on write mode of numpy.memmap.
Comment by xarray author Stephan Hoyer about using np.memmap on GitHub:
If it’s already on disk in a memory-mappable format, it’s very hard to imagine beating np.memmap.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.