2

I have two fits file data (file1.fits and file2.fits). The first one (file1.fits) consists of 80,700 important rows of data and another one is 140,000 rows. The both of them have the same Header.

$ python
>>> import pyfits 
>>> f1 = pyfits.open('file1.fits')
>>> f2 = pyfits.open('file2.fits')
>>> event1 = f1[1].data
>>> event2 = f2[1].data
>>> len(event1)
80700
>>> len(event2)
140000

How can I combine file1.fits and file2.fits into new fits file (newfile.fits) with the same header as the old ones and the total number of rows of newfile.fits is 80,700+ 140,000 = 220,700 ?

Iguananaut
  • 21,810
  • 5
  • 50
  • 63
  • 1
    do the important data start from row 2 and continue sequentially? – Ma0 Aug 24 '16 at 09:58
  • 1
    You can get inspiration from https://stackoverflow.com/questions/33850641/how-to-merge-two-table-with-pyfits? – Tiger-222 Aug 24 '16 at 10:20
  • This is a duplicate of http://stackoverflow.com/questions/33850641/how-to-merge-two-table-with-pyfits?noredirect=1&lq=1 – Iguananaut Aug 24 '16 at 17:17
  • Possible duplicate of [How to merge two table with pyfits?](https://stackoverflow.com/questions/33850641/how-to-merge-two-table-with-pyfits) – usernumber Jan 29 '19 at 14:34

1 Answers1

3

I tried with astropy:

from astropy.table import Table, hstack

t1 = Table.read('file1.fits', format='fits')
t2 = Table.read('file2.fits', format='fits')
new = hstack([t1, t2])
new.write('combined.fits')

It seems to work with samples from NASA.

Tiger-222
  • 6,677
  • 3
  • 47
  • 60