LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
DipoleAlgorithms.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2015 AURA/LSST
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
26 #include <iostream> // std::cout
27 #include <algorithm> // std::sort
28 #include <functional> // std::binary_function
29 #include <limits> // std::numeric_limits
30 #include <cmath> // std::sqrt
31 
32 #if !defined(DOXYGEN)
33 # include "Minuit2/FCNBase.h"
34 # include "Minuit2/FunctionMinimum.h"
35 # include "Minuit2/MnMigrad.h"
36 # include "Minuit2/MnMinos.h"
37 # include "Minuit2/MnPrint.h"
38 #endif
39 
40 #include <memory>
41 #include "lsst/pex/exceptions.h"
42 #include "lsst/afw/image.h"
43 #include "lsst/afw/detection.h"
44 #include "lsst/afw/table.h"
45 #include "lsst/afw/math.h"
46 #include "lsst/geom.h"
48 #include "ndarray/eigen.h"
49 
51 namespace afwDet = lsst::afw::detection;
52 namespace afwImage = lsst::afw::image;
53 namespace afwMath = lsst::afw::math;
54 namespace geom = lsst::geom;
55 
56 namespace lsst { namespace ip { namespace diffim {
57 
58 namespace {
59 meas::base::FlagDefinitionList dipoleFluxFlagDefinitions;
60 }
61 
62 meas::base::FlagDefinition const DipoleFluxAlgorithm::FAILURE = dipoleFluxFlagDefinitions.addFailureFlag("general failure flag, set if anything went wrong");
63 meas::base::FlagDefinition const DipoleFluxAlgorithm::POS_FLAG = dipoleFluxFlagDefinitions.add("pos_flag", "failure flag for positive, set if anything went wrong");
64 meas::base::FlagDefinition const DipoleFluxAlgorithm::NEG_FLAG = dipoleFluxFlagDefinitions.add("neg_flag", "failure flag for negative, set if anything went wrong");
65 
67  return dipoleFluxFlagDefinitions;
68 }
69 
70 namespace {
71 meas::base::FlagDefinitionList dipoleCentroidFlagDefinitions;
72 }
73 
74 meas::base::FlagDefinition const DipoleCentroidAlgorithm::FAILURE = dipoleCentroidFlagDefinitions.addFailureFlag("general failure flag, set if anything went wrong");
75 meas::base::FlagDefinition const DipoleCentroidAlgorithm::POS_FLAG = dipoleCentroidFlagDefinitions.add("pos_flag", "failure flag for positive, set if anything went wrong");
76 meas::base::FlagDefinition const DipoleCentroidAlgorithm::NEG_FLAG = dipoleCentroidFlagDefinitions.add("neg_flag", "failure flag for negative, set if anything went wrong");
77 
79  return dipoleCentroidFlagDefinitions;
80 }
81 
82  int const NEGCENTXPAR(0); // Parameter for the x-component of the negative lobe centroid
83  int const NEGCENTYPAR(1); // Parameter for the y-component of the negative lobe centroid
84  int const NEGFLUXPAR(2); // Parameter for the flux of the negative lobe
85  int const POSCENTXPAR(3); // Parameter for the x-component of the positive lobe centroid
86  int const POSCENTYPAR(4); // Parameter for the y-component of the positive lobe centroid
87  int const POSFLUXPAR(5); // Parameter for the flux of the positive lobe
88 
89 
90 namespace {
91 
92 void naiveCentroid(
94  afw::image::Exposure<float> const& exposure,
95  geom::Point2I const & center,
97  )
98 {
99  typedef afw::image::Image<float> ImageT;
100  ImageT const& image = *exposure.getMaskedImage().getImage();
101  // set to the input centroid, just in case all else fails
102  source.set(keys.getX(), center.getX());
103  source.set(keys.getY(), center.getY());
104 
105  int x = center.getX() - image.getX0();
106  int y = center.getY() - image.getY0();
107 
108  if (x < 1 || x >= image.getWidth() - 1 || y < 1 || y >= image.getHeight() - 1) {
110  (boost::format("Object at (%d, %d) is too close to the edge")
111  % x % y).str());
112  }
113 
114  ImageT::xy_locator im = image.xy_at(x, y);
115 
116  double const sum =
117  (im(-1, 1) + im( 0, 1) + im( 1, 1) +
118  im(-1, 0) + im( 0, 0) + im( 1, 0) +
119  im(-1, -1) + im( 0, -1) + im( 1, -1));
120 
121 
122  if (sum == 0.0) {
124  (boost::format("Object at (%d, %d) has no counts") %
125  x % y).str());
126  }
127 
128  double const sum_x =
129  -im(-1, 1) + im( 1, 1) +
130  -im(-1, 0) + im( 1, 0) +
131  -im(-1, -1) + im( 1, -1);
132  double const sum_y =
133  (im(-1, 1) + im( 0, 1) + im( 1, 1)) -
134  (im(-1, -1) + im( 0, -1) + im( 1, -1));
135 
136  float xx = afw::image::indexToPosition(x + image.getX0()) + sum_x / sum;
137  float yy = afw::image::indexToPosition(y + image.getY0()) + sum_y / sum;
138  source.set(keys.getX(), xx);
139  source.set(keys.getY(), yy);
140 }
141 
142 } // anonymous namespace
143 
144 
146  Control const & ctrl,
147  std::string const & name,
149 ) : DipoleCentroidAlgorithm(ctrl, name, schema, "unweighted first moment centroid"),
150  _ctrl(ctrl)
151 { }
152 
158  afw::image::Exposure<float> const & exposure
159 ) const {
160  afw::detection::PeakCatalog const& peaks = source.getFootprint()->getPeaks();
161 
162  int posInd = 0;
163  double posValue = peaks[posInd].getPeakValue(), negValue = 0;
164  if (posValue < 0.) { /* All peaks are negative so use the *most* negative value */
165  posInd = peaks.size() - 1;
166  posValue = peaks[posInd].getPeakValue();
167  }
168  naiveCentroid(source, exposure, peaks[posInd].getI(),
169  (posValue >= 0 ? getPositiveKeys() : getNegativeKeys()));
170 
171  if (posValue > 0. && posInd == 0 && peaks.size() > 1) { /* See if there's also a negative peak */
172  int negInd = peaks.size() - 1;
173  negValue = peaks[negInd].getPeakValue();
174  if (posValue > 0. && negValue < 0.) {
175  naiveCentroid(source, exposure, peaks[negInd].getI(),
176  (negValue >= 0 ? getPositiveKeys() : getNegativeKeys()));
177  }
178  }
179 
180  mergeCentroids(source, posValue, negValue);
181 
182 }
183 
185  double posValue, double negValue) const {
186 
187  double pos_x, pos_y, pos_f;
188  double neg_x, neg_y, neg_f;
189 
190  pos_x = source.get(getPositiveKeys().getX());
191  pos_y = source.get(getPositiveKeys().getY());
192  pos_f = posValue;
193 
194  neg_x = source.get(getNegativeKeys().getX());
195  neg_y = source.get(getNegativeKeys().getY());
196  neg_f = -negValue;
197 
198  if(std::isfinite(pos_x) && std::isfinite(pos_y) &&
199  std::isfinite(neg_x) && std::isfinite(neg_y)) {
200  source.set(getCenterKeys().getX(), (pos_x * pos_f + neg_x * neg_f) / (pos_f + neg_f));
201  source.set(getCenterKeys().getY(), (pos_y * pos_f + neg_y * neg_f) / (pos_f + neg_f));
202  } else if (std::isfinite(pos_x) && std::isfinite(pos_y)) {
203  source.set(getCenterKeys().getX(), pos_x);
204  source.set(getCenterKeys().getY(), pos_y);
205  } else {
206  source.set(getCenterKeys().getX(), neg_x);
207  source.set(getCenterKeys().getY(), neg_y);
208  }
209 }
210 
213  _flagHandler.handleFailure(measRecord, error);
214 }
215 
216 
217 namespace {
218 
219 class NaiveDipoleFootprinter {
220 public:
221  explicit NaiveDipoleFootprinter() : _sumPositive(0.0), _sumNegative(0.0), _numPositive(0),
222  _numNegative(0) {}
223 
225  void reset() {
226  _sumPositive = _sumNegative = 0.0;
227  _numPositive = _numNegative = 0;
228  }
229  void reset(afwDet::Footprint const&) {}
230 
232  void operator() (geom::Point2I const & pos,
235  if (ival >= 0.0) {
236  _sumPositive += ival;
237  _varPositive += vval;
238  ++_numPositive;
239  } else {
240  _sumNegative += ival;
241  _varPositive += vval;
242  ++_numNegative;
243  }
244  }
245 
246  double getSumPositive() const { return _sumPositive; }
247  double getSumNegative() const { return _sumNegative; }
248  double getVarPositive() const { return _sumPositive; }
249  double getVarNegative() const { return _sumNegative; }
250  int getNumPositive() const { return _numPositive; }
251  int getNumNegative() const { return _numNegative; }
252 
253 private:
254  double _sumPositive;
255  double _sumNegative;
256  double _varPositive;
257  double _varNegative;
258  int _numPositive;
259  int _numNegative;
260 };
261 
262 } // anonymous namespace
263 
264 
270  afw::image::Exposure<float> const & exposure
271 ) const {
272  typedef afw::image::Exposure<float>::MaskedImageT MaskedImageT;
273 
274  NaiveDipoleFootprinter functor;
275  source.getFootprint()->getSpans()->applyFunctor(functor, *(exposure.getMaskedImage().getImage()),
276  *(exposure.getMaskedImage().getVariance()));
277 
278  source.set(getPositiveKeys().getInstFlux(), functor.getSumPositive());
279  source.set(getPositiveKeys().getInstFluxErr(), ::sqrt(functor.getVarPositive()));
280  source.set(_numPositiveKey, functor.getNumPositive());
281 
282  source.set(getNegativeKeys().getInstFlux(), functor.getSumNegative());
283  source.set(getNegativeKeys().getInstFluxErr(), ::sqrt(functor.getVarNegative()));
284  source.set(_numNegativeKey, functor.getNumNegative());
285  functor.reset();
286 }
287 
289  _flagHandler.handleFailure(measRecord, error);
290 }
291 
292 
296 class MinimizeDipoleChi2 : public ROOT::Minuit2::FCNBase {
297 public:
298  explicit MinimizeDipoleChi2(PsfDipoleFlux const& psfDipoleFlux,
300  afw::image::Exposure<float> const& exposure
301  ) : _errorDef(1.0),
302  _nPar(6),
303  _maxPix(1e4),
304  _bigChi2(1e10),
305  _psfDipoleFlux(psfDipoleFlux),
306  _source(source),
307  _exposure(exposure)
308  {}
309  double Up() const { return _errorDef; }
310  void setErrorDef(double def) { _errorDef = def; }
311  int getNpar() const { return _nPar; }
312  int getMaxPix() const { return _maxPix; }
313  void setMaxPix(int maxPix) { _maxPix = maxPix; }
314 
315  // Evaluate our cost function (in this case chi^2)
316  virtual double operator()(std::vector<double> const & params) const {
317  double negCenterX = params[NEGCENTXPAR];
318  double negCenterY = params[NEGCENTYPAR];
319  double negFlux = params[NEGFLUXPAR];
320  double posCenterX = params[POSCENTXPAR];
321  double posCenterY = params[POSCENTYPAR];
322  double posFlux = params[POSFLUXPAR];
323 
324  /* Restrict negative dipole to be negative; positive to be positive */
325  if ((negFlux > 0.0) || (posFlux < 0.0)) {
326  return _bigChi2;
327  }
328 
329  std::pair<double,int> fit = _psfDipoleFlux.chi2(_source, _exposure, negCenterX, negCenterY, negFlux,
330  posCenterX, posCenterY, posFlux);
331  double chi2 = fit.first;
332  int nPix = fit.second;
333  if (nPix > _maxPix) {
334  return _bigChi2;
335  }
336 
337  return chi2;
338  }
339 
340 private:
341  double _errorDef; // how much cost function has changed at the +- 1 error points
342  int _nPar; // number of parameters in the fit; hard coded for MinimizeDipoleChi2
343  int _maxPix; // maximum number of pixels that shoud be in the footprint;
344  // prevents too much centroid wander
345  double _bigChi2; // large value to tell fitter when it has gone into bad region of parameter space
346 
347  PsfDipoleFlux const& _psfDipoleFlux;
348  afw::table::SourceRecord & _source;
349  afw::image::Exposure<float> const& _exposure;
350 };
351 
354  afw::image::Exposure<float> const& exposure,
355  double negCenterX, double negCenterY, double negFlux,
356  double posCenterX, double posCenterY, double posFlux
357 ) const {
358 
359  geom::Point2D negCenter(negCenterX, negCenterY);
360  geom::Point2D posCenter(posCenterX, posCenterY);
361 
362  CONST_PTR(afw::detection::Footprint) footprint = source.getFootprint();
363 
364  /*
365  * Fit for the superposition of Psfs at the two centroids.
366  */
367  CONST_PTR(afwDet::Psf) psf = exposure.getPsf();
368  PTR(afwImage::Image<afwMath::Kernel::Pixel>) negPsf = psf->computeImage(negCenter);
369  PTR(afwImage::Image<afwMath::Kernel::Pixel>) posPsf = psf->computeImage(posCenter);
370 
371  afwImage::Image<double> negModel(footprint->getBBox());
372  afwImage::Image<double> posModel(footprint->getBBox());
373  afwImage::Image<float> data(*(exposure.getMaskedImage().getImage()),footprint->getBBox());
375  footprint->getBBox());
376 
377  geom::Box2I negPsfBBox = negPsf->getBBox();
378  geom::Box2I posPsfBBox = posPsf->getBBox();
379  geom::Box2I negModelBBox = negModel.getBBox();
380  geom::Box2I posModelBBox = posModel.getBBox();
381 
382  // Portion of the negative Psf that overlaps the model
383  int negXmin = std::max(negPsfBBox.getMinX(), negModelBBox.getMinX());
384  int negYmin = std::max(negPsfBBox.getMinY(), negModelBBox.getMinY());
385  int negXmax = std::min(negPsfBBox.getMaxX(), negModelBBox.getMaxX());
386  int negYmax = std::min(negPsfBBox.getMaxY(), negModelBBox.getMaxY());
387  geom::Box2I negBBox = geom::Box2I(geom::Point2I(negXmin, negYmin),
388  geom::Point2I(negXmax, negYmax));
389  afwImage::Image<afwMath::Kernel::Pixel> negSubim(*negPsf, negBBox);
390  afwImage::Image<double> negModelSubim(negModel, negBBox);
391  negModelSubim += negSubim;
392 
393  // Portion of the positive Psf that overlaps the model
394  int posXmin = std::max(posPsfBBox.getMinX(), posModelBBox.getMinX());
395  int posYmin = std::max(posPsfBBox.getMinY(), posModelBBox.getMinY());
396  int posXmax = std::min(posPsfBBox.getMaxX(), posModelBBox.getMaxX());
397  int posYmax = std::min(posPsfBBox.getMaxY(), posModelBBox.getMaxY());
398  geom::Box2I posBBox = geom::Box2I(geom::Point2I(posXmin, posYmin),
399  geom::Point2I(posXmax, posYmax));
400  afwImage::Image<afwMath::Kernel::Pixel> posSubim(*posPsf, posBBox);
401  afwImage::Image<double> posModelSubim(posModel, posBBox);
402  posModelSubim += posSubim;
403 
404  negModel *= negFlux; // scale negative model to image
405  posModel *= posFlux; // scale positive model to image
406  afwImage::Image<double> residuals(negModel, true); // full model contains negative lobe...
407  residuals += posModel; // plus positive lobe...
408  residuals -= data; // minus the data...
409  residuals *= residuals; // squared...
410  residuals /= var; // divided by the variance : [(model-data)/sigma]**2
412  double chi2 = stats.getValue(afwMath::SUM);
413  int nPix = stats.getValue(afwMath::NPOINT);
414  return std::pair<double,int>(chi2, nPix);
415 }
416 
419  afw::image::Exposure<float> const & exposure
420 ) const {
421 
422  typedef afw::image::Exposure<float>::MaskedImageT MaskedImageT;
423 
424  CONST_PTR(afw::detection::Footprint) footprint = source.getFootprint();
425  if (!footprint) {
427  (boost::format("No footprint for source %d") % source.getId()).str());
428  }
429 
430  afw::detection::PeakCatalog peakCatalog = afw::detection::PeakCatalog(footprint->getPeaks());
431 
432  if (peakCatalog.size() == 0) {
434  (boost::format("No peak for source %d") % source.getId()).str());
435  }
436  else if (peakCatalog.size() == 1) {
437  // No deblending to do
438  return;
439  }
440 
441  // For N>=2, just measure the brightest-positive and brightest-negative
442  // peaks. peakCatalog is automatically ordered by peak flux, with the most
443  // positive one (brightest) being first
444  afw::detection::PeakRecord const& positivePeak = peakCatalog.front();
445  afw::detection::PeakRecord const& negativePeak = peakCatalog.back();
446 
447  // Set up fit parameters and param names
448  ROOT::Minuit2::MnUserParameters fitPar;
449 
450  fitPar.Add((boost::format("P%d")%NEGCENTXPAR).str(), negativePeak.getFx(), _ctrl.stepSizeCoord);
451  fitPar.Add((boost::format("P%d")%NEGCENTYPAR).str(), negativePeak.getFy(), _ctrl.stepSizeCoord);
452  fitPar.Add((boost::format("P%d")%NEGFLUXPAR).str(), negativePeak.getPeakValue(), _ctrl.stepSizeFlux);
453  fitPar.Add((boost::format("P%d")%POSCENTXPAR).str(), positivePeak.getFx(), _ctrl.stepSizeCoord);
454  fitPar.Add((boost::format("P%d")%POSCENTYPAR).str(), positivePeak.getFy(), _ctrl.stepSizeCoord);
455  fitPar.Add((boost::format("P%d")%POSFLUXPAR).str(), positivePeak.getPeakValue(), _ctrl.stepSizeFlux);
456 
457  // Create the minuit object that knows how to minimise our functor
458  //
459  MinimizeDipoleChi2 minimizerFunc(*this, source, exposure);
460  minimizerFunc.setErrorDef(_ctrl.errorDef);
461 
462  //
463  // tell minuit about it
464  //
465  ROOT::Minuit2::MnMigrad migrad(minimizerFunc, fitPar);
466 
467  //
468  // And let it loose
469  //
470  ROOT::Minuit2::FunctionMinimum min = migrad(_ctrl.maxFnCalls);
471 
472  float minChi2 = min.Fval();
473  bool const isValid = min.IsValid() && std::isfinite(minChi2);
474 
475  if (true || isValid) { // calculate coeffs even in minuit is unhappy
476 
477  /* I need to call chi2 one more time to grab nPix to calculate chi2/dof.
478  Turns out that the Minuit operator method has to be const, and the
479  measurement _apply method has to be const, so I can't store nPix as a
480  private member variable anywhere. Consted into a corner.
481  */
482  std::pair<double,int> fit = chi2(source, exposure,
483  min.UserState().Value(NEGCENTXPAR),
484  min.UserState().Value(NEGCENTYPAR),
485  min.UserState().Value(NEGFLUXPAR),
486  min.UserState().Value(POSCENTXPAR),
487  min.UserState().Value(POSCENTYPAR),
488  min.UserState().Value(POSFLUXPAR));
489  double evalChi2 = fit.first;
490  int nPix = fit.second;
491 
492  PTR(geom::Point2D) minNegCentroid(new geom::Point2D(min.UserState().Value(NEGCENTXPAR),
493  min.UserState().Value(NEGCENTYPAR)));
494  source.set(getNegativeKeys().getInstFlux(), min.UserState().Value(NEGFLUXPAR));
495  source.set(getNegativeKeys().getInstFluxErr(), min.UserState().Error(NEGFLUXPAR));
496 
497  PTR(geom::Point2D) minPosCentroid(new geom::Point2D(min.UserState().Value(POSCENTXPAR),
498  min.UserState().Value(POSCENTYPAR)));
499  source.set(getPositiveKeys().getInstFlux(), min.UserState().Value(POSFLUXPAR));
500  source.set(getPositiveKeys().getInstFluxErr(), min.UserState().Error(POSFLUXPAR));
501 
502  source.set(_chi2dofKey, evalChi2 / (nPix - minimizerFunc.getNpar()));
503  source.set(_negCentroid.getX(), minNegCentroid->getX());
504  source.set(_negCentroid.getY(), minNegCentroid->getY());
505  source.set(_posCentroid.getX(), minPosCentroid->getX());
506  source.set(_posCentroid.getY(), minPosCentroid->getY());
507  source.set(_avgCentroid.getX(), 0.5*(minNegCentroid->getX() + minPosCentroid->getX()));
508  source.set(_avgCentroid.getY(), 0.5*(minNegCentroid->getY() + minPosCentroid->getY()));
509 
510  }
511 }
512 
514  _flagHandler.handleFailure(measRecord, error);
515 }
516 }}} // namespace lsst::ip::diffim
y
int y
Definition: SpanSet.cc:49
schema
table::Schema schema
Definition: Amplifier.cc:115
DipoleAlgorithms.h
lsst::ip::diffim::NaiveDipoleCentroid::fail
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.
Definition: DipoleAlgorithms.cc:211
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
lsst::afw::image::Exposure::getPsf
std::shared_ptr< lsst::afw::detection::Psf const > getPsf() const
Return the Exposure's Psf object.
Definition: Exposure.h:307
lsst::ip::diffim::MinimizeDipoleChi2::getNpar
int getNpar() const
Definition: DipoleAlgorithms.cc:311
lsst::ip::diffim::POSCENTYPAR
int const POSCENTYPAR(4)
std::string
STL class.
lsst::log.log.logContinued.error
def error(fmt, *args)
Definition: logContinued.py:213
lsst::ip::diffim::DipoleFluxAlgorithm::POS_FLAG
static meas::base::FlagDefinition const POS_FLAG
Definition: DipoleAlgorithms.h:119
lsst::afw::detection::PeakRecord
Record class that represents a peak in a Footprint.
Definition: Peak.h:42
lsst::meas::base::FlagHandler::handleFailure
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
Handle an expected or unexpected Exception thrown by a measurement algorithm.
Definition: FlagHandler.cc:76
lsst::ip::diffim::NaiveDipoleCentroid::NaiveDipoleCentroid
NaiveDipoleCentroid(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
Definition: DipoleAlgorithms.cc:145
lsst::afw::table::SourceRecord
Record class that contains measurements made on a single exposure.
Definition: Source.h:80
lsst::ip::diffim::MinimizeDipoleChi2::MinimizeDipoleChi2
MinimizeDipoleChi2(PsfDipoleFlux const &psfDipoleFlux, afw::table::SourceRecord &source, afw::image::Exposure< float > const &exposure)
Definition: DipoleAlgorithms.cc:298
lsst::ip::diffim::PsfDipoleFluxControl::stepSizeCoord
float stepSizeCoord
"Default initial step size for coordinates in non-linear fitter" ;
Definition: DipoleAlgorithms.h:69
lsst::afw::image::Exposure< float >
std::pair
lsst::ip::diffim::DipoleCentroidAlgorithm
Intermediate base class for algorithms that compute a centroid.
Definition: DipoleAlgorithms.h:80
std::vector< double >
psf
Key< int > psf
Definition: Exposure.cc:65
lsst::ip::diffim::NaiveDipoleFlux::measure
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.
Definition: DipoleAlgorithms.cc:268
lsst::ip::diffim::NEGCENTXPAR
int const NEGCENTXPAR(0)
lsst::meas::base::MeasurementError
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition: exceptions.h:48
lsst::ip::diffim::NaiveDipoleCentroid::measure
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.
Definition: DipoleAlgorithms.cc:156
astshim.keyMap.keyMapContinued.keys
def keys(self)
Definition: keyMapContinued.py:6
lsst::ip::diffim::DipoleFluxAlgorithm::_flagHandler
meas::base::FlagHandler _flagHandler
Definition: DipoleAlgorithms.h:145
lsst::ip::diffim::POSCENTXPAR
int const POSCENTXPAR(3)
lsst::afw::table::Schema
Defines the fields and offsets for a table.
Definition: Schema.h:50
lsst::afw::image::indexToPosition
double indexToPosition(double ind)
Convert image index to image position.
Definition: ImageUtils.h:55
lsst.pex.config.history.format
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
lsst::meas::base::CentroidResultKey
A FunctorKey for CentroidResult.
Definition: CentroidUtilities.h:88
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::ip::diffim::DipoleFluxAlgorithm::getNegativeKeys
ResultKey const & getNegativeKeys() const
Definition: DipoleAlgorithms.h:134
lsst::ip::diffim::MinimizeDipoleChi2::setMaxPix
void setMaxPix(int maxPix)
Definition: DipoleAlgorithms.cc:313
PTR
#define PTR(...)
Definition: base.h:41
lsst::afw::image::Exposure::getMaskedImage
MaskedImageT getMaskedImage()
Return the MaskedImage.
Definition: Exposure.h:228
lsst::afw::math::Statistics::getValue
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
Definition: Statistics.cc:1056
lsst::ip::diffim::NEGFLUXPAR
int const NEGFLUXPAR(2)
lsst::ip::diffim::NaiveDipoleCentroid::getPositiveKeys
ResultKey const & getPositiveKeys() const
Definition: DipoleAlgorithms.h:256
lsst::ip::diffim::DipoleFluxAlgorithm::getPositiveKeys
ResultKey const & getPositiveKeys() const
Return the standard flux keys registered by this algorithm.
Definition: DipoleAlgorithms.h:133
lsst::meas::base::FlagDefinitionList
vector-type utility class to build a collection of FlagDefinitions
Definition: FlagHandler.h:60
lsst::afw::math::makeStatistics
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
Definition: Statistics.h:354
math.h
lsst::afw::table::CatalogT::size
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:408
lsst::ip::diffim::PsfDipoleFluxControl::maxFnCalls
int maxFnCalls
"Maximum function calls for non-linear fitter; 0 = unlimited" ;
Definition: DipoleAlgorithms.h:72
lsst::ip::diffim::MinimizeDipoleChi2::operator()
virtual double operator()(std::vector< double > const &params) const
Definition: DipoleAlgorithms.cc:316
data
char * data
Definition: BaseRecord.cc:62
lsst::afw::image::MaskedImage
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
std::isfinite
T isfinite(T... args)
lsst::ip::diffim::NEGCENTYPAR
int const NEGCENTYPAR(1)
lsst::ip::diffim::DipoleFluxAlgorithm::FAILURE
static meas::base::FlagDefinition const FAILURE
Definition: DipoleAlgorithms.h:118
ast::detail::source
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
lsst::ip::diffim::MinimizeDipoleChi2::Up
double Up() const
Definition: DipoleAlgorithms.cc:309
image
afw::table::Key< afw::table::Array< ImagePixelT > > image
Definition: HeavyFootprint.cc:216
lsst::ip::diffim::MinimizeDipoleChi2::setErrorDef
void setErrorDef(double def)
Definition: DipoleAlgorithms.cc:310
x
double x
Definition: ChebyshevBoundedField.cc:277
lsst.pex::exceptions::LengthError
Reports attempts to exceed implementation-defined length limits for some classes.
Definition: Runtime.h:76
lsst::ip::diffim::MinimizeDipoleChi2
Class to minimize PsfDipoleFlux; this is the object that Minuit minimizes.
Definition: DipoleAlgorithms.cc:296
lsst::afw::detection::PeakCatalog
afw::table::CatalogT< PeakRecord > PeakCatalog
Definition: Peak.h:244
lsst::afw::detection::PeakRecord::getPeakValue
float getPeakValue() const
Definition: Peak.h:240
image.h
CONST_PTR
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
detection.h
lsst::ip::diffim::PsfDipoleFlux::fail
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.
Definition: DipoleAlgorithms.cc:513
lsst::ip::diffim::PsfDipoleFlux::chi2
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
Definition: DipoleAlgorithms.cc:352
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::afw::image::MaskedImage::getVariance
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
Definition: MaskedImage.h:1079
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::afw::detection
Definition: Footprint.h:50
std::min
T min(T... args)
lsst::afw::detection::PeakRecord::getFx
float getFx() const
Definition: Peak.h:235
lsst::geom
Definition: AffineTransform.h:36
lsst::ip::diffim::NaiveDipoleCentroid::getCenterKeys
ResultKey const & getCenterKeys() const
Return the standard centroid keys registered by this algorithm.
Definition: DipoleAlgorithms.h:255
lsst::ip::diffim::DipoleCentroidAlgorithm::getFlagDefinitions
static meas::base::FlagDefinitionList const & getFlagDefinitions()
Definition: DipoleAlgorithms.cc:78
lsst::meas::base::FlagDefinition
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
Definition: FlagHandler.h:40
lsst::ip::diffim::DipoleFluxAlgorithm::NEG_FLAG
static meas::base::FlagDefinition const NEG_FLAG
Definition: DipoleAlgorithms.h:120
lsst::afw::math::NPOINT
@ NPOINT
number of sample points
Definition: Statistics.h:66
lsst::geom::Box2I::getMaxY
int getMaxY() const noexcept
Definition: Box.h:162
lsst::afw::table::CatalogT::front
reference front() const
Return the first record.
Definition: Catalog.h:453
min
int min
Definition: BoundedField.cc:103
lsst::ip::diffim::PsfDipoleFlux
Implementation of Psf dipole flux.
Definition: DipoleAlgorithms.h:289
lsst::geom::Box2I::getMaxX
int getMaxX() const noexcept
Definition: Box.h:161
lsst::afw::math
Definition: statistics.dox:6
lsst::ip::diffim::NaiveDipoleCentroid::mergeCentroids
void mergeCentroids(afw::table::SourceRecord &source, double posValue, double negValue) const
Definition: DipoleAlgorithms.cc:184
lsst::meas::base::CentroidResultKey::getX
afw::table::Key< CentroidElement > getX() const
Return a Key for the x coordinate.
Definition: CentroidUtilities.h:147
lsst::geom::Point< int, 2 >
lsst::ip::diffim::NaiveDipoleFlux::fail
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.
Definition: DipoleAlgorithms.cc:288
lsst::ip::diffim::NaiveDipoleCentroid::getNegativeKeys
ResultKey const & getNegativeKeys() const
Definition: DipoleAlgorithms.h:257
lsst::ip::diffim::POSFLUXPAR
int const POSFLUXPAR(5)
isValid
bool isValid
Definition: fits.cc:399
lsst::ip::diffim::DipoleCentroidAlgorithm::NEG_FLAG
static meas::base::FlagDefinition const NEG_FLAG
Definition: DipoleAlgorithms.h:85
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
lsst::geom::Box2I::getMinX
int getMinX() const noexcept
Definition: Box.h:157
lsst::afw::math::Statistics
Definition: Statistics.h:215
lsst::ip::diffim::MinimizeDipoleChi2::getMaxPix
int getMaxPix() const
Definition: DipoleAlgorithms.cc:312
lsst::afw::image::MaskedImage::getImage
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
Definition: MaskedImage.h:1046
lsst.pex::exceptions
Definition: Exception.h:37
lsst::afw::detection::Psf
A polymorphic base class for representing an image's Point Spread Function.
Definition: Psf.h:76
lsst::afw::image::ImageBase< ImagePixelT >::Pixel
ImagePixelT Pixel
A pixel in this ImageBase.
Definition: ImageBase.h:115
lsst::afw::image::ImageBase::getBBox
lsst::geom::Box2I getBBox(ImageOrigin origin=PARENT) const
Definition: ImageBase.h:443
lsst::ip::diffim::PsfDipoleFluxControl::errorDef
double errorDef
"How many sigma the error bars of the non-linear fitter represent" ;
Definition: DipoleAlgorithms.h:71
std::max
T max(T... args)
lsst::afw::detection::Footprint
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:63
lsst::afw::image::Image< float >
lsst::ip::diffim::PsfDipoleFlux::measure
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
Definition: DipoleAlgorithms.cc:417
lsst::meas::base::CentroidResultKey::getY
afw::table::Key< CentroidElement > getY() const
Return a Key for the y coordinate.
Definition: CentroidUtilities.h:150
lsst::ip::diffim.Control
Control
Definition: __init__.py:49
lsst::afw::table::CatalogT< PeakRecord >
lsst::afw::math::SUM
@ SUM
find sum of pixels in the image
Definition: Statistics.h:78
geom.h
lsst::ip::diffim::PsfDipoleFluxControl::stepSizeFlux
float stepSizeFlux
"Default initial step size for flux in non-linear fitter" ;
Definition: DipoleAlgorithms.h:70
lsst::ip::diffim::DipoleCentroidAlgorithm::POS_FLAG
static meas::base::FlagDefinition const POS_FLAG
Definition: DipoleAlgorithms.h:84
table.h
lsst::ip::diffim::DipoleFluxAlgorithm::getFlagDefinitions
static meas::base::FlagDefinitionList const & getFlagDefinitions()
Definition: DipoleAlgorithms.cc:66
lsst.pex::exceptions::RuntimeError
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
lsst::geom::Box2I::getMinY
int getMinY() const noexcept
Definition: Box.h:158
lsst::afw::detection::PeakRecord::getFy
float getFy() const
Definition: Peak.h:236
lsst::afw::table::CatalogT::back
reference back() const
Return the last record.
Definition: Catalog.h:456
exceptions.h
lsst::ip::diffim::DipoleCentroidAlgorithm::FAILURE
static meas::base::FlagDefinition const FAILURE
Definition: DipoleAlgorithms.h:83