From b7396fad631fa5fb4011ea67da26a0ca9e879cb2 Mon Sep 17 00:00:00 2001 From: "Sergey E. Koposov" Date: Thu, 3 Oct 2024 01:23:42 +0100 Subject: [PATCH] correctly deal with masked pixels when coadd()'ing i.e. the only way to get mask=0 in a pixel must be to have at least one mask=0 pixel in the stack --- py/desispec/coaddition.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/py/desispec/coaddition.py b/py/desispec/coaddition.py index ae43d3c68..21bd5c336 100644 --- a/py/desispec/coaddition.py +++ b/py/desispec/coaddition.py @@ -654,9 +654,11 @@ def coadd(spectra, cosmics_nsig=None, onetile=False) : trdata[i, :, :] = _resolution_coadd(spectra.resolution_data[b][jj], weights)[0] - tmask[i] = np.bitwise_and.reduce(spectra_mask[jj], axis=0) - # TODO This logic is broken. If the spectrum is used with weight of 0 - # the mask should get ignored + # for pixels where we found ivar=0, since we decided + # to combine data anyway we need to OR the masks to indicate issues + # for the rest of the we assume there were some good pixels + # hence the mask should stay zero + tmask[i, bad] = np.bitwise_or.reduce(spectra_mask[jj,bad], axis=0) spectra.flux[b] = tflux spectra.ivar[b] = tivar if spectra.mask is not None :