LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
LSSTDataManagementBasePackage
KronPhotometry.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2015 LSST Corporation.
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 <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 
24 #include <numeric>
25 #include <cmath>
26 #include <functional>
27 #include "boost/math/constants/constants.hpp"
28 #include "lsst/pex/exceptions.h"
29 #include "lsst/geom/Point.h"
30 #include "lsst/geom/Box.h"
31 #include "lsst/afw/geom/SpanSet.h"
33 #include "lsst/afw/table/Source.h"
37 #include "lsst/afw/detection/Psf.h"
39 #include "lsst/afw/geom/ellipses.h"
40 #include "lsst/meas/base.h"
42 
44 
45 namespace lsst {
46 namespace meas {
47 namespace extensions {
48 namespace photometryKron {
49 
50 namespace {
51 base::FlagDefinitionList flagDefinitions;
52 } // end anonymous
53 
54 base::FlagDefinition const KronFluxAlgorithm::FAILURE = flagDefinitions.addFailureFlag( "general failure flag, set if anything went wrong");
55 base::FlagDefinition const KronFluxAlgorithm::EDGE = flagDefinitions.add("flag_edge", "bad measurement due to image edge");
56 base::FlagDefinition const KronFluxAlgorithm::BAD_SHAPE_NO_PSF = flagDefinitions.add("flag_bad_shape_no_psf", "bad shape and no PSF");
57 base::FlagDefinition const KronFluxAlgorithm::NO_MINIMUM_RADIUS = flagDefinitions.add("flag_no_minimum_radius", "minimum radius could not enforced: no minimum value or PSF");
58 base::FlagDefinition const KronFluxAlgorithm::NO_FALLBACK_RADIUS = flagDefinitions.add("flag_no_fallback_radius", "no minimum radius and no PSF provided");
59 base::FlagDefinition const KronFluxAlgorithm::BAD_RADIUS = flagDefinitions.add("flag_bad_radius", "bad Kron radius");
60 base::FlagDefinition const KronFluxAlgorithm::USED_MINIMUM_RADIUS = flagDefinitions.add("flag_used_minimum_radius", "used the minimum radius for the Kron aperture");
61 base::FlagDefinition const KronFluxAlgorithm::USED_PSF_RADIUS = flagDefinitions.add("flag_used_psf_radius", "used the PSF Kron radius for the Kron aperture");
62 base::FlagDefinition const KronFluxAlgorithm::SMALL_RADIUS = flagDefinitions.add("flag_small_radius", "measured Kron radius was smaller than that of the PSF");
63 base::FlagDefinition const KronFluxAlgorithm::BAD_SHAPE = flagDefinitions.add("flag_bad_shape", "shape for measuring Kron radius is bad; used PSF shape");
64 
66  return flagDefinitions;
67 }
68 
71 
72 namespace {
73 
74 template <typename MaskedImageT>
75  class FootprintFlux {
76 public:
77  explicit FootprintFlux() : _sum(0.0), _sumVar(0.0) {}
78 
80  void reset() {
81  _sum = _sumVar = 0.0;
82  }
83  void reset(afw::detection::Footprint const&) {}
84 
86  void operator()(geom::Point2I const & pos,
87  typename MaskedImageT::Image::Pixel const & ival,
88  typename MaskedImageT::Variance::Pixel const & vval) {
89  _sum += ival;
90  _sumVar += vval;
91  }
92 
94  double getSum() const { return _sum; }
95 
97  double getSumVar() const { return _sumVar; }
98 
99 private:
100  double _sum;
101  double _sumVar;
102 };
103 
104 /************************************************************************************************************/
115 template <typename MaskedImageT, typename WeightImageT>
116 class FootprintFindMoment {
117 public:
118  FootprintFindMoment(MaskedImageT const& mimage,
119  geom::Point2D const& center, // center of the object
120  double const ab, // axis ratio
121  double const theta // rotation of ellipse +ve from x axis
122  ) : _xcen(center.getX()), _ycen(center.getY()),
123  _ab(ab),
124  _cosTheta(::cos(theta)),
125  _sinTheta(::sin(theta)),
126  _sum(0.0), _sumR(0.0),
127 #if 0
128  _sumVar(0.0), _sumRVar(0.0),
129 #endif
130  _imageX0(mimage.getX0()), _imageY0(mimage.getY0())
131  {}
132 
134  void reset() {}
135  void reset(afw::detection::Footprint const& foot) {
136  _sum = _sumR = 0.0;
137 #if 0
138  _sumVar = _sumRVar = 0.0;
139 #endif
140 
141  MaskedImageT const& mimage = this->getImage();
142  geom::Box2I const& bbox(foot.getBBox());
143  int const x0 = bbox.getMinX(), y0 = bbox.getMinY(), x1 = bbox.getMaxX(), y1 = bbox.getMaxY();
144 
145  if (x0 < _imageX0 || y0 < _imageY0 ||
146  x1 >= _imageX0 + mimage.getWidth() || y1 >= _imageY0 + mimage.getHeight()) {
148  (boost::format("Footprint %d,%d--%d,%d doesn't fit in image %d,%d--%d,%d")
149  % x0 % y0 % x1 % y1
150  % _imageX0 % _imageY0
151  % (_imageX0 + mimage.getWidth() - 1) % (_imageY0 + mimage.getHeight() - 1)
152  ).str());
153  }
154  }
155 
157  void operator()(geom::Point2I const & pos, typename MaskedImageT::Image::Pixel const & ival) {
158  double x = static_cast<double>(pos.getX());
159  double y = static_cast<double>(pos.getY());
160  double const dx = x - _xcen;
161  double const dy = y - _ycen;
162  double const du = dx*_cosTheta + dy*_sinTheta;
163  double const dv = -dx*_sinTheta + dy*_cosTheta;
164 
165  double r = ::hypot(du, dv*_ab); // ellipsoidal radius
166 #if 1
167  if (::hypot(dx, dy) < 0.5) { // within a pixel of the centre
168  /*
169  * We gain significant precision for flattened Gaussians by treating the central pixel specially
170  *
171  * If the object's centered in the pixel (and has constant surface brightness) we have <r> == eR;
172  * if it's at the corner <r> = 2*eR; we interpolate between these exact results linearily in the
173  * displacement. And then add in quadrature which is also a bit dubious
174  *
175  * We could avoid all these issues by estimating <r> using the same trick as we use for
176  * the sinc fluxes; it's not clear that it's worth it.
177  */
178 
179  double const eR = 0.38259771140356325; // <r> for a single square pixel, about the centre
180  r = ::hypot(r, eR*(1 + ::hypot(dx, dy)/geom::ROOT2));
181  }
182 #endif
183 
184  _sum += ival;
185  _sumR += r*ival;
186 #if 0
187  typename MaskedImageT::Variance::Pixel vval = iloc.variance(0, 0);
188  _sumVar += vval;
189  _sumRVar += r*r*vval;
190 #endif
191  }
192 
194  double getIr() const { return _sumR/_sum; }
195 
196 #if 0
197 // double getIrVar() const { return _sumRVar/_sum - getIr()*getIr(); } // Wrong?
199  double getIrVar() const { return _sumRVar/(_sum*_sum) + _sumVar*_sumR*_sumR/::pow(_sum, 4); }
200 #endif
201 
203  bool getGood() const { return _sum > 0 && _sumR > 0; }
204 
205 private:
206  double const _xcen; // center of object
207  double const _ycen; // center of object
208  double const _ab; // axis ratio
209  double const _cosTheta, _sinTheta; // {cos,sin}(angle from x-axis)
210  double _sum; // sum of I
211  double _sumR; // sum of R*I
212 #if 0
213  double _sumVar; // sum of Var(I)
214  double _sumRVar; // sum of R*R*Var(I)
215 #endif
216  int const _imageX0, _imageY0; // origin of image we're measuring
217 
218 };
219 } // end anonymous namespace
220 
222  afw::geom::ellipses::Axes const& shape,
223  geom::LinearTransform const& transformation,
224  double const radius
225  )
226 {
227  afw::geom::ellipses::Axes axes(shape);
228  axes.scale(radius/axes.getDeterminantRadius());
229  return axes.transform(transformation);
230 }
231 
232 template<typename ImageT>
234  ImageT const& image,
236  geom::Point2D const& center,
237  KronFluxControl const& ctrl
238  )
239 {
240  //
241  // We might smooth the image because this is what SExtractor and Pan-STARRS do. But I don't see much gain
242  //
243  double const sigma = ctrl.smoothingSigma; // Gaussian width of smoothing sigma to apply
244  bool const smoothImage = sigma > 0;
245  int kSize = smoothImage ? 2*int(2*sigma) + 1 : 1;
246  afw::math::GaussianFunction1<afw::math::Kernel::Pixel> gaussFunc(smoothImage ? sigma : 100);
247  afw::math::SeparableKernel kernel(kSize, kSize, gaussFunc, gaussFunc);
248  bool const doNormalize = true, doCopyEdge = false;
249  afw::math::ConvolutionControl convCtrl(doNormalize, doCopyEdge);
250  double radius0 = axes.getDeterminantRadius();
252  float radiusForRadius = std::nanf("");
253  for (int i = 0; i < ctrl.nIterForRadius; ++i) {
254  axes.scale(ctrl.nSigmaForRadius);
255  radiusForRadius = axes.getDeterminantRadius(); // radius we used to estimate R_K
256  //
257  // Build an elliptical Footprint of the proper size
258  //
260  afw::geom::ellipses::Ellipse(axes, center)));
261  geom::Box2I bbox = !smoothImage ?
262  foot.getBBox() :
263  kernel.growBBox(foot.getBBox()); // the smallest bbox needed to convolve with Kernel
264  bbox.clip(image.getBBox());
265  ImageT subImage(image, bbox, afw::image::PARENT, smoothImage);
266  if (smoothImage) {
267  afw::math::convolve(subImage, ImageT(image, bbox, afw::image::PARENT, false), kernel, convCtrl);
268  }
269  //
270  // Find the desired first moment of the elliptical radius, which corresponds to the major axis.
271  //
272  FootprintFindMoment<ImageT, afw::detection::Psf::Image> iRFunctor(
273  subImage, center, axes.getA()/axes.getB(), axes.getTheta()
274  );
275 
276  try {
277  foot.getSpans()->applyFunctor(
278  iRFunctor, *(subImage.getImage()));
280  if (i == 0) {
281  LSST_EXCEPT_ADD(e, "Determining Kron aperture");
282  }
283  break; // use the radius we have
284  }
285 
286  if (!iRFunctor.getGood()) {
287  throw LSST_EXCEPT(BadKronException, "Bad integral defining Kron radius");
288  }
289 
290  radius = iRFunctor.getIr()*sqrt(axes.getB()/axes.getA());
291  if (radius <= radius0) {
292  break;
293  }
294  radius0 = radius;
295 
296  axes.scale(radius/axes.getDeterminantRadius()); // set axes to our current estimate of R_K
297  iRFunctor.reset();
298  }
299 
300  return std::make_shared<KronAperture>(center, axes, radiusForRadius);
301 }
302 
303 // Photometer an image with a particular aperture
304 template<typename ImageT>
306  ImageT const& image, // Image to measure
307  afw::geom::ellipses::Ellipse const& aperture, // Aperture in which to measure
308  double const maxSincRadius // largest radius that we use sinc apertures to measure
309  )
310 {
311  afw::geom::ellipses::Axes const& axes = aperture.getCore();
312  if (axes.getB() > maxSincRadius) {
313  FootprintFlux<ImageT> fluxFunctor;
314  auto spans = afw::geom::SpanSet::fromShape(aperture);
315  spans->applyFunctor(
316  fluxFunctor, *(image.getImage()), *(image.getVariance()));
317  return std::make_pair(fluxFunctor.getSum(), ::sqrt(fluxFunctor.getSumVar()));
318  }
319  try {
320  base::ApertureFluxResult fluxResult = base::ApertureFluxAlgorithm::computeSincFlux<float>(image, aperture);
321  return std::make_pair(fluxResult.instFlux, fluxResult.instFluxErr);
322  } catch(pex::exceptions::LengthError &e) {
323  LSST_EXCEPT_ADD(e, (boost::format("Measuring Kron flux for object at (%.3f, %.3f);"
324  " aperture radius %g,%g theta %g")
325  % aperture.getCenter().getX() % aperture.getCenter().getY()
326  % axes.getA() % axes.getB() % geom::radToDeg(axes.getTheta())).str());
327  throw e;
328  }
329 }
330 
331 
333  CONST_PTR(afw::detection::Psf) const& psf, // PSF to measure
334  geom::Point2D const& center, // Centroid of source on parent image
335  double smoothingSigma=0.0 // Gaussian sigma of smoothing applied
336  )
337 {
338  assert(psf);
339  double const radius = psf->computeShape(center).getDeterminantRadius();
340  // For a Gaussian N(0, sigma^2), the Kron radius is sqrt(pi/2)*sigma
341  return ::sqrt(geom::PI/2)*::hypot(radius, std::max(0.0, smoothingSigma));
342 }
343 
344 template<typename ImageT>
346  ImageT const& image,
347  double const nRadiusForFlux,
348  double const maxSincRadius
349  ) const
350 {
351  afw::geom::ellipses::Axes axes(getAxes()); // Copy of ellipse core, so we can scale
352  axes.scale(nRadiusForFlux);
353  afw::geom::ellipses::Ellipse const ellip(axes, getCenter());
354 
355  return photometer(image, ellip, maxSincRadius);
356 }
357 
358 /************************************************************************************************************/
359 
366  KronFluxControl const & ctrl,
367  std::string const & name,
369  daf::base::PropertySet & metadata
370 ) : _name(name),
371  _ctrl(ctrl),
372  _fluxResultKey(
373  meas::base::FluxResultKey::addFields(schema, name, "flux from Kron Flux algorithm")
374  ),
375  _radiusKey(schema.addField<float>(name + "_radius", "Kron radius (sqrt(a*b))")),
376  _radiusForRadiusKey(schema.addField<float>(name + "_radius_for_radius",
377  "radius used to estimate <radius> (sqrt(a*b))")),
378  _psfRadiusKey(schema.addField<float>(name + "_psf_radius", "Radius of PSF")),
379  _centroidExtractor(schema, name, true)
380 {
381  _flagHandler = meas::base::FlagHandler::addFields(schema, name, getFlagDefinitions());
382  metadata.add(name + "_nRadiusForFlux", ctrl.nRadiusForFlux);
383 }
384 
386  afw::table::SourceRecord & measRecord,
388 ) const {
389  _flagHandler.handleFailure(measRecord, error);
390 }
391 
392 void KronFluxAlgorithm::_applyAperture(
394  afw::image::Exposure<float> const& exposure,
395  KronAperture const& aperture
396  ) const
397 {
398  double const rad = aperture.getAxes().getDeterminantRadius();
400  throw LSST_EXCEPT(
402  BAD_RADIUS.doc,
404  );
405  }
406 
408  try {
409  result = aperture.measureFlux(exposure.getMaskedImage(), _ctrl.nRadiusForFlux, _ctrl.maxSincRadius);
410  } catch (pex::exceptions::LengthError const& e) {
411  // We hit the edge of the image; there's no reasonable fallback or recovery
412  throw LSST_EXCEPT(
414  EDGE.doc,
415  EDGE.number
416  );
418  throw LSST_EXCEPT(
420  EDGE.doc,
421  EDGE.number
422  );
423  }
424 
425  // set the results in the source object
426  meas::base::FluxResult fluxResult;
427  fluxResult.instFlux = result.first;
428  fluxResult.instFluxErr = result.second;
429  source.set(_fluxResultKey, fluxResult);
430  source.set(_radiusKey, aperture.getAxes().getDeterminantRadius());
431  //
432  // REMINDER: In the old code, the psfFactor is calculated using getPsfFactor,
433  // and the values set for _fluxCorrectionKeys. See old meas_algorithms version.
434 }
435 
436 void KronFluxAlgorithm::_applyForced(
437  afw::table::SourceRecord & source,
438  afw::image::Exposure<float> const & exposure,
439  geom::Point2D const & center,
440  afw::table::SourceRecord const & reference,
441  geom::AffineTransform const & refToMeas
442  ) const
443 {
444  float const radius = reference.get(reference.getSchema().find<float>(_ctrl.refRadiusName).key);
445  KronAperture const aperture(reference, refToMeas, radius);
446  _applyAperture(source, exposure, aperture);
447  if (exposure.getPsf()) {
448  source.set(_psfRadiusKey, calculatePsfKronRadius(exposure.getPsf(), center, _ctrl.smoothingSigma));
449  }
450 }
451 
453  afw::table::SourceRecord & source,
454  afw::image::Exposure<float> const& exposure
455  ) const {
456  geom::Point2D center = _centroidExtractor(source, _flagHandler);
457 
458  // Did we hit a condition that fundamentally prevented measuring the Kron flux?
459  // Such conditions include hitting the edge of the image and bad input shape, but not low signal-to-noise.
460  bool bad = false;
461 
462  afw::image::MaskedImage<float> const& mimage = exposure.getMaskedImage();
463 
464  double R_K_psf = -1;
465  if (exposure.getPsf()) {
466  R_K_psf = calculatePsfKronRadius(exposure.getPsf(), center, _ctrl.smoothingSigma);
467  }
468 
469  //
470  // Get the shape of the desired aperture
471  //
473  if (!source.getShapeFlag()) {
474  axes = source.getShape();
475  } else {
476  bad = true;
477  if (!exposure.getPsf()) {
478  throw LSST_EXCEPT(
482  );
483  }
484  axes = exposure.getPsf()->computeShape();
485  _flagHandler.setValue(source, BAD_SHAPE.number, true);
486  }
487  if (_ctrl.useFootprintRadius) {
488  afw::geom::ellipses::Axes footprintAxes(source.getFootprint()->getShape());
489  // if the Footprint's a disk of radius R we want footRadius == R.
490  // As <r^2> = R^2/2 for a disk, we need to scale up by sqrt(2)
491  footprintAxes.scale(::sqrt(2));
492 
493  double radius0 = axes.getDeterminantRadius();
494  double const footRadius = footprintAxes.getDeterminantRadius();
495 
496  if (footRadius > radius0*_ctrl.nSigmaForRadius) {
497  radius0 = footRadius/_ctrl.nSigmaForRadius; // we'll scale it up by nSigmaForRadius
498  axes.scale(radius0/axes.getDeterminantRadius());
499  }
500  }
501 
502  PTR(KronAperture) aperture;
503  if (_ctrl.fixed) {
504  aperture.reset(new KronAperture(source));
505  } else {
506  try {
507  aperture = KronAperture::determineRadius(mimage, axes, center, _ctrl);
508  } catch (pex::exceptions::OutOfRangeError& e) {
509  // We hit the edge of the image: no reasonable fallback or recovery possible
510  throw LSST_EXCEPT(
512  EDGE.doc,
513  EDGE.number
514  );
515  } catch (BadKronException& e) {
516  // Not setting bad=true because we only failed due to low S/N
517  aperture = _fallbackRadius(source, R_K_psf, e);
518  } catch(pex::exceptions::Exception& e) {
519  bad = true; // There's something fundamental keeping us from measuring the Kron aperture
520  aperture = _fallbackRadius(source, R_K_psf, e);
521  }
522  }
523 
524  /*
525  * Estimate the minimum acceptable Kron radius as the Kron radius of the PSF or the
526  * provided minimum radius
527  */
528 
529  // Enforce constraints on minimum radius
530  double rad = aperture->getAxes().getDeterminantRadius();
531  if (_ctrl.enforceMinimumRadius) {
532  double newRadius = rad;
533  if (_ctrl.minimumRadius > 0.0) {
534  if (rad < _ctrl.minimumRadius) {
535  newRadius = _ctrl.minimumRadius;
536  _flagHandler.setValue(source, USED_MINIMUM_RADIUS.number, true);
537  }
538  } else if (!exposure.getPsf()) {
539  throw LSST_EXCEPT(
543  );
544  } else if (rad < R_K_psf) {
545  newRadius = R_K_psf;
546  _flagHandler.setValue(source, USED_PSF_RADIUS.number, true);
547  }
548  if (newRadius != rad) {
549  aperture->getAxes().scale(newRadius/rad);
550  _flagHandler.setValue(source, SMALL_RADIUS.number, true); // guilty after all
551  }
552  }
553 
554  _applyAperture(source, exposure, *aperture);
555  source.set(_radiusForRadiusKey, aperture->getRadiusForRadius());
556  source.set(_psfRadiusKey, R_K_psf);
557  if (bad) _flagHandler.setValue(source, FAILURE.number, true);
558 }
559 
561  afw::table::SourceRecord & measRecord,
562  afw::image::Exposure<float> const & exposure,
563  afw::table::SourceRecord const & refRecord,
564  afw::geom::SkyWcs const & refWcs
565  ) const {
566  geom::Point2D center = _centroidExtractor(measRecord, _flagHandler);
567  auto xytransform = afw::geom::makeWcsPairTransform(refWcs, *exposure.getWcs());
568  _applyForced(measRecord, exposure, center, refRecord,
569  linearizeTransform(*xytransform, refRecord.getCentroid())
570  );
571 
572 }
573 
574 
575 PTR(KronAperture) KronFluxAlgorithm::_fallbackRadius(afw::table::SourceRecord& source, double const R_K_psf,
576  pex::exceptions::Exception& exc) const
577 {
578  _flagHandler.setValue(source, BAD_RADIUS.number, true);
579  double newRadius;
580  if (_ctrl.minimumRadius > 0) {
581  newRadius = _ctrl.minimumRadius;
582  _flagHandler.setValue(source, USED_MINIMUM_RADIUS.number, true);
583  } else if (R_K_psf > 0) {
584  newRadius = R_K_psf;
585  _flagHandler.setValue(source, USED_PSF_RADIUS.number, true);
586  } else {
587  throw LSST_EXCEPT(
591  );
592  }
593  PTR(KronAperture) aperture(new KronAperture(source));
594  aperture->getAxes().scale(newRadius/aperture->getAxes().getDeterminantRadius());
595  return aperture;
596 }
597 
598 
599 #define INSTANTIATE(TYPE) \
600 template PTR(KronAperture) KronAperture::determineRadius<afw::image::MaskedImage<TYPE> >( \
601  afw::image::MaskedImage<TYPE> const&, \
602  afw::geom::ellipses::Axes, \
603  geom::Point2D const&, \
604  KronFluxControl const& \
605  ); \
606 template std::pair<double, double> KronAperture::measureFlux<afw::image::MaskedImage<TYPE> >( \
607  afw::image::MaskedImage<TYPE> const&, \
608  double const, \
609  double const \
610  ) const;
611 
612 INSTANTIATE(float);
613 
614 }}}} // namespace lsst::meas::extensions::photometryKron
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
Defines the fields and offsets for a table.
Definition: Schema.h:50
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
double const getB() const
Definition: Axes.h:54
static meas::base::FlagDefinition const SMALL_RADIUS
lsst::geom::Point2D const & getCenter() const
Return the center point.
Definition: Ellipse.h:62
static meas::base::FlagDefinition const NO_MINIMUM_RADIUS
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition: SkyWcs.h:117
afw::table::Key< afw::table::Array< ImagePixelT > > image
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
lsst::geom::AffineTransform linearizeTransform(TransformPoint2ToPoint2 const &original, lsst::geom::Point2D const &inPoint)
Approximate a Transform by its local linearization.
float Pixel
Typedefs to be used for pixel values.
Definition: common.h:37
virtual void measureForced(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure, afw::table::SourceRecord const &refRecord, afw::geom::SkyWcs const &refWcs) const
Called to measure a single child source in an image.
ShapeSlotDefinition::MeasValue getShape() const
Get the value of the Shape slot measurement.
Definition: Source.h:668
An affine coordinate transformation consisting of a linear transformation and an offset.
std::pair< double, double > photometer(ImageT const &image, afw::geom::ellipses::Ellipse const &aperture, double const maxSincRadius)
double smoothingSigma
"Smooth image with N(0, smoothingSigma^2) Gaussian while estimating R_K" ;
double const getA() const
Definition: Axes.h:51
Parameters to control convolution.
Definition: ConvolveImage.h:50
constexpr double radToDeg(double x) noexcept
Definition: Angle.h:52
Reports attempts to exceed implementation-defined length limits for some classes. ...
Definition: Runtime.h:76
double minimumRadius
"Minimum Kron radius (if == 0.0 use PSF&#39;s Kron radius) if enforceMinimumRadius. " "Also functions as ...
bool getShapeFlag() const
Return true if the measurement in the Shape slot failed.
Definition: Source.h:676
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:895
int y
Definition: SpanSet.cc:49
std::shared_ptr< Footprint > getFootprint() const
Definition: Source.h:102
BaseCore const & getCore() const
Return the ellipse core.
Definition: Ellipse.h:71
static std::shared_ptr< geom::SpanSet > fromShape(int r, Stencil s=Stencil::CIRCLE, lsst::geom::Point2I offset=lsst::geom::Point2I())
Factory function for creating SpanSets from a Stencil.
Definition: SpanSet.cc:689
Provides consistent interface for LSST exceptions.
Definition: Exception.h:107
KronFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema, daf::base::PropertySet &metadata)
A class that knows how to calculate fluxes using the KRON photometry algorithm.
bool fixed
"if true, use existing shape and centroid measurements instead of fitting" ;
void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const
Set the flag field corresponding to the given flag index.
Definition: FlagHandler.h:262
double sin(Angle const &a)
Definition: Angle.h:102
meas::base::FluxErrElement instFluxErr
Standard deviation of instFlux in DN.
Definition: FluxUtilities.h:43
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition: exceptions.h:48
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition: BaseRecord.h:151
double cos(Angle const &a)
Definition: Angle.h:103
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:50
STL class.
lsst::geom::Box2I getBBox() const
Return the Footprint&#39;s bounding box.
Definition: Footprint.h:208
static meas::base::FlagDefinition const USED_MINIMUM_RADIUS
static meas::base::FlagDefinition const USED_PSF_RADIUS
SchemaItem< T > find(std::string const &name) const
Find a SchemaItem in the Schema by name.
Definition: Schema.cc:656
A base class for image defects.
MaskedImageT getMaskedImage()
Return the MaskedImage.
Definition: Exposure.h:228
lsst::geom::Box2I growBBox(lsst::geom::Box2I const &bbox) const
Given a bounding box for pixels one wishes to compute by convolving an image with this kernel...
Definition: Kernel.cc:177
static meas::base::FlagDefinition const NO_FALLBACK_RADIUS
static meas::base::FlagDefinition const BAD_SHAPE_NO_PSF
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:51
double nSigmaForRadius
"Multiplier of rms size for aperture used to initially estimate the Kron radius" ; ...
double calculatePsfKronRadius(boost::shared_ptr< afw::detection::Psf const > const &psf, geom::Point2D const &center, double smoothingSigma=0.0)
table::Schema schema
Definition: Amplifier.cc:115
bool enforceMinimumRadius
"If true check that the Kron radius exceeds some minimum" ;
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:73
Key< U > key
Definition: Schema.cc:281
T make_pair(T... args)
Schema getSchema() const
Return the Schema that holds this record&#39;s fields and keys.
Definition: BaseRecord.h:80
std::pair< double, double > measureFlux(ImageT const &image, double const nRadiusForFlux, double const maxSincRadius) const
Photometer within the Kron Aperture on an image.
void scale(double factor)
Scale the size of the ellipse core by the given factor.
Definition: BaseCore.cc:104
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
std::string refRadiusName
"Name of field specifying reference Kron radius for forced measurement" ;
void convolve(OutImageT &convolvedImage, InImageT const &inImage, KernelT const &kernel, ConvolutionControl const &convolutionControl=ConvolutionControl())
Convolve an Image or MaskedImage with a Kernel, setting pixels of an existing output image...
T max(T... args)
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:62
double x
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinitionList const &flagDefs, FlagDefinitionList const &exclDefs=FlagDefinitionList::getEmptyList())
Add Flag fields to a schema, creating a FlagHandler object to manage them.
Definition: FlagHandler.cc:37
Definition: __init__.py:1
std::shared_ptr< TransformPoint2ToPoint2 > makeWcsPairTransform(SkyWcs const &src, SkyWcs const &dst)
A Transform obtained by putting two SkyWcs objects "back to back".
Definition: SkyWcs.cc:151
static meas::base::FlagDefinition const FAILURE
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Reports attempts to access elements outside a valid range of indices.
Definition: Runtime.h:89
An ellipse core for the semimajor/semiminor axis and position angle parametrization (a...
Definition: Axes.h:47
double maxSincRadius
"Largest aperture for which to use the slow, accurate, sinc aperture code" ;
static meas::base::FlagDefinition const BAD_RADIUS
static boost::shared_ptr< KronAperture > determineRadius(ImageT const &image, afw::geom::ellipses::Axes axes, geom::Point2D const &center, KronFluxControl const &ctrl)
Determine the Kron Aperture from an image.
Transformer transform(lsst::geom::LinearTransform const &transform)
Definition: Transformer.h:116
int nIterForRadius
"Number of times to iterate when setting the Kron radius" ;
Class for storing generic metadata.
Definition: PropertySet.h:67
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
Definition: Box.cc:189
bool useFootprintRadius
"Use the Footprint size as part of initial estimate of Kron radius" ;
static meas::base::FlagDefinition const EDGE
T nanf(T... args)
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
static meas::base::FlagDefinitionList const & getFlagDefinitions()
std::shared_ptr< geom::SkyWcs const > getWcs() const
Definition: Exposure.h:232
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Definition: BaseRecord.h:164
std::shared_ptr< geom::SpanSet > getSpans() const
Return a shared pointer to the SpanSet.
Definition: Footprint.h:115
virtual 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...
Record class that contains measurements made on a single exposure.
Definition: Source.h:82
std::shared_ptr< lsst::afw::detection::Psf const > getPsf() const
Return the Exposure&#39;s Psf object.
Definition: Exposure.h:307
meas::base::Flux instFlux
Measured instFlux in DN.
Definition: FluxUtilities.h:42
T quiet_NaN(T... args)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
double getDeterminantRadius() const
Return the radius defined as the 4th root of the determinant of the quadrupole matrix.
Definition: BaseCore.cc:118
double const getTheta() const
Definition: Axes.h:57
vector-type utility class to build a collection of FlagDefinitions
Definition: FlagHandler.h:60
void add(std::string const &name, T const &value)
Append a single value to the vector of values for a property name (possibly hierarchical).
A polymorphic base class for representing an image&#39;s Point Spread Function.
Definition: Psf.h:75
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition: Exception.h:69
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it...
Definition: Exception.h:54
An integer coordinate rectangle.
Definition: Box.h:55
double constexpr ROOT2
Definition: Angle.h:46
py::object result
Definition: _schema.cc:429
A reusable result struct for instFlux measurements.
Definition: FluxUtilities.h:41
double constexpr PI
The ratio of a circle&#39;s circumference to diameter.
Definition: Angle.h:39
A 2D linear coordinate transformation.
static afw::geom::ellipses::Axes getKronAxes(afw::geom::ellipses::Axes const &shape, geom::LinearTransform const &transformation, double const radius)
Determine Kron axes from a reference image.
CentroidSlotDefinition::MeasValue getCentroid() const
Get the value of the Centroid slot measurement.
Definition: Source.h:656
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
double nRadiusForFlux
"Number of Kron radii for Kron flux" ;
A Result struct for running an aperture flux algorithm with a single radius.
Definition: ApertureFlux.h:217
#define PTR(...)
Definition: base.h:41
#define INSTANTIATE(TYPE)
static meas::base::FlagDefinition const BAD_SHAPE
geom::ellipses::Quadrupole computeShape(lsst::geom::Point2D position=makeNullPoint(), image::Color color=image::Color()) const
Compute the ellipse corresponding to the second moments of the Psf.
Definition: Psf.cc:156