LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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 "lsst/base.h"
37 #include "lsst/pex/config.h"
38 #include "ndarray/eigen.h"
39 #include "lsst/afw/table/Source.h"
45 
46 namespace lsst {
47 namespace ip {
48 namespace diffim {
49 
51 public:
52 
53  explicit DipoleCentroidControl() {}
54 };
55 
57 public:
58 
59  explicit DipoleFluxControl() {}
60 };
61 
66 public:
67  LSST_CONTROL_FIELD(maxPixels, int, "Maximum number of pixels to apply the measurement to");
68  LSST_CONTROL_FIELD(stepSizeCoord, float, "Default initial step size for coordinates in non-linear fitter");
69  LSST_CONTROL_FIELD(stepSizeFlux, float, "Default initial step size for flux in non-linear fitter");
70  LSST_CONTROL_FIELD(errorDef, double, "How many sigma the error bars of the non-linear fitter represent");
71  LSST_CONTROL_FIELD(maxFnCalls, int, "Maximum function calls for non-linear fitter; 0 = unlimited");
73  stepSizeCoord(0.1), stepSizeFlux(1.0), errorDef(1.0), maxFnCalls(100000) {}
74 };
75 
80 public:
81  enum {
86  };
87 
89 
90  DipoleCentroidAlgorithm(Control const & ctrl, std::string const & name,
91  afw::table::Schema & schema, std::string const & doc);
92 
94 
96  ResultKey const & getPositiveKeys() const { return _positiveKeys; }
97  ResultKey const & getNegativeKeys() const { return _negativeKeys; }
98 
99 protected:
101  DipoleCentroidAlgorithm(Control const & ctrl, std::string const & name, afw::table::Schema & schema,
102  std::string const & doc, ResultKey const & positiveKeys, ResultKey const & negativeKeys);
103 
110 };
111 
116 public:
117  enum {
122  };
123 
127 
128  DipoleFluxAlgorithm(Control const & ctrl, std::string const & name, afw::table::Schema & schema,
129  std::string const & doc);
130 
131  // A typedef for the FunctorKey which returns the result of this algorithm
134  ResultKey const & getPositiveKeys() const { return _positiveKeys; }
135  ResultKey const & getNegativeKeys() const { return _negativeKeys; }
136 
137 protected:
138 
140  DipoleFluxAlgorithm(Control const & ctrl, std::string const & name,
141  afw::table::Schema & schema, std::string const & doc,
142  ResultKey const & positiveKeys, ResultKey const & negativeKeys);
143 
148 
151 };
152 
154  Control const & ctrl, std::string const & name, afw::table::Schema & schema, std::string const & doc
155  ) :
156  _ctrl(ctrl),
157  _centroidExtractor(schema, name, true)
158 {
159  static boost::array<meas::base::FlagDefinition,N_FLAGS> const flagDefs = {{
160  {"flag", "general failure flag, set if anything went wrong"},
161  {"pos_flag", "failure flag for positive, set if anything went wrong"},
162  {"neg_flag", "failure flag for negative, set if anything went wrong"}
163  }};
164  _flagHandler = meas::base::FlagHandler::addFields(schema, name, flagDefs.begin(), flagDefs.end());
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  _positiveKeys = ResultKey(schema[name+"_pos"]);
168  _negativeKeys = ResultKey(schema[name+"_neg"]);
169 }
170 
172  Control const & ctrl, std::string const & name, afw::table::Schema & schema, std::string const & doc,
173  ResultKey const & positiveKeys, ResultKey const & negativeKeys
174  ) :
175  _ctrl(ctrl),
176  _centroidExtractor(schema, name, true)
177 {
178  meas::base::CentroidResultKey::addFields(schema, name+"_pos", doc + ": positive lobe", meas::base::SIGMA_ONLY);
179  meas::base::CentroidResultKey::addFields(schema, name+"_neg", doc + ": negative lobe", meas::base::SIGMA_ONLY);
180  static boost::array<meas::base::FlagDefinition,N_FLAGS> const flagDefs = {{
181  {"flag", "general failure flag, set if anything went wrong"},
182  {"pos_flag", "failure flag for positive, set if anything went wrong"},
183  {"neg_flag", "failure flag for negative, set if anything went wrong"}
184  }};
185  _flagHandler = meas::base::FlagHandler::addFields(schema, name, flagDefs.begin(), flagDefs.end());
186  _positiveKeys = ResultKey(schema[name+"_pos"]);
187  _negativeKeys = ResultKey(schema[name+"_neg"]);
188 }
189 
191  Control const & ctrl, std::string const & name, afw::table::Schema & schema,
192  std::string const & doc, ResultKey const & positiveKeys, ResultKey const & negativeKeys
193  ) :
194  _ctrl(ctrl),
195  _centroidExtractor(schema, name, false)
196 {
197  static boost::array<meas::base::FlagDefinition,N_FLAGS> const flagDefs = {{
198  {"flag", "general failure flag, set if anything went wrong"},
199  {"pos_flag", "failure flag for positive, set if anything went wrong"},
200  {"neg_flag", "failure flag for negative, set if anything went wrong"}
201  }};
202  _flagHandler = meas::base::FlagHandler::addFields(schema, name, flagDefs.begin(), flagDefs.end());
203  meas::base::FluxResultKey::addFields(schema, name+"_pos", doc+": positive lobe");
204  meas::base::FluxResultKey::addFields(schema, name+"_neg", doc+": negative lobe");
205  _positiveKeys = ResultKey(positiveKeys);
206  _negativeKeys = ResultKey(negativeKeys);
207 }
208 
210  Control const & ctrl, std::string const & name, afw::table::Schema & schema,
211  std::string const & doc
212  ) :
213  _ctrl(ctrl),
214  _centroidExtractor(schema, name, false)
215 {
216  static boost::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", "dn")),
240  _numNegativeKey(schema.addField<int>(name+"_nneg", "number of negative pixels", "dn"))
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 & getPositiveKeys() const { return _positiveKeys; }
283  ResultKey const & getNegativeKeys() const { return _negativeKeys; }
284 
285  void measure(
286  afw::table::SourceRecord & measRecord,
287  afw::image::Exposure<float> const & exposure
288  ) const;
289 
290  void fail(
291  afw::table::SourceRecord & measRecord,
293  ) const;
294 
295 protected:
297  NaiveDipoleCentroid(Control const & ctrl, std::string const & name, afw::table::Schema & schema,
298  ResultKey const & positiveKeys, ResultKey const & negativeKeys);
299 
300 private:
301 
306 };
307 
308 
309 
310 
315 public:
316 
318 
319  PsfDipoleFlux(PsfDipoleFluxControl const & ctrl, std::string const & name, afw::table::Schema & schema) :
320  DipoleFluxAlgorithm(ctrl, name, schema, "jointly fitted psf flux counts"),
321  _ctrl(ctrl),
322  _chi2dofKey(schema.addField<float>(name+"_chi2dof",
323  "chi2 per degree of freedom of fit")),
324  _flagMaxPixelsKey(schema.addField<afw::table::Flag>(name+"_flags_maxpix",
325  "set if too large a footprint was sent to the algorithm"))
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 
359 };
360 
361 }}}// namespace lsst::ip::diffim
362 
363 #endif // !LSST_IP_DIFFIM_DIPOLEALGORITHMS_H
Defines the fields and offsets for a table.
Definition: Schema.h:46
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
table::Key< std::string > name
Definition: ApCorrMap.cc:71
Eigen matrix objects that present a view into an ndarray::Array.
Intermediate base class for algorithms that compute a centroid.
afw::table::Key< int > _numNegativeKey
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
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)
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)
ResultKey const & getNegativeKeys() const
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
meas::base::SafeCentroidExtractor _centroidExtractor
int maxPixels
&quot;Maximum number of pixels to apply the measurement to&quot; ;
meas::base::CentroidResultKey _posCentroid
ResultKey const & getNegativeKeys() const
def error
Definition: log.py:108
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
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
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
meas::base::SafeCentroidExtractor _centroidExtractor
meas::base::SafeCentroidExtractor _centroidExtractor
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.
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
Return the standard centroid keys registered by this algorithm.
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:81
afw::table::Key< int > _numPositiveKey
PsfDipoleFlux(PsfDipoleFluxControl const &ctrl, std::string const &name, afw::table::Schema &schema)
afw::table::Key< afw::table::Flag > _flagMaxPixelsKey
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinition const *begin, FlagDefinition const *end)
Definition: FlagHandler.cc:28
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const