24#include "ndarray/eigen.h"
79 double computeGaussianWidth(Method how = ADAPTIVE_MOMENT)
const;
80 double computeEffectiveArea()
const;
100PsfAttributes::PsfAttributes(
105 _psfImage(psf->computeImage(
geom::PointD(cen))) {}
111double PsfAttributes::computeEffectiveArea()
const {
114 for (
int iY = 0; iY != _psfImage->getHeight(); ++iY) {
115 afw::image::Image<double>::x_iterator
end = _psfImage->row_end(iY);
116 for (afw::image::Image<double>::x_iterator ptr = _psfImage->row_begin(iY); ptr != end; ++ptr) {
118 sumsqr += (*ptr) * (*ptr);
121 return sum * sum / sumsqr;
145 if ((std::abs(fracShift[0]) >= 1) || (std::abs(fracShift[1]) >= 1)) {
147 os <<
"fracShift = " << fracShift <<
" too large; abs value must be < 1 in both axes";
152 if (fracShift[0] < 0) {
153 warpingKernelPtr->setCtr(warpingKernelPtr->getCtr() +
geom::Extent2I(1, 0));
155 if (fracShift[1] < 0) {
156 warpingKernelPtr->setCtr(warpingKernelPtr->getCtr() +
geom::Extent2I(0, 1));
159 warpingKernelPtr->getDimensions());
162 os <<
"Warping kernel extends off the edge"
163 <<
"; kernel bbox = " << warpingOverlapBBox <<
"; exposure bbox = " << maskedImage.
getBBox();
166 warpingKernelPtr->setKernelParameters(
std::make_pair(fracShift[0], fracShift[1]));
167 KernelImageT warpingKernelImage(warpingKernelPtr->getDimensions());
168 warpingKernelPtr->computeImage(warpingKernelImage,
true);
169 typename KernelImageT::const_xy_locator
const warpingKernelLoc = warpingKernelImage.xy_at(0, 0);
174 typename MaskedImageT::const_xy_locator
const mimageLoc =
175 maskedImage.
xy_at(subimMin.getX(), subimMin.getY());
177 mimageLoc, warpingKernelLoc, warpingKernelPtr->getWidth(), warpingKernelPtr->getHeight());
183 FluxResultKey::addFields(schema, name,
"instFlux from PeakLikelihood Flux algorithm")),
184 _centroidExtractor(schema, name) {
191 geom::Point2D center = _centroidExtractor(measRecord, _flagHandler);
194 MaskedImageT
const &mimage = exposure.getMaskedImage();
206 if (!exposure.hasPsf()) {
212 os <<
"Center = " << center <<
" not in exposure bbox" << mimage.getBBox();
221 geom::Point2I ctrPixParentInd(xCtrPixParentIndFrac.first + mimage.getX0(),
222 yCtrPixParentIndFrac.first + mimage.getY0());
227 PsfAttributes psfAttr(psfPtr, ctrPixParentInd);
228 double weight = psfAttr.computeEffectiveArea();
235 mimage, _ctrl.warpingKernelName,
236 geom::Point2D(xCtrPixParentIndFrac.second, yCtrPixParentIndFrac.second), ctrPixParentInd);
237 double instFlux = mimageCtrPix.image() * weight;
238 double var = mimageCtrPix.variance() * weight * weight;
239 result.instFlux = instFlux;
241 measRecord.
set(_instFluxResultKey, result);
242 _flagHandler.setValue(measRecord,
FAILURE.number,
false);
246 _flagHandler.handleFailure(measRecord, error);
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
A class to contain the data, WCS, and other information needed to describe an image of the sky.
MaskedImage< ImageT, MaskT, VarianceT > MaskedImageT
A class to represent a 2-dimensional array of pixels.
A class to manipulate images, masks, and variance as a single object.
lsst::geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
lsst::afw::image::pixel::SinglePixel< ImagePixelT, MaskPixelT, VariancePixelT > SinglePixel
A single Pixel of the same type as those in the MaskedImage.
xy_locator xy_at(int x, int y) const
Return an xy_locator at the point (x, y)
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Defines the fields and offsets for a table.
Record class that contains measurements made on a single exposure.
A floating-point coordinate rectangle geometry.
bool contains(Point2D const &point) const noexcept
Return true if the box contains the point.
An integer coordinate rectangle.
Point2I const getMin() const noexcept
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
vector-type utility class to build a collection of FlagDefinitions
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.
A FunctorKey for FluxResult.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
PeakLikelihoodFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
static FlagDefinitionList const & getFlagDefinitions()
PeakLikelihoodFluxControl Control
A typedef to the Control object for this algorithm, defined above.
static FlagDefinition const FAILURE
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=nullptr) const
Handle an exception thrown by the current algorithm by setting flags in the given record.
Reports invalid arguments.
Reports when the result of an operation cannot be represented by the destination type.
double indexToPosition(double ind)
Convert image index to image position.
int positionToIndex(double pos)
Convert image position to nearest integer index.
OutImageT::SinglePixel convolveAtAPoint(typename InImageT::const_xy_locator inImageLocator, typename lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel >::const_xy_locator kernelLocator, int kWidth, int kHeight)
Apply convolution kernel to an image at one point.
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
Return a warping kernel given its name.
Point< double, 2 > PointD
Point< double, 2 > Point2D
Extent< int, 2 > Extent2I
afw::image::MaskedImage< T >::SinglePixel computeShiftedValue(afw::image::MaskedImage< T > const &maskedImage, std::string const &warpingKernelName, geom::Point2D const &fracShift, geom::Point2I const &parentInd)
Compute the value of one pixel of an image after a fractional pixel shift Since we only want the valu...
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
A reusable result struct for instFlux measurements.