24 #include "ndarray/eigen.h" 36 namespace lsst {
namespace meas {
namespace base {
38 FlagDefinitionList flagDefinitions;
44 return flagDefinitions;
69 enum Method { ADAPTIVE_MOMENT,
79 double computeGaussianWidth(Method how=ADAPTIVE_MOMENT)
const;
80 double computeEffectiveArea()
const;
89 PsfAttributes::PsfAttributes(
102 PsfAttributes::PsfAttributes(
115 double PsfAttributes::computeEffectiveArea()
const {
119 for (
int iY = 0; iY != _psfImage->getHeight(); ++iY) {
123 sumsqr += (*ptr)*(*ptr);
126 return sum*sum/sumsqr;
150 if ((std::abs(fracShift[0]) >= 1) || (std::abs(fracShift[1]) >= 1)) {
152 os <<
"fracShift = " << fracShift <<
" too large; abs value must be < 1 in both axes";
157 if (fracShift[0] < 0) {
158 warpingKernelPtr->setCtrX(warpingKernelPtr->getCtrX() + 1);
160 if (fracShift[1] < 0) {
161 warpingKernelPtr->setCtrY(warpingKernelPtr->getCtrY() + 1);
165 warpingKernelPtr->getDimensions());
166 if (!maskedImage.
getBBox().contains(warpingOverlapBBox)) {
168 os <<
"Warping kernel extends off the edge" 169 <<
"; kernel bbox = " << warpingOverlapBBox
170 <<
"; exposure bbox = " << maskedImage.
getBBox();
173 warpingKernelPtr->setKernelParameters(
std::make_pair(fracShift[0], fracShift[1]));
174 KernelImageT warpingKernelImage(warpingKernelPtr->getDimensions());
175 warpingKernelPtr->computeImage(warpingKernelImage,
true);
176 typename KernelImageT::const_xy_locator
const warpingKernelLoc = warpingKernelImage.xy_at(0,0);
181 typename MaskedImageT::const_xy_locator
const mimageLoc = maskedImage.
xy_at(subimMin.getX(), subimMin.getY());
182 return afw::math::convolveAtAPoint<MaskedImageT, MaskedImageT>(
183 mimageLoc, warpingKernelLoc, warpingKernelPtr->getWidth(), warpingKernelPtr->getHeight());
191 FluxResultKey::addFields(schema, name,
"flux from PeakLikelihood Flux algorithm")
193 _centroidExtractor(schema, name)
224 os <<
"Center = " << center <<
" not in exposure bbox" << mimage.getBBox();
233 afw::geom::Point2I ctrPixParentInd(xCtrPixParentIndFrac.first, yCtrPixParentIndFrac.first);
240 PsfAttributes psfAttr(psfPtr, ctrPixParentInd);
241 double weight = psfAttr.computeEffectiveArea();
253 double flux = mimageCtrPix.image()*weight;
254 double var = mimageCtrPix.variance()*weight*weight;
257 measRecord.
set(_fluxResultKey, 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)
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.
geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
C++ control object for peak likelihood flux.
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...
std::shared_ptr< SeparableKernel > makeWarpingKernel(std::string name)
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.
Flux flux
Measured flux in DN.
A FunctorKey for FluxResult.
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,...)
std::string warpingKernelName
"Name of warping kernel (e.g. \"lanczos4") used to compute the peak" ;
std::shared_ptr< lsst::afw::detection::Psf > getPsf()
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< Image > computeImage(geom::Point2D position=makeNullPoint(), image::Color color=image::Color(), ImageOwnerEnum owner=COPY) const
afw::image::MaskedImage< T >::SinglePixel computeShiftedValue(afw::image::MaskedImage< T > const &maskedImage, std::string const &warpingKernelName, afw::geom::Point2D const &fracShift, afw::geom::Point2I const &parentInd)
Compute the value of one pixel of an image after a fractional pixel shift Since we only want the valu...
vector-type utility class to build a collection of FlagDefinitions
FluxErrElement fluxSigma
1-Sigma error (sqrt of variance) on flux in DN.
A reusable result struct for flux measurements.
xy_locator xy_at(int x, int y) const
static FlagDefinitionList const & getFlagDefinitions()