26#ifndef LATTICES_LATTICESTATISTICS_H
27#define LATTICES_LATTICESTATISTICS_H
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/Array.h>
31#include <casacore/casa/Containers/Block.h>
32#include <casacore/casa/Arrays/Vector.h>
33#include <casacore/casa/Containers/Record.h>
34#include <casacore/lattices/LatticeMath/LatticeStatsBase.h>
35#include <casacore/lattices/LatticeMath/TiledCollapser.h>
36#include <casacore/lattices/LatticeMath/TiledCollapser.h>
37#include <casacore/lattices/LEL/LatticeExprNode.h>
38#include <casacore/lattices/LatticeMath/LatticeStatsDataProvider.h>
39#include <casacore/lattices/LatticeMath/MaskedLatticeStatsDataProvider.h>
40#include <casacore/scimath/Mathematics/NumericTraits.h>
41#include <casacore/casa/Utilities/DataType.h>
42#include <casacore/casa/BasicSL/String.h>
43#include <casacore/casa/Logging/LogIO.h>
44#include <casacore/scimath/StatsFramework/FitToHalfStatisticsData.h>
45#include <casacore/scimath/StatsFramework/StatisticsData.h>
46#include <casacore/scimath/StatsFramework/StatisticsAlgorithm.h>
47#include <casacore/scimath/StatsFramework/StatisticsAlgorithmFactory.h>
55template <
class T>
class MaskedLattice;
56template <
class T>
class SubLattice;
57template <
class T>
class TempLattice;
60#include <casacore/casa/iosstrfwd.h>
282 Int zAxis=-1,
Int zLayer=-1,
283 Int hAxis=-1,
Int hLayer=-1);
288 Int zAxis=-1,
Int zLayer=-1,
289 Int hAxis=-1,
Int hLayer=-1);
453 ThrowCc(
"Logic Error: This object cannot compute flux density");
457 ostringstream& osMax,
458 Int oWidth, DataType type);
477 ostringstream& rslt,
Int zLayer);
570 template <
class U,
class V>
577 template <
class U,
class V>
608 const Bool posInLattice);
628 std::shared_ptr<LattStatsProgress> progressMeter,
634 std::shared_ptr<LattStatsProgress> progressMeter,
uInt nsets
647 >& sa, T& overallMin, T& overallMax,
IPosition& arrayShape,
649 std::vector<
Array<Bool>>& maskArray, std::vector<IPosition>& curPos,
651 Bool isMasked,
Bool isReal, std::shared_ptr<const DataRanges> range
655 T currentMin, T currentMax,
const IPosition& curPos,
661 return npts <= 0 ? 0 :
sum/npts;
665 return npts <= 0 ? 0 :
sqrt(sumsq/npts);
669 T& overallMin, T& overallMax, T currentMin, T currentMax,
681#ifndef CASACORE_NO_AUTO_TEMPLATES
682#include <casacore/lattices/LatticeMath/LatticeStatistics.tcc>
USE_DATA
which section of data to use, greater than or less than the center value
CENTER
choice of center point based on the corresponding statistics from the entire distribution of data,...
Bool goodParameterStatus_p
Bool retrieveStorageStatistic(Vector< AccumType > &slice, const IPosition &pos, const Bool posInLattice)
Retrieve a statistic from the storage lattice at the specified location and return in an array.
Bool someGoodPoints()
See if there were some valid points found in the storage lattice.
Vector< Int > displayAxes_p
LatticeStatistics< T > & operator=(const LatticeStatistics< T > &other)
Assignment operator.
void _fillStorageLattice(T currentMin, T currentMax, const IPosition &curPos, const StatsData< AccumType > &stats, Bool doQuantiles, AccumType q1=0, AccumType q3=0)
IPosition locInStorageLattice(const IPosition &latticePosition, LatticeStatsBase::StatisticsTypes type) const
Given a location in the lattice and a statistic type, work out where to put it in the storage lattice...
Bool getLayerStats(String &stats, Double area, Int zAxis=-1, Int zLayer=-1, Int hAxis=-1, Int hLayer=-1)
std::map< String, uInt > _chauvIters
Bool doRobust_p
doRobust means that when the storage lattice is generated, the robust statistics are generated as wel...
Bool configureHingesFences(Double f)
configure to use hinges-fences algorithm
static AccumType _mean(const AccumType &sum, const AccumType &npts)
virtual Bool listLayerStats(const Matrix< AccumType > &ord, ostringstream &rslt, Int zLayer)
Vector< Int > cursorAxes_p
void forceAllowCodeDecideWhichAlgortihmToUse()
Vector< Int > displayAxes() const
Return the display axes.
virtual ~LatticeStatistics()
Destructor.
virtual Bool _computeFlux(Array< AccumType > &flux, const Array< AccumType > &npts, const Array< AccumType > &sum)
Bool configureClassical(Double aOld, Double bOld, Double aNew, Double bNew)
void setComputeQuantiles(Bool b)
should quantile-like stats (median, quartiles, medabsdevmed) be computed? When the stats framework is...
Bool display()
Display the statistics by listing and/or plotting them.
std::list< stat_element > stat_list
virtual void summStats()
Summarize the statistics found over the entire lattice.
void _computeQuantiles(AccumType &median, AccumType &medAbsDevMed, AccumType &q1, AccumType &q3, std::shared_ptr< StatisticsAlgorithm< AccumType, U, V > > statsAlg, uInt64 knownNpts, AccumType knownMin, AccumType knownMax) const
StatisticsAlgorithmFactory< AccumType, const T *, const Bool * > _saf
Bool setAxes(const Vector< Int > &cursorAxes)
Set the cursor axes (0 relative).
std::unique_ptr< LatticeStatsAlgorithm > _latticeStatsAlgortihm
unset means let the code decide
Bool retrieveStorageStatistic(Array< AccumType > &slice, const LatticeStatsBase::StatisticsTypes type, const Bool dropDeg)
Retrieve a statistic from the storage lattice and return in an array.
NumericTraits< T >::PrecisionType AccumType
StatisticsData::ALGORITHM _getAlgorithm() const
const MaskedLattice< T > * pInLattice_p
Bool someGoodPointsValue_p
Bool configureFitToHalf(FitToHalfStatisticsData::CENTER centerType=FitToHalfStatisticsData::CMEAN, FitToHalfStatisticsData::USE_DATA useData=FitToHalfStatisticsData::LE_CENTER, AccumType centerValue=0)
configure to use fit to half algorithm.
void resetError()
Reset argument error condition.
Bool getFullMinMax(T &dataMin, T &dataMax)
Get full lattice min and max only.
std::shared_ptr< TempLattice< AccumType > > pStoreLattice_p
@ STATS_FRAMEWORK_DATA_PROVIDERS
Bool configureBiweight(Int maxIter, Double c)
The configure methods return True if reconfiguration is actually necessary (ie if the underlying stor...
virtual Bool _computeFlux(Quantum< AccumType > &flux, AccumType sum, const IPosition &pos, Bool posInLattice)
static AccumType _rms(const AccumType &sumsq, const AccumType &npts)
Bool setList(const Bool &doList)
This function allows you to control whether the statistics are written to the output stream if you ar...
Bool getMinMaxPos(IPosition &minPos, IPosition &maxPos)
Recover position of min and max.
void _computeStatsUsingArrays(std::shared_ptr< LattStatsProgress > progressMeter, const IPosition &cursorShape)
Bool setInExCludeRange(const Vector< T > &include, const Vector< T > &exclude, Bool setMinMaxToInclude=False)
You may specify a pixel intensity range as either one for which all pixels in that range are included...
IPosition locInLattice(const IPosition &storagePosition, Bool relativeToParent=True) const
Given a location in the storage lattice, convert those locations on the non-statistics axis (the la...
Vector< Int > statsToPlot_p
String errorMessage() const
Recover last error message.
Bool setNewLattice(const MaskedLattice< T > &lattice, Bool clone=True)
Set a new MaskedLattice object.
void _configureDataProviders(LatticeStatsDataProvider< T > &lattDP, MaskedLatticeStatsDataProvider< T > &maskedLattDP) const
Bool configureChauvenet(Double zscore=-1, Int maxIterations=-1)
configure to use Chauvenet's criterion
void stretchMinMax(AccumType &dMin, AccumType &dMax) const
Stretch min and max by 5%.
std::map< String, uInt > getChauvenetNiter() const
get number of iterations associated with Chauvenet criterion algorithm
void forceUseStatsFrameworkUsingDataProviders()
The force* methods are really only for testing.
IPosition statsSliceShape() const
Find the shape of slice from the statistics lattice at one spatial pixel.
std::pair< String, String > stat_element
LatticeStatistics(const MaskedLattice< T > &lattice, Bool showProgress=True, Bool forceDisk=False, Bool clone=True)
Constructor takes the lattice only.
Bool hasLogger() const
Did we construct with a logger ?
virtual Bool listStats(Bool hasBeam, const IPosition &dPos, const Matrix< AccumType > &ord)
List the statistics to the logger.
Bool calculateStatistic(Array< AccumType > &slice, LatticeStatsBase::StatisticsTypes type, Bool dropDeg)
Calculate statistic from storage lattice and return in an array.
std::shared_ptr< const MaskedLattice< T > > _inLatPtrMgr
Bool needStorageLattice_p
Bool getStats(Vector< AccumType > &, const IPosition &pos, const Bool posInLattice=False)
This function gets a vector containing all the statistics for a given location.
LatticeStatistics(const LatticeStatistics< T > &other)
Copy constructor.
void _updateMinMaxPos(T &overallMin, T &overallMax, T currentMin, T currentMax, const IPosition &minPos, const IPosition &maxPos, Bool atStart)
void _latticePosToStoragePos(IPosition &storagePos, const IPosition &latticePos)
convert a position in the input lattice to the corresponding position in the stats storage lattice.
virtual Bool _canDoFlux() const
Virtual Functions.
virtual void listMinMax(ostringstream &osMin, ostringstream &osMax, Int oWidth, DataType type)
LatticeStatistics(const MaskedLattice< T > &lattice, LogIO &os, Bool showProgress=True, Bool forceDisk=False, Bool clone=True)
Constructor takes the lattice and a LogIO object for logging.
virtual void displayStats(AccumType nPts, AccumType sum, AccumType median, AccumType medAbsDevMed, AccumType quartile, AccumType sumSq, AccumType mean, AccumType var, AccumType rms, AccumType sigma, AccumType dMin, AccumType dMax, AccumType q1, AccumType q3)
Bool getStatistic(Array< AccumType > &stat, LatticeStatsBase::StatisticsTypes type, Bool dropDeg=True)
Recover the desired Statistic into an array.
IPosition _cursorShapeForArrayMethod(uInt64 setSize) const
void forceUseOldTiledApplyMethod()
IPosition _storageLatticeShape() const
get the storage lattice shape
Bool configureClassical()
configure object to use Classical Statistics The time, t_x, it takes to compute classical statistics ...
void _doComputationUsingArrays(std::vector< std::shared_ptr< StatisticsAlgorithm< AccumType, typename Array< T >::const_iterator, Array< Bool >::const_iterator > > > &sa, T &overallMin, T &overallMax, IPosition &arrayShape, std::vector< Array< T > > &dataArray, std::vector< Array< Bool > > &maskArray, std::vector< IPosition > &curPos, uInt nthreads, Bool isChauv, Bool isMasked, Bool isReal, std::shared_ptr< const DataRanges > range)
Bool getLayerStats(stat_list &stats, Double area, Int zAxis=-1, Int zLayer=-1, Int hAxis=-1, Int hLayer=-1)
void generateRobust()
Find the median per cursorAxes chunk.
Bool getConvertedStatistic(Array< T > &stat, LatticeStatsBase::StatisticsTypes type, Bool dropDeg=True)
Bool doneSomeGoodPoints_p
void minMax(Bool &none, AccumType &dMin, AccumType &dMax, const Vector< AccumType > &d, const Vector< AccumType > &n) const
Find min and max of good data in arrays specified by pointers.
void forceUseStatsFrameworkUsingArrays()
void _computeStatsUsingLattDataProviders(LatticeStepper &stepper, SubLattice< T > subLat, Slicer &slicer, std::shared_ptr< LattStatsProgress > progressMeter, uInt nsets)
void _computeQuantilesForStatsFramework(StatsData< AccumType > &stats, AccumType &q1, AccumType &q3, std::shared_ptr< StatisticsAlgorithm< AccumType, U, V > > statsAlg) const
void _doStatsLoop(uInt nsets, std::shared_ptr< LattStatsProgress > progressMeter)
Bool generateStorageLattice()
Create a new storage lattice.
virtual Quantum< AccumType > _flux(Bool &, AccumType, Double) const
void setStream(ostream &os, Int oPrec)
Non-virtual functions.
StatisticsTypes
This enum StatisticTypes is provided for use with the LatticeStatistics<T>::setPlotting function.
Data provider which allows stats framework to iterate through an unmasked lattice.
Data provider which allows stats framework to iterate through a masked lattice.
Char PrecisionType
Higher precision type (Float->Double)
Provides a single interface for creation of stats algorithm objects.
Base class of statistics algorithm class hierarchy.
ALGORITHM
implemented algorithms
String: the storage and methods of handling collections of characters.
this file contains all the compiler specific defines
LatticeExprNode mean(const LatticeExprNode &expr)
LatticeExprNode sum(const LatticeExprNode &expr)
LatticeExprNode sqrt(const LatticeExprNode &expr)
bool Bool
Define the standard types used by Casacore.
LatticeExprNode median(const LatticeExprNode &expr)
unsigned long long uInt64
TableExprNode rms(const TableExprNode &array)