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-40064: Add configuration to override default psfex reference flux. #72

Merged
merged 2 commits into from
Sep 20, 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
8 changes: 8 additions & 0 deletions python/lsst/meas/extensions/psfex/psfexPsfDeterminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class PsfexPsfDeterminerConfig(measAlg.BasePsfDeterminerConfig):
doc="Should PSFEX be permitted to recentroid PSF candidates?",
default=False,
)
photometricFluxField = pexConfig.Field[str](
doc="Flux field to use for photometric normalization. This overrides the "
"``PHOTFLUX_KEY`` field for psfex. The associated flux error is "
"derived by appending ``Err`` to this field.",
default="base_CircularApertureFlux_9_0_instFlux",
erykoff marked this conversation as resolved.
Show resolved Hide resolved
)

def setDefaults(self):
super().setDefaults()
Expand Down Expand Up @@ -192,6 +198,8 @@ def determinePsf(self, exposure, psfCandidateList, metadata=None, flagKey=None):
args_md.set("PSFVAR_DEGREES", str(self.config.spatialOrder))
args_md.set("PSF_SIZE", str(actualKernelSize))
args_md.set("PSF_SAMPLING", str(self.config.samplingSize))
args_md.set("PHOTFLUX_KEY", str(self.config.photometricFluxField))
args_md.set("PHOTFLUXERR_KEY", str(self.config.photometricFluxField) + "Err")
prefs = psfex.Prefs(defaultsFile, args_md)
prefs.setCommandLine([])
prefs.addCatalog("psfexPsfDeterminer")
Expand Down
19 changes: 18 additions & 1 deletion tests/test_PsfexPsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def tearDown(self):
del self.schema
del self.measureSources

def setupDeterminer(self, exposure):
def setupDeterminer(self, exposure, fluxField=None):
"""Setup the starSelector and psfDeterminer"""
starSelectorClass = measAlg.sourceSelectorRegistry["objectSize"]
starSelectorConfig = starSelectorClass.ConfigClass()
Expand All @@ -221,6 +221,8 @@ def setupDeterminer(self, exposure):
psfDeterminerConfig.sizeCellX = width
psfDeterminerConfig.sizeCellY = height//3
psfDeterminerConfig.spatialOrder = 1
if fluxField is not None:
psfDeterminerConfig.photometricFluxField = fluxField

self.psfDeterminer = psfDeterminerClass(psfDeterminerConfig)

Expand Down Expand Up @@ -284,6 +286,21 @@ def testPsfexDeterminerTooFewStars(self):
with self.assertRaisesRegex(RuntimeError, "Failed to determine"):
psf, cellSet = self.psfDeterminer.determinePsf(self.exposure, psfCandidateListShort, metadata)

def testPsfDeterminerChangeFluxField(self):
"""Test the psfDeterminer with a different flux normalization field."""
# We test here with an aperture that we would be unlikely to ever use
# as a default.
self.setupDeterminer(self.exposure, fluxField="base_CircularApertureFlux_6_0_instFlux")
metadata = dafBase.PropertyList()

stars = self.starSelector.run(self.catalog, exposure=self.exposure)
psfCandidateList = self.makePsfCandidates.run(stars.sourceCat, exposure=self.exposure).psfCandidates
psf, cellSet = self.psfDeterminer.determinePsf(self.exposure, psfCandidateList, metadata)
self.exposure.setPsf(psf)

# Test how well we can subtract the PSF model
self.subtractStars(self.exposure, self.catalog, chi_lim=5.6)


class TestMemory(lsst.utils.tests.MemoryTestCase):
pass
Expand Down