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