Skip to content

Commit

Permalink
Fix score image non-finite value handling avoiding comparision of non…
Browse files Browse the repository at this point in the history
…-finites and replace them with zero score.
  • Loading branch information
Gabor Kovacs committed Aug 20, 2020
1 parent dd5c15c commit 996bac3
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions python/lsst/ip/diffim/zogy.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def inverseFftAndCropImage(self, imgArr, origSize, filtInf=None, filtNaN=None, d
origSize : `tuple` of `int`
Original unpadded shape tuple of the image to be cropped to.
filtInf, filtNan : `numpy.ndarray` of indices, optional
filtInf, filtNan : `numpy.ndarray` of bool or int, optional
If specified, they are used as index arrays for ``result`` to set values to
`numpy.inf` and `numpy.nan` respectively at these positions.
Expand Down Expand Up @@ -785,26 +785,31 @@ def makeDiffimSubExposure(self, ftDiff):

if ftDiff.S is not None:
S = self.inverseFftAndCropImage(
ftDiff.S, self.imgShape, np.logical_or(self.fftFullIm1.filtInf, self.fftFullIm2.filtInf),
np.logical_or(self.fftFullIm1.filtNaN, self.fftFullIm2.filtNaN),
dtype=self.subExposure1.image.dtype)
ftDiff.S, self.imgShape, dtype=self.subExposure1.image.dtype)
varPlaneS = self.inverseFftAndCropImage(
ftDiff.varPlaneS, self.imgShape,
np.logical_or(self.fftVarPl1.filtInf, self.fftVarPl2.filtInf),
np.logical_or(self.fftVarPl1.filtNaN, self.fftVarPl2.filtNaN),
dtype=self.subExposure1.variance.dtype)
ftDiff.varPlaneS, self.imgShape, dtype=self.subExposure1.variance.dtype)

# There is no detection where the image or its variance was not finite
flt = np.logical_or(self.fftFullIm1.filtInf, self.fftFullIm2.filtInf)
flt = np.logical_or(flt, self.fftFullIm1.filtNaN)
flt = np.logical_or(flt, self.fftFullIm2.filtNaN)
flt = np.logical_or(flt, self.fftVarPl1.filtInf)
flt = np.logical_or(flt, self.fftVarPl2.filtInf)
flt = np.logical_or(flt, self.fftVarPl1.filtNaN)
flt = np.logical_or(flt, self.fftVarPl2.filtNaN)
tiny = np.finfo(varPlaneS.dtype).tiny * 100
# Ensure that no division by 0 occurs in S/sigma(S).
# S is set to be always finite, 0 where pixels non-finite
flt = np.logical_or(flt, varPlaneS < tiny)
varPlaneS[flt] = 1
S[flt] = 0

imgS = afwImage.Image(S, deep=False, xy0=xy0, dtype=self.subExposure1.image.dtype)
imgVarPlaneS = afwImage.Image(varPlaneS, deep=False, xy0=xy0,
dtype=self.subExposure1.variance.dtype)
imgS = imgS[bbox]
imgVarPlaneS = imgVarPlaneS[bbox]

# Ensure that no 0/0 occur in S/sigma(S).
tiny = np.finfo(varPlaneS.dtype).tiny * 10
fltZero = imgVarPlaneS.array < tiny
imgVarPlaneS.array[fltZero] = tiny
imgS.array[fltZero] = 0

# PSF of S
Ps = self.inverseFftAndCropImage(ftDiff.Ps, self.psfShape1, dtype=self.subExpPsf1.dtype)
sumPs = np.sum(Ps)
Expand Down

0 comments on commit 996bac3

Please sign in to comment.