Commit 261f74b9 authored by LUSTIG Peter's avatar LUSTIG Peter

'added function to combine simulation results to one fits file'

parent 70aec6bf
from astropy.table import Table
from import PrimaryHDU, BinTableHDU, HDUList, open
from pathlib import Path
import astropy.units as u
import os
directory = 'montecarlo_results/'
outname = 'combined_tables.fits'
fnames = list(sorted(Path(directory).glob('*nsim50.fits')))
hdul = [PrimaryHDU()]
n = 0
for i, ifile in enumerate(fnames):
_file = open(ifile)
_flux = u.Quantity(_file[0].header['influx'])
hdul.append(BinTableHDU(data=_dt, name=('DETECTED_SOURCES{}'
except KeyError:
print('no sources detected in {}'.format(ifile))
_ft =['FAKE_SOURCES'])
hdul.append(BinTableHDU(data=_ft, name='FAKE_SOURCES{}'.format(_flux)))
n += 1
hdul[0].header['flux{}'.format(i)] = '{}'.format(_flux)
hdul[0].header['nfluxes'] = n
hdul = HDUList(hdul)
hdul.writeto(outname, overwrite=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment