casacore
Loading...
Searching...
No Matches
LatticeStatistics.h
Go to the documentation of this file.
1//# LatticeStatistics.h: generate statistics from a Lattice
2//# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef LATTICES_LATTICESTATISTICS_H
27#define LATTICES_LATTICESTATISTICS_H
28
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>
48
49#include <vector>
50#include <list>
51
52namespace casacore { //# NAMESPACE CASACORE - BEGIN
53
54//# Forward Declarations
55template <class T> class MaskedLattice;
56template <class T> class SubLattice;
57template <class T> class TempLattice;
58class IPosition;
59
60#include <casacore/casa/iosstrfwd.h>
61
62// <summary>
63// Compute and display various statistics from a lattice
64// </summary>
65// <use visibility=export>
66// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
67// </reviewed>
68// <prerequisite>
69// <li> <linkto class=LatticeStatsBase>LatticeStatsBase</linkto>
70// <li> <linkto class=MaskedLattice>MaskedLattice</linkto>
71// </prerequisite>
72
73// <etymology>
74// This is a class designed to display and retrieve statistics from lattices
75// </etymology>
76
77// <synopsis>
78// This class enable you to display and/or retrieve statistics evaluated over
79// specified regions of a lattice. The dimension of the region is arbitrary, but
80// the size of each dimension is always the shape of the corresponding lattice axis.
81// The statistics are displayed as a function of location of the axes not
82// used to evaluate the statistics over. The axes which you evaluate the statistics
83// over are called the cursor axes, the others are called the display axes.
84//
85// For example, consider a lattice cube (call the axes xyz or [0,1,2]). You could
86// display statistics from xy planes (cursor axes [0,1]) as a function of z (display
87// axes [2]). Or you could retrieve statistics from the z axis (cursor axes [2])
88// for each [x,y] location (display axes [0,1]).
89//
90// This class inherits from <linkto class="LatticeStatsBase">LatticeStatsBase</linkto>
91// This base class provides an <src>enum</src> defining allowed statistics types and a
92// helper function to convert between a <src>String</src> and a
93// <src>Vector<Int></src> describing the desired statistics to plot.
94// An example is shown below.
95//
96// This class can list, plot and retrieve statistics. When it lists statistics,
97// it always lists all the available statistics. When you plot statistics,
98// you must specify which ones you would like to see.
99//
100// This class generates a "storage lattice" into which it writes the accumulated
101// statistical sums. It is from this storage lattice that the plotting and retrieval
102// arrays are drawn. The storage lattice is either in core or on disk
103// depending upon its size (if > 10% of memory given by .aipsrc system.resources.memory
104// then it goes into a disk-based PagedArray). If on disk, the
105// storage lattice is deleted when the <src>LatticeStatistics</src> class
106// object destructs. However, currently, if the process is terminated ungracefully,
107// the storage lattice will be left over.
108// </synopsis>
109//
110// <note role=tip>
111// This class has a few virtual functions; they are not part of a nice general
112// polymorphic interface; rather they have specialized functionality. The idea
113// of these is that you can derive a class from LatticeStatistics, such as
114// <linkto class="ImageStatistics">ImageStatistics</linkto> which provides
115// you with a little more information when displaying/logging the
116// statistics (such as world coordinates)
117// The virtual functions are
118// <ul>
119// <li> <src>getBeamArea</src> can be used to return the synthesized beam
120// area so that the FLUX statistic can be computed
121// <li> <src>listStats</src> is used to list the statistics to the logger
122// <li> <src>getLabelsM</src> find the X-axis label and the title label
123// for the plotting.
124// </ul>
125// </note>
126//
127// <note role=tip>
128// If you ignore return error statuses from the functions that set the
129// state of the class, the internal status of the class is set to bad.
130// This means it will just keep on returning error conditions until you
131// explicitly recover the situation. A message describing the last
132// error condition can be recovered with function errorMessage.
133// </note>
134
135
136// <example>
137// <srcBlock>
139//
140// PagedImage<Float> inImage(inName);
141//
143//
144// LogOrigin or("myClass", "myFunction(...)", WHERE);
145// LogIO os(or);
146// LatticeStatistics<Float> stats(SubImage<FLoat>(inImage), os);
147//
149//
150// Vector<Int> cursorAxes(2)
151// cursorAxes(0) = 1;
152// cursorAxes(1) = 2;
153// if (!stats.setAxes(cursorAxes)) return 1;
154//
156//
157// if (!stats.setList(True)) return 1;
158// String device = "/xs";
159// Vector<Int> nxy(2);
160// nxy(0) = 1;
161// nxy(1) = 1;
162// Vector<Int> statsToPlot = LatticeStatsBase::toStatisticTypes("mean,rms,sigma");
163// if (!stats.setPlotting(statsToPlot, device, nxy)) return 1;
164//
166//
167// if (!stats.display ()) return 1;
168//
170//
171// Array<Double> sum;
172// if (!stats.getStatistic(sum, LatticeStatsBase::SUM)) return 1;
173//
174// </srcBlock>
175// In this example, a <src>PagedImage</src> is constructed (which isA
176// MaskedLattice) with . We set the cursor axes
177// to be the y and z axes, we specify to list the statistics if we plot them,
178// and we ask to plot the mean, standard deviation, and root mean square of each
179// yz plane as a function of x location on the PGPLOT device "/xs" with
180// 1 subplot per page (there will be only one in this case). After the
181// plotting and listing, we also retrieve the sum of the selected pixels
182// as a function of x location into an array.
183// </example>
184
185// <motivation>
186// The generation of statistical information from a lattice is a basic
187// and necessary capability.
188// </motivation>
189
190// <todo asof="1996/11/26">
191// <li> Implement plotting for complex lattices
192// <li> Retrieve statistics at specified location of display axes
193// </todo>
194
195template <class T> class LatticeStatistics : public LatticeStatsBase
196{
197
198public:
199
201
202// Constructor takes the lattice and a <src>LogIO</src> object for logging.
203// You can specify whether you want to see progress meters or not.
204// You can force the storage lattice to be disk based, otherwise
205// the decision for core or disk is taken for you.
206// If <src>clone</src> is True, the input lattice will be cloned, so the caller
207// can make changes to the input lattice, but the statistics will reflect the
208// lattice as it was at construction. If False, a reference to the input lattice
209// is used, and so the caller shouldn't make changes to the input lattice between
210// construction and calling statistics computation methods, unless it calls setNewLattice()
211// to update the changed lattice. Obviously, cloning the lattice impacts performance
212// and memory usage.
214 LogIO& os,
215 Bool showProgress=True,
216 Bool forceDisk=False,
217 Bool clone=True);
218
219// Constructor takes the lattice only. In the absence of a logger you get no messages.
220// This includes error messages and potential listing of the statistics.
221// You can specify whether you want to see progress meters or not.
222// You can force the storage lattice to be disk based, otherwise
223// the decision for core or disk is taken for you.
225 Bool showProgress=True,
226 Bool forceDisk=False,
227 Bool clone=True);
228
229// Copy constructor. Copy semantics are followed. Therefore any storage lattice
230// that has already been created for <src>other</src> is copied to <src>*this</src>
232
233// Destructor
235
236// Assignment operator. Deletes any storage lattice associated with
237// the object being assigned to and copies any storage lattice that has
238// already been created for "other".
240
241// Set the cursor axes (0 relative). A return value of <src>False</src>
242// indicates you have asked for an invalid axis. The default state of the class
243// is to set the cursor axes to all axes in the lattice.
244 Bool setAxes (const Vector<Int>& cursorAxes);
245
246// You may specify a pixel intensity range as either one for which
247// all pixels in that range are included or one for which all pixels
248// in that range are excluded. One or the other of <src>include</src>
249// and <src>exclude</src> must therefore be a zero length vector if you
250// call this function. If you are setting an <src>include</src>
251// range, then if you set <src>setMinMaxToInclude=True</src>, the
252// minimum and maximum values that this class returns will always be
253// the minimum and maximum of the <src>include</src> range, respectively.
254// A return value of <src>False</src> indicates that
255// you have given both an <src>include</src> and an <src>exclude</src>
256// range. A vector of length 1 for <src>include</src> and/or <src>exclude</src>
257// means that the range will be set to (say for <src>include</src>)
258// <src>-abs(include(0))</src> to <src>abs(include(0))</src>. A return value
259// of <src>False</src> indicates that both an inclusion and exclusion
260// range were given or that the internal state of the class is bad. If you don't
261// call this function, the default state of the class is to include all pixels.
263 const Vector<T>& exclude,
264 Bool setMinMaxToInclude=False);
265
266// This function allows you to control whether the statistics are written to
267// the output stream if you are also making a plot. A return value of
268// <src>False</src> indicates that the internal state of the class is bad.
269// If you have created the <src>LatticeStatistics</src> object without
270// a <src>LogIO</src> object, you won't see any listings, but no error
271// conditions will be generated. The default state of the class is to
272// not list the output when making a plot.
273 Bool setList(const Bool& doList);
274
275// Display the statistics by listing and/or plotting them. If you don't call
276// this function then you won't see anything ! A return value of <src>False</src>
277// indicates an invalid plotting device, or that the internal state of the class is bad.
278
280
282 Int zAxis=-1, Int zLayer=-1,
283 Int hAxis=-1, Int hLayer=-1);
284
285 typedef std::pair<String,String> stat_element;
286 typedef std::list<stat_element> stat_list;
288 Int zAxis=-1, Int zLayer=-1,
289 Int hAxis=-1, Int hLayer=-1);
290
291// Return the display axes. The returned vector will be valid only if <src>setAxes</src>
292// has been called, or if one of the active "display" or "get*" methods has been called.
294
295// Recover the desired Statistic into an array. If you choose to use
296// the T version, be aware that the values in the AccumType version of the
297// Array may not be representable in the T version (e.g. large values for
298// SumSq). The shape of the
299// array is the shape of the display axes (e.g. if the shape of the lattice is
300// [nx,ny,nz] and you ask for the mean of the y axis the shape of the returned
301// array would be [nx,nz]. A returned array of zero shape indicates that there
302// were no good values. A return value of <src>False</src>
303// indicates that the internal state of the class is bad.
304// <group>
307// </group>
308
309// Recover position of min and max. Only works if there are no
310// display axes (i.e. statistics found over entire image), otherwise,
311// the returned values are resized to 0 shape. A return
312// value of <src>False</src> indicates that the internal state of
313// the class is bad.
315
316// This function gets a vector containing all the statistics
317// for a given location. If <src>posInLattice=True</src> then
318// the location is a location in the input lattice. Any
319// positions on the display axes are ignored. Otherwise, you
320// should just give locations for the display axes only.
321// Use can use the enum in class LatticeStatsBase to find out
322// which locations in the vector contain which statistics.
323// A returned vector of zero shape indicates that there
324// were no good values. A return value of <src>False</src>
325// indicates that the internal state of the class is bad.
327 const IPosition& pos,
328 const Bool posInLattice=False);
329
330// Reset argument error condition. If you specify invalid arguments to
331// one of the above <src>set</src> functions, an internal flag will be set which will
332// prevent the work functions from doing anything (should you have chosen
333// to ignore the Boolean return values of the <src>set</src> functions).
334// This function allows you to reset that internal state to good.
336
337// Get full lattice min and max only. Returns False if no unmasked data, else returns True.
338// Honours any include or exclude range if set.
339 Bool getFullMinMax (T& dataMin, T& dataMax);
340
341// Recover last error message
342 String errorMessage() const {return error_p;};
343
344// Set a new MaskedLattice object. A return value of <src>False</src> indicates the
345// lattice had an invalid type or that the internal state of the class is bad.
346// If <src>clone</src> is True, the input lattice will be cloned, so the caller
347// can make changes to the input lattice, but the statistics will reflect the
348// lattice as it was at construction. If False, a reference to the input lattice
349// is used, and so the caller shouldn't make changes to the input lattice between
350// construction and calling statistics computation methods, unless it calls setNewLattice()
351// to update the changed lattice. Obviously, cloning the lattice impacts performance
352// and memory usage.
354
355// Did we construct with a logger ?
356 Bool hasLogger () const {return haveLogger_p;};
357
358 // The configure methods return True if reconfiguration is actually
359 // necessary (ie if the underlying storage lattice needs to be recomputed).
360 // If no reconfiguration is necessary, False is returned.
361
362 // configure to use biweight algorithm.
364
365 // configure object to use Classical Statistics
366 // The time, t_x, it takes to compute classical statistics using algorithm x, can
367 // be modeled by
368 // t_x = n_sets*(a_x + b_x*n_el)
369 // where n_sets is the number of independent sets of data to compute stats on,
370 // each containing n_el number of elements. a_x is the time it takes to compute
371 // stats a a single set of data, and b_x is the time it takes to accumulate
372 // a single point.
373 // The old algorithm was developed in the early history of the project, I'm guessing
374 // by Neil Kileen, while the new algorithm was developed in 2015 by Dave Mehringer
375 // as part of the stats framework project. The old algorithm is faster in the regime
376 // of large n_sets and small n_el, while the new algorithm is faster in the
377 // regime of small n_sets and large n_el.
378 // If one always wants to use one of these algorithms, that algorithm's coefficients
379 // should be set to 0, while setting the other algorithm's coefficients to positive
380 // values. Note that it's the relative, not the absolute, values of these
381 // coeffecients that is important
382 // The version that takes no parameters uses the default values of the coefficients;
383 // <group>
385
387 // </group>
388
389 // configure to use fit to half algorithm.
393 AccumType centerValue=0
394 );
395
396 // configure to use hinges-fences algorithm
398
399 // configure to use Chauvenet's criterion
401 Double zscore=-1, Int maxIterations=-1
402 );
403
404 // <group>
405 // The force* methods are really only for testing. They in general shouldn't
406 // be called in production code. The last one to be called will be the one to
407 // be attempted to be used.
409
411
413 // </group>
414
416
417 // get number of iterations associated with Chauvenet criterion algorithm
418 std::map<String, uInt> getChauvenetNiter() const { return _chauvIters; }
419
420 // should quantile-like stats (median, quartiles, medabsdevmed) be computed?
421 // When the stats framework is used, It is better to set this before computing
422 // any statistics, to avoid unnecessary duplicate creations of the
423 // stats algorithm objects. Unnecessary recreation of these is a performance
424 // bottleneck for iterative stats algorithms (eg Chauvenet), especially for
425 // large images (CAS-10947/10948).
427
428protected:
429
434
435// doRobust means that when the storage lattice is generated, the
436// robust statistics are generated as well
437
442//
443// Virtual Functions. See implementation to figure it all out !
444
445 // FIXME The indirect dependence of this class on ImageInterface related
446 // issues (eg flux density) breaks encapsulation. All the ImageInterface related code should be
447 // encapsulated in ImageStatistics. Unfortunately, that requires significantly
448 // more time than I have atm. A return value of False means that the object in
449 // question cannot compute flux density values. The default implementation returns False.
450 virtual Bool _canDoFlux() const { return False; }
451
453 ThrowCc("Logic Error: This object cannot compute flux density");
454 }
455
456 virtual void listMinMax (ostringstream& osMin,
457 ostringstream& osMax,
458 Int oWidth, DataType type);
459
460 //
461
462// List the statistics to the logger. The implementation here
463// is adequate for all lattices. See ImageStatistics for an
464// example of where extra information is provided. hasBeam is
465// the return value of getBeamArea. If it is true, that means
466// that the FLUX statistics will be available in the storage
467// lattice. dPos is the location of the start of the cursor in the
468// storage image for this row. stats(j,i) is the statistics matrix.
469// for the jth point and the ith statistic.
470// The return value is False if something goes wrong !
471// Have a look at the implementation to see what you really
472// have to do.
473 virtual Bool listStats (Bool hasBeam, const IPosition& dPos,
474 const Matrix<AccumType>& ord);
476 const Matrix<AccumType>& ord,
477 ostringstream& rslt, Int zLayer);
478
479// Given a location in the storage lattice, convert those locations on the
480// non-statistics axis (the last one) and optionally account for the
481// lattice subsectioning
482 IPosition locInLattice (const IPosition& storagePosition,
483 Bool relativeToParent=True) const;
484
485// Non-virtual functions
486//
487// set stream manipulators
488 void setStream (ostream& os, Int oPrec);
489
490 // get the storage lattice shape
491 inline IPosition _storageLatticeShape() const { return pStoreLattice_p->shape(); }
492
494 Array<AccumType>& flux, const Array<AccumType>& npts, const Array<AccumType>& sum
495 );
496
498 Quantum<AccumType>& flux, AccumType sum, const IPosition& pos,
499 Bool posInLattice
500 );
501
502 // convert a position in the input lattice to the corresponding
503 // position in the stats storage lattice. The number of elements
504 // in storagePos will not be changed and only the first N elements
505 // will be modified where N = the number of elements in latticePos.
506 // <src>storagePos</src> must therefore have at least as many elements
507 // as <src>latticePos</src>. Returns False if
508 //<src>latticePos</src> is inconsistent with the input lattice.
510 IPosition& storagePos, const IPosition& latticePos
511 );
512
514
515private:
516
522
524 std::shared_ptr<const MaskedLattice<T>> _inLatPtrMgr;
525
526 std::shared_ptr<TempLattice<AccumType>> pStoreLattice_p;
530
533
536
538 std::map<String, uInt> _chauvIters;
539
541
542 // unset means let the code decide
543 std::unique_ptr<LatticeStatsAlgorithm> _latticeStatsAlgortihm;
544
546 // coefficients from timings run on PagedImages on
547 // etacarinae.cv.nrao.edu (dmehring's development
548 // machine)
549 _aOld = 4.7e-7;
550 _bOld = 2.3e-8;
551 _aNew = 1.6e-5;
552 _bNew = 1.5e-8;
553 }
554
555// Summarize the statistics found over the entire lattice
556 virtual void summStats();
557
558 virtual void displayStats(
560 AccumType medAbsDevMed, AccumType quartile, AccumType sumSq, AccumType mean,
561 AccumType var, AccumType rms, AccumType sigma, AccumType dMin, AccumType dMax,
562 AccumType q1, AccumType q3
563 );
564
565// Calculate statistic from storage lattice and return in an array
568 Bool dropDeg);
569
570 template <class U, class V>
572 AccumType& median, AccumType& medAbsDevMed, AccumType& q1, AccumType& q3,
573 std::shared_ptr<StatisticsAlgorithm<AccumType, U, V>> statsAlg,
574 uInt64 knownNpts, AccumType knownMin, AccumType knownMax
575 ) const;
576
577 template <class U, class V>
580 std::shared_ptr<StatisticsAlgorithm<AccumType, U, V>> statsAlg
581 ) const;
582
583// Find the median per cursorAxes chunk
585
586// Create a new storage lattice
588
589// Given a location in the lattice and a statistic type, work
590// out where to put it in the storage lattice
593
594// Find min and max of good data in arrays specified by pointers
595 void minMax (Bool& none, AccumType& dMin, AccumType& dMax,
596 const Vector<AccumType>& d,
597 const Vector<AccumType>& n) const;
598
599// Retrieve a statistic from the storage lattice and return in an array
602 const Bool dropDeg);
603
604// Retrieve a statistic from the storage lattice at the specified
605// location and return in an array
607 const IPosition& pos,
608 const Bool posInLattice);
609
610// Find the shape of slice from the statistics lattice at one
611// spatial pixel
613
614// See if there were some valid points found in the storage lattice
616
617// Stretch min and max by 5%
618 void stretchMinMax (AccumType& dMin, AccumType& dMax) const;
619
623 ) const;
624
625 void _doStatsLoop(uInt nsets, std::shared_ptr<LattStatsProgress> progressMeter);
626
628 std::shared_ptr<LattStatsProgress> progressMeter,
629 const IPosition& cursorShape
630 );
631
633 LatticeStepper& stepper, SubLattice<T> subLat, Slicer& slicer,
634 std::shared_ptr<LattStatsProgress> progressMeter, uInt nsets
635 );
636
638
640 std::vector<
641 std::shared_ptr<
645 >
646 >
647 >& sa, T& overallMin, T& overallMax, IPosition& arrayShape,
648 std::vector<Array<T>>& dataArray,
649 std::vector<Array<Bool>>& maskArray, std::vector<IPosition>& curPos,
650 uInt nthreads, Bool isChauv,
651 Bool isMasked, Bool isReal, std::shared_ptr<const DataRanges> range
652 );
653
655 T currentMin, T currentMax, const IPosition& curPos,
656 const StatsData<AccumType>& stats, Bool doQuantiles,
657 AccumType q1=0, AccumType q3=0
658 );
659
660 inline static AccumType _mean(const AccumType& sum, const AccumType& npts) {
661 return npts <= 0 ? 0 : sum/npts;
662 }
663
664 inline static AccumType _rms(const AccumType& sumsq, const AccumType& npts) {
665 return npts <= 0 ? 0 : sqrt(sumsq/npts);
666 }
667
669 T& overallMin, T& overallMax, T currentMin, T currentMax,
670 const IPosition& minPos, const IPosition& maxPos, Bool atStart
671 );
672
673};
674
675//# Declare extern templates for often used types.
676 extern template class LatticeStatistics<Float>;
677
678
679} //# NAMESPACE CASA - END
680
681#ifndef CASACORE_NO_AUTO_TEMPLATES
682#include <casacore/lattices/LatticeMath/LatticeStatistics.tcc>
683#endif //# CASACORE_NO_AUTO_TEMPLATES
684#endif
#define ThrowCc(m)
Definition Error.h:83
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 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.
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)
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 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
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...
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 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
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)
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 _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.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
LatticeExprNode mean(const LatticeExprNode &expr)
LatticeExprNode sum(const LatticeExprNode &expr)
unsigned int uInt
Definition aipstype.h:49
LatticeExprNode sqrt(const LatticeExprNode &expr)
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
const Bool True
Definition aipstype.h:41
double Double
Definition aipstype.h:53
LatticeExprNode median(const LatticeExprNode &expr)
unsigned long long uInt64
Definition aipsxtype.h:37
TableExprNode rms(const TableExprNode &array)
Definition ExprNode.h:1684