lsst.meas.base  14.0-23-g2010ef9+4
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"
30 #include "lsst/afw/geom/SkyWcs.h"
31 #include "lsst/afw/image/Calib.h"
40 
41 namespace lsst {
42 namespace meas {
43 namespace base {
44 
45 class SdssShapeResult;
46 
53 public:
54  LSST_CONTROL_FIELD(background, double, "Additional value to add to background");
55  LSST_CONTROL_FIELD(maxIter, int, "Maximum number of iterations");
56  LSST_CONTROL_FIELD(maxShift, double, "Maximum centroid shift, limited to 2-10");
57  LSST_CONTROL_FIELD(tol1, float, "Convergence tolerance for e1,e2");
58  LSST_CONTROL_FIELD(tol2, float, "Convergence tolerance for FWHM");
59  LSST_CONTROL_FIELD(doMeasurePsf, bool, "Whether to also compute the shape of the PSF model");
60 
62  SdssShapeControl() : background(0.0), maxIter(100), maxShift(), tol1(1E-5), tol2(1E-4),
63  doMeasurePsf(true) {}
64 };
65 
73 class SdssShapeResultKey : public afw::table::FunctorKey<SdssShapeResult> {
74 public:
75 
87  static SdssShapeResultKey addFields(
88  afw::table::Schema & schema,
89  std::string const & name,
90  bool doMeasurePsf
91  );
92 
95 
106 
108  virtual SdssShapeResult get(afw::table::BaseRecord const & record) const;
109 
111  virtual void set(afw::table::BaseRecord & record, SdssShapeResult const & value) const;
112 
114  virtual afw::geom::ellipses::Quadrupole getPsfShape(afw::table::BaseRecord const & record) const;
115 
117  virtual void setPsfShape(afw::table::BaseRecord & record,
118  afw::geom::ellipses::Quadrupole const & value) const;
119 
121  bool operator==(SdssShapeResultKey const & other) const;
123  bool operator!=(SdssShapeResultKey const & other) const { return !(*this == other); }
125 
127  bool isValid() const;
128 
129  FlagHandler const & getFlagHandler() const { return _flagHandler; }
130 
131 private:
132  bool _includePsf;
133  ShapeResultKey _shapeResult;
134  CentroidResultKey _centroidResult;
135  FluxResultKey _fluxResult;
136  afw::table::QuadrupoleKey _psfShapeResult;
137  afw::table::Key<ErrElement> _flux_xx_Cov;
138  afw::table::Key<ErrElement> _flux_yy_Cov;
139  afw::table::Key<ErrElement> _flux_xy_Cov;
140  FlagHandler _flagHandler;
141 };
142 
155 public:
156 
157  // Structures and routines to manage flaghandler
158  static FlagDefinitionList const & getFlagDefinitions();
159  static unsigned int const N_FLAGS = 6;
160  static FlagDefinition const FAILURE;
163  static FlagDefinition const SHIFT;
164  static FlagDefinition const MAXITER;
166 
170 
171  // NOTE: In order to accommodate the optional setting of additional fields when running with
172  // doMeasurePsf = true (do set extra fields) or false (do NOT set extra fields), all of
173  // the code in SdssShape assumes that PSF_SHAPE_BAD is the last entry in the enum list.
174  // If new flags are added, be sure to add them above the PSF_SHAPE_BAD entry.
175 
176  SdssShapeAlgorithm(Control const & ctrl, std::string const & name, afw::table::Schema & schema);
177 
188  template <typename ImageT>
189  static Result computeAdaptiveMoments(
190  ImageT const & image,
191  afw::geom::Point2D const & position,
192  bool negative=false,
193  Control const & ctrl=Control()
194  );
195 
205  template <typename ImageT>
206  static FluxResult computeFixedMomentsFlux(
207  ImageT const & image,
208  afw::geom::ellipses::Quadrupole const & shape,
209  afw::geom::Point2D const & position
210  );
211 
212  virtual void measure(
213  afw::table::SourceRecord & measRecord,
214  afw::image::Exposure<float> const & exposure
215  ) const;
216 
217  virtual void fail(
218  afw::table::SourceRecord & measRecord,
219  MeasurementError * error=nullptr
220  ) const;
221 
222 private:
223  Control _ctrl;
224  ResultKey _resultKey;
225  SafeCentroidExtractor _centroidExtractor;
226 };
227 
240 class SdssShapeResult : public ShapeResult, public CentroidResult, public FluxResult {
241 public:
245 
247 
249  // TODO is this workaround still needed?
250  bool getFlag(unsigned int index) const { return flags[index]; }
251 
252  bool getFlag(std::string const & name) const {
254  }
255 
256  SdssShapeResult();
257 
258 };
259 
268 public:
270 
271  SdssShapeTransform(Control const & ctrl, std::string const & name, afw::table::SchemaMapper & mapper);
272 
273  /*
274  * @brief Perform transformation from inputCatalog to outputCatalog.
275  *
276  * @param[in] inputCatalog Source of data to be transformed
277  * @param[in,out] outputCatalog Container for transformed results
278  * @param[in] wcs World coordinate system under which transformation will take place
279  * @param[in] calib Photometric calibration under which transformation will take place
280  * @throws LengthError Catalog sizes do not match
281  */
282  virtual void operator()(afw::table::SourceCatalog const & inputCatalog,
283  afw::table::BaseCatalog & outputCatalog,
284  afw::geom::SkyWcs const & wcs,
285  afw::image::Calib const & calib) const;
286 private:
287  FluxTransform _fluxTransform;
288  CentroidTransform _centroidTransform;
289  ShapeResultKey _outShapeKey;
290  afw::table::QuadrupoleKey _outPsfShapeKey;
291  bool _transformPsf;
292 };
293 
294 }}} // namespace lsst::meas::base
295 
296 #endif // !LSST_MEAS_BASE_SdssShape_h_INCLUDED
Transformation for SdssShape measurements.
Definition: SdssShape.h:267
bool doMeasurePsf
"Whether to also compute the shape of the PSF model" ;
Definition: SdssShape.h:59
float tol2
"Convergence tolerance for FWHM" ;
Definition: SdssShape.h:58
static FlagDefinition const SHIFT
Definition: SdssShape.h:163
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:123
double background
"Additional value to add to background" ;
Definition: SdssShape.h:54
bool operator==(CoordKey const &lhs, CoordKey const &rhs)
int maxIter
"Maximum number of iterations" ;
Definition: SdssShape.h:55
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:162
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
Base for flux measurement transformations.
float tol1
"Convergence tolerance for e1,e2" ;
Definition: SdssShape.h:57
static FlagDefinition const UNWEIGHTED_BAD
Definition: SdssShape.h:161
string name
double maxShift
"Maximum centroid shift, limited to 2-10" ;
Definition: SdssShape.h:56
float ErrElement
Definition: constants.h:53
ErrElement flux_yy_Cov
flux, yy term in the uncertainty covariance matrix
Definition: SdssShape.h:243
A FunctorKey for ShapeResult.
bool getFlag(std::string const &name) const
Definition: SdssShape.h:252
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:240
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:52
A FunctorKey for FluxResult.
Definition: FluxUtilities.h:58
std::bitset< SdssShapeAlgorithm::N_FLAGS > flags
Status flags (see SdssShapeAlgorithm).
Definition: SdssShape.h:246
An abstract base classes for which the same implementation can be used for both SingleFrameAlgorithm ...
Definition: Algorithm.h:185
static FlagDefinition const MAXITER
Definition: SdssShape.h:164
static FlagDefinition const PSF_SHAPE_BAD
Definition: SdssShape.h:165
A FunctorKey that maps SdssShapeResult to afw::table Records.
Definition: SdssShape.h:73
Abstract base class for all C++ measurement transformations.
Definition: Transform.h:83
static FlagDefinition const FAILURE
Definition: SdssShape.h:160
A FunctorKey for CentroidResult.
Measure the image moments of source using adaptive Gaussian weights.
Definition: SdssShape.h:154
SdssShapeResultKey()
Default constructor; instance will not be usuable unless subsequently assigned to.
Definition: SdssShape.h:94
FlagHandler const & getFlagHandler() const
Definition: SdssShape.h:129
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:242
bool getFlag(unsigned int index) const
Flag getter for Swig, which doesn&#39;t understand std::bitset.
Definition: SdssShape.h:250
bool isValid
Base for centroid measurement transformations.
A reusable result struct for flux measurements.
Definition: FluxUtilities.h:39
ErrElement flux_xy_Cov
flux, xy term in the uncertainty covariance matrix
Definition: SdssShape.h:244