Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions python/lsst/ip/diffim/getTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,9 @@ def _merge(self, maskedImages, bbox, wcs):
merged = afwImage.ExposureF(bbox, wcs)
weights = afwImage.ImageF(bbox)
for maskedImage in maskedImages:
weight = afwImage.ImageF(maskedImage.variance.array**(-0.5))
goodPix = maskedImage.variance.array > 0
weight = afwImage.ImageF(maskedImage.getBBox())
weight.array[goodPix] = maskedImage.variance.array[goodPix]**(-0.5)
bad = np.isnan(maskedImage.image.array) | ~np.isfinite(maskedImage.variance.array)
# Note that modifying the patch MaskedImage in place is fine;
# we're throwing it away at the end anyway.
Expand All @@ -419,9 +421,13 @@ def _merge(self, maskedImages, bbox, wcs):
# Cannot use `merged.maskedImage /= weights` because that operator
# divides the variance by the weight twice; in this case `weights` are
# the exact values we want to scale by.
merged.image /= weights
merged.variance /= weights
merged.mask.array |= merged.mask.getPlaneBitMask("NO_DATA") * (weights.array == 0)
invWeights = np.zeros_like(weights.array)
goodPix = weights.array > 0
invWeights[goodPix] = 1/weights.array[goodPix]

merged.image.array *= invWeights
merged.variance.array *= invWeights
merged.mask.array |= merged.mask.getPlaneBitMask("NO_DATA") * (invWeights == 0)

return merged

Expand Down
4 changes: 1 addition & 3 deletions tests/test_getTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ def testMissingPatches(self):
dataIds=self.dataIds,
physical_filter="a_test")
no_data = (result.template.mask.array & result.template.mask.getPlaneBitMask("NO_DATA")) != 0
self.assertTrue(all(np.isnan(result.template.image.array[no_data])))
self.assertTrue(all(np.isnan(result.template.variance.array[no_data])))
self.assertEqual(no_data.sum(), 21548)
self.assertEqual(no_data.sum(), 20990)


def setup_module(module):
Expand Down