elphick.geomet.utils.interp.mass_preserving_interp

elphick.geomet.utils.interp.mass_preserving_interp(df_intervals, interval_edges, include_original_edges=True, precision=None, mass_wet='mass_wet', mass_dry='mass_dry')[source]

Interpolate with zero mass loss using pchip

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:
  • df_intervals (DataFrame) – A pd.DataFrame with a single interval index, with mass, composition context.

  • interval_edges (Union[Iterable, int]) – The values of the new grid (interval edges). If an int, will up-sample by that factor, for example the value of 10 will automatically define edges that create 10 x the resolution (up-sampled).

  • include_original_edges (bool) – If True include the original index edges in the result

  • precision (Optional[int]) – Number of decimal places to round the index (edge) values.

  • mass_wet (str) – The wet mass column, not optional. Consider solve_mass_moisture prior to this call if needed.

  • mass_dry (str) – The dry mass column, not optional. Consider solve_mass_moisture prior to this call if needed.

Return type:

DataFrame

Returns: