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.extensions.psfex.psfexStarSelector.PsfexStarSelectorTask Class Reference
Inheritance diagram for lsst.meas.extensions.psfex.psfexStarSelector.PsfexStarSelectorTask:
lsst.meas.algorithms.sourceSelector.BaseSourceSelectorTask

Public Member Functions

 selectSources (self, sourceCat, 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 189 of file psfexStarSelector.py.

Member Function Documentation

◆ selectSources()

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 253 of file psfexStarSelector.py.

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

Member Data Documentation

◆ ConfigClass

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

Definition at line 250 of file psfexStarSelector.py.

◆ usesMatches

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

Definition at line 251 of file psfexStarSelector.py.


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