LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+b2075782a9,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g3ddfee87b4+a60788ef87,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+a60788ef87,g591dd9f2cf+ba8caea58f,g5ec818987f+864ee9cddb,g858d7b2824+9ee1ab4172,g876c692160+a40945ebb7,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+5e309b7bc6,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+aa12a14d27,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+d0da15e3be,gba4ed39666+1ac82b564f,gbb8dafda3b+5dfd9c994b,gbeb006f7da+97157f9740,gc28159a63d+c6dfa2ddaf,gc86a011abf+9ee1ab4172,gcf0d15dbbd+a60788ef87,gdaeeff99f8+1cafcb7cd4,gdc0c513512+9ee1ab4172,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,geb961e4c1e+f9439d1e6f,gee10cc3b42+90ebb246c7,gf1cff7945b+9ee1ab4172,w.2024.12
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
lsst::meas::base::LocalBackgroundAlgorithm Class Reference

A measurement algorithm that estimates the local background value per pixel. More...

#include <LocalBackground.h>

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

Public Types

typedef LocalBackgroundControl Control
 

Public Member Functions

 LocalBackgroundAlgorithm (Control const &ctrl, std::string const &name, afw::table::Schema &schema, std::string const &logName="")
 
virtual void measure (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
 Called to measure a single child source in an image.
 
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.
 
void measureForced (afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure, afw::table::SourceRecord const &refRecord, afw::geom::SkyWcs const &refWcs) const override
 Called to measure a single child source in an image.
 
void measureNForced (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure, afw::table::SourceCatalog const &refRecord, afw::geom::SkyWcs const &refWcs) const override
 Called to simultaneously measure all children in a deblend family, in a single image.
 
virtual void measureN (afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure) const
 Called to simultaneously measure all children in a deblend family, in a single image.
 
std::string getLogName () const
 

Static Public Member Functions

static FlagDefinitionList const & getFlagDefinitions ()
 

Static Public Attributes

static FlagDefinition const FAILURE = flagDefinitions.addFailureFlag()
 
static FlagDefinition const NO_GOOD_PIXELS
 
static FlagDefinition const NO_PSF = flagDefinitions.add("flag_noPsf", "no PSF provided")
 

Protected Attributes

std::string _logName
 

Detailed Description

A measurement algorithm that estimates the local background value per pixel.

Definition at line 65 of file LocalBackground.h.

Member Typedef Documentation

◆ Control

Definition at line 72 of file LocalBackground.h.

Constructor & Destructor Documentation

◆ LocalBackgroundAlgorithm()

lsst::meas::base::LocalBackgroundAlgorithm::LocalBackgroundAlgorithm ( Control const & ctrl,
std::string const & name,
afw::table::Schema & schema,
std::string const & logName = "" )

Definition at line 48 of file LocalBackground.cc.

50 : _ctrl(ctrl),
51 _resultKey(FluxResultKey::addFields(schema, name, "background in annulus around source")),
52 _flagHandler(FlagHandler::addFields(schema, name, getFlagDefinitions())),
53 _centroidExtractor(schema, name),
54 _stats(ctrl.bgRej, ctrl.bgIter) {
55 _logName = logName.size() ? logName : name;
56}
table::Key< std::string > name
Definition Amplifier.cc:116
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.
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...
static FlagDefinitionList const & getFlagDefinitions()
T size(T... args)

Member Function Documentation

◆ fail()

void lsst::meas::base::LocalBackgroundAlgorithm::fail ( afw::table::SourceRecord & measRecord,
MeasurementError * error = nullptr ) 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 111 of file LocalBackground.cc.

111 {
112 _flagHandler.handleFailure(measRecord, error);
113}
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
Handle an expected or unexpected Exception thrown by a measurement algorithm.

◆ getFlagDefinitions()

FlagDefinitionList const & lsst::meas::base::LocalBackgroundAlgorithm::getFlagDefinitions ( )
static

Definition at line 46 of file LocalBackground.cc.

46{ return flagDefinitions; }

◆ getLogName()

std::string lsst::meas::base::BaseAlgorithm::getLogName ( ) const
inlineinherited

Definition at line 66 of file Algorithm.h.

66{ return _logName; }

◆ measure()

void lsst::meas::base::LocalBackgroundAlgorithm::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 58 of file LocalBackground.cc.

59 {
60 geom::Point2D const center = _centroidExtractor(measRecord, _flagHandler);
61 afw::image::MaskedImage<float> const& image = exposure.getMaskedImage();
62 afw::image::Mask<afw::image::MaskPixel> const& mask = *image.getMask();
63 afw::image::MaskPixel const badMask = mask.getPlaneBitMask(_ctrl.badMaskPlanes);
64
65 // Define pixels in annulus
66 auto const psf = exposure.getPsf();
67 if (!psf) {
68 _flagHandler.setValue(measRecord, NO_PSF.number, true);
69 _flagHandler.setValue(measRecord, LocalBackgroundAlgorithm::FAILURE.number, true);
70 return;
71 }
72 float const psfSigma = psf->computeShape(center).getDeterminantRadius();
73
74 float const innerRadius = _ctrl.annulusInner * psfSigma;
75 afw::geom::ellipses::Axes const innerCircle{innerRadius, innerRadius};
76 auto const& inner = afw::geom::SpanSet::fromShape(afw::geom::ellipses::Ellipse(innerCircle, center));
77
78 float const outerRadius = _ctrl.annulusOuter * psfSigma;
79 afw::geom::ellipses::Axes const outerCircle{outerRadius, outerRadius};
80 auto const& outer = afw::geom::SpanSet::fromShape(afw::geom::ellipses::Ellipse(outerCircle, center));
81
82 auto const& annulus = outer->clippedTo(image.getBBox())->intersectNot(*inner);
83 auto const& imageValues = annulus->flatten(image.getImage()->getArray(), image.getXY0());
84 auto const& maskValues = annulus->flatten(image.getMask()->getArray(), image.getXY0());
85
86 // Extract from ndarray::Array into std::vector because of limitations in afw::math::makeStatistics
87 std::vector<float> values;
88 values.reserve(imageValues.getNumElements());
89 if(imageValues.getNumElements() != maskValues.getNumElements()) {
90 throw LSST_EXCEPT(lsst::pex::exceptions::LengthError, "invalid number of elements");
91 } // constructed from the same spans
92 auto maskIter = maskValues.begin();
93 for (auto imageIter = imageValues.begin(); imageIter != imageValues.end(); ++imageIter, ++maskIter) {
94 if ((*maskIter & badMask) == 0) {
95 values.push_back(*imageIter);
96 }
97 }
98
99 if (values.size() == 0) {
100 _flagHandler.setValue(measRecord, NO_GOOD_PIXELS.number, true);
101 _flagHandler.setValue(measRecord, LocalBackgroundAlgorithm::FAILURE.number, true);
102 return;
103 }
104
105 // Measure the background
106 auto const stats = afw::math::makeStatistics(values, afw::math::MEANCLIP | afw::math::STDEVCLIP, _stats);
107 FluxResult const result(stats.getValue(afw::math::MEANCLIP), stats.getValue(afw::math::STDEVCLIP));
108 measRecord.set(_resultKey, result);
109}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
afw::table::Key< afw::table::Array< MaskPixelT > > mask
static std::shared_ptr< geom::SpanSet > fromShape(int r, Stencil s=Stencil::CIRCLE, lsst::geom::Point2I offset=lsst::geom::Point2I())
Factory function for creating SpanSets from a Stencil.
Definition SpanSet.cc:688
void setValue(afw::table::BaseRecord &record, std::size_t i, bool value) const
Set the flag field corresponding to the given flag index.
static FlagDefinition const NO_GOOD_PIXELS
std::vector< std::string > badMaskPlanes
"Mask planes that indicate pixels that should be excluded from the measurement" ;
float annulusInner
"Inner radius for background annulus as a multiple of the PSF sigma" ;
float annulusOuter
"Outer radius for background annulus as a multiple of the PSF sigma" ;
Reports attempts to exceed implementation-defined length limits for some classes.
Definition Runtime.h:76
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
Definition Statistics.h:361
@ STDEVCLIP
estimate sample N-sigma clipped stdev (N set in StatisticsControl, default=3)
Definition Statistics.h:63
@ MEANCLIP
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
Definition Statistics.h:62
T push_back(T... args)
T reserve(T... args)

◆ measureForced()

void lsst::meas::base::SimpleAlgorithm::measureForced ( afw::table::SourceRecord & measRecord,
afw::image::Exposure< float > const & exposure,
afw::table::SourceRecord const & refRecord,
afw::geom::SkyWcs const & refWcs ) const
inlineoverridevirtualinherited

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::ForcedAlgorithm.

Reimplemented in lsst::meas::extensions::photometryKron::KronFluxAlgorithm.

Definition at line 172 of file Algorithm.h.

175 {
176 measure(measRecord, exposure);
177 }
virtual void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const =0
Called to measure a single child source in an image.

◆ measureN()

void lsst::meas::base::SingleFrameAlgorithm::measureN ( afw::table::SourceCatalog const & measCat,
afw::image::Exposure< float > const & exposure ) const
virtualinherited

Called to simultaneously measure all children in a deblend family, in a single image.

Outputs should be saved in the given SourceCatalog, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

The default implementation simply throws an exception, indicating that simultaneous measurement is not supported.

Definition at line 31 of file Algorithm.cc.

32 {
33 throw LSST_EXCEPT(pex::exceptions::LogicError, "measureN not implemented for this algorithm");
34}

◆ measureNForced()

void lsst::meas::base::SimpleAlgorithm::measureNForced ( afw::table::SourceCatalog const & measCat,
afw::image::Exposure< float > const & exposure,
afw::table::SourceCatalog const & refRecord,
afw::geom::SkyWcs const & refWcs ) const
inlineoverridevirtualinherited

Called to simultaneously measure all children in a deblend family, in a single image.

Outputs should be saved in the given SourceCatalog, which can also be used to obtain centroid (see SafeCentroidExtractor) and shape (see SafeShapeExtractor) information.

The default implementation simply throws an exception, indicating that simultaneous measurement is not supported.

Reimplemented from lsst::meas::base::ForcedAlgorithm.

Definition at line 179 of file Algorithm.h.

182 {
183 measureN(measCat, exposure);
184 }
virtual void measureN(afw::table::SourceCatalog const &measCat, afw::image::Exposure< float > const &exposure) const
Called to simultaneously measure all children in a deblend family, in a single image.
Definition Algorithm.cc:31

Member Data Documentation

◆ _logName

std::string lsst::meas::base::BaseAlgorithm::_logName
protectedinherited

Definition at line 69 of file Algorithm.h.

◆ FAILURE

FlagDefinition const lsst::meas::base::LocalBackgroundAlgorithm::FAILURE = flagDefinitions.addFailureFlag()
static

Definition at line 68 of file LocalBackground.h.

◆ NO_GOOD_PIXELS

FlagDefinition const lsst::meas::base::LocalBackgroundAlgorithm::NO_GOOD_PIXELS
static
Initial value:
=
flagDefinitions.add("flag_noGoodPixels", "no good pixels in the annulus")

Definition at line 69 of file LocalBackground.h.

◆ NO_PSF

FlagDefinition const lsst::meas::base::LocalBackgroundAlgorithm::NO_PSF = flagDefinitions.add("flag_noPsf", "no PSF provided")
static

Definition at line 70 of file LocalBackground.h.


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