Skip to content

Commit

Permalink
sourceSelector: add selection by magnitude error
Browse files Browse the repository at this point in the history
If you've got only a magnitude (not flux), you can't use the
SignalToNoiseLimit without some modification. However, for
magnitudes the error is the inverse of the signal-to-noise
ratio, so we can just put a limit on that.
  • Loading branch information
PaulPrice committed Dec 7, 2017
1 parent 04656fe commit c295f05
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
35 changes: 35 additions & 0 deletions python/lsst/meas/algorithms/sourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,37 @@ def apply(self, catalog):
return selected


class MagnitudeErrorLimit(BaseLimit):
"""Select sources using a magnitude error limit
Because the magnitude error is the inverse of the signal-to-noise
ratio, this also works to select sources by signal-to-noise when
you only have a magnitude.
This object can be used as a `lsst.pex.config.Config` for configuring
the limit, and then the `apply` method can be used to identify sources
in the catalog that match the configured limit.
"""
magErrField = pexConfig.Field(dtype=str, default="mag_err",
doc="Name of the source flux error field to use.")

def apply(self, catalog):
"""Apply the magnitude limit to a catalog
Parameters
----------
catalog : `lsst.afw.table.SourceCatalog`
Source to which to apply limits.
Returns
-------
selected : `numpy.ndarray`
Boolean array indicating whether each source is selected
(True means selected).
"""
return BaseLimit.apply(self, catalog[self.magErrField])


class RequireFlags(pexConfig.Config):
"""Select sources using flags
Expand Down Expand Up @@ -425,9 +456,11 @@ class ReferenceSourceSelectorConfig(pexConfig.Config):
doMagLimit = pexConfig.Field(dtype=bool, default=False, doc="Apply magnitude limit?")
doFlags = pexConfig.Field(dtype=bool, default=False, doc="Apply flag limitation?")
doSignalToNoise = pexConfig.Field(dtype=bool, default=False, doc="Apply signal-to-noise limit?")
doMagError = pexConfig.Field(dtype=bool, default=False, doc="Apply magnitude error limit?")
magLimit = pexConfig.ConfigField(dtype=MagnitudeLimit, doc="Magnitude limit to apply")
flags = pexConfig.ConfigField(dtype=RequireFlags, doc="Flags to require")
signalToNoise = pexConfig.ConfigField(dtype=SignalToNoiseLimit, doc="Signal-to-noise limit to apply")
magError = pexConfig.ConfigField(dtype=MagnitudeErrorLimit, doc="Magnitude error limit to apply")
colorLimits = pexConfig.ConfigDictField(keytype=str, itemtype=ColorLimit, default={},
doc="Color limits to apply; key is used as a label only")

Expand Down Expand Up @@ -462,6 +495,8 @@ def selectSources(self, catalog, matches=None):
selected &= self.config.flags.apply(catalog)
if self.config.doSignalToNoise:
selected &= self.config.signalToNoise.apply(catalog)
if self.config.doMagError:
selected &= self.config.magError.apply(catalog)
for limit in self.config.colorLimits.values():
selected &= limit.apply(catalog)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_sourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,22 @@ def testMagnitudeLimit(self):
self.config.magLimit.maximum = None
self.check([True, True, False, True])

def testMagErrorLimit(self):
field = "flux_err"
# Note: using a field named "flux_err" as if it was a magnitude to save adding a new field
tooFaint = self.catalog.addNew()
tooFaint.set(field, 0.5)
tooBright = self.catalog.addNew()
tooBright.set(field, 0.00001)
good = self.catalog.addNew()
good.set(field, 0.2)

self.config.doMagError = True
self.config.magError.minimum = 0.01
self.config.magError.maximum = 0.3
self.config.magError.magErrField = field
self.check([False, False, True])

def testColorLimits(self):
num = 10
for _ in range(num):
Expand Down

0 comments on commit c295f05

Please sign in to comment.