LSSTApplications  18.1.0
LSSTDataManagementBasePackage
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"
31 #include "lsst/afw/geom/SkyWcs.h"
37 
38 namespace lsst { namespace meas { namespace extensions { namespace photometryKron {
39 
40 class KronAperture;
41 
48 public:
49 
51  "if true, use existing shape and centroid measurements instead of fitting");
53  "Multiplier of rms size for aperture used to initially estimate the Kron radius");
54  LSST_CONTROL_FIELD(nIterForRadius, int, "Number of times to iterate when setting the Kron radius");
55  LSST_CONTROL_FIELD(nRadiusForFlux, double, "Number of Kron radii for Kron flux");
57  "Largest aperture for which to use the slow, accurate, sinc aperture code");
59  "Minimum Kron radius (if == 0.0 use PSF's Kron radius) if enforceMinimumRadius. "
60  "Also functions as fallback aperture radius if set.");
61  LSST_CONTROL_FIELD(enforceMinimumRadius, bool, "If true check that the Kron radius exceeds some minimum");
63  "Use the Footprint size as part of initial estimate of Kron radius");
65  "Smooth image with N(0, smoothingSigma^2) Gaussian while estimating R_K");
67  "Name of field specifying reference Kron radius for forced measurement");
68 
70  fixed(false),
71  nSigmaForRadius(6.0),
72  nIterForRadius(1),
73  nRadiusForFlux(2.5),
74  maxSincRadius(10.0),
75  minimumRadius(0.0),
77  useFootprintRadius(false),
78  smoothingSigma(-1.0),
79  refRadiusName("ext_photometryKron_KronFlux_radius")
80  {}
81 };
82 
87 public:
88 
89  // Structures and routines to manage flaghandler
90  static meas::base::FlagDefinitionList const & getFlagDefinitions();
101 
105 
107  Control const & ctrl,
108  std::string const & name,
110  daf::base::PropertySet & metadata
111  );
112 
113  virtual void measure(
114  afw::table::SourceRecord & measRecord,
115  afw::image::Exposure<float> const & exposure
116  ) const;
117 
118  virtual void measureForced(
119  afw::table::SourceRecord & measRecord,
120  afw::image::Exposure<float> const & exposure,
121  afw::table::SourceRecord const & refRecord,
122  afw::geom::SkyWcs const & refWcs
123  ) const;
124 
125  virtual void fail(
126  afw::table::SourceRecord & measRecord,
128  ) const;
129 
130 private:
131 
132  void _applyAperture(
134  afw::image::Exposure<float> const& exposure,
135  KronAperture const& aperture
136  ) const;
137 
138  void _applyForced(
140  afw::image::Exposure<float> const & exposure,
141  afw::geom::Point2D const & center,
142  afw::table::SourceRecord const & reference,
143  afw::geom::AffineTransform const & refToMeas
144  ) const;
145 
146  PTR(KronAperture) _fallbackRadius(afw::table::SourceRecord& source, double const R_K_psf,
147  pex::exceptions::Exception& exc) const;
148 
149  std::string _name;
150  Control _ctrl;
151  meas::base::FluxResultKey _fluxResultKey;
152  afw::table::Key<float> _radiusKey;
153  afw::table::Key<float> _radiusForRadiusKey;
154  afw::table::Key<float> _psfRadiusKey;
155  meas::base::FlagHandler _flagHandler;
156  meas::base::SafeCentroidExtractor _centroidExtractor;
157 };
158 
160 public:
162  float radiusForRadius=std::nanf("")) :
163  _center(center),
164  _axes(core),
165  _radiusForRadius(radiusForRadius)
166  {}
167 
168  explicit KronAperture(afw::table::SourceRecord const& source, float radiusForRadius=std::nanf("")) :
169  _center(afw::geom::Point2D(source.getX(), source.getY())),
170  _axes(source.getShape()),
171  _radiusForRadius(radiusForRadius)
172  {}
173 
175  double radius, float radiusForRadius=std::nanf("")) :
176  _center(refToMeas(reference.getCentroid())),
177  _axes(getKronAxes(reference.getShape(), refToMeas.getLinear(), radius)),
178  _radiusForRadius(radiusForRadius)
179  {}
180 
182  double getX() const { return _center.getX(); }
183  double getY() const { return _center.getY(); }
184  float getRadiusForRadius() const { return _radiusForRadius; }
185 
186  afw::geom::Point2D const& getCenter() const { return _center; }
187 
188  afw::geom::ellipses::Axes & getAxes() { return _axes; }
189 
190  afw::geom::ellipses::Axes const& getAxes() const { return _axes; }
191 
192 
197  template<typename ImageT>
198  static PTR(KronAperture) determineRadius(
199  ImageT const& image,
201  afw::geom::Point2D const& center,
202  KronFluxControl const& ctrl
203  );
204 
206  template<typename ImageT>
207  std::pair<double, double> measureFlux(
208  ImageT const& image,
209  double const nRadiusForFlux,
210  double const maxSincRadius
211  ) const;
212 
215  afw::geom::Point2D const center = trans(getCenter());
216  afw::geom::ellipses::Axes const axes(*getAxes().transform(trans.getLinear()).copy());
217  return std::make_shared<KronAperture>(center, axes);
218  }
219 
221  static
222  afw::geom::ellipses::Axes getKronAxes(
223  afw::geom::ellipses::Axes const& shape,
224  afw::geom::LinearTransform const& transformation,
225  double const radius
226  );
227 
228 private:
229  afw::geom::Point2D const _center; // Center of aperture
230  afw::geom::ellipses::Axes _axes; // Ellipse defining aperture shape
231  float _radiusForRadius; // Radius used to estimate the Kron radius
232 };
233 
234 }}}} // namespace lsst::meas::extensions::photometryKron
235 
236 #endif // !LSST_MEAS_EXTENSIONS_PHOTOMETRY_KRON_H
Defines the fields and offsets for a table.
Definition: Schema.h:50
static meas::base::FlagDefinition const SMALL_RADIUS
static meas::base::FlagDefinition const NO_MINIMUM_RADIUS
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:117
#define PTR(...)
Definition: base.h:41
An affine coordinate transformation consisting of a linear transformation and an offset.
double smoothingSigma
"Smooth image with N(0, smoothingSigma^2) Gaussian while estimating R_K" ;
afw::geom::Point2D const & getCenter() const
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
Definition: FlagHandler.h:40
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.
Provides consistent interface for LSST exceptions.
Definition: Exception.h:107
Utility class for measurement algorithms that extracts a position from the Centroid slot and handles ...
bool fixed
"if true, use existing shape and centroid measurements instead of fitting" ;
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition: exceptions.h:48
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
A preprocessor macro used to define fields in C++ "control object" structs.
Definition: config.h:36
Point< double, 2 > Point2D
Definition: Point.h:324
STL class.
static meas::base::FlagDefinition const USED_MINIMUM_RADIUS
Utility class for handling flag fields that indicate the failure modes of an algorithm.
Definition: FlagHandler.h:148
static meas::base::FlagDefinition const USED_PSF_RADIUS
A base class for image defects.
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.
table::Schema schema
Definition: Camera.cc:161
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
std::string refRadiusName
"Name of field specifying reference Kron radius for forced measurement" ;
A FunctorKey for FluxResult.
Definition: FluxUtilities.h:59
KronAperture(afw::table::SourceRecord const &reference, afw::geom::AffineTransform const &refToMeas, double radius, float radiusForRadius=std::nanf(""))
LinearTransform const & getLinear() const noexcept
static meas::base::FlagDefinition const FAILURE
An ellipse core for the semimajor/semiminor axis and position angle parametrization (a...
Definition: Axes.h:47
double maxSincRadius
"Largest aperture for which to use the slow, accurate, sinc aperture code" ;
static meas::base::FlagDefinition const BAD_RADIUS
An abstract base classes for which the same implementation can be used for both SingleFrameAlgorithm ...
Definition: Algorithm.h:170
int nIterForRadius
"Number of times to iterate when setting the Kron radius" ;
A base class for parametrizations of the "core" of an ellipse - the ellipticity and size...
Definition: BaseCore.h:55
Class for storing generic metadata.
Definition: PropertySet.h:68
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(""))
def measure(mi, x, y, size, statistic, stats)
Definition: fringe.py:357
Record class that contains measurements made on a single exposure.
Definition: Source.h:82
table::Key< int > transform
KronAperture(afw::table::SourceRecord const &source, float radiusForRadius=std::nanf(""))
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
vector-type utility class to build a collection of FlagDefinitions
Definition: FlagHandler.h:60
A 2D linear coordinate transformation.
double nRadiusForFlux
"Number of Kron radii for Kron flux" ;
static meas::base::FlagDefinition const BAD_SHAPE