Commit cd29a2a4 authored by LUSTIG Peter's avatar LUSTIG Peter

zwischenstand...

parent 9dfc819c
......@@ -7,13 +7,6 @@ import os
import sys
print(os.getcwd())
directory = 'montecarlo_results/700/'
outname = 'NEWcombined_tables_long.fits'
fnames = list(sorted(Path(directory).glob('*nsim700.fits')))
print(fnames)
hdul = [PrimaryHDU()]
n = 0
def CombineMeasurements(sourceslist, fakesourceslist):
fake_sources = Table()
......@@ -33,29 +26,67 @@ def CombineMeasurements(sourceslist, fakesourceslist):
return sources, fake_sources
for i, ifile in enumerate(fnames):
_file = open(ifile)
_flux = u.Quantity(_file[0].header['influx'])
def LoadSingleFile(fname):
_file = open(fname)
flux = u.Quantity(_file[0].header['influx'])
try:
_dt = Table.read(_file['DETECTED_SOURCES'])
hdul.append(BinTableHDU(data=_dt, name=('DETECTED_SOURCES{}'
.format(i))))
sources = Table.read(_file['DETECTED_SOURCES'])
except KeyError:
print('no sources detected in {}'.format(_flux))
print('no sources detected for {}'.format(flux))
sources = None
fsources = Table.read(_file['FAKE_SOURCES'])
dthresh = _file[0].header['DTHRESH']
return flux, sources, fsources, dthresh
def Combine(directory, key, outfile):
fnames = list(sorted(Path(directory).glob(key)))
minthresh = None
n = 0
fluxlist = []
sourceslist = []
fsourceslist = []
''' load every single file '''
for i, ifile in enumerate(fnames):
_flux, _sources, _fsources, _dthresh = LoadSingleFile(ifile)
fluxlist.append(_flux)
sourceslist.append(_sources)
fsourceslist.append(_fsources)
if minthresh is None or minthresh < _dthresh:
minthresh = _dthresh
'''sort for flux comparison'''
fluxlist = u.Quantity(fluxlist)
idxsort = np.argsort(fluxlist.to_value(u.mJy))
fluxlist = fluxlist[idxsort]
sourceslist = [sourceslist[i] for i in idxsort]
fsourceslist = [fsourceslist[i] for i in idxsort]
_ft = Table.read(_file['FAKE_SOURCES'])
hdul.append(BinTableHDU(data=_ft, name='FAKE_SOURCES{}'.format(i)))
n += 1
hdul[0].header['flux{}'.format(i)] = '{}'.format(_flux)
fluxlist = u.Quantity(fluxlist)
directory = 'montecarlo_results/700/'
outname = 'NEWcombined_tables_long.fits'
key = '*182707*'
Combine(directory, key, outname)
'''
idxsort = np.argsort(flux.to_value(u.mJy))
self.flux = flux[idxsort]
self.sources = [sources[i] for i in idxsort]
self.fake_sources = [fake_sources[i] for i in idxsort]
'''
'''
hdul[0].header['nfluxes'] = n
hdul = HDUList(hdul)
hdul.writeto(outname, overwrite=True)
print('tables written to {}'.format(outname))
'''
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