casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef LATTICES_STATSTILEDCOLLAPSER_H
26#define LATTICES_STATSTILEDCOLLAPSER_H
27
28// # Includes
29#include <casacore/casa/aips.h>
30#include <memory>
31
32namespace casacore {
33
34// <summary> Generate statistics, tile by tile, from a masked lattice </summary>
35
36// NOTE this version was moved from LatticeStatistics (early Dec 2014 version)
37// and slightly modified mostly for style issues (no significant semantic differences
38// from that version). For a large number of statistics sets that need to be computed
39// simultaneously, this version is more efficient than using the new stats framework,
40// because creating large numbers of eg ClassicalStatistics objects is much less efficient
41// than the direct manipulation of pointers to primitive types that this class does.
42//
43// <use visibility=export>
44//
45// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
46// </reviewed>
47//
48// <prerequisite>
49// <li> <linkto class=LatticeApply>LatticeApply</linkto>
50// <li> <linkto class=TiledCollapser>TiledCollapser</linkto>
51// </prerequisite>
52//
53// <etymology>
54// This class is used by <src>LatticeStatistics</src> to generate
55// statistical sum from an input <src>MaskedLattice</src>.
56// The input lattice is iterated through in tile-sized chunks
57// and fed to an object of this class.
58// </etymology>
59//
60// <synopsis>
61// <src>StatsTiledCollapser</src> is derived from <src>TiledCollapser</src> which
62// is a base class used to define methods. Objects of this base class are
63// used by <src>LatticeApply</src> functions. In this particular case,
64// we are interested in <src>LatticeApply::tiledApply</src>. This function iterates
65// through a <src>MaskedLattice</src> and allows you to collapse one or more
66// axes, computing some values from it, and placing those values into
67// an output <src>MaskedLattice</src>. It iterates through the input
68// lattice in optimal tile-sized chunks. <src>LatticeStatistics</src>
69// uses a <src>StatsTiledCollapser</src> object which it gives to
70// <src>LatticeApply::tiledApply</src> for digestion. After it has
71// done its work, <src>LatticeStatistics</src> then accesses the output
72// <src>Lattice</src> that it made.
73// </synopsis>
74//
75// <example>
76// <srcblock>
78//
79// StatsTiledCollapser<T> collapser(range_p, noInclude_p, noExclude_p,
80// fixedMinMax_p, blcParent_p);
81//
84//
85// Int newOutAxis = outLattice.ndim()-1;
86//
89//
90// LatticeApply<T>::tiledApply(outLattice, inLattice,
91// collapser, collapseAxes,
92// newOutAxis);
93//
94// </srcblock>
95// In this example, a collapser is made and passed to LatticeApply.
96// Afterwards, the output Lattice is available for use.
97// The Lattices must all be the correct shapes on input to tiledApply
98// </example>
99//
100// <motivation>
101// The LatticeApply classes enable the ugly details of optimal
102// Lattice iteration to be hidden from the user.
103// </motivation>
104//
105// <todo asof="1998/05/10">
106// <li>
107// </todo>
108
109template <class T, class U = T>
111 public:
112 // Constructor provides pixel selection range and whether that
113 // range is an inclusion or exclusion range. If <src>fixedMinMax=True</src>
114 // and an inclusion range is given, the min and max is set to
115 // that inclusion range.
116 StatsTiledCollapser(const Vector<T>& pixelRange, Bool noInclude, Bool noExclude,
117 Bool fixedMinMax);
118
120
121 // Initialize process, making some checks
122 virtual void init(uInt nOutPixelsPerCollapse);
123
124 // Initialiaze the accumulator
125 virtual void initAccumulator(uInt64 n1, uInt64 n3);
126
127 // Process the data in the current chunk.
128 virtual void process(uInt accumIndex1, uInt accumIndex3, const T* inData, const Bool* inMask,
129 uInt dataIncr, uInt maskIncr, uInt nrval, const IPosition& startPos,
130 const IPosition& shape);
131
132 // End the accumulation process and return the result arrays
133 virtual void endAccumulator(Array<U>& result, Array<Bool>& resultMask, const IPosition& shape);
134
135 // Can handle null mask
136 virtual Bool canHandleNullMask() const { return True; };
137
138 // Find the location of the minimum and maximum data values
139 // in the input lattice.
140 void minMaxPos(IPosition& minPos, IPosition& maxPos);
141
142 private:
146
147 // Accumulators for sum, sum squared, number of points
148 // minimum, and maximum
149
150 std::shared_ptr<Block<Double>> _npts;
151 std::shared_ptr<Block<U>> _sum, _sumSq, _mean, _variance, _nvariance, _sigma;
152 std::shared_ptr<Block<T>> _min, _max;
153 std::shared_ptr<Block<Bool>> _initMinMax;
154
156
157 void _convertNPts(Double*& nptsPtr, std::shared_ptr<Block<Double>> npts,
158 std::shared_ptr<Block<DComplex>> nptsComplex) const;
159
160 void _convertNPts(DComplex*& nptsPtr, std::shared_ptr<Block<Double>> npts,
161 std::shared_ptr<Block<DComplex>> nptsComplex) const;
162};
163
164} // namespace casacore
165
166#ifndef CASACORE_NO_AUTO_TEMPLATES
167#include <casacore/lattices/LatticeMath/StatsTiledCollapser.tcc>
168#endif
169#endif
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, std::shared_ptr< Block< Double > > npts, std::shared_ptr< Block< DComplex > > nptsComplex) const
virtual void init(uInt nOutPixelsPerCollapse)
Initialize process, making some checks.
std::shared_ptr< Block< Double > > _npts
Accumulators for sum, sum squared, number of points minimum, and maximum.
std::shared_ptr< Block< Bool > > _initMinMax
std::shared_ptr< Block< T > > _max
std::shared_ptr< Block< U > > _mean
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 _convertNPts(Double *&nptsPtr, std::shared_ptr< Block< Double > > npts, std::shared_ptr< Block< DComplex > > nptsComplex) const
std::shared_ptr< Block< U > > _variance
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.
std::shared_ptr< Block< U > > _sumSq
std::shared_ptr< Block< U > > _sum
virtual void endAccumulator(Array< U > &result, Array< Bool > &resultMask, const IPosition &shape)
End the accumulation process and return the result arrays.
std::shared_ptr< Block< U > > _nvariance
virtual Bool canHandleNullMask() const
Can handle null mask.
std::shared_ptr< Block< U > > _sigma
std::shared_ptr< Block< T > > _min
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
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
unsigned long long uInt64
Definition aipsxtype.h:37