Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.atnf.csiro.au/computing/software/casacore/casacore-1.2.0/doc/html/LatticeStatistics_8h_source.html
Дата изменения: Unknown Дата индексирования: Mon Feb 14 22:24:38 2011 Кодировка: |
00001 //# LatticeStatistics.h: generate statistics from a Lattice 00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: LatticeStatistics.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $ 00027 00028 #ifndef LATTICES_LATTICESTATISTICS_H 00029 #define LATTICES_LATTICESTATISTICS_H 00030 00031 00032 //# Includes 00033 #include <casa/aips.h> 00034 #include <casa/Arrays/Array.h> 00035 #include <casa/Containers/Block.h> 00036 #include <casa/Arrays/Vector.h> 00037 #include <lattices/Lattices/LatticeStatsBase.h> 00038 #include <lattices/Lattices/TiledCollapser.h> 00039 #include <lattices/Lattices/TiledCollapser.h> 00040 #include <lattices/Lattices/LatticeExprNode.h> 00041 #include <scimath/Mathematics/NumericTraits.h> 00042 #include <casa/System/PGPlotter.h> 00043 #include <casa/Utilities/DataType.h> 00044 #include <casa/BasicSL/String.h> 00045 #include <casa/Logging/LogIO.h> 00046 00047 00048 namespace casa { //# NAMESPACE CASA - BEGIN 00049 00050 //# Forward Declarations 00051 template <class T> class MaskedLattice; 00052 template <class T> class TempLattice; 00053 class IPosition; 00054 #include <casa/iosstrfwd.h> 00055 00056 00057 // <summary> 00058 // Compute and display various statistics from a lattice 00059 // </summary> 00060 // <use visibility=export> 00061 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00062 // </reviewed> 00063 // <prerequisite> 00064 // <li> <linkto class=LatticeStatsBase>LatticeStatsBase</linkto> 00065 // <li> <linkto class=MaskedLattice>MaskedLattice</linkto> 00066 // </prerequisite> 00067 00068 // <etymology> 00069 // This is a class designed to display and retrieve statistics from lattices 00070 // </etymology> 00071 00072 // <synopsis> 00073 // This class enable you to display and/or retrieve statistics evaluated over 00074 // specified regions of a lattice. The dimension of the region is arbitrary, but 00075 // the size of each dimension is always the shape of the corresponding lattice axis. 00076 // The statistics are displayed as a function of location of the axes not 00077 // used to evaluate the statistics over. The axes which you evaluate the statistics 00078 // over are called the cursor axes, the others are called the display axes. 00079 // 00080 // For example, consider a lattice cube (call the axes xyz or [0,1,2]). You could 00081 // display statistics from xy planes (cursor axes [0,1]) as a function of z (display 00082 // axes [2]). Or you could retrieve statistics from the z axis (cursor axes [2]) 00083 // for each [x,y] location (display axes [0,1]). 00084 // 00085 // This class inherits from <linkto class="LatticeStatsBase">LatticeStatsBase</linkto> 00086 // This base class provides an <src>enum</src> defining allowed statistics types and a 00087 // helper function to convert between a <src>String</src> and a 00088 // <src>Vector<Int></src> describing the desired statistics to plot. 00089 // An example is shown below. 00090 // 00091 // This class can list, plot and retrieve statistics. When it lists statistics, 00092 // it always lists all the available statistics. When you plot statistics, 00093 // you must specify which ones you would like to see. 00094 // 00095 // This class generates a "storage lattice" into which it writes the accumulated 00096 // statistical sums. It is from this storage lattice that the plotting and retrieval 00097 // arrays are drawn. The storage lattice is either in core or on disk 00098 // depending upon its size (if > 10% of memory given by .aipsrc system.resources.memory 00099 // then it goes into a disk-based PagedArray). If on disk, the 00100 // storage lattice is deleted when the <src>LatticeStatistics</src> class 00101 // object destructs. However, currently, if the process is terminated ungracefully, 00102 // the storage lattice will be left over. 00103 // </synopsis> 00104 // 00105 // <note role=tip> 00106 // This class has a few virtual functions; they are not part of a nice general 00107 // polymorphic interface; rather they have specialized functionality. The idea 00108 // of these is that you can derive a class from LatticeStatistics, such as 00109 // <linkto class="ImageStatistics">ImageStatistics</linkto> which provides 00110 // you with a little more information when displaying/logging the 00111 // statistics (such as world coordinates) 00112 // The virtual functions are 00113 // <ul> 00114 // <li> <src>getBeamArea</src> can be used to return the synthesized beam 00115 // area so that the FLUX statistic can be computed 00116 // <li> <src>listStats</src> is used to list the statistics to the logger 00117 // <li> <src>getLabelsM</src> find the X-axis label and the title label 00118 // for the plotting. 00119 // </ul> 00120 // </note> 00121 // 00122 // <note role=tip> 00123 // If you ignore return error statuses from the functions that set the 00124 // state of the class, the internal status of the class is set to bad. 00125 // This means it will just keep on returning error conditions until you 00126 // explicitly recover the situation. A message describing the last 00127 // error condition can be recovered with function errorMessage. 00128 // </note> 00129 00130 00131 // <example> 00132 // <srcBlock> 00134 // 00135 // PagedImage<Float> inImage(inName); 00136 // 00138 // 00139 // LogOrigin or("myClass", "myFunction(...)", WHERE); 00140 // LogIO os(or); 00141 // LatticeStatistics<Float> stats(SubImage<FLoat>(inImage), os); 00142 // 00144 // 00145 // Vector<Int> cursorAxes(2) 00146 // cursorAxes(0) = 1; 00147 // cursorAxes(1) = 2; 00148 // if (!stats.setAxes(cursorAxes)) return 1; 00149 // 00151 // 00152 // if (!stats.setList(True)) return 1; 00153 // String device = "/xs"; 00154 // Vector<Int> nxy(2); 00155 // nxy(0) = 1; 00156 // nxy(1) = 1; 00157 // Vector<Int> statsToPlot = LatticeStatsBase::toStatisticTypes("mean,rms,sigma"); 00158 // if (!stats.setPlotting(statsToPlot, device, nxy)) return 1; 00159 // 00161 // 00162 // if (!stats.display ()) return 1; 00163 // 00165 // 00166 // Array<Double> sum; 00167 // if (!stats.getStatistic(sum, LatticeStatsBase::SUM)) return 1; 00168 // 00169 // </srcBlock> 00170 // In this example, a <src>PagedImage</src> is constructed (which isA 00171 // MaskedLattice) with . We set the cursor axes 00172 // to be the y and z axes, we specify to list the statistics if we plot them, 00173 // and we ask to plot the mean, standard deviation, and root mean square of each 00174 // yz plane as a function of x location on the PGPLOT device "/xs" with 00175 // 1 subplot per page (there will be only one in this case). After the 00176 // plotting and listing, we also retrieve the sum of the selected pixels 00177 // as a function of x location into an array. 00178 // </example> 00179 00180 // <motivation> 00181 // The generation of statistical information from a lattice is a basic 00182 // and necessary capability. 00183 // </motivation> 00184 00185 // <todo asof="1996/11/26"> 00186 // <li> Implement plotting for complex lattices 00187 // <li> Retrieve statistics at specified location of display axes 00188 // </todo> 00189 00190 00191 template <class T> class LatticeStatistics : public LatticeStatsBase 00192 { 00193 // TypeDef 00194 00195 typedef typename NumericTraits<T>::PrecisionType AccumType; 00196 00197 public: 00198 00199 // Constructor takes the lattice and a <src>LogIO</src> object for logging. 00200 // You can specify whether you want to see progress meters or not. 00201 // You can force the storage lattice to be disk based, otherwise 00202 // the decision for core or disk is taken for you. 00203 LatticeStatistics (const MaskedLattice<T>& lattice, 00204 LogIO& os, 00205 Bool showProgress=True, 00206 Bool forceDisk=False); 00207 00208 // Constructor takes the lattice only. In the absence of a logger you get no messages. 00209 // This includes error messages and potential listing of the statistics. 00210 // You can specify whether you want to see progress meters or not. 00211 // You can force the storage lattice to be disk based, otherwise 00212 // the decision for core or disk is taken for you. 00213 LatticeStatistics (const MaskedLattice<T>& lattice, 00214 Bool showProgress=True, 00215 Bool forceDisk=False); 00216 00217 // Copy constructor. Copy semantics are followed. Therefore any storage lattice 00218 // that has already been created for <src>other</src> is copied to <src>*this</src> 00219 LatticeStatistics(const LatticeStatistics<T> &other); 00220 00221 // Destructor 00222 virtual ~LatticeStatistics (); 00223 00224 // Assignment operator. Deletes any storage lattice associated with 00225 // the object being assigned to and copies any storage lattice that has 00226 // already been created for "other". 00227 LatticeStatistics<T> &operator=(const LatticeStatistics<T> &other); 00228 00229 // Set the cursor axes (0 relative). A return value of <src>False</src> 00230 // indicates you have asked for an invalid axis. The default state of the class 00231 // is to set the cursor axes to all axes in the lattice. 00232 Bool setAxes (const Vector<Int>& cursorAxes); 00233 00234 // You may specify a pixel intensity range as either one for which 00235 // all pixels in that range are included or one for which all pixels 00236 // in that range are excluded. One or the other of <src>include</src> 00237 // and <src>exclude</src> must therefore be a zero length vector if you 00238 // call this function. If you are setting an <src>include</src> 00239 // range, then if you set <src>setMinMaxToInclude=True</src>, the 00240 // minimum and maximum values that this class returns will always be 00241 // the minimum and maximum of the <src>include</src> range, respectively. 00242 // A return value of <src>False</src> indicates that 00243 // you have given both an <src>include</src> and an <src>exclude</src> 00244 // range. A vector of length 1 for <src>include</src> and/or <src>exclude</src> 00245 // means that the range will be set to (say for <src>include</src>) 00246 // <src>-abs(include(0))</src> to <src>abs(include(0))</src>. A return value 00247 // of <src>False</src> indicates that both an inclusion and exclusion 00248 // range were given or that the internal state of the class is bad. If you don't 00249 // call this function, the default state of the class is to include all pixels. 00250 Bool setInExCludeRange(const Vector<T>& include, 00251 const Vector<T>& exclude, 00252 Bool setMinMaxToInclude=False); 00253 00254 // This function allows you to control whether the statistics are written to 00255 // the output stream if you are also making a plot. A return value of 00256 // <src>False</src> indicates that the internal state of the class is bad. 00257 // If you have created the <src>LatticeStatistics</src> object without 00258 // a <src>LogIO</src> object, you won't see any listings, but no error 00259 // conditions will be generated. The default state of the class is to 00260 // not list the output when making a plot. 00261 Bool setList(const Bool& doList); 00262 00263 // This functions enable you to specify which statistics you would like to 00264 // plot, sets the name of the PGPLOT plotting device and the number of 00265 // subplots in x and y per page. If you set <src>device</src> 00266 // but offer a zero length array for <src>nxy</src> then <src>nxy</src> is 00267 // set to [1,1]. Similarly, the default for <src>statsToPlot</src> is 00268 // to plot the mean and standard deviation. Use the helper function 00269 // <src>LatticeStatsBase::toStatisticTypes(String& stats)</src> to convert 00270 // a <src>String</src> to the desired <src>Vector<Int> statsToPlot</src>. 00271 // A return value of <src>False</src> indicates invalid plotting arguments 00272 // or that the internal state of the class is bad. If you don't call this function, 00273 // the default state of the class is to not make plots. 00274 Bool setPlotting(PGPlotter& plotter, 00275 const Vector<Int>& statsToPlot, 00276 const Vector<Int>& nxy); 00277 00278 // Display the statistics by listing and/or plotting them. If you don't call 00279 // this function then you won't see anything ! A return value of <src>False</src> 00280 // indicates an invalid plotting device, or that the internal state of the class is bad. 00281 Bool display (); 00282 00283 // CLose plotter 00284 void closePlotting(); 00285 00286 00287 // Return the display axes. The returned vector will be valid only if <src>setAxes</src> 00288 // has been called, or if one of the active "display" or "get*" methods has been called. 00289 Vector<Int> displayAxes() const {return displayAxes_p;} 00290 00291 // Recover the desired Statistic into an array. If you choose to use 00292 // the T version, be aware that the values in the AccumType version of the 00293 // Array may not be representable in the T version (e.g. large values for 00294 // SumSq). The shape of the 00295 // array is the shape of the display axes (e.g. if the shape of the lattice is 00296 // [nx,ny,nz] and you ask for the mean of the y axis the shape of the returned 00297 // array would be [nx,nz]. A returned array of zero shape indicates that there 00298 // were no good values. A return value of <src>False</src> 00299 // indicates that the internal state of the class is bad. 00300 // <group> 00301 Bool getStatistic (Array<AccumType>& stat, LatticeStatsBase::StatisticsTypes type, Bool dropDeg=True); 00302 Bool getConvertedStatistic (Array<T>& stat, LatticeStatsBase::StatisticsTypes type, Bool dropDeg=True); 00303 // </group> 00304 00305 // Recover position of min and max. Only works if there are no 00306 // display axes (i.e. statistics found over entire image), otherwise, 00307 // the returned values are resized to 0 shape. A return 00308 // value of <src>False</src> indicates that the internal state of 00309 // the class is bad. 00310 Bool getMinMaxPos(IPosition& minPos, IPosition& maxPos); 00311 00312 // This function gets a vector containing all the statistics 00313 // for a given location. If <src>posInLattice=True</src> then 00314 // the location is a location in the input lattice. Any 00315 // positions on the display axes are ignored. Otherwise, you 00316 // should just give locations for the display axes only. 00317 // Use can use the enum in class LatticeStatsBase to find out 00318 // which locations in the vector contain which statistics. 00319 // A returned vector of zero shape indicates that there 00320 // were no good values. A return value of <src>False</src> 00321 // indicates that the internal state of the class is bad. 00322 Bool getStats (Vector<AccumType>&, 00323 const IPosition& pos, 00324 const Bool posInLattice=False); 00325 00326 // Reset argument error condition. If you specify invalid arguments to 00327 // one of the above <src>set</src> functions, an internal flag will be set which will 00328 // prevent the work functions from doing anything (should you have chosen 00329 // to ignore the Boolean return values of the <src>set</src> functions). 00330 // This function allows you to reset that internal state to good. 00331 void resetError () {goodParameterStatus_p = True;}; 00332 00333 // Get full lattice min and max only. Returns False if no unmasked data, else returns True. 00334 // Honours any include or exclude range if set. 00335 Bool getFullMinMax (T& dataMin, T& dataMax); 00336 00337 // Recover last error message 00338 String errorMessage() const {return error_p;}; 00339 00340 // Set a new MaskedLattice object. A return value of <src>False</src> indicates the 00341 // lattice had an invalid type or that the internal state of the class is bad. 00342 Bool setNewLattice(const MaskedLattice<T>& lattice); 00343 00344 // Did we construct with a logger ? 00345 Bool hasLogger () const {return haveLogger_p;}; 00346 00347 protected: 00348 00349 LogIO os_p; 00350 Vector<Int> cursorAxes_p, displayAxes_p; 00351 Bool goodParameterStatus_p; 00352 Bool haveLogger_p, fixedMinMax_p; 00353 00354 // doRobust means that when the storage lattice is generated, the 00355 // robust statistics are generated as well 00356 00357 Bool doRobust_p; 00358 Bool doList_p; 00359 IPosition minPos_p, maxPos_p, blcParent_p; 00360 String error_p; 00361 // 00362 // Virtual Functions. See implementation to figure it all out ! 00363 // 00364 // Get beam volume if possible. Your lattice needs to be 00365 // an ImageInterface for you to be able to do this. 00366 // See for example, class ImageStatistics. When you provide 00367 // the beam, then the Flux statistic, if requested, can be 00368 // computed. Returns False if beam not available, else True. 00369 // The implementation here returns False. 00370 virtual Bool getBeamArea (Double& beamArea) const; 00371 00372 virtual void listMinMax (ostringstream& osMin, 00373 ostringstream& osMax, 00374 Int oWidth, DataType type); 00375 00376 // List the statistics to the logger. The implementation here 00377 // is adequate for all lattices. See ImageStatistics for an 00378 // example of where extra information is provided. hasBeam is 00379 // the return value of getBeamArea. If it is true, that means 00380 // that the FLUX statistics will be available in the storage 00381 // lattice. dPos is the location of the start of the cursor in the 00382 // storage image for this row. stats(j,i) is the statistics matrix. 00383 // for the jth point and the ith statistic. 00384 // The return value is False if something goes wrong ! 00385 // Have a look at the implementation to see what you really 00386 // have to do. 00387 virtual Bool listStats (Bool hasBeam, const IPosition& dPos, 00388 const Matrix<AccumType>& ord); 00389 00390 // Gets labels for higher order axes and x axis. 00391 // dPos is the location of the start of the cursor in the 00392 // storage image for this row. 00393 virtual void getLabels(String& higherOrderLabel, String& xAxisLabel, 00394 const IPosition& dPos) const; 00395 00396 // Given a location in the storage lattice, convert those locations on the 00397 // non-statistics axis (the last one) and optionally account for the 00398 // lattice subsectioning 00399 IPosition locInLattice (const IPosition& storagePosition, 00400 Bool relativeToParent=True) const; 00401 00402 // Non-virtual functions 00403 // 00404 // set stream manipulators 00405 void setStream (ostream& os, Int oPrec); 00406 00407 private: 00408 const MaskedLattice<T>* pInLattice_p; 00409 TempLattice<AccumType>* pStoreLattice_p; 00410 Vector<Int> nxy_p, statsToPlot_p; 00411 Vector<T> range_p; 00412 PGPlotter plotter_p; 00413 Bool noInclude_p, noExclude_p; 00414 00415 Bool needStorageLattice_p, doneSomeGoodPoints_p, someGoodPointsValue_p; 00416 Bool showProgress_p, forceDisk_p; 00417 // 00418 T minFull_p, maxFull_p; 00419 Bool doneFullMinMax_p; 00420 00421 // Summarize the statistics found over the entire lattice 00422 virtual void summStats(); 00423 virtual void displayStats( AccumType nPts, AccumType sum, AccumType median, 00424 AccumType medAbsDevMed, AccumType quartile, AccumType sumSq, AccumType mean, 00425 AccumType var, AccumType rms, AccumType sigma, AccumType dMin, AccumType dMax ); 00426 00427 // Calculate statistic from storage lattice and return in an array 00428 Bool calculateStatistic (Array<AccumType>& slice, 00429 LatticeStatsBase::StatisticsTypes type, 00430 Bool dropDeg); 00431 00432 // Convert a AccumType to a Float for plotting. 00433 static Float convertATtoF (AccumType value) {return Float(std::real(value));}; 00434 00435 // Find the next good or bad point in an array 00436 Bool findNextDatum (uInt& iFound, 00437 const uInt& n, 00438 const Vector<AccumType>& mask, 00439 const uInt& iStart, 00440 const Bool& findGood) const; 00441 00442 // Find the next label in a list of comma delimitered labels 00443 Bool findNextLabel (String& subLabel, 00444 Int& iLab, 00445 String& label) const; 00446 00447 // Find the median per cursorAxes chunk 00448 void generateRobust (); 00449 00450 // Create a new storage lattice 00451 Bool generateStorageLattice (); 00452 00453 // Examine an array and determine how many segments of good points it consists 00454 // of. A good point occurs if the array value is greater than zero. 00455 void lineSegments (uInt& nSeg, 00456 Vector<uInt>& start, 00457 Vector<uInt>& nPts, 00458 const Vector<AccumType>& mask) const; 00459 00460 // Given a location in the lattice and a statistic type, work 00461 // out where to put it in the storage lattice 00462 IPosition locInStorageLattice(const IPosition& latticePosition, 00463 LatticeStatsBase::StatisticsTypes type) const; 00464 00465 // Draw each Y-axis sublabel in a string with a different colour 00466 void multiColourYLabel (String& label, 00467 PGPlotter& plotter, 00468 const String& LRLoc, 00469 const Vector<uInt>& colours, 00470 const Int& nLabs) const; 00471 00472 // Plot an array which may have some blanked points. 00473 // Thus we plot it in segments 00474 void multiPlot (PGPlotter& plotter, 00475 const Vector<AccumType>& x, 00476 const Vector<AccumType>& y, 00477 const Vector<AccumType>& n) const; 00478 00479 // Find min and max of good data in arrays specified by pointers 00480 void minMax (Bool& none, AccumType& dMin, AccumType& dMax, 00481 const Vector<AccumType>& d, 00482 const Vector<AccumType>& n) const; 00483 00484 // Find the next nice PGPLOT colour index 00485 Int niceColour (Bool& initColours) const; 00486 00487 // Plot the statistics 00488 Bool plotStats (Bool hasBeam, const IPosition& dPos, 00489 const Matrix<AccumType>& ord, 00490 PGPlotter& plotter); 00491 00492 // Retrieve a statistic from the storage lattice and return in an array 00493 Bool retrieveStorageStatistic (Array<AccumType>& slice, 00494 LatticeStatsBase::StatisticsTypes type, 00495 Bool dropDeg); 00496 00497 // Retrieve a statistic from the storage lattice at the specified 00498 // location and return in an array 00499 Bool retrieveStorageStatistic (Vector<AccumType>& slice, 00500 const IPosition& pos, 00501 const Bool posInLattice); 00502 00503 // Find the shape of slice from the statistics lattice at one 00504 // spatial pixel 00505 IPosition statsSliceShape () const; 00506 00507 // See if there were some valid points found in the storage lattice 00508 Bool someGoodPoints (); 00509 00510 00511 // Stretch min and max by 5% 00512 void stretchMinMax (AccumType& dMin, AccumType& dMax) const; 00513 }; 00514 00515 00516 00517 00518 // <summary> Generate statistics, tile by tile, from a masked lattice </summary> 00519 // 00520 // <use visibility=export> 00521 // 00522 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00523 // </reviewed> 00524 // 00525 // <prerequisite> 00526 // <li> <linkto class=LatticeApply>LatticeApply</linkto> 00527 // <li> <linkto class=TiledCollapser>TiledCollapser</linkto> 00528 // </prerequisite> 00529 // 00530 // <etymology> 00531 // This class is used by <src>LatticeStatistics</src> to generate 00532 // statistical sum from an input <src>MaskedLattice</src>. 00533 // The input lattice is iterated through in tile-sized chunks 00534 // and fed to an object of this class. 00535 // </etymology> 00536 // 00537 // <synopsis> 00538 // <src>StatsTiledCollapser</src> is derived from <src>TiledCollapser</src> which 00539 // is a base class used to define methods. Objects of this base class are 00540 // used by <src>LatticeApply</src> functions. In this particular case, 00541 // we are interested in <src>LatticeApply::tiledApply</src>. This function iterates 00542 // through a <src>MaskedLattice</src> and allows you to collapse one or more 00543 // axes, computing some values from it, and placing those values into 00544 // an output <src>MaskedLattice</src>. It iterates through the input 00545 // lattice in optimal tile-sized chunks. <src>LatticeStatistics</src> 00546 // uses a <src>StatsTiledCollapser</src> object which it gives to 00547 // <src>LatticeApply::tiledApply</src> for digestion. After it has 00548 // done its work, <src>LatticeStatistics</src> then accesses the output 00549 // <src>Lattice</src> that it made. 00550 // </synopsis> 00551 // 00552 // <example> 00553 // <srcblock> 00555 // 00556 // StatsTiledCollapser<T> collapser(range_p, noInclude_p, noExclude_p, 00557 // fixedMinMax_p, blcParent_p); 00558 // 00561 // 00562 // Int newOutAxis = outLattice.ndim()-1; 00563 // 00566 // 00567 // LatticeApply<T>::tiledApply(outLattice, inLattice, 00568 // collapser, collapseAxes, 00569 // newOutAxis); 00570 // 00571 // </srcblock> 00572 // In this example, a collapser is made and passed to LatticeApply. 00573 // Afterwards, the output Lattice is available for use. 00574 // The Lattices must all be the correct shapes on input to tiledApply 00575 // </example> 00576 // 00577 // <motivation> 00578 // The LatticeApply classes enable the ugly details of optimal 00579 // Lattice iteration to be hidden from the user. 00580 // </motivation> 00581 // 00582 // <todo asof="1998/05/10"> 00583 // <li> 00584 // </todo> 00585 00586 template <class T, class U=T> 00587 class StatsTiledCollapser : public TiledCollapser<T,U> 00588 { 00589 public: 00590 // Constructor provides pixel selection range and whether that 00591 // range is an inclusion or exclusion range. If <src>fixedMinMax=True</src> 00592 // and an inclusion range is given, the min and max is set to 00593 // that inclusion range. 00594 StatsTiledCollapser(const Vector<T>& pixelRange, Bool noInclude, 00595 Bool noExclude, Bool fixedMinMax); 00596 00597 // Initialize process, making some checks 00598 virtual void init (uInt nOutPixelsPerCollapse); 00599 00600 // Initialiaze the accumulator 00601 virtual void initAccumulator (uInt n1, uInt n3); 00602 00603 // Process the data in the current chunk. 00604 virtual void process (uInt accumIndex1, 00605 uInt accumIndex3, 00606 const T* inData, 00607 const Bool* inMask, 00608 uInt inIncr, 00609 uInt nrval, 00610 const IPosition& startPos, 00611 const IPosition& shape); 00612 00613 // End the accumulation process and return the result arrays 00614 virtual void endAccumulator(Array<U>& result, 00615 Array<Bool>& resultMask, 00616 const IPosition& shape); 00617 00618 // Can handle null mask 00619 virtual Bool canHandleNullMask() const {return True;}; 00620 00621 // Find the location of the minimum and maximum data values 00622 // in the input lattice. 00623 void minMaxPos(IPosition& minPos, IPosition& maxPos); 00624 00625 00626 private: 00627 Vector<T> range_p; 00628 Bool noInclude_p, noExclude_p, fixedMinMax_p; 00629 IPosition minPos_p, maxPos_p; 00630 00631 // Accumulators for sum, sum squared, number of points 00632 // minimum, and maximum 00633 00634 Block<U> *pSum_p; 00635 Block<U> *pSumSq_p; 00636 Block<U>* pNPts_p; 00637 Block<T>* pMin_p; 00638 Block<T>* pMax_p; 00639 Block<Bool>* pInitMinMax_p; 00640 // 00641 uInt n1_p; 00642 uInt n3_p; 00643 }; 00644 00645 } //# NAMESPACE CASA - END 00646 00647 #ifndef CASACORE_NO_AUTO_TEMPLATES 00648 #include <lattices/Lattices/LatticeStatistics.tcc> 00649 #endif //# CASACORE_NO_AUTO_TEMPLATES 00650 #endif