LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
lsst.meas.algorithms.secondMomentStarSelector.SecondMomentStarSelector Class Reference
Inheritance diagram for lsst.meas.algorithms.secondMomentStarSelector.SecondMomentStarSelector:

Public Member Functions

def __init__
 
def selectStars
 

Public Attributes

 config
 

Static Public Attributes

 ConfigClass = SecondMomentStarSelectorConfig
 

Detailed Description

Definition at line 129 of file secondMomentStarSelector.py.

Constructor & Destructor Documentation

def lsst.meas.algorithms.secondMomentStarSelector.SecondMomentStarSelector.__init__ (   self,
  config 
)
Construct a star selector that uses second moments

This is a naive algorithm and should be used with caution.

@param[in] config: An instance of SecondMomentStarSelectorConfig

Definition at line 132 of file secondMomentStarSelector.py.

133  def __init__(self, config):
134  """Construct a star selector that uses second moments
135 
136  This is a naive algorithm and should be used with caution.
137 
138  @param[in] config: An instance of SecondMomentStarSelectorConfig
139  """
140  self.config = config

Member Function Documentation

def lsst.meas.algorithms.secondMomentStarSelector.SecondMomentStarSelector.selectStars (   self,
  exposure,
  catalog,
  matches = None 
)
Return a list of PSF candidates that represent likely stars

A list of PSF candidates may be used by a PSF fitter to construct a PSF.

@param[in] exposure: the exposure containing the sources
@param[in] catalog: a SourceCatalog containing sources that may be stars
@param[in] matches: astrometric matches; ignored by this star selector

@return psfCandidateList: a list of PSF candidates.

Definition at line 141 of file secondMomentStarSelector.py.

