30 fluxLim = pexConfig.Field(
31 doc =
"specify the minimum psfFlux for good Kernel Candidates",
34 check =
lambda x: x >= 0.0,
36 fluxMax = pexConfig.Field(
37 doc =
"specify the maximum psfFlux for good Kernel Candidates (ignored if == 0)",
40 check =
lambda x: x >= 0.0,
42 badPixelFlags = pexConfig.ListField(
43 doc =
"Kernel candidate objects may not have any of these bits set",
45 default = [
"base_PixelFlags_edge",
"base_PixelFlags_interpolatedCenter",
46 "base_PixelFlags_saturatedCenter",
"slot_Centroid_flag"],
49 selectStar = pexConfig.Field(
50 doc =
"Select objects that are flagged as stars",
54 selectGalaxy = pexConfig.Field(
55 doc =
"Select objects that are flagged as galaxies",
59 includeVariable = pexConfig.Field(
60 doc =
"Include objects that are known to be variable",
64 grMin = pexConfig.Field(
65 doc =
"Minimum g-r color for selection (inclusive)",
69 grMax = pexConfig.Field(
70 doc =
"Maximum g-r color for selection (inclusive)",
76 """A functor to check whether a source has any flags set that should cause it to be labeled bad."""
78 def __init__(self, table, fluxLim, fluxMax, badPixelFlags):
79 self.
keys = [table.getSchema().find(name).key
for name
in badPixelFlags]
94 ConfigClass = DiaCatalogSourceSelectorConfig
97 """Construct a source selector that uses a reference catalog
99 @param[in] config: An instance of ConfigClass
102 config = DiaCatalogSourceSelector.ConfigClass()
105 'lsst.ip.diffim.DiaCatalogSourceSelector', pexLog.Log.INFO)
108 """Return a list of Sources for Kernel candidates
110 @param[in] exposure: the exposure containing the sources
111 @param[in] sources: a source list containing sources that may be candidates
112 @param[in] matches: a match vector as produced by meas_astrom; not optional
113 (passing None just allows us to handle the exception better here
114 than in calling code)
116 @return kernelCandidateSourceList: a list of sources to be used as kernel candidates
126 "Cannot use catalog source selector without running astrometry."
129 mi = exposure.getMaskedImage()
133 ds9.mtv(mi, title=
"Kernel candidates", frame=lsstDebug.frame)
137 isGoodSource =
CheckSource(sources, self.config.fluxLim, self.config.fluxMax, self.config.badPixelFlags)
142 kernelCandidateSourceList = []
145 with ds9.Buffering():
146 refSchema = matches[0][0].schema
147 rRefFluxField = measAlg.getRefFluxField(refSchema,
"r")
148 gRefFluxField = measAlg.getRefFluxField(refSchema, "g")
149 for ref, source, d
in matches:
150 if not isGoodSource(source):
151 symb, ctype =
"+", ds9.RED
153 isStar =
not ref.get(
"resolved")
154 isVar =
not ref.get(
"photometric")
159 gMag = -2.5 * np.log10(ref.get(gRefFluxField))
160 rMag = -2.5 * np.log10(ref.get(rRefFluxField))
162 self.log.warn(
"Cannot cut on color info; fields 'g' and 'r' do not exist")
166 isRightColor = (gMag-rMag) >= self.config.grMin
and (gMag-rMag) <= self.config.grMax
168 isRightType = (self.config.selectStar
and isStar)
or (self.config.selectGalaxy
and not isStar)
169 isRightVar = (self.config.includeVariable)
or (self.config.includeVariable
is isVar)
170 if isRightType
and isRightVar
and isRightColor:
171 kernelCandidateSourceList.append(source)
172 symb, ctype =
"+", ds9.GREEN
174 symb, ctype =
"o", ds9.BLUE
176 if display
and displayExposure:
177 ds9.dot(symb, source.getX() - mi.getX0(), source.getY() - mi.getY0(),
178 size=4, ctype=ctype, frame=lsstDebug.frame)
183 raw_input(
"Continue? y[es] p[db] ")
185 return kernelCandidateSourceList
187 measAlg.starSelectorRegistry.register(
"diacatalog", DiaCatalogSourceSelector)
a place to record messages and descriptions of the state of processing.