LSST Applications 26.0.0,g0265f82a02+6660c170cc,g07994bdeae+30b05a742e,g0a0026dc87+17526d298f,g0a60f58ba1+17526d298f,g0e4bf8285c+96dd2c2ea9,g0ecae5effc+c266a536c8,g1e7d6db67d+6f7cb1f4bb,g26482f50c6+6346c0633c,g2bbee38e9b+6660c170cc,g2cc88a2952+0a4e78cd49,g3273194fdb+f6908454ef,g337abbeb29+6660c170cc,g337c41fc51+9a8f8f0815,g37c6e7c3d5+7bbafe9d37,g44018dc512+6660c170cc,g4a941329ef+4f7594a38e,g4c90b7bd52+5145c320d2,g58be5f913a+bea990ba40,g635b316a6c+8d6b3a3e56,g67924a670a+bfead8c487,g6ae5381d9b+81bc2a20b4,g93c4d6e787+26b17396bd,g98cecbdb62+ed2cb6d659,g98ffbb4407+81bc2a20b4,g9ddcbc5298+7f7571301f,ga1e77700b3+99e9273977,gae46bcf261+6660c170cc,gb2715bf1a1+17526d298f,gc86a011abf+17526d298f,gcf0d15dbbd+96dd2c2ea9,gdaeeff99f8+0d8dbea60f,gdb4ec4c597+6660c170cc,ge23793e450+96dd2c2ea9,gf041782ebf+171108ac67
LSST Data Management Base Package
Loading...
Searching...
No Matches
matcherSourceSelector.py
Go to the documentation of this file.
1# This file is part of meas_algorithms.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21
22__all__ = ["MatcherSourceSelectorConfig", "MatcherSourceSelectorTask"]
23
24import numpy as np
25
26import lsst.pex.config as pexConfig
27from .sourceSelector import BaseSourceSelectorConfig, BaseSourceSelectorTask, sourceSelectorRegistry
28from lsst.pipe.base import Struct
29
30
32 sourceFluxType = pexConfig.Field(
33 doc="Type of source flux; typically one of Ap or Psf",
34 dtype=str,
35 default="Ap",
36 )
37 minSnr = pexConfig.Field(
38 dtype=float,
39 doc="Minimum allowed signal-to-noise ratio for sources used for matching "
40 "(in the flux specified by sourceFluxType); <= 0 for no limit",
41 default=40,
42 )
43 excludePixelFlags = pexConfig.Field(
44 dtype=bool,
45 doc="Exclude objects that have saturated, interpolated, or edge "
46 "pixels using PixelFlags. For matchOptimisticB set this to False "
47 "to recover previous matcher selector behavior.",
48 default=True,
49 )
50
51
52@pexConfig.registerConfigurable("matcher", sourceSelectorRegistry)
54 """Select sources that are useful for matching.
55
56 Good matching sources have high signal/noise, are non-blended. They need not
57 be PSF sources, just have reliable centroids.
58
59 Distinguished from astrometrySourceSelector because it is more lenient
60 (i.e. not checking footprints or bad flags).
61 """
62 ConfigClass = MatcherSourceSelectorConfig
63
64 def __init__(self, *args, **kwargs):
65 BaseSourceSelectorTask.__init__(self, *args, **kwargs)
66
67 def selectSources(self, sourceCat, matches=None, exposure=None):
68 """Return a selection of sources that are useful for matching.
69
70 Parameters
71 ----------
73 Catalog of sources to select from.
74 This catalog must be contiguous in memory.
75 matches : `list` of `lsst.afw.table.ReferenceMatch` or None
76 Ignored in this SourceSelector.
77 exposure : `lsst.afw.image.Exposure` or None
78 The exposure the catalog was built from; used for debug display.
79
80 Returns
81 -------
82 struct : `lsst.pipe.base.Struct`
83 The struct contains the following data:
84
85 ``selected``
86 Boolean array of sources that were selected, same length as
87 sourceCat. (`numpy.ndarray` of `bool`)
88 """
89 self._getSchemaKeys(sourceCat.schema)
90
91 good = self._isUsable(sourceCat)
92 if self.config.excludePixelFlags:
93 good = good & self._isGood(sourceCat)
94 return Struct(selected=good)
95
96 def _getSchemaKeys(self, schema):
97 """Extract and save the necessary keys from schema with asKey.
98 """
99 self.parentKey = schema["parent"].asKey()
100 self.centroidXKey = schema["slot_Centroid_x"].asKey()
101 self.centroidYKey = schema["slot_Centroid_y"].asKey()
102 self.centroidFlagKey = schema["slot_Centroid_flag"].asKey()
103
104 fluxPrefix = "slot_%sFlux_" % (self.config.sourceFluxType,)
105 self.fluxField = fluxPrefix + "instFlux"
106 self.fluxKey = schema[fluxPrefix + "instFlux"].asKey()
107 self.fluxFlagKey = schema[fluxPrefix + "flag"].asKey()
108 self.fluxErrKey = schema[fluxPrefix + "instFluxErr"].asKey()
109
110 self.edgeKey = schema["base_PixelFlags_flag_edge"].asKey()
111 self.interpolatedCenterKey = schema["base_PixelFlags_flag_interpolatedCenter"].asKey()
112 self.saturatedKey = schema["base_PixelFlags_flag_saturated"].asKey()
113
114 def _isParent(self, sourceCat):
115 """Return True for each source that is the parent source.
116 """
117 test = (sourceCat[self.parentKey] == 0)
118 return test
119
120 def _hasCentroid(self, sourceCat):
121 """Return True for each source that has a valid centroid
122 """
123 return np.isfinite(sourceCat[self.centroidXKey]) \
124 & np.isfinite(sourceCat[self.centroidYKey]) \
125 & ~sourceCat[self.centroidFlagKey]
126
127 def _goodSN(self, sourceCat):
128 """Return True for each source that has Signal/Noise > config.minSnr.
129 """
130 if self.config.minSnr <= 0:
131 return True
132 else:
133 with np.errstate(invalid="ignore"): # suppress NAN warnings
134 return sourceCat[self.fluxKey]/sourceCat[self.fluxErrKey] > self.config.minSnr
135
136 def _isUsable(self, sourceCat):
137 """
138 Return True for each source that is usable for matching, even if it may
139 have a poor centroid.
140
141 For a source to be usable it must:
142
143 - have a valid centroid
144 - not be deblended
145 - have a valid instFlux (of the type specified in this object's constructor)
146 - have adequate signal-to-noise
147 """
148 return self._hasCentroid(sourceCat) \
149 & self._isParent(sourceCat) \
150 & self._goodSN(sourceCat) \
151 & ~sourceCat[self.fluxFlagKey]
152
153 def _isGood(self, sourceCat):
154 """
155 Return True for each source that is usable for matching, even if it may
156 have a poor centroid.
157
158 For a source to be usable it must:
159
160 - Not be on a CCD edge.
161 - Not have an interpolated pixel within 3x3 around their centroid.
162 - Not have a saturated pixel in their footprint.
163 """
164 return ~sourceCat[self.edgeKey] & \
165 ~sourceCat[self.interpolatedCenterKey] & \
166 ~sourceCat[self.saturatedKey]
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Definition Exposure.h:72
Lightweight representation of a geometric match between two records.
Definition Match.h:67