earthkit.meteo.vertical.array.interpolate_monotonic

earthkit.meteo.vertical.array.interpolate_monotonic(data, coord, target_coord, interpolation='linear', aux_min_level_data=None, aux_min_level_coord=None, aux_max_level_data=None, aux_max_level_coord=None, vertical_dim=0)

Interpolate data between the same type of monotonic coordinate levels.

Parameters:
  • data (ArrayLike) – Data to be interpolated. The axis corresponding to the vertical coordinate is defined by the vertical_dim parameter. Must have at least two levels.

  • coord (ArrayLike) – Vertical coordinates related to data. Either must have the same shape as data or be a 1D array with length equal to the size of the number of levels in data. Must be monotonic (either sorted ascending or descending) along the vertical axis.

  • target_coord (ArrayLike) – Target coordinate levels to which data will be interpolated. It can be either a scalar or a 1D array of coordinate levels. Alternatively, it can be a multidimensional array with a vertical axis defined by vertical_dim. In this case the other axes/dimensions must match those of data. Must be the same type of coordinate as coord.

  • interpolation ({"linear", "log", "nearest"}, default "linear") –

    Interpolation mode. Possible values are:

    • ”linear”: linear interpolation in coordinate between the two nearest levels

    • ”log”: linear interpolation in logarithm of coordinate between the two nearest levels

    • ”nearest”: nearest level interpolation

  • aux_min_level_data (ArrayLike|None, optional) – Auxiliary data for interpolation to target levels below the minimum level of coord and above aux_min_level_coord. Can be a scalar or must have the same shape as a single level of data.

  • aux_min_level_coord (ArrayLike|None, optional) – Coordinates of aux_min_level_data. Can be a scalar or must have the same shape as a single level of data or coord. Must be the same type of coordinate as coord.

  • aux_max_level_data (ArrayLike|None, optional) – Auxiliary data for interpolation to target levels above the maximum level of coord and below aux_max_level_coord. Can be a scalar or must have the same shape as a single level of data.

  • aux_max_level_coord (ArrayLike|None, optional) – Coordinates of aux_max_level_data. Can be a scalar or must have the same shape as a single level of data or coord. Must be the same type of coordinate as coord.

  • vertical_dim (int) – Axis corresponding to the vertical coordinate in the input arrays and also in the output array. Default is 0 (first axis).

Returns:

Data interpolated to the target levels. The shape depends on the shape of target_coord. The axis corresponding to the vertical coordinate is defined by the vertical_dim parameter. When interpolation is not possible for a given target level (e.g., when the target level is outside the available level range), the corresponding output values are set to nan.

Return type:

ArrayLike

Raises:
  • ValueError – If data has less than two levels.

  • ValueError – If the shape of data and that of coord are not compatible.

Notes

  • The ordering of the input coordinate levels is not checked.

  • The units of coord and target_coord are assumed to be the same; no checks or conversions are performed.

Examples

  • /how-tos/interpolate_hybrid_to_pl.ipynb

  • /how-tos/interpolate_hybrid_to_hl.ipynb

  • /how-tos/interpolate_pl_to_hl.ipynb

  • /how-tos/interpolate_pl_to_pl.ipynb