Commit c6e1de3c authored by LUSTIG Peter's avatar LUSTIG Peter

modified combine function and load function

parent 8550ae20
......@@ -3,11 +3,12 @@ from astropy.io.fits import PrimaryHDU, BinTableHDU, HDUList, open
from pathlib import Path
import astropy.units as u
import os
import sys
print(os.getcwd())
directory = 'montecarlo_results/'
outname = 'combined_tables.fits'
fnames = list(sorted(Path(directory).glob('*nsim50.fits')))
directory = 'montecarlo_results/700/'
outname = 'NEWcombined_tables_long.fits'
fnames = list(sorted(Path(directory).glob('*nsim700.fits')))
print(fnames)
hdul = [PrimaryHDU()]
n = 0
......@@ -19,14 +20,15 @@ for i, ifile in enumerate(fnames):
try:
_dt = Table.read(_file['DETECTED_SOURCES'])
hdul.append(BinTableHDU(data=_dt, name=('DETECTED_SOURCES{}'
.format(_flux))))
.format(i))))
except KeyError:
print('no sources detected in {}'.format(ifile))
print('no sources detected in {}'.format(_flux))
_ft = Table.read(_file['FAKE_SOURCES'])
hdul.append(BinTableHDU(data=_ft, name='FAKE_SOURCES{}'.format(_flux)))
hdul.append(BinTableHDU(data=_ft, name='FAKE_SOURCES{}'.format(i)))
n += 1
hdul[0].header['flux{}'.format(i)] = '{}'.format(_flux)
hdul[0].header['nfluxes'] = n
hdul = HDUList(hdul)
hdul.writeto(outname, overwrite=True)
print('tables written to {}'.format(outname))
......@@ -259,9 +259,9 @@ def UglyLoader(filename):
FLUX.append(u.Quantity(hdul[0].header['flux{}'.format(isimu)]))
SOURCE.append(Table.read(hdul['DETECTED_SOURCES{}'
.format(FLUX[isimu])]))
.format(isimu)]))
FSOURCE.append(Table.read(hdul['FAKE_SOURCES{}'
.format(FLUX[isimu])]))
.format(isimu)]))
return u.Quantity(FLUX), SOURCE, FSOURCE
......@@ -273,7 +273,7 @@ if __name__ == '__main__':
wcs = data.wcs
fname = ('/home/peter/Dokumente/Uni/Paris/Stage/'
'FirstSteps/Completness/combined_tables_long.fits')
'FirstSteps/Completness/NEWcombined_tables_long.fits')
FLUX, SOURCE, FSOURCE = UglyLoader(fname)
......
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