28#include "ndarray/eigen.h"
40FlagDefinitionList 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 schema,
name,
"instFlux derived from linear least-squares fit of PSF model")),
58 _areaKey(
schema.addField<float>(
name +
"_area",
"effective area of PSF",
"pixel")),
59 _chi2Key(
schema.addField<float>(
name +
"_chi2",
"chi2 of the fitted PSF")),
60 _npixelsKey(
schema.addField<int>(
name +
"_npixels",
61 "number of pixels that were included in the PSF fit",
"pixel")),
74 geom::Point2D position = _centroidExtractor(measRecord, _flagHandler);
78 if (fitBBox != psfImage->getBBox()) {
83 auto fitRegionSpans = std::make_shared<afw::geom::SpanSet>(fitBBox);
89 badBits |=
exposure.getMaskedImage().getMask()->getPlaneBitMask(*i);
92 ->intersectNot(*
exposure.getMaskedImage().getMask(), badBits)
93 ->clippedTo(
exposure.getMaskedImage().getMask()->getBBox()));
103 auto modelNdArray = fitRegion.
getSpans()->flatten(psfImage->getArray(), psfImage->getXY0());
104 auto dataNdArray = fitRegion.
getSpans()->flatten(
exposure.getMaskedImage().getImage()->getArray(),
106 auto varianceNdArray = fitRegion.
getSpans()->flatten(
exposure.getMaskedImage().getVariance()->getArray(),
108 auto model = ndarray::asEigenMatrix(modelNdArray);
109 auto data = ndarray::asEigenMatrix(dataNdArray);
110 auto variance = ndarray::asEigenMatrix(varianceNdArray);
111 PsfPixel alpha = model.squaredNorm();
113 result.instFlux = model.dot(
data.cast<PsfPixel>()) / alpha;
117 measRecord.
set(_areaKey, model.sum() / alpha);
118 measRecord.
set(_npixelsKey, fitRegion.
getSpans()->getArea());
122 measRecord.
set(_instFluxResultKey,
result);
123 auto chi2 = ((
data.cast<PsfPixel>() -
result.instFlux * model).array().square() /
126 measRecord.
set(_chi2Key, chi2);
139 if (
mapper.getInputSchema().getNames().count(
mapper.getInputSchema().join(
name, flag.
name)) == 0)
142 mapper.getInputSchema().find<afw::table::Flag>(
name +
"_" + flag.
name).key;
table::Key< std::string > name
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
LSST DM logging module built on log4cxx.
#define LOGL_ERROR(logger, message...)
Log a error-level message using a varargs/printf style interface.
math::Kernel::Pixel Pixel
Pixel type of Image returned by computeImage.
A class to contain the data, WCS, and other information needed to describe an image of the sky.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
A class used as a handle to a particular field in a table.
Defines the fields and offsets for a table.
A mapping between the keys of two Schemas, used to copy data between them.
Record class that contains measurements made on a single exposure.
An integer coordinate rectangle.
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
std::string getLogName() const
Exception to be thrown when a measurement algorithm experiences a fatal error.
vector-type utility class to build a collection of FlagDefinitions
std::size_t size() const
return the current size (number of defined elements) of the collection
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
Handle an expected or unexpected Exception thrown by a measurement algorithm.
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.
void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const
Set the flag field corresponding to the given flag index.
A FunctorKey for FluxResult.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Exception to be thrown when a measurement algorithm encounters a NaN or infinite pixel.
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
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.
static FlagDefinition const NO_GOOD_PIXELS
static FlagDefinition const EDGE
static FlagDefinitionList const & getFlagDefinitions()
PsfFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema, std::string const &logName="")
A C++ control class to handle PsfFluxAlgorithm's configuration.
std::vector< std::string > badMaskPlanes
"Mask planes that indicate pixels that should be excluded from the fit" ;
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.