28 #include "ndarray/eigen.h" 36 namespace lsst {
namespace meas {
namespace base {
38 FlagDefinitionList flagDefinitions;
42 FlagDefinition
const PsfFluxAlgorithm::NO_GOOD_PIXELS = flagDefinitions.add(
"flag_noGoodPixels",
"not enough non-rejected pixels in data to attempt the fit");
43 FlagDefinition
const PsfFluxAlgorithm::EDGE = flagDefinitions.add(
"flag_edge",
"object was too close to the edge of the image to use the full PSF model");
46 return flagDefinitions;
62 FluxResultKey::addFields(schema, name,
"flux derived from linear least-squares fit of PSF model")
64 _areaKey(schema.addField<float>(name +
"_area",
"effective area of PSF",
"pixel")),
65 _centroidExtractor(schema, name)
81 "PsfFlux algorithm requires a Psf with every exposure" 88 if (fitBBox != psfImage->getBBox()) {
92 auto fitRegionSpans = std::make_shared<afw::geom::SpanSet>(fitBBox);
101 badBits |= exposure.
getMaskedImage().getMask()->getPlaneBitMask(*i);
103 fitRegion.setSpans(fitRegion.getSpans()->intersectNot(*exposure.
getMaskedImage().getMask(),
104 badBits)->clippedTo(exposure.
getMaskedImage().getMask()->getBBox()));
106 if (fitRegion.getArea() == 0) {
115 ndarray::EigenView<PsfPixel,1,1,Eigen::ArrayXpr> model(
116 fitRegion.getSpans()->flatten(psfImage->getArray(), psfImage->getXY0())
118 ndarray::EigenView<float,1,1,Eigen::ArrayXpr> data(
119 fitRegion.getSpans()->flatten(exposure.
getMaskedImage().getImage()->getArray(), exposure.
getXY0())
121 ndarray::EigenView<VarPixel,1,1,Eigen::ArrayXpr> variance(
122 fitRegion.getSpans()->flatten(exposure.
getMaskedImage().getVariance()->getArray(),
125 PsfPixel alpha = model.matrix().squaredNorm();
127 result.
flux = model.matrix().dot(data.matrix().cast<PsfPixel>()) / alpha;
130 result.
fluxSigma =
std::sqrt(model.square().matrix().dot(variance.matrix().cast<PsfPixel>()))
132 measRecord.
set(_areaKey, model.matrix().sum() / alpha);
136 measRecord.
set(_fluxResultKey, result);
152 if (flag == PsfFluxAlgorithm::FAILURE)
continue;
153 if (mapper.getInputSchema().getNames().count(
154 mapper.getInputSchema().join(
name, flag.
name)) == 0)
continue;
157 mapper.addMapping(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" ;
#define LOGL_ERROR(logger, message...)
static FlagDefinition const NO_GOOD_PIXELS
static FlagDefinitionList const & getFlagDefinitions()
geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
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...
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.
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.
geom::Point2I getXY0() const
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 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)
void clip(Box2I const &other)
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.