Commit 62e8c3c8 authored by LUSTIG Peter's avatar LUSTIG Peter

ready

parent cd29a2a4
......@@ -11,7 +11,7 @@ print(os.getcwd())
def CombineMeasurements(sourceslist, fakesourceslist):
fake_sources = Table()
sources = Table()
for _fake, _detected in zip(sourceslist, fakesourceslist):
for _fake, _detected in zip(fakesourceslist, sourceslist):
n_fake = len(fake_sources)
n_detected = len(sources)
......@@ -42,7 +42,8 @@ def LoadSingleFile(fname):
return flux, sources, fsources, dthresh
def Combine(directory, key, outfile):
def Combine(directory, key, outfile, precision=0.001*u.mJy):
fnames = list(sorted(Path(directory).glob(key)))
minthresh = None
......@@ -69,14 +70,62 @@ def Combine(directory, key, outfile):
sourceslist = [sourceslist[i] for i in idxsort]
fsourceslist = [fsourceslist[i] for i in idxsort]
groupflux = []
sourcegroup = []
fsourcegroup = []
'''
_fgroup = [fluxlist[0]]
_sgroup = [sourceslist[0]]
_fsgroup = [fsourceslist[0]]
'''
_fgroup = []
_sgroup = []
_fsgroup = []
for i in range(len(fluxlist)):
_f = fluxlist[i]
_s = sourceslist[i]
_fs = fsourceslist[i]
if _fgroup == [] or (_f - fluxlist[i-1]) < precision:
_fgroup.append(_f)
_sgroup.append(_s)
_fsgroup.append(_fs)
else:
groupflux.append(np.mean(u.Quantity(_fgroup)))
print('combining', _fgroup)
_gs, _gfs = CombineMeasurements(_sgroup, _fsgroup)
sourcegroup.append(_gs)
fsourcegroup.append(_gfs)
_fgroup = [_f]
_sgroup = [_s]
_fsgroup = [_fs]
groupflux.append(np.mean(u.Quantity(_fgroup)))
print('combining', _fgroup)
_gs, _gfs = CombineMeasurements(_sgroup, _fsgroup)
sourcegroup.append(_gs)
fsourcegroup.append(_gfs)
phdu = PrimaryHDU()
phdu.header['dthresh'] = minthresh
phdu.header['nfluxes'] = len(groupflux)
hdul = [phdu]
for i in range(len(groupflux)):
hdul.append(BinTableHDU(sourcegroup[i],
name='detected_sources{}'.format(i)))
hdul.append(BinTableHDU(fsourcegroup[i],
name='fake_sources{}'.format(i)))
hdul[0].header['flux{}'.format(i)] = '{}'.format(groupflux[i])
hdul = HDUList(hdul)
hdul.writeto(outname, overwrite=True)
print('{} different fluxes, tables written to {}'.format(len(groupflux),
outname))
fluxlist = u.Quantity(fluxlist)
directory = 'montecarlo_results/700/'
outname = 'NEWcombined_tables_long.fits'
key = '*182707*'
outname = 'NEW_combine_fct_result.fits'
key = '*700.fits'
Combine(directory, key, 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