Work with iMOD MODFLOW models
Work with iMOD MODFLOW models in Python.
Source code: https://gitlab.com/deltares/imod-python
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')
- 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.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|imod-0.4.0-py3-none-any.whl (27.9 kB) Copy SHA256 hash SHA256||Wheel||py3||Oct 4, 2018|
|imod-0.4.0.tar.gz (40.4 kB) Copy SHA256 hash SHA256||Source||None||Oct 4, 2018|