Converters#
- specpolFlow.converters.espadons(flist, flistout=None, writeSpecHeader=False)#
Convert a list of .fits files in the CADC ESPaDOnS format into text .s files.
The code provides two files in .s format:
The UPENA normalized spectrum (n.s), with automated radial velocity corrections from the telluric lines.
The UPENA unnormalized spectrum (u.s), using the automated radial velocity correction from the normalized spectrum.
This is done starting from the unnormalized spectrum without the automated radial velocity correction, to which we apply the radial velocity correction determined from the normalized spectrum. The reason behind this is that the UPENA automated radial velocity determination performed on unnormalized spectra does not produce consistently reliable results. The content of the fits header is also saved in a .out text file. If flistout=None (default), the files are written at the same path as the fits-format data, with the ‘.fits’ stripped, and ‘n.s’ and ‘u.s’ appended to the filename root. If flistout is a list of paths ending with a rootname, the files will be saved at that path with that rootname, and ‘n.s’ and ‘u.s’ appended to the filename root.
- Parameters:
flist – (list of strings) a list of ESPaDOnS filenames
flistout – (list of strings) optional, list of output file rootnames
writeSpecHeader – Flag for whether to write two lines of header in the .s text file (True = include header)
- specpolFlow.converters.spirou(flist, flistout=None, ftype=None, nanTreatment='replace', removeSegmentSize=200, allowGapSize=3, saveFitsHeader=True, writeSpecHeader=False)#
Convert a .fits, file or list of files, from SPIRou APERO formats into text .s files.
This supports intensity spectrum e.fits files, telluric corrected intensity spectrum t.fits files, and polarized spectrum p.fits files. This calls the spirou_e, spirou_t, and spirou_p functions.
The .fits files usually contain nan values for pixels where the telluric correction failed, or where the spectrum extraction failed. This function provides options: to remove those pixels (and optionally remove some of the small fragments of spectrum that get left behind), to replace those pixels with placeholder values, or to keep the nan values. (Keeping the nan values will cause problems for other SpecpolFlow functions!)
For e.fits and t.fits files: this function estimates uncertainties on the spectrum simply as sqrt(N), applies a blaze correction to the spectrum, and applies a barycentric velocity correction.
For p.fits files: this function converts the input polarized spectrum from being normalized by the intensity spectrum (e.g. V/I) to being normalized by the continuum (e.g. V/Ic, like I/Ic).
- Parameters:
flist – .fits file name or list filenames (a string or list of strings)
flistout – optional, an output filename or list of filenames. If this is not provided output names will be generated from the input filenames, replacing .fits with .s
ftype – the type of input .fits file to process. ‘e’ is e.fits files, with intensity spectra, still with separate spectral orders. ‘t’ is t.fits files, with telluric corrected spectra, still with separate spectral orders. ‘p’ is p.fits files, with polarized spectra. If this is not provided, the file type will be estimated from the input filename, but the files must end with e.fits, t.fits, or p.fits.
nanTreatment – Flag for how to deal with nan values in the input file, can be: ‘remove’, ‘replace’, ‘keep’. nan values can be from places where the spectrum extraction failed or the telluric correction was too uncertain. ‘remove’ deletes pixels with nans. ‘replace’ replaces the nan values with 0, and sets the uncertainties to 100. ‘keep’ retains the nan values in the spectrum.
removeSegmentSize – If nanTreatment = ‘remove’, this can leave a lot of little fragments of spectrum in the output, mostly in regions with strong telluric lines. Fragments that are shorter than removeSegmentSize pixels will be removed from the output. (Set this to 0 to keep all the spectrum)
allowGapSize – If nanTreatment = ‘remove’, and small fragments of spectrum are also being removed, there can be small gaps of a few pixels in the spectrum. Setting allowGapSize ignores gaps smaller than this value when calculating the size of segments for removeSegmentSize.
saveFitsHeader – Flag for whether to save the .fits header information to a text file, named using the output filename .out (True = save to file).
writeSpecHeader – Flag for whether to write two lines of header in the .s text file (True = include header)
- Returns:
list of Spectrum objects
- specpolFlow.converters.spirou_p(fname, outname=None, nanTreatment='replace', removeSegmentSize=200, allowGapSize=3, saveFitsHeader=True, writeSpecHeader=False)#
Function to read in a SPIRou p.fits file containing a polarized spectrum, save it to a .s file, and return a Spectrum object
The p.fits files usually contain the polarization spectrum normalized by the full Stokes I spectrum, not the continuum of Stokes I (e.g. V/I not V/Ic). This function converts the polarized spectrum to be normalized by the continuum (outputting e.g. V/Ic).
The p.fits files usually contain nan values for pixels where the telluric correction failed, or where the spectrum extraction failed. This function provides options: to remove those pixels (and optionally remove some of the small fragments of spectrum that get left behind), to replace those pixels with placeholder values, or to keep the nan values. (Keeping the nan values will cause problems for other SpecpolFlow functions!) APERO p.fits files also have nan values for wavelengths, so in the ‘replace’ mode wavelengths in nan regions are only estimates, based on the surrounding wavelength values.
- Parameters:
fname – name of the .fits file to read
outname – name of the file to save the spectrum to. If not provided the function will default to using the input fname and replacing .fits with .s
nanTreatment – Flag for how to deal with nan values in the input file, can be: ‘remove’, ‘replace’, ‘keep’. nan values can be from places where the spectrum extraction failed or the telluric correction was too uncertain. ‘remove’ deletes pixels with nans. ‘replace’ replaces the nan values with 0, and sets the uncertainties to 100. ‘keep’ retains the nan values in the spectrum.
removeSegmentSize – If nanTreatment = ‘remove’, this can leave a lot of little fragments of spectrum in the output, mostly in regions with strong telluric lines. Fragments that are shorter than removeSegmentSize pixels will be removed from the output. (Set this to 0 to keep all the spectrum)
allowGapSize – If nanTreatment = ‘remove’, and small fragments of spectrum are also being removed, there can be small gaps of a few pixels in the spectrum. Setting allowGapSize ignores gaps smaller than this value when calculating the size of segments for removeSegmentSize.
saveFitsHeader – Flag for whether to save the .fits header information to a text file, named using the output filename .out (True = save to file).
writeSpecHeader – Flag for whether to write two lines of header in the .s text file (True = include header)
- Return type:
- specpolFlow.converters.spirou_e(fname, outname=None, nanTreatment='replace', removeSegmentSize=100, allowGapSize=3, bervCorr=True, saveFitsHeader=True, writeSpecHeader=False)#
Function to read in a SPIRou e.fits file containing an intensity spectrum, save it to a .s file, and return a Spectrum object
This function estimates uncertainties on the spectrum simply as the square root of the flux, then applies a blaze correction to the spectrum.
The e.fits files usually contain nan values for pixels where the spectrum extraction failed (most commonly near order edges where the flux is low). This function provides options: to remove those pixels (and optionally remove some of the small fragments of spectrum that get left behind), to replace those pixels with placeholder values, or to keep the nan values. (Keeping the nan values will cause problems for other SpecpolFlow functions!)
- Parameters:
fname – name of the .fits file to read
outname – name of the file to save the spectrum to. If not provided the function will default to using the input fname and replacing .fits with .s
nanTreatment – Flag for how to deal with nan values in the input file, can be: ‘remove’, ‘replace’, ‘keep’. ‘remove’ deletes pixels with any nans. ‘replace’ replaces the nan values with 0, and sets the uncertainties to 100. ‘keep’ retains the nan values in the spectrum.
removeSegmentSize – If nanTreatment=’remove’, this can leave little fragments of spectrum in the output. Fragments that are shorter than removeSegmentSize pixels will be removed from the output. (Set this to 0 to keep all the spectrum)
allowGapSize – If nanTreatment = ‘remove’, and small fragments of spectrum are also being removed, there can be small gaps of a few pixels in the spectrum. Setting allowGapSize ignores gaps smaller than this value when calculating the size of segments for removeSegmentSize.
bervCorr – Flag for whether to apply a barycentric radial velocity correction to the spectrum (using the BERV from the fits header, True = apply correction). Without this correction the observation is in the observer’s rest frame, rather than the solar system barycentric rest frame.
saveFitsHeader – Flag for whether to save the .fits header information to a text file, named using the output filename .out (True = save to file).
writeSpecHeader – Flag for whether to write two lines of header in the .s text file (True = include header)
- Return type:
- specpolFlow.converters.spirou_t(fname, outname=None, nanTreatment='replace', removeSegmentSize=200, allowGapSize=3, bervCorr=True, saveFitsHeader=True, writeSpecHeader=False)#
Function to read in a SPIRou t.fits file containing a telluric corrected intensity spectrum, save it to a .s file, and return a Spectrum object
This function estimates uncertainties on the spectrum simply as the square root of the flux, then applies a blaze correction to the spectrum.
The t.fits files usually contain the telluric corrected spectrum and a copy of the telluric line spectrum removed from the original observation. This function saves both to two different files (with the telluric spectrum in [outname].telluric).
The t.fits files usually contain nan values for pixels where the telluric correction failed, or where the spectrum extraction failed. This function provides options: to remove those pixels (and optionally remove some of the small fragments of spectrum that get left behind), to replace those pixels with placeholder values, or to keep the nan values. (Keeping the nan values will cause problems for other SpecpolFlow functions!)
- Parameters:
fname – name of the .fits file to read
outname – name of the file to save the spectrum to. If not provided the function will default to using the input fname and replacing .fits with .s
nanTreatment – Flag for how to deal with nan values in the input file, can be: ‘remove’, ‘replace’, ‘keep’. nan values can be from bad pixels or from places where the telluric correction was too uncertain. ‘remove’ deletes pixels with any nans. ‘replace’ replaces the nan values with 0, and sets the uncertainties to 100. ‘keep’ retains the nan values in the spectrum.
removeSegmentSize – If nanTreatment = ‘remove’, this can leave a lot of little fragments of spectrum in the output, mostly in regions with strong telluric lines. Fragments that are shorter than removeSegmentSize pixels will be removed from the output. (Set this to 0 to keep all the spectrum)
allowGapSize – If nanTreatment = ‘remove’, and small fragments of spectrum are also being removed, there can be small gaps of a few pixels in the spectrum. Setting allowGapSize ignores gaps smaller than this value when calculating the size of segments for removeSegmentSize.
bervCorr – Flag for whether to apply a barycentric radial velocity correction to the spectrum (using the BERV from the fits header, True = apply correction). Without this correction the observation is in the observer’s rest frame, rather than the solar system barycentric rest frame.
saveFitsHeader – Flag for whether to save the .fits header information to a text file, named using the output filename .out (True = save to file).
writeSpecHeader – Flag for whether to write two lines of header in the .s text file (True = include header)
- Return type: