grids
Functions
|
Interpolate unstructured data to a structured grid. |
|
Determines whether the x and y points form a structured grid. |
|
Module Contents
- grids.interpolate_unstructured(x, y, z, resolution=1000, method='linear')
Interpolate unstructured data to a structured grid.
This function takes unstructured (scattered) data points and interpolates them to a structured grid, handling NaN values in z and providing options for different interpolation methods. It creates a regular grid based on the given resolution and interpolates the z-values from the unstructured points onto this grid.
- Parameters:
x (array_like) – 1D array of x-coordinates.
y (array_like) – 1D array of y-coordinates.
z (array_like) – 1D array of z-values at each (x, y) point.
resolution (int, optional) – The number of points along each axis for the structured grid. Default is 1000.
method ({'linear', 'nearest', 'cubic'}, optional) –
The interpolation method to use. Default is ‘linear’. The methods supported are:
’linear’: Linear interpolation between points.
’nearest’: Nearest-neighbor interpolation.
’cubic’: Cubic interpolation, which may produce smoother results.
- Returns:
grid_x (ndarray) – 2D array representing the x-coordinates of the structured grid.
grid_y (ndarray) – 2D array representing the y-coordinates of the structured grid.
grid_z (ndarray) – 2D array of interpolated z-values at the grid points. NaNs may be present in regions where interpolation was not possible (e.g., due to large gaps in the data).
- grids.is_structured(x, y, tol=1e-05)
Determines whether the x and y points form a structured grid.
This function checks if the x and y coordinate arrays represent a structured grid, i.e., a grid with consistent spacing between points. The function supports 1D arrays (representing coordinates of a grid) and 2D arrays (representing the actual grid coordinates) of x and y.
- Parameters:
x (array_like) – A 1D or 2D array of x-coordinates. For example, this can be longitude or the x-coordinate in a Cartesian grid.
y (array_like) – A 1D or 2D array of y-coordinates. For example, this can be latitude or the y-coordinate in a Cartesian grid.
tol (float, optional) – Tolerance for floating-point comparison to account for numerical precision errors when checking spacing consistency. The default is 1e-5.
- Returns:
True if the data represents a structured grid, i.e., the spacing between consecutive points in both x and y is consistent. False otherwise.
- Return type:
bool
- grids.needs_cyclic_point(lons)