LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
DipoleAlgorithms.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008-2015 AURA/LSST
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_IP_DIFFIM_DIPOLEALGORITHMS_H
26 #define LSST_IP_DIFFIM_DIPOLEALGORITHMS_H
27 // Control/algorithm hierarchy for dipole measurement.
29 //
30 
31 #include <stdio.h>
32 #include <execinfo.h>
33 #include <signal.h>
34 #include <stdlib.h>
35 #include <unistd.h>
36 #include <array>
37 
38 #include "lsst/base.h"
39 #include "lsst/pex/config.h"
40 #include "ndarray/eigen.h"
41 #include "lsst/afw/table/Source.h"
47 
48 namespace lsst {
49 namespace ip {
50 namespace diffim {
51 
53 public:
54 
55  explicit DipoleCentroidControl() {}
56 };
57 
59 public:
60 
61  explicit DipoleFluxControl() {}
62 };
63 
68 public:
69  LSST_CONTROL_FIELD(stepSizeCoord, float, "Default initial step size for coordinates in non-linear fitter");
70  LSST_CONTROL_FIELD(stepSizeFlux, float, "Default initial step size for flux in non-linear fitter");
71  LSST_CONTROL_FIELD(errorDef, double, "How many sigma the error bars of the non-linear fitter represent");
72  LSST_CONTROL_FIELD(maxFnCalls, int, "Maximum function calls for non-linear fitter; 0 = unlimited");
74  stepSizeCoord(0.1), stepSizeFlux(1.0), errorDef(1.0), maxFnCalls(100000) {}
75 };
76 
81 public:
82  enum {
87  };
88 
90 
91  DipoleCentroidAlgorithm(Control const & ctrl, std::string const & name,
92  afw::table::Schema & schema, std::string const & doc);
93 
95 
97  ResultKey const & getPositiveKeys() const { return _positiveKeys; }
98  ResultKey const & getNegativeKeys() const { return _negativeKeys; }
99 
100 protected:
102  DipoleCentroidAlgorithm(Control const & ctrl, std::string const & name, afw::table::Schema & schema,
103  std::string const & doc, ResultKey const & positiveKeys, ResultKey const & negativeKeys);
104 
111 };
112 
117 public:
118  enum {
123  };
124 
128 
129  DipoleFluxAlgorithm(Control const & ctrl, std::string const & name, afw::table::Schema & schema,
130  std::string const & doc);
131 
132  // A typedef for the FunctorKey which returns the result of this algorithm
135  ResultKey const & getPositiveKeys() const { return _positiveKeys; }
136  ResultKey const & getNegativeKeys() const { return _negativeKeys; }
137 
138 protected:
139 
141  DipoleFluxAlgorithm(Control const & ctrl, std::string const & name,
142  afw::table::Schema & schema, std::string const & doc,
143  ResultKey const & positiveKeys, ResultKey const & negativeKeys);
144 
148 
151 };
152 
154  Control const & ctrl, std::string const & name, afw::table::Schema & schema, std::string const & doc
155  ) :
156  _ctrl(ctrl)
157 {
158  static std::array<meas::base::FlagDefinition,N_FLAGS> const flagDefs = {{
159  {"flag", "general failure flag, set if anything went wrong"},
160  {"pos_flag", "failure flag for positive, set if anything went wrong"},
161  {"neg_flag", "failure flag for negative, set if anything went wrong"}
162  }};
163  _flagHandler = meas::base::FlagHandler::addFields(schema, name, flagDefs.begin(), flagDefs.end());
164  meas::base::CentroidResultKey::addFields(schema, name, doc+": overall centroid", meas::base::SIGMA_ONLY);
165  meas::base::CentroidResultKey::addFields(schema, name+"_pos", doc+": positive lobe", meas::base::SIGMA_ONLY);
166  meas::base::CentroidResultKey::addFields(schema, name+"_neg", doc+": negative lobe", meas::base::SIGMA_ONLY);
167  _centerKeys = ResultKey(schema[name]);
168  _positiveKeys = ResultKey(schema[name+"_pos"]);
169  _negativeKeys = ResultKey(schema[name+"_neg"]);
170 }
171 
173  Control const & ctrl, std::string const & name, afw::table::Schema & schema, std::string const & doc,
174  ResultKey const & positiveKeys, ResultKey const & negativeKeys
175  ) :
176  _ctrl(ctrl)
177 {
178  meas::base::CentroidResultKey::addFields(schema, name, doc+": overall centroid", meas::base::SIGMA_ONLY);
179  meas::base::CentroidResultKey::addFields(schema, name+"_pos", doc + ": positive lobe", meas::base::SIGMA_ONLY);
180  meas::base::CentroidResultKey::addFields(schema, name+"_neg", doc + ": negative lobe", meas::base::SIGMA_ONLY);
181  static std::array<meas::base::FlagDefinition,N_FLAGS> const flagDefs = {{
182  {"flag", "general failure flag, set if anything went wrong"},
183  {"pos_flag", "failure flag for positive, set if anything went wrong"},
184  {"neg_flag", "failure flag for negative, set if anything went wrong"}
185  }};
186  _flagHandler = meas::base::FlagHandler::addFields(schema, name, flagDefs.begin(), flagDefs.end());
187  _centerKeys = ResultKey(schema[name]);
188  _positiveKeys = ResultKey(schema[name+"_pos"]);
189  _negativeKeys = ResultKey(schema[name+"_neg"]);
190 }
191 
193  Control const & ctrl, std::string const & name, afw::table::Schema & schema,
194  std::string const & doc, ResultKey const & positiveKeys, ResultKey const & negativeKeys
195  ) :
196  _ctrl(ctrl)
197 {
198  static std::array<meas::base::FlagDefinition,N_FLAGS> const flagDefs = {{
199  {"flag", "general failure flag, set if anything went wrong"},
200  {"pos_flag", "failure flag for positive, set if anything went wrong"},
201  {"neg_flag", "failure flag for negative, set if anything went wrong"}
202  }};
203  _flagHandler = meas::base::FlagHandler::addFields(schema, name, flagDefs.begin(), flagDefs.end());
204  meas::base::FluxResultKey::addFields(schema, name+"_pos", doc+": positive lobe");
205  meas::base::FluxResultKey::addFields(schema, name+"_neg", doc+": negative lobe");
206  _positiveKeys = ResultKey(positiveKeys);
207  _negativeKeys = ResultKey(negativeKeys);
208 }
209 
211  Control const & ctrl, std::string const & name, afw::table::Schema & schema,
212  std::string const & doc
213  ) :
214  _ctrl(ctrl)
215 {
216  static std::array<meas::base::FlagDefinition,N_FLAGS> const flagDefs = {{
217  {"flag", "general failure flag, set if anything went wrong"},
218  {"pos_flag", "failure flag for positive, set if anything went wrong"},
219  {"neg_flag", "failure flag for negative, set if anything went wrong"}
220  }};
221  _flagHandler = meas::base::FlagHandler::addFields(schema, name, flagDefs.begin(), flagDefs.end());
222  meas::base::FluxResultKey::addFields(schema, name+"_pos", doc+": positive lobe");
223  meas::base::FluxResultKey::addFields(schema, name+"_neg", doc+": negative lobe");
224  _positiveKeys = ResultKey(schema[name+"_pos"]);
225  _negativeKeys = ResultKey(schema[name+"_neg"]);
226 }
227 
228 /*
229 class that knows how to calculate centroids as a simple unweighted first
230  * moment of the 3x3 region around the peaks
231  */
233 public:
234 
236 
237  NaiveDipoleFlux(Control const & ctrl, std::string const & name, afw::table::Schema & schema) :
238  DipoleFluxAlgorithm(ctrl, name, schema, "raw flux counts"),
239  _numPositiveKey(schema.addField<int>(name+"_npos", "number of positive pixels", "count")),
240  _numNegativeKey(schema.addField<int>(name+"_nneg", "number of negative pixels", "count"))
241  {
242  }
243 
244  void measure(
245  afw::table::SourceRecord & measRecord,
246  afw::image::Exposure<float> const & exposure
247  ) const;
248 
249  void fail(
250  afw::table::SourceRecord & measRecord,
252  ) const;
253 
254 private:
255 
259 };
260 
265 public:
266  enum {
271  };
272 
273  NaiveDipoleCentroid(Control const & ctrl, std::string const & name, afw::table::Schema & schema);
280 
282  ResultKey const & getCenterKeys() const { return _centerKeys; }
283  ResultKey const & getPositiveKeys() const { return _positiveKeys; }
284  ResultKey const & getNegativeKeys() const { return _negativeKeys; }
285 
286  void measure(
287  afw::table::SourceRecord & measRecord,
288  afw::image::Exposure<float> const & exposure
289  ) const;
290 
291  void mergeCentroids(afw::table::SourceRecord & source, double posValue, double negValue) const;
292 
293  void fail(
294  afw::table::SourceRecord & measRecord,
296  ) const;
297 
298 protected:
300  NaiveDipoleCentroid(Control const & ctrl, std::string const & name, afw::table::Schema & schema,
301  ResultKey const & positiveKeys, ResultKey const & negativeKeys);
302 
303 private:
304 
308 };
309 
310 
311 
312 
317 public:
318 
320 
321  PsfDipoleFlux(PsfDipoleFluxControl const & ctrl, std::string const & name, afw::table::Schema & schema) :
322  DipoleFluxAlgorithm(ctrl, name, schema, "jointly fitted psf flux counts"),
323  _ctrl(ctrl),
324  _chi2dofKey(schema.addField<float>(name+"_chi2dof",
325  "chi2 per degree of freedom of fit"))
326  {
327  meas::base::CentroidResultKey::addFields(schema, name+"_pos_centroid", "psf fitted center of positive lobe", meas::base::SIGMA_ONLY);
328  meas::base::CentroidResultKey::addFields(schema, name+"_neg_centroid", "psf fitted center of negative lobe", meas::base::SIGMA_ONLY);
329  meas::base::CentroidResultKey::addFields(schema, name+"_centroid", "average of negative and positive lobe positions", meas::base::SIGMA_ONLY);
330  _posCentroid = meas::base::CentroidResultKey(schema[name+"_pos_centroid"]);
331  _negCentroid = meas::base::CentroidResultKey(schema[name+"_neg_centroid"]);
332  _avgCentroid = meas::base::CentroidResultKey(schema[name+"_centroid"]);
333  }
334  std::pair<double,int> chi2(afw::table::SourceRecord & source,
335  afw::image::Exposure<float> const & exposure,
336  double negCenterX, double negCenterY, double negFlux,
337  double posCenterX, double poCenterY, double posFlux
338  ) const;
339 
340  void measure(
341  afw::table::SourceRecord & measRecord,
342  afw::image::Exposure<float> const & exposure
343  ) const;
344 
345  void fail(
346  afw::table::SourceRecord & measRecord,
348  ) const;
349 
350 private:
351 
357 
358 };
359 
360 }}}// namespace lsst::ip::diffim
361 
362 #endif // !LSST_IP_DIFFIM_DIPOLEALGORITHMS_H
Defines the fields and offsets for a table.
Definition: Schema.h:44
afw::table::Key< float > _chi2dofKey
meas::base::FluxResultKey _fluxResultKey
float stepSizeFlux
&quot;Default initial step size for flux in non-linear fitter&quot; ;
meas::base::CentroidResultKey _avgCentroid
meas::base::CentroidResultKey ResultKey
DipoleFluxControl Control
A typedef to the Control object for this algorithm, defined above.
Implementation of Psf dipole flux.
table::Key< std::string > name
Definition: ApCorrMap.cc:71
void mergeCentroids(afw::table::SourceRecord &source, double posValue, double negValue) const
Intermediate base class for algorithms that compute a centroid.
afw::table::Key< int > _numNegativeKey
ResultKey const & getCenterKeys() const
Return the standard centroid keys registered by this algorithm.
afw::table::Schema schema
Definition: GaussianPsf.cc:41
meas::base::FluxResultKey ResultKey
NaiveDipoleFlux(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
Only the diagonal elements of the covariance matrix are provided.
Definition: constants.h:43
meas::base::FluxResultKey _fluxResultKey
void fail(afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
Handle an exception thrown by the current algorithm by setting flags in the given record...
meas::base::CentroidResultKey _negCentroid
C++ control object for PSF dipole fluxes.
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++ &quot;control object&quot; structs.
Definition: config.h:36
ResultKey const & getPositiveKeys() const
Return the standard flux keys registered by this algorithm.
static FluxResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
Add a pair of _flux, _fluxSigma fields to a Schema, and return a FluxResultKey that points to them...
ResultKey const & getNegativeKeys() const
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Given an image and a pixel position, return a Centroid using a naive 3x3 weighted moment...
meas::base::CentroidResultKey _posCentroid
ResultKey const & getNegativeKeys() const
def error
Definition: log.py:103
Utility class for handling flag fields that indicate the failure modes of an algorithm.
Definition: FlagHandler.h:73
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
DipoleCentroidAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema, std::string const &doc)
ResultKey const & getNegativeKeys() const
static CentroidResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc, UncertaintyEnum uncertainty)
Add the appropriate fields to a Schema, and return a CentroidResultKey that manages them...
NaiveDipoleCentroid(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
double errorDef
&quot;How many sigma the error bars of the non-linear fitter represent&quot; ;
Intermediate base class for algorithms that compute a flux.
void fail(afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
Handle an exception thrown by the current algorithm by setting flags in the given record...
A FunctorKey for FluxResult.
Definition: FluxUtilities.h:56
Intermediate base class for algorithms that compute a centroid.
int maxFnCalls
&quot;Maximum function calls for non-linear fitter; 0 = unlimited&quot; ;
void fail(afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
Handle an exception thrown by the current algorithm by setting flags in the given record...
DipoleFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema, std::string const &doc)
meas::base::CentroidResultKey ResultKey
Tuple type that holds the keys that define a standard centroid algorithm.
An abstract base classes for which the same implementation can be used for both SingleFrameAlgorithm ...
Definition: Algorithm.h:177
float stepSizeCoord
&quot;Default initial step size for coordinates in non-linear fitter&quot; ;
std::pair< double, int > chi2(afw::table::SourceRecord &source, afw::image::Exposure< float > const &exposure, double negCenterX, double negCenterY, double negFlux, double posCenterX, double poCenterY, double posFlux) const
ResultKey const & getPositiveKeys() const
A FunctorKey for CentroidResult.
ResultKey const & getPositiveKeys() const
Return the standard centroid keys registered by this algorithm.
Record class that contains measurements made on a single exposure.
Definition: Source.h:80
afw::table::Key< int > _numPositiveKey
PsfDipoleFlux(PsfDipoleFluxControl const &ctrl, std::string const &name, afw::table::Schema &schema)
Basic LSST definitions.
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinition const *begin, FlagDefinition const *end)
Add Flag fields to a schema, creating a FlagHandler object to manage them.
Definition: FlagHandler.cc:28
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Given an image and a pixel position, return a Centroid using a naive 3x3 weighted moment...