pypeit.specutils.pypeit_loaders module

Data parsers for use with specutils.

Usage

  • To read a PypeIt spec1d file using specutils:

    from pypeit.specutils import SpectrumList
    spec = SpectrumList.read(spec1d_file)
    

    where spec1d_file is the relative or absolute path to a PypeIt spec1d file. You must always use a SpectrumList to read a spec1d file, even if the file only contains one spectrum. The spec1d loader provides PypeIt-specific options that enable you to specify the type of extraction used and whether or not to use the flux-calibrated spectrum; see pypeit.specutils.pypeit_loaders.pypeit_spec1d_loader(). By default, optimal extraction takes precedence over boxcar extraction, and flux-calibrated data take precedence over uncalibrated counts.

  • To read a PypeIt pypeit.onespec.OneSpec file:

    from pypeit.specutils import Spectrum1D
    spec = Spectrum1D.read(onespec_file)
    

    where onespec_file is the relative or absolute path to a PypeIt pypeit.onespec.OneSpec file. For these files, you can use either Spectrum1D or SpectrumList to read the file, but (by definition) the result of using SpectrumList will just be a list of one Spectrum1D object. The pypeit.onespec.OneSpec loader provides a PypeIt-specific option that enables you to select the uniform grid wavelength vector, instead of the contribution-weighted wavelengths; see pypeit.specutils.pypeit_loaders.pypeit_onespec_loader().

Note

Importing Spectrum1D and SpectrumList are shown as coming from the pypeit.specutils module, but the objects themselves are identical to the specutils objects. The reason they are imported from within PypeIt is that, under the hood, the import also “registers” the PypeIt-specific loaders with the relevant specutils module. This circumvents the need to place any pypeit specific code in a ~/.specutils directory (as recommended here) and keeps the import statement to one line. That is,

from pypeit.specutils import Spectrum1D

is really just shorthand for

from specutils import Spectrum1D
from pypeit.specutils import pypeit_loaders

Examples

In addition to the pypeit_show_1dspec GUI, these specutils loaders allow you to interact with your spectra using jdaviz. To do so, use the following lines in a jupyter notebook (you currently must do this from within a notebook):

from pypeit.specutils import SpectrumList
from jdaviz import Specviz

file = 'my_spec1d_file.fits'
spec = SpectrumList.read(file)

specviz = Specviz()
specviz.load_spectrum(spec)
specviz.show()

Version History

  • 2022-02-04: Initial Version (tbowers)

  • 2022-09-16: Correct an import error and add module docstring (tbowers)

  • 2023-03-09: Moved into the main pypeit repo and refactored (KBW)

pypeit.specutils.pypeit_loaders._identify_pypeit(*args, **kwargs)[source]

Check if a file is a PypeIt output file, in the most general sense.

This currently only checks if VERSPYP is in the primary header.

pypeit.specutils.pypeit_loaders.identify_pypeit_onespec(origin, *args, **kwargs)[source]

Check if a file is a PypeIt file that follows the pypeit.onespec.OneSpec datamodel.

In addition to checking if it is a PypeIt file (see _identify_pypeit()), this also checks that the datamodel classes are correct.

pypeit.specutils.pypeit_loaders.identify_pypeit_spec1d(origin, *args, **kwargs)[source]

Check if a file is a PypeIt spec1d file.

In addition to checking if it is a PypeIt file (see _identify_pypeit()), this also checks that the datamodel classes are correct.

pypeit.specutils.pypeit_loaders.pypeit_onespec_loader(filename, grid=False, **kwargs)[source]

Load a spectrum from a PypeIt OneSpec file into a Spectrum1D object.

Parameters:
  • filename (str) – The path to the FITS file

  • grid (bool, optional) – Use the uniform grid wavelengths, instead of the contribution-weighted center.

Returns:

spec – Spectrum in the PypeIt OneSpec file

Return type:

specutils.Spectrum1D

pypeit.specutils.pypeit_loaders.pypeit_spec1d_loader(filename, extract=None, fluxed=True, **kwargs)[source]

Load spectra from a PypeIt spec1d file into a SpectrumList.

Parameters:
  • filename (str) – The path to the FITS file

  • extract (str, optional) – The extraction used to produce the spectrum. Must be either None, 'BOX' (for a boxcar extraction), or 'OPT' for optimal extraction. If None, the optimal extraction will be returned, if it exists, otherwise the boxcar extraction will be returned.

  • fluxed (bool, optional) – If True, return the flux-calibrated spectrum, if it exists. If the flux calibration hasn’t been performed or fluxed=False, the spectrum is returned in counts.

Returns:

spec – Contains all spectra in the PypeIt spec1d file

Return type:

specutils.SpectrumList