Skip to content

Commit

Permalink
Fix bug in deblending diaSources with negative fluxes.
Browse files Browse the repository at this point in the history
This does not fix a separate footprint merging bug.
  • Loading branch information
mrawls committed Jan 29, 2025
1 parent ce7788e commit c6874a2
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions python/lsst/ip/diffim/detectAndMeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,35 @@ def makeFootprints(sources):
footprints.setFootprints([src.getFootprint() for src in sources])
return footprints

def deblend(footprints):
def deblend(footprints, negative=False):
"""Deblend a positive or negative footprint set,
and return the deblended children.
Parameters
----------
footprints : `lsst.afw.detection.FootprintSet`
negative : `bool`
Set True if the footprints contain negative fluxes
Returns
-------
sources : `lsst.afw.table.SourceCatalog`
"""
sources = afwTable.SourceCatalog(self.schema)
footprints.makeSources(sources)
self.deblend.run(exposure=difference, sources=sources)
if negative:
# Invert the image so the deblender can run on positive peaks
difference_inverted = difference.clone()
difference_inverted.image *= -1
self.deblend.run(exposure=difference_inverted, sources=sources)
children = sources[sources["parent"] != 0]
# Set the heavy footprint pixel values back to reality
for child in children:
footprint = child.getFootprint()
array = footprint.getImageArray()
array *= -1
else:
self.deblend.run(exposure=difference, sources=sources)
self.setPrimaryFlags.run(sources)
children = sources["detect_isDeblendedSource"] == 1
sources = sources[children].copy(deep=True)
Expand All @@ -541,7 +563,7 @@ def deblend(footprints):
return sources.copy(deep=True)

positives = deblend(positiveFootprints)
negatives = deblend(negativeFootprints)
negatives = deblend(negativeFootprints, negative=True)

sources = afwTable.SourceCatalog(self.schema)
sources.reserve(len(positives) + len(negatives))
Expand Down

0 comments on commit c6874a2

Please sign in to comment.