WavelengthSolution1D

class specreduce.wavesol1d.WavelengthSolution1D(p2w: None | CompoundModel, bounds_pix: tuple[int, int], unit: Unit)[source]

Bases: object

Class defining a one-dimensional wavelength solution.

This class manages the mapping between pixel positions and wavelength values in a 1D spectrum, supporting both forward and reverse transformations. It provides methods for resampling spectra in the pixel-to-wavelength space while conserving flux, and integrates with GWCS for coordinate transformations.

Initializes an object with pixel-to-wavelength transformation, pixel bounds, and measurement unit. Also, converts the unit to its LaTeX string representation.

Parameters:
p2w

The pixel-to-wavelength transformation model. If None, no transformation will be set.

bounds_pix

The lower and upper pixel bounds defining the range of the spectrum.

unit

The wavelength unit.

Attributes Summary

gwcs

GWCS object defining the mapping between pixel and spectral coordinate frames.

p2w

Pixel-to-wavelength transformation.

p2w_dldx

Partial derivative of the pixel-to-wavelength transformation, (d lambda) / (d pix).

w2p

Wavelength-to-pixel transformation.

Methods Summary

pix_to_wav(pix)

Map pixel values into wavelength values.

resample(spectrum[, nbins, wlbounds, bin_edges])

Bin the given pixel-space 1D spectrum to a wavelength space conserving the flux.

wav_to_pix(wav)

Map wavelength values into pixel values.

Attributes Documentation

gwcs[source]

GWCS object defining the mapping between pixel and spectral coordinate frames.

p2w

Pixel-to-wavelength transformation.

p2w_dldx[source]

Partial derivative of the pixel-to-wavelength transformation, (d lambda) / (d pix).

w2p[source]

Wavelength-to-pixel transformation.

Methods Documentation

pix_to_wav(pix: float | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) float | ndarray[tuple[Any, ...], dtype[_ScalarT]] | MaskedArray[source]

Map pixel values into wavelength values.

Parameters:
pix

The pixel value(s) to be transformed into wavelength value(s).

Returns:
Transformed wavelength value(s) corresponding to the input pixel value(s).
resample(spectrum: Spectrum, nbins: int | None = None, wlbounds: tuple[float, float] | None = None, bin_edges: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str] | None = None) Spectrum[source]

Bin the given pixel-space 1D spectrum to a wavelength space conserving the flux.

This method bins a pixel-space spectrum to a wavelength space using the computed pixel-to-wavelength and wavelength-to-pixel transformations and their derivatives with respect to the spectral axis. The binning is exact and conserves the integrated flux.

Parameters:
spectrum

A Spectrum instance containing the flux to be resampled over the wavelength space.

nbins

The number of bins for resampling. If not provided, it defaults to the size of the input spectrum.

wlbounds

A tuple specifying the starting and ending wavelengths for resampling. If not provided, the wavelength bounds are inferred from the object’s methods and the entire flux array is used.

bin_edges

Explicit bin edges in the wavelength space. Should be an 1D array-like [e_0, e_1, …, e_n] with n = nbins + 1. The bins are created as [[e_0, e_1], [e_1, e_2], …, [e_n-1, n]]. If provided, nbins and wlbounds are ignored.

Returns:
1D spectrum binned to the specified wavelength bins.
wav_to_pix(wav: float | Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) float | ndarray[tuple[Any, ...], dtype[_ScalarT]] | MaskedArray[source]

Map wavelength values into pixel values.

Parameters:
wav

The wavelength value(s) to be converted into pixel value(s).

Returns:
The corresponding pixel value(s) for the input wavelength(s).