interpolate¶
- emg3d.maps.interpolate(grid, values, xi, method='linear', extrapolate=True, log=False, **kwargs)[source]¶
Interpolate values from one grid to another grid or to points.
- Parameters
- gridTensorMesh
Input grid; a
emg3d.meshes.TensorMesh
instance.- valuesndarray
A model property such as
Model.property_x
, or a field such asField.fx
(ndim=3
; the dimension in each direction must either correspond to the number of nodes or cell centers in the corresponding direction).- xi{TensorMesh, tuple, ndarray}
Output coordinates; possibilities:
A grid (
emg3d.meshes.TensorMesh
): interpolation from one grid to another.A tuple (array_like, array_like, array_like) containing x-, y-, and z-coordinates. The length of each can be either one or the number of coordinates, the size-one elements will be expanded internally to the length of the coordinates. E.g.,
(x, [y0, y1, y2], z)
will be expanded to([x, x, x], [y0, y1, y2], [z, z, z])
.Arbitrary point coordinates as
ndarray
of shape(..., 3)
, e.g.,array([[x0, y0, z0], ..., [xN, yN, zN]))
.
- method{‘nearest’, ‘linear’, ‘volume’, ‘cubic’}, default: ‘linear’
The method of interpolation to perform.
'nearest', 'linear'
: Fastest methods; work for model properties and fields living on edges or faces. Carried out withscipy.interpolate.RegularGridInterpolator
.'cubic'
: Cubic spline interpolation usingemg3d.maps.interp_spline_3d
.'volume'
: Volume average interpolation usingemg3d.maps.interp_volume_average
.Volume average interpolation ensures that the total sum of the interpolated quantity stays constant. The result can be quite different if you provide resistivity, conductivity, or the logarithm of any of the two. The recommended way is to use
log=True
, in which case the output is the same for conductivities and resistivities.This method is only implemented for quantities living on cell centers, not on edges/faces (hence not for fields); and only for grids as input to
xi
.
- extrapolatebool, default: True
This parameter controls the default parameters provided to the interpolation routines.
'nearest', 'linear'
: If True, values outside of the domain are extrapolated (bounds_error=False, fill_value=None
); if False, values outside are set to 0.0 (bounds_error=False, fill_value=0.0
)'cubic'
: If True, values outside of the domain are extrapolated using nearest interpolation (mode='nearest'
); if False, values outside are set to 0.0 (mode='constant', cval=0.0
).'volume'
: Always uses nearest interpolation for points outside of the provided grid, independent of the choice ofextrapolate
.
- logbool, default: False
If True, the interpolation is carried out on a log10-scale; this corresponds to
10**interpolate(grid, np.log10(values), ...)
.- kwargsdict, optional
Will be forwarded to the corresponding interpolation algorithm, if they accept additional keywords. This can be used, e.g., to change the behaviour outlined in the parameter
extrapolate
.
- Returns
- values_xndarray
Values corresponding to the new grid.