mpas_tools.mesh.interpolation.interp_bilin
- mpas_tools.mesh.interpolation.interp_bilin(x, y, field, xCell, yCell)[source]
Perform bilinear interpolation of
field
on a regular (tensor) grid to cell centers on an MPAS mesh.This function is designed to be much faster and more memory-efficient than using scipy.interpolate routines for large MPAS meshes.
- Parameters:
x (ndarray) – 1D array of x coordinates of the input grid (length n). For geographic data, this is typically longitude in degrees.
y (ndarray) – 1D array of y coordinates of the input grid (length m). For geographic data, this is typically latitude in degrees.
field (ndarray) – 2D array of field values of shape (m, n), defined on the (y, x) grid.
xCell (ndarray) – 1D array of x coordinates of MPAS cell centers (same units as x).
yCell (ndarray) – 1D array of y coordinates of MPAS cell centers (same units as y).
- Returns:
mpasField (ndarray) – 1D array of interpolated field values at MPAS cell centers.
Notes
All xCell and yCell values must be within the bounds of x and y.
No extrapolation is performed.
For longitude/latitude grids, it is recommended to use degrees to avoid round-off issues at the poles or dateline.
This function is intended for use cases where the input grid is regular (tensor product), not scattered points.
Examples
>>> import numpy as np >>> from mpas_tools.mesh.interpolation import interp_bilin >>> x = np.linspace(-180, 180, 361) >>> y = np.linspace(-90, 90, 181) >>> field = np.random.rand(181, 361) >>> xCell = np.array([0.0, 45.0]) >>> yCell = np.array([0.0, 45.0]) >>> values = interp_bilin(x, y, field, xCell, yCell)