elphick.mass_composition.utils.interp.interp_monotonic

elphick.mass_composition.utils.interp.interp_monotonic(ds, coords, include_original_coords=True)[source]

Interpolate with zero mass loss using pchip

The pchip interpolation cannot be used via the xr.Dataset.interp method directly due to an error. This interpolates data_vars independently for a single dimension (coord) at a time.

The function will: - convert from relative composition (%) to absolute (mass) - convert the index from interval to a float representing the right edge of the interval - cumsum to provide monotonic increasing data - interpolate with a pchip spline to preserve mass - diff to recover the original fractional data - reconstruct the interval index from the right edges - convert from absolute to relative composition

Parameters:
  • ds (Dataset) – The xarray Dataset with relative composition context

  • include_original_coords (bool) – If True include the original coordinates in the result

  • coords (Dict) – A dictionary of coordinates mapped to the interpolated values.

Return type:

Dataset

Returns: