From 43d302176d0c591c74fee38f572c5a9450fcf7c0 Mon Sep 17 00:00:00 2001 From: Julien Guy Date: Fri, 23 Aug 2024 15:16:16 -0700 Subject: [PATCH 1/3] Avoid unstable correction if fiber is off from target. Use cframe mask and ivar instead for frame mask and ivar when computing TSNR --- py/desispec/tsnr.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/py/desispec/tsnr.py b/py/desispec/tsnr.py index 7b569542c..972609a1f 100644 --- a/py/desispec/tsnr.py +++ b/py/desispec/tsnr.py @@ -894,7 +894,7 @@ def calc_tsnr_fiberfracs(fibermap, etc_fiberfracs, no_offsets=False): # = (rel. fiber frac-offset correction for psf in seeing) / (rel. fiber frac-offset correction for psf in 1.1'') / plate scale**2 [flux calib * fiberflat] # - notnull = rel_psf_loss_1p1 > 0.0 + notnull = (rel_psf_loss_1p1 > 0.01) # do not do the subtle correction of relative fiber loss vs seeing compare to 1.1'' if the fiber is off target for tracer in ['psf', 'mws', 'qso', 'lya', 'gpbbackup']: tsnr_fiberfracs[tracer] = np.ones_like(rel_psf_loss) @@ -963,13 +963,14 @@ def calc_tsnr2_cframe(cframe): skymodel = read_sky(skyfile) fluxcalib = read_flux_calibration(fluxcalibfile) - return calc_tsnr2(frame, fiberflat, skymodel, fluxcalib) + return calc_tsnr2(cframe, frame, fiberflat, skymodel, fluxcalib) -def calc_tsnr2(frame, fiberflat, skymodel, fluxcalib, alpha_only=False, include_poisson=True, include_fiberfracs=True): +def calc_tsnr2(cframe, frame, fiberflat, skymodel, fluxcalib, alpha_only=False, include_poisson=True, include_fiberfracs=True): ''' Compute template SNR^2 values for a given frame Args: + cframe : calibrated Frame object for one camera frame : uncalibrated Frame object for one camera fiberflat : FiberFlat object sky : SkyModel object @@ -1100,9 +1101,10 @@ def calc_tsnr2(frame, fiberflat, skymodel, fluxcalib, alpha_only=False, include_ if alpha_only: return {}, alpha - maskfactor = np.ones_like(frame.mask, dtype=float) - maskfactor[frame.mask > 0] = 0.0 - maskfactor *= (frame.ivar > 0.0) + # use cframe instead of frame mask and ivar + maskfactor = np.ones_like(cframe.mask, dtype=float) + maskfactor[cframe.mask > 0] = 0.0 + maskfactor *= (cframe.ivar > 0.0) tsnrs = {} for tracer in ensemble.keys(): From 9bf00097e1e7fa2158552d49a6a08d80b8a3f5a5 Mon Sep 17 00:00:00 2001 From: Julien Guy Date: Fri, 23 Aug 2024 15:28:41 -0700 Subject: [PATCH 2/3] calc_tsnr2 needs cframe --- py/desispec/scripts/procexp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/desispec/scripts/procexp.py b/py/desispec/scripts/procexp.py index 5454de2fe..99a1e157f 100644 --- a/py/desispec/scripts/procexp.py +++ b/py/desispec/scripts/procexp.py @@ -149,7 +149,7 @@ def main(args): if not args.no_tsnr: log.info("calculating tsnr") - results, alpha = calc_tsnr2(uncalibrated_frame, fiberflat=fiberflat, skymodel=skymodel, fluxcalib=fluxcalib, alpha_only=args.alpha_only) + results, alpha = calc_tsnr2(frame,uncalibrated_frame, fiberflat=fiberflat, skymodel=skymodel, fluxcalib=fluxcalib, alpha_only=args.alpha_only) frame.meta['TSNRALPH'] = alpha From f0c8c87469193a34361eb14cc01f3a88fb75fbd8 Mon Sep 17 00:00:00 2001 From: Julien Guy Date: Fri, 23 Aug 2024 15:30:57 -0700 Subject: [PATCH 3/3] calc_tsnr2 needs cframe --- bin/desi_tsnr_afterburner | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bin/desi_tsnr_afterburner b/bin/desi_tsnr_afterburner index 7faa77015..2a03dedb1 100755 --- a/bin/desi_tsnr_afterburner +++ b/bin/desi_tsnr_afterburner @@ -210,12 +210,13 @@ def compute_tsnr_values(cframe_filename,cframe_hdulist,night,expid,camera,specpr sky = cframe_filename.replace('cframe', 'sky') psf = cframe_filename.replace('cframe', 'psf') + cframe=read_frame(cframe_filename, skip_resolution=True) frame=read_frame(iin, skip_resolution=True) fiberflat=read_fiberflat(flat) fluxcalib=read_flux_calibration(calib) skymodel=read_sky(sky) - results, alpha = calc_tsnr2(frame, fiberflat=fiberflat, + results, alpha = calc_tsnr2(cframe, frame, fiberflat=fiberflat, skymodel=skymodel, fluxcalib=fluxcalib, alpha_only=alpha_only) table=Table()