imod.prepare.fill#
- imod.prepare.fill(da, invalid=None, by=None)[source]#
Replace the value of invalid
da
cells (indicated byinvalid
) using basic nearest neighbour interpolation.- Parameters:
da (xr.DataArray with gaps) – array containing missing value
by (str, optional) – dimension over which the array will be filled, one by one. See the examples.
invalid (xr.DataArray) – a binary array of same shape as
da
. data value are replaced where invalid is True If None (default), uses: invalid = np.isnan(data)
- Returns:
with the same coordinates as the input.
- Return type:
xarray.DataArray
Examples
A common use case is filling holes in a DataArray, filling it with the value of its nearest (valid) neighbor:
>>> filled = imod.prepare.fill(da)
In case of a tie (e.g. neighbors in x and y are both one cell removed), the neighbor in the last dimension is chosen (for rasters, that’s generally x).
A typical use case is filling a 3D array (layer, y, x), but only in the horizontal dimensions. The
by
keyword can be used to do this:>>> filled = imod.prepare.fill(da, by="layer")
In this case, the array is filled by one layer at a time.