Determine the Kron Aperture from an image.
Determines the object Kron aperture, using the shape from source.getShape() (e.g. SDSS's adaptive moments)
240{
241
242
243
244 double const sigma = ctrl.smoothingSigma;
245 bool const smoothImage =
sigma > 0;
246 int kSize = smoothImage ? 2*
int(2*
sigma) + 1 : 1;
247 afw::math::GaussianFunction1<afw::math::Kernel::Pixel> gaussFunc(smoothImage ?
sigma : 100);
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();
254 for (int i = 0; i < ctrl.nIterForRadius; ++i) {
255 axes.scale(ctrl.nSigmaForRadius);
256 radiusForRadius = axes.getDeterminantRadius();
257
258
259
261 afw::geom::ellipses::Ellipse(axes, center)));
263 foot.getBBox() :
264 kernel.growBBox(foot.getBBox());
267 if (smoothImage) {
269 }
270
271
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) {
283 }
284 break;
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 }
296
297 axes.scale(radius/axes.getDeterminantRadius());
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}
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
afw::table::Key< double > sigma
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.
An integer coordinate rectangle.
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
Reports attempts to access elements outside a valid range of indices.
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.