26 #include "boost/array.hpp"
27 #include "boost/algorithm/string/replace.hpp"
37 namespace lsst {
namespace meas {
namespace base {
41 static boost::array<double,10> defaultRadii = {{
42 3.0, 4.5, 6.0, 9.0, 12.0, 17.0, 25.0, 35.0, 50.0, 70.0
44 std::copy(defaultRadii.begin(), defaultRadii.end(),
radii.begin());
49 boost::array<FlagDefinition,ApertureFluxAlgorithm::N_FLAGS>
const & getFlagDefinitions() {
50 static boost::array<FlagDefinition,ApertureFluxAlgorithm::N_FLAGS> flagDefs = {{
51 {
"flag",
"flag set if aperture failed for any reason"},
52 {
"flag_apertureTruncated",
"flag set if aperture did not fit within the measurement image"},
53 {
"flag_sincCoeffsTruncated",
54 "flag set if the full sinc coefficient image for aperture %d did not "
55 "fit within the measurement image"}
63 std::string prefix = (
boost::format(
"%s_%.1f") % name % radius).str();
64 return boost::replace_all_copy(prefix,
".",
"_");
74 getFlagDefinitions().begin(),
75 getFlagDefinitions().begin() + (isSinc ? 3 : 2)
82 std::string
const &
name,
90 for (std::size_t i = 0; i < ctrl.
radii.size(); ++i) {
91 metadata.
add(name +
"_radii", ctrl.
radii[i]);
93 std::string doc = (
boost::format(
"flux within %f-pixel aperture") % ctrl.
radii[i]).str();
102 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
103 _keys[i].flags.handleFailure(measRecord, error);
112 record.
set(
_keys[index].fluxKey, result);
128 template <
typename T>
130 afw::geom::Box2I const & bbox,
131 afw::geom::ellipses::Ellipse const & ellipse,
138 ellipse.getCenter().getX(),
139 ellipse.getCenter().getY(),
142 if (!bbox.contains(cImage->getBBox())) {
156 cImage = boost::make_shared< afw::image::Image<T> >(*cImage, overlap);
163 template <
typename T>
173 result.flux = (subImage.getArray().template asEigen<Eigen::ArrayXpr>()
174 * cImage->getArray().template asEigen<Eigen::ArrayXpr>()).sum();
178 template <
typename T>
188 result.flux = (subImage.getImage()->getArray().template asEigen<Eigen::ArrayXpr>()
189 * cImage->getArray().template asEigen<Eigen::ArrayXpr>()).sum();
190 result.fluxSigma = std::sqrt(
191 (subImage.getVariance()->getArray().template asEigen<Eigen::ArrayXpr>().
template cast<T>()
192 * cImage->getArray().template asEigen<Eigen::ArrayXpr>().square()).
sum()
197 template <
typename T>
217 spanIter->getBeginX() - image.
getX0(),
218 spanIter->getY() - image.
getY0()
220 result.
flux += std::accumulate(pixIter, pixIter + spanIter->
getWidth(), 0.0);
225 template <
typename T>
246 spanIter->getBeginX() - image.
getX0(),
247 spanIter->getY() - image.
getY0()
250 spanIter->getBeginX() - image.
getX0(),
251 spanIter->getY() - image.
getY0()
253 result.
flux += std::accumulate(pixIter, pixIter + spanIter->
getWidth(), 0.0);
255 result.
fluxSigma += std::accumulate(varIter, varIter + spanIter->
getWidth(), 0.0);
261 template <
typename T>
272 template <
typename T>
282 #define INSTANTIATE(T) \
284 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \
285 afw::image::Image<T> const &, \
286 afw::geom::ellipses::Ellipse const &, \
290 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \
291 afw::image::MaskedImage<T> const &, \
292 afw::geom::ellipses::Ellipse const &, \
296 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \
297 afw::image::Image<T> const &, \
298 afw::geom::ellipses::Ellipse const &, \
302 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \
303 afw::image::MaskedImage<T> const &, \
304 afw::geom::ellipses::Ellipse const &, \
308 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \
309 afw::image::Image<T> const &, \
310 afw::geom::ellipses::Ellipse const &, \
314 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \
315 afw::image::MaskedImage<T> const &, \
316 afw::geom::ellipses::Ellipse const &, \
325 std::string
const &
name,
331 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
332 for (
auto flag = getFlagDefinitions().begin();
336 flag->name).str()).key);
350 std::vector<FluxResultKey> fluxKeys;
351 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
361 for (; inSrc != inputCatalog.
end() && outSrc != outputCatalog.
end(); ++inSrc, ++outSrc) {
362 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
363 FluxResult fluxResult = fluxKeys[i].get(*inSrc);
Defines the fields and offsets for a table.
void setFlag(ApertureFluxAlgorithm::FlagBits bit, bool value=true)
Set the flag value associated with the given bit.
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=NULL) 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.
Eigen matrix objects that present a view into an ndarray::Array.
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
A mapping between the keys of two Schemas, used to copy data between them.
std::vector< Keys > _keys
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
ApertureFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema, daf::base::PropertySet &metadata)
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.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
bool getFlag(ApertureFluxAlgorithm::FlagBits bit) const
Return the flag value associated with the given bit.
void copyResultToRecord(Result const &result, afw::table::SourceRecord &record, int index) const
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
An integer coordinate rectangle.
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's variance.
table::Key< table::Array< Kernel::Pixel > > image
Keys(afw::table::Schema &schema, std::string const &prefix, std::string const &doc, bool isSinc)
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
static Result computeFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
An ellipse defined by an arbitrary BaseCore and a center point.
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)
Iterator class for CatalogT.
Box2I const & getBBox() const
A class to manipulate images, masks, and variance as a single object.
static Result computeNaiveFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Flux flux
Measured flux in DN.
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
BaseCore const & getCore() const
Return the ellipse core.
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
A FunctorKey for FluxResult.
ImageT::Ptr offsetImage(ImageT const &image, float dx, float dy, std::string const &algorithmName="lanczos5", unsigned int buffer=0)
Return an image offset by (dx, dy) using the specified algorithm.
static MagResultKey addFields(afw::table::Schema &schema, std::string const &name)
An ellipse core for the semimajor/semiminor axis and position angle parametrization (a...
Class for storing generic metadata.
static Result computeSincFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
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.
std::vector< double > radii
"Radius (in pixels) of apertures." ;
void add(std::string const &name, T const &value)
FluxErrElement fluxSigma
1-Sigma error (sqrt of variance) on flux in DN.
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.
SafeCentroidExtractor _centroidExtractor
double getMagnitude(double const flux) const