2

So I have some Astropy fits tables that I save (they have all have the same format, column names, etc.). I want to take all these fits files and combine them to make one large fits file.

Currently, I am playing around with the astropy.io append and update functions to no avail.

Any help would be greatly appreciated.

Ratan Uday Kumar
  • 3,556
  • 5
  • 26
  • 49
Patrick
  • 161
  • 7

1 Answers1

3

So I have it working now. This is what I did essentially:

# Read in the fits table you want to append 
table = Table.read(input_file, format='fits')

# Read in the large table you want to append to 
base_table = Table.read('base_file.fits', format='fits')

# Use Astropy's 'vstack' function and overwrite the file 
concat_table = vstack([base_table,append_table])
concat_table.write('base_file.fits', format='fits', overwrite=True)

In my case, all the columns are the same for every table. So I just looped through all the fits files and appended them one at a time. There are probably other ways to do this, but I found this was the easiest.

Patrick
  • 161
  • 7
  • Using table.vstack is exactly the right way to combine FITS tables. – Tom Aldcroft Nov 07 '19 at 13:40
  • 1
    Could you please post your loop as well? – Srivatsan May 12 '20 at 02:10
  • I used a bash script to iterate through the files, but you can just easily do it in python. If you want to iterate through files in python, use the module os, and to get the correct files I typically use the glob module. Something like: " for f in glob(os.path.join(folder_with_files), '*.fits'): ....." – Patrick May 20 '20 at 03:00