lsst.meas.extensions.photometryKron  14.0-1-g30344f0+45
photometryKron.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2015 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef LSST_MEAS_EXTENSIONS_PHOTOMETRY_KRON_H
24 #define LSST_MEAS_EXTENSIONS_PHOTOMETRY_KRON_H
25 
26 #include <memory>
27 #include <cmath>
28 
29 #include "lsst/pex/config.h"
36 
37 namespace lsst { namespace meas { namespace extensions { namespace photometryKron {
38 
39 class KronAperture;
40 
47 public:
48 
50  "if true, use existing shape and centroid measurements instead of fitting");
52  "Multiplier of rms size for aperture used to initially estimate the Kron radius");
53  LSST_CONTROL_FIELD(nIterForRadius, int, "Number of times to iterate when setting the Kron radius");
54  LSST_CONTROL_FIELD(nRadiusForFlux, double, "Number of Kron radii for Kron flux");
56  "Largest aperture for which to use the slow, accurate, sinc aperture code");
58  "Minimum Kron radius (if == 0.0 use PSF's Kron radius) if enforceMinimumRadius. "
59  "Also functions as fallback aperture radius if set.");
60  LSST_CONTROL_FIELD(enforceMinimumRadius, bool, "If true check that the Kron radius exceeds some minimum");
62  "Use the Footprint size as part of initial estimate of Kron radius");
64  "Smooth image with N(0, smoothingSigma^2) Gaussian while estimating R_K");
66  "Name of field specifying reference Kron radius for forced measurement");
67 
69  fixed(false),
70  nSigmaForRadius(6.0),
71  nIterForRadius(1),
72  nRadiusForFlux(2.5),
73  maxSincRadius(10.0),
74  minimumRadius(0.0),
76  useFootprintRadius(false),
77  smoothingSigma(-1.0),
78  refRadiusName("ext_photometryKron_KronFlux_radius")
79  {}
80 };
81 
86 public:
87 
88  // Structures and routines to manage flaghandler
89  static meas::base::FlagDefinitionList const & getFlagDefinitions();
100 
104 
106  Control const & ctrl,
107  std::string const & name,
108  afw::table::Schema & schema,
109  daf::base::PropertySet & metadata
110  );
111 
112  virtual void measure(
113  afw::table::SourceRecord & measRecord,
114  afw::image::Exposure<float> const & exposure
115  ) const;
116 
117  virtual void measureForced(
118  afw::table::SourceRecord & measRecord,
119  afw::image::Exposure<float> const & exposure,
120  afw::table::SourceRecord const & refRecord,
121  afw::image::Wcs const & refWcs
122  ) const;
123 
124  virtual void fail(
125  afw::table::SourceRecord & measRecord,
126  meas::base::MeasurementError * error=NULL
127  ) const;
128 
129 private:
130 
131  void _applyAperture(
132  afw::table::SourceRecord & source,
133  afw::image::Exposure<float> const& exposure,
134  KronAperture const& aperture
135  ) const;
136 
137  void _applyForced(
138  afw::table::SourceRecord & source,
139  afw::image::Exposure<float> const & exposure,
140  afw::geom::Point2D const & center,
141  afw::table::SourceRecord const & reference,
142  afw::geom::AffineTransform const & refToMeas
143  ) const;
144 
145  PTR(KronAperture) _fallbackRadius(afw::table::SourceRecord& source, double const R_K_psf,
146  pex::exceptions::Exception& exc) const;
147 
149  Control _ctrl;
150  meas::base::FluxResultKey _fluxResultKey;
151  afw::table::Key<float> _radiusKey;
152  afw::table::Key<float> _radiusForRadiusKey;
153  afw::table::Key<float> _psfRadiusKey;
154  meas::base::FlagHandler _flagHandler;
155  meas::base::SafeCentroidExtractor _centroidExtractor;
156 };
157 
159 public:
161  float radiusForRadius=std::nanf("")) :
162  _center(center),
163  _axes(core),
164  _radiusForRadius(radiusForRadius)
165  {}
166 
167  explicit KronAperture(afw::table::SourceRecord const& source, float radiusForRadius=std::nanf("")) :
168  _center(afw::geom::Point2D(source.getX(), source.getY())),
169  _axes(source.getShape()),
170  _radiusForRadius(radiusForRadius)
171  {}
172 
174  double radius, float radiusForRadius=std::nanf("")) :
175  _center(refToMeas(reference.getCentroid())),
176  _axes(getKronAxes(reference.getShape(), refToMeas.getLinear(), radius)),
177  _radiusForRadius(radiusForRadius)
178  {}
179 
181  double getX() const { return _center.getX(); }
182  double getY() const { return _center.getY(); }
183  float getRadiusForRadius() const { return _radiusForRadius; }
184 
185  afw::geom::Point2D const& getCenter() const { return _center; }
186 
187  afw::geom::ellipses::Axes & getAxes() { return _axes; }
188 
189  afw::geom::ellipses::Axes const& getAxes() const { return _axes; }
190 
191 
196  template<typename ImageT>
197  static PTR(KronAperture) determineRadius(
198  ImageT const& image,
200  afw::geom::Point2D const& center,
201  KronFluxControl const& ctrl
202  );
203 
205  template<typename ImageT>
206  std::pair<double, double> measureFlux(
207  ImageT const& image,
208  double const nRadiusForFlux,
209  double const maxSincRadius
210  ) const;
211 
214  afw::geom::Point2D const center = trans(getCenter());
215  afw::geom::ellipses::Axes const axes(*getAxes().transform(trans.getLinear()).copy());
216  return std::make_shared<KronAperture>(center, axes);
217  }
218 
220  static
221  afw::geom::ellipses::Axes getKronAxes(
222  afw::geom::ellipses::Axes const& shape,
223  afw::geom::LinearTransform const& transformation,
224  double const radius
225  );
226 
227 private:
228  afw::geom::Point2D const _center; // Center of aperture
229  afw::geom::ellipses::Axes _axes; // Ellipse defining aperture shape
230  float _radiusForRadius; // Radius used to estimate the Kron radius
231 };
232 
233 }}}} // namespace lsst::meas::extensions::photometryKron
234 
235 #endif // !LSST_MEAS_EXTENSIONS_PHOTOMETRY_KRON_H
static meas::base::FlagDefinition const SMALL_RADIUS
static meas::base::FlagDefinition const NO_MINIMUM_RADIUS
afw::table::Key< afw::table::Array< ImagePixelT > > image
std::string const & _name
double smoothingSigma
"Smooth image with N(0, smoothingSigma^2) Gaussian while estimating R_K" ;
afw::geom::Point2D const & getCenter() const
LinearTransform const & getLinear() const
double minimumRadius
"Minimum Kron radius (if == 0.0 use PSF&#39;s Kron radius) if enforceMinimumRadius. " "Also functions as ...
boost::shared_ptr< KronAperture > transform(afw::geom::AffineTransform const &trans) const
Transform a Kron Aperture to a different frame.
#define PTR(...)
bool fixed
"if true, use existing shape and centroid measurements instead of fitting" ;
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
STL class.
static meas::base::FlagDefinition const USED_MINIMUM_RADIUS
static meas::base::FlagDefinition const USED_PSF_RADIUS
static meas::base::FlagDefinition const NO_FALLBACK_RADIUS
static meas::base::FlagDefinition const BAD_SHAPE_NO_PSF
double nSigmaForRadius
"Multiplier of rms size for aperture used to initially estimate the Kron radius" ; ...
afw::geom::ellipses::Axes const & getAxes() const
bool enforceMinimumRadius
"If true check that the Kron radius exceeds some minimum" ;
KronFluxControl Control
A typedef to the Control object for this algorithm, defined above.
std::string refRadiusName
"Name of field specifying reference Kron radius for forced measurement" ;
KronAperture(afw::table::SourceRecord const &reference, afw::geom::AffineTransform const &refToMeas, double radius, float radiusForRadius=std::nanf(""))
static meas::base::FlagDefinition const FAILURE
double maxSincRadius
"Largest aperture for which to use the slow, accurate, sinc aperture code" ;
static meas::base::FlagDefinition const BAD_RADIUS
int nIterForRadius
"Number of times to iterate when setting the Kron radius" ;
bool useFootprintRadius
"Use the Footprint size as part of initial estimate of Kron radius" ;
A measurement algorithm that estimates flux using Kron photometry.
static meas::base::FlagDefinition const EDGE
T nanf(T... args)
KronAperture(afw::geom::Point2D const &center, afw::geom::ellipses::BaseCore const &core, float radiusForRadius=std::nanf(""))
KronAperture(afw::table::SourceRecord const &source, float radiusForRadius=std::nanf(""))
table::Key< int > transform
double nRadiusForFlux
"Number of Kron radii for Kron flux" ;
static meas::base::FlagDefinition const BAD_SHAPE