splicer

splicer.read_spectrum(filename, prefix, truncate_edge_left=None, truncate_edge_right=None)[source]

This is a fairly straightforward function to read the spectrum from a x1d FITS file.

Parameters:
filename (``str``):

Name of the *_x1d.fits file containing the spectrum.

prefix (``str``):

Path to the *_x1d.fits file containing the spectrum.

truncate_edge_left (``int``, optional):

Set the number of low-resolution pixels at the left edge of the detector where the spectra should be truncated. If None, then no truncation is applied. Default is None.

truncate_edge_right (``int``, optional):

Set the number of low-resolution pixels at the right edge of the detector where the spectra should be truncated. If None, then no truncation is applied. Default is None.

Returns:
spectrum (list):

List of all the orders contained in the Echelle spectrum and their respective fluxes.

splicer.find_overlap(spectrum)[source]

Find and return the overlapping sections of the Echelle spectrum.

Parameters:
spectrum (``list``):

List of dictionaries containing the orders of the Echelle spectrum. It should resemble the output of read_spectrum().

Returns:
unique_sections (list):

List containing the unique sections of the spectrum.

overlap_pair_sections (list):

List containing the overlapping pairs of the spectrum.

overlap_trio_sections (list):

List containing the overlapping trios of the spectrum.

splicer.merge_overlap(overlap_sections, acceptable_dq_flags=(0, 64, 128, 1024, 2048), weight='sensitivity')[source]

Merges overlapping spectral regions. The basic workflow of this function is to interpolate the sections into a common wavelength table and calculate the weighted mean flux for each wavelength bin. If the fluxes are inconsistent between each other, the code can use the flux with higher SNR instead of the mean. If there are still outlier fluxes (compared to neighboring pixels), the code uses the flux from the lower SNR section instead. Co-added (merged) pixels will have their DQ flag set to 32768 if they are the result of combining good pixels (according to the list of acceptable flags). Their DQ flag will be set to 65536 if the combined pixels do not have an acceptable DQ flag.

Parameters:
overlap_sections (``list``):

List of dictionaries containing the overlapping spectra of neighboring orders.

acceptable_dq_flags (array-like, optional):

Data-quality flags that are acceptable when co-adding overlapping spectra. The default values are (0, 64, 128, 1024, 2048), which correspond to: 0 = regular pixel, 64 = vignetted pixel, 128 = pixel in overscan region, 1024 = small blemish, 2048 = more than 30% of background pixels rejected by sigma-clipping in the data reduction.

weightstr, optional

Defines how to merge the overlapping sections. The options currently implemented are 'sensitivity' and 'snr' (inverse square of the uncertainties). Default is 'sensitivity'.

Returns:
overlap_merged (dict):

Dictionary containing the merged overlapping spectrum.

splicer.splice(unique_spectra_list, merged_pair_list, merged_trio_list)[source]

Concatenate the unique and the (merged) overlapping spectra.

Parameters:
unique_spectra_list (``list``):

List of unique spectra.

merged_pair_list (``list``):

List of merged overlapping pair spectra.

merged_trio_list (``list``):

List of merged overlapping trio spectra.

Returns:
spliced_wavelength (numpy.ndarray):

Array containing the wavelengths in the entire spectrum.

spliced_flux (numpy.ndarray):

Array containing the fluxes in the entire spectrum.

spliced_uncertainty (numpy.ndarray):

Array containing the flux uncertainties in the entire spectrum.

splicer.splice_pipeline(dataset, prefix='./', update_fits=False, output_file=None, weight='sensitivity', acceptable_dq_flags=(0, 64, 128, 1024, 2048))[source]

The main workhorse of the package. This pipeline performs all the steps necessary to merge overlapping spectral sections and splice them with the unique sections.

Parameters:
dataset (``str``):

String that identifies the dataset (example: 'oblh01040').

prefix (``str``):

Path to the *_x1d.fits file containing the spectrum.

update_fits (``bool``, optional):

Use carefully, since it can modify fits files permanently. Parameter that decides whether to update the *_x1d.fits file with a new extension containing the spliced spectrum.

output_file (``str`` or ``None``, optional):

String containing the location to save the output spectrum as an ascii file. If None, no output file is saved and the code returns an Astropy Table instead. Default is None.

weightstr, optional

Defines how to merge the overlapping sections. The options currently implemented are 'sensitivity' and 'snr' (inverse square of the uncertainties). Default is 'sensitivity'.

acceptable_dq_flags (array-like, optional):

Data-quality flags that are acceptable when co-adding overlapping spectra. The default values are (0, 64, 128, 1024, 2048), which correspond to: 0 = regular pixel, 64 = vignetted pixel, 128 = pixel in overscan region, 1024 = small blemish, 2048 = more than 30% of background pixels rejected by sigma-clipping in the data reduction.

Returns:
spliced_spectrum_table (astropy.Table object):

Astropy Table containing the spliced spectrum. Only returned if output_file is None.