Combine different FITS extension headers and data into new fits file using astropy

744 Views Asked by At

I have a fits.gz file which contains 5 different extensions

No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU     720   ()      
  1  VidInp1       1 ImageHDU       359   (577, 2048)   int16 (rescales to uint16)   
  2  VidInp2       1 ImageHDU       359   (577, 2048)   int16 (rescales to uint16)   
  3  VidInp3       1 ImageHDU       359   (577, 2048)   int16 (rescales to uint16)   
  4  VidInp4       1 ImageHDU       359   (577, 2048)   int16 (rescales to uint16)

I'm trying to take the header from exten[0] and the data from exten[3] to create a new fits file which only has 1 extension. I'm currently trying to use astropy.io.fits to achieve this, but it's not clear to me from the documentation if there's a clean way to do this. Is there a better package to use, or is this a messy process no matter what?

1

There are 1 best solutions below

0
On

The solution turns out to be very simple/elegant, a one liner which is what I was hoping for.

fits.writeto(splitFileName, fits.getdata(fileName, 3), fits.getheader(fileName, 0))

where fileName is the original fits file and splitFileName is the created file