25#if !defined(LSST_AFW_MATH_STATISTICS_H)
26#define LSST_AFW_MATH_STATISTICS_H
31#include "boost/iterator/iterator_adaptor.hpp"
41template <
typename,
typename,
typename>
91 bool isNanSafe =
true,
95 : _numSigmaClip(numSigmaClip),
98 _noGoodPixelsMask(0x0),
99 _isNanSafe(isNanSafe),
100 _useWeights(useWeights),
101 _calcErrorFromInputVariance(false),
102 _calcErrorMosaicMode(false),
103 _maskPropagationThresholds() {
110 assert(_numSigmaClip > 0);
111 assert(_numIter > 0);
135 if (!(numSigmaClip > 0)) {
137 "numSigmaClip has to be positive.");
139 _numSigmaClip = numSigmaClip;
142 if (!(numIter > 0)) {
144 "numIter has to be positive.");
150 void setNanSafe(
bool isNanSafe)
noexcept { _isNanSafe = isNanSafe; }
153 _calcErrorFromInputVariance = calcErrorFromInputVariance;
156 _calcErrorMosaicMode = calcErrorMosaicMode;
162 double _numSigmaClip;
165 int _noGoodPixelsMask;
168 bool _calcErrorFromInputVariance;
169 bool _calcErrorMosaicMode;
239 template <
typename ImageT,
typename MaskT,
typename VarianceT>
240 explicit Statistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var,
int const flags,
251 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
252 explicit Statistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
310 bool _weightsAreMultiplicative;
320 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
321 void doStatistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
330template <
typename ValueT>
331class infinite_iterator :
public boost::iterator_adaptor<infinite_iterator<ValueT>, const ValueT *,
332 const ValueT, boost::forward_traversal_tag> {
339 void increment() noexcept { ; }
345template <
typename ValueT>
360template <
typename Pixel>
365 return Statistics(img, msk, var, flags, sctrl);
372template <
typename ImageT,
typename MaskT,
typename VarianceT>
375 return Statistics(img, msk, var, flags, sctrl);
382template <
typename Pixel>
385 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance() || sctrl.getCalcErrorMosaicMode()) {
397template <
typename Pixel>
401 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance() || sctrl.getCalcErrorMosaicMode() ||
402 (!sctrl.getWeightedIsSet() && (weights.
getWidth() != 0 && weights.
getHeight() != 0))) {
426template <
typename Pixel>
435 return Statistics(img, msk, var, flags, sctrl);
442template <
typename ValueT>
475template <
typename EntryT>
483 return Statistics(img, msk, var, flags, sctrl);
490template <
typename EntryT>
502 return Statistics(img, msk, var, weights, flags, sctrl);
509template <
typename EntryT>
514 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance() || sctrl.getCalcErrorMosaicMode()) {
526template <
typename EntryT>
534 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance() || sctrl.getCalcErrorMosaicMode()) {
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
int getWidth() const
Return the number of columns in the image.
int getHeight() const
Return the number of rows in the image.
A class to represent a 2-dimensional array of pixels.
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
typename std::vector< ValueT >::const_iterator fast_iterator
ImageImposter(ImageImposter< ValueT > const &img)
ImageImposter(std::vector< ValueT > const &v)
typename std::vector< ValueT >::const_iterator x_iterator
bool empty() const noexcept
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().
infinite_iterator< ValueT > x_iterator
MaskImposter(ValueT val=0) noexcept
x_iterator row_begin(int) const noexcept
lsst::afw::image::MaskedImage< EntryT >::VariancePtr getVariance() const
lsst::afw::image::MaskedImage< EntryT >::MaskPtr getMask() const
lsst::afw::image::MaskedImage< EntryT >::ImagePtr getImage() 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...
void setCalcErrorMosaicMode(bool calcErrorMosaicMode) noexcept
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 getCalcErrorMosaicMode() 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.
Statistics & operator=(Statistics const &)=default
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 & operator=(Statistics &&)=default
~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 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.
double getValue(Property const prop=NOTHING) const
Return the value of the desired property (if specified in the constructor)
std::pair< double, double > Value
The type used to report (value, error) for desired statistics.
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)
Reports invalid arguments.
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