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-42979: Use calibFlux for source selector #983

Merged
merged 3 commits into from
Jan 15, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/lsst/pipe/tasks/calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ def setDefaults(self):
# Keep sky sources in the output catalog, even though they aren't
# wanted for calibration.
self.star_selector["science"].doSkySources = True
# Set the flux and error fields
self.star_selector["science"].signalToNoise.fluxField = "slot_CalibFlux_instFlux"
self.star_selector["science"].signalToNoise.errField = "slot_CalibFlux_instFluxErr"

# Use the affine WCS fitter (assumes we have a good camera geometry).
self.astrometry.wcsFitter.retarget(lsst.meas.astrom.FitAffineWcsTask)
Expand Down Expand Up @@ -986,6 +989,9 @@ def _fit_photometry(self, exposure, stars):
unchanged.
stars : `lsst.afw.table.SourceCatalog`
Good stars selected for use in calibration.
background : `lsst.afw.math.BackgroundList`
Background that was fit to the exposure during detection of the
above stars.

Returns
-------
Expand Down
18 changes: 12 additions & 6 deletions python/lsst/pipe/tasks/photoCal.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ def validate(self):
raise RuntimeError("applyColorTerms=True requires photoCatName is non-None")
if self.applyColorTerms and len(self.colorterms.data) == 0:
raise RuntimeError("applyColorTerms=True requires colorterms be provided")
if self.fluxField != self.match.sourceSelection.signalToNoise.fluxField:
raise RuntimeError("Configured flux field %s does not match source selector field %s",
self.fluxField, self.match.sourceSelection.signalToNoise.fluxField)
if self.fluxField + "Err" != self.match.sourceSelection.signalToNoise.errField:
raise RuntimeError("Configured flux field %sErr does not match source selector error field %s",
self.fluxField, self.match.sourceSelection.signalToNoise.errField)

def setDefaults(self):
pexConf.Config.setDefaults(self)
Expand All @@ -114,6 +120,10 @@ def setDefaults(self):
"base_PixelFlags_flag_saturated",
]
self.match.sourceSelection.doUnresolved = True
self.match.sourceSelection.doSignalToNoise = True
self.match.sourceSelection.signalToNoise.minimum = 10.0
self.match.sourceSelection.signalToNoise.fluxField = self.fluxField
self.match.sourceSelection.signalToNoise.errField = self.fluxField + "Err"


class PhotoCalTask(pipeBase.Task):
Expand Down Expand Up @@ -322,12 +332,8 @@ def run(self, exposure, sourceCat, expId=0):
----------
exposure : `lsst.afw.image.Exposure`
Exposure upon which the sources in the matches were detected.
sourceCat : `lsst.afw.image.SourceCatalog`
A catalog of sources to use in the calibration
(i.e. a `list` of `lsst.afw.table.Match` with
first being of type `lsst.afw.table.SimpleRecord` and second type `lsst.afw.table.SourceRecord`
the reference object and matched object respectively).
Will not be modified except to set the outputField if requested.
sourceCat : `lsst.afw.table.SourceCatalog`
Good stars selected for use in calibration.
expId : `int`, optional
Exposure ID.

Expand Down
8 changes: 4 additions & 4 deletions tests/test_calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _check_run(self, calibrate, result, expect_calibrated_pixels: bool = True):
self.assertEqual(result.stars["slot_PsfFlux_mag"].unit, u.ABmag)

# Should have detected all S/N >= 10 sources plus 2 sky sources, whether 1 or 2 snaps.
self.assertEqual(len(result.stars), 7)
self.assertEqual(len(result.stars), 6)
# Did the psf flags get propagated from the psf_stars catalog?
self.assertEqual(result.stars["calib_psf_used"].sum(), 3)

Expand Down Expand Up @@ -319,7 +319,7 @@ def test_find_stars(self):

# Only 5 psf-like sources with S/N>10 should be in the output catalog,
# plus two sky sources.
self.assertEqual(len(stars), 7)
self.assertEqual(len(stars), 6)
self.assertTrue(stars.isContiguous())
# Sort in order of brightness, to easily compare with expected positions.
stars.sort(stars.getPsfFluxSlot().getMeasKey())
Expand Down Expand Up @@ -420,8 +420,8 @@ def test_match_psf_stars(self):
# sort() above leaves the catalog non-contiguous.
stars = stars.copy(deep=True)
np.testing.assert_array_equal(stars["calib_psf_candidate"],
[False, False, False, False, True, True, True])
np.testing.assert_array_equal(stars["calib_psf_used"], [False, False, False, False, True, True, True])
[False, False, False, True, True, True])
np.testing.assert_array_equal(stars["calib_psf_used"], [False, False, False, True, True, True])
# Too few sources to reserve any in these tests.
self.assertEqual(stars["calib_psf_reserved"].sum(), 0)

Expand Down
2 changes: 2 additions & 0 deletions tests/test_photoCal.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ def setUp(self):
# The test and associated data have been prepared on the basis that we
# use the PsfFlux to perform photometry.
self.config.fluxField = "base_PsfFlux_instFlux"
self.config.match.sourceSelection.signalToNoise.fluxField = "base_PsfFlux_instFlux"
self.config.match.sourceSelection.signalToNoise.errField = "base_PsfFlux_instFluxErr"

def tearDown(self):
del self.srcCat
Expand Down
Loading