radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
98 stars 65 forks source link

Problems with reading FITS file produced by CLASS #213

Open esoPanda opened 9 years ago

esoPanda commented 9 years ago
WARNING: No spectral axis found; header may be non-compliant. [spectral_cube.cube_utils]

WARNING: FITS file has no STOKES axis, but it has a blank axis type at index 4 that is assumed to be stokes. [spectral_cube.cube_utils]

Could not parse unit K (Tmb)

SIMPLE  =                    T         /                                        
BITPIX  =                   32         /                                        
NAXIS   =                    4         /                                        
NAXIS1  =                  107         /                                        
NAXIS2  =                  158         /                                        
NAXIS3  =                  200         /                                        
NAXIS4  =                    1         /                                        
BSCALE  =  0.2135455590135E-08         /                                        
BZERO   =  0.1350482463837E+01         /                                        
BLANK   =           2147483647         / Blanking value                         
DATAMIN = -0.3235373497009E+01         /                                        
DATAMAX =  0.5936336994171E+01         /                                        
BUNIT   = 'K (Tmb)     '               /                                        
CTYPE1  = 'RA---GLS    '               /                                        
CRVAL1  =  0.2726166666667E+03         /                                        
CDELT1  = -0.2777777779420E-02         /                                        
CRPIX1  =  0.5300648762083E+02         /                                        
CROTA1  =  0.0000000000000E+00         /                                        
CTYPE2  = 'DEC--GLS    '               /                                        
CRVAL2  = -0.1938083333333E+02         /                                        
CDELT2  =  0.2777777779420E-02         /                                        
CRPIX2  =  0.6253897971531E+02         /                                        
CROTA2  =  0.0000000000000E+00         /                                        
CTYPE3  = 'VELOCITY    '               /                                        
CRVAL3  =  0.3000000000000E+05         /                                        
CDELT3  =  0.2000000029802E+03         /                                        
CRPIX3  =  0.1000000000000E+03         /                                        
CROTA3  =  0.0000000000000E+00         /                                        
CTYPE4  = '            '               /                                        
CRVAL4  =  0.1000000000000E+01         /                                        
CDELT4  =  0.1000000000000E+01         /                                        
CRPIX4  =  0.1000000000000E+01         /                                        
CROTA4  =  0.0000000000000E+00         /                                        
OBJECT  = 'G11_Snake   '               /                                        
RA      =  0.2726166666667E+03         / Right Ascension                        
DEC     = -0.1938083333333E+02         / Declination                            
EQUINOX =  0.2000000000000E+04         /                                        
LINE    = '13CO(2-1)   '                                                        
ALTRVAL =  0.3000000000000E+07         /                                        
ALTRPIX =  0.1000000000000E+03         /                                        
RESTFREQ=  0.2203986770000E+12         /                                        
VELREF  =  0.3000000000000E+07         /                                        
BMAJ    =  0.8351990890994E-02         /                                        
BMIN    =  0.8351990890994E-02         /                                        
BPA     =  0.0000000000000E+00         /                                        
ORIGIN  = 'GILDAS Consortium  '        /                                        
DATE    = '2014-03-24T00:00:00.00'     / Date written                           
END                                                                             
keflavich commented 9 years ago

The 4th axis is degenerate but has no type. It actually looks like SpectralCube is generally handling this. Could you print out the result of the cube's __repr__? To do this, just enter the cube variable name on the command line, e.g. if you did cube = SpectralCube.read('file.fits'), just enter cube and print the results.

To fix the cube and get rid of the warnings, drop the degenerate axis and change BUNIT

f = fits.open('file.fits')
f[0].data = f[0].data.squeeze()
for k in f[0].header.keys():
    if k[0] == 'C' and k[-1] == '4':
        del f[0].header[k]
f[0].header['BUNIT'] = 'K'
cube = SpectralCube.read(f)
keflavich commented 9 years ago

Related https://github.com/radio-astro-tools/spectral-cube/pull/192#issuecomment-78965186

esoPanda commented 9 years ago
<bound method SpectralCube.__repr__ of SpectralCube with shape=(200, 158, 107):
 n_x: 107  type_x: RA---SFL  unit_x: deg
 n_y: 158  type_y: DEC--SFL  unit_y: deg
 n_s: 200  type_s: VOPT      unit_s: m / s>

     25 f[0].data = f[0].data.squeeze()
     26 for k in f[0].header.keys():
---> 27     if k[0] == 'C' and k[-1] == '4':
     28         del f[0].header[k]
     29 f[0].header['BUNIT'] = 'K'

IndexError: string index out of range
keflavich commented 9 years ago

Based on the output you showed, you are not on the most up-to-date version of spectral_cube. Try pip install https://github.com/radio-astro-tools/spectral-cube/archive/master.zip. If that doesn't work, try pip install --upgrade https://github.com/radio-astro-tools/spectral-cube/archive/master.zip