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.extensions.psfex.psfexStarSelector.PsfexStarSelectorTask Class Reference
Inheritance diagram for lsst.meas.extensions.psfex.psfexStarSelector.PsfexStarSelectorTask:
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 = PsfexStarSelectorConfig
 
bool usesMatches = False
 

Detailed Description

A star selector whose algorithm is not yet documented.

@anchor PsfexStarSelectorTask_

@section meas_extensions_psfex_psfexStarSelectorStarSelector_Contents  Contents

 - @ref meas_extensions_psfex_psfexStarSelectorStarSelector_Purpose
 - @ref meas_extensions_psfex_psfexStarSelectorStarSelector_Initialize
 - @ref meas_extensions_psfex_psfexStarSelectorStarSelector_IO
 - @ref meas_extensions_psfex_psfexStarSelectorStarSelector_Config
 - @ref meas_extensions_psfex_psfexStarSelectorStarSelector_Debug

@section meas_extensions_psfex_psfexStarSelectorStarSelector_Purpose  Description

A star selector whose algorithm is not yet documented

@section meas_extensions_psfex_psfexStarSelectorStarSelector_Initialize  Task initialisation

@copydoc \_\_init\_\_

@section meas_extensions_psfex_psfexStarSelectorStarSelector_IO  Invoking the Task

Like all star selectors, the main method is `run`.

@section meas_extensions_psfex_psfexStarSelectorStarSelector_Config  Configuration parameters

See @ref PsfexStarSelectorConfig

@section meas_extensions_psfex_psfexStarSelectorStarSelector_Debug  Debug variables

PsfexStarSelectorTask has a debug dictionary with the following keys:
<dl>
<dt>display
<dd>bool; if True display debug information
<dt>displayExposure
<dd>bool; if True display the exposure and spatial cells
<dt>plotFwhmHistogram
<dd>bool; if True plot histogram of FWHM
<dt>plotFlags
<dd>bool: if True plot the sources coloured by their flags
<dt>plotRejection
<dd>bool; if True plot why sources are rejected
</dl>

For example, put something like:
@code{.py}
    import lsstDebug
    def DebugInfo(name):
        di = lsstDebug.getInfo(name)  # N.b. lsstDebug.Info(name) would call us recursively
        if name.endswith("objectSizeStarSelector"):
            di.display = True
            di.displayExposure = True
            di.plotFwhmHistogram = True

        return di

    lsstDebug.Info = DebugInfo
@endcode
into your `debug.py` file and run your task with the `--debug` flag.

Definition at line 202 of file psfexStarSelector.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.extensions.psfex.psfexStarSelector.PsfexStarSelectorTask.selectSources (   self,
  sourceCat,
  matches = None,
  exposure = None 
)
Return a selection of psf-like objects.

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 by this source selector.
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:

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

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

Definition at line 266 of file psfexStarSelector.py.

266  def selectSources(self, sourceCat, matches=None, exposure=None):
267  """Return a selection of psf-like objects.
268 
269  Parameters
270  ----------
271  sourceCat : `lsst.afw.table.SourceCatalog`
272  Catalog of sources to select from.
273  This catalog must be contiguous in memory.
274  matches : `list` of `lsst.afw.table.ReferenceMatch` or None
275  Ignored by this source selector.
276  exposure : `lsst.afw.image.Exposure` or None
277  The exposure the catalog was built from; used for debug display.
278 
279  Return
280  ------
281  struct : `lsst.pipe.base.Struct`
282  The struct contains the following data:
283 
284  - selected : `numpy.ndarray` of `bool``
285  Boolean array of sources that were selected, same length as
286  sourceCat.
287  """
288  import lsstDebug
289  display = lsstDebug.Info(__name__).display
290 
291  displayExposure = display and \
292  lsstDebug.Info(__name__).displayExposure # display the Exposure + spatialCells
293  plotFwhmHistogram = display and plt and \
294  lsstDebug.Info(__name__).plotFwhmHistogram # Plot histogram of FWHM
295  plotFlags = display and plt and \
296  lsstDebug.Info(__name__).plotFlags # Plot the sources coloured by their flags
297  plotRejection = display and plt and \
298  lsstDebug.Info(__name__).plotRejection # Plot why sources are rejected
299  afwDisplay.setDefaultMaskTransparency(75)
300 
301  fluxName = self.config.fluxName
302  fluxErrName = self.config.fluxErrName
303  minFwhm = self.config.minFwhm
304  maxFwhm = self.config.maxFwhm
305  maxFwhmVariability = self.config.maxFwhmVariability
306  maxellip = self.config.maxellip
307  minsn = self.config.minsn
308 
309  maxelong = (maxellip + 1.0)/(1.0 - maxellip) if maxellip < 1.0 else 100
310 
311  # Unpack the catalogue
312  shape = sourceCat.getShapeDefinition()
313  ixx = sourceCat.get("%s.xx" % shape)
314  iyy = sourceCat.get("%s.yy" % shape)
315 
316  fwhm = 2*np.sqrt(2*np.log(2))*np.sqrt(0.5*(ixx + iyy))
317  elong = 0.5*(ixx - iyy)/(ixx + iyy)
318 
319  flux = sourceCat.get(fluxName)
320  fluxErr = sourceCat.get(fluxErrName)
321  sn = flux/np.where(fluxErr > 0, fluxErr, 1)
322  sn[fluxErr <= 0] = -psfexLib.BIG
323 
324  flags = 0x0
325  for i, f in enumerate(self.config.badFlags):
326  flags = np.bitwise_or(flags, np.where(sourceCat.get(f), 1 << i, 0))
327  #
328  # Estimate the acceptable range of source widths
329  #
330  good = np.logical_and(sn > minsn, np.logical_not(flags))
331  good = np.logical_and(good, elong < maxelong)
332  good = np.logical_and(good, fwhm >= minFwhm)
333  good = np.logical_and(good, fwhm < maxFwhm)
334 
335  fwhmMode, fwhmMin, fwhmMax = compute_fwhmrange(fwhm[good], maxFwhmVariability, minFwhm, maxFwhm,
336  plot=dict(fwhmHistogram=plotFwhmHistogram))
337 
338  # -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
339  #
340  # Here's select_candidates
341  #
342  # ---- Apply some selection over flags, fluxes...
343 
344  bad = (flags != 0)
345  # set.setBadFlags(int(sum(bad)))
346 
347  if plotRejection:
348  selectionVectors = []
349  selectionVectors.append((bad, "flags %d" % sum(bad)))
350 
351  dbad = sn < minsn
352  # set.setBadSN(int(sum(dbad)))
353  bad = np.logical_or(bad, dbad)
354  if plotRejection:
355  selectionVectors.append((dbad, "S/N %d" % sum(dbad)))
356 
357  dbad = fwhm < fwhmMin
358  # set.setBadFrmin(int(sum(dbad)))
359  bad = np.logical_or(bad, dbad)
360  if plotRejection:
361  selectionVectors.append((dbad, "fwhmMin %d" % sum(dbad)))
362 
363  dbad = fwhm > fwhmMax
364  # set.setBadFrmax(int(sum(dbad)))
365  bad = np.logical_or(bad, dbad)
366  if plotRejection:
367  selectionVectors.append((dbad, "fwhmMax %d" % sum(dbad)))
368 
369  dbad = elong > maxelong
370  # set.setBadElong(int(sum(dbad)))
371  bad = np.logical_or(bad, dbad)
372  if plotRejection:
373  selectionVectors.append((dbad, "elong %d" % sum(dbad)))
374 
375  good = np.logical_not(bad)
376  #
377  # We know enough to plot, if so requested
378  #
379  frame = 0
380  if displayExposure:
381  mi = exposure.getMaskedImage()
382  disp = afwDisplay.Display(frame=frame)
383  disp.mtv(mi, title="PSF candidates")
384 
385  with disp.Buffering():
386  for i, source in enumerate(sourceCat):
387  if good[i]:
388  ctype = afwDisplay.GREEN # star candidate
389  else:
390  ctype = afwDisplay.RED # not star
391 
392  disp.dot("+", source.getX() - mi.getX0(), source.getY() - mi.getY0(),
393  ctype=ctype)
394 
395  if plotFlags or plotRejection:
396  imag = -2.5*np.log10(flux)
397  plt.clf()
398 
399  alpha = 0.5
400  if plotFlags:
401  isSet = np.where(flags == 0x0)[0]
402  plt.plot(imag[isSet], fwhm[isSet], 'o', alpha=alpha, label="good")
403 
404  for i, f in enumerate(self.config.badFlags):
405  mask = 1 << i
406  isSet = np.where(np.bitwise_and(flags, mask))[0]
407  if isSet.any():
408  if np.isfinite(imag[isSet] + fwhm[isSet]).any():
409  label = re.sub(r"\_flag", "",
410  re.sub(r"^base\_", "",
411  re.sub(r"^.*base\_PixelFlags\_flag\_", "", f)))
412  plt.plot(imag[isSet], fwhm[isSet], 'o', alpha=alpha, label=label)
413  else:
414  for bad, label in selectionVectors:
415  plt.plot(imag[bad], fwhm[bad], 'o', alpha=alpha, label=label)
416 
417  plt.plot(imag[good], fwhm[good], 'o', color="black", label="selected")
418  [plt.axhline(_, color='red') for _ in [fwhmMin, fwhmMax]]
419  plt.xlim(np.median(imag[good]) + 5*np.array([-1, 1]))
420  plt.ylim(fwhm[np.where(np.isfinite(fwhm + imag))].min(), 2*fwhmMax)
421  plt.legend(loc=2)
422  plt.xlabel("Instrumental %s Magnitude" % fluxName.split(".")[-1].title())
423  plt.ylabel("fwhm")
424  title = "PSFEX Star Selection"
425  plt.title("%s %d selected" % (title, sum(good)))
426 
427  if displayExposure:
428  global eventHandler
429  eventHandler = EventHandler(plt.axes(), imag, fwhm, sourceCat.getX(), sourceCat.getY(),
430  frames=[frame])
431 
432  if plotFlags or plotRejection:
433  while True:
434  try:
435  reply = input("continue? [y[es] h(elp) p(db) q(uit)] ").strip()
436  except EOFError:
437  reply = "y"
438 
439  if not reply:
440  reply = "y"
441 
442  if reply[0] == "h":
443  print("""\
444 At this prompt, you can continue with almost any key; 'p' enters pdb,
445  'q' returns to the shell, and
446  'h' prints this text
447 """, end=' ')
448 
449  if displayExposure:
450  print("""
451 If you put the cursor on a point in the matplotlib scatter plot and hit 'p' you'll see it in ds9.""")
452  elif reply[0] == "p":
453  import pdb
454  pdb.set_trace()
455  elif reply[0] == 'q':
456  sys.exit(1)
457  else:
458  break
459 
460  return Struct(selected=good)
int min
bool strip
Definition: fits.cc:911
bool any(CoordinateExpr< N > const &expr) noexcept
Return true if any elements are true.
def compute_fwhmrange(fwhm, maxvar, minin, maxin, plot=dict(fwhmHistogram=False))
Definition: psfex.py:22

Member Data Documentation

◆ ConfigClass

lsst.meas.extensions.psfex.psfexStarSelector.PsfexStarSelectorTask.ConfigClass = PsfexStarSelectorConfig
static

Definition at line 263 of file psfexStarSelector.py.

◆ usesMatches

bool lsst.meas.extensions.psfex.psfexStarSelector.PsfexStarSelectorTask.usesMatches = False
static

Definition at line 264 of file psfexStarSelector.py.


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