26 #include "boost/algorithm/string/replace.hpp"
28 #include "ndarray/eigen.h"
36 namespace lsst {
namespace meas {
namespace base {
40 static std::array<double,10> defaultRadii = {{
41 3.0, 4.5, 6.0, 9.0, 12.0, 17.0, 25.0, 35.0, 50.0, 70.0
43 std::copy(defaultRadii.begin(), defaultRadii.end(),
radii.begin());
47 static std::array<FlagDefinition,ApertureFluxAlgorithm::N_FLAGS> flagDefs = {{
48 {
"flag",
"general failure flag"},
49 {
"flag_apertureTruncated",
"aperture did not fit within measurement image"},
50 {
"flag_sincCoeffsTruncated",
"full sinc coefficient image did not fit within measurement image"}
56 std::string prefix = (
boost::format(
"%s_%.1f") % name % radius).str();
57 return boost::replace_all_copy(prefix,
".",
"_");
75 std::string
const &
name,
83 for (std::size_t i = 0; i < ctrl.
radii.size(); ++i) {
84 metadata.
add(name +
"_radii", ctrl.
radii[i]);
86 std::string doc = (
boost::format(
"flux within %f-pixel aperture") % ctrl.
radii[i]).str();
95 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
96 _keys[i].flags.handleFailure(measRecord, error);
105 record.
set(
_keys[index].fluxKey, result);
121 template <
typename T>
123 afw::geom::Box2I const & bbox,
124 afw::geom::ellipses::Ellipse const & ellipse,
131 ellipse.getCenter().getX(),
132 ellipse.getCenter().getY(),
135 if (!bbox.contains(cImage->getBBox())) {
149 cImage = std::make_shared< afw::image::Image<T> >(*cImage, overlap);
156 template <
typename T>
166 result.flux = (subImage.getArray().template asEigen<Eigen::ArrayXpr>()
167 * cImage->getArray().template asEigen<Eigen::ArrayXpr>()).sum();
171 template <
typename T>
181 result.flux = (subImage.getImage()->getArray().template asEigen<Eigen::ArrayXpr>()
182 * cImage->getArray().template asEigen<Eigen::ArrayXpr>()).sum();
183 result.fluxSigma = std::sqrt(
184 (subImage.getVariance()->getArray().template asEigen<Eigen::ArrayXpr>().
template cast<T>()
185 * cImage->getArray().template asEigen<Eigen::ArrayXpr>().square()).sum()
190 template <
typename T>
210 spanIter->getBeginX() - image.
getX0(),
211 spanIter->getY() - image.
getY0()
213 result.
flux += std::accumulate(pixIter, pixIter + spanIter->
getWidth(), 0.0);
218 template <
typename T>
239 spanIter->getBeginX() - image.
getX0(),
240 spanIter->getY() - image.
getY0()
243 spanIter->getBeginX() - image.
getX0(),
244 spanIter->getY() - image.
getY0()
246 result.
flux += std::accumulate(pixIter, pixIter + spanIter->
getWidth(), 0.0);
248 result.
fluxSigma += std::accumulate(varIter, varIter + spanIter->
getWidth(), 0.0);
254 template <
typename T>
265 template <
typename T>
275 #define INSTANTIATE(T) \
277 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \
278 afw::image::Image<T> const &, \
279 afw::geom::ellipses::Ellipse const &, \
283 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \
284 afw::image::MaskedImage<T> const &, \
285 afw::geom::ellipses::Ellipse const &, \
289 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \
290 afw::image::Image<T> const &, \
291 afw::geom::ellipses::Ellipse const &, \
295 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \
296 afw::image::MaskedImage<T> const &, \
297 afw::geom::ellipses::Ellipse const &, \
301 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \
302 afw::image::Image<T> const &, \
303 afw::geom::ellipses::Ellipse const &, \
307 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \
308 afw::image::MaskedImage<T> const &, \
309 afw::geom::ellipses::Ellipse const &, \
318 std::string
const &
name,
324 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
330 flag->name).str()).key);
344 std::vector<FluxResultKey> fluxKeys;
345 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
355 for (; inSrc != inputCatalog.
end() && outSrc != outputCatalog.
end(); ++inSrc, ++outSrc) {
356 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
357 FluxResult fluxResult = fluxKeys[i].get(*inSrc);
Defines the fields and offsets for a table.
static std::array< FlagDefinition, ApertureFluxAlgorithm::N_FLAGS > const & getFlagDefinitions()
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=NULL) const
ImageT::Ptr offsetImage(ImageT const &inImage, float dx, float dy, std::string const &algorithmName, unsigned int buffer)
Return an image offset by (dx, dy) using the specified algorithm.
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.
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
bool contains(Point2I const &point) const
Return true if the box contains the point.
Schema const getInputSchema() const
Return the input schema (copy-on-write).
A custom container class for records, based on std::vector.
afw::table::Schema schema
SafeCentroidExtractor _centroidExtractor
A mapping between the keys of two Schemas, used to copy data between them.
static Result computeSincFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
std::vector< double > radii
"Radius (in pixels) of apertures." ;
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
Flux flux
Measured flux in DN.
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's image.
Implementation of the WCS standard for a any projection.
std::array< FlagDefinition, BlendednessAlgorithm::N_FLAGS > const & getFlagDefinitions()
Exception to be thrown when a measurement algorithm experiences a known failure mode.
double maxSincRadius
"Maximum radius (in pixels) for which the sinc algorithm should be used instead of the " "faster naiv...
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.
table::Key< table::Array< Kernel::Pixel > > image
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
An ellipse defined by an arbitrary BaseCore and a center point.
bool getFlag(ApertureFluxAlgorithm::FlagBits bit) const
Return the flag value associated with the given bit.
Iterator class for CatalogT.
A class to manipulate images, masks, and variance as a single object.
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
Box2I const & getBBox() const
void copyResultToRecord(Result const &result, afw::table::SourceRecord &record, int index) const
A FunctorKey for FluxResult.
static MagResultKey addFields(afw::table::Schema &schema, std::string const &name)
BaseCore const & getCore() const
Return the ellipse core.
ApertureFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema, daf::base::PropertySet &metadata)
static std::string makeFieldPrefix(std::string const &name, double radius)
An ellipse core for the semimajor/semiminor axis and position angle parametrization (a...
void setFlag(ApertureFluxAlgorithm::FlagBits bit, bool value=true)
Set the flag value associated with the given bit.
Class for storing generic metadata.
std::vector< Keys > _keys
Keys(afw::table::Schema &schema, std::string const &prefix, std::string const &doc, bool isSinc)
int getWidth() const
Return the number of columns in the image.
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).
SchemaItem< T > find(std::string const &name) const
Find a SchemaItem in the Schema by name.
static Result computeNaiveFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
void add(std::string const &name, T const &value)
int getWidth() const
Return the number of columns in the image.
A class to represent a 2-dimensional array of pixels.
Schema getSchema() const
Return the schema associated with the catalog's table.
A reusable result struct for flux measurements.
static Result computeFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
double getMagnitude(double const flux) const