26 #include "boost/algorithm/string/replace.hpp" 28 #include "ndarray/eigen.h" 40 FlagDefinitionList flagDefinitions;
45 flagDefinitions.add(
"flag_apertureTruncated",
"aperture did not fit within measurement image");
47 "flag_sincCoeffsTruncated",
"full sinc coefficient image did not fit within measurement image");
53 static std::array<double, 10> defaultRadii = {{3.0, 4.5, 6.0, 9.0, 12.0, 17.0, 25.0, 35.0, 50.0, 70.0}};
59 return boost::replace_all_copy(prefix,
".",
"_");
75 : _ctrl(ctrl), _centroidExtractor(schema, name) {
78 metadata.
add(name +
"_radii", ctrl.
radii[i]);
80 std::string doc = (boost::format(
"flux within %f-pixel aperture") % ctrl.
radii[i]).str();
90 _keys[i].flags.handleFailure(measRecord, error);
96 record.
set(_keys[index].fluxKey, result);
112 template <
typename T>
122 if (!bbox.
contains(cImage->getBBox())) {
127 result.
setFlag(ApertureFluxAlgorithm::SINC_COEFFS_TRUNCATED.number);
133 result.
setFlag(ApertureFluxAlgorithm::APERTURE_TRUNCATED.number);
134 result.
setFlag(ApertureFluxAlgorithm::FAILURE.number);
136 cImage = std::make_shared<afw::image::Image<T> >(*cImage, overlap);
143 template <
typename T>
150 result.flux = (subImage.getArray().template asEigen<Eigen::ArrayXpr>() *
151 cImage->getArray().template asEigen<Eigen::ArrayXpr>())
156 template <
typename T>
164 result.flux = (subImage.getImage()->getArray().template asEigen<Eigen::ArrayXpr>() *
165 cImage->getArray().template asEigen<Eigen::ArrayXpr>())
168 (subImage.getVariance()->getArray().template asEigen<Eigen::ArrayXpr>().
template cast<T>() *
169 cImage->getArray().template asEigen<Eigen::ArrayXpr>().square())
174 template <
typename T>
186 spanIter != spanEnd; ++spanIter) {
188 image.
x_at(spanIter->getBeginX() - image.
getX0(), spanIter->getY() - image.
getY0());
194 template <
typename T>
208 spanIter != spanEnd; ++spanIter) {
210 spanIter->getBeginX() - image.
getX0(), spanIter->getY() - image.
getY0());
212 spanIter->getBeginX() - image.
getX0(), spanIter->getY() - image.
getY0());
221 template <
typename T>
230 template <
typename T>
238 #define INSTANTIATE(T) \ 239 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \ 240 afw::image::Image<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 241 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \ 242 afw::image::MaskedImage<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 243 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \ 244 afw::image::Image<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 245 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \ 246 afw::image::MaskedImage<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 247 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \ 248 afw::image::Image<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 249 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \ 250 afw::image::MaskedImage<T> const &, afw::geom::ellipses::Ellipse const &, Control const &) 262 flag == ApertureFluxAlgorithm::SINC_COEFFS_TRUNCATED) {
267 .
find<afw::table::Flag>(
268 (boost::format(
"%s_%s") %
293 for (; inSrc != inputCatalog.
end() && outSrc != outputCatalog.
end(); ++inSrc, ++outSrc) {
295 FluxResult fluxResult = fluxKeys[i].get(*inSrc);
std::size_t size() const
return the current size (number of defined elements) of the collection
VariancePtr getVariance() const
lsst::geom::Point2D const & getCenter() const
lsst::geom::Box2I const & getBBox() const
static boost::shared_ptr< CoeffT const > get(afw::geom::ellipses::Axes const &outerEllipse, float const innerRadiusFactor=0.0)
Get the coefficients for an aperture.
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...
bool getFlag(unsigned int index) const
Return the flag value associated with the given bit.
void setFlag(unsigned int index, bool value=true)
Set the flag value associated with the given bit.
Schema const getInputSchema() const
afw::table::Schema schema
static FlagDefinitionList const & getFlagDefinitions()
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
_view_t::x_iterator x_iterator
Temporarily replace negative fluxes with NaNs.
BaseCore const & getCore() const
ApertureFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema, daf::base::PropertySet &metadata)
Construct the algorithm and add its fields to the given Schema.
void copyResultToRecord(Result const &result, afw::table::SourceRecord &record, int index) const
Return the flag definitions which apply to aperture flux measurements.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
static FluxResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
Add a pair of _flux, _fluxSigma fields to a Schema, and return a FluxResultKey that points to them...
ImagePtr getImage() const
Configuration object for multiple-aperture flux algorithms.
SchemaItem< T > find(std::string const &name) const
static FlagDefinition const FAILURE
static FlagDefinition const APERTURE_TRUNCATED
lsst::geom::Box2I getBBox(ImageOrigin origin=PARENT) const
static Result computeFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Compute the flux (and optionally, uncertanties) within an aperture using the algorithm determined by ...
double maxSincRadius
"Maximum radius (in pixels) for which the sinc algorithm should be used instead of the " "faster naiv...
static std::string makeFieldPrefix(std::string const &name, double radius)
Construct an appropriate prefix for table fields.
static FlagDefinition const SINC_COEFFS_TRUNCATED
lsst::geom::Box2D computeBBox() const
static Result computeNaiveFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Compute the flux (and optionally, uncertanties) within an aperture using naive photometry.
Flux flux
Measured flux in DN.
Schema & editOutputSchema()
A FunctorKey for FluxResult.
std::unique_ptr< SchemaItem< U > > result
double getMagnitude(double const flux) 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.
static MagResultKey addFields(afw::table::Schema &schema, std::string const &name)
Add a pair of _mag, _magErr fields to a Schema, and return a MagResultKey that points to them...
bool contains(Point2I const &point) const
std::shared_ptr< ImageT > offsetImage(ImageT const &image, float dx, float dy, std::string const &algorithmName="lanczos5", unsigned int buffer=0)
Base::const_iterator const_iterator
static Result computeSincFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Compute the flux (and optionally, uncertanties) within an aperture using Sinc photometry.
x_iterator x_at(int x, int y) const
void set(Key< T > const &key, U const &value)
Key< T > addMapping(Key< T > const &inputKey, bool doReplace=false)
std::string shiftKernel
"Warping kernel used to shift Sinc photometry coefficients to different center positions" ; ...
std::vector< double > radii
"Radius (in pixels) of apertures." ;
vector-type utility class to build a collection of FlagDefinitions
void add(std::string const &name, T const &value)
FluxErrElement fluxSigma
1-Sigma error (sqrt of variance) on flux in DN.
void clip(Box2I const &other)
lsst::geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
A reusable result struct for flux measurements.
CatalogIterator< typename Internal::iterator > iterator
A Result struct for running an aperture flux algorithm with a single radius.