paleos.interpolate module#

This module has a selection of interpolation algorithms. Core samples are usually irregularly sampled in age, meaning that interpolation of some form is required to put any age indexed data on regular sampling.

The following techniques are provided here

  • linear interpolation via scipy

  • cubic interpolation via scipy

  • spline interpolation via scipy

  • lowess from statsmodels, which is a local least squares with a tricubic weighting. Multiple iterations are performed here for robustness from outliers

  • lowess from a custom function using a tricubic weight function

  • loess from a custom function using a uniform weight function, meaning local least squares without any weighting

paleos.interpolate.tricubic_weights(x)#

Tricubic weights for external LOWESS

paleos.interpolate.uniform_weights(x)#

Uniform weights for external LOESS

class paleos.interpolate.Loess(xx, yy, degree=1, weight_fnc: Optional[Callable] = None)#

Bases: object

Local linear regression

This code was minimally modified from https://github.com/joaofig/pyloess to allow support for other weighting functions, in this case uniform weights or local linear regression (unweighted).

Copyright (c) 2019 João Paulo Figueira

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

static normalize_array(array)#
static get_min_range(distances, window)#
get_weights(distances, min_range)#
normalize_x(value)#
denormalize_y(value)#
estimate(x, window, use_matrix=False, degree=1)#
paleos.interpolate.get_output_index(series: Series, step: float = 0.1) ndarray#

Get output index given the index range in the series

Parameters:
  • series (pd.Series) – pandas series

  • step (float, optional) – The step to use. Defaults to 0.1.

Returns:

The output index

Return type:

np.ndarray

paleos.interpolate.linear_interpolate(series: Series, new_idxs: ndarray) Series#

Interpolate values from series to new index using linear interpolation

Parameters:
  • series (pd.Series) – pandas series to interpolate

  • new_idxs (np.ndarray) – The new index to interpolate to

Returns:

Interpolated pandas series

Return type:

pd.Series

paleos.interpolate.cubic_interpolate(series: Series, new_idxs: ndarray) Series#

Interpolate values from series to new index using cubic interpolation

Parameters:
  • series (pd.Series) – pandas series to interpolate

  • new_idxs (np.ndarray) – The new index to interpolate to

Returns:

Interpolated pandas series

Return type:

pd.Series

paleos.interpolate.spline_interpolate(series: Series, new_idxs: ndarray, s: int = 0) Series#

Interpolate values from series to new index using spline interpolation.

With s(moothing) = 0, this should match cubic interpolation

Parameters:
  • series (pd.Series) – pandas series to interpolate

  • new_idxs (np.ndarray) – The new index to interpolate to

Returns:

Interpolated pandas series

Return type:

pd.Series

paleos.interpolate.lowess_sm_interpolate(series: Series, new_idxs: ndarray, smoothing_factor: float, iterations: int = 3) Series#

Perform local weighted least squares for interpolation

This uses statsmodels internally

Parameters:
  • series (pd.Series) – pandas series to interpolate

  • new_idxs (np.ndarray) – The new index to interpolate to

  • smoothing_factor (float) – The smoothing factor

  • iterations (int, optional) – [description]. Number of iterations to help robustness to 3.

Returns:

Interpolated pandas series

Return type:

pd.Series

paleos.interpolate.lowess_ext_interpolate(series: Series, new_idxs: ndarray, smoothing_factor: float, use_matrix: bool = True, degree: int = 1) Series#

Perform local weighted least squares for interpolation

This uses custom code internally

Parameters:
  • series (pd.Series) – pandas series to interpolate

  • new_idxs (np.ndarray) – The new index to interpolate to

  • smoothing_factor (float) – The smoothing factor

  • use_matrix (bool, optional) – Use matrix algebra to compute. Defaults to True.

  • degree (int, optional) – Polynomical degree, 1 means linear fit. Defaults to 1.

Returns:

Interpolated pandas series

Return type:

pd.Series

paleos.interpolate.loess_ext_interpolate(series: Series, new_idxs: ndarray, smoothing_factor: float, use_matrix: bool = True, degree: int = 1) Series#

Perform local least squares for interpolation

This uses custom code internally

Parameters:
  • series (pd.Series) – pandas series to interpolate

  • new_idxs (np.ndarray) – The new index to interpolate to

  • smoothing_factor (float) – The smoothing factor

  • use_matrix (bool, optional) – Use matrix algebra to compute. Defaults to True.

  • degree (int, optional) – Polynomical degree, 1 means linear fit. Defaults to 1.

Returns:

Interpolated pandas series

Return type:

pd.Series