lsst.meas.algorithms  13.0-20-g02a2147
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PsfCandidate.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 #if !defined(LSST_MEAS_ALGORITHMS_PSFCANDIDATE_H)
3 #define LSST_MEAS_ALGORITHMS_PSFCANDIDATE_H
4 
5 /*
6  * LSST Data Management System
7  * Copyright 2008, 2009, 2010 LSST Corporation.
8  *
9  * This product includes software developed by the
10  * LSST Project (http://www.lsst.org/).
11  *
12  * This program is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the LSST License Statement and
23  * the GNU General Public License along with this program. If not,
24  * see <http://www.lsstcorp.org/LegalNotices/>.
25  */
26 
34 #include <memory>
35 #include <vector>
36 
37 #include "lsst/pex/policy.h"
38 
39 #include "lsst/afw/image/Exposure.h"
40 #include "lsst/afw/detection/Psf.h"
41 #include "lsst/afw/detection/FootprintSet.h"
42 #include "lsst/afw/table/Source.h"
43 #include "lsst/afw/math/SpatialCell.h"
44 
45 namespace lsst {
46 namespace meas {
47 namespace algorithms {
55  template <typename PixelT>
56  class PsfCandidate : public lsst::afw::math::SpatialCellImageCandidate {
57  public:
58 
59  typedef std::shared_ptr<PsfCandidate<PixelT> > Ptr;
60  typedef std::shared_ptr<const PsfCandidate<PixelT> > ConstPtr;
61  typedef std::vector<Ptr > PtrList;
62 
63  typedef lsst::afw::image::MaskedImage<PixelT> MaskedImageT;
64 
71  PTR(afw::table::SourceRecord) const& source,
72  CONST_PTR(afw::image::Exposure<PixelT>) parentExposure
73  ) :
74  afw::math::SpatialCellImageCandidate(source->getX(), source->getY()),
75  _parentExposure(parentExposure),
76  _offsetImage(),
77  _source(source),
78  _image(nullptr),
79  _amplitude(0.0), _var(1.0)
80  {}
81 
86  PTR(afw::table::SourceRecord) const& source,
87  CONST_PTR(afw::image::Exposure<PixelT>) parentExposure,
88  double xCenter,
89  double yCenter
90  ) :
91  afw::math::SpatialCellImageCandidate(xCenter, yCenter),
92  _parentExposure(parentExposure),
93  _offsetImage(),
94  _source(source),
95  _image(nullptr),
96  _amplitude(0.0), _var(1.0)
97  {}
98 
100  virtual ~PsfCandidate() {};
101 
107  double getCandidateRating() const { return _source->getPsfFlux(); }
108 
110  PTR(afw::table::SourceRecord) getSource() const { return _source; }
111 
113  double getAmplitude() const { return _amplitude; }
114 
116  void setAmplitude(double amplitude) { _amplitude = amplitude; }
117 
119  double getVar() const { return _var; }
120 
122  void setVar(double var) { _var = var; }
123 
124  CONST_PTR(afw::image::MaskedImage<PixelT>) getMaskedImage() const;
125  CONST_PTR(afw::image::MaskedImage<PixelT>) getMaskedImage(int width, int height) const;
126  PTR(afw::image::MaskedImage<PixelT>) getOffsetImage(std::string const algorithm,
127  unsigned int buffer) const;
128 
130  static int getBorderWidth() { return _border; }
131 
133  static void setBorderWidth(int border) { _border = border; }
134 
138  static void setPixelThreshold(float threshold) { _pixelThreshold = threshold; }
139 
141  static float getPixelThreshold() { return _pixelThreshold; }
142 
144  static void setMaskBlends(bool doMaskBlends) { _doMaskBlends = doMaskBlends; }
145 
147  static bool getMaskBlends() { return _doMaskBlends; }
148 
149  private:
150  CONST_PTR(lsst::afw::image::Exposure<PixelT>) _parentExposure; // the %image that the Sources are found in
151 
152  PTR(afw::image::MaskedImage<PixelT>)
153  offsetImage(
154  PTR(afw::image::MaskedImage<PixelT>) img,
155  std::string const algorithm,
156  unsigned int buffer
157  );
158 
159  PTR(afw::image::MaskedImage<PixelT>)
160  extractImage(unsigned int width, unsigned int height) const;
161 
162  PTR(afw::image::MaskedImage<PixelT>) mutable _offsetImage; // %image offset to put center on a pixel
163  PTR(afw::table::SourceRecord) _source; // the Source itself
164 
165  mutable std::shared_ptr<afw::image::MaskedImage<PixelT>> _image; // cutout image to return (cached)
166  double _amplitude; // best-fit amplitude of current PSF model
167  double _var; // variance to use when fitting this candidate
168  static int _border; // width of border of ignored pixels around _image
169  afw::geom::Point2D _xyCenter;
170  static int _defaultWidth;
171  static float _pixelThreshold;
172  static bool _doMaskBlends;
173  };
174 
180  template <typename PixelT>
181  std::shared_ptr<PsfCandidate<PixelT> >
182  makePsfCandidate(PTR(afw::table::SourceRecord) const& source,
183  PTR(afw::image::Exposure<PixelT>) image
184  )
185  {
186  return std::make_shared< PsfCandidate<PixelT> >(source, image);
187  }
188 
189 }}}
190 
191 #endif
void setAmplitude(double amplitude)
Set the best-fit amplitude.
Definition: PsfCandidate.h:116
std::shared_ptr< PsfCandidate< PixelT > > Ptr
Definition: PsfCandidate.h:59
std::shared_ptr< const PsfCandidate< PixelT > > ConstPtr
Definition: PsfCandidate.h:60
static void setPixelThreshold(float threshold)
Set threshold for rejecting pixels unconnected with the central footprint.
Definition: PsfCandidate.h:138
PsfCandidate(boost::shared_ptr< afw::table::SourceRecord > const &source, boost::shared_ptr< afw::image::Exposure< PixelT > const > parentExposure, double xCenter, double yCenter)
Construct a PsfCandidate from a specified source, image and xyCenter.
Definition: PsfCandidate.h:85
double getCandidateRating() const
Return Cell rating.
Definition: PsfCandidate.h:107
static void setMaskBlends(bool doMaskBlends)
Set whether blends are masked.
Definition: PsfCandidate.h:144
boost::shared_ptr< afw::table::SourceRecord > getSource() const
Return the original Source.
Definition: PsfCandidate.h:110
boost::shared_ptr< afw::image::MaskedImage< PixelT > const > getMaskedImage() const
Return the image at the position of the Source, without any sub-pixel shifts to put the centre of the...
virtual ~PsfCandidate()
Destructor.
Definition: PsfCandidate.h:100
static bool getMaskBlends()
Get whether blends are masked.
Definition: PsfCandidate.h:147
double getAmplitude() const
Return the best-fit amplitude.
Definition: PsfCandidate.h:113
void setVar(double var)
Set the variance to use when fitting this object.
Definition: PsfCandidate.h:122
std::shared_ptr< PsfCandidate< PixelT > > makePsfCandidate(boost::shared_ptr< afw::table::SourceRecord > const &source, boost::shared_ptr< afw::image::Exposure< PixelT > > image)
Return a PsfCandidate of the right sort.
Definition: PsfCandidate.h:182
static float getPixelThreshold()
Get threshold for rejecting pixels unconnected with the central footprint.
Definition: PsfCandidate.h:141
PsfCandidate(boost::shared_ptr< afw::table::SourceRecord > const &source, boost::shared_ptr< afw::image::Exposure< PixelT > const > parentExposure)
Construct a PsfCandidate from a specified source and image.
Definition: PsfCandidate.h:70
static int getBorderWidth()
Return the number of pixels being ignored around the candidate image&#39;s edge.
Definition: PsfCandidate.h:130
boost::shared_ptr< afw::image::MaskedImage< PixelT > > getOffsetImage(std::string const algorithm, unsigned int buffer) const
Return an offset version of the image of the source.
static void setBorderWidth(int border)
Set the number of pixels to ignore around the candidate image&#39;s edge.
Definition: PsfCandidate.h:133
Class stored in SpatialCells for spatial Psf fitting.
Definition: PsfCandidate.h:56
lsst::afw::image::MaskedImage< PixelT > MaskedImageT
Definition: PsfCandidate.h:63
double getVar() const
Return the variance in use when fitting this object.
Definition: PsfCandidate.h:119