27 #include "ndarray/eigen.h"
32 #include "lsst/afw/detection/FootprintArray.cc"
35 namespace lsst {
namespace meas {
namespace base {
40 static std::array<FlagDefinition,PsfFluxAlgorithm::N_FLAGS>
const flagDefs = {{
41 {
"flag",
"general failure flag"},
42 {
"flag_noGoodPixels",
"not enough non-rejected pixels in data to attempt the fit"},
43 {
"flag_edge",
"object was too close to the edge of the image to use the full PSF model"}
52 std::string
const &
name,
56 FluxResultKey::addFields(schema, name,
"flux derived from linear least-squares fit of PSF model")
58 _centroidExtractor(schema, name)
72 "PsfFlux algorithm requires a Psf with every exposure"
79 if (fitBBox != psfImage->getBBox()) {
104 ndarray::EigenView<PsfPixel,1,1,Eigen::ArrayXpr> model(
107 psfImage->getArray(),
111 ndarray::EigenView<float,1,1,Eigen::ArrayXpr> data(
118 ndarray::EigenView<VarPixel,1,1,Eigen::ArrayXpr> variance(
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 if (!std::isfinite(result.
flux) || !std::isfinite(result.
fluxSigma)) {
133 throw LSST_EXCEPT(PixelValueError,
"Invalid pixel value detected in image.");
144 std::string
const &
name,
150 mapper.
addMapping(mapper.getInputSchema().find<afw::table::Flag>(
name +
"_" + flag->name).key);
Defines the fields and offsets for a table.
void flattenArray(Footprint const &fp, ndarray::Array< T, N, C > const &src, ndarray::Array< U, N-1, D > const &dest, lsst::afw::geom::Point2I const &xy0=lsst::afw::geom::Point2I())
Flatten the first two dimensions of an array.
FluxResultKey _fluxResultKey
geom::Point2I getXY0() const
geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
FlagDefinition getDefinition(std::size_t i) const
table::Key< std::string > name
Key< T > addMapping(Key< T > const &inputKey, bool doReplace=false)
Add a new field to the output Schema that is a copy of a field in the input Schema.
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=NULL) const
afw::table::Schema schema
A mapping between the keys of two Schemas, used to copy data between them.
PixelT Pixel
A pixel in this ImageBase.
SafeCentroidExtractor _centroidExtractor
Flux flux
Measured flux in DN.
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's image.
std::array< FlagDefinition, BlendednessAlgorithm::N_FLAGS > const & getFlagDefinitions()
Exception to be thrown when a measurement algorithm experiences a known failure mode.
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=NULL) const
An integer coordinate rectangle.
FluxErrElement fluxSigma
1-Sigma error (sqrt of variance) on flux in DN.
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's variance.
MaskedImageT getMaskedImage()
Return the MaskedImage.
math::Kernel::Pixel Pixel
Pixel type of Image returned by computeImage.
MaskPtr getMask(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's mask.
A FunctorKey for FluxResult.
std::vector< std::string > badMaskPlanes
"Mask planes that indicate pixels that should be excluded from the fit" ;
PsfFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema)
boost::shared_ptr< lsst::afw::detection::Psf > getPsf()
Return the Exposure's Psf object.
#define LSST_EXCEPT(type,...)
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinition const *begin, FlagDefinition const *end)
lsst::afw::image::VariancePixel VarPixel
void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
Record class that contains measurements made on a single exposure.
void clip(Box2I const &other)
Shrink this to ensure that other.contains(*this).
A polymorphic base class for representing an image's Point Spread Function.
A C++ control class to handle PsfFluxAlgorithm's configuration.
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
A reusable result struct for flux measurements.