casacore
ImageStatistics.h
Go to the documentation of this file.
1 //# ImageStatistics.h: generate statistics from an image
2 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef IMAGES_IMAGESTATISTICS_H
29 #define IMAGES_IMAGESTATISTICS_H
30 
31 
32 //# Includes
33 #include <casacore/casa/aips.h>
34 #include <casacore/casa/BasicSL/String.h>
35 #include <casacore/casa/Utilities/DataType.h>
36 #include <casacore/casa/Logging/LogIO.h>
37 #include <casacore/lattices/LatticeMath/LatticeStatistics.h>
38 #include <casacore/scimath/Mathematics/NumericTraits.h>
39 #include <casacore/casa/iosstrfwd.h>
40 
41 namespace casacore { //# NAMESPACE CASACORE - BEGIN
42 
43 //# Forward Declarations
44 template <class T> class ImageInterface;
45 class IPosition;
46 
47 // <summary>
48 // Displays various statistics from an image.
49 // </summary>
50 
51 // <use visibility=export>
52 
53 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
54 // </reviewed>
55 
56 // <prerequisite>
57 // <li> <linkto class=LatticeStatistics>LatticeStatistics</linkto> (base class)
58 // <li> <linkto class=ImageInterface>ImageInterface</linkto>
59 // </prerequisite>
60 
61 // <etymology>
62 // This is a class designed to display and retrieve statistics from images
63 // </etymology>
64 
65 // <synopsis>
66 // This class enable you to display and/or retrieve statistics evaluated over
67 // specified regions from an image. The dimension of the region is arbitrary, but
68 // the size of each dimension is always the size of the corresponding image axis.
69 // The statistics are displayed as a function of location of the axes not
70 // used to evaluate the statistics over. The axes which you evaluate the statistics
71 // over are called the cursor axes, the others are called the display axes.
72 //
73 // This class is derived from the class LatticeStatistics which does all
74 // the work. This class only adds some extra capability in terms of
75 // logging world (rather than pixel) coordinates and computing the
76 // synthesized beam area, if there is one. There are just a few virtual
77 // functions for you to over-ride. These are rather specialized, they
78 // are not part of a general polymorphic interface, just a way to
79 // separate the Lattice and Image functionality out.
80 //
81 // See LatticeStatistics for details and examples.
82 // </synopsis>
83 //
84 // <motivation>
85 // The generation of statistical information from an image is a basic
86 // and necessary capability.
87 // </motivation>
88 
89 // <todo asof="1996/11/26">
90 // <li> Deal with complex images at least for statistics retrieval if not
91 // plotting.
92 // <li> Retrieve statistics at specified location of display axes
93 // <li> Standard errors on statistical quantities
94 // <li> Median, other more exotic statistics. Life made difficult by
95 // accumulation image approach
96 // </todo>
97 
98 
99 template <class T> class ImageStatistics : public LatticeStatistics<T>
100 {
101 public:
102 
103 // Constructor takes the image and a <src>LogIO</src> object for logging.
104 // You can specify whether you want to see progress meters or not.
105 // You can force the storage image to be disk based, otherwise
106 // the decision for core or disk is taken for you.
107  ImageStatistics (const ImageInterface<T>& image,
108  LogIO& os,
109  Bool showProgress=True,
110  Bool forceDisk=False);
111 
112 // Constructor takes the image only. In the absence of a logger you get no messages.
113 // This includes error messages and potential listing of the statistics.
114 // You can specify whether you want to see progress meters or not.
115 // You can force the storage image to be disk based, otherwise
116 // the decision for core or disk is taken for you.
117  ImageStatistics (const ImageInterface<T>& image,
118  Bool showProgress=True,
119  Bool forceDisk=False);
120 
121 // Copy constructor. Copy semantics are followed. Therefore any storage image
122 // that has already been created for <src>other</src> is copied to <src>*this</src>
123  ImageStatistics(const ImageStatistics<T> &other);
124 
125 // Destructor
126  virtual ~ImageStatistics ();
127 
128 // Assignment operator. Deletes any storage image associated with
129 // the object being assigned to and copies any storage image that has
130 // already been created for "other".
132 
133 // Set a new ImageInterface object. A return value of <src>False</src> indicates the
134 // image had an invalid type or that the internal state of the class is bad.
135  Bool setNewImage (const ImageInterface<T>& image);
136 
137  void setPrecision(Int precision);
138 
139  void setBlc(const IPosition& blc);
140 
141  IPosition getBlc() const;
142 
143  Int getPrecision() const;
144 
145  // list robust statistics? Should be called before display()
146  void showRobust(const Bool show);
147 
148  inline void recordMessages(const Bool rm) { _recordMessages = rm; }
149 
150  inline vector<String> getMessages() { return _messages; }
151 
152  inline void clearMessages() { _messages.resize(0); }
153 
154  void setListStats(Bool b) { _listStats = b; }
155 protected:
156 
158 
159  virtual Bool _canDoFlux() const;
160 
161 
162 
163 private:
164 // Data
165 
171  mutable vector<String> _messages;
172 
173 // Virtual functions. See LatticeStatistics for more information
174 // about these, or see the implementation.
175 
176 // Get label for higher order axes
177  virtual void getLabels(String& higherOrder, String& xAxis, const IPosition& dPos) const;
178 
179  // Get beam area in pixels if possible. Return False if the beam area could not be
180  // calculated.
181  virtual Bool _getBeamArea(
182  Array<Double>& beamArea, String& msg
183  ) const;
184 
185 // List min and max with world coordinates
186  virtual void listMinMax (ostringstream& osMin,
187  ostringstream& osMax,
188  Int oWidth, DataType type);
189 
190 // List the statistics
191  virtual Bool listStats (Bool hasBeam, const IPosition& dPos,
192  const Matrix<AccumType>& ord);
193 
194  virtual void displayStats(
195  AccumType nPts, AccumType sum, AccumType median,
196  AccumType medAbsDevMed, AccumType quartile,
197  AccumType sumSq, AccumType mean, AccumType var,
198  AccumType rms, AccumType sigma, AccumType dMin,
199  AccumType dMax, AccumType q1, AccumType q3
200  );
201 
202 
203  // If <src>isFluxDensity</src> is False, then the computed value is
204  // a flux (ie flux density integrated over a spectral extent)
206  Bool& isFluxDensity, AccumType sum, Double beamAreaInPixels
207  ) const;
208 
210  Array<AccumType>& flux, const Array<AccumType>& npts,
211  const Array<AccumType>& sum
212  );
213 
215  Quantum<AccumType>& flux, AccumType sum, const IPosition& pos,
216  Bool posInLattice
217  );
218  //# Make members of parent class known.
219 protected:
233 public:
243 };
244 
245 //# Declare extern templates for often used types.
246 #ifdef AIPS_CXX11
247  extern template class ImageStatistics<Float>;
248 #endif
249 
250 
251 } //# NAMESPACE CASACORE - END
252 
253 #ifndef CASACORE_NO_AUTO_TEMPLATES
254 #include <casacore/images/Images/ImageStatistics.tcc>
255 #endif //# CASACORE_NO_AUTO_TEMPLATES
256 #endif
257 
A Vector of integers, for indexing into Array<T> objects.
Definition: IPosition.h:119
int Int
Definition: aipstype.h:50
LatticeExprNode median(const LatticeExprNode &expr)
virtual Bool listStats(Bool hasBeam, const IPosition &dPos, const Matrix< AccumType > &ord)
List the statistics.
ImageStatistics< T > & operator=(const ImageStatistics< T > &other)
Assignment operator.
LatticeExprNode sum(const LatticeExprNode &expr)
virtual void getLabels(String &higherOrder, String &xAxis, const IPosition &dPos) const
Virtual functions.
Displays various statistics from an image.
virtual void displayStats(AccumType nPts, AccumType sum, AccumType median, AccumType medAbsDevMed, AccumType quartile, AccumType sumSq, AccumType mean, AccumType var, AccumType rms, AccumType sigma, AccumType dMin, AccumType dMax, AccumType q1, AccumType q3)
void showRobust(const Bool show)
list robust statistics? Should be called before display()
Quantum< AccumType > _flux(Bool &isFluxDensity, AccumType sum, Double beamAreaInPixels) const
If isFluxDensity is False, then the computed value is a flux (ie flux density integrated over a spect...
A 2-D Specialization of the Array class.
Definition: Array.h:53
ostream-like interface to creating log messages.
Definition: LogIO.h:167
void setBlc(const IPosition &blc)
virtual ~ImageStatistics()
Destructor.
Bool _computeFlux(Array< AccumType > &flux, const Array< AccumType > &npts, const Array< AccumType > &sum)
IPosition getBlc() const
void setPrecision(Int precision)
Char PrecisionType
Higher precision type (Float->Double)
A base class for astronomical images.
NumericTraits< T >::PrecisionType AccumType
void recordMessages(const Bool rm)
double Double
Definition: aipstype.h:55
Compute and display various statistics from a lattice.
ImageStatistics(const ImageInterface< T > &image, LogIO &os, Bool showProgress=True, Bool forceDisk=False)
Constructor takes the image and a LogIO object for logging.
vector< String > getMessages()
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual Bool _canDoFlux() const
Virtual Functions.
Bool setNewImage(const ImageInterface< T > &image)
Set a new ImageInterface object.
Quantities (i.e. dimensioned values)
Definition: MeasValue.h:40
const Bool False
Definition: aipstype.h:44
virtual Bool _getBeamArea(Array< Double > &beamArea, String &msg) const
Get beam area in pixels if possible.
vector< String > _messages
LatticeExprNode mean(const LatticeExprNode &expr)
TableExprNode rms(const TableExprNode &array)
Definition: ExprNode.h:1844
String: the storage and methods of handling collections of characters.
Definition: String.h:223
const ImageInterface< T > * pInImage_p
const Bool True
Definition: aipstype.h:43
virtual void listMinMax(ostringstream &osMin, ostringstream &osMax, Int oWidth, DataType type)
List min and max with world coordinates.
this file contains all the compiler specific defines
Definition: mainpage.dox:28