imod.prepare.fill#

imod.prepare.fill(da, dims=None)[source]#

Fill in NaNs using basic nearest neighbour interpolation.

Parameters:
  • da (xr.DataArray with gaps) – array containing NaN values.

  • dims (sequence of str, optional, default is ("y", "x").) – Dimensions along which to search for nearest neighbors. For example, (“y”, “x”) will perform 2D interpolation in the horizontal plane, while (“layer”, “y”, “x”) will perform 3D interpolation including the vertical dimension.

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 dims keyword can be used to do control this:

>>> filled = imod.prepare.fill(da, dims=("y", "x"))

In this case, the array is filled by one layer at a time.

To also incorporate nearest values across the layer dimension:

>>> filled = imod.prepare.fill(da, dims=("layer", "y", "x"))