interpolate
Interpolators for spatial data
- FirnCorr.interpolate.inpaint(xs: ndarray, ys: ndarray, zs: ndarray, N: int = 0, s0: int = 3, power: int = 2, epsilon: float = 2.0, **kwargs)[source]
Inpaint over missing data in a two-dimensional array using a penalized least-squares method based on discrete cosine transforms [5, 17]
- Parameters:
- xs: np.ndarray
x-coordinates
- ys: np.ndarray
y-coordinates
- zs: np.ndarray
Data with masked values
- N: int, default 0
Number of iterations (0 for nearest neighbors)
- s0: int, default 3
Smoothing factor
- power: int, default 2
Power for lambda function
- epsilon: float, default 2.0
Relaxation factor
- Returns:
- z0: np.ndarray
Data with inpainted (filled) values
- FirnCorr.interpolate.extrapolate(xs: ndarray, ys: ndarray, zs: ndarray, X: ndarray, Y: ndarray, fill_value: float = None, cutoff: int | float = inf, is_geographic: bool = True, **kwargs)[source]
Nearest-neighbor (NN) extrapolation of valid model data using KD-trees
- Parameters:
- xs: np.ndarray
x-coordinates of firn model
- ys: np.ndarray
y-coordinates of firn model
- zs: np.ndarray
Firn model data
- X: np.ndarray
Output x-coordinates
- Y: np.ndarray
Output y-coordinates
- fill_value: float, default np.nan
Invalid value
- dtype: np.dtype, default np.float64
Output data type
- cutoff: float, default np.inf
Return only neighbors within distance (kilometers)
Set to
np.infto extrapolate for all points- is_geographic: bool, default True
Input grid is in geographic coordinates
- Returns:
- data: xr.DataArray
Interpolated data
- FirnCorr.interpolate._to_cartesian(x: ndarray, y: ndarray, is_geographic: bool = True)[source]
Convert input coordinates to an array of points in a Cartesian coordinate system
- Parameters:
- x: np.ndarray
x-coordinates to be converted
- y: np.ndarray
y-coordinates to be converted
- is_geographic: bool, default True
Coordinates are geographic
- Returns:
- points: np.ndarray
Output points in Cartesian coordinates
- FirnCorr.interpolate._build_tree(points: ndarray, **kwargs)[source]
Build a KD-tree to search for the nearest-neighbors (NN)
- Parameters:
- points: np.ndarray
Input points in Cartesian coordinates
- kwargs: dict
Keyword arguments for
scipy.spatial.cKDTree
- Returns:
- tree: scipy.spatial.cKDTree
KD-tree from input points
- FirnCorr.interpolate._nearest_neighbors(tree: cKDTree, points: ndarray, flattened: ndarray, cutoff: int | float = inf, fill_value: float = None, **kwargs)[source]
Nearest-neighbor (NN) extrapolation of valid model data using KD-trees
- Parameters:
- tree: scipy.spatial.cKDTree
KD-tree of valid points for nearest-neighbor extrapolation
- points: np.ndarray
Output points in Cartesian coordinates
- flattened: np.ndarray
Valid data array to be extrapolated
- cutoff: float, default np.inf
Return only neighbors within distance (kilometers)
- fill_value: float, default None
Invalid value
- dtype: np.dtype, default from input data
Output data type
- Returns:
- data: xr.DataArray
Extrapolated data