Skip to content

Commit

Permalink
Add sky source "or" science source selection
Browse files Browse the repository at this point in the history
  • Loading branch information
parejkoj committed Feb 13, 2024
1 parent 735c6b5 commit 9afb2c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/lsst/meas/algorithms/sourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ class ScienceSourceSelectorConfig(pexConfig.Config):
doc="Apply finite sky coordinate check?")
doRequirePrimary = pexConfig.Field(dtype=bool, default=False,
doc="Apply source is primary check?")
doSkySources = pexConfig.Field(dtype=bool, default=False,
doc="Include sky sources, unioned with all other criteria?")
fluxLimit = pexConfig.ConfigField(dtype=FluxLimit, doc="Flux limit to apply")
flags = pexConfig.ConfigField(dtype=RequireFlags, doc="Flags to require")
unresolved = pexConfig.ConfigField(dtype=RequireUnresolved, doc="Star/galaxy separation to apply")
Expand All @@ -576,12 +578,14 @@ class ScienceSourceSelectorConfig(pexConfig.Config):
doc="Finite sky coordinate criteria to apply")
requirePrimary = pexConfig.ConfigField(dtype=RequirePrimary,
doc="Primary source criteria to apply")
skyFlag = pexConfig.ConfigField(dtype=RequireFlags, doc="Sky source flag to include")

def setDefaults(self):
pexConfig.Config.setDefaults(self)
self.flags.bad = ["base_PixelFlags_flag_edge", "base_PixelFlags_flag_saturated", "base_PsfFlux_flag"]
self.signalToNoise.fluxField = "base_PsfFlux_instFlux"
self.signalToNoise.errField = "base_PsfFlux_instFluxErr"
self.skyFlag.good = ["sky_source"]


@pexConfig.registerConfigurable("science", sourceSelectorRegistry)
Expand Down Expand Up @@ -634,6 +638,8 @@ def selectSources(self, sourceCat, matches=None, exposure=None):
selected &= self.config.requireFiniteRaDec.apply(sourceCat)
if self.config.doRequirePrimary:
selected &= self.config.requirePrimary.apply(sourceCat)
if self.config.doSkySources:
selected |= self.config.skyFlag.apply(sourceCat)

self.log.info("Selected %d/%d sources", selected.sum(), len(sourceCat))

Expand Down
13 changes: 13 additions & 0 deletions tests/test_sourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def setUp(self):
schema.addField("starGalaxy", float, "0=star, 1=galaxy")
schema.addField("nChild", np.int32, "Number of children")
schema.addField("detect_isPrimary", "Flag", "Is primary detection?")
schema.addField("sky_source", "Flag", "Empty sky region.")
self.catalog = lsst.afw.table.SourceCatalog(schema)
self.catalog.reserve(10)
self.config = self.Task.ConfigClass()
Expand Down Expand Up @@ -215,6 +216,18 @@ def testRequirePrimary(self):
self.config.requirePrimary.primaryColName = "detect_isPrimary"
self.check(primary.tolist())

def testSkySource(self):
num = 5
for _ in range(num):
self.catalog.addNew()
sky = np.array([True, True, False, True, False], dtype=bool)
self.catalog["sky_source"] = sky
# This is a union, not an intersection, so include another selection
# that would otherwise reject everything.
self.config.doRequirePrimary = True
self.config.doSkySources = True
self.check(sky.tolist())


class ReferenceSourceSelectorTaskTest(SourceSelectorTester, lsst.utils.tests.TestCase):
Task = lsst.meas.algorithms.ReferenceSourceSelectorTask
Expand Down

0 comments on commit 9afb2c9

Please sign in to comment.