Spectrum classes and functions#
- class specpolFlow.Spectrum(wl, specI, specV, specN1, specN2, specSig, header=None)#
Contains an observed spectrum, usually spectropolarimetric data.
Usually contains arrays:
wl - wavelengths
specI - Stokes I spectrum
specV - polarized spectrum, usually Stokes V
specN1 - the first polarimetric null spectrum
specN2 - the second polarimetric null spectrum
specSig - the formal uncertainties, which apply to the other spectra
- coadd(*args)#
coadd this spectrum with other spectra
Uses the the wavelength grid of this spectrum for the coadded spectrum. Other spectra are interpolated onto this spectrum’s wavelengths before coadding. Coadding here essentially averages spectra weighted by 1/sigma**2. This assumes the spectra are continuum normalized, and have reliable uncertainties.
Warning: regions with order overlap, or where wavelength goes backwards, will produce incorrect results with this routine. We strongly recommend using the merge_orders function before using this routine.
- Parameters:
args – other Spectrum objects (or a list or tuple of them) to coadd with this one
- Return type:
- concatenate(*args)#
Combine this Spectrum with other Spectrum objects, passed as arguments, concatenating them in order, into a new Spectrum object.
- Parameters:
args – other Spectrum objects (or a list or tuple of them) to concatenate with this one
- Return type:
- get_orders(ignoreGaps=False)#
Split an observed echelle spectrum into individual echelle orders.
This splits a concatenated spectrum into echelle orders, based on overlap (places where wavelength decreases), and optionally gaps in wavelength between orders.
- Parameters:
ignoreGaps – if True then regions separated by gaps in wavelength are treated as one order, otherwise gaps are used as order edges
- Returns:
a list of Spectrum objects, one for each identified order
- get_orders_in_range(wl1, wl2=None, ignoreGaps=False)#
Split an observed echelle spectrum into individual orders, and return orders that include the specified wavelength range.
This splits a concatenated spectrum into echelle orders, based on overlap (places where wavelength decreases), and optionally gaps in wavelength between orders. Returning the order, or orders, that include any part of the specified wavelength range (wl1 and wl2 can be identical).
- Parameters:
wl1 – the start of the wavelength range to include
wl2 – the end of the wavelength range to include (if not provided, orders including just the point in wavelength wl1 will be returned)
ignoreGaps – if True then regions separated by gaps in wavelength are treated as one order, otherwise gaps are used as order edges
- Returns:
a list of Spectrum objects, one for each relevant order
- individual_line(lambda0, lwidth)#
Select an individual line in the spectrum and return it as an LSD profile object
- Parameters:
lambda0 – wavelength of the line (same units as self.wl)
lwidth – distance from the line center, in wavelength, for the wavelength window used for the line profile. One element: same distance on each side of line center. Two elements: distance to the left and right of line center.
- Return type:
- merge_orders(mode='trim', midpoint=0.5)#
Simple merging of spectral orders, for echelle spectra.
The default mode ‘trim’ simply uses one order up to the midpoint of an overlap region, and then uses the next order past the midpoint. This is more robust against continuum normalization errors but doesn’t optimize the total signal-to-noise.
The mode ‘coadd’ attempts to coadd orders in the overlap region. It interpolates the second order onto the wavelength grid of the first order, then averages the spectra weighted by 1/sigma**2. This optimizes the total signal-to-noise but is vulnerable to continuum normalization errors at the edges of orders. This mode requires reliable uncertainties.
- Parameters:
mode – choice of ‘trim’, ‘coadd’
midpoint – for mode ‘trim’, the fraction of the way through an overlap region treated as the midpoint
- Return type:
- save(fname, saveHeader=True)#
Write the Spectrum into a text .s file in a LibreESPRIT style format. Optionally skip writing the two lines of header.
- Parameters:
saveHeader – optional flag, skip writing the header if False
- specpolFlow.read_spectrum(fname, trimBadPix=False, sortByWavelength=False)#
Read in the observed spectrum and save it.
This follows the .s format from Donati’s LibreESPRIT. Files can either have two lines of header or no header. This supports 6 column spectropolarimetric files (wavelength, I, V|Q|U, null1, null2, errors), and also 3 column spectra (wavelength, I, errors).
- Parameters:
fname – the name of the file to read.
trimBadPix – optionally remove the more obviously bad pixels if True. Removes pixels with negative flux or error bars of zero, pixels with flux within 3sigma of zero (large errors), and pixels with extremely large values.
sortByWavelength – reorder the points in the spectrum to always increase in wavelength, if set to True.
- Return type: