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-39828: Use 'Catalog.__getitem__' instead of 'get' in selectors. #343

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 14 additions & 14 deletions python/lsst/meas/algorithms/astrometrySourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def selectSources(self, sourceCat, matches=None, exposure=None):
"""
self._getSchemaKeys(sourceCat.schema)

bad = reduce(lambda x, y: np.logical_or(x, sourceCat.get(y)), self.config.badFlags, False)
bad = reduce(lambda x, y: np.logical_or(x, sourceCat[y]), self.config.badFlags, False)
good = self._isGood(sourceCat)
return Struct(selected=good & ~bad)

Expand Down Expand Up @@ -130,7 +130,7 @@ def _getSchemaKeys(self, schema):
def _isMultiple(self, sourceCat):
"""Return True for each source that is likely multiple sources.
"""
test = (sourceCat.get(self.parentKey) != 0) | (sourceCat.get(self.nChildKey) != 0)
test = (sourceCat[self.parentKey] != 0) | (sourceCat[self.nChildKey] != 0)
# have to currently manage footprints on a source-by-source basis.
for i, cat in enumerate(sourceCat):
footprint = cat.getFootprint()
Expand All @@ -143,13 +143,13 @@ def _hasCentroid(self, sourceCat):
def checkNonfiniteCentroid():
"""Return True for sources with non-finite centroids.
"""
return ~np.isfinite(sourceCat.get(self.centroidXKey)) | \
~np.isfinite(sourceCat.get(self.centroidYKey))
return ~np.isfinite(sourceCat[self.centroidXKey]) | \
~np.isfinite(sourceCat[self.centroidYKey])
assert ~checkNonfiniteCentroid().any(), \
"Centroids not finite for %d unflagged sources." % (checkNonfiniteCentroid().sum())
return np.isfinite(sourceCat.get(self.centroidXErrKey)) \
& np.isfinite(sourceCat.get(self.centroidYErrKey)) \
& ~sourceCat.get(self.centroidFlagKey)
return np.isfinite(sourceCat[self.centroidXErrKey]) \
& np.isfinite(sourceCat[self.centroidYErrKey]) \
& ~sourceCat[self.centroidFlagKey]

def _goodSN(self, sourceCat):
"""Return True for each source that has Signal/Noise > config.minSnr.
Expand All @@ -158,7 +158,7 @@ def _goodSN(self, sourceCat):
return True
else:
with np.errstate(invalid="ignore"): # suppress NAN warnings
return sourceCat.get(self.instFluxKey)/sourceCat.get(self.instFluxErrKey) > self.config.minSnr
return sourceCat[self.instFluxKey]/sourceCat[self.instFluxErrKey] > self.config.minSnr

def _isUsable(self, sourceCat):
"""Return True for each source that is usable for matching, even if it may
Expand All @@ -174,13 +174,13 @@ def _isUsable(self, sourceCat):
return self._hasCentroid(sourceCat) \
& ~self._isMultiple(sourceCat) \
& self._goodSN(sourceCat) \
& ~sourceCat.get(self.fluxFlagKey)
& ~sourceCat[self.fluxFlagKey]

def _isPrimary(self, sourceCat):
"""Return True if this is a primary source.
"""
if self.primaryKey:
return sourceCat.get(self.primaryKey)
return sourceCat[self.primaryKey]
else:
return np.ones(len(sourceCat), dtype=bool)

Expand All @@ -196,11 +196,11 @@ def _isGood(self, sourceCat):

return self._isUsable(sourceCat) \
& self._isPrimary(sourceCat) \
& ~sourceCat.get(self.saturatedKey) \
& ~sourceCat.get(self.interpolatedCenterKey) \
& ~sourceCat.get(self.edgeKey)
& ~sourceCat[self.saturatedKey] \
& ~sourceCat[self.interpolatedCenterKey] \
& ~sourceCat[self.edgeKey]

def _isBadFlagged(self, source):
"""Return True if any of config.badFlags are set for this source.
"""
return any(source.get(flag) for flag in self.config.badFlags)
return any(source[flag] for flag in self.config.badFlags)
2 changes: 1 addition & 1 deletion python/lsst/meas/algorithms/flaggedSourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ def selectSources(self, sourceCat, matches=None, exposure=None):
``sourceCat``. (`numpy.ndarray` of `bool`)
"""
key = sourceCat.schema.find(self.config.field).key
return pipeBase.Struct(selected=sourceCat.get(key))
return pipeBase.Struct(selected=sourceCat[key])
18 changes: 9 additions & 9 deletions python/lsst/meas/algorithms/matcherSourceSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ def _getSchemaKeys(self, schema):
def _isParent(self, sourceCat):
"""Return True for each source that is the parent source.
"""
test = (sourceCat.get(self.parentKey) == 0)
test = (sourceCat[self.parentKey] == 0)
return test

def _hasCentroid(self, sourceCat):
"""Return True for each source that has a valid centroid
"""
return np.isfinite(sourceCat.get(self.centroidXKey)) \
& np.isfinite(sourceCat.get(self.centroidYKey)) \
& ~sourceCat.get(self.centroidFlagKey)
return np.isfinite(sourceCat[self.centroidXKey]) \
& np.isfinite(sourceCat[self.centroidYKey]) \
& ~sourceCat[self.centroidFlagKey]

def _goodSN(self, sourceCat):
"""Return True for each source that has Signal/Noise > config.minSnr.
Expand All @@ -133,7 +133,7 @@ def _goodSN(self, sourceCat):
return True
else:
with np.errstate(invalid="ignore"): # suppress NAN warnings
return sourceCat.get(self.fluxKey)/sourceCat.get(self.fluxErrKey) > self.config.minSnr
return sourceCat[self.fluxKey]/sourceCat[self.fluxErrKey] > self.config.minSnr

def _isUsable(self, sourceCat):
"""
Expand All @@ -150,7 +150,7 @@ def _isUsable(self, sourceCat):
return self._hasCentroid(sourceCat) \
& self._isParent(sourceCat) \
& self._goodSN(sourceCat) \
& ~sourceCat.get(self.fluxFlagKey)
& ~sourceCat[self.fluxFlagKey]

def _isGood(self, sourceCat):
"""
Expand All @@ -163,6 +163,6 @@ def _isGood(self, sourceCat):
- Not have an interpolated pixel within 3x3 around their centroid.
- Not have a saturated pixel in their footprint.
"""
return ~sourceCat.get(self.edgeKey) & \
~sourceCat.get(self.interpolatedCenterKey) & \
~sourceCat.get(self.saturatedKey)
return ~sourceCat[self.edgeKey] & \
~sourceCat[self.interpolatedCenterKey] & \
~sourceCat[self.saturatedKey]
6 changes: 3 additions & 3 deletions python/lsst/meas/algorithms/objectSizeStarSelector.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ def selectSources(self, sourceCat, matches=None, exposure=None):
#
# Look at the distribution of stars in the magnitude-size plane
#
flux = sourceCat.get(self.config.sourceFluxField)
fluxErr = sourceCat.get(self.config.sourceFluxField + "Err")
flux = sourceCat[self.config.sourceFluxField]
fluxErr = sourceCat[self.config.sourceFluxField + "Err"]

xx = numpy.empty(len(sourceCat))
xy = numpy.empty_like(xx)
Expand All @@ -386,7 +386,7 @@ def selectSources(self, sourceCat, matches=None, exposure=None):

width = numpy.sqrt(0.5*(xx + yy))
with numpy.errstate(invalid="ignore"): # suppress NAN warnings
bad = reduce(lambda x, y: numpy.logical_or(x, sourceCat.get(y)), self.config.badFlags, False)
bad = reduce(lambda x, y: numpy.logical_or(x, sourceCat[y]), self.config.badFlags, False)
bad = numpy.logical_or(bad, numpy.logical_not(numpy.isfinite(width)))
bad = numpy.logical_or(bad, numpy.logical_not(numpy.isfinite(flux)))
if self.config.doFluxLimit:
Expand Down