pythonastropyastronomyfitspyfits

Reading Table from FITS format file with many dimensions in header?


I have a FITS format file which I can read the headers (hdu) using astropy:

from astropy.table import Table
from astropy.io import fits

fits.info('file.fits')

Filename: file.fits
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU      11   (150, 1, 1, 8, 8)   float32   
  1  WAVELENGTH    1 BinTableHDU     12   150R x 1C   [1E]   
  2  ANGLE         1 BinTableHDU     15   1R x 2C   [1E, 1E]   
  3  APERTURE      1 BinTableHDU     12   1R x 1C   [1E] 

Now, I can read Tables 1-3 by choosing the headers. Example, with hdu=1 (WAVELENGTH) I can read and export that particular table which gives 150 rows with one column of values:

Table.read('file.fits', format='fits', hdu=1)

However, I'm trying to pick out a certain column of values from the PRIMARY header hdu = 0, and I can't export anything because the code gives

ValueError: No table found in hdu=0

I'm assuming because of the dimensions, but I'm not sure how to single out a particular table from the primary header with this error in the way. Any help would be greatly appreciated.


Solution

  • In your fits file, the primary header has 5 dimensions, so it fundamentally cannot be represented as a Table, which can only handle 2 dimensions.

    To read the primary header data, you need to read it in as a numpy array which is described in astropy's tutorial and copied below

    hdul = fits.open("file.fits")
    hdu = hdul[0]
    data = hdu.data
    

    data is a numpy array which you can use to select the column you're interested in.