25 #if !defined(LSST_AFW_MATH_STATISTICS_H)
26 #define LSST_AFW_MATH_STATISTICS_H
40 #include "boost/iterator/iterator_adaptor.hpp"
50 template <
typename,
typename,
typename>
100 bool isNanSafe =
true,
104 : _numSigmaClip(numSigmaClip),
107 _noGoodPixelsMask(0x0),
108 _isNanSafe(isNanSafe),
109 _useWeights(useWeights),
110 _calcErrorFromInputVariance(false),
111 _maskPropagationThresholds() {
118 assert(_numSigmaClip > 0);
119 assert(_numIter > 0);
142 if (!(numSigmaClip > 0)) {
144 "numSigmaClip has to be positive.");
146 _numSigmaClip = numSigmaClip;
149 if (!(numIter > 0)) {
151 "numIter has to be positive.");
157 void setNanSafe(
bool isNanSafe) noexcept { _isNanSafe = isNanSafe; }
160 _calcErrorFromInputVariance = calcErrorFromInputVariance;
166 double _numSigmaClip;
169 int _noGoodPixelsMask;
172 bool _calcErrorFromInputVariance;
237 template <
typename ImageT,
typename MaskT,
typename VarianceT>
238 explicit Statistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var,
int const flags,
249 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
250 explicit Statistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
308 bool _weightsAreMultiplicative;
318 template <
typename ImageT,
typename MaskT,
typename VarianceT,
typename WeightT>
319 void doStatistics(ImageT
const &img, MaskT
const &msk, VarianceT
const &var, WeightT
const &weights,
328 template <
typename ValueT>
329 class infinite_iterator :
public boost::iterator_adaptor<infinite_iterator<ValueT>, const ValueT *,
330 const ValueT, boost::forward_traversal_tag> {
337 void increment() noexcept { ; }
343 template <
typename ValueT>
358 template <
typename Pixel>
363 return Statistics(img, msk, var, flags, sctrl);
370 template <
typename ImageT,
typename MaskT,
typename VarianceT>
373 return Statistics(img, msk, var, flags, sctrl);
380 template <
typename Pixel>
383 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance()) {
395 template <
typename Pixel>
399 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance() ||
400 (!sctrl.getWeightedIsSet() && (weights.
getWidth() != 0 && weights.
getHeight() != 0))) {
424 template <
typename Pixel>
433 return Statistics(img, msk, var, flags, sctrl);
440 template <
typename ValueT>
473 template <
typename EntryT>
481 return Statistics(img, msk, var, flags, sctrl);
488 template <
typename EntryT>
500 return Statistics(img, msk, var, weights, flags, sctrl);
507 template <
typename EntryT>
512 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance()) {
524 template <
typename EntryT>
532 if (sctrl.getWeighted() || sctrl.getCalcErrorFromInputVariance()) {
#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.
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 >::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.
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
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.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
float VariancePixel
default type for MaskedImage variance images
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
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.