LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
lsst::meas::base::ApertureFluxAlgorithm Class Referenceabstract

#include <ApertureFlux.h>

Inheritance diagram for lsst::meas::base::ApertureFluxAlgorithm:
lsst::meas::base::SimpleAlgorithm lsst::meas::base::SingleFrameAlgorithm lsst::meas::base::ForcedAlgorithm lsst::meas::base::BaseAlgorithm lsst::meas::base::BaseAlgorithm lsst::meas::base::CircularApertureFluxAlgorithm

Classes

struct  Keys
 

Public Types

enum  FlagBits { FAILURE =0, APERTURE_TRUNCATED, SINC_COEFFS_TRUNCATED, N_FLAGS }
 
typedef ApertureFluxControl Control
 Typedef to the control object associated with this algorithm, defined above. More...
 
typedef ApertureFluxResult Result
 Result object returned by static methods. More...
 

Public Member Functions

 ApertureFluxAlgorithm (Control const &ctrl, std::string const &name, afw::table::Schema &schema, daf::base::PropertySet &metadata)
 
virtual ~ApertureFluxAlgorithm ()
 
virtual void measure (afw::table::SourceRecord &record, afw::image::Exposure< float > const &exposure) const =0
 
virtual void fail (afw::table::SourceRecord &measRecord, MeasurementError *error=NULL) const
 
- Public Member Functions inherited from lsst::meas::base::SimpleAlgorithm
virtual void measureForced (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure, afw::table::SourceRecord const &refRecord, afw::image::Wcs const &refWcs) const
 
virtual void measureNForced (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure, afw::table::SourceCatalog const &refRecord, afw::image::Wcs const &refWcs) const
 
- Public Member Functions inherited from lsst::meas::base::SingleFrameAlgorithm
virtual void measureN (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure) const
 
- Public Member Functions inherited from lsst::meas::base::BaseAlgorithm
virtual ~BaseAlgorithm ()
 

Static Public Member Functions

static std::string makeFieldPrefix (std::string const &name, double radius)
 
