casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StatsTiledCollapser.h
Go to the documentation of this file.
1 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This library is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU Library General Public License as published by
6 //# the Free Software Foundation; either version 2 of the License, or (at your
7 //# option) any later version.
8 //#
9 //# This library is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 //# License for more details.
13 //#
14 //# You should have received a copy of the GNU Library General Public License
15 //# along with this library; if not, write to the Free Software Foundation,
16 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email: aips2-request@nrao.edu.
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 //#
25 //# $Id: LatticeStatistics.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $
26 
27 #ifndef LATTICES_STATSTILEDCOLLAPSER_H
28 #define LATTICES_STATSTILEDCOLLAPSER_H
29 
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 
34 namespace casacore {
35 
36 
37 // <summary> Generate statistics, tile by tile, from a masked lattice </summary>
38 
39 // NOTE this version was moved from LatticeStatistics (early Dec 2014 version)
40 // and slightly modified mostly for style issues (no significant semantic differences
41 // from that version). For a large number of statistics sets that need to be computed
42 // simultaneously, this version is more efficient than using the new stats framework,
43 // because creating large numbers of eg ClassicalStatistics objects is much less efficient
44 // than the direct manipulation of pointers to primitive types that this class does.
45 //
46 // <use visibility=export>
47 //
48 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
49 // </reviewed>
50 //
51 // <prerequisite>
52 // <li> <linkto class=LatticeApply>LatticeApply</linkto>
53 // <li> <linkto class=TiledCollapser>TiledCollapser</linkto>
54 // </prerequisite>
55 //
56 // <etymology>
57 // This class is used by <src>LatticeStatistics</src> to generate
58 // statistical sum from an input <src>MaskedLattice</src>.
59 // The input lattice is iterated through in tile-sized chunks
60 // and fed to an object of this class.
61 // </etymology>
62 //
63 // <synopsis>
64 // <src>StatsTiledCollapser</src> is derived from <src>TiledCollapser</src> which
65 // is a base class used to define methods. Objects of this base class are
66 // used by <src>LatticeApply</src> functions. In this particular case,
67 // we are interested in <src>LatticeApply::tiledApply</src>. This function iterates
68 // through a <src>MaskedLattice</src> and allows you to collapse one or more
69 // axes, computing some values from it, and placing those values into
70 // an output <src>MaskedLattice</src>. It iterates through the input
71 // lattice in optimal tile-sized chunks. <src>LatticeStatistics</src>
72 // uses a <src>StatsTiledCollapser</src> object which it gives to
73 // <src>LatticeApply::tiledApply</src> for digestion. After it has
74 // done its work, <src>LatticeStatistics</src> then accesses the output
75 // <src>Lattice</src> that it made.
76 // </synopsis>
77 //
78 // <example>
79 // <srcblock>
81 //
82 // StatsTiledCollapser<T> collapser(range_p, noInclude_p, noExclude_p,
83 // fixedMinMax_p, blcParent_p);
84 //
87 //
88 // Int newOutAxis = outLattice.ndim()-1;
89 //
92 //
93 // LatticeApply<T>::tiledApply(outLattice, inLattice,
94 // collapser, collapseAxes,
95 // newOutAxis);
96 //
97 // </srcblock>
98 // In this example, a collapser is made and passed to LatticeApply.
99 // Afterwards, the output Lattice is available for use.
100 // The Lattices must all be the correct shapes on input to tiledApply
101 // </example>
102 //
103 // <motivation>
104 // The LatticeApply classes enable the ugly details of optimal
105 // Lattice iteration to be hidden from the user.
106 // </motivation>
107 //
108 // <todo asof="1998/05/10">
109 // <li>
110 // </todo>
111 
112 template <class T, class U=T>
113 class StatsTiledCollapser : public TiledCollapser<T, U> {
114 public:
115  // Constructor provides pixel selection range and whether that
116  // range is an inclusion or exclusion range. If <src>fixedMinMax=True</src>
117  // and an inclusion range is given, the min and max is set to
118  // that inclusion range.
120  const Vector<T>& pixelRange, Bool noInclude,
121  Bool noExclude, Bool fixedMinMax
122  );
123 
124  virtual ~StatsTiledCollapser() {}
125 
126  // Initialize process, making some checks
127  virtual void init (uInt nOutPixelsPerCollapse);
128 
129  // Initialiaze the accumulator
130  virtual void initAccumulator (uInt64 n1, uInt64 n3);
131 
132  // Process the data in the current chunk.
133  virtual void process (
134  uInt accumIndex1, uInt accumIndex3,
135  const T* inData, const Bool* inMask,
136  uInt dataIncr, uInt maskIncr,
137  uInt nrval, const IPosition& startPos,
138  const IPosition& shape
139  );
140 
141  // End the accumulation process and return the result arrays
142  virtual void endAccumulator(Array<U>& result,
143  Array<Bool>& resultMask,
144  const IPosition& shape);
145 
146  // Can handle null mask
147  virtual Bool canHandleNullMask() const {return True;};
148 
149  // Find the location of the minimum and maximum data values
150  // in the input lattice.
151  void minMaxPos(IPosition& minPos, IPosition& maxPos);
152 
153 private:
157 
158  // Accumulators for sum, sum squared, number of points
159  // minimum, and maximum
160 
166 
168 
169  void _convertNPts(
170  Double*& nptsPtr, CountedPtr<Block<Double> > npts,
171  CountedPtr<Block<DComplex> > nptsComplex
172  ) const;
173 
174  void _convertNPts(
175  DComplex*& nptsPtr, CountedPtr<Block<Double> > npts,
176  CountedPtr<Block<DComplex> > nptsComplex
177  ) const;
178 };
179 
180 }
181 
182 #ifndef CASACORE_NO_AUTO_TEMPLATES
183 #include <casacore/lattices/LatticeMath/StatsTiledCollapser.tcc>
184 #endif
185 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
A 1-D Specialization of the Array class.
virtual void init(uInt nOutPixelsPerCollapse)
Initialize process, making some checks.
CountedPtr< Block< U > > _mean
CountedPtr< Block< U > > _sumSq
CountedPtr< Block< U > > _sum
virtual Bool canHandleNullMask() const
Can handle null mask.
unsigned long long uInt64
Definition: aipsxtype.h:39
CountedPtr< Block< Double > > _npts
Accumulators for sum, sum squared, number of points minimum, and maximum.
void _convertNPts(Double *&nptsPtr, CountedPtr< Block< Double > > npts, CountedPtr< Block< DComplex > > nptsComplex) const
CountedPtr< Block< T > > _min
void minMaxPos(IPosition &minPos, IPosition &maxPos)
Find the location of the minimum and maximum data values in the input lattice.
CountedPtr< Block< U > > _sigma
StatsTiledCollapser(const Vector< T > &pixelRange, Bool noInclude, Bool noExclude, Bool fixedMinMax)
Constructor provides pixel selection range and whether that range is an inclusion or exclusion range...
virtual void initAccumulator(uInt64 n1, uInt64 n3)
Initialiaze the accumulator.
CountedPtr< Block< U > > _nvariance
Referenced counted pointer for constant data.
Definition: VisModelData.h:42
Abstract base class to collapse chunks for LatticeApply.
Generate statistics, tile by tile, from a masked lattice NOTE this version was moved from LatticeStat...
CountedPtr< Block< U > > _variance
double Double
Definition: aipstype.h:55
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
CountedPtr< Block< T > > _max
virtual void endAccumulator(Array< U > &result, Array< Bool > &resultMask, const IPosition &shape)
End the accumulation process and return the result arrays.
virtual void process(uInt accumIndex1, uInt accumIndex3, const T *inData, const Bool *inMask, uInt dataIncr, uInt maskIncr, uInt nrval, const IPosition &startPos, const IPosition &shape)
Process the data in the current chunk.
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape...
Definition: ExprNode.h:1944
template &lt;class T, class U&gt; class vector;
Definition: MSFlagger.h:37
CountedPtr< Block< Bool > > _initMinMax
const Bool True
Definition: aipstype.h:43
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42