25 #if !defined(LSST_AFW_MATH_STATISTICS_H)
26 #define LSST_AFW_MATH_STATISTICS_H
40 #include "boost/iterator/iterator_adaptor.hpp"
41 #include "boost/tuple/tuple.hpp"
51 template <
typename,
typename,
typename>
101 bool isNanSafe =
true,
105 : _numSigmaClip(numSigmaClip),
108 _noGoodPixelsMask(0x0),
109 _isNanSafe(isNanSafe),
110 _useWeights(useWeights),
111 _calcErrorFromInputVariance(false),
112 _maskPropagationThresholds() {
119 assert(_numSigmaClip > 0);
120 assert(_numIter > 0);
143 if (!(numSigmaClip > 0)) {
145 "numSigmaClip has to be positive.");
147 _numSigmaClip = numSigmaClip;
150 if (!(numIter > 0)) {
152 "numIter has to be positive.");
158 void setNanSafe(
bool isNanSafe) noexcept { _isNanSafe = isNanSafe; }
161 _calcErrorFromInputVariance = calcErrorFromInputVariance;
167 double _numSigmaClip;
170 int _noGoodPixelsMask;
173 bool _calcErrorFromInputVariance;
238 template <
typename ImageT,
typename MaskT,
typename VarianceT>
239 explicit Statistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var,
int const flags,
250 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
251 explicit Statistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
309 bool _weightsAreMultiplicative;
319 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
320 void doStatistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
329 template <
typename ValueT>
330 class infinite_iterator :
public boost::iterator_adaptor<infinite_iterator<ValueT>, const ValueT *,
331 const ValueT, boost::forward_traversal_tag> {
338 void increment() noexcept { ; }
344 template <
typename ValueT>
359 template <
typename Pixel>
364 return Statistics(img, msk, var, flags, sctrl);
371 template <
typename ImageT,
typename MaskT,
typename VarianceT>
374 return Statistics(img, msk, var, flags, sctrl);
381 template <
typename Pixel>
384 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance()) {
396 template <
typename Pixel>
400 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance() ||
401 (!sctrl.getWeightedIsSet() && (weights.
getWidth() != 0 && weights.
getHeight() != 0))) {
425 template <
typename Pixel>
434 return Statistics(img, msk, var, flags, sctrl);
441 template <
typename ValueT>
474 template <
typename EntryT>
482 return Statistics(img, msk, var, flags, sctrl);
489 template <
typename EntryT>
501 return Statistics(img, msk, var, weights, flags, sctrl);
508 template <
typename EntryT>
513 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance()) {
525 template <
typename EntryT>
533 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance()) {
#define LSST_EXCEPT(type,...)
int getWidth() const
Return the number of columns in the image.
int getHeight() const
Return the number of rows in the image.
Represent a 2-dimensional array of bitmask pixels.
static MaskPixelT getPlaneBitMask(const std::vector< std::string > &names)
Return the bitmask corresponding to a vector of plane names OR'd together.
A class to manipulate images, masks, and variance as a single object.
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage's mask.
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
A vector wrapper to provide a vector with the necessary methods and typedefs to be processed by Stati...
lsst::geom::Extent2I getDimensions() const noexcept
x_iterator row_begin(int) const noexcept
ImageImposter(ImageImposter< ValueT > const &img)
ImageImposter(std::vector< ValueT > const &v)
std::vector< ValueT >::const_iterator x_iterator
bool empty() const noexcept
std::vector< ValueT >::const_iterator fast_iterator
int getWidth() const noexcept
x_iterator row_end(int) const noexcept
int getHeight() const noexcept
A Mask wrapper to provide an infinite_iterator for Mask::row_begin().
MaskImposter(ValueT val=0) noexcept
x_iterator row_begin(int) const noexcept
infinite_iterator< ValueT > x_iterator
lsst::afw::image::MaskedImage< EntryT >::VariancePtr getVariance() const
lsst::afw::image::MaskedImage< EntryT >::ImagePtr getImage() const
lsst::afw::image::MaskedImage< EntryT >::MaskPtr getMask() const
Pass parameters to a Statistics object.
void setNumSigmaClip(double numSigmaClip)
double getMaskPropagationThreshold(int bit) const
When pixels with the given bit are rejected, we count what fraction the rejected pixels would have co...
bool getCalcErrorFromInputVariance() const noexcept
int getAndMask() const noexcept
StatisticsControl(double numSigmaClip=3.0, int numIter=3, lsst::afw::image::MaskPixel andMask=0x0, bool isNanSafe=true, WeightsBoolean useWeights=WEIGHTS_NONE)
void setCalcErrorFromInputVariance(bool calcErrorFromInputVariance) noexcept
bool getWeightedIsSet() const noexcept
void setMaskPropagationThreshold(int bit, double threshold)
void setWeighted(bool useWeights) noexcept
double getNumSigmaClip() const noexcept
bool getWeighted() const noexcept
int getNoGoodPixelsMask() const noexcept
int getNumIter() const noexcept
bool getNanSafe() const noexcept
void setNoGoodPixelsMask(int noGoodPixelsMask)
void setNumIter(int numIter)
void setNanSafe(bool isNanSafe) noexcept
void setAndMask(int andMask)
A class to evaluate image statistics.
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, int const flags, StatisticsControl const &sctrl=StatisticsControl())
The makeStatistics() overload to handle regular (non-masked) Images.
Statistics makeStatistics(std::vector< EntryT > const &v, int const flags, StatisticsControl const &sctrl=StatisticsControl())
The makeStatistics() overload to handle std::vector<>
Statistics makeStatistics(lsst::afw::image::MaskedImage< Pixel > const &mimg, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle MaskedImages, just pass the getImage() and getMask() values right on through.
std::pair< double, double > Value
The type used to report (value, error) for desired statistics.
Value getResult(Property const prop=NOTHING) const
Return the value and error in the specified statistic (e.g.
Statistics makeStatistics(ImageT const &img, MaskT const &msk, VarianceT const &var, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a straight front-end to the constructor.
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)
double getError(Property const prop=NOTHING) const
Return the error in the desired property (if specified in the constructor)
~Statistics() noexcept=default
Statistics makeStatistics(lsst::afw::math::MaskedVector< EntryT > const &mv, std::vector< WeightPixel > const &vweights, int const flags, StatisticsControl const &sctrl=StatisticsControl())
The makeStatistics() overload to handle lsst::afw::math::MaskedVector<>
Statistics makeStatistics(lsst::afw::math::MaskedVector< EntryT > const &mv, int const flags, StatisticsControl const &sctrl=StatisticsControl())
The makeStatistics() overload to handle lsst::afw::math::MaskedVector<>
Statistics & operator=(Statistics const &)=default
Statistics makeStatistics(lsst::afw::image::MaskedImage< Pixel > const &mimg, lsst::afw::image::Image< WeightPixel > const &weights, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle MaskedImages, just pass the getImage() and getMask() values right on through.
Statistics(ImageT const &img, MaskT const &msk, VarianceT const &var, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Constructor for Statistics object.
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
Statistics & operator=(Statistics &&)=default
Statistics makeStatistics(std::vector< EntryT > const &v, std::vector< WeightPixel > const &vweights, int const flags, StatisticsControl const &sctrl=StatisticsControl())
The makeStatistics() overload to handle std::vector<>
Statistics(Statistics const &)=default
lsst::afw::image::MaskPixel getOrMask() const noexcept
Statistics(Statistics &&)=default
This iterator will never increment.
friend class boost::iterator_core_access
infinite_iterator(const ValueT *p)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
class[[deprecated("Removed with no replacement (but see lsst::afw::image::TransmissionCurve). Will be " "removed after v22.")]] FilterProperty final
Describe the properties of a Filter (e.g.
std::int32_t MaskPixel
default type for Masks and MaskedImage Masks
float VariancePixel
default type for MaskedImage variance images
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)
Property
control what is calculated
@ ORMASK
get the or-mask of all pixels used.
@ ERRORS
Include errors of requested quantities.
@ VARIANCECLIP
estimate sample N-sigma clipped variance (N set in StatisticsControl, default=3)
@ MEANSQUARE
find mean value of square of pixel values
@ MIN
estimate sample minimum
@ NCLIPPED
number of clipped points
@ NOTHING
We don't want anything.
@ STDEV
estimate sample standard deviation
@ NMASKED
number of masked points
@ STDEVCLIP
estimate sample N-sigma clipped stdev (N set in StatisticsControl, default=3)
@ VARIANCE
estimate sample variance
@ MEDIAN
estimate sample median
@ MAX
estimate sample maximum
@ SUM
find sum of pixels in the image
@ IQRANGE
estimate sample inter-quartile range
@ MEAN
estimate sample mean
@ MEANCLIP
estimate sample N-sigma clipped mean (N set in StatisticsControl, default=3)
@ NPOINT
number of sample points
Property stringToStatisticsProperty(std::string const property)
Conversion function to switch a string to a Property (see Statistics.h)
lsst::afw::image::VariancePixel WeightPixel
Extent< int, 2 > Extent2I
A base class for image defects.