26 #include "boost/array.hpp"
36 namespace lsst {
namespace meas {
namespace base {
40 static boost::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());
48 boost::array<FlagDefinition,ApertureFluxAlgorithm::N_FLAGS>
const & getFlagDefinitions() {
49 static boost::array<FlagDefinition,ApertureFluxAlgorithm::N_FLAGS> flagDefs = {{
50 {
"flag",
"flag set if aperture failed for any reason"},
51 {
"flag_apertureTruncated",
"flag set if aperture did not fit within the measurement image"},
52 {
"flag_sincCoeffsTruncated",
53 "flag set if the full sinc coefficient image for aperture %d did not "
54 "fit within the measurement image"}
68 getFlagDefinitions().begin(),
69 getFlagDefinitions().begin() + (isSinc ? 3 : 2)
76 std::string
const & name,
84 for (std::size_t i = 0; i < ctrl.
radii.size(); ++i) {
85 metadata.
add(name +
"_radii", ctrl.
radii[i]);
86 std::string prefix = (
boost::format(
"%s_%d") % name % i).str();
87 std::string doc = (
boost::format(
"flux within %f-pixel aperture") % ctrl.
radii[i]).str();
96 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
97 _keys[i].flags.handleFailure(measRecord, error);
106 record.
set(
_keys[index].fluxKey, result);
122 template <
typename T>
124 afw::geom::Box2I const & bbox,
125 afw::geom::ellipses::Ellipse const & ellipse,
132 ellipse.getCenter().getX(),
133 ellipse.getCenter().getY(),
136 if (!bbox.contains(cImage->getBBox())) {
150 cImage = boost::make_shared< afw::image::Image<T> >(*cImage, overlap);
157 template <
typename T>
167 result.flux = (subImage.getArray().template asEigen<Eigen::ArrayXpr>()
168 * cImage->getArray().template asEigen<Eigen::ArrayXpr>()).sum();
172 template <
typename T>
182 result.flux = (subImage.getImage()->getArray().template asEigen<Eigen::ArrayXpr>()
183 * cImage->getArray().template asEigen<Eigen::ArrayXpr>()).sum();
184 result.fluxSigma = std::sqrt(
185 (subImage.getVariance()->getArray().template asEigen<Eigen::ArrayXpr>().
template cast<T>()
186 * cImage->getArray().template asEigen<Eigen::ArrayXpr>().square()).
sum()
191 template <
typename T>
211 spanIter->getBeginX() - image.
getX0(),
212 spanIter->getY() - image.
getY0()
214 result.
flux += std::accumulate(pixIter, pixIter + spanIter->
getWidth(), 0.0);
219 template <
typename T>
240 spanIter->getBeginX() - image.
getX0(),
241 spanIter->getY() - image.
getY0()
244 spanIter->getBeginX() - image.
getX0(),
245 spanIter->getY() - image.
getY0()
247 result.
flux += std::accumulate(pixIter, pixIter + spanIter->
getWidth(), 0.0);
249 result.
fluxSigma += std::accumulate(varIter, varIter + spanIter->
getWidth(), 0.0);
255 template <
typename T>
266 template <
typename T>
276 #define INSTANTIATE(T) \
278 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \
279 afw::image::Image<T> const &, \
280 afw::geom::ellipses::Ellipse const &, \
284 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \
285 afw::image::MaskedImage<T> const &, \
286 afw::geom::ellipses::Ellipse const &, \
290 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \
291 afw::image::Image<T> const &, \
292 afw::geom::ellipses::Ellipse const &, \
296 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \
297 afw::image::MaskedImage<T> const &, \
298 afw::geom::ellipses::Ellipse const &, \
302 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \
303 afw::image::Image<T> const &, \
304 afw::geom::ellipses::Ellipse const &, \
308 ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \
309 afw::image::MaskedImage<T> const &, \
310 afw::geom::ellipses::Ellipse const &, \
319 std::string
const & name,
325 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
326 for (
auto flag = getFlagDefinitions().begin();
329 (
boost::format(
"%s_%d_%s") % name % i % flag->name).str()).key);
343 std::vector<FluxResultKey> fluxKeys;
344 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
349 for (; inSrc < inputCatalog.
end() && outSrc < outputCatalog.
end(); ++inSrc, ++outSrc) {
350 for (std::size_t i = 0; i <
_ctrl.
radii.size(); ++i) {
351 FluxResult fluxResult = fluxKeys[i].get(*inSrc);
double getMagnitude(double const flux) const
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.
int getWidth() const
Return the number of columns in the image.
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's image.
virtual void fail(afw::table::SourceRecord &measRecord, MeasurementError *error=NULL) const
void clip(Box2I const &other)
Shrink this to ensure that other.contains(*this).
Eigen matrix objects that present a view into an ndarray::Array.
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
A custom container class for records, based on std::vector.
A mapping between the keys of two Schemas, used to copy data between them.
std::vector< Keys > _keys
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
ApertureFluxAlgorithm(Control const &ctrl, std::string const &name, afw::table::Schema &schema, daf::base::PropertySet &metadata)
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.
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.
table::Key< table::Array< Kernel::Pixel > > image
Keys(afw::table::Schema &schema, std::string const &prefix, std::string const &doc, bool isSinc)
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's variance.
int getWidth() const
Return the number of columns in the image.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Schema getSchema() const
Return the schema associated with the catalog's table.
static Result computeFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
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...
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
Iterator class for CatalogT.
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())
SchemaItem< T > find(std::string const &name) const
Find a SchemaItem in the Schema by name.
Flux flux
Measured flux in DN.
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
void add(std::string const &name, T const &value)
bool contains(Point2I const &point) const
Return true if the box contains the point.
Box2I const & getBBox() const
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...
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Class for storing generic metadata.
static Result computeSincFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
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.
BaseCore const & getCore() const
Return the ellipse core.
std::vector< double > radii
"Radius (in pixels) of apertures." ;
FluxErrElement fluxSigma
1-Sigma error (sqrt of variance) on flux in DN.
Schema const getInputSchema() const
Return the input schema (copy-on-write).
A class to represent a 2-dimensional array of pixels.
A reusable result struct for flux measurements.
SafeCentroidExtractor _centroidExtractor