FITS syntax question
Karl Glazebrook wrote on Jul 10, 2009
Hello,
I seem to have a fits file with an extension name that has embedded spaces.
In IDL:
IDL> fits_info,'test.fits'
% Compiled module: FITS_INFO.
% Compiled module: TEXTOPEN.
% Compiled module: FILEPATH.
% Compiled module: SXPAR.
% Compiled module: GETTOK.
% Compiled module: STRN.
% Compiled module: VALID_NUM.
% Compiled module: MRD_SKIP.
test.fits has 9 extensions
Primary header: 196 records
Image -- Real*4 array ( 4892 400 )
Extension 1 -- VARIANCE
Header : 29 records
IMAGE ( 4892 400 )
Extension 2 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.FIBRES
Header : 93 records
Binary Table ( 232 400 )
Extension 3 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.NDF_CLASS
Header : 15 records
Binary Table ( 10 1 )
Extension 4 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.SHIFTS
Header : 16 records
Binary Table ( 16000 1 )
Extension 5 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.PSFMAP
Header : 16 records
Binary Table ( 3276800 1 )
Extension 6 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.THPUT
Header : 15 records
Binary Table ( 1600 1 )
Extension 7 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.SKY
Header : 15 records
Binary Table ( 19568 1 )
Extension 8 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.REDUCED
Header : 15 records
Binary Table ( 1 1 )
Extension 9 -- PCA SKY SUBTRACTED SPECTRA
Header : 198 records
IMAGE ( 4892 400 )
% Compiled module: TEXTCLOSE.
So how would I access Extension 9 using IRAF FITS image kernel, by name?
The obvious thing
imstat test.fits['PCA SKY SUBTRACTED SPECTRA']
** Syntax error
**: imstat test.fits['PCA SKY SUBTRACTED SPECTRA']
^
fitsutil> e
imstat test.fits[PCA SKY SUBTRACTED SPECTRA]
ERROR: too many positional arguments for `imstatistics'
fitsutil>
Does not work (thought test.fits[9] does)
Also it seems that catfits crashes on this file. Is this related?
I am wondering if the extension name is even legal?!
thanks for any light you can shed!
Karl
I seem to have a fits file with an extension name that has embedded spaces.
In IDL:
IDL> fits_info,'test.fits'
% Compiled module: FITS_INFO.
% Compiled module: TEXTOPEN.
% Compiled module: FILEPATH.
% Compiled module: SXPAR.
% Compiled module: GETTOK.
% Compiled module: STRN.
% Compiled module: VALID_NUM.
% Compiled module: MRD_SKIP.
test.fits has 9 extensions
Primary header: 196 records
Image -- Real*4 array ( 4892 400 )
Extension 1 -- VARIANCE
Header : 29 records
IMAGE ( 4892 400 )
Extension 2 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.FIBRES
Header : 93 records
Binary Table ( 232 400 )
Extension 3 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.NDF_CLASS
Header : 15 records
Binary Table ( 10 1 )
Extension 4 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.SHIFTS
Header : 16 records
Binary Table ( 16000 1 )
Extension 5 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.PSFMAP
Header : 16 records
Binary Table ( 3276800 1 )
Extension 6 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.THPUT
Header : 15 records
Binary Table ( 1600 1 )
Extension 7 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.SKY
Header : 15 records
Binary Table ( 19568 1 )
Extension 8 -- HDS_SCRATCH.TEMP_1.NDF_18.MORE.REDUCED
Header : 15 records
Binary Table ( 1 1 )
Extension 9 -- PCA SKY SUBTRACTED SPECTRA
Header : 198 records
IMAGE ( 4892 400 )
% Compiled module: TEXTCLOSE.
So how would I access Extension 9 using IRAF FITS image kernel, by name?
The obvious thing
imstat test.fits['PCA SKY SUBTRACTED SPECTRA']
** Syntax error
**: imstat test.fits['PCA SKY SUBTRACTED SPECTRA']
^
fitsutil> e
imstat test.fits[PCA SKY SUBTRACTED SPECTRA]
ERROR: too many positional arguments for `imstatistics'
fitsutil>
Does not work (thought test.fits[9] does)
Also it seems that catfits crashes on this file. Is this related?
I am wondering if the extension name is even legal?!
thanks for any light you can shed!
Karl
Mike Fitzpatrick wrote on Jul 10, 2009
The use of embedded whitespace appears to be legal FITS, however it isn't allowed in the FITS kernel. It isn't explicitly excluded, however the kernel section parsing code assumes whitespace is a natural boundary and I can't think of a way to escape it so the whitespace is preserved.
As for CATFITS, the extname should still show up in the listing even with whitespace although it may be truncated to fit the table. If you have the FITSUTIL package installed then the FXHEADER task does the same thing and might work better.
Note the HFIX task is able to run an arbitrary command on header text (see the help page examples), so you may be able to quickly hack some Perl expression to replace the whitespace in EXTNAME with underscores.
-Mike
As for CATFITS, the extname should still show up in the listing even with whitespace although it may be truncated to fit the table. If you have the FITSUTIL package installed then the FXHEADER task does the same thing and might work better.
Note the HFIX task is able to run an arbitrary command on header text (see the help page examples), so you may be able to quickly hack some Perl expression to replace the whitespace in EXTNAME with underscores.
-Mike
Karl Glazebrook wrote on Jul 10, 2009
Thanks for the answers.
It turned out I could do what I wanted directly using other software so I did not need to use IRAF to hack the header.
Interestingly catfits crashes on this file while fitsheader does not (see below). Send me an email if you want the file for debugging purposes.
Karl
catfits test.fits
EXT# FITSNAME FILENAME EXTVE DIMENS BITPI OBJECT
0 test.fits 4892x400 -32 r22_f06_s01
1 IMAGE VARIANCE 4892x400 -32 r22_f06_s01
2 BINTABLE HDS_SCRATCH.TEMP_1.ND 17Fx400R
3 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
4 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
5 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
6 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
7 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
8 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
test.fits ** Unexpected data at end of fits file **
fitsutil>
fitsutil> e
fxheader test.fits
EXT# EXTTYPE EXTNAME EXTVE DIMENS BITPI INH OBJECT
0 test.fits 4892x400 -32 r22_f06_s01
1 IMAGE VARIANCE 4892x400 -32 r22_f06_s01
2 BINTABLE HDS_SCRATCH.T 232x400 8
3 BINTABLE HDS_SCRATCH.T 10x1 8
4 BINTABLE HDS_SCRATCH.T 16000x1 8
5 BINTABLE HDS_SCRATCH.T 3276800x1 8
6 BINTABLE HDS_SCRATCH.T 1600x1 8
7 BINTABLE HDS_SCRATCH.T 19568x1 8
8 BINTABLE HDS_SCRATCH.T 1x1 8
9 IMAGE PCA SKY SUBTR 4892x400 -32 r22_f06_s01
It turned out I could do what I wanted directly using other software so I did not need to use IRAF to hack the header.
Interestingly catfits crashes on this file while fitsheader does not (see below). Send me an email if you want the file for debugging purposes.
Karl
catfits test.fits
EXT# FITSNAME FILENAME EXTVE DIMENS BITPI OBJECT
0 test.fits 4892x400 -32 r22_f06_s01
1 IMAGE VARIANCE 4892x400 -32 r22_f06_s01
2 BINTABLE HDS_SCRATCH.TEMP_1.ND 17Fx400R
3 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
4 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
5 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
6 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
7 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
8 BINTABLE HDS_SCRATCH.TEMP_1.ND 1Fx1R
test.fits ** Unexpected data at end of fits file **
fitsutil>
fitsutil> e
fxheader test.fits
EXT# EXTTYPE EXTNAME EXTVE DIMENS BITPI INH OBJECT
0 test.fits 4892x400 -32 r22_f06_s01
1 IMAGE VARIANCE 4892x400 -32 r22_f06_s01
2 BINTABLE HDS_SCRATCH.T 232x400 8
3 BINTABLE HDS_SCRATCH.T 10x1 8
4 BINTABLE HDS_SCRATCH.T 16000x1 8
5 BINTABLE HDS_SCRATCH.T 3276800x1 8
6 BINTABLE HDS_SCRATCH.T 1600x1 8
7 BINTABLE HDS_SCRATCH.T 19568x1 8
8 BINTABLE HDS_SCRATCH.T 1x1 8
9 IMAGE PCA SKY SUBTR 4892x400 -32 r22_f06_s01
Last post on Jul 10, 2009