lezargus.library.interpolate module#

Interpolation routines, across both multi-dimensional and multi-mode.

We have many interpolation functions for a wide variety of use cases. We store all of them here. We usually derive the more specialty interpolation functions from a set of base functions.

lezargus.library.interpolate.cubic_1d_interpolate_bounds_factory(x: ndarray, y: ndarray) Callable[[ndarray], ndarray][source]#

Return a wrapper function around Scipy’s Cubic interpolation.

We ignore NaN values for interpolation.

Parameters:
  • x (ndarray) – The x data to interpolate over.

  • y (ndarray) – The y data to interpolate over.

Returns:

interpolate_function – The interpolation function of the data.

Return type:

Callable

lezargus.library.interpolate.cubic_1d_interpolate_bounds_gap_factory(x: ndarray, y: ndarray, gap_size: float | None = None) Callable[[ndarray], ndarray][source]#

Wrap around Scipy’s Cubic interpolation, accounting for gaps, bounds.

Regions which are considered to have a gap are not interpolated. Should a request for data be outside of the input domain, we return NaN. Should a request for data within a gap region be called, we return NaN. We also ignore NaN values for interpolation.

Parameters:
  • x (ndarray) – The x data to interpolate over.

  • y (ndarray) – The y data to interpolate over.

  • gap_size (float, default = None) – The maximum difference between two ordered x-coordinates before the region within the difference is considered to be a gap. If None, we assume that there are no gaps.

Returns:

interpolate_function – The interpolation function of the data.

Return type:

Callable

lezargus.library.interpolate.cubic_1d_interpolate_factory(x: ndarray, y: ndarray) Callable[[ndarray], ndarray][source]#

Return a wrapper function around Scipy’s Cubic interpolation.

We ignore NaN values for interpolation. Moreover, this function allows for extrapolation outside of the normal domain, though we still log it for debugging purposes.

Parameters:
  • x (ndarray) – The x data to interpolate over.

  • y (ndarray) – The y data to interpolate over.

Returns:

interpolate_function – The interpolation function of the data.

Return type:

Callable

lezargus.library.interpolate.cubic_1d_interpolate_gap_factory(x: ndarray, y: ndarray, gap_size: float | None = None) Callable[[ndarray], ndarray][source]#

Wrap around Scipy’s Cubic interpolation, accounting for gaps.

Regions which are considered to have a gap are not interpolated. Should a request for data within a gap region be called, we return NaN. We also ignore NaN values for interpolation.

Parameters:
  • x (ndarray) – The x data to interpolate over.

  • y (ndarray) – The y data to interpolate over.

  • gap_size (float, default = None) – The maximum difference between two ordered x-coordinates before the region within the difference is considered to be a gap. If None, we assume that there are no gaps.

Returns:

interpolate_function – The interpolation function of the data.

Return type:

Callable

lezargus.library.interpolate.custom_1d_interpolate_bounds_factory(interpolation: Callable[[ndarray, ndarray], Callable[[ndarray], ndarray]], x: ndarray, y: ndarray) Callable[[ndarray], ndarray][source]#

Wrap around a custom interpolation, accounting for bounds.

We interpolate, based on the provided interpolation function. However, for any interpolation which is outside of the original domain boundary of the input data, we return NaN instead.

Parameters:
  • interpolation (Callable) – The interpolation factory function which we are wrapping around.

  • x (ndarray) – The x data to interpolate over. NaN values are ignored.

  • y (ndarray) – The y data to interpolate over. NaN values are ignored.

Returns:

interpolate_function – The interpolation function of the data, with the bounds handled.

Return type:

Callable

lezargus.library.interpolate.custom_1d_interpolate_gap_factory(interpolation: Callable[[ndarray, ndarray], Callable[[ndarray], ndarray]], x: ndarray, y: ndarray, gap_size: float | None = None) Callable[[ndarray], ndarray][source]#

Wrap around a custom interpolation, accounting for gaps.

Regions which are considered to have a gap are not interpolated. Should a request for data within a gap region be called, we return NaN. We also ignore NaN values for interpolation.

Parameters:
  • interpolation (Callable) – The interpolation factory function which we are wrapping around.

  • x (ndarray) – The x data to interpolate over. NaN values are ignored.

  • y (ndarray) – The y data to interpolate over. NaN values are ignored.

  • gap_size (float, default = None) – The maximum difference between two ordered x-coordinates before the region within the difference is considered to be a gap. If None, we assume that there are no gaps.

Returns:

interpolate_function – The interpolation function of the data.

Return type:

Callable

lezargus.library.interpolate.nearest_neighbor_1d_interpolate_bounds_factory(x: ndarray, y: ndarray) Callable[[ndarray], ndarray][source]#

Wrap around Scipy’s interp1d interpolation.

This function exists so that in the event of the removal of Scipy’s interp1d function, we only need to fix it once here.

Parameters:
  • x (ndarray) – The x data to interpolate over.

  • y (ndarray) – The y data to interpolate over.

Returns:

interpolate_function – The interpolation function of the data.

Return type:

Callable

lezargus.library.interpolate.nearest_neighbor_1d_interpolate_factory(x: ndarray, y: ndarray) Callable[[ndarray], ndarray][source]#

Wrap around Scipy’s interp1d interpolation.

This function exists so that in the event of the removal of Scipy’s interp1d function, we only need to fix it once here.

Parameters:
  • x (ndarray) – The x data to interpolate over.

  • y (ndarray) – The y data to interpolate over.

Returns:

interpolate_function – The interpolation function of the data.

Return type:

Callable