lezargus.library.old_stitch module#
Stitch spectra, images, and cubes together.
Stitching spectra, images, and cubes consistently, while keeping all of the pitfalls in check, is not trivial. We group these three stitching functions, and the required spin-off functions, here.
- lezargus.library.old_stitch.__spectra_rewrapped_interpolation_average_function(data: ndarray, uncertainty: ndarray, weights: ndarray, average_function: Callable[[ndarray, ndarray, ndarray], tuple[float, float]]) float [source]#
Average values, per the provided function, handing -inf.
- Parameters:
data (ndarray) – The data values which we are going to take an average of.
uncertainty (ndarray) – The uncertainty of the data.
weights (ndarray) – The weights for the average.
average_function (Callable) – The average function we are wrapping around. It must be able to handle uncertainties and weights. Namely, it must be of the form f(val, uncert, weight) = avg, uncert.
- Returns:
average_value (float) – The calculated average value.
average_uncertainty (float) – The uncertainty in the average value.
- lezargus.library.old_stitch.__spectra_rewrapped_interpolation_factory(base_wave: ndarray, base_data: ndarray, interp_factory: Callable[[ndarray, ndarray], Callable[[ndarray], ndarray]]) Callable[[ndarray], ndarray] [source]#
Generate data interpolators for stitching for 1D spectra.
This is an internal function and should not be used outside of it. We have small wrappers around the interpolation functions to suit our goals. Namely, cubic interpolation with -inf out-of-bounds; maximum uncertainty, and minimum weight.
- Parameters:
base_wave (ndarray) – The base or original wavelength of the data we are interpolating.
base_data (ndarray) – The base or original data we are interpolating.
interp_factory (Callable) – The interpolation function. Its function call must be of the form: interp(x, y) = z
- Returns:
rewrapped_interpolation – The wrapped interpolation function, built to handle -inf.
- Return type:
Callable
- lezargus.library.old_stitch.stitch_spectra_arrays(wavelength: list[numpy.ndarray], data: list[numpy.ndarray], uncertainty: list[numpy.ndarray] | None = None, weight: list[numpy.ndarray] | None = None, average_function: Callable[[ndarray, ndarray, ndarray], tuple[float, float]] = None) tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray] [source]#
Stitch and average different spectra together using a custom function.
This function takes any number of spectra, represented as parallel arrays of wavelength, spectral flux or data, and (optionally) weights, and combines them. We stitch them together; the formal method is described in [[TODO]]. In summary, we interpolate over overlapping regions, ignoring gaps if needed, and combine the data according to the average function.
Note, the average function provided is re-wrapped to properly handle NaNs. NaNs in the data are ignored and not used for any stitching. If NaNs are desired to be preserved and propagated, you will need to re-NaN values after the stitched spectra; see [[TODO; MAKE NAN PROPAGATE VERSION]].
- Parameters:
wavelength (list[ndarray]) – A list of wavelengths for stitching multiple spectra arrays together. Each entry in the list must have a corresponding entry in the data list.
data (list[ndarray]) – A list of spectra/data for stitching multiple spectra arrays together. Each entry in the list must have a corresponding entry in the wavelength list.
uncertainty (list[ndarray], default = None) – A list of the uncertainties in the data for stitching. Each entry in the list must have a corresponding entry in the wavelength and data list, or None. If the entry (or entire input) is None, we assume zero uncertainty for the corresponding input spectra arrays.
weight (list[ndarray], default = None) – A list of the weights in the data for stitching. Each entry in the list must have a corresponding entry in the wavelength and data list, or None. If the entry (or entire input) is None, we assume uniform weights for the corresponding input spectra arrays.
average_function (Callable, str, default = None) – The function used to average all of the spectra together. It must also be able to accept weights and propagate uncertainties. If None, we default to the weighted mean. Namely, it must be of the form f(val, uncert, weight) = avg, uncert.
note:: (..) – This function uses negative infinity internally for calculations as a flag value. Unexpected behavior might happen if the data contains negative infinity values for any of the input or as a hard return of the average function. (We handle inputs of negative infinity.) We suggest using NaN instead.
- Returns:
stitch_wavelength (ndarray) – The wavelength of the snitched spectra made from the input spectra.
stitch_spectra (ndarray) – The spectral data of the stitched spectra made from the input spectra.
stitch_uncertainty (ndarray) – The spectral uncertainty of the stitched spectra made from the input spectra.