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.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.get_smallest_gap(wavelength: ndarray) float [source]#
Find the smallest possible gap value for a wavelength array.
Gaps, which are important in gap-based interpolation, are where there is no data. Gaps are primarily a wavelength criterion: should data be missing for enough of a wavelength range, it is determined to be a gap. This function determines the smallest possible gap in the provided wavelength array for which a data-only gap may exist.
Basically, we find the maximum spacing in the wavelength array and assume that is it perfect and determine a gap from it.
- Parameters:
wavelength (ndarray) – The wavelength array which is used to find the small gap.
- Returns:
small_gap – The wavelength spacing for the small gap, in the same units as the provided wavelength array.
- Return type:
float
- 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
- lezargus.library.interpolate.spline_1d_interpolate_bounds_factory(x: ndarray, y: ndarray) Callable[[ndarray], ndarray] [source]#
Return a wrapper function around Scipy’s spline interpolations.
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.spline_1d_interpolate_bounds_gap_factory(x: ndarray, y: ndarray, gap_size: float | None = None) Callable[[ndarray], ndarray] [source]#
Wrap around Scipy’s spline 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.spline_1d_interpolate_factory(x: ndarray, y: ndarray) Callable[[ndarray], ndarray] [source]#
Return a wrapper function around Scipy’s spline 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.spline_1d_interpolate_gap_factory(x: ndarray, y: ndarray, gap_size: float | None = None) Callable[[ndarray], ndarray] [source]#
Wrap around Scipy’s spline 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