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 | Static Public Attributes | Private Attributes | List of all members
lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector Class Reference

A measurePsfTask star selector. More...

Inheritance diagram for lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector:

Public Member Functions

def __init__
 Construct a star selector that looks for a cluster of small objects in a size-magnitude plot. More...
 
def selectStars
 Return a list of PSF candidates that represent likely stars. More...
 

Static Public Attributes

 ConfigClass = ObjectSizeStarSelectorConfig
 

Private Attributes

 _kernelSize
 
 _borderWidth
 
 _widthMin
 
 _widthMax
 
 _fluxMin
 
 _fluxMax
 
 _badFlags
 
 _sourceFluxField
 
 _widthStdAllowed
 
 _nSigmaClip
 

Detailed Description

A measurePsfTask star selector.

Definition at line 273 of file objectSizeStarSelector.py.

Constructor & Destructor Documentation

def lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector.__init__ (   self,
  config 
)

Construct a star selector that looks for a cluster of small objects in a size-magnitude plot.

Parameters
[in]configAn instance of ObjectSizeStarSelectorConfig

Definition at line 279 of file objectSizeStarSelector.py.

280  def __init__(self, config):
281  """!
282  Construct a star selector that looks for a cluster of small objects in a size-magnitude plot.
283 
284  \param[in] config An instance of ObjectSizeStarSelectorConfig
285  """
286  self._kernelSize = config.kernelSize
287  self._borderWidth = config.borderWidth
288  self._widthMin = config.widthMin
289  self._widthMax = config.widthMax
290  self._fluxMin = config.fluxMin
291  self._fluxMax = config.fluxMax
292  self._badFlags = config.badFlags
293  self._sourceFluxField = config.sourceFluxField
294  self._widthStdAllowed = config.widthStdAllowed
295  self._nSigmaClip = config.nSigmaClip
def __init__
Construct a star selector that looks for a cluster of small objects in a size-magnitude plot...

Member Function Documentation

def lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector.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.

Parameters
[in]exposurethe exposure containing the sources
[in]cataloga SourceCatalog containing sources that may be stars
[in]matchesastrometric matches; ignored by this star selector
Returns
psfCandidateList a list of PSF candidates.

Definition at line 296 of file objectSizeStarSelector.py.

