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
Public Types | Public Member Functions | Private Attributes | List of all members
lsst::meas::base::PsfFluxAlgorithm Class Reference

A measurement algorithm that estimates flux using a linear least-squares fit with the Psf model. More...

#include <PsfFlux.h>

Inheritance diagram for lsst::meas::base::PsfFluxAlgorithm:
lsst::meas::base::SimpleAlgorithm lsst::meas::base::SingleFrameAlgorithm lsst::meas::base::ForcedAlgorithm lsst::meas::base::BaseAlgorithm lsst::meas::base::BaseAlgorithm

Public Types

enum  { FAILURE =FlagHandler::FAILURE, NO_GOOD_PIXELS, EDGE, N_FLAGS }
 
typedef PsfFluxControl Control
 

Public Member Functions

 PsfFluxAlgorithm (Control const &ctrl, std::string const &name, afw::table::Schema &schema)
 
virtual void measure (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
 
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 ()
 

Private Attributes

Control _ctrl
 
FluxResultKey _fluxResultKey
 
FlagHandler _flagHandler
 
SafeCentroidExtractor _centroidExtractor
 

Detailed Description

A measurement algorithm that estimates flux using a linear least-squares fit with the Psf model.

The PsfFlux algorithm is extremely simple: we do a least-squares fit of the Psf model (evaluated at a given position) to the data. For point sources, this provides the optimal flux measurement in the limit where the Psf model is correct. We do not use per-pixel weights in the fit, as this results in bright stars being fit with a different effective profile than faint stairs.

Definition at line 68 of file PsfFlux.h.

Member Typedef Documentation

A typedef to the Control object for this algorithm, defined above. The control object contains the configuration parameters for this algorithm.

Definition at line 80 of file PsfFlux.h.

Member Enumeration Documentation

anonymous enum

Constructor & Destructor Documentation

lsst::meas::base::PsfFluxAlgorithm::PsfFluxAlgorithm ( Control const &  ctrl,
std::string const &  name,
afw::table::Schema schema 
)

Definition at line 49 of file PsfFlux.cc.

53  : _ctrl(ctrl),
55  FluxResultKey::addFields(schema, name, "flux derived from linear least-squares fit of PSF model")
56  ),
58 {
60  getFlagDefinitions().begin(), getFlagDefinitions().end());
61 }
table::Key< std::string > name
Definition: ApCorrMap.cc:71
afw::table::Schema schema
Definition: GaussianPsf.cc:41
static FluxResultKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
SafeCentroidExtractor _centroidExtractor
Definition: PsfFlux.h:99
static FlagHandler addFields(afw::table::Schema &schema, std::string const &prefix, FlagDefinition const *begin, FlagDefinition const *end)
Definition: FlagHandler.cc:28

Member Function Documentation

void lsst::meas::base::PsfFluxAlgorithm::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 137 of file PsfFlux.cc.

137  {
138  _flagHandler.handleFailure(measRecord, error);
139 }
def error
Definition: log.py:108
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=NULL) const
Definition: FlagHandler.cc:59
void lsst::meas::base::PsfFluxAlgorithm::measure ( afw::table::SourceRecord measRecord,
afw::image::Exposure< float > const &  exposure 
) const
virtual

Called to measure a single child source in an image.

Before this method is called, all neighbors will be replaced with noise, using the outputs of the deblender. Outputs should be saved in the given SourceRecord, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

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

Definition at line 63 of file PsfFlux.cc.

