24 #include "ndarray/eigen.h" 40 FlagDefinitionList flagDefinitions;
79 double computeGaussianWidth(Method how = ADAPTIVE_MOMENT)
const;
80 double computeEffectiveArea()
const;
100 PsfAttributes::PsfAttributes(
111 double PsfAttributes::computeEffectiveArea()
const {
114 for (
int iY = 0; iY != _psfImage->getHeight(); ++iY) {
118 sumsqr += (*ptr) * (*ptr);
121 return sum * sum / sumsqr;
133 template <
typename T>
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->setCtrX(warpingKernelPtr->getCtrX() + 1);
155 if (fracShift[1] < 0) {
156 warpingKernelPtr->setCtrY(warpingKernelPtr->getCtrY() + 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());
176 return afw::math::convolveAtAPoint<MaskedImageT, MaskedImageT>(
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);
212 os <<
"Center = " << center <<
" not in exposure bbox" << mimage.getBBox();
221 geom::Point2I ctrPixParentInd(xCtrPixParentIndFrac.first, yCtrPixParentIndFrac.first);
226 PsfAttributes psfAttr(psfPtr, ctrPixParentInd);
227 double weight = psfAttr.computeEffectiveArea();
235 geom::Point2D(xCtrPixParentIndFrac.second, yCtrPixParentIndFrac.second), ctrPixParentInd);
236 double instFlux = mimageCtrPix.image() * weight;
237 double var = mimageCtrPix.variance() * weight * weight;
240 measRecord.
set(_instFluxResultKey, result);
double indexToPosition(double ind)
int positionToIndex(double pos)
_view_t::x_iterator x_iterator
PeakLikelihoodFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
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...
void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const
Set the flag field corresponding to the given flag index.
meas::base::FluxErrElement instFluxErr
Standard deviation of instFlux in DN.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
std::shared_ptr< Image > computeImage(lsst::geom::Point2D position=makeNullPoint(), image::Color color=image::Color(), ImageOwnerEnum owner=COPY) const
C++ control object for peak likelihood instrument flux.
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
static FlagDefinition const FAILURE
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...
MaskedImageT getMaskedImage()
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
A FunctorKey for FluxResult.
std::unique_ptr< SchemaItem< U > > result
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.
#define LSST_EXCEPT(type,...)
bool contains(Box2I const &other) const noexcept
std::string warpingKernelName
"Name of warping kernel (e.g. \"lanczos4") used to compute the peak" ;
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
Handle an expected or unexpected Exception thrown by a measurement algorithm.
void set(Key< T > const &key, U const &value)
std::shared_ptr< lsst::afw::detection::Psf const > getPsf() const
meas::base::Flux instFlux
Measured instFlux in DN.
vector-type utility class to build a collection of FlagDefinitions
lsst::geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
A reusable result struct for instFlux measurements.
xy_locator xy_at(int x, int y) const
static FlagDefinitionList const & getFlagDefinitions()