pyissm.data.interp

Tools to interpolate data to/from ISSM model mesh.

This module contains various interpolation functions that can be used in conjunction with ISSM models.

Functions

points_to_mesh(data_x, data_y, data_values, ...)

Interpolate scattered points onto mesh node coordinates using scipy.

xr_to_mesh(data, var_name, mesh_x, mesh_y[, ...])

Interpolate a variable from an xarray dataset onto mesh nodes.

pyissm.data.interp.points_to_mesh(data_x, data_y, data_values, mesh_x, mesh_y, default_value=nan, interpolation_type='linear')

Interpolate scattered points onto mesh node coordinates using scipy.

Parameters:
  • data_x (array_like) – X-coordinates of the scattered data points. Can be 1D or 2D; if 2D it will be flattened.

  • data_y (array_like) – Y-coordinates of the scattered data points. Must have the same shape as data_x.

  • data_values (array_like) – Values at the scattered data points. Must have the same shape as data_x.

  • mesh_x (array_like) – X-coordinates of mesh nodes. 1D array.

  • mesh_y (array_like) – Y-coordinates of mesh nodes. 1D array.

  • default_value (float, optional) – Value used to fill points outside the convex hull of the input data. Default is np.nan.

  • interpolation_type (str, optional) – Interpolation method passed to scipy.interpolate.griddata. Supported options: ‘linear’, ‘nearest’, ‘cubic’. Default is ‘linear’.

Returns:

1D array of interpolated values at the mesh nodes (shape equals mesh_x/mesh_y). Points outside the convex hull of the input data are assigned default_value.

Return type:

ndarray

Raises:

ValueError – If interpolation_type is not supported by scipy, if input shapes are inconsistent, or if no valid data points remain after removing NaNs/Infs.

pyissm.data.interp.xr_to_mesh(data, var_name, mesh_x, mesh_y, x_var='x', y_var='y', default_value=nan, interpolation_type='bilinear', issm_wrapper=True, crop_to_mesh=True, crop_buffer=5000, fill_nan=False, fill_nan_interpolation_type='nearest')

Interpolate a variable from an xarray dataset onto mesh nodes.

Assumes rectilinear (structured) grid in the xarray dataset.

Parameters:
  • data (str or xr.Dataset) – Path to a netCDF file or an xarray Dataset containing the gridded data.

  • var_name (str) – Name of the variable to interpolate.

  • mesh_x (ndarray) – X-coordinates of mesh nodes.

  • mesh_y (ndarray) – Y-coordinates of mesh nodes.

  • x_var (str, optional) – Name of the x-coordinate variable in the dataset. Default is ‘x’.

  • y_var (str, optional) – Name of the y-coordinate variable in the dataset. Default is ‘y’.

  • default_value (float, optional) – Value to assign to points outside the grid domain. Default is np.nan.

  • interpolation_type (str, optional) – Type of interpolation method. For ISSM wrapper: ‘bilinear’, ‘nearest’, etc. For scipy: ‘linear’, ‘nearest’, ‘slinear’, ‘cubic’, ‘quintic’, ‘pchip’. Default is ‘bilinear’.

  • issm_wrapper (bool, optional) – If True, use ISSM wrapper functions for interpolation. If False, use scipy. Default is True.

  • crop_to_mesh (bool, optional) – If True, the xarraxy Dataset is cropped to the extent of the mesh prior to interpolation. Default is True.

  • crop_buffer (float or int, optional) – Buffer distance (m) applied to mesh bounding box to prevent edge effects. Default is 5000 m

  • fill_nan (bool, optional) – If True, any remaining NaN values (after the initial interpolation) are filled using the fill_nan_interpolation_type interpolation method. Default is False.

  • fill_nan_interpolation_type (str, optional) – Interpolation type used to fill NaN vaules when fill_nan is True. Default is ‘nearest’.

Returns:

Interpolated variable values at mesh nodes.

Return type:

ndarray

Raises:
  • TypeError – If data is neither a file path nor an xarray Dataset.

  • ValueError – If variable is not 2D, coordinates are inconsistent, or grid is not rectilinear.

  • ImportError – If issm_wrapper is True but ISSM wrappers are not installed.