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
psfSelectionFromMatchList.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 # Copyright 2008, 2009, 2010 LSST Corporation.
4 #
5 # This product includes software developed by the
6 # LSST Project (http://www.lsst.org/).
7 #
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the LSST License Statement and
19 # the GNU General Public License along with this program. If not,
20 # see <http://www.lsstcorp.org/LegalNotices/>.
21 #
22 import numpy
23 import lsst.afw.math as afwMath
24 import lsst.meas.algorithms as measAlg
25 import lsst.afw.display.ds9 as ds9
26 
27 args = [None, "MatchList", None] # allow the user to probe for this signature
28 
29 def selectPsfSources(exposure, matches, psfPolicy):
30  """Get a list of suitable stars to construct a PSF."""
31 
32  import lsstDebug
33  display = lsstDebug.Info(__name__).display
34  displayExposure = lsstDebug.Info(__name__).displayExposure # display the Exposure + spatialCells
35  #
36  # Unpack policy
37  #
38  kernelSize = psfPolicy.get("kernelSize")
39  borderWidth = psfPolicy.get("borderWidth")
40  sizePsfCellX = psfPolicy.get("sizeCellX")
41  sizePsfCellY = psfPolicy.get("sizeCellY")
42  #
43  mi = exposure.getMaskedImage()
44 
45  if display and displayExposure:
46  frame = 0
47  ds9.mtv(mi, frame=frame, title="PSF candidates")
48 
49  psfCellSet = afwMath.SpatialCellSet(mi.getBBox(), sizePsfCellX, sizePsfCellY)
50  psfStars = []
51 
52  for val in matches:
53  ref, source = val[0:2]
54  if not (ref.getFlagForDetection() & measAlg.Flags.STAR) or \
55  (source.getFlagForDetection() & measAlg.Flags.BAD):
56  continue
57 
58  try:
59  cand = measAlg.makePsfCandidate(source, mi)
60  #
61  # The setXXX methods are class static, but it's convenient to call them on
62  # an instance as we don't know Exposure's pixel type (and hence cand's exact type)
63  if cand.getWidth() == 0:
64  cand.setBorderWidth(borderWidth)
65  cand.setWidth(kernelSize + 2*borderWidth)
66  cand.setHeight(kernelSize + 2*borderWidth)
67 
68  im = cand.getMaskedImage().getImage()
69  max = afwMath.makeStatistics(im, afwMath.MAX).getValue()
70  if not numpy.isfinite(max):
71  continue
72 
73  psfCellSet.insertCandidate(cand)
74 
75  if display and displayExposure:
76  ds9.dot("+", source.getXAstrom() - mi.getX0(), source.getYAstrom() - mi.getY0(),
77  size=4, frame=frame, ctype=ds9.CYAN)
78  ds9.dot("o", source.getXAstrom() - mi.getX0(), source.getYAstrom() - mi.getY0(),
79  size=4, frame=frame, ctype=ds9.CYAN)
80  except Exception:
81  continue
82 
83  source.setFlagForDetection(source.getFlagForDetection() | measAlg.Flags.STAR)
84  psfStars += [source]
85 
86  return psfStars, psfCellSet
boost::shared_ptr< PsfCandidate< PixelT > > makePsfCandidate(boost::shared_ptr< afw::table::SourceRecord > const &source, boost::shared_ptr< afw::image::Exposure< PixelT > > image)
Definition: PsfCandidate.h:188
A collection of SpatialCells covering an entire image.
Definition: SpatialCell.h:378
Statistics makeStatistics(afwImage::Mask< afwImage::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl)
Specialization to handle Masks.
Definition: Statistics.cc:1082