sup3r.utilities.interpolation.Interpolator

sup3r.utilities.interpolation.Interpolator#

class Interpolator[source]#

Bases: object

Class for handling pressure and height interpolation

Methods

get_level_masks(lev_array, level)

Get the masks used to select closest surrounding levels in the lev_array to requested interpolation level.

interp_to_level(lev_array, var_array, level)

Interpolate var_array to the given level.

classmethod get_level_masks(lev_array, level)[source]#

Get the masks used to select closest surrounding levels in the lev_array to requested interpolation level.

Parameters:
  • var_array (Union[np.ndarray, da.core.Array]) – Array of variable data, for example u-wind in a 4D array of shape (lat, lon, time, level)

  • lev_array (Union[np.ndarray, da.core.Array]) – Height or pressure values for the corresponding entries in var_array, in the same shape as var_array. If this is height and the requested levels are hub heights above surface, lev_array should be the geopotential height corresponding to every var_array index relative to the surface elevation (subtract the elevation at the surface from the geopotential height)

  • level (float) – level to interpolate to (e.g. final desired hub height above surface elevation)

Returns:

  • mask1 (Union[np.ndarray, da.core.Array]) – Array of bools selecting the entries with the closest levels to the one requested. (lat, lon, time, level)

  • mask2 (Union[np.ndarray, da.core.Array]) – Array of bools selecting the entries with the second closest levels to the one requested. (lat, lon, time, level)

classmethod interp_to_level(lev_array: ndarray | Array, var_array: ndarray | Array, level, interp_kwargs=None)[source]#

Interpolate var_array to the given level.

Parameters:
  • var_array (xr.DataArray) – Array of variable data, for example u-wind in a 4D array of shape (lat, lon, time, level)

  • lev_array (xr.DataArray) – Height or pressure values for the corresponding entries in var_array, in the same shape as var_array. If this is height and the requested levels are hub heights above surface, lev_array should be the geopotential height corresponding to every var_array index relative to the surface elevation (subtract the elevation at the surface from the geopotential height)

  • level (float) – level or levels to interpolate to (e.g. final desired hub height above surface elevation)

  • interp_kwargs (dict | None) – Dictionary of kwargs for level interpolation. Can include “method” and “run_level_check” keys

Returns:

out (Union[np.ndarray, da.core.Array]) – Interpolated var_array (lat, lon, time)