casacore
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
34namespace 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
112template <class T, class U=T>
114public:
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
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
153private:
157
158 // Accumulators for sum, sum squared, number of points
159 // minimum, and maximum
160
166
168
170 Double*& nptsPtr, CountedPtr<Block<Double> > npts,
171 CountedPtr<Block<DComplex> > nptsComplex
172 ) const;
173
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
Referenced counted pointer for constant data.
Definition: CountedPtr.h:81
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.
void _convertNPts(DComplex *&nptsPtr, CountedPtr< Block< Double > > npts, CountedPtr< Block< DComplex > > nptsComplex) const
virtual void init(uInt nOutPixelsPerCollapse)
Initialize process, making some checks.
CountedPtr< Block< T > > _max
CountedPtr< Block< U > > _sumSq
void _convertNPts(Double *&nptsPtr, CountedPtr< Block< Double > > npts, CountedPtr< Block< DComplex > > nptsComplex) const
CountedPtr< Block< U > > _sum
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.
void minMaxPos(IPosition &minPos, IPosition &maxPos)
Find the location of the minimum and maximum data values in the input lattice.
virtual void initAccumulator(uInt64 n1, uInt64 n3)
Initialiaze the accumulator.
CountedPtr< Block< Double > > _npts
Accumulators for sum, sum squared, number of points minimum, and maximum.
CountedPtr< Block< Bool > > _initMinMax
virtual void endAccumulator(Array< U > &result, Array< Bool > &resultMask, const IPosition &shape)
End the accumulation process and return the result arrays.
CountedPtr< Block< U > > _nvariance
virtual Bool canHandleNullMask() const
Can handle null mask.
CountedPtr< Block< U > > _variance
CountedPtr< Block< U > > _sigma
CountedPtr< Block< U > > _mean
CountedPtr< Block< T > > _min
this file contains all the compiler specific defines
Definition: mainpage.dox:28
unsigned int uInt
Definition: aipstype.h:51
TableExprNode shape(const TableExprNode &array)
Function operating on any scalar or array resulting in a Double array containing the shape.
Definition: ExprNode.h:1987
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
const Bool True
Definition: aipstype.h:43
double Double
Definition: aipstype.h:55
unsigned long long uInt64
Definition: aipsxtype.h:39