LSSTApplications  16.0-10-g9d3e444,16.0-11-g09ed895+3,16.0-11-g12e47bd+4,16.0-11-g9bb73b2+10,16.0-12-g5c924a4+10,16.0-15-g7af1f30,16.0-15-gdd5ca33+2,16.0-16-gf0259e2+1,16.0-17-g31abd91+11,16.0-17-g5cf0468+3,16.0-18-g51a54b3+3,16.0-18-ga4d4bcb+5,16.0-18-gcf94535+2,16.0-19-g9d290d5+2,16.0-2-g0febb12+22,16.0-2-g9d5294e+73,16.0-2-ga8830df+7,16.0-21-g3d035912+2,16.0-26-g8e79609,16.0-28-gfc9ea6c+9,16.0-29-ge8801f9+4,16.0-3-ge00e371+38,16.0-4-g18f3627+17,16.0-4-g5f3a788+21,16.0-4-ga3eb747+11,16.0-4-gabf74b7+33,16.0-4-gb13d127+7,16.0-5-g27fb78a+11,16.0-5-g6a53317+38,16.0-5-gb3f8a4b+91,16.0-51-gbbe9c988+3,16.0-6-g9321be7+5,16.0-6-gcbc7b31+47,16.0-6-gf49912c+33,16.0-75-gbf7a9a820,16.0-8-g21fd5fe+34,16.0-8-g3a9f023+24,16.0-8-gc11f1cf,16.0-9-gf3bc169+2,16.0-9-gf5c1f43+12,master-gc237143d49,w.2019.02
LSSTDataManagementBasePackage
catalogStarSelector.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 
23 __all__ = ["CatalogStarSelectorConfig", "CatalogStarSelectorTask"]
24 
25 import numpy as np
26 
27 from lsst.meas.algorithms import BaseSourceSelectorTask, sourceSelectorRegistry
28 from lsst.pipe.base import Struct
29 import lsst.pex.config as pexConfig
30 import lsst.afw.display.ds9 as ds9
31 
32 
33 class CatalogStarSelectorConfig(BaseSourceSelectorTask.ConfigClass):
34  fluxLim = pexConfig.RangeField(
35  doc="specify the minimum psfFlux for good Psf Candidates",
36  dtype=float,
37  default=0.0,
38  min=0.0,
39  )
40  fluxMax = pexConfig.RangeField(
41  doc="specify the maximum psfFlux for good Psf Candidates (ignored if == 0)",
42  dtype=float,
43  default=0.0,
44  min=0.0,
45  )
46  badFlags = pexConfig.ListField(
47  doc="List of flags which cause a source to be rejected as bad",
48  dtype=str,
49  default=[
50  "base_PixelFlags_flag_edge",
51  "base_PixelFlags_flag_interpolatedCenter",
52  "base_PixelFlags_flag_saturatedCenter",
53  ],
54  )
55 
56 
58  """A functor to check whether a source has any flags set that should cause it to be labeled bad."""
59 
60  def __init__(self, table, fluxLim, fluxMax, badFlags):
61  self.keys = [table.getSchema().find(name).key for name in badFlags]
62  self.keys.append(table.getCentroidFlagKey())
63  self.fluxLim = fluxLim
64  self.fluxMax = fluxMax
65 
66  def __call__(self, source):
67  for k in self.keys:
68  if source.get(k):
69  return False
70  if self.fluxLim is not None and source.getPsfInstFlux() < self.fluxLim: # ignore faint objects
71  return False
72  if self.fluxMax != 0.0 and source.getPsfInstFlux() > self.fluxMax: # ignore bright objects
73  return False
74  return True
75 
76 # \addtogroup LSST_task_documentation
77 # \{
78 # \page CatalogStarSelectorTask
79 # \ref CatalogStarSelectorTask_ "CatalogStarSelectorTask"
80 # \copybrief CatalogStarSelectorTask
81 # \}
82 
83 
84 @pexConfig.registerConfigurable("catalog", sourceSelectorRegistry)
86  """Select stars based on a reference catalog.
87 
88  Attributes
89  ----------
90  usesMatches : `bool`
91  A boolean variable specify if the inherited source selector uses
92  matches to an external catalog, and thus requires the ``matches``
93  argument to ``run()``. Set to True for this selector.
94  """
95  ConfigClass = CatalogStarSelectorConfig
96  usesMatches = True # `run` and `selectStars` require the `matches` argument
97 
98  def selectSources(self, sourceCat, matches=None, exposure=None):
99  """Return a selection of sources based on reference catalog matches.
100 
101  Parameters
102  ----------
103  sourceCat : `lsst.afw.table.SourceCatalog`
104  Catalog of sources to select from.
105  This catalog must be contiguous in memory.
106  matches : `list` of `lsst.afw.table.ReferenceMatch`
107  A match vector as produced by meas_astrom; required.
108  exposure : `lsst.afw.image.Exposure` or None
109  The exposure the catalog was built from; used for debug display.
110 
111  Return
112  ------
113  struct : `lsst.pipe.base.Struct`
114  Result struct with components:
115 
116  - selected : Boolean array of sources that were selected, same
117  length as sourceCat (`numpy.ndarray` of `bool`)
118  """
119  import lsstDebug
120  debugInfo = lsstDebug.Info(__name__)
121  display = debugInfo.display
122  pauseAtEnd = debugInfo.pauseAtEnd # pause when done
123 
124  if matches is None:
125  raise RuntimeError("CatalogStarSelectorTask requires matches")
126 
127  mi = exposure.getMaskedImage()
128 
129  if display:
130  frame = 1
131  ds9.mtv(mi, frame=frame, title="PSF candidates")
132 
133  isGoodSource = CheckSource(sourceCat, self.config.fluxLim, self.config.fluxMax, self.config.badFlags)
134  good = np.array([isGoodSource(record) for record in sourceCat])
135 
136  with ds9.Buffering():
137  for ref, source, d in matches:
138  if not ref.get("resolved"):
139  if not isGoodSource(source):
140  symb, ctype = "+", ds9.RED
141  else:
142  symb, ctype = "+", ds9.GREEN
143 
144  if display:
145  ds9.dot(symb, source.getX() - mi.getX0(), source.getY() - mi.getY0(),
146  size=4, frame=frame, ctype=ctype)
147 
148  if display and pauseAtEnd:
149  input("Continue? y[es] p[db] ")
150 
151  return Struct(selected=good)
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33
Fit spatial kernel using approximate fluxes for candidates, and solving a linear system of equations...
def selectSources(self, sourceCat, matches=None, exposure=None)
def __init__(self, table, fluxLim, fluxMax, badFlags)