Suttiwat Madlee
Suttiwat Madlee

Reputation: 41

How can I combine two FITS tables into a single table in new fits file?

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 ?

Upvotes: 3

Views: 4763

Answers (1)

Tiger-222
Tiger-222

Reputation: 7150

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.

Upvotes: 4

Related Questions