casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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: aips2-request@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 //# $Id$
27 
28 #ifndef LATTICES_LATTICESTATISTICS_H
29 #define LATTICES_LATTICESTATISTICS_H
30 
31 #include <casacore/casa/aips.h>
50 
51 #include <vector>
52 #include <list>
53 
54 namespace casacore { //# NAMESPACE CASACORE - BEGIN
55 
56 //# Forward Declarations
57 template <class T> class MaskedLattice;
58 template <class T> class SubLattice;
59 template <class T> class TempLattice;
60 class IPosition;
61 
63 
64 // <summary>
65 // Compute and display various statistics from a lattice
66 // </summary>
67 // <use visibility=export>
68 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
69 // </reviewed>
70 // <prerequisite>
71 // <li> <linkto class=LatticeStatsBase>LatticeStatsBase</linkto>
72 // <li> <linkto class=MaskedLattice>MaskedLattice</linkto>
73 // </prerequisite>
74 
75 // <etymology>
76 // This is a class designed to display and retrieve statistics from lattices
77 // </etymology>
78 
79 // <synopsis>
80 // This class enable you to display and/or retrieve statistics evaluated over
81 // specified regions of a lattice. The dimension of the region is arbitrary, but
82 // the size of each dimension is always the shape of the corresponding lattice axis.
83 // The statistics are displayed as a function of location of the axes not
84 // used to evaluate the statistics over. The axes which you evaluate the statistics
85 // over are called the cursor axes, the others are called the display axes.
86 //
87 // For example, consider a lattice cube (call the axes xyz or [0,1,2]). You could
88 // display statistics from xy planes (cursor axes [0,1]) as a function of z (display
89 // axes [2]). Or you could retrieve statistics from the z axis (cursor axes [2])
90 // for each [x,y] location (display axes [0,1]).
91 //
92 // This class inherits from <linkto class="LatticeStatsBase">LatticeStatsBase</linkto>
93 // This base class provides an <src>enum</src> defining allowed statistics types and a
94 // helper function to convert between a <src>String</src> and a
95 // <src>Vector<Int></src> describing the desired statistics to plot.
96 // An example is shown below.
97 //
98 // This class can list, plot and retrieve statistics. When it lists statistics,
99 // it always lists all the available statistics. When you plot statistics,
100 // you must specify which ones you would like to see.
101 //
102 // This class generates a "storage lattice" into which it writes the accumulated
103 // statistical sums. It is from this storage lattice that the plotting and retrieval
104 // arrays are drawn. The storage lattice is either in core or on disk
105 // depending upon its size (if > 10% of memory given by .aipsrc system.resources.memory
106 // then it goes into a disk-based PagedArray). If on disk, the
107 // storage lattice is deleted when the <src>LatticeStatistics</src> class
108 // object destructs. However, currently, if the process is terminated ungracefully,
109 // the storage lattice will be left over.
110 // </synopsis>
111 //
112 // <note role=tip>
113 // This class has a few virtual functions; they are not part of a nice general
114 // polymorphic interface; rather they have specialized functionality. The idea
115 // of these is that you can derive a class from LatticeStatistics, such as
116 // <linkto class="ImageStatistics">ImageStatistics</linkto> which provides
117 // you with a little more information when displaying/logging the
118 // statistics (such as world coordinates)
119 // The virtual functions are
120 // <ul>
121 // <li> <src>getBeamArea</src> can be used to return the synthesized beam
122 // area so that the FLUX statistic can be computed
123 // <li> <src>listStats</src> is used to list the statistics to the logger
124 // <li> <src>getLabelsM</src> find the X-axis label and the title label
125 // for the plotting.
126 // </ul>
127 // </note>
128 //
129 // <note role=tip>
130 // If you ignore return error statuses from the functions that set the
131 // state of the class, the internal status of the class is set to bad.
132 // This means it will just keep on returning error conditions until you
133 // explicitly recover the situation. A message describing the last
134 // error condition can be recovered with function errorMessage.
135 // </note>
136 
137 
138 // <example>
139 // <srcBlock>
141 //
142 // PagedImage<Float> inImage(inName);
143 //
145 //
146 // LogOrigin or("myClass", "myFunction(...)", WHERE);
147 // LogIO os(or);
148 // LatticeStatistics<Float> stats(SubImage<FLoat>(inImage), os);
149 //
151 //
152 // Vector<Int> cursorAxes(2)
153 // cursorAxes(0) = 1;
154 // cursorAxes(1) = 2;
155 // if (!stats.setAxes(cursorAxes)) return 1;
156 //
158 //
159 // if (!stats.setList(True)) return 1;
160 // String device = "/xs";
161 // Vector<Int> nxy(2);
162 // nxy(0) = 1;
163 // nxy(1) = 1;
164 // Vector<Int> statsToPlot = LatticeStatsBase::toStatisticTypes("mean,rms,sigma");
165 // if (!stats.setPlotting(statsToPlot, device, nxy)) return 1;
166 //
168 //
169 // if (!stats.display ()) return 1;
170 //
172 //
173 // Array<Double> sum;
174 // if (!stats.getStatistic(sum, LatticeStatsBase::SUM)) return 1;
175 //
176 // </srcBlock>
177 // In this example, a <src>PagedImage</src> is constructed (which isA
178 // MaskedLattice) with . We set the cursor axes
179 // to be the y and z axes, we specify to list the statistics if we plot them,
180 // and we ask to plot the mean, standard deviation, and root mean square of each
181 // yz plane as a function of x location on the PGPLOT device "/xs" with
182 // 1 subplot per page (there will be only one in this case). After the
183 // plotting and listing, we also retrieve the sum of the selected pixels
184 // as a function of x location into an array.
185 // </example>
186 
187 // <motivation>
188 // The generation of statistical information from a lattice is a basic
189 // and necessary capability.
190 // </motivation>
191 
192 // <todo asof="1996/11/26">
193 // <li> Implement plotting for complex lattices
194 // <li> Retrieve statistics at specified location of display axes
195 // </todo>
196 
197 template <class T> class LatticeStatistics : public LatticeStatsBase
198 {
199 
200 public:
201 
203 
204 // Constructor takes the lattice and a <src>LogIO</src> object for logging.
205 // You can specify whether you want to see progress meters or not.
206 // You can force the storage lattice to be disk based, otherwise
207 // the decision for core or disk is taken for you.
208 // If <src>clone</src> is True, the input lattice will be cloned, so the caller
209 // can make changes to the input lattice, but the statistics will reflect the
210 // lattice as it was at construction. If False, a reference to the input lattice
211 // is used, and so the caller shouldn't make changes to the input lattice between
212 // construction and calling statistics computation methods, unless it calls setNewLattice()
213 // to update the changed lattice. Obviously, cloning the lattice impacts performance
214 // and memory usage.
215  LatticeStatistics (const MaskedLattice<T>& lattice,
216  LogIO& os,
217  Bool showProgress=True,
218  Bool forceDisk=False,
219  Bool clone=True);
220 
221 // Constructor takes the lattice only. In the absence of a logger you get no messages.
222 // This includes error messages and potential listing of the statistics.
223 // You can specify whether you want to see progress meters or not.
224 // You can force the storage lattice to be disk based, otherwise
225 // the decision for core or disk is taken for you.
226  LatticeStatistics (const MaskedLattice<T>& lattice,
227  Bool showProgress=True,
228  Bool forceDisk=False,
229  Bool clone=True);
230 
231 // Copy constructor. Copy semantics are followed. Therefore any storage lattice
232 // that has already been created for <src>other</src> is copied to <src>*this</src>
234 
235 // Destructor
236  virtual ~LatticeStatistics ();
237 
238 // Assignment operator. Deletes any storage lattice associated with
239 // the object being assigned to and copies any storage lattice that has
240 // already been created for "other".
242 
243 // Set the cursor axes (0 relative). A return value of <src>False</src>
244 // indicates you have asked for an invalid axis. The default state of the class
245 // is to set the cursor axes to all axes in the lattice.
246  Bool setAxes (const Vector<Int>& cursorAxes);
247 
248 // You may specify a pixel intensity range as either one for which
249 // all pixels in that range are included or one for which all pixels
250 // in that range are excluded. One or the other of <src>include</src>
251 // and <src>exclude</src> must therefore be a zero length vector if you
252 // call this function. If you are setting an <src>include</src>
253 // range, then if you set <src>setMinMaxToInclude=True</src>, the
254 // minimum and maximum values that this class returns will always be
255 // the minimum and maximum of the <src>include</src> range, respectively.
256 // A return value of <src>False</src> indicates that
257 // you have given both an <src>include</src> and an <src>exclude</src>
258 // range. A vector of length 1 for <src>include</src> and/or <src>exclude</src>
259 // means that the range will be set to (say for <src>include</src>)
260 // <src>-abs(include(0))</src> to <src>abs(include(0))</src>. A return value
261 // of <src>False</src> indicates that both an inclusion and exclusion
262 // range were given or that the internal state of the class is bad. If you don't
263 // call this function, the default state of the class is to include all pixels.
264  Bool setInExCludeRange(const Vector<T>& include,
265  const Vector<T>& exclude,
266  Bool setMinMaxToInclude=False);
267 
268 // This function allows you to control whether the statistics are written to
269 // the output stream if you are also making a plot. A return value of
270 // <src>False</src> indicates that the internal state of the class is bad.
271 // If you have created the <src>LatticeStatistics</src> object without
272 // a <src>LogIO</src> object, you won't see any listings, but no error
273 // conditions will be generated. The default state of the class is to
274 // not list the output when making a plot.
275  Bool setList(const Bool& doList);
276 
277 // Display the statistics by listing and/or plotting them. If you don't call
278 // this function then you won't see anything ! A return value of <src>False</src>
279 // indicates an invalid plotting device, or that the internal state of the class is bad.
280 
281  Bool display();
282 
283  Bool getLayerStats(String& stats, Double area,
284  Int zAxis=-1, Int zLayer=-1,
285  Int hAxis=-1, Int hLayer=-1);
286 
287  typedef std::pair<String,String> stat_element;
288  typedef std::list<stat_element> stat_list;
289  Bool getLayerStats( stat_list &stats, Double area,
290  Int zAxis=-1, Int zLayer=-1,
291  Int hAxis=-1, Int hLayer=-1);
292 
293 // Return the display axes. The returned vector will be valid only if <src>setAxes</src>
294 // has been called, or if one of the active "display" or "get*" methods has been called.
296 
297 // Recover the desired Statistic into an array. If you choose to use
298 // the T version, be aware that the values in the AccumType version of the
299 // Array may not be representable in the T version (e.g. large values for
300 // SumSq). The shape of the
301 // array is the shape of the display axes (e.g. if the shape of the lattice is
302 // [nx,ny,nz] and you ask for the mean of the y axis the shape of the returned
303 // array would be [nx,nz]. A returned array of zero shape indicates that there
304 // were no good values. A return value of <src>False</src>
305 // indicates that the internal state of the class is bad.
306 // <group>
309 // </group>
310 
311 // Recover position of min and max. Only works if there are no
312 // display axes (i.e. statistics found over entire image), otherwise,
313 // the returned values are resized to 0 shape. A return
314 // value of <src>False</src> indicates that the internal state of
315 // the class is bad.
316  Bool getMinMaxPos(IPosition& minPos, IPosition& maxPos);
317 
318 // This function gets a vector containing all the statistics
319 // for a given location. If <src>posInLattice=True</src> then
320 // the location is a location in the input lattice. Any
321 // positions on the display axes are ignored. Otherwise, you
322 // should just give locations for the display axes only.
323 // Use can use the enum in class LatticeStatsBase to find out
324 // which locations in the vector contain which statistics.
325 // A returned vector of zero shape indicates that there
326 // were no good values. A return value of <src>False</src>
327 // indicates that the internal state of the class is bad.
329  const IPosition& pos,
330  const Bool posInLattice=False);
331 
332 // Reset argument error condition. If you specify invalid arguments to
333 // one of the above <src>set</src> functions, an internal flag will be set which will
334 // prevent the work functions from doing anything (should you have chosen
335 // to ignore the Boolean return values of the <src>set</src> functions).
336 // This function allows you to reset that internal state to good.
338 
339 // Get full lattice min and max only. Returns False if no unmasked data, else returns True.
340 // Honours any include or exclude range if set.
341  Bool getFullMinMax (T& dataMin, T& dataMax);
342 
343 // Recover last error message
344  String errorMessage() const {return error_p;};
345 
346 // Set a new MaskedLattice object. A return value of <src>False</src> indicates the
347 // lattice had an invalid type or that the internal state of the class is bad.
348 // If <src>clone</src> is True, the input lattice will be cloned, so the caller
349 // can make changes to the input lattice, but the statistics will reflect the
350 // lattice as it was at construction. If False, a reference to the input lattice
351 // is used, and so the caller shouldn't make changes to the input lattice between
352 // construction and calling statistics computation methods, unless it calls setNewLattice()
353 // to update the changed lattice. Obviously, cloning the lattice impacts performance
354 // and memory usage.
356 
357 // Did we construct with a logger ?
358  Bool hasLogger () const {return haveLogger_p;};
359 
360  // The configure methods return True if reconfiguration is actually
361  // necessary (ie if the underlying storage lattice needs to be recomputed).
362  // If no reconfiguration is necessary, False is returned.
363 
364  // configure to use biweight algorithm.
365  Bool configureBiweight(Int maxIter, Double c);
366 
367  // configure object to use Classical Statistics
368  // The time, t_x, it takes to compute classical statistics using algorithm x, can
369  // be modeled by
370  // t_x = n_sets*(a_x + b_x*n_el)
371  // where n_sets is the number of independent sets of data to compute stats on,
372  // each containing n_el number of elements. a_x is the time it takes to compute
373  // stats a a single set of data, and b_x is the time it takes to accumulate
374  // a single point.
375  // The old algorithm was developed in the early history of the project, I'm guessing
376  // by Neil Kileen, while the new algorithm was developed in 2015 by Dave Mehringer
377  // as part of the stats framework project. The old algorithm is faster in the regime
378  // of large n_sets and small n_el, while the new algorithm is faster in the
379  // regime of small n_sets and large n_el.
380  // If one always wants to use one of these algorithms, that algorithm's coefficients
381  // should be set to 0, while setting the other algorithm's coefficients to positive
382  // values. Note that it's the relative, not the absolute, values of these
383  // coeffecients that is important
384  // The version that takes no parameters uses the default values of the coefficients;
385  // <group>
387 
388  Bool configureClassical(Double aOld, Double bOld, Double aNew, Double bNew);
389  // </group>
390 
391  // configure to use fit to half algorithm.
395  AccumType centerValue=0
396  );
397 
398  // configure to use hinges-fences algorithm
400 
401  // configure to use Chauvenet's criterion
403  Double zscore=-1, Int maxIterations=-1
404  );
405 
406  // <group>
407  // The force* methods are really only for testing. They in general shouldn't
408  // be called in production code. The last one to be called will be the one to
409  // be attempted to be used.
411 
413 
415  // </group>
416 
418 
419  // get number of iterations associated with Chauvenet criterion algorithm
420  std::map<String, uInt> getChauvenetNiter() const { return _chauvIters; }
421 
422  // should quantile-like stats (median, quartiles, medabsdevmed) be computed?
423  // When the stats framework is used, It is better to set this before computing
424  // any statistics, to avoid unnecessary duplicate creations of the
425  // stats algorithm objects. Unnecessary recreation of these is a performance
426  // bottleneck for iterative stats algorithms (eg Chauvenet), especially for
427  // large images (CAS-10947/10948).
428  void setComputeQuantiles(Bool b);
429 
430 protected:
431 
436 
437 // doRobust means that when the storage lattice is generated, the
438 // robust statistics are generated as well
439 
444 //
445 // Virtual Functions. See implementation to figure it all out !
446 
447  // FIXME The indirect dependence of this class on ImageInterface related
448  // issues (eg flux density) breaks encapsulation. All the ImageInterface related code should be
449  // encapsulated in ImageStatistics. Unfortunately, that requires significantly
450  // more time than I have atm. A return value of False means that the object in
451  // question cannot compute flux density values. The default implementation returns False.
452  virtual Bool _canDoFlux() const { return False; }
453 
455  ThrowCc("Logic Error: This object cannot compute flux density");
456  }
457 
458  virtual void listMinMax (ostringstream& osMin,
459  ostringstream& osMax,
460  Int oWidth, DataType type);
461 
462  //
463 
464 // List the statistics to the logger. The implementation here
465 // is adequate for all lattices. See ImageStatistics for an
466 // example of where extra information is provided. hasBeam is
467 // the return value of getBeamArea. If it is true, that means
468 // that the FLUX statistics will be available in the storage
469 // lattice. dPos is the location of the start of the cursor in the
470 // storage image for this row. stats(j,i) is the statistics matrix.
471 // for the jth point and the ith statistic.
472 // The return value is False if something goes wrong !
473 // Have a look at the implementation to see what you really
474 // have to do.
475  virtual Bool listStats (Bool hasBeam, const IPosition& dPos,
476  const Matrix<AccumType>& ord);
477  virtual Bool listLayerStats (
478  const Matrix<AccumType>& ord,
479  ostringstream& rslt, Int zLayer);
480 
481 // Given a location in the storage lattice, convert those locations on the
482 // non-statistics axis (the last one) and optionally account for the
483 // lattice subsectioning
484  IPosition locInLattice (const IPosition& storagePosition,
485  Bool relativeToParent=True) const;
486 
487 // Non-virtual functions
488 //
489 // set stream manipulators
490  void setStream (ostream& os, Int oPrec);
491 
492  // get the storage lattice shape
493  inline IPosition _storageLatticeShape() const { return pStoreLattice_p->shape(); }
494 
495  virtual Bool _computeFlux(
496  Array<AccumType>& flux, const Array<AccumType>& npts, const Array<AccumType>& sum
497  );
498 
499  virtual Bool _computeFlux(
500  Quantum<AccumType>& flux, AccumType sum, const IPosition& pos,
501  Bool posInLattice
502  );
503 
504  // convert a position in the input lattice to the corresponding
505  // position in the stats storage lattice. The number of elements
506  // in storagePos will not be changed and only the first N elements
507  // will be modified where N = the number of elements in latticePos.
508  // <src>storagePos</src> must therefore have at least as many elements
509  // as <src>latticePos</src>. Returns False if
510  //<src>latticePos</src> is inconsistent with the input lattice.
512  IPosition& storagePos, const IPosition& latticePos
513  );
514 
516 
517 private:
518 
523  };
524 
526  std::shared_ptr<const MaskedLattice<T> > _inLatPtrMgr;
527 
532 
535 
538 
540  std::map<String, uInt> _chauvIters;
541 
543 
544  // unset means let the code decide
546 
548  // coefficients from timings run on PagedImages on
549  // etacarinae.cv.nrao.edu (dmehring's development
550  // machine)
551  _aOld = 4.7e-7;
552  _bOld = 2.3e-8;
553  _aNew = 1.6e-5;
554  _bNew = 1.5e-8;
555  }
556 
557 // Summarize the statistics found over the entire lattice
558  virtual void summStats();
559 
560  virtual void displayStats(
562  AccumType medAbsDevMed, AccumType quartile, AccumType sumSq, AccumType mean,
563  AccumType var, AccumType rms, AccumType sigma, AccumType dMin, AccumType dMax,
564  AccumType q1, AccumType q3
565  );
566 
567 // Calculate statistic from storage lattice and return in an array
570  Bool dropDeg);
571 
572  template <class U, class V>
573  void _computeQuantiles(
574  AccumType& median, AccumType& medAbsDevMed, AccumType& q1, AccumType& q3,
576  uInt64 knownNpts, AccumType knownMin, AccumType knownMax
577  ) const;
578 
579  template <class U, class V>
581  StatsData<AccumType>& stats, AccumType& q1, AccumType& q3,
583  ) const;
584 
585 // Find the median per cursorAxes chunk
586  void generateRobust ();
587 
588 // Create a new storage lattice
590 
591 // Given a location in the lattice and a statistic type, work
592 // out where to put it in the storage lattice
593  IPosition locInStorageLattice(const IPosition& latticePosition,
595 
596 // Find min and max of good data in arrays specified by pointers
597  void minMax (Bool& none, AccumType& dMin, AccumType& dMax,
598  const Vector<AccumType>& d,
599  const Vector<AccumType>& n) const;
600 
601 // Retrieve a statistic from the storage lattice and return in an array
604  const Bool dropDeg);
605 
606 // Retrieve a statistic from the storage lattice at the specified
607 // location and return in an array
609  const IPosition& pos,
610  const Bool posInLattice);
611 
612 // Find the shape of slice from the statistics lattice at one
613 // spatial pixel
614  IPosition statsSliceShape () const;
615 
616 // See if there were some valid points found in the storage lattice
617  Bool someGoodPoints ();
618 
619 // Stretch min and max by 5%
620  void stretchMinMax (AccumType& dMin, AccumType& dMax) const;
621 
625  ) const;
626 
627  void _doStatsLoop(uInt nsets, CountedPtr<LattStatsProgress> progressMeter);
628 
630  SubLattice<T> subLat, CountedPtr<LattStatsProgress> progressMeter,
631  const IPosition& cursorShape
632  );
633 
635  LatticeStepper& stepper, SubLattice<T> subLat, Slicer& slicer,
636  CountedPtr<LattStatsProgress> progressMeter, uInt nsets
637  );
638 
640 
642  std::vector<
643  CountedPtr<
647  >
648  >
649  >& sa, T& overallMin, T& overallMax, IPosition& arrayShape,
650  std::vector<Array<T> >& dataArray,
651  std::vector<Array<Bool> >& maskArray, std::vector<IPosition>& curPos,
652  uInt nthreads, const SubLattice<T>& subLat, Bool isChauv,
653  Bool isMasked, Bool isReal, CountedPtr<const DataRanges> range
654  );
655 
656  void _fillStorageLattice(
657  T currentMin, T currentMax, const IPosition& curPos,
658  const StatsData<AccumType>& stats, Bool doQuantiles,
659  AccumType q1=0, AccumType q3=0
660  );
661 
662  inline static AccumType _mean(const AccumType& sum, const AccumType& npts) {
663  return npts <= 0 ? 0 : sum/npts;
664  }
665 
666  inline static AccumType _rms(const AccumType& sumsq, const AccumType& npts) {
667  return npts <= 0 ? 0 : sqrt(sumsq/npts);
668  }
669 
670  void _updateMinMaxPos(
671  T& overallMin, T& overallMax, T currentMin, T currentMax,
672  const IPosition& minPos, const IPosition& maxPos,
673  Bool atStart, const SubLattice<T>& subLat
674  );
675 
676 };
677 
678 //# Declare extern templates for often used types.
679  extern template class LatticeStatistics<Float>;
680 
681 
682 } //# NAMESPACE CASA - END
683 
684 #ifndef CASACORE_NO_AUTO_TEMPLATES
685 #include <casacore/lattices/LatticeMath/LatticeStatistics.tcc>
686 #endif //# CASACORE_NO_AUTO_TEMPLATES
687 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
void forceAllowCodeDecideWhichAlgortihmToUse()
virtual Bool listLayerStats(const Matrix< AccumType > &ord, ostringstream &rslt, Int zLayer)
A subset of a Lattice or MaskedLattice.
void _computeQuantiles(AccumType &median, AccumType &medAbsDevMed, AccumType &q1, AccumType &q3, CountedPtr< StatisticsAlgorithm< AccumType, U, V > > statsAlg, uInt64 knownNpts, AccumType knownMin, AccumType knownMax) const
int Int
Definition: aipstype.h:50
std::shared_ptr< const MaskedLattice< T > > _inLatPtrMgr
PtrHolder< LatticeStatsAlgorithm > _latticeStatsAlgortihm
unset means let the code decide
void _computeQuantilesForStatsFramework(StatsData< AccumType > &stats, AccumType &q1, AccumType &q3, CountedPtr< StatisticsAlgorithm< AccumType, U, V > > statsAlg) const
void forceUseStatsFrameworkUsingDataProviders()
The force* methods are really only for testing.
LatticeExprNode median(const LatticeExprNode &expr)
Bool retrieveStorageStatistic(Array< AccumType > &slice, const LatticeStatsBase::StatisticsTypes type, const Bool dropDeg)
Retrieve a statistic from the storage lattice and return in an array.
std::map< String, uInt > _chauvIters
Bool getMinMaxPos(IPosition &minPos, IPosition &maxPos)
Recover position of min and max.
Vector< Int > displayAxes() const
Return the display axes.
virtual Quantum< AccumType > _flux(Bool &, AccumType, Double) const
const MaskedLattice< T > * pInLattice_p
LatticeExprNode sum(const LatticeExprNode &expr)
unsigned long long uInt64
Definition: aipsxtype.h:39
virtual Bool _canDoFlux() const
Virtual Functions.
Bool someGoodPoints()
See if there were some valid points found in the storage lattice.
void _doComputationUsingArrays(std::vector< CountedPtr< 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, const SubLattice< T > &subLat, Bool isChauv, Bool isMasked, Bool isReal, CountedPtr< const DataRanges > range)
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.
A templated, abstract base class for array-like objects with masks.
Bool setList(const Bool &doList)
This function allows you to control whether the statistics are written to the output stream if you ar...
virtual casacore::String type() const
Implements RegionShape::type.
Definition: RegionShapes.h:548
Data provider which allows stats framework to iterate through an unmasked lattice.
virtual ~LatticeStatistics()
Destructor.
A 2-D Specialization of the Array class.
ostream-like interface to creating log messages.
Definition: LogIO.h:167
Bool getStatistic(Array< AccumType > &stat, LatticeStatsBase::StatisticsTypes type, Bool dropDeg=True)
Recover the desired Statistic into an array.
Bool configureClassical()
configure object to use Classical Statistics The time, t_x, it takes to compute classical statistics ...
void _computeStatsUsingArrays(SubLattice< T > subLat, CountedPtr< LattStatsProgress > progressMeter, const IPosition &cursorShape)
std::list< stat_element > stat_list
Traverse a Lattice by cursor shape.
USE_DATA
which section of data to use, greater than or less than the center value
void _doStatsLoop(uInt nsets, CountedPtr< LattStatsProgress > progressMeter)
std::pair< String, String > stat_element
void _computeStatsUsingLattDataProviders(LatticeStepper &stepper, SubLattice< T > subLat, Slicer &slicer, CountedPtr< LattStatsProgress > progressMeter, uInt nsets)
Bool calculateStatistic(Array< AccumType > &slice, LatticeStatsBase::StatisticsTypes type, Bool dropDeg)
Calculate statistic from storage lattice and return in an array.
void stretchMinMax(AccumType &dMin, AccumType &dMax) const
Stretch min and max by 5%.
Bool doRobust_p
doRobust means that when the storage lattice is generated, the robust statistics are generated as wel...
LatticeStatistics< T > & operator=(const LatticeStatistics< T > &other)
Assignment operator.
Bool display()
Display the statistics by listing and/or plotting them.
ALGORITHM
implemented algorithms
Bool getFullMinMax(T &dataMin, T &dataMax)
Get full lattice min and max only.
Bool setNewLattice(const MaskedLattice< T > &lattice, Bool clone=True)
Set a new MaskedLattice object.
void generateRobust()
Find the median per cursorAxes chunk.
virtual void summStats()
Summarize the statistics found over the entire lattice.
CENTER
choice of center point based on the corresponding statistics from the entire distribution of data...
Bool getLayerStats(String &stats, Double area, Int zAxis=-1, Int zLayer=-1, Int hAxis=-1, Int hLayer=-1)
IPosition statsSliceShape() const
Find the shape of slice from the statistics lattice at one spatial pixel.
Char PrecisionType
Higher precision type (Float-&gt;Double)
String errorMessage() const
Recover last error message.
Data provider which allows stats framework to iterate through a masked lattice.
IPosition _cursorShapeForArrayMethod(uInt64 setSize) const
Referenced counted pointer for constant data.
Definition: VisModelData.h:42
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.
double Double
Definition: aipstype.h:55
void _updateMinMaxPos(T &overallMin, T &overallMax, T currentMin, T currentMax, const IPosition &minPos, const IPosition &maxPos, Bool atStart, const SubLattice< T > &subLat)
Compute and display various statistics from a lattice.
Definition: LatticePADD.h:47
LatticeExprNode sqrt(const LatticeExprNode &expr)
virtual Bool _computeFlux(Array< AccumType > &flux, const Array< AccumType > &npts, const Array< AccumType > &sum)
Bool getConvertedStatistic(Array< T > &stat, LatticeStatsBase::StatisticsTypes type, Bool dropDeg=True)
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void setStream(ostream &os, Int oPrec)
Non-virtual functions.
void _latticePosToStoragePos(IPosition &storagePos, const IPosition &latticePos)
convert a position in the input lattice to the corresponding position in the stats storage lattice...
IPosition _storageLatticeShape() const
get the storage lattice shape
Bool configureHingesFences(Double f)
configure to use hinges-fences algorithm
StatisticsTypes
This enum StatisticTypes is provided for use with the LatticeStatistics&lt;T&gt;::setPlotting function...
void _fillStorageLattice(T currentMin, T currentMax, const IPosition &curPos, const StatsData< AccumType > &stats, Bool doQuantiles, AccumType q1=0, AccumType q3=0)
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...
casacore::Bool clone(const casacore::String &imageName, const casacore::String &newImageName)
Quantities (i.e. dimensioned values)
Definition: QuantumHolder.h:44
Bool hasLogger() const
Did we construct with a logger ?
Bool setAxes(const Vector< Int > &cursorAxes)
Set the cursor axes (0 relative).
virtual void listMinMax(ostringstream &osMin, ostringstream &osMax, Int oWidth, DataType type)
const Bool False
Definition: aipstype.h:44
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...
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
Specify which elements to extract from an n-dimensional array.
Definition: Slicer.h:289
Bool getStats(Vector< AccumType > &, const IPosition &pos, const Bool posInLattice=False)
This function gets a vector containing all the statistics for a given location.
Bool generateStorageLattice()
Create a new storage lattice.
#define ThrowCc(m)
Definition: Error.h:85
Bool configureBiweight(Int maxIter, Double c)
The configure methods return True if reconfiguration is actually necessary (ie if the underlying stor...
LatticeExprNode mean(const LatticeExprNode &expr)
CountedPtr< TempLattice< AccumType > > pStoreLattice_p
TableExprNode rms(const TableExprNode &array)
Definition: ExprNode.h:1637
const Double c
Fundamental physical constants (SI units):
Bool configureChauvenet(Double zscore=-1, Int maxIterations=-1)
configure to use Chauvenet&#39;s criterion
StatisticsData::ALGORITHM _getAlgorithm() const
std::map< String, uInt > getChauvenetNiter() const
get number of iterations associated with Chauvenet criterion algorithm
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual Bool listStats(Bool hasBeam, const IPosition &dPos, const Matrix< AccumType > &ord)
List the statistics to the logger.
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 last...
NumericTraits< T >::PrecisionType AccumType
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 configureFitToHalf(FitToHalfStatisticsData::CENTER centerType=FitToHalfStatisticsData::CMEAN, FitToHalfStatisticsData::USE_DATA useData=FitToHalfStatisticsData::LE_CENTER, AccumType centerValue=0)
configure to use fit to half algorithm.
Base class of statistics algorithm class hierarchy.
const Bool True
Definition: aipstype.h:43
void _configureDataProviders(LatticeStatsDataProvider< T > &lattDP, MaskedLatticeStatsDataProvider< T > &maskedLattDP) const
static AccumType _rms(const AccumType &sumsq, const AccumType &npts)
void resetError()
Reset argument error condition.
static AccumType _mean(const AccumType &sum, const AccumType &npts)
void setComputeQuantiles(Bool b)
should quantile-like stats (median, quartiles, medabsdevmed) be computed? When the stats framework is...
unsigned int uInt
Definition: aipstype.h:51
StatisticsAlgorithmFactory< AccumType, const T *, const Bool * > _saf
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42