Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 449
Suttiwat Madlee Avatar asked Dec 06 '25 07:12

Suttiwat Madlee


1 Answers

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.

like image 120
Tiger-222 Avatar answered Dec 07 '25 19:12

Tiger-222