Commit 2be1717e authored by LUSTIG Peter's avatar LUSTIG Peter

Added possibility to do photometry without detection of fake sources

parent 45d45ee6
......@@ -63,7 +63,7 @@ def get_size(obj, seen=None):
def fake_worker(img, min_threshold=2, nsources=8**2, flux=1*u.Jy,
within=(0, 1), cat_gen=pos_uniform,
retmask=True, photometry=False, **kwargs):
retmask=True, detection=True, photometry=False, **kwargs):
"""The completness purity worker, create a fake dataset from an jackknifed
image and return catalogs
......@@ -77,6 +77,8 @@ def fake_worker(img, min_threshold=2, nsources=8**2, flux=1*u.Jy,
arguments for source injection
"""
# print('using Jackknife object', jkiter)
assert detection or photometry, ('you have to chose either detection or '
'photometry or both')
np.random.seed(int(os.urandom(4).hex(), 16))
# img = IMAGE
......@@ -90,30 +92,44 @@ def fake_worker(img, min_threshold=2, nsources=8**2, flux=1*u.Jy,
img.add_gaussian_sources(nsources=nsources, within=within,
peak_flux=flux, cat_gen=cat_gen, **kwargs)
# ... match filter it ...
mf_img = img.match_filter(img.beam)
std = mf_img.check_SNR()
# print(std)
mf_img.uncertainty.array *= std
# print(mf_img.wcs)
# ... and detect sources with the lowest threshold...
# The gaussian fit from subpixel=True is very slow here...
mf_img.detect_sources(threshold=min_threshold)
if photometry and mf_img.sources is not None:
img.phot_sources(sources=mf_img.sources, peak=False, psf=True)
if detection:
# ... match filter it ...
mf_img = img.match_filter(img.beam)
std = mf_img.check_SNR()
# print(std)
mf_img.uncertainty.array *= std
# print(mf_img.wcs)
# ... and detect sources with the lowest threshold...
# The gaussian fit from subpixel=True is very slow here...
mf_img.detect_sources(threshold=min_threshold)
if photometry:
if detection and mf_img.sources is not None:
img.phot_sources(sources=mf_img.sources, peak=False, psf=True)
if not detection:
# print('testprint', img.sources.keys())
img.phot_sources(sources=img.fake_sources, peak=False, psf=True)
sources = img.sources
else:
sources = mf_img.sources
fake_sources = mf_img.fake_sources
if detection:
fake_sources = mf_img.fake_sources
else:
fake_sources = img.fake_sources
if detection:
mf_img_mask = mf_img.mask
else:
mf_img_mask = np.zeros(img.data.shape)
if retmask:
return sources, fake_sources, img.mask, mf_img.mask
return sources, fake_sources, img.mask, mf_img_mask
else:
return sources, fake_sources
def CreateParallelJackkifes(jkiter, parity_threshold):
np.random.seed(int(os.urandom(4).hex(), 16))
jk = jkiter(parity_threshold=parity_threshold)
......@@ -121,12 +137,14 @@ def CreateParallelJackkifes(jkiter, parity_threshold):
##############################################################
np.random.seed(0)
flux = np.array([10]) * u.mJy
nsim = 1
min_detection_threshold = 3
nsim = 3
min_detection_threshold = 4
nsources = 2
photometry = True
detection = False
ncores = 2
parity_threshold = 1
......@@ -152,9 +170,10 @@ message = '''\
# No Different Fluxes: {:5d} #
# Number of Injected Sources: {:5d} #
# Photometry: {} #
# Detection: {} #
###############################################################
'''.format(nsim, ncores, min_detection_threshold, len(flux), nsources,
photometry)
photometry, detection)
print(message, "\n")
......@@ -220,7 +239,8 @@ for _flux in flux:
'within': (0, 1),
'cat_gen': pos_uniform,
'dist_threshold': min_source_dist,
'photometry': photometry})
'photometry': photometry,
'detection': detection})
if nsources != 0:
print('Simulation with {:.2f}...'.format(_flux))
......@@ -259,9 +279,10 @@ for _flux in flux:
immask = np.sum(immask, axis=0)
matchmask = np.sum(matchmask, axis=0)
fname = ('flux{:.2f}mJy_thresh{}_nsources{}_nsim{}_phot{}.fits'
fname = ('flux{:.2f}mJy_thresh{}_nsources{}_nsim{}_phot{}_detect{}.fits'
.format(_flux.to_value(unit=u.mJy),
min_detection_threshold, nsources, nsim, photometry))
min_detection_threshold, nsources, nsim, photometry,
detection))
fname = timeprefix + fname
outfile = outdir / 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