template<typename T >
static Result computeSincFlux (afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
 
template<typename T >
static Result computeSincFlux (afw::image::MaskedImage< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
 
template<typename T >
static Result computeNaiveFlux (afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
 
template<typename T >
static Result computeNaiveFlux (afw::image::MaskedImage< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
 
template<typename T >
static Result computeFlux (afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
 
template<typename T >
static Result computeFlux (afw::image::MaskedImage< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
 

Protected Member Functions

void copyResultToRecord (Result const &result, afw::table::SourceRecord &record, int index) const
 
FlagHandler const & getFlagHandler (int index) const
 

Protected Attributes

Control const _ctrl
 
SafeCentroidExtractor _centroidExtractor
 

Private Attributes

std::vector< Keys_keys
 

Detailed Description

Base class for multiple-aperture photometry algorithms

ApertureFluxAlgorithm serves as an intermediate base class for all aperture fluxes, which it assumes have that capability of measuring multiple apertures (even if they are not always configured to do so).

Concrete implementations for single-aperture flux measurements are provided as static methods, as well as a consistent interface and control object for its derived classes. Currently, we only have one derived class, CircularApertureFluxAlgorithm, but in the future we anticipate adding more derived classes for e.g. elliptical apertures, or apertures that are circular in sky coordinates rather than pixel coordinates.

Definition at line 82 of file ApertureFlux.h.

Member Typedef Documentation

Typedef to the control object associated with this algorithm, defined above.

Definition at line 94 of file ApertureFlux.h.

Result object returned by static methods.

Definition at line 97 of file ApertureFlux.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

lsst::meas::base::ApertureFluxAlgorithm::ApertureFluxAlgorithm ( Control const &  ctrl,
std::string const &  name,
afw::table::Schema schema,
daf::base::PropertySet metadata 
)
explicit

Construct the algorithm and add its fields to the given Schema.

Definition at line 80 of file ApertureFlux.cc.

86  : _ctrl(ctrl),
88 {
89  _keys.reserve(ctrl.radii.size());
90  for (std::size_t i = 0; i < ctrl.radii.size(); ++i) {
91  metadata.add(name + "_radii", ctrl.radii[i]);
92  std::string prefix = ApertureFluxAlgorithm::makeFieldPrefix(name, ctrl.radii[i]);
93  std::string doc = (boost::format("flux within %f-pixel aperture") % ctrl.radii[i]).str();
94  _keys.push_back(Keys(schema, prefix, doc, ctrl.radii[i] <= ctrl.maxSincRadius));
95  }
96 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
afw::table::Schema schema
Definition: GaussianPsf.cc:41
static std::string makeFieldPrefix(std::string const &name, double radius)
Definition: ApertureFlux.cc:62
SafeCentroidExtractor _centroidExtractor
Definition: ApertureFlux.h:228
virtual lsst::meas::base::ApertureFluxAlgorithm::~ApertureFluxAlgorithm ( )
inlinevirtual

Definition at line 186 of file ApertureFlux.h.

186 {}

Member Function Documentation

template<typename T >
ApertureFluxAlgorithm::Result lsst::meas::base::ApertureFluxAlgorithm::computeFlux ( afw::image::Image< T > const &  image,
afw::geom::ellipses::Ellipse const &  ellipse,
Control const &  ctrl = Control() 
)
static

Compute the flux (and optionally, uncertanties) within an aperture using the algorithm determined by its size and the maxSincRadius control parameter.

This method delegates to computeSincFlux is the minor axis of the aperture is smaller than ctrl.maxSincRadius, and delegates to computeNaiveFlux otherwise.

Parameters
[in]imageImage or MaskedImage to be measured. If a MaskedImage is provided, uncertainties will be returned as well as fluxes.
[in]ellipseEllipse that defines the outer boundary of the aperture.
[in]ctrlControl object.

Definition at line 262 of file ApertureFlux.cc.

266  {
267  return (afw::geom::ellipses::Axes(ellipse.getCore()).getB() <= ctrl.maxSincRadius)
268  ? computeSincFlux(image, ellipse, ctrl)
269  : computeNaiveFlux(image, ellipse, ctrl);
270 }
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
static Result computeNaiveFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
static Result computeSincFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
template<typename T >
ApertureFluxAlgorithm::Result lsst::meas::base::ApertureFluxAlgorithm::computeFlux ( afw::image::MaskedImage< T > const &  image,
afw::geom::ellipses::Ellipse const &  ellipse,
Control const &  ctrl = Control() 
)
static

Compute the flux (and optionally, uncertanties) within an aperture using the algorithm determined by its size and the maxSincRadius control parameter.

This method delegates to computeSincFlux is the minor axis of the aperture is smaller than ctrl.maxSincRadius, and delegates to computeNaiveFlux otherwise.

Parameters
[in]imageImage or MaskedImage to be measured. If a MaskedImage is provided, uncertainties will be returned as well as fluxes.
[in]ellipseEllipse that defines the outer boundary of the aperture.
[in]ctrlControl object.

Definition at line 273 of file ApertureFlux.cc.

277  {
278  return (afw::geom::ellipses::Axes(ellipse.getCore()).getB() <= ctrl.maxSincRadius)
279  ? computeSincFlux(image, ellipse, ctrl)
280  : computeNaiveFlux(image, ellipse, ctrl);
281 }
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
static Result computeNaiveFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
static Result computeSincFlux(afw::image::Image< T > const &image, afw::geom::ellipses::Ellipse const &ellipse, Control const &ctrl=Control())
template<typename T >
ApertureFluxAlgorithm::Result lsst::meas::base::ApertureFluxAlgorithm::computeNaiveFlux ( afw::image::Image< T > const &  image,
afw::geom::ellipses::Ellipse const &  ellipse,
Control const &  ctrl = Control() 
)
static

Compute the flux (and optionally, uncertanties) within an aperture using naive photometry

The naive algorithm just counts the flux in pixels whose centers lie within the aperture, ignoring the effects of sub-pixel aperture boundaries.

Parameters
[in]imageImage or MaskedImage to be measured. If a MaskedImage is provided, uncertainties will be returned as well as fluxes.
[in]ellipseEllipse that defines the outer boundary of the aperture.

Definition at line 198 of file ApertureFlux.cc.

202  {
203  Result result;
204  afw::geom::ellipses::PixelRegion region(ellipse); // behaves mostly like a Footprint
205  if (!image.getBBox().contains(region.getBBox())) {
206  result.setFlag(APERTURE_TRUNCATED);
207  result.setFlag(FAILURE);
208  return result;
209  }
210  result.flux = 0;
211  for (
212  afw::geom::ellipses::PixelRegion::Iterator spanIter = region.begin(), spanEnd = region.end();
213  spanIter != spanEnd;
214  ++spanIter
215  ) {
216  typename afw::image::Image<T>::x_iterator pixIter = image.x_at(
217  spanIter->getBeginX() - image.getX0(),
218  spanIter->getY() - image.getY0()
219  );
220  result.flux += std::accumulate(pixIter, pixIter + spanIter->getWidth(), 0.0);
221  }
222  return result;
223 }
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
ApertureFluxResult Result
Result object returned by static methods.
Definition: ApertureFlux.h:97
template<typename T >
ApertureFluxAlgorithm::Result lsst::meas::base::ApertureFluxAlgorithm::computeNaiveFlux ( afw::image::MaskedImage< T > const &  image,
afw::geom::ellipses::Ellipse const &  ellipse,
Control const &  ctrl = Control() 
)
static

Compute the flux (and optionally, uncertanties) within an aperture using naive photometry

The naive algorithm just counts the flux in pixels whose centers lie within the aperture, ignoring the effects of sub-pixel aperture boundaries.

Parameters
[in]imageImage or MaskedImage to be measured. If a MaskedImage is provided, uncertainties will be returned as well as fluxes.
[in]ellipseEllipse that defines the outer boundary of the aperture.

Definition at line 226 of file ApertureFlux.cc.

230  {
231  Result result;
232  afw::geom::ellipses::PixelRegion region(ellipse); // behaves mostly like a Footprint
233  if (!image.getBBox().contains(region.getBBox())) {
234  result.setFlag(APERTURE_TRUNCATED);
235  result.setFlag(FAILURE);
236  return result;
237  }
238  result.flux = 0.0;
239  result.fluxSigma = 0.0;
240  for (
241  afw::geom::ellipses::PixelRegion::Iterator spanIter = region.begin(), spanEnd = region.end();
242  spanIter != spanEnd;
243  ++spanIter
244  ) {
245  typename afw::image::MaskedImage<T>::Image::x_iterator pixIter = image.getImage()->x_at(
246  spanIter->getBeginX() - image.getX0(),
247  spanIter->getY() - image.getY0()
248  );
249  typename afw::image::MaskedImage<T>::Variance::x_iterator varIter = image.getVariance()->x_at(
250  spanIter->getBeginX() - image.getX0(),
251  spanIter->getY() - image.getY0()
252  );
253  result.flux += std::accumulate(pixIter, pixIter + spanIter->getWidth(), 0.0);
254  // we use this to hold variance as we accumulate...
255  result.fluxSigma += std::accumulate(varIter, varIter + spanIter->getWidth(), 0.0);
256  }
257  result.fluxSigma = std::sqrt(result.fluxSigma); // ...and switch back to sigma here.
258  return result;
259 }
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
Definition: Image.h:151
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
ApertureFluxResult Result
Result object returned by static methods.
Definition: ApertureFlux.h:97
template<typename T >
ApertureFluxAlgorithm::Result lsst::meas::base::ApertureFluxAlgorithm::computeSincFlux ( afw::image::Image< T > const &  image,
afw::geom::ellipses::Ellipse const &  ellipse,
Control const &  ctrl = Control() 
)
static

Compute the flux (and optionally, uncertanties) within an aperture using Sinc photometry

The Sinc algorithm is slower than a naive aperture, but more accurate, in that it correctly handles sub-pixel aperture boundaries on well-sampled data. This improved accuracy is most important for smaller apertures.

Parameters
[in]imageImage or MaskedImage to be measured. If a MaskedImage is provided, uncertainties will be returned as well as fluxes.
[in]ellipseEllipse that defines the outer boundary of the aperture.
[in]ctrlControl object.

Definition at line 164 of file ApertureFlux.cc.

168  {
169  Result result;
170  CONST_PTR(afw::image::Image<T>) cImage = getSincCoeffs<T>(image.getBBox(), ellipse, result, ctrl);
171  if (result.getFlag(APERTURE_TRUNCATED)) return result;
172  afw::image::Image<T> subImage(image, cImage->getBBox());
173  result.flux = (subImage.getArray().template asEigen<Eigen::ArrayXpr>()
174  * cImage->getArray().template asEigen<Eigen::ArrayXpr>()).sum();
175  return result;
176 }
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
Definition: operators.h:1250
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
#define CONST_PTR(...)
Definition: base.h:47
ApertureFluxResult Result
Result object returned by static methods.
Definition: ApertureFlux.h:97
template<typename T >
ApertureFluxAlgorithm::Result lsst::meas::base::ApertureFluxAlgorithm::computeSincFlux ( afw::image::MaskedImage< T > const &  image,
afw::geom::ellipses::Ellipse const &  ellipse,
Control const &  ctrl = Control() 
)
static

Compute the flux (and optionally, uncertanties) within an aperture using Sinc photometry

The Sinc algorithm is slower than a naive aperture, but more accurate, in that it correctly handles sub-pixel aperture boundaries on well-sampled data. This improved accuracy is most important for smaller apertures.

Parameters
[in]imageImage or MaskedImage to be measured. If a MaskedImage is provided, uncertainties will be returned as well as fluxes.
[in]ellipseEllipse that defines the outer boundary of the aperture.
[in]ctrlControl object.

Definition at line 179 of file ApertureFlux.cc.

183  {
184  Result result;
185  CONST_PTR(afw::image::Image<T>) cImage = getSincCoeffs<T>(image.getBBox(), ellipse, result, ctrl);
186  if (result.getFlag(APERTURE_TRUNCATED)) return result;
187  afw::image::MaskedImage<T> subImage(image, cImage->getBBox(afw::image::PARENT), afw::image::PARENT);
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()
193  );
194  return result;
195 }
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
Definition: operators.h:1250
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
#define CONST_PTR(...)
Definition: base.h:47
ApertureFluxResult Result
Result object returned by static methods.
Definition: ApertureFlux.h:97
void lsst::meas::base::ApertureFluxAlgorithm::copyResultToRecord ( Result const &  result,
afw::table::SourceRecord record,
int  index 
) const
protected

Definition at line 107 of file ApertureFlux.cc.

111  {
112  record.set(_keys[index].fluxKey, result);
113  if (result.getFlag(FAILURE)) {
114  _keys[index].flags.setValue(record, FAILURE, true);
115  }
116  if (result.getFlag(APERTURE_TRUNCATED)) {
117  _keys[index].flags.setValue(record, APERTURE_TRUNCATED, true);
118  }
119  if (result.getFlag(SINC_COEFFS_TRUNCATED)) {
120  _keys[index].flags.setValue(record, SINC_COEFFS_TRUNCATED, true);
121  }
122 }
void lsst::meas::base::ApertureFluxAlgorithm::fail ( afw::table::SourceRecord measRecord,
MeasurementError error = NULL 
) const
virtual

Handle an exception thrown by the current algorithm by setting flags in the given record.

fail() is called by the measurement framework when an exception is allowed to propagate out of one the algorithm's measure() methods. It should generally set both a general failure flag for the algorithm as well as a specific flag indicating the error condition, if possible. To aid in this, if the exception was an instance of MeasurementError, it will be passed in, carrying information about what flag to set.

An algorithm can also to chose to set flags within its own measure() methods, and then just return, rather than throw an exception. However, fail() should be implemented even when all known failure modes do not throw exceptions, to ensure that unexpected exceptions thrown in lower-level code are properly handled.

Implements lsst::meas::base::BaseAlgorithm.

Definition at line 98 of file ApertureFlux.cc.

98  {
99  // This should only get called in the case of completely unexpected failures, so it's not terrible
100  // that we just set the general failure flags for all radii here instead of trying to figure out
101  // which ones we've already done. Any known failure modes are handled inside measure().
102  for (std::size_t i = 0; i < _ctrl.radii.size(); ++i) {
103  _keys[i].flags.handleFailure(measRecord, error);
104  }
105 }
def error
Definition: log.py:108
std::vector< double > radii
&quot;Radius (in pixels) of apertures.&quot; ;
Definition: ApertureFlux.h:50
FlagHandler const& lsst::meas::base::ApertureFluxAlgorithm::getFlagHandler ( int  index) const
inlineprotected

Definition at line 225 of file ApertureFlux.h.

225 { return _keys[index].flags; }
std::string lsst::meas::base::ApertureFluxAlgorithm::makeFieldPrefix ( std::string const &  name,
double  radius 
)
static

Construct an appropriate prefix for table fields.

Given a plugin name (e.g. base_CircularApertureFlux) and an aperture radius (e.g. 12 pixels) return an appropriate prefix for table fields to contain the measurement results (e.g. base_CircularApertureFlux_12_0). Table fields can then be created named <prefix>_flux, <prefix>_fluxErr, etc.

Parameters
[in]pluginNameName of measurement plugin.
[in]radiusAperture radius (pixels).
Returns
Table field name prefix.

Definition at line 62 of file ApertureFlux.cc.

62  {
63  std::string prefix = (boost::format("%s_%.1f") % name % radius).str();
64  return boost::replace_all_copy(prefix, ".", "_");
65 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
virtual void lsst::meas::base::ApertureFluxAlgorithm::measure ( afw::table::SourceRecord record,
afw::image::Exposure< float > const &  exposure 
) const
pure virtual

Measure the configured apertures on the given image.

Python plugins will delegate to this method.

Parameters
[in,out]recordRecord used to save outputs and retrieve positions.
[in]exposureImage to be measured.

Implements lsst::meas::base::SingleFrameAlgorithm.

Implemented in lsst::meas::base::CircularApertureFluxAlgorithm.

Member Data Documentation

SafeCentroidExtractor lsst::meas::base::ApertureFluxAlgorithm::_centroidExtractor
protected

Definition at line 228 of file ApertureFlux.h.

Control const lsst::meas::base::ApertureFluxAlgorithm::_ctrl
protected

Definition at line 227 of file ApertureFlux.h.

std::vector<Keys> lsst::meas::base::ApertureFluxAlgorithm::_keys
private

Definition at line 239 of file ApertureFlux.h.


The documentation for this class was generated from the following files: