LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+ffe7eabc7e,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g36da64cc00+ea84795170,g3ddfee87b4+955a963fd8,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+955a963fd8,g591dd9f2cf+bac198a2cb,g5ec818987f+420292cfeb,g858d7b2824+d6c9a0a3b8,g876c692160+aabc49a3c3,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+e6cd765486,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+acd47f83f4,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+12c8382528,gba4ed39666+1ac82b564f,gbb8dafda3b+0574160a1f,gbeb006f7da+dea2fbb49f,gc28159a63d+c6dfa2ddaf,gc86a011abf+d6c9a0a3b8,gcf0d15dbbd+955a963fd8,gdaeeff99f8+1cafcb7cd4,gdc0c513512+d6c9a0a3b8,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,gee10cc3b42+90ebb246c7,gf1cff7945b+d6c9a0a3b8,w.2024.13
LSST Data Management Base Package
Loading...
Searching...
No Matches
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

 selectSources (self, sourceCat, 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

◆ selectSources()

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.

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

    ``selected``
        Boolean array of sources that were selected, same length as
        sourceCat. (`numpy.ndarray` of `bool`)

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 Returns
347 -------
348 struct : `lsst.pipe.base.Struct`
349 The struct contains the following data:
350
351 ``selected``
352 Boolean array of sources that were selected, same length as
353 sourceCat. (`numpy.ndarray` of `bool`)
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[self.config.sourceFluxField]
371 fluxErr = sourceCat[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[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:930
lsst::geom::AffineTransform linearizeTransform(TransformPoint2ToPoint2 const &original, lsst::geom::Point2D const &inPoint)
Approximate a Transform by its local linearization.

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: