Search code examples
python-3.xtensorflowmachine-learningastropy

What part of the fits file from sdss contains the spectrum?


I'm working on a CNN quasar detector that takes the optical spectrum as input, and classifies it as Quasar or non-quasar. I'm currently gathering data from this site:https://dr18.sdss.org/optical/spectrum/search?plateid=266&mjd=51602&run2d=26&action=search. I used the wget method to download the fits files, and then loaded it into python. The problem I am facing is that the output from this code:

from astropy.io import fits

arr = fits.open('test.fits')

print(arr[0].header)
print(arr[0].data)

Seems to have nothing to do with quasars. Another issue is that fits viewers wont open this. Why? What do I need to change to view the spectra?


Solution

  • I downloaded the first QSO file from your link (object 299490226730985472). I then examined the full FITS file. It contains a primary HDU (as every FITS file does) and three binary table extensions.

    The header of the primary HDU indicates we're looking at a science observations, although the details are missing.

    The header of the first binary table extension mentions

    COMMENT Coadded spectrum
    

    which sounds promising.

    I guessed a bit about which columns would be the relevant ones for a simple plot, and used the loglam and flux columns to plot the following: enter image description here

    I'll leave it you to judge whether that's a QSO spectrum.


    To confirm and compare: the Sloan page on this particular object is https://dr18.sdss.org/optical/spectrum/view?id=330136&plate=266&mjd=51602&fiberid=3 , which shows the same spectrum with more detail, plus various other details.


    The reason that you're not seeing anything, is because you skipped past the other FITS extensions (unless you downloaded a completely wrong file). But it doesn't make sense to have a spectrum in a primary HDU, which always has to contain an image (or, as in this case, an empty image, that is, no data at all).

    So you should always examine the full file, with all its extensions. You can probably also find a lot more information in the documentation on the website.