How to read spectral data from this FITS file?

I am a new user to SpecUtils and I am simply attempting to read in spectral data from a FITS file and plot the spectrum, just like on the first page of SpecUtils.

My code is identical to the first page of SpecUtils and is as follows:

from astropy.io import fits
from astropy import units as u
import numpy as np
from matplotlib import pyplot as plt
from astropy.visualization import quantity_support
quantity_support()  # for getting units on the axes below  

f = fits.open('GIRAF.2021-02-14T01:00:34.723.fits')  
# The spectrum is in the second HDU of this file.
specdata = f[0].data 
f.close() 

from specutils import Spectrum1D
lamb = 10**specdata['loglam'] * u.AA 
flux = specdata['flux'] * 10**-17 * u.Unit('erg cm-2 s-1 AA-1') 
spec = Spectrum1D(spectral_axis=lamb, flux=flux)

However, it seems loglam and flux are no acceptablr identifiers from this file

IndexError                                Traceback (most recent call last)
Input In [22], in <cell line: 2>()
      1 from specutils import Spectrum1D
----> 2 lamb = 10**specdata['loglam'] * u.AA 
      3 flux = specdata['flux'] * 10**-17 * u.Unit('erg cm-2 s-1 AA-1') 
      4 spec = Spectrum1D(spectral_axis=lamb, flux=flux)

IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices

Does anyone have any advice on how I can figure out what the headers are in my file, how to read them in, and then ultimately plot the spectral data? Here is the link to the FITS file: link

I don’t know anything about FITS files, but you can figure out some things using:

  • dir(f)
  • type(f)
  • len(f)
  • f[0].header shows a lot of headers from the file
>>> f.info()
Filename: GIRAF.2021-02-14T01 00 34.723.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU     504   (2148, 4096)   uint16
>>> type(specdata)
<class 'numpy.ndarray'>
>>> specdata.shape
(4096, 2148)
>>> specdata.dtype
dtype('uint16')

It seems in only loads one 2D array.

Also this other way to load the file prints some information:

>>> from specutils import Spectrum1D
>>> spec1d = Spectrum1D.read("GIRAF.2021-02-14T01:00:34.723.fits")
WARNING: UnitsWarning: 'degrees' did not parse as fits unit: At col 0, Unit 'degrees' not supported by the FITS standard.  If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see https://docs.astropy.org/en/latest/units/combining_and_defining.html [astropy.units.core]
WARNING: UnitsWarning: 'microns' did not parse as fits unit: At col 0, Unit 'microns' not supported by the FITS standard.  If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see https://docs.astropy.org/en/latest/units/combining_and_defining.html [astropy.units.core]
WARNING: UnitsWarning: 'radians' did not parse as fits unit: At col 0, Unit 'radians' not supported by the FITS standard.  If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see https://docs.astropy.org/en/latest/units/combining_and_defining.html [astropy.units.core]
...
OSError: Could not identify column containing the wavelength, frequency or energy

Maybe these other data streams are not loaded?
But this did not seem to help:

degrees = u.def_unit('degrees', u.degree)
radians = u.def_unit('radians', u.radian)
microns = u.def_unit('microns', u.micron)
u.add_enabled_units([degrees, radians, microns])
1 Like