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]);
90 _keys[i].flags.handleFailure(measRecord, error);
96 record.
set(_keys[index].instFluxKey, 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>
151 (ndarray::asEigenArray(subImage.getArray()) * ndarray::asEigenArray(cImage->getArray())).sum();
155 template <
typename T>
163 result.instFlux = (ndarray::asEigenArray(subImage.getImage()->getArray()) *
164 ndarray::asEigenArray(cImage->getArray()))
167 std::sqrt((ndarray::asEigenArray(subImage.getVariance()->getArray()).
template cast<T>() *
168 ndarray::asEigenArray(cImage->getArray()).square())
173 template <
typename T>
185 spanIter != spanEnd; ++spanIter) {
187 image.
x_at(spanIter->getBeginX() - image.
getX0(), spanIter->getY() - image.
getY0());
193 template <
typename T>
207 spanIter != spanEnd; ++spanIter) {
209 spanIter->getBeginX() - image.
getX0(), spanIter->getY() - image.
getY0());
211 spanIter->getBeginX() - image.
getX0(), spanIter->getY() - image.
getY0());
220 template <
typename T>
229 template <
typename T>
237 #define INSTANTIATE(T) \ 238 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \ 239 afw::image::Image<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 240 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeFlux( \ 241 afw::image::MaskedImage<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 242 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \ 243 afw::image::Image<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 244 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeSincFlux( \ 245 afw::image::MaskedImage<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 246 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \ 247 afw::image::Image<T> const &, afw::geom::ellipses::Ellipse const &, Control const &); \ 248 template ApertureFluxAlgorithm::Result ApertureFluxAlgorithm::computeNaiveFlux( \ 249 afw::image::MaskedImage<T> const &, afw::geom::ellipses::Ellipse const &, Control const &) 261 flag == ApertureFluxAlgorithm::SINC_COEFFS_TRUNCATED) {
266 .
find<afw::table::Flag>(
289 for (; inSrc != inputCatalog.end() && outSrc != outputCatalog.
end(); ++inSrc, ++outSrc) {
291 FluxResult instFluxResult = instFluxKeys[i].get(*inSrc);
std::size_t size() const
return the current size (number of defined elements) of the collection
Defines the fields and offsets for a table.
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
lsst::geom::Point2D const & getCenter() const
Return the center point.
lsst::geom::Box2I const & getBBox() const
Return the bounding box of the pixel region.
static boost::shared_ptr< CoeffT const > get(afw::geom::ellipses::Axes const &outerEllipse, float const innerRadiusFactor=0.0)
Get the coefficients for an aperture.
A 2-dimensional celestial WCS that transform pixels to ICRS RA/Dec, using the LSST standard for pixel...
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.
#define CONST_PTR(...)
A shared pointer to a const object.
The photometric calibration of an exposure.
Schema const getInputSchema() const
Return the input schema (copy-on-write).
static FlagDefinitionList const & getFlagDefinitions()
A mapping between the keys of two Schemas, used to copy data between them.
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
double instFluxToMagnitude(double instFlux, lsst::geom::Point< double, 2 > const &point) const
Convert instFlux in ADU to AB magnitude.
BaseCore const & getCore() const
Return the ellipse core.
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
int getX0() const
Return the image's column-origin.
meas::base::FluxErrElement instFluxErr
Standard deviation of instFlux in DN.
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 _instFlux, _instFluxErr fields to a Schema, and return a FluxResultKey that points to t...
table::Key< table::Array< std::uint8_t > > wcs
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
Configuration object for multiple-aperture flux algorithms.
A pixelized region containing all pixels whose centers are within an Ellipse.
std::vector< Span >::const_iterator Iterator
Iterator type used by begin() and end().
SchemaItem< T > find(std::string const &name) const
Find a SchemaItem in the Schema by name.
static FlagDefinition const FAILURE
A base class for image defects.
static FlagDefinition const APERTURE_TRUNCATED
lsst::geom::Box2I getBBox(ImageOrigin origin=PARENT) const
int getX0() const
Return the image's column-origin.
static Result computeFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Compute the instFlux (and optionally, uncertanties) within an aperture using the algorithm determined...
iterator end()
Iterator access.
Iterator end() const
Iterator range over Spans whose pixels are within the Ellipse.
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)
Construct an appropriate prefix for table fields.
static FlagDefinition const SINC_COEFFS_TRUNCATED
Iterator class for CatalogT.
A class to manipulate images, masks, and variance as a single object.
lsst::geom::Box2D computeBBox() const
Return the bounding box of the ellipse.
static Result computeNaiveFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Compute the instFlux (and optionally, uncertanties) within an aperture using naive photometry...
Schema & editOutputSchema()
Return a reference to the output schema that allows it to be modified in place.
A FunctorKey for FluxResult.
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.
int getY0() const
Return the image's row-origin.
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...
An ellipse core for the semimajor/semiminor axis and position angle parametrization (a...
int getY0() const
Return the image's row-origin.
std::shared_ptr< ImageT > 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.
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
Class for storing generic metadata.
int getWidth() const
Return the number of columns in the image.
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
static Result computeSincFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
Compute the instFlux (and optionally, uncertanties) within an aperture using Sinc photometry...
x_iterator x_at(int x, int y) const
Return an x_iterator to the point (x, y) in the image.
void set(Key< T > const &key, U const &value)
Set value of a field for the given key.
int getWidth() const
Return the number of columns in the image.
Record class that contains measurements made on a single exposure.
meas::base::Flux instFlux
Measured instFlux in DN.
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.
std::string shiftKernel
"Warping kernel used to shift Sinc photometry coefficients to different center positions" ; ...
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
std::vector< double > radii
"Radius (in pixels) of apertures." ;
iterator begin()
Iterator access.
vector-type utility class to build a collection of FlagDefinitions
void add(std::string const &name, T const &value)
Append a single value to the vector of values for a property name (possibly hierarchical).
lsst::geom::Box2I getBBox(ImageOrigin const origin=PARENT) const
An integer coordinate rectangle.
A class to represent a 2-dimensional array of pixels.
Iterator begin() const
Iterator range over Spans whose pixels are within the Ellipse.
A reusable result struct for instFlux measurements.
A Result struct for running an aperture flux algorithm with a single radius.