LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
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/algorithm/string.hpp"
28#include "boost/math/constants/constants.hpp"
29#include "lsst/pex/exceptions.h"
30#include "lsst/geom/Point.h"
31#include "lsst/geom/Box.h"
41#include "lsst/meas/base.h"
43
45
46namespace lsst {
47namespace meas {
48namespace extensions {
49namespace photometryKron {
50
51namespace {
52base::FlagDefinitionList flagDefinitions;
53} // end anonymous
54
55base::FlagDefinition const KronFluxAlgorithm::FAILURE = flagDefinitions.addFailureFlag( "general failure flag, set if anything went wrong");
56base::FlagDefinition const KronFluxAlgorithm::EDGE = flagDefinitions.add("flag_edge", "bad measurement due to image edge");
57base::FlagDefinition const KronFluxAlgorithm::BAD_SHAPE_NO_PSF = flagDefinitions.add("flag_bad_shape_no_psf", "bad shape and no PSF");
58base::FlagDefinition const KronFluxAlgorithm::NO_MINIMUM_RADIUS = flagDefinitions.add("flag_no_minimum_radius", "minimum radius could not enforced: no minimum value or PSF");
59base::FlagDefinition const KronFluxAlgorithm::NO_FALLBACK_RADIUS = flagDefinitions.add("flag_no_fallback_radius", "no minimum radius and no PSF provided");
60base::FlagDefinition const KronFluxAlgorithm::BAD_RADIUS = flagDefinitions.add("flag_bad_radius", "bad Kron radius");
61base::FlagDefinition const KronFluxAlgorithm::USED_MINIMUM_RADIUS = flagDefinitions.add("flag_used_minimum_radius", "used the minimum radius for the Kron aperture");
62base::FlagDefinition const KronFluxAlgorithm::USED_PSF_RADIUS = flagDefinitions.add("flag_used_psf_radius", "used the PSF Kron radius for the Kron aperture");
63base::FlagDefinition const KronFluxAlgorithm::SMALL_RADIUS = flagDefinitions.add("flag_small_radius", "measured Kron radius was smaller than that of the PSF");
64base::FlagDefinition const KronFluxAlgorithm::BAD_SHAPE = flagDefinitions.add("flag_bad_shape", "shape for measuring Kron radius is bad; used PSF shape");
65
67 return flagDefinitions;
68}
69
72
73namespace {
74
75template <typename MaskedImageT>
76 class FootprintFlux {
77public:
78 explicit FootprintFlux() : _sum(0.0), _sumVar(0.0) {}
79
81 void reset() {
82 _sum = _sumVar = 0.0;
83 }
84 void reset(afw::detection::Footprint const&) {}
85
87 void operator()(geom::Point2I const & pos,
88 typename MaskedImageT::Image::Pixel const & ival,
89 typename MaskedImageT::Variance::Pixel const & vval) {
90 _sum += ival;
91 _sumVar += vval;
92 }
93
95 double getSum() const { return _sum; }
96
98 double getSumVar() const { return _sumVar; }
99
100private:
101 double _sum;
102 double _sumVar;
103};
104
105/************************************************************************************************************/
116template <typename MaskedImageT, typename WeightImageT>
117class FootprintFindMoment {
118public:
119 FootprintFindMoment(MaskedImageT const& mimage,
120 geom::Point2D const& center, // center of the object
121 double const ab, // axis ratio
122 double const theta // rotation of ellipse +ve from x axis
123 ) : _xcen(center.getX()), _ycen(center.getY()),
124 _ab(ab),
125 _cosTheta(::cos(theta)),
126 _sinTheta(::sin(theta)),
127 _sum(0.0), _sumR(0.0),
128#if 0
129 _sumVar(0.0), _sumRVar(0.0),
130#endif
131 _imageX0(mimage.getX0()), _imageY0(mimage.getY0())
132 {}
133
135 void reset() {}
136 void reset(afw::detection::Footprint const& foot) {
137 _sum = _sumR = 0.0;
138#if 0
139 _sumVar = _sumRVar = 0.0;
140#endif
141
142 MaskedImageT const& mimage = this->getImage();
143 geom::Box2I const& bbox(foot.getBBox());
144 int const x0 = bbox.getMinX(), y0 = bbox.getMinY(), x1 = bbox.getMaxX(), y1 = bbox.getMaxY();
145
146 if (x0 < _imageX0 || y0 < _imageY0 ||
147 x1 >= _imageX0 + mimage.getWidth() || y1 >= _imageY0 + mimage.getHeight()) {
149 (boost::format("Footprint %d,%d--%d,%d doesn't fit in image %d,%d--%d,%d")
150 % x0 % y0 % x1 % y1
151 % _imageX0 % _imageY0
152 % (_imageX0 + mimage.getWidth() - 1) % (_imageY0 + mimage.getHeight() - 1)
153 ).str());
154 }
155 }
156
158 void operator()(geom::Point2I const & pos, typename MaskedImageT::Image::Pixel const & ival) {
159 double x = static_cast<double>(pos.getX());
160 double y = static_cast<double>(pos.getY());
161 double const dx = x - _xcen;
162 double const dy = y - _ycen;
163 double const du = dx*_cosTheta + dy*_sinTheta;
164 double const dv = -dx*_sinTheta + dy*_cosTheta;
165
166 double r = ::hypot(du, dv*_ab); // ellipsoidal radius
167#if 1
168 if (::hypot(dx, dy) < 0.5) { // within a pixel of the centre
169 /*
170 * We gain significant precision for flattened Gaussians by treating the central pixel specially
171 *
172 * If the object's centered in the pixel (and has constant surface brightness) we have <r> == eR;
173 * if it's at the corner <r> = 2*eR; we interpolate between these exact results linearily in the
174 * displacement. And then add in quadrature which is also a bit dubious
175 *
176 * We could avoid all these issues by estimating <r> using the same trick as we use for
177 * the sinc fluxes; it's not clear that it's worth it.
178 */
179
180 double const eR = 0.38259771140356325; // <r> for a single square pixel, about the centre
181 r = ::hypot(r, eR*(1 + ::hypot(dx, dy)/geom::ROOT2));
182 }
183#endif
184
185 _sum += ival;
186 _sumR += r*ival;
187#if 0
188 typename MaskedImageT::Variance::Pixel vval = iloc.variance(0, 0);
189 _sumVar += vval;
190 _sumRVar += r*r*vval;
191#endif
192 }
193
195 double getIr() const { return _sumR/_sum; }
196
197#if 0
199// double getIrVar() const { return _sumRVar/_sum - getIr()*getIr(); } // Wrong?
200 double getIrVar() const { return _sumRVar/(_sum*_sum) + _sumVar*_sumR*_sumR/::pow(_sum, 4); }
201#endif
202
204 bool getGood() const { return _sum > 0 && _sumR > 0; }
205
206private:
207 double const _xcen; // center of object
208 double const _ycen; // center of object
209 double const _ab; // axis ratio
210 double const _cosTheta, _sinTheta; // {cos,sin}(angle from x-axis)
211 double _sum; // sum of I
212 double _sumR; // sum of R*I
213#if 0
214 double _sumVar; // sum of Var(I)
215 double _sumRVar; // sum of R*R*Var(I)
216#endif
217 int const _imageX0, _imageY0; // origin of image we're measuring
218
219};
220} // end anonymous namespace
221
223 afw::geom::ellipses::Axes const& shape,
224 geom::LinearTransform const& transformation,
225 double const radius
226 )
227{
228 afw::geom::ellipses::Axes axes(shape);
229 axes.scale(radius/axes.getDeterminantRadius());
230 return axes.transform(transformation);
231}
232
233template<typename ImageT>
235 ImageT const& image,
237 geom::Point2D const& center,
238 KronFluxControl const& ctrl
239 )
240{
241 //
242 // We might smooth the image because this is what SExtractor and Pan-STARRS do. But I don't see much gain
243 //
244 double const sigma = ctrl.smoothingSigma; // Gaussian width of smoothing sigma to apply
245 bool const smoothImage = sigma > 0;
246 int kSize = smoothImage ? 2*int(2*sigma) + 1 : 1;
248 afw::math::SeparableKernel kernel(kSize, kSize, gaussFunc, gaussFunc);
249 bool const doNormalize = true, doCopyEdge = false;
250 afw::math::ConvolutionControl convCtrl(doNormalize, doCopyEdge);
251 double radius0 = axes.getDeterminantRadius();
253 float radiusForRadius = std::nanf("");
254 for (int i = 0; i < ctrl.nIterForRadius; ++i) {
255 axes.scale(ctrl.nSigmaForRadius);
256 radiusForRadius = axes.getDeterminantRadius(); // radius we used to estimate R_K
257 //
258 // Build an elliptical Footprint of the proper size
259 //
261 afw::geom::ellipses::Ellipse(axes, center)));
262 geom::Box2I bbox = !smoothImage ?
263 foot.getBBox() :
264 kernel.growBBox(foot.getBBox()); // the smallest bbox needed to convolve with Kernel
265 bbox.clip(image.getBBox());
266 ImageT subImage(image, bbox, afw::image::PARENT, smoothImage);
267 if (smoothImage) {
268 afw::math::convolve(subImage, ImageT(image, bbox, afw::image::PARENT, false), kernel, convCtrl);
269 }
270 //
271 // Find the desired first moment of the elliptical radius, which corresponds to the major axis.
272 //
273 FootprintFindMoment<ImageT, afw::detection::Psf::Image> iRFunctor(
274 subImage, center, axes.getA()/axes.getB(), axes.getTheta()
275 );
276
277 try {
278 foot.getSpans()->applyFunctor(
279 iRFunctor, *(subImage.getImage()));
281 if (i == 0) {
282 LSST_EXCEPT_ADD(e, "Determining Kron aperture");
283 }
284 break; // use the radius we have
285 }
286
287 if (!iRFunctor.getGood()) {
288 throw LSST_EXCEPT(BadKronException, "Bad integral defining Kron radius");
289 }
290
291 radius = iRFunctor.getIr()*sqrt(axes.getB()/axes.getA());
292 if (radius <= radius0) {
293 break;
294 }
295 radius0 = radius;
296
297 axes.scale(radius/axes.getDeterminantRadius()); // set axes to our current estimate of R_K
298
299 if (radius > ctrl.maxRadius) {
300 throw LSST_EXCEPT(BadKronException, "Kron radius too large");
301 }
302
303 iRFunctor.reset();
304 }
305
306 return std::make_shared<KronAperture>(center, axes, radiusForRadius);
307}
308
309// Photometer an image with a particular aperture
310template<typename ImageT>
312 ImageT const& image, // Image to measure
313 afw::geom::ellipses::Ellipse const& aperture, // Aperture in which to measure
314 double const maxSincRadius // largest radius that we use sinc apertures to measure
315 )
316{
317 afw::geom::ellipses::Axes const& axes = aperture.getCore();
318 if (axes.getB() > maxSincRadius) {
319 FootprintFlux<ImageT> fluxFunctor;
320 auto spans = afw::geom::SpanSet::fromShape(aperture);
321 spans->applyFunctor(
322 fluxFunctor, *(image.getImage()), *(image.getVariance()));
323 return std::make_pair(fluxFunctor.getSum(), ::sqrt(fluxFunctor.getSumVar()));
324 }
325 try {
326 base::ApertureFluxResult fluxResult = base::ApertureFluxAlgorithm::computeSincFlux<float>(image, aperture);
327 return std::make_pair(fluxResult.instFlux, fluxResult.instFluxErr);
328 } catch(pex::exceptions::LengthError &e) {
329 LSST_EXCEPT_ADD(e, (boost::format("Measuring Kron flux for object at (%.3f, %.3f);"
330 " aperture radius %g,%g theta %g")
331 % aperture.getCenter().getX() % aperture.getCenter().getY()
332 % axes.getA() % axes.getB() % geom::radToDeg(axes.getTheta())).str());
333 throw e;
334 }
335}
336
337
339 std::shared_ptr<afw::detection::Psf const> const& psf, // PSF to measure
340 geom::Point2D const& center, // Centroid of source on parent image
341 double smoothingSigma=0.0 // Gaussian sigma of smoothing applied
342 )
343{
344 assert(psf);
345 double const radius = psf->computeShape(center).getDeterminantRadius();
346 // For a Gaussian N(0, sigma^2), the Kron radius is sqrt(pi/2)*sigma
347 return ::sqrt(geom::PI/2)*::hypot(radius, std::max(0.0, smoothingSigma));
348}
349
350template<typename ImageT>
352 ImageT const& image,
353 double const nRadiusForFlux,
354 double const maxSincRadius
355 ) const
356{
357 afw::geom::ellipses::Axes axes(getAxes()); // Copy of ellipse core, so we can scale
358 axes.scale(nRadiusForFlux);
359 afw::geom::ellipses::Ellipse const ellip(axes, getCenter());
360
361 return photometer(image, ellip, maxSincRadius);
362}
363
364/************************************************************************************************************/
365
372 KronFluxControl const & ctrl,
373 std::string const & name,
375 daf::base::PropertySet & metadata
376) : _name(name),
377 _ctrl(ctrl),
378 _fluxResultKey(
379 meas::base::FluxResultKey::addFields(schema, name, "flux from Kron Flux algorithm")
380 ),
381 _radiusKey(schema.addField<float>(name + "_radius", "Kron radius (sqrt(a*b))")),
382 _radiusForRadiusKey(schema.addField<float>(name + "_radius_for_radius",
383 "radius used to estimate <radius> (sqrt(a*b))")),
384 _psfRadiusKey(schema.addField<float>(name + "_psf_radius", "Radius of PSF")),
385 _centroidExtractor(schema, name, true)
386{
388 auto metadataName = name + "_nRadiusForflux";
389 boost::to_upper(metadataName);
390 metadata.add(metadataName, ctrl.nRadiusForFlux);
391}
392
394 afw::table::SourceRecord & measRecord,
396) const {
397 _flagHandler.handleFailure(measRecord, error);
398}
399
400void KronFluxAlgorithm::_applyAperture(
402 afw::image::Exposure<float> const& exposure,
403 KronAperture const& aperture
404 ) const
405{
406 double const rad = aperture.getAxes().getDeterminantRadius();
408 throw LSST_EXCEPT(
412 );
413 }
414
416 try {
417 result = aperture.measureFlux(exposure.getMaskedImage(), _ctrl.nRadiusForFlux, _ctrl.maxSincRadius);
418 } catch (pex::exceptions::LengthError const& e) {
419 // We hit the edge of the image; there's no reasonable fallback or recovery
420 throw LSST_EXCEPT(
422 EDGE.doc,
424 );
426 throw LSST_EXCEPT(
428 EDGE.doc,
430 );
431 }
432
433 // set the results in the source object
434 meas::base::FluxResult fluxResult;
435 fluxResult.instFlux = result.first;
436 fluxResult.instFluxErr = result.second;
437 source.set(_fluxResultKey, fluxResult);
438 source.set(_radiusKey, aperture.getAxes().getDeterminantRadius());
439 //
440 // REMINDER: In the old code, the psfFactor is calculated using getPsfFactor,
441 // and the values set for _fluxCorrectionKeys. See old meas_algorithms version.
442}
443
444void KronFluxAlgorithm::_applyForced(
445 afw::table::SourceRecord & source,
446 afw::image::Exposure<float> const & exposure,
447 geom::Point2D const & center,
448 afw::table::SourceRecord const & reference,
449 geom::AffineTransform const & refToMeas
450 ) const
451{
452 float const radius = reference.get(reference.getSchema().find<float>(_ctrl.refRadiusName).key);
453 KronAperture const aperture(reference, refToMeas, radius);
454 _applyAperture(source, exposure, aperture);
455 if (exposure.getPsf()) {
456 source.set(_psfRadiusKey, calculatePsfKronRadius(exposure.getPsf(), center, _ctrl.smoothingSigma));
457 }
458}
459
462 afw::image::Exposure<float> const& exposure
463 ) const {
464 geom::Point2D center = _centroidExtractor(source, _flagHandler);
465
466 // Did we hit a condition that fundamentally prevented measuring the Kron flux?
467 // Such conditions include hitting the edge of the image and bad input shape, but not low signal-to-noise.
468 bool bad = false;
469
470 afw::image::MaskedImage<float> const& mimage = exposure.getMaskedImage();
471
472 double R_K_psf = -1;
473 if (exposure.getPsf()) {
474 R_K_psf = calculatePsfKronRadius(exposure.getPsf(), center, _ctrl.smoothingSigma);
475 }
476
477 //
478 // Get the shape of the desired aperture
479 //
481 if (!source.getShapeFlag()) {
482 axes = source.getShape();
483 } else {
484 bad = true;
485 if (!exposure.getPsf()) {
486 throw LSST_EXCEPT(
490 );
491 }
492 axes = exposure.getPsf()->computeShape(exposure.getPsf()->getAveragePosition());
493 _flagHandler.setValue(source, BAD_SHAPE.number, true);
494 }
495 if (_ctrl.useFootprintRadius) {
496 afw::geom::ellipses::Axes footprintAxes(source.getFootprint()->getShape());
497 // if the Footprint's a disk of radius R we want footRadius == R.
498 // As <r^2> = R^2/2 for a disk, we need to scale up by sqrt(2)
499 footprintAxes.scale(::sqrt(2));
500
501 double radius0 = axes.getDeterminantRadius();
502 double const footRadius = footprintAxes.getDeterminantRadius();
503
504 if (footRadius > radius0*_ctrl.nSigmaForRadius) {
505 radius0 = footRadius/_ctrl.nSigmaForRadius; // we'll scale it up by nSigmaForRadius
506 axes.scale(radius0/axes.getDeterminantRadius());
507 }
508 }
509
511 if (_ctrl.fixed) {
512 aperture.reset(new KronAperture(source));
513 } else {
514 try {
515 aperture = KronAperture::determineRadius(mimage, axes, center, _ctrl);
517 // We hit the edge of the image: no reasonable fallback or recovery possible
518 throw LSST_EXCEPT(
520 EDGE.doc,
522 );
523 } catch (BadKronException& e) {
524 // Not setting bad=true because we only failed due to low S/N
525 aperture = _fallbackRadius(source, R_K_psf, e);
526 } catch(pex::exceptions::Exception& e) {
527 bad = true; // There's something fundamental keeping us from measuring the Kron aperture
528 aperture = _fallbackRadius(source, R_K_psf, e);
529 }
530 }
531
532 /*
533 * Estimate the minimum acceptable Kron radius as the Kron radius of the PSF or the
534 * provided minimum radius
535 */
536
537 // Enforce constraints on minimum radius
538 double rad = aperture->getAxes().getDeterminantRadius();
539 if (_ctrl.enforceMinimumRadius) {
540 double newRadius = rad;
541 if (_ctrl.minimumRadius > 0.0) {
542 if (rad < _ctrl.minimumRadius) {
543 newRadius = _ctrl.minimumRadius;
544 _flagHandler.setValue(source, USED_MINIMUM_RADIUS.number, true);
545 }
546 } else if (!exposure.getPsf()) {
547 throw LSST_EXCEPT(
551 );
552 } else if (rad < R_K_psf) {
553 newRadius = R_K_psf;
554 _flagHandler.setValue(source, USED_PSF_RADIUS.number, true);
555 }
556 if (newRadius != rad) {
557 aperture->getAxes().scale(newRadius/rad);
558 _flagHandler.setValue(source, SMALL_RADIUS.number, true); // guilty after all
559 }
560 }
561
562 _applyAperture(source, exposure, *aperture);
563 source.set(_radiusForRadiusKey, aperture->getRadiusForRadius());
564 source.set(_psfRadiusKey, R_K_psf);
565 if (bad) _flagHandler.setValue(source, FAILURE.number, true);
566}
567
569 afw::table::SourceRecord & measRecord,
570 afw::image::Exposure<float> const & exposure,
571 afw::table::SourceRecord const & refRecord,
572 afw::geom::SkyWcs const & refWcs
573 ) const {
574 geom::Point2D center = _centroidExtractor(measRecord, _flagHandler);
575 auto xytransform = afw::geom::makeWcsPairTransform(refWcs, *exposure.getWcs());
576 _applyForced(measRecord, exposure, center, refRecord,
577 linearizeTransform(*xytransform, refRecord.getCentroid())
578 );
579
580}
581
582
583std::shared_ptr<KronAperture> KronFluxAlgorithm::_fallbackRadius(afw::table::SourceRecord& source, double const R_K_psf,
585{
586 _flagHandler.setValue(source, BAD_RADIUS.number, true);
587 double newRadius;
588 if (_ctrl.minimumRadius > 0) {
589 newRadius = _ctrl.minimumRadius;
590 _flagHandler.setValue(source, USED_MINIMUM_RADIUS.number, true);
591 } else if (R_K_psf > 0) {
592 newRadius = R_K_psf;
593 _flagHandler.setValue(source, USED_PSF_RADIUS.number, true);
594 } else {
595 throw LSST_EXCEPT(
599 );
600 }
601 std::shared_ptr<KronAperture> aperture(new KronAperture(source));
602 aperture->getAxes().scale(newRadius/aperture->getAxes().getDeterminantRadius());
603 return aperture;
604}
605
606
607#define INSTANTIATE(TYPE) \
608template std::shared_ptr<KronAperture> KronAperture::determineRadius<afw::image::MaskedImage<TYPE> >( \
609 afw::image::MaskedImage<TYPE> const&, \
610 afw::geom::ellipses::Axes, \
611 geom::Point2D const&, \
612 KronFluxControl const& \
613 ); \
614template std::pair<double, double> KronAperture::measureFlux<afw::image::MaskedImage<TYPE> >( \
615 afw::image::MaskedImage<TYPE> const&, \
616 double const, \
617 double const \
618 ) const;
619
621
622}}}} // namespace lsst::meas::extensions::photometryKron
py::object result
Definition _schema.cc:429
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
#define INSTANTIATE(FROMSYS, TOSYS)
Definition Detector.cc:509
#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
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
afw::table::Key< double > sigma
int y
Definition SpanSet.cc:48
table::Schema schema
Definition python.h:134
Class to describe the properties of a detected object from an image.
Definition Footprint.h:63
lsst::geom::Box2I getBBox() const
Return the Footprint's bounding box.
Definition Footprint.h:208
std::shared_ptr< geom::SpanSet > getSpans() const
Return a shared pointer to the SpanSet.
Definition Footprint.h:115
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
Definition SkyWcs.h:117
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:688
An ellipse core for the semimajor/semiminor axis and position angle parametrization (a,...
Definition Axes.h:47
double const getTheta() const
Definition Axes.h:57
double const getA() const
Definition Axes.h:51
double const getB() const
Definition Axes.h:54
void scale(double factor)
Scale the size of the ellipse core by the given factor.
Definition BaseCore.cc:103
double getDeterminantRadius() const
Return the radius defined as the 4th root of the determinant of the quadrupole matrix.
Definition BaseCore.cc:117
Transformer transform(lsst::geom::LinearTransform const &transform)
Return the transform that maps the ellipse to the unit circle.
An ellipse defined by an arbitrary BaseCore and a center point.
Definition Ellipse.h:51
lsst::geom::Point2D const & getCenter() const
Return the center point.
Definition Ellipse.h:62
BaseCore const & getCore() const
Return the ellipse core.
Definition Ellipse.h:71
A class to contain the data, WCS, and other information needed to describe an image of the sky.
Definition Exposure.h:72
A class to manipulate images, masks, and variance as a single object.
Definition MaskedImage.h:74
Parameters to control convolution.
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition Kernel.h:860
Defines the fields and offsets for a table.
Definition Schema.h:51
Record class that contains measurements made on a single exposure.
Definition Source.h:78
CentroidSlotDefinition::MeasValue getCentroid() const
Get the value of the Centroid slot measurement.
Definition Source.h:569
Class for storing generic metadata.
Definition PropertySet.h:66
void add(std::string const &name, T const &value)
Append a single value to the vector of values for a property name (possibly hierarchical).
An affine coordinate transformation consisting of a linear transformation and an offset.
An integer coordinate rectangle.
Definition Box.h:55
A 2D linear coordinate transformation.
vector-type utility class to build a collection of FlagDefinitions
Definition FlagHandler.h:60
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
Handle an expected or unexpected Exception thrown by a measurement algorithm.
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.
void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const
Set the flag field corresponding to the given flag index.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition exceptions.h:48
std::pair< double, double > measureFlux(ImageT const &image, double const nRadiusForFlux, double const maxSincRadius) const
Photometer within the Kron Aperture on an image.
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.
static std::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.
static meas::base::FlagDefinition const BAD_RADIUS
static meas::base::FlagDefinition const USED_MINIMUM_RADIUS
static meas::base::FlagDefinition const FAILURE
static meas::base::FlagDefinition const SMALL_RADIUS
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.
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
static meas::base::FlagDefinition const BAD_SHAPE
static meas::base::FlagDefinitionList const & getFlagDefinitions()
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.
static meas::base::FlagDefinition const EDGE
static meas::base::FlagDefinition const NO_MINIMUM_RADIUS
static meas::base::FlagDefinition const NO_FALLBACK_RADIUS
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.
static meas::base::FlagDefinition const BAD_SHAPE_NO_PSF
static meas::base::FlagDefinition const USED_PSF_RADIUS
double smoothingSigma
"Smooth image with N(0, smoothingSigma^2) Gaussian while estimating R_K" ;
std::string refRadiusName
"Name of field specifying reference Kron radius for forced measurement" ;
int nIterForRadius
"Number of times to iterate when setting the Kron radius" ;
bool fixed
"if true, use existing shape and centroid measurements instead of fitting" ;
bool useFootprintRadius
"Use the Footprint size as part of initial estimate of Kron radius" ;
double maxRadius
"Maximum aperture radius in pixels; used to avoid excess memory consumption for faint objects" ;
double minimumRadius
"Minimum Kron radius (if == 0.0 use PSF's Kron radius) if enforceMinimumRadius. " "Also functions as ...
double maxSincRadius
"Largest aperture for which to use the slow, accurate, sinc aperture code" ;
double nRadiusForFlux
"Number of Kron radii for Kron flux" ;
bool enforceMinimumRadius
"If true check that the Kron radius exceeds some minimum" ;
double nSigmaForRadius
"Multiplier of rms size for aperture used to initially estimate the Kron radius" ;
Provides consistent interface for LSST exceptions.
Definition Exception.h:107
Reports attempts to exceed implementation-defined length limits for some classes.
Definition Runtime.h:76
Reports attempts to access elements outside a valid range of indices.
Definition Runtime.h:89
Reports errors that are due to events beyond the control of the program.
Definition Runtime.h:104
T make_pair(T... args)
T max(T... args)
const char * source()
Source function that allows astChannel to source from a Stream.
Definition Stream.h:224
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:146
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.
double constexpr ROOT2
Definition Angle.h:47
constexpr double radToDeg(double x) noexcept
Definition Angle.h:53
double constexpr PI
The ratio of a circle's circumference to diameter.
Definition Angle.h:40
std::pair< double, double > photometer(ImageT const &image, afw::geom::ellipses::Ellipse const &aperture, double const maxSincRadius)
double calculatePsfKronRadius(std::shared_ptr< afw::detection::Psf const > const &psf, geom::Point2D const &center, double smoothingSigma=0.0)
T nanf(T... args)
T quiet_NaN(T... args)
T reset(T... args)
A Result struct for running an aperture flux algorithm with a single radius.
meas::base::Flux instFlux
Measured instFlux in DN.
meas::base::FluxErrElement instFluxErr
Standard deviation of instFlux in DN.
Key< int > psf
Definition Exposure.cc:65