66  {
67  PTR(afw::detection::Psf const) psf = exposure.getPsf();
68  if (!psf) {
69  throw LSST_EXCEPT(
70  FatalAlgorithmError,
71  "PsfFlux algorithm requires a Psf with every exposure"
72  );
73  }
74  afw::geom::Point2D position = _centroidExtractor(measRecord, _flagHandler);
75  PTR(afw::detection::Psf::Image) psfImage = psf->computeImage(position);
76  afw::geom::Box2I fitBBox = psfImage->getBBox();
77  fitBBox.clip(exposure.getBBox());
78  if (fitBBox != psfImage->getBBox()) {
79  _flagHandler.setValue(measRecord, FAILURE, true); // if we had a suspect flag, we'd set that instead
80  _flagHandler.setValue(measRecord, EDGE, true);
81  }
82  afw::detection::Footprint fitRegion(fitBBox);
83  if (!_ctrl.badMaskPlanes.empty()) {
84  afw::image::MaskPixel badBits = 0x0;
85  for (
86  std::vector<std::string>::const_iterator i = _ctrl.badMaskPlanes.begin();
87  i != _ctrl.badMaskPlanes.end();
88  ++i
89  ) {
90  badBits |= exposure.getMaskedImage().getMask()->getPlaneBitMask(*i);
91  }
92  fitRegion.intersectMask(*exposure.getMaskedImage().getMask(), badBits);
93  }
94  if (fitRegion.getArea() == 0) {
95  throw LSST_EXCEPT(
96  MeasurementError,
99  );
100  }
101  typedef afw::detection::Psf::Pixel PsfPixel;
105  fitRegion,
106  psfImage->getArray(),
107  psfImage->getXY0()
108  )
109  );
112  fitRegion,
113  exposure.getMaskedImage().getImage()->getArray(),
114  exposure.getXY0()
115  )
116  );
119  fitRegion,
120  exposure.getMaskedImage().getVariance()->getArray(),
121  exposure.getXY0()
122  )
123  );
124  PsfPixel alpha = model.matrix().squaredNorm();
125  FluxResult result;
126  result.flux = model.matrix().dot(data.matrix().cast<PsfPixel>()) / alpha;
127  // If we're not using per-pixel weights to compute the flux, we'll still want to compute the
128  // variance as if we had, so we'll apply the weights to the model vector now, and update alpha.
129  result.fluxSigma = std::sqrt(model.square().matrix().dot(variance.matrix().cast<PsfPixel>()))
130  / alpha;
131  if (!utils::isfinite(result.flux) || !utils::isfinite(result.fluxSigma)) {
132  throw LSST_EXCEPT(PixelValueError, "Invalid pixel value detected in image.");
133  }
134  measRecord.set(_fluxResultKey, result);
135 }
std::vector< std::string > badMaskPlanes
&quot;Mask planes that indicate pixels that should be excluded from the fit&quot; ;
Definition: PsfFlux.h:50
void flattenArray(Footprint const &fp, ndarray::Array< T, N, C > const &src, ndarray::Array< U, N-1, D > const &dest, lsst::afw::geom::Point2I const &xy0=lsst::afw::geom::Point2I())
Flatten the first two dimensions of an array.
Eigen3 view into an ndarray::Array.
Definition: eigen.h:232
boost::uint16_t MaskPixel
PixelT Pixel
A pixel in this ImageBase.
Definition: Image.h:133
#define PTR(...)
Definition: base.h:41
Point< double, 2 > Point2D
Definition: Point.h:286
Matrix alpha
FlagDefinition getDefinition(int i) const
Definition: FlagHandler.h:66
math::Kernel::Pixel Pixel
Pixel type of Image returned by computeImage.
Definition: Psf.h:78
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
void setValue(afw::table::BaseRecord &record, int i, bool value) const
Definition: FlagHandler.h:72
int isfinite(T t)
Definition: ieee.h:100
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
SafeCentroidExtractor _centroidExtractor
Definition: PsfFlux.h:99
lsst::afw::detection::Footprint Footprint
Definition: Source.h:61
lsst::afw::image::VariancePixel VarPixel
Definition: convCUDA.h:44
image::Image< Pixel > Image
Image type returned by computeImage.
Definition: Psf.h:79

Member Data Documentation

SafeCentroidExtractor lsst::meas::base::PsfFluxAlgorithm::_centroidExtractor
private

Definition at line 99 of file PsfFlux.h.

Control lsst::meas::base::PsfFluxAlgorithm::_ctrl
private

Definition at line 96 of file PsfFlux.h.

FlagHandler lsst::meas::base::PsfFluxAlgorithm::_flagHandler
private

Definition at line 98 of file PsfFlux.h.

FluxResultKey lsst::meas::base::PsfFluxAlgorithm::_fluxResultKey
private

Definition at line 97 of file PsfFlux.h.


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