LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
matcherSourceSelector.py
Go to the documentation of this file.
2# LSST Data Management System
3#
4# Copyright 2008-2017 AURA/LSST.
5#
6# This product includes software developed by the
7# LSST Project (http://www.lsst.org/).
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 LSST License Statement and
20# the GNU General Public License along with this program. If not,
21# see <https://www.lsstcorp.org/LegalNotices/>.
22#
23
24__all__ = ["MatcherSourceSelectorConfig", "MatcherSourceSelectorTask"]
25
26import numpy as np
27
28import lsst.pex.config as pexConfig
29from .sourceSelector import BaseSourceSelectorConfig, BaseSourceSelectorTask, sourceSelectorRegistry
30from lsst.pipe.base import Struct
31
32
34 sourceFluxType = pexConfig.Field(
35 doc="Type of source flux; typically one of Ap or Psf",
36 dtype=str,
37 default="Ap",
38 )
39 minSnr = pexConfig.Field(
40 dtype=float,
41 doc="Minimum allowed signal-to-noise ratio for sources used for matching "
42 "(in the flux specified by sourceFluxType); <= 0 for no limit",
43 default=40,
44 )
45 excludePixelFlags = pexConfig.Field(
46 dtype=bool,
47 doc="Exclude objects that have saturated, interpolated, or edge "
48 "pixels using PixelFlags. For matchOptimisticB set this to False "
49 "to recover previous matcher selector behavior.",
50 default=True,
51 )
52
53
54@pexConfig.registerConfigurable("matcher", sourceSelectorRegistry)
56 """Select sources that are useful for matching.
57
58 Good matching sources have high signal/noise, are non-blended. They need not
59 be PSF sources, just have reliable centroids.
60
61 Distinguished from astrometrySourceSelector because it is more lenient
62 (i.e. not checking footprints or bad flags).
63 """
64 ConfigClass = MatcherSourceSelectorConfig
65
66 def __init__(self, *args, **kwargs):
67 BaseSourceSelectorTask.__init__(self, *args, **kwargs)
68
69 def selectSources(self, sourceCat, matches=None, exposure=None):
70 """Return a selection of sources that are useful for matching.
71
72 Parameters
73 ----------
75 Catalog of sources to select from.
76 This catalog must be contiguous in memory.
77 matches : `list` of `lsst.afw.table.ReferenceMatch` or None
78 Ignored in this SourceSelector.
79 exposure : `lsst.afw.image.Exposure` or None
80 The exposure the catalog was built from; used for debug display.
81
82 Returns
83 -------
84 struct : `lsst.pipe.base.Struct`
85 The struct contains the following data:
86
87 ``selected``
88 Boolean array of sources that were selected, same length as
89 sourceCat. (`numpy.ndarray` of `bool`)
90 """
91 self._getSchemaKeys(sourceCat.schema)
92
93 good = self._isUsable(sourceCat)
94 if self.config.excludePixelFlags:
95 good = good & self._isGood(sourceCat)
96 return Struct(selected=good)
97
98 def _getSchemaKeys(self, schema):
99 """Extract and save the necessary keys from schema with asKey.
100 """
101 self.parentKey = schema["parent"].asKey()
102 self.centroidXKey = schema["slot_Centroid_x"].asKey()
103 self.centroidYKey = schema["slot_Centroid_y"].asKey()
104 self.centroidFlagKey = schema["slot_Centroid_flag"].asKey()
105
106 fluxPrefix = "slot_%sFlux_" % (self.config.sourceFluxType,)
107 self.fluxField = fluxPrefix + "instFlux"
108 self.fluxKey = schema[fluxPrefix + "instFlux"].asKey()
109 self.fluxFlagKey = schema[fluxPrefix + "flag"].asKey()
110 self.fluxErrKey = schema[fluxPrefix + "instFluxErr"].asKey()
111
112 self.edgeKey = schema["base_PixelFlags_flag_edge"].asKey()
113 self.interpolatedCenterKey = schema["base_PixelFlags_flag_interpolatedCenter"].asKey()
114 self.saturatedKey = schema["base_PixelFlags_flag_saturated"].asKey()
115
116 def _isParent(self, sourceCat):
117 """Return True for each source that is the parent source.
118 """
119 test = (sourceCat.get(self.parentKey) == 0)
120 return test
121
122 def _hasCentroid(self, sourceCat):
123 """Return True for each source that has a valid centroid
124 """
125 return np.isfinite(sourceCat.get(self.centroidXKey)) \
126 & np.isfinite(sourceCat.get(self.centroidYKey)) \
127 & ~sourceCat.get(self.centroidFlagKey)
128
129 def _goodSN(self, sourceCat):
130 """Return True for each source that has Signal/Noise > config.minSnr.
131 """
132 if self.config.minSnr <= 0:
133 return True
134 else:
135 with np.errstate(invalid="ignore"): # suppress NAN warnings
136 return sourceCat.get(self.fluxKey)/sourceCat.get(self.fluxErrKey) > self.config.minSnr
137
138 def _isUsable(self, sourceCat):
139 """
140 Return True for each source that is usable for matching, even if it may
141 have a poor centroid.
142
143 For a source to be usable it must:
144
145 - have a valid centroid
146 - not be deblended
147 - have a valid instFlux (of the type specified in this object's constructor)
148 - have adequate signal-to-noise
149 """
150 return self._hasCentroid(sourceCat) \
151 & self._isParent(sourceCat) \
152 & self._goodSN(sourceCat) \
153 & ~sourceCat.get(self.fluxFlagKey)
154
155 def _isGood(self, sourceCat):
156 """
157 Return True for each source that is usable for matching, even if it may
158 have a poor centroid.
159
160 For a source to be usable it must:
161
162 - Not be on a CCD edge.
163 - Not have an interpolated pixel within 3x3 around their centroid.
164 - Not have a saturated pixel in their footprint.
165 """
166 return ~sourceCat.get(self.edgeKey) & \
167 ~sourceCat.get(self.interpolatedCenterKey) & \
168 ~sourceCat.get(self.saturatedKey)
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Definition: Exposure.h:72
def selectSources(self, sourceCat, matches=None, exposure=None)
Lightweight representation of a geometric match between two records.
Definition: Match.h:67