[daip] FITS FILES {External}

egreisen egreisen at nrao.edu
Tue Nov 2 23:43:30 EDT 2021


On 2021-11-02 17:35, tom scott wrote:
> Hi Eric
> 
> I’m having a problem using ASTROPY APLPY in python 3.5 and I am
> wondering if you have any suggestions about it, as there appears to be
> a problem with converting a fits file with NAXIS=3 to one with
> NAXIS=2. In order to overplot contours with APLPY I need to reduce the
> number axis in fits image files from 3 to 2 axes. Just removing the
> keywords from with suffix =3 works for some moment 0 and moment 1 fits
> files. However, when I apply  the function below
> 
> def drop2axesf(filename, outname):
>     hdu = fits.open(filename)[0]
>     print(hdu)
>     hdu.header['naxis'] = 2
>     hdu.data = hdu.data[0, :, :]
>     hdu.header.remove('CRPIX3')
>     hdu.header.remove('CRVAL3')
>     hdu.header.remove('CDELT3')
>     hdu.header.remove('CUNIT3')
>     hdu.header.remove('CTYPE3')
>     hdu.writeto(outname, overwrite=True)
>     print('outname', outname)
> 
> to do this on the fits file UDGB1-LR-MOM0.FITS (attached)
> 
> it produces the fits file (UDGB1-LR-MOM0ax.FITS) but with NAXIS=1
> 
> From what I can understand from your 2002 FITS paper this behavior may
> be related to the use of the third axis for long slit spectrums. Is
> there a way to convert the NAXIS3 fits to a fits image file with
> NAXIS2
> 
> Thanks
> 
> Tom

I don't know anything about your python but it looks like you told it to 
drop two axes which it did.  You only want to drop one.  I looked at the 
2 files and axis 3 has only one pixel and it is used to say that it is 
Stokes I (value = +1).  I do not understand FITS programs that are so 
stupid as to be confused by NAXIS 3 esp when the 3rd axis is merely 
informative.  NAXIS 3 was described in absolutely the first ever FITS 
paper.  In this case you have only a 2-diemnsional image which is normal 
for a moment 0 image.  Note that this moment 0 was produced from an 
image that had a real 3rd axis, probably images at a number of Doppler 
shifts.  It was a radio astronomy image and so has nothing to do with 
long slits.  Instead it used a correlator able to separate the incoming 
signal into multiple frequencies.  It then used software to calibrate 
and image the multiple frequencies.  Finally the moments of the image 
cube were analyzed quite possibly by the AIPS software for which I am 
most known.

Eric Greisen



More information about the Daip mailing list