28 #include "ndarray/eigen.h" 40 FlagDefinitionList flagDefinitions;
45 flagDefinitions.add(
"flag_noGoodPixels",
"not enough non-rejected pixels in data to attempt the fit");
47 "flag_edge",
"object was too close to the edge of the image to use the full PSF model");
57 "flux derived from linear least-squares fit of PSF model")),
58 _areaKey(schema.addField<float>(name +
"_area",
"effective area of PSF",
"pixel")),
59 _centroidExtractor(schema, name) {
71 geom::Point2D position = _centroidExtractor(measRecord, _flagHandler);
75 if (fitBBox != psfImage->getBBox()) {
80 auto fitRegionSpans = std::make_shared<afw::geom::SpanSet>(fitBBox);
86 badBits |= exposure.
getMaskedImage().getMask()->getPlaneBitMask(*i);
88 fitRegion.setSpans(fitRegion.getSpans()
92 if (fitRegion.getArea() == 0) {
98 auto modelNdArray = fitRegion.getSpans()->flatten(psfImage->getArray(), psfImage->getXY0());
99 auto dataNdArray = fitRegion.getSpans()->flatten(exposure.
getMaskedImage().getImage()->getArray(),
101 auto varianceNdArray = fitRegion.getSpans()->flatten(exposure.
getMaskedImage().getVariance()->getArray(),
103 auto model = ndarray::asEigenMatrix(modelNdArray);
104 auto data = ndarray::asEigenMatrix(dataNdArray);
105 auto variance = ndarray::asEigenMatrix(varianceNdArray);
106 PsfPixel alpha = model.squaredNorm();
108 result.
flux = model.dot(
data.cast<PsfPixel>()) / alpha;
112 measRecord.
set(_areaKey, model.sum() / alpha);
116 measRecord.
set(_fluxResultKey, result);
128 if (flag == PsfFluxAlgorithm::FAILURE)
continue;
129 if (
mapper.getInputSchema().getNames().count(
mapper.getInputSchema().join(
name, flag.
name)) == 0)
132 mapper.getInputSchema().find<afw::table::Flag>(
name +
"_" + flag.
name).key;
std::size_t size() const
return the current size (number of defined elements) of the collection
std::vector< std::string > badMaskPlanes
"Mask planes that indicate pixels that should be excluded from the fit" ;
static FlagDefinition const NO_GOOD_PIXELS
static FlagDefinitionList const & getFlagDefinitions()
Exception to be thrown when a measurement algorithm encounters a NaN or infinite pixel.
PsfFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema, std::string const &logName="")
static FlagDefinition const EDGE
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
lsst::geom::Point2I getXY0() const
#define LOGL_ERROR(logger, message...)
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.
lsst::geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
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...
Exception to be thrown when a measurement algorithm experiences a fatal error.
MaskedImageT getMaskedImage()
math::Kernel::Pixel Pixel
static FlagDefinition const FAILURE
std::string getLogName() const
Flux flux
Measured flux in DN.
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,...)
std::shared_ptr< lsst::afw::detection::Psf > getPsf()
void clip(Box2I const &other) noexcept
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)
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
vector-type utility class to build a collection of FlagDefinitions
FluxErrElement fluxSigma
1-Sigma error (sqrt of variance) on flux in DN.
A C++ control class to handle PsfFluxAlgorithm's configuration.
A reusable result struct for flux measurements.