142  def selectStars(self, exposure, catalog, matches=None):
143  """Return a list of PSF candidates that represent likely stars
144 
145  A list of PSF candidates may be used by a PSF fitter to construct a PSF.
146 
147  @param[in] exposure: the exposure containing the sources
148  @param[in] catalog: a SourceCatalog containing sources that may be stars
149  @param[in] matches: astrometric matches; ignored by this star selector
150 
151  @return psfCandidateList: a list of PSF candidates.
152  """
153  import lsstDebug
154  display = lsstDebug.Info(__name__).display
155 
156  displayExposure = lsstDebug.Info(__name__).displayExposure # display the Exposure + spatialCells
157 
158  isGoodSource = CheckSource(catalog.getTable(), self.config.badFlags, self.config.fluxLim,
159  self.config.fluxMax)
160 
161  detector = exposure.getDetector()
162 
163  mi = exposure.getMaskedImage()
164  #
165  # Create an Image of Ixx v. Iyy, i.e. a 2-D histogram
166  #
167 
168  # Use stats on our Ixx/yy values to determine the xMax/yMax range for clump image
169  iqqList = []
170  for s in catalog:
171  ixx, iyy = s.getIxx(), s.getIyy()
172  # ignore NaN and unrealistically large values
173  if (ixx == ixx and ixx < self.config.histMomentMax and
174  iyy == iyy and iyy < self.config.histMomentMax and
175  isGoodSource(s)):
176  iqqList.append(s.getIxx())
177  iqqList.append(s.getIyy())
178  stat = afwMath.makeStatistics(iqqList, afwMath.MEANCLIP | afwMath.STDEVCLIP | afwMath.MAX)
179  iqqMean = stat.getValue(afwMath.MEANCLIP)
180  iqqStd = stat.getValue(afwMath.STDEVCLIP)
181  iqqMax = stat.getValue(afwMath.MAX)
182 
183  iqqLimit = max(iqqMean + self.config.histMomentClip*iqqStd,
184  self.config.histMomentMaxMultiplier*iqqMean)
185  # if the max value is smaller than our range, use max as the limit, but don't go below N*mean
186  if iqqLimit > iqqMax:
187  iqqLimit = max(self.config.histMomentMinMultiplier*iqqMean, iqqMax)
188 
189  psfHist = _PsfShapeHistogram(detector=detector, xSize=self.config.histSize, ySize=self.config.histSize,
190  ixxMax=iqqLimit, iyyMax=iqqLimit)
191 
192  if display and displayExposure:
193  frame = 0
194  ds9.mtv(mi, frame=frame, title="PSF candidates")
195 
196  with ds9.Buffering():
197  for source in catalog:
198  if isGoodSource(source):
199  if psfHist.insert(source): # n.b. this call has the side effect of inserting
200  ctype = ds9.GREEN # good
201  else:
202  ctype = ds9.MAGENTA # rejected
203  else:
204  ctype = ds9.RED # bad
205 
206  if display and displayExposure:
207  ds9.dot("o", source.getX() - mi.getX0(),
208  source.getY() - mi.getY0(), frame=frame, ctype=ctype)
209 
210  clumps = psfHist.getClumps(display=display)
211 
212  #
213  # Go through and find all the PSF-like objects
214  #
215  # We'll split the image into a number of cells, each of which contributes only
216  # one PSF candidate star
217  #
218  psfCandidateList = []
219 
220  pixToTanXYTransform = None
221  if detector is not None:
222  tanSys = detector.makeCameraSys(cameraGeom.TAN_PIXELS)
223  pixToTanXYTransform = detector.getTransformMap().get(tanSys)
224 
225  # psf candidate shapes must lie within this many RMS of the average shape
226  # N.b. if Ixx == Iyy, Ixy = 0 the criterion is
227  # dx^2 + dy^2 < self.config.clumpNSigma*(Ixx + Iyy) == 2*self.config.clumpNSigma*Ixx
228  for source in catalog:
229  if not isGoodSource(source): continue
230  Ixx, Ixy, Iyy = source.getIxx(), source.getIxy(), source.getIyy()
231  if pixToTanXYTransform:
232  p = afwGeom.Point2D(source.getX(), source.getY())
233  linTransform = pixToTanXYTransform.linearizeForwardTransform(p).getLinear()
234  m = geomEllip.Quadrupole(Ixx, Iyy, Ixy)
235  m.transform(linTransform)
236  Ixx, Iyy, Ixy = m.getIxx(), m.getIyy(), m.getIxy()
237 
238  x, y = psfHist.momentsToPixel(Ixx, Iyy)
239  for clump in clumps:
240  dx, dy = (x - clump.x), (y - clump.y)
241 
242  if math.sqrt(clump.a*dx*dx + 2*clump.b*dx*dy + clump.c*dy*dy) < 2*self.config.clumpNSigma:
243  # A test for > would be confused by NaN
244  if not isGoodSource(source):
245  continue
246  try:
247  psfCandidate = algorithmsLib.makePsfCandidate(source, exposure)
248 
249  # The setXXX methods are class static, but it's convenient to call them on
250  # an instance as we don't know Exposure's pixel type
251  # (and hence psfCandidate's exact type)
252  if psfCandidate.getWidth() == 0:
253  psfCandidate.setBorderWidth(self.config.borderWidth)
254  psfCandidate.setWidth(self.config.kernelSize + 2*self.config.borderWidth)
255  psfCandidate.setHeight(self.config.kernelSize + 2*self.config.borderWidth)
256 
257  im = psfCandidate.getMaskedImage().getImage()
258  if not numpy.isfinite(afwMath.makeStatistics(im, afwMath.MAX).getValue()):
259  continue
260  psfCandidateList.append(psfCandidate)
261 
262  if display and displayExposure:
263  ds9.dot("o", source.getX() - mi.getX0(), source.getY() - mi.getY0(),
264  size=4, frame=frame, ctype=ds9.CYAN)
265  except Exception as err:
266  pass # FIXME: should log this!
267  break
268 
269  return psfCandidateList
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1082

Member Data Documentation

lsst.meas.algorithms.secondMomentStarSelector.SecondMomentStarSelector.config

Definition at line 139 of file secondMomentStarSelector.py.

lsst.meas.algorithms.secondMomentStarSelector.SecondMomentStarSelector.ConfigClass = SecondMomentStarSelectorConfig
static

Definition at line 130 of file secondMomentStarSelector.py.


The documentation for this class was generated from the following file: