LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Static Public Attributes | List of all members
lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelectorTask Class Reference
Inheritance diagram for lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelectorTask:
lsst.meas.algorithms.sourceSelector.BaseSourceSelectorTask

Public Member Functions

def selectSources (self, sourceCat, matches=None, exposure=None)
 
def run (self, sourceCat, sourceSelectedField=None, matches=None, exposure=None)
 

Static Public Attributes

 ConfigClass = ObjectSizeStarSelectorConfig
 
bool usesMatches = False
 

Detailed Description

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

Definition at line 324 of file objectSizeStarSelector.py.

Member Function Documentation

◆ run()

def lsst.meas.algorithms.sourceSelector.BaseSourceSelectorTask.run (   self,
  sourceCat,
  sourceSelectedField = None,
  matches = None,
  exposure = None 
)
inherited
Select sources and return them.

The input catalog must be contiguous in memory.

Parameters:
-----------
sourceCat : `lsst.afw.table.SourceCatalog` or `pandas.DataFrame`
            or `astropy.table.Table`
    Catalog of sources to select from.
sourceSelectedField : `str` or None
    Name of flag field in sourceCat to set for selected sources.
    If set, will modify sourceCat in-place.
matches : `list` of `lsst.afw.table.ReferenceMatch` or None
    List of matches to use for source selection.
    If usesMatches is set in source selector this field is required.
    If not, it is ignored.
exposure : `lsst.afw.image.Exposure` or None
    The exposure the catalog was built from; used for debug display.

Return
------
struct : `lsst.pipe.base.Struct`
    The struct contains the following data:

    - sourceCat : `lsst.afw.table.SourceCatalog` or `pandas.DataFrame`
                  or `astropy.table.Table`
        The catalog of sources that were selected.
        (may not be memory-contiguous)
    - selected : `numpy.ndarray` of `bool``
        Boolean array of sources that were selected, same length as
        sourceCat.

Raises
------
RuntimeError
    Raised if ``sourceCat`` is not contiguous.

Definition at line 71 of file sourceSelector.py.

71  def run(self, sourceCat, sourceSelectedField=None, matches=None, exposure=None):
72  """Select sources and return them.
73 
74  The input catalog must be contiguous in memory.
75 
76  Parameters:
77  -----------
78  sourceCat : `lsst.afw.table.SourceCatalog` or `pandas.DataFrame`
79  or `astropy.table.Table`
80  Catalog of sources to select from.
81  sourceSelectedField : `str` or None
82  Name of flag field in sourceCat to set for selected sources.
83  If set, will modify sourceCat in-place.
84  matches : `list` of `lsst.afw.table.ReferenceMatch` or None
85  List of matches to use for source selection.
86  If usesMatches is set in source selector this field is required.
87  If not, it is ignored.
88  exposure : `lsst.afw.image.Exposure` or None
89  The exposure the catalog was built from; used for debug display.
90 
91  Return
92  ------
93  struct : `lsst.pipe.base.Struct`
94  The struct contains the following data:
95 
96  - sourceCat : `lsst.afw.table.SourceCatalog` or `pandas.DataFrame`
97  or `astropy.table.Table`
98  The catalog of sources that were selected.
99  (may not be memory-contiguous)
100  - selected : `numpy.ndarray` of `bool``
101  Boolean array of sources that were selected, same length as
102  sourceCat.
103 
104  Raises
105  ------
106  RuntimeError
107  Raised if ``sourceCat`` is not contiguous.
108  """
109  if hasattr(sourceCat, 'isContiguous'):
110  # Check for continuity on afwTable catalogs
111  if not sourceCat.isContiguous():
112  raise RuntimeError("Input catalogs for source selection must be contiguous.")
113 
114  result = self.selectSources(sourceCat=sourceCat,
115  exposure=exposure,
116  matches=matches)
117 
118  if sourceSelectedField is not None:
119  if isinstance(sourceCat, (pandas.DataFrame, astropy.table.Table)):
120  sourceCat[sourceSelectedField] = result.selected
121  else:
122  source_selected_key = \
123  sourceCat.getSchema()[sourceSelectedField].asKey()
124  # TODO: Remove for loop when DM-6981 is completed.
125  for source, flag in zip(sourceCat, result.selected):
126  source.set(source_selected_key, bool(flag))
127  return pipeBase.Struct(sourceCat=sourceCat[result.selected],
128  selected=result.selected)
129 
def run(self, coaddExposures, bbox, wcs)
Definition: getTemplate.py:603

◆ selectSources()

def lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelectorTask.selectSources (   self,
  sourceCat,
  matches = None,
  exposure = None 
)
Return a selection of PSF candidates that represent likely stars.

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

Parameters:
-----------
sourceCat : `lsst.afw.table.SourceCatalog`
    Catalog of sources to select from.
    This catalog must be contiguous in memory.
matches : `list` of `lsst.afw.table.ReferenceMatch` or None
    Ignored in this SourceSelector.
exposure : `lsst.afw.image.Exposure` or None
    The exposure the catalog was built from; used to get the detector
    to transform to TanPix, and for debug display.

Return
------
struct : `lsst.pipe.base.Struct`
    The struct contains the following data:

    - selected : `array` of `bool``
        Boolean array of sources that were selected, same length as
        sourceCat.

Reimplemented from lsst.meas.algorithms.sourceSelector.BaseSourceSelectorTask.

Definition at line 330 of file objectSizeStarSelector.py.

330  def selectSources(self, sourceCat, matches=None, exposure=None):
331  """Return a selection of PSF candidates that represent likely stars.
332 
333  A list of PSF candidates may be used by a PSF fitter to construct a PSF.
334 
335  Parameters:
336  -----------
337  sourceCat : `lsst.afw.table.SourceCatalog`
338  Catalog of sources to select from.
339  This catalog must be contiguous in memory.
340  matches : `list` of `lsst.afw.table.ReferenceMatch` or None
341  Ignored in this SourceSelector.
342  exposure : `lsst.afw.image.Exposure` or None
343  The exposure the catalog was built from; used to get the detector
344  to transform to TanPix, and for debug display.
345 
346  Return
347  ------
348  struct : `lsst.pipe.base.Struct`
349  The struct contains the following data:
350 
351  - selected : `array` of `bool``
352  Boolean array of sources that were selected, same length as
353  sourceCat.
354  """
355  import lsstDebug
356  display = lsstDebug.Info(__name__).display
357  displayExposure = lsstDebug.Info(__name__).displayExposure # display the Exposure + spatialCells
358  plotMagSize = lsstDebug.Info(__name__).plotMagSize # display the magnitude-size relation
359  dumpData = lsstDebug.Info(__name__).dumpData # dump data to pickle file?
360 
361  detector = None
362  pixToTanPix = None
363  if exposure:
364  detector = exposure.getDetector()
365  if detector:
366  pixToTanPix = detector.getTransform(PIXELS, TAN_PIXELS)
367  #
368  # Look at the distribution of stars in the magnitude-size plane
369  #
370  flux = sourceCat.get(self.config.sourceFluxField)
371  fluxErr = sourceCat.get(self.config.sourceFluxField + "Err")
372 
373  xx = numpy.empty(len(sourceCat))
374  xy = numpy.empty_like(xx)
375  yy = numpy.empty_like(xx)
376  for i, source in enumerate(sourceCat):
377  Ixx, Ixy, Iyy = source.getIxx(), source.getIxy(), source.getIyy()
378  if pixToTanPix:
379  p = lsst.geom.Point2D(source.getX(), source.getY())
380  linTransform = afwGeom.linearizeTransform(pixToTanPix, p).getLinear()
381  m = afwGeom.Quadrupole(Ixx, Iyy, Ixy)
382  m.transform(linTransform)
383  Ixx, Iyy, Ixy = m.getIxx(), m.getIyy(), m.getIxy()
384 
385  xx[i], xy[i], yy[i] = Ixx, Ixy, Iyy
386 
387  width = numpy.sqrt(0.5*(xx + yy))
388  with numpy.errstate(invalid="ignore"): # suppress NAN warnings
389  bad = reduce(lambda x, y: numpy.logical_or(x, sourceCat.get(y)), self.config.badFlags, False)
390  bad = numpy.logical_or(bad, numpy.logical_not(numpy.isfinite(width)))
391  bad = numpy.logical_or(bad, numpy.logical_not(numpy.isfinite(flux)))
392  if self.config.doFluxLimit:
393  bad = numpy.logical_or(bad, flux < self.config.fluxMin)
394  if self.config.fluxMax > 0:
395  bad = numpy.logical_or(bad, flux > self.config.fluxMax)
396  if self.config.doSignalToNoiseLimit:
397  bad = numpy.logical_or(bad, flux/fluxErr < self.config.signalToNoiseMin)
398  if self.config.signalToNoiseMax > 0:
399  bad = numpy.logical_or(bad, flux/fluxErr > self.config.signalToNoiseMax)
400  bad = numpy.logical_or(bad, width < self.config.widthMin)
401  bad = numpy.logical_or(bad, width > self.config.widthMax)
402  good = numpy.logical_not(bad)
403 
404  if not numpy.any(good):
405  raise RuntimeError("No objects passed our cuts for consideration as psf stars")
406 
407  mag = -2.5*numpy.log10(flux[good])
408  width = width[good]
409  #
410  # Look for the maximum in the size histogram, then search upwards for the minimum that separates
411  # the initial peak (of, we presume, stars) from the galaxies
412  #
413  if dumpData:
414  import os
415  import pickle as pickle
416  _ii = 0
417  while True:
418  pickleFile = os.path.expanduser(os.path.join("~", "widths-%d.pkl" % _ii))
419  if not os.path.exists(pickleFile):
420  break
421  _ii += 1
422 
423  with open(pickleFile, "wb") as fd:
424  pickle.dump(mag, fd, -1)
425  pickle.dump(width, fd, -1)
426 
427  centers, clusterId = _kcenters(width, nCluster=4, useMedian=True,
428  widthStdAllowed=self.config.widthStdAllowed)
429 
430  if display and plotMagSize:
431  fig = plot(mag, width, centers, clusterId,
432  magType=self.config.sourceFluxField.split(".")[-1].title(),
433  marker="+", markersize=3, markeredgewidth=None, ltype=':', clear=True)
434  else:
435  fig = None
436 
437  clusterId = _improveCluster(width, centers, clusterId,
438  nsigma=self.config.nSigmaClip,
439  widthStdAllowed=self.config.widthStdAllowed)
440 
441  if display and plotMagSize:
442  plot(mag, width, centers, clusterId, marker="x", markersize=3, markeredgewidth=None, clear=False)
443 
444  stellar = (clusterId == 0)
445  #
446  # We know enough to plot, if so requested
447  #
448  frame = 0
449 
450  if fig:
451  if display and displayExposure:
452  disp = afwDisplay.Display(frame=frame)
453  disp.mtv(exposure.getMaskedImage(), title="PSF candidates")
454 
455  global eventHandler
456  eventHandler = EventHandler(fig.get_axes()[0], mag, width,
457  sourceCat.getX()[good], sourceCat.getY()[good], frames=[frame])
458 
459  fig.show()
460 
461  while True:
462  try:
463  reply = input("continue? [c h(elp) q(uit) p(db)] ").strip()
464  except EOFError:
465  reply = None
466  if not reply:
467  reply = "c"
468 
469  if reply:
470  if reply[0] == "h":
471  print("""\
472  We cluster the points; red are the stellar candidates and the other colours are other clusters.
473  Points labelled + are rejects from the cluster (only for cluster 0).
474 
475  At this prompt, you can continue with almost any key; 'p' enters pdb, and 'h' prints this text
476 
477  If displayExposure is true, you can put the cursor on a point and hit 'p' to see it in the
478  image display.
479  """)
480  elif reply[0] == "p":
481  import pdb
482  pdb.set_trace()
483  elif reply[0] == 'q':
484  sys.exit(1)
485  else:
486  break
487 
488  if display and displayExposure:
489  mi = exposure.getMaskedImage()
490  with disp.Buffering():
491  for i, source in enumerate(sourceCat):
492  if good[i]:
493  ctype = afwDisplay.GREEN # star candidate
494  else:
495  ctype = afwDisplay.RED # not star
496 
497  disp.dot("+", source.getX() - mi.getX0(), source.getY() - mi.getY0(), ctype=ctype)
498 
499  # stellar only applies to good==True objects
500  mask = good == True # noqa (numpy bool comparison): E712
501  good[mask] = stellar
502 
503  return Struct(selected=good)
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
bool strip
Definition: fits.cc:911
lsst::geom::AffineTransform linearizeTransform(TransformPoint2ToPoint2 const &original, lsst::geom::Point2D const &inPoint)
Approximate a Transform by its local linearization.
def plot(mag, width, centers, clusterId, marker="o", markersize=2, markeredgewidth=0, ltype='-', magType="model", clear=True)

Member Data Documentation

◆ ConfigClass

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

Definition at line 327 of file objectSizeStarSelector.py.

◆ usesMatches

bool lsst.meas.algorithms.objectSizeStarSelector.ObjectSizeStarSelectorTask.usesMatches = False
static

Definition at line 328 of file objectSizeStarSelector.py.


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