lsst.meas.base  14.0-17-g4f4ea82+2
SdssShape.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2016 AURA/LSST.
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 <https://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #ifndef LSST_MEAS_BASE_SdssShape_h_INCLUDED
25 #define LSST_MEAS_BASE_SdssShape_h_INCLUDED
26 
27 #include <bitset>
28 
29 #include "lsst/pex/config.h"
38 
39 namespace lsst {
40 namespace meas {
41 namespace base {
42 
43 class SdssShapeResult;
44 
51 public:
52  LSST_CONTROL_FIELD(background, double, "Additional value to add to background");
53  LSST_CONTROL_FIELD(maxIter, int, "Maximum number of iterations");
54  LSST_CONTROL_FIELD(maxShift, double, "Maximum centroid shift, limited to 2-10");
55  LSST_CONTROL_FIELD(tol1, float, "Convergence tolerance for e1,e2");
56  LSST_CONTROL_FIELD(tol2, float, "Convergence tolerance for FWHM");
57  LSST_CONTROL_FIELD(doMeasurePsf, bool, "Whether to also compute the shape of the PSF model");
58 
60  SdssShapeControl() : background(0.0), maxIter(100), maxShift(), tol1(1E-5), tol2(1E-4),
61  doMeasurePsf(true) {}
62 };
63 
71 class SdssShapeResultKey : public afw::table::FunctorKey<SdssShapeResult> {
72 public:
73 
85  static SdssShapeResultKey addFields(
87  std::string const & name,
88  bool doMeasurePsf
89  );
90 
93 
104 
106  virtual SdssShapeResult get(afw::table::BaseRecord const & record) const;
107 
109  virtual void set(afw::table::BaseRecord & record, SdssShapeResult const & value) const;
110 
112  virtual afw::geom::ellipses::Quadrupole getPsfShape(afw::table::BaseRecord const & record) const;
113 
115  virtual void setPsfShape(afw::table::BaseRecord & record,
116  afw::geom::ellipses::Quadrupole const & value) const;
117 
119  bool operator==(SdssShapeResultKey const & other) const;
121  bool operator!=(SdssShapeResultKey const & other) const { return !(*this == other); }
123 
125  bool isValid() const;
126 
127  FlagHandler const & getFlagHandler() const { return _flagHandler; }
128 
129 private:
130  bool _includePsf;
131  ShapeResultKey _shapeResult;
132  CentroidResultKey _centroidResult;
133  FluxResultKey _fluxResult;
134  afw::table::QuadrupoleKey _psfShapeResult;
135  afw::table::Key<ErrElement> _flux_xx_Cov;
136  afw::table::Key<ErrElement> _flux_yy_Cov;
137  afw::table::Key<ErrElement> _flux_xy_Cov;
138  FlagHandler _flagHandler;
139 };
140 
153 public:
154 
155  // Structures and routines to manage flaghandler
156  static FlagDefinitionList const & getFlagDefinitions();
157  static unsigned int const N_FLAGS = 6;
158  static FlagDefinition const FAILURE;
161  static FlagDefinition const SHIFT;
162  static FlagDefinition const MAXITER;
164 
168 
169  // NOTE: In order to accommodate the optional setting of additional fields when running with
170  // doMeasurePsf = true (do set extra fields) or false (do NOT set extra fields), all of
171  // the code in SdssShape assumes that PSF_SHAPE_BAD is the last entry in the enum list.
172  // If new flags are added, be sure to add them above the PSF_SHAPE_BAD entry.
173 
174  SdssShapeAlgorithm(Control const & ctrl, std::string const & name, afw::table::Schema & schema);
175 
186  template <typename ImageT>
187  static Result computeAdaptiveMoments(
188  ImageT const & image,
189  afw::geom::Point2D const & position,
190  bool negative=false,
191  Control const & ctrl=Control()
192  );
193 
203  template <typename ImageT>
204  static FluxResult computeFixedMomentsFlux(
205  ImageT const & image,
206  afw::geom::ellipses::Quadrupole const & shape,
207  afw::geom::Point2D const & position
208  );
209 
210  virtual void measure(
211  afw::table::SourceRecord & measRecord,
212  afw::image::Exposure<float> const & exposure
213  ) const;
214 
215  virtual void fail(
216  afw::table::SourceRecord & measRecord,
217  MeasurementError * error=nullptr
218  ) const;
219 
220 private:
221  Control _ctrl;
222  ResultKey _resultKey;
223  SafeCentroidExtractor _centroidExtractor;
224 };
225 
238 class SdssShapeResult : public ShapeResult, public CentroidResult, public FluxResult {
239 public:
243 
245 
247  // TODO is this workaround still needed?
248  bool getFlag(unsigned int index) const { return flags[index]; }
249 
250  bool getFlag(std::string const & name) const {
252  }
253 
254  SdssShapeResult();
255 
256 };
257 
266 public:
268 
269  SdssShapeTransform(Control const & ctrl, std::string const & name, afw::table::SchemaMapper & mapper);
270 
271  /*
272  * @brief Perform transformation from inputCatalog to outputCatalog.
273  *
274  * @param[in] inputCatalog Source of data to be transformed
275  * @param[in,out] outputCatalog Container for transformed results
276  * @param[in] wcs World coordinate system under which transformation will take place
277  * @param[in] calib Photometric calibration under which transformation will take place
278  * @throws LengthError Catalog sizes do not match
279  */
280  virtual void operator()(afw::table::SourceCatalog const & inputCatalog,
281  afw::table::BaseCatalog & outputCatalog,
282  afw::image::Wcs const & wcs,
283  afw::image::Calib const & calib) const;
284 private:
285  FluxTransform _fluxTransform;
286  CentroidTransform _centroidTransform;
287  ShapeResultKey _outShapeKey;
288  afw::table::QuadrupoleKey _outPsfShapeKey;
289  bool _transformPsf;
290 };
291 
292 }}} // namespace lsst::meas::base
293 
294 #endif // !LSST_MEAS_BASE_SdssShape_h_INCLUDED
Transformation for SdssShape measurements.
Definition: SdssShape.h:265
bool doMeasurePsf
"Whether to also compute the shape of the PSF model" ;
Definition: SdssShape.h:57
float tol2
"Convergence tolerance for FWHM" ;
Definition: SdssShape.h:56
static FlagDefinition const SHIFT
Definition: SdssShape.h:161
afw::table::Schema schema
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
Definition: FlagHandler.h:38
A reusable struct for centroid measurements.
bool operator!=(SdssShapeResultKey const &other) const
Compare the FunctorKey for equality with another, using the underlying Keys.
Definition: SdssShape.h:121
double background
"Additional value to add to background" ;
Definition: SdssShape.h:52
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
int maxIter
"Maximum number of iterations" ;
Definition: SdssShape.h:53
Utility class for measurement algorithms that extracts a position from the Centroid slot and handles ...
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition: exceptions.h:48
static FlagDefinition const UNWEIGHTED
Definition: SdssShape.h:160
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
Base for flux measurement transformations.
float tol1
"Convergence tolerance for e1,e2" ;
Definition: SdssShape.h:55
static FlagDefinition const UNWEIGHTED_BAD
Definition: SdssShape.h:159
string name
double maxShift
"Maximum centroid shift, limited to 2-10" ;
Definition: SdssShape.h:54
float ErrElement
Definition: constants.h:53
ErrElement flux_yy_Cov
flux, yy term in the uncertainty covariance matrix
Definition: SdssShape.h:241
A FunctorKey for ShapeResult.
bool getFlag(std::string const &name) const
Definition: SdssShape.h:250
STL class.
Utility class for handling flag fields that indicate the failure modes of an algorithm.
Definition: FlagHandler.h:156
A reusable struct for moments-based shape measurements.
Result object SdssShapeAlgorithm.
Definition: SdssShape.h:238
static FlagDefinitionList const & getFlagDefinitions()
Definition: SdssShape.cc:57
FlagDefinition getDefinition(std::size_t index) const
get a reference to the FlagDefinition with specified index.
Definition: FlagHandler.h:87
A C++ control class to handle SdssShapeAlgorithm&#39;s configuration.
Definition: SdssShape.h:50
A FunctorKey for FluxResult.
Definition: FluxUtilities.h:56
std::bitset< SdssShapeAlgorithm::N_FLAGS > flags
Status flags (see SdssShapeAlgorithm).
Definition: SdssShape.h:244
An abstract base classes for which the same implementation can be used for both SingleFrameAlgorithm ...
Definition: Algorithm.h:184
static FlagDefinition const MAXITER
Definition: SdssShape.h:162
static FlagDefinition const PSF_SHAPE_BAD
Definition: SdssShape.h:163
A FunctorKey that maps SdssShapeResult to afw::table Records.
Definition: SdssShape.h:71
Abstract base class for all C++ measurement transformations.
Definition: Transform.h:82
static FlagDefinition const FAILURE
Definition: SdssShape.h:158
A FunctorKey for CentroidResult.
Measure the image moments of source using adaptive Gaussian weights.
Definition: SdssShape.h:152
SdssShapeResultKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
Definition: SdssShape.h:92
FlagHandler const & getFlagHandler() const
Definition: SdssShape.h:127
vector-type utility class to build a collection of FlagDefinitions
Definition: FlagHandler.h:63
ErrElement flux_xx_Cov
flux, xx term in the uncertainty covariance matrix
Definition: SdssShape.h:240
bool getFlag(unsigned int index) const
Flag getter for Swig, which doesn&#39;t understand std::bitset.
Definition: SdssShape.h:248
Base for centroid measurement transformations.
A reusable result struct for flux measurements.
Definition: FluxUtilities.h:37
ErrElement flux_xy_Cov
flux, xy term in the uncertainty covariance matrix
Definition: SdssShape.h:242