00001 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003 00002 //# Associated Universities, Inc. Washington DC, USA. 00003 //# 00004 //# This library is free software; you can redistribute it and/or modify it 00005 //# under the terms of the GNU Library General Public License as published by 00006 //# the Free Software Foundation; either version 2 of the License, or (at your 00007 //# option) any later version. 00008 //# 00009 //# This library is distributed in the hope that it will be useful, but WITHOUT 00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 //# License for more details. 00013 //# 00014 //# You should have received a copy of the GNU Library General Public License 00015 //# along with this library; if not, write to the Free Software Foundation, 00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00017 //# 00018 //# Correspondence concerning AIPS++ should be addressed as follows: 00019 //# Internet email: aips2-request@nrao.edu. 00020 //# Postal address: AIPS++ Project Office 00021 //# National Radio Astronomy Observatory 00022 //# 520 Edgemont Road 00023 //# Charlottesville, VA 22903-2475 USA 00024 //# 00025 //# $Id: LatticeStatistics.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $ 00026 00027 #ifndef LATTICES_STATSTILEDCOLLAPSER_H 00028 #define LATTICES_STATSTILEDCOLLAPSER_H 00029 00030 00031 //# Includes 00032 #include <casacore/casa/aips.h> 00033 00034 namespace casacore { 00035 00036 00037 // <summary> Generate statistics, tile by tile, from a masked lattice </summary> 00038 00039 // NOTE this version was moved from LatticeStatistics (early Dec 2014 version) 00040 // and slightly modified mostly for style issues (no significant semantic differences 00041 // from that version). For a large number of statistics sets that need to be computed 00042 // simultaneously, this version is more efficient than using the new stats framework, 00043 // because creating large numbers of eg ClassicalStatistics objects is much less efficient 00044 // than the direct manipulation of pointers to primitive types that this class does. 00045 // 00046 // <use visibility=export> 00047 // 00048 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00049 // </reviewed> 00050 // 00051 // <prerequisite> 00052 // <li> <linkto class=LatticeApply>LatticeApply</linkto> 00053 // <li> <linkto class=TiledCollapser>TiledCollapser</linkto> 00054 // </prerequisite> 00055 // 00056 // <etymology> 00057 // This class is used by <src>LatticeStatistics</src> to generate 00058 // statistical sum from an input <src>MaskedLattice</src>. 00059 // The input lattice is iterated through in tile-sized chunks 00060 // and fed to an object of this class. 00061 // </etymology> 00062 // 00063 // <synopsis> 00064 // <src>StatsTiledCollapser</src> is derived from <src>TiledCollapser</src> which 00065 // is a base class used to define methods. Objects of this base class are 00066 // used by <src>LatticeApply</src> functions. In this particular case, 00067 // we are interested in <src>LatticeApply::tiledApply</src>. This function iterates 00068 // through a <src>MaskedLattice</src> and allows you to collapse one or more 00069 // axes, computing some values from it, and placing those values into 00070 // an output <src>MaskedLattice</src>. It iterates through the input 00071 // lattice in optimal tile-sized chunks. <src>LatticeStatistics</src> 00072 // uses a <src>StatsTiledCollapser</src> object which it gives to 00073 // <src>LatticeApply::tiledApply</src> for digestion. After it has 00074 // done its work, <src>LatticeStatistics</src> then accesses the output 00075 // <src>Lattice</src> that it made. 00076 // </synopsis> 00077 // 00078 // <example> 00079 // <srcblock> 00081 // 00082 // StatsTiledCollapser<T> collapser(range_p, noInclude_p, noExclude_p, 00083 // fixedMinMax_p, blcParent_p); 00084 // 00087 // 00088 // Int newOutAxis = outLattice.ndim()-1; 00089 // 00092 // 00093 // LatticeApply<T>::tiledApply(outLattice, inLattice, 00094 // collapser, collapseAxes, 00095 // newOutAxis); 00096 // 00097 // </srcblock> 00098 // In this example, a collapser is made and passed to LatticeApply. 00099 // Afterwards, the output Lattice is available for use. 00100 // The Lattices must all be the correct shapes on input to tiledApply 00101 // </example> 00102 // 00103 // <motivation> 00104 // The LatticeApply classes enable the ugly details of optimal 00105 // Lattice iteration to be hidden from the user. 00106 // </motivation> 00107 // 00108 // <todo asof="1998/05/10"> 00109 // <li> 00110 // </todo> 00111 00112 template <class T, class U=T> 00113 class StatsTiledCollapser : public TiledCollapser<T, U> { 00114 public: 00115 // Constructor provides pixel selection range and whether that 00116 // range is an inclusion or exclusion range. If <src>fixedMinMax=True</src> 00117 // and an inclusion range is given, the min and max is set to 00118 // that inclusion range. 00119 StatsTiledCollapser( 00120 const Vector<T>& pixelRange, Bool noInclude, 00121 Bool noExclude, Bool fixedMinMax 00122 ); 00123 00124 virtual ~StatsTiledCollapser() {} 00125 00126 // Initialize process, making some checks 00127 virtual void init (uInt nOutPixelsPerCollapse); 00128 00129 // Initialiaze the accumulator 00130 virtual void initAccumulator (uInt n1, uInt n3); 00131 00132 // Process the data in the current chunk. 00133 virtual void process ( 00134 uInt accumIndex1, uInt accumIndex3, 00135 const T* inData, const Bool* inMask, 00136 uInt dataIncr, uInt maskIncr, 00137 uInt nrval, const IPosition& startPos, 00138 const IPosition& shape 00139 ); 00140 00141 // End the accumulation process and return the result arrays 00142 virtual void endAccumulator(Array<U>& result, 00143 Array<Bool>& resultMask, 00144 const IPosition& shape); 00145 00146 // Can handle null mask 00147 virtual Bool canHandleNullMask() const {return True;}; 00148 00149 // Find the location of the minimum and maximum data values 00150 // in the input lattice. 00151 void minMaxPos(IPosition& minPos, IPosition& maxPos); 00152 00153 private: 00154 Vector<T> _range; 00155 Bool _include, _exclude, _fixedMinMax, _isReal; 00156 IPosition _minpos, _maxpos; 00157 00158 // Accumulators for sum, sum squared, number of points 00159 // minimum, and maximum 00160 00161 CountedPtr<Block<U> > _sum, _sumSq, _npts, 00162 _mean, _variance, _nvariance; 00163 CountedPtr<Block<T> > _min, _max; 00164 CountedPtr<Block<Bool> > _initMinMax; 00165 00166 uInt _n1, _n3; 00167 }; 00168 00169 } 00170 00171 #ifndef CASACORE_NO_AUTO_TEMPLATES 00172 #include <casacore/lattices/LatticeMath/StatsTiledCollapser.tcc> 00173 #endif 00174 #endif