Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-41008: Update deblend_coverage for all parents #76

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 19 additions & 14 deletions python/lsst/meas/extensions/scarlet/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def updateCatalogFootprints(
modelData: scl.io.ScarletModelData,
catalog: SourceCatalog,
band: str,
imageForResdistibution: MaskedImage | Exposure | None = None,
imageForRedistribution: MaskedImage | Exposure | None = None,
removeScarletData: bool = True,
updateFluxColumns: bool = True
):
Expand All @@ -127,9 +127,9 @@ def updateCatalogFootprints(
The catalog missing heavy footprints for deblended sources.
band:
The name of the band that the catalog data describes.
imageForResdistibution:
imageForRedistribution:
The image that is the source for flux re-distribution.
If `imageForResdistibution` is `None` then flux re-distribution is
If `imageForRedistribution` is `None` then flux re-distribution is
not performed.
removeScarletData:
Whether or not to remove `ScarletBlendData` for each blend
Expand All @@ -153,13 +153,18 @@ def updateCatalogFootprints(
# no models for its sources.
continue

parent = catalog.find(parentId)
if updateFluxColumns and imageForRedistribution is not None:
# Update the data coverage (1 - # of NO_DATA pixels/# of pixels)
parentRecord["deblend_dataCoverage"] = calculateFootprintCoverage(
parent.getFootprint(),
imageForRedistribution.mask
)

if band not in blendModel.bands:
parent = catalog.find(parentId)
peaks = parent.getFootprint().peaks
# Set the footprint and coverage of the sources in this blend
# to zero
if updateFluxColumns:
parentRecord["deblend_dataCoverage"] = 0
for sourceId, sourceData in blendModel.sources.items():
sourceRecord = catalog.find(sourceId)
footprint = afwFootprint()
Expand All @@ -178,7 +183,7 @@ def updateCatalogFootprints(
blendData=blendModel,
catalog=catalog,
modelPsf=modelData.psf,
imageForResdistibution=imageForResdistibution,
imageForRedistribution=imageForRedistribution,
bandIndex=bandIndex,
parentFootprint=parentRecord.getFootprint(),
updateFluxColumns=updateFluxColumns,
Expand Down Expand Up @@ -222,7 +227,7 @@ def updateBlendRecords(
blendData: scl.io.ScarletBlendData,
catalog: SourceCatalog,
modelPsf: np.ndarray,
imageForResdistibution: MaskedImage | Exposure | None,
imageForRedistribution: MaskedImage | Exposure | None,
bandIndex: int,
parentFootprint: afwFootprint,
updateFluxColumns: bool,
Expand All @@ -239,9 +244,9 @@ def updateBlendRecords(
The 2D model of the PSF.
observedPsf:
The observed PSF model for the catalog.
imageForResdistibution:
imageForRedistribution:
The image that is the source for flux re-distribution.
If `imageForResdistibution` is `None` then flux re-distribution is
If `imageForRedistribution` is `None` then flux re-distribution is
not performed.
bandIndex:
The number of the band to extract.
Expand All @@ -253,7 +258,7 @@ def updateBlendRecords(
This should only be true when the input catalog schema already
contains those columns.
"""
useFlux = imageForResdistibution is not None
useFlux = imageForRedistribution is not None
bands = ("dummy",)

if useFlux:
Expand All @@ -263,13 +268,13 @@ def updateBlendRecords(
bbox = Box2I(xy0, extent)

images = Image(
imageForResdistibution[bbox].image.array[None, :, :],
imageForRedistribution[bbox].image.array[None, :, :],
yx0=blendData.origin,
bands=bands,
)

variance = Image(
imageForResdistibution[bbox].variance.array[None, :, :],
imageForRedistribution[bbox].variance.array[None, :, :],
yx0=blendData.origin,
bands=bands,
)
Expand Down Expand Up @@ -331,7 +336,7 @@ def updateBlendRecords(
if updateFluxColumns:
if useFlux:
# Set the fraction of pixels with valid data.
coverage = calculateFootprintCoverage(heavy, imageForResdistibution.mask)
coverage = calculateFootprintCoverage(heavy, imageForRedistribution.mask)
sourceRecord.set("deblend_dataCoverage", coverage)

# Set the flux of the scarlet model
Expand Down
8 changes: 4 additions & 4 deletions tests/test_deblend.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ def test_deblend_task(self):
coadd = self.coadds[band]

if useFlux:
imageForResdistibution = coadd
imageForRedistribution = coadd
else:
imageForResdistibution = None
imageForRedistribution = None

updateCatalogFootprints(
modelData,
catalog,
band=band,
imageForResdistibution=imageForResdistibution,
imageForRedistribution=imageForRedistribution,
removeScarletData=False,
)

Expand Down Expand Up @@ -210,7 +210,7 @@ def test_deblend_task(self):
# the image of the flux-redistributed model,
# since the HeavyFootprint may trim rows or columns.
parentFootprint = catalog[catalog["id"] == child["parent"]][0].getFootprint()
_images = imageForResdistibution[parentFootprint.getBBox()].image.array
_images = imageForRedistribution[parentFootprint.getBBox()].image.array
blend.observation.images = scl.Image(
_images[None, :, :],
yx0=blendData.origin,
Expand Down