From 0e810f92a61a659363751dc6f34d5290bc21e56f Mon Sep 17 00:00:00 2001 From: Giacomo Terreran Date: Wed, 13 Mar 2024 11:37:30 -0700 Subject: [PATCH 1/3] Adding a missing gain factor in the noise image creation --- trunk/bin/lscdiff.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/trunk/bin/lscdiff.py b/trunk/bin/lscdiff.py index 966ad390..a18046d4 100755 --- a/trunk/bin/lscdiff.py +++ b/trunk/bin/lscdiff.py @@ -13,6 +13,20 @@ from reproject import reproject_interp import shutil +def create_variance_image(_data, _gain, _ron): + median = np.median(_data) + MAD = np.median(np.abs(_data - median)) #median absolute deviation + + #assuming the distribution is gaussian (normal), which is a good approximation + #of the poissonian distribution for large number of events, then we can convert + #the MAD to a pseudo pseudo standard deviation usinge 1.4826 as the scale factor + std = 1.4826 * MAD + + #pssl = previously subtracted sky level + pssl = _gain*std**2 - _ron**2/_gain - median + + return _data/_gain + pssl/_gain + _ron**2/_gain**2 #variance in ADUs^2 + def crossmatchtwofiles(img1, img2, radius=3): ''' This module is crossmatch two images: @@ -182,10 +196,8 @@ def crossmatchtwofiles(img1, img2, radius=3): targnoise = 'targnoise.fits' # create the noise images - median = np.median(data_targ) - noise = 1.4826*np.median(np.abs(data_targ - median)) - pssl_targ = gain_targ*noise**2 - rn_targ**2/gain_targ - median - noiseimg = data_targ + pssl_targ + rn_targ**2 + noiseimg = create_variance_image(data_targ, gain_targ, rn_targ) + targmask_data = fits.getdata(_dir + targmask0) if noiseimg.size == targmask_data.size: noiseimg[targmask_data > 0] = sat_targ @@ -197,10 +209,7 @@ def crossmatchtwofiles(img1, img2, radius=3): fits.writeto(targnoise, noiseimg, output_verify='fix', overwrite=True) if not os.path.isfile(_dirtemp + tempnoise0): - median = np.median(data_temp) - noise = 1.4826*np.median(np.abs(data_temp - median)) - pssl_temp = gain_temp*noise**2 - rn_temp**2/gain_temp - median - noiseimg = data_temp + pssl_temp + rn_temp**2 + noiseimg = create_variance_image(data_temp, gain_temp, rn_temp) tempmask_data = fits.getdata(_dirtemp + tempmask0) if noiseimg.size == tempmask_data.size: noiseimg[tempmask_data > 0] = sat_temp From 4c99fb0b21acd85b27e1c2b9e1e286e578df7142 Mon Sep 17 00:00:00 2001 From: Giacomo Terreran Date: Thu, 21 Mar 2024 20:25:57 -0700 Subject: [PATCH 2/3] bug fix related to the noise image --- trunk/bin/lscdiff.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trunk/bin/lscdiff.py b/trunk/bin/lscdiff.py index a18046d4..60d5b452 100755 --- a/trunk/bin/lscdiff.py +++ b/trunk/bin/lscdiff.py @@ -25,7 +25,7 @@ def create_variance_image(_data, _gain, _ron): #pssl = previously subtracted sky level pssl = _gain*std**2 - _ron**2/_gain - median - return _data/_gain + pssl/_gain + _ron**2/_gain**2 #variance in ADUs^2 + return _data/_gain + pssl/_gain + _ron**2/_gain**2, pssl #variance in ADUs^2 def crossmatchtwofiles(img1, img2, radius=3): @@ -196,7 +196,7 @@ def crossmatchtwofiles(img1, img2, radius=3): targnoise = 'targnoise.fits' # create the noise images - noiseimg = create_variance_image(data_targ, gain_targ, rn_targ) + noiseimg, pssl_targ = create_variance_image(data_targ, gain_targ, rn_targ) targmask_data = fits.getdata(_dir + targmask0) if noiseimg.size == targmask_data.size: From fd150857d17e2a8eebeadf0c69ac36fe6c4dd508 Mon Sep 17 00:00:00 2001 From: Giacomo Terreran Date: Thu, 21 Mar 2024 20:26:20 -0700 Subject: [PATCH 3/3] bug fix related to the noise image --- trunk/bin/lscdiff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trunk/bin/lscdiff.py b/trunk/bin/lscdiff.py index 60d5b452..c2c31b70 100755 --- a/trunk/bin/lscdiff.py +++ b/trunk/bin/lscdiff.py @@ -25,7 +25,8 @@ def create_variance_image(_data, _gain, _ron): #pssl = previously subtracted sky level pssl = _gain*std**2 - _ron**2/_gain - median - return _data/_gain + pssl/_gain + _ron**2/_gain**2, pssl #variance in ADUs^2 + #return variance in ADUs^2 + return _data/_gain + pssl/_gain + _ron**2/_gain**2, pssl def crossmatchtwofiles(img1, img2, radius=3):