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-30046: Defer reading refcats in forcedPhotCcd #177

Merged
merged 1 commit into from
May 26, 2021
Merged
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
15 changes: 11 additions & 4 deletions python/lsst/meas/base/forcedPhotCcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ class ForcedPhotCcdConnections(PipelineTaskConnections,
name="{inputCoaddName}Coadd_ref",
storageClass="SourceCatalog",
dimensions=["skymap", "tract", "patch"],
multiple=True
multiple=True,
deferLoad=True,
)
skyMap = cT.Input(
doc="SkyMap dataset that defines the coordinate system of the reference catalog.",
Expand Down Expand Up @@ -360,8 +361,9 @@ def mergeAndFilterReferences(self, exposure, refCats, refWcs):
----------
exposure : `lsst.afw.image.exposure.Exposure`
Exposure to generate the catalog for.
refCats : sequence of `lsst.afw.table.SourceCatalog`
Catalogs of shapes and positions at which to force photometry.
refCats : sequence of `lsst.daf.butler.DeferredDatasetHandle`
Handles for catalogs of shapes and positions at which to force
photometry.
refWcs : `lsst.afw.image.SkyWcs`
Reference world coordinate system.

Expand Down Expand Up @@ -395,14 +397,19 @@ def mergeAndFilterReferences(self, exposure, refCats, refWcs):
# parents are not within the exposure boundaries. Note
# that within a single input refCat, the parents always
# appear before the children.
mergedRefCat = lsst.afw.table.SourceCatalog(refCats[0].table)
mergedRefCat = None
for refCat in refCats:
refCat = refCat.get()
if mergedRefCat is None:
mergedRefCat = lsst.afw.table.SourceCatalog(refCat.table)
containedIds = {0} # zero as a parent ID means "this is a parent"
for record in refCat:
if expPolygon.contains(record.getCoord().getVector()) and record.getParent() in containedIds:
record.setFootprint(record.getFootprint().transform(refWcs, expWcs, expRegion))
mergedRefCat.append(record)
containedIds.add(record.getId())
if mergedRefCat is None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question more than a comment - will we get here only if refCats is an empty list? Would it ever be the case where refCats have empty tables, in which case this might still have to be raised? Sure, it wasn't raised earlier, but just wondering.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, reading it I think you're right, if all records are empty we wouldn't raise. I'm never quite sure what happens with empty things in general, and the best to handle it in particular. From what I gathered at discussions following DM-29862, I'm not sure there really is a standard way of dealing with such cases yet.

As you say, we never raised before anyway; this addition was just Jim figuring we might as well throw a clearer exception since we needed to change the way we handled mergedRefCat. I'm going to go ahead and merge - I'm sure we can live with postponing handling the case of empty-only records until after this weekly gets tagged :)

Thanks for the instantaneous review, Arun!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If refCats was empty, then line 398 before would have thrown an IndexError. Now, we make it throw a RuntimeError. I'm betting this doesn't make any difference, unless the file calling this was catching specific exceptions in which case that would have to be changed as well. Just wanted to point that out here.

raise RuntimeError("No reference objects for forced photometry.")
mergedRefCat.sort(lsst.afw.table.SourceTable.getParentKey())
return mergedRefCat

Expand Down