297  def selectStars(self, exposure, catalog, matches=None):
298  """!Return a list of PSF candidates that represent likely stars
299 
300  A list of PSF candidates may be used by a PSF fitter to construct a PSF.
301 
302  \param[in] exposure the exposure containing the sources
303  \param[in] catalog a SourceCatalog containing sources that may be stars
304  \param[in] matches astrometric matches; ignored by this star selector
305 
306  \return psfCandidateList a list of PSF candidates.
307  """
308  import lsstDebug
309  display = lsstDebug.Info(__name__).display
310  displayExposure = lsstDebug.Info(__name__).displayExposure # display the Exposure + spatialCells
311  plotMagSize = lsstDebug.Info(__name__).plotMagSize # display the magnitude-size relation
312  dumpData = lsstDebug.Info(__name__).dumpData # dump data to pickle file?
313 
314  # create a log for my application
315  logger = pexLogging.Log(pexLogging.getDefaultLog(), "meas.algorithms.objectSizeStarSelector")
316 
317  detector = exposure.getDetector()
318  pixToTanXYTransform = None
319  if detector is not None:
320  tanSys = detector.makeCameraSys(cameraGeom.TAN_PIXELS)
321  pixToTanXYTransform = detector.getTransformMap().get(tanSys)
322  #
323  # Look at the distribution of stars in the magnitude-size plane
324  #
325  flux = catalog.get(self._sourceFluxField)
326 
327  xx = numpy.empty(len(catalog))
328  xy = numpy.empty_like(xx)
329  yy = numpy.empty_like(xx)
330  for i, source in enumerate(catalog):
331  Ixx, Ixy, Iyy = source.getIxx(), source.getIxy(), source.getIyy()
332  if pixToTanXYTransform:
333  p = afwGeom.Point2D(source.getX(), source.getY())
334  linTransform = pixToTanXYTransform.linearizeForwardTransform(p).getLinear()
335  m = geomEllip.Quadrupole(Ixx, Iyy, Ixy)
336  m.transform(linTransform)
337  Ixx, Iyy, Ixy = m.getIxx(), m.getIyy(), m.getIxy()
338 
339  xx[i], xy[i], yy[i] = Ixx, Ixy, Iyy
340 
341  width = numpy.sqrt(0.5*(xx + yy))
342 
343  badFlags = self._badFlags
344 
345  bad = reduce(lambda x, y: numpy.logical_or(x, catalog.get(y)), badFlags, False)
346  bad = numpy.logical_or(bad, flux < self._fluxMin)
347  bad = numpy.logical_or(bad, numpy.logical_not(numpy.isfinite(width)))
348  bad = numpy.logical_or(bad, numpy.logical_not(numpy.isfinite(flux)))
349  bad = numpy.logical_or(bad, width < self._widthMin)
350  bad = numpy.logical_or(bad, width > self._widthMax)
351  if self._fluxMax > 0:
352  bad = numpy.logical_or(bad, flux > self._fluxMax)
353  good = numpy.logical_not(bad)
354 
355  if not numpy.any(good):
356  raise RuntimeError("No objects passed our cuts for consideration as psf stars")
357 
358  mag = -2.5*numpy.log10(flux[good])
359  width = width[good]
360  #
361  # Look for the maximum in the size histogram, then search upwards for the minimum that separates
362  # the initial peak (of, we presume, stars) from the galaxies
363  #
364  if dumpData:
365  import os, cPickle as pickle
366  _ii = 0
367  while True:
368  pickleFile = os.path.expanduser(os.path.join("~", "widths-%d.pkl" % _ii))
369  if not os.path.exists(pickleFile):
370  break
371  _ii += 1
372 
373  with open(pickleFile, "wb") as fd:
374  pickle.dump(mag, fd, -1)
375  pickle.dump(width, fd, -1)
376 
377  centers, clusterId = _kcenters(width, nCluster=4, useMedian=True,
378  widthStdAllowed=self._widthStdAllowed)
379 
380  if display and plotMagSize and pyplot:
381  fig = plot(mag, width, centers, clusterId, magType=self._sourceFluxField.split(".")[-1].title(),
382  marker="+", markersize=3, markeredgewidth=None, ltype=':', clear=True)
383  else:
384  fig = None
385 
386  clusterId = _improveCluster(width, centers, clusterId,
387  nsigma = self._nSigmaClip, widthStdAllowed=self._widthStdAllowed)
388 
389  if display and plotMagSize and pyplot:
390  plot(mag, width, centers, clusterId, marker="x", markersize=3, markeredgewidth=None, clear=False)
391 
392  stellar = (clusterId == 0)
393  #
394  # We know enough to plot, if so requested
395  #
396  frame = 0
397 
398  if fig:
399  if display and displayExposure:
400  ds9.mtv(exposure.getMaskedImage(), frame=frame, title="PSF candidates")
401 
402  global eventHandler
403  eventHandler = EventHandler(fig.get_axes()[0], mag, width,
404  catalog.getX()[good], catalog.getY()[good], frames=[frame])
405 
406  fig.show()
407 
408  #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
409 
410  while True:
411  try:
412  reply = raw_input("continue? [c h(elp) q(uit) p(db)] ").strip()
413  except EOFError:
414  reply = None
415  if not reply:
416  reply = "c"
417 
418  if reply:
419  if reply[0] == "h":
420  print """\
421  We cluster the points; red are the stellar candidates and the other colours are other clusters.
422  Points labelled + are rejects from the cluster (only for cluster 0).
423 
424  At this prompt, you can continue with almost any key; 'p' enters pdb, and 'h' prints this text
425 
426  If displayExposure is true, you can put the cursor on a point and hit 'p' to see it in ds9.
427  """
428  elif reply[0] == "p":
429  import pdb; pdb.set_trace()
430  elif reply[0] == 'q':
431  sys.exit(1)
432  else:
433  break
434 
435  if display and displayExposure:
436  mi = exposure.getMaskedImage()
437 
438  with ds9.Buffering():
439  for i, source in enumerate(catalog):
440  if good[i]:
441  ctype = ds9.GREEN # star candidate
442  else:
443  ctype = ds9.RED # not star
444 
445  ds9.dot("+", source.getX() - mi.getX0(),
446  source.getY() - mi.getY0(), frame=frame, ctype=ctype)
447  #
448  # Time to use that stellar classification to generate psfCandidateList
449  #
450  with ds9.Buffering():
451  psfCandidateList = []
452  for isStellar, source in zip(stellar, [s for g, s in zip(good, catalog) if g]):
453  if not isStellar:
454  continue
455 
456  try:
457  psfCandidate = algorithmsLib.makePsfCandidate(source, exposure)
458  # The setXXX methods are class static, but it's convenient to call them on
459  # an instance as we don't know Exposure's pixel type
460  # (and hence psfCandidate's exact type)
461  if psfCandidate.getWidth() == 0:
462  psfCandidate.setBorderWidth(self._borderWidth)
463  psfCandidate.setWidth(self._kernelSize + 2*self._borderWidth)
464  psfCandidate.setHeight(self._kernelSize + 2*self._borderWidth)
465 
466  im = psfCandidate.getMaskedImage().getImage()
467  vmax = afwMath.makeStatistics(im, afwMath.MAX).getValue()
468  if not numpy.isfinite(vmax):
469  continue
470  psfCandidateList.append(psfCandidate)
471 
472  if display and displayExposure:
473  ds9.dot("o", source.getX() - mi.getX0(), source.getY() - mi.getY0(),
474  size=4, frame=frame, ctype=ds9.CYAN)
475  except Exception as err:
476  logger.logdebug("Failed to make a psfCandidate from source %d: %s" % (source.getId(), err))
477 
478  return psfCandidateList
479 
480 starSelectorRegistry.register("objectSize", ObjectSizeStarSelector)
def selectStars
Return a list of PSF candidates that represent likely stars.
a place to record messages and descriptions of the state of processing.
Definition: Log.h:154
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.objectSizeStarSelector.ObjectSizeStarSelector._badFlags
private

Definition at line 291 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector._borderWidth
private

Definition at line 286 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector._fluxMax
private

Definition at line 290 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector._fluxMin
private

Definition at line 289 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector._kernelSize
private

Definition at line 285 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector._nSigmaClip
private

Definition at line 294 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector._sourceFluxField
private

Definition at line 292 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector._widthMax
private

Definition at line 288 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector._widthMin
private

Definition at line 287 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector._widthStdAllowed
private

Definition at line 293 of file objectSizeStarSelector.py.

lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelector.ConfigClass = ObjectSizeStarSelectorConfig
static

Definition at line 277 of file objectSizeStarSelector.py.


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