LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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:1023