From 43d302176d0c591c74fee38f572c5a9450fcf7c0 Mon Sep 17 00:00:00 2001 From: Julien Guy Date: Fri, 23 Aug 2024 15:16:16 -0700 Subject: [PATCH] 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():