casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef IMAGES_IMAGESTATISTICS_H
27#define IMAGES_IMAGESTATISTICS_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/BasicSL/String.h>
32#include <casacore/casa/Utilities/DataType.h>
33#include <casacore/casa/Logging/LogIO.h>
34#include <casacore/lattices/LatticeMath/LatticeStatistics.h>
35#include <casacore/scimath/Mathematics/NumericTraits.h>
36#include <casacore/casa/iosstrfwd.h>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40// # Forward Declarations
41template <class T>
42class ImageInterface;
43class IPosition;
44
45// <summary>
46// Displays various statistics from an image.
47// </summary>
48
49// <use visibility=export>
50
51// <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
52// </reviewed>
53
54// <prerequisite>
55// <li> <linkto class=LatticeStatistics>LatticeStatistics</linkto> (base class)
56// <li> <linkto class=ImageInterface>ImageInterface</linkto>
57// </prerequisite>
58
59// <etymology>
60// This is a class designed to display and retrieve statistics from images
61// </etymology>
62
63// <synopsis>
64// This class enable you to display and/or retrieve statistics evaluated over
65// specified regions from an image. The dimension of the region is arbitrary, but
66// the size of each dimension is always the size of the corresponding image axis.
67// The statistics are displayed as a function of location of the axes not
68// used to evaluate the statistics over. The axes which you evaluate the statistics
69// over are called the cursor axes, the others are called the display axes.
70//
71// This class is derived from the class LatticeStatistics which does all
72// the work. This class only adds some extra capability in terms of
73// logging world (rather than pixel) coordinates and computing the
74// synthesized beam area, if there is one. There are just a few virtual
75// functions for you to over-ride. These are rather specialized, they
76// are not part of a general polymorphic interface, just a way to
77// separate the Lattice and Image functionality out.
78//
79// See LatticeStatistics for details and examples.
80// </synopsis>
81//
82// <motivation>
83// The generation of statistical information from an image is a basic
84// and necessary capability.
85// </motivation>
86
87// <todo asof="1996/11/26">
88// <li> Deal with complex images at least for statistics retrieval if not
89// plotting.
90// <li> Retrieve statistics at specified location of display axes
91// <li> Standard errors on statistical quantities
92// <li> Median, other more exotic statistics. Life made difficult by
93// accumulation image approach
94// </todo>
95
96template <class T>
98 public:
99 // Constructor takes the image and a <src>LogIO</src> object for logging.
100 // You can specify whether you want to see progress meters or not.
101 // You can force the storage image to be disk based, otherwise
102 // the decision for core or disk is taken for you.
103 // If <src>clone</src> is True, the input image will be cloned, so the caller
104 // can make changes to the input image, but the statistics will reflect the
105 // image as it was at construction. If False, a reference to the input image
106 // is used, and so the caller shouldn't make changes to the input image between
107 // construction and calling statistics computation methods, unless it calls setNewImage()
108 // to update the changed image. Obviously, cloning the image impacts performance
109 // and memory usage.
110 ImageStatistics(const ImageInterface<T>& image, LogIO& os, Bool showProgress = True,
111 Bool forceDisk = False, Bool clone = True);
112
113 // Constructor takes the image only. In the absence of a logger you get no messages.
114 // This includes error messages and potential listing of the statistics.
115 // You can specify whether you want to see progress meters or not.
116 // You can force the storage image to be disk based, otherwise
117 // the decision for core or disk is taken for you.
118 ImageStatistics(const ImageInterface<T>& image, Bool showProgress = True, Bool forceDisk = False,
119 Bool clone = True);
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>
124
125 // Destructor
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 // If <src>clone</src> is True, the input image will be cloned, so the caller
136 // can make changes to the input image, but the statistics will reflect the
137 // image as it was at construction. If False, a reference to the input image
138 // is used, and so the caller shouldn't make changes to the input image between
139 // construction and calling statistics computation methods, unless it calls setNewImage()
140 // to update the changed image. Obviously, cloning the image impacts performance
141 // and memory usage.
143
144 void setPrecision(Int precision);
145
146 void setBlc(const IPosition& blc);
147
149
151
152 // list robust statistics? Should be called before display()
153 void showRobust(const Bool show);
154
155 inline void recordMessages(const Bool rm) { _recordMessages = rm; }
156
157 inline vector<String> getMessages() { return _messages; }
158
159 inline void clearMessages() { _messages.resize(0); }
160
161 void setListStats(Bool b) { _listStats = b; }
162
163 protected:
165
166 virtual Bool _canDoFlux() const;
167
168 private:
169 // Data
170
173 std::shared_ptr<const ImageInterface<T>> _inImPtrMgr;
177 mutable vector<String> _messages;
178
179 // Virtual functions. See LatticeStatistics for more information
180 // about these, or see the implementation.
181
182 // Get label for higher order axes
183 virtual void getLabels(String& higherOrder, String& xAxis, const IPosition& dPos) const;
184
185 // Get beam area in pixels if possible. Return False if the beam area could not be
186 // calculated.
187 virtual Bool _getBeamArea(Array<Double>& beamArea, String& msg) const;
188
189 // List min and max with world coordinates
190 virtual void listMinMax(std::ostringstream& osMin, std::ostringstream& osMax, Int oWidth,
191 DataType type);
192
193 // List the statistics
194 virtual Bool listStats(Bool hasBeam, const IPosition& dPos, const Matrix<AccumType>& ord);
195
196 virtual void displayStats(AccumType nPts, AccumType sum, AccumType median, AccumType medAbsDevMed,
197 AccumType quartile, AccumType sumSq, AccumType mean, AccumType var,
198 AccumType rms, AccumType sigma, AccumType dMin, AccumType dMax,
199 AccumType q1, AccumType q3);
200
201 // If <src>isFluxDensity</src> is False, then the computed value is
202 // a flux (ie flux density integrated over a spectral extent)
203 Quantum<AccumType> _flux(Bool& isFluxDensity, AccumType sum, Double beamAreaInPixels) const;
204
206 const Array<AccumType>& sum);
207
209 Bool posInLattice);
210 // # Make members of parent class known.
211 protected:
225
226 public:
228 using LatticeStatistics<T>::SUM;
232 using LatticeStatistics<T>::RMS;
234 using LatticeStatistics<T>::MIN;
235 using LatticeStatistics<T>::MAX;
236};
237
238// # Declare extern templates for often used types.
239extern template class ImageStatistics<Float>;
240
241} // namespace casacore
242
243#ifndef CASACORE_NO_AUTO_TEMPLATES
244#include <casacore/images/Images/ImageStatistics.tcc>
245#endif // # CASACORE_NO_AUTO_TEMPLATES
246#endif
ImageStatistics(const ImageInterface< T > &image, LogIO &os, Bool showProgress=True, Bool forceDisk=False, Bool clone=True)
Constructor takes the image and a LogIO object for logging.
void recordMessages(const Bool rm)
virtual Bool _getBeamArea(Array< Double > &beamArea, String &msg) const
Get beam area in pixels if possible.
ImageStatistics(const ImageStatistics< T > &other)
Copy constructor.
virtual ~ImageStatistics()
Destructor.
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...
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)
const ImageInterface< T > * pInImage_p
void setBlc(const IPosition &blc)
virtual Bool listStats(Bool hasBeam, const IPosition &dPos, const Matrix< AccumType > &ord)
List the statistics.
ImageStatistics(const ImageInterface< T > &image, Bool showProgress=True, Bool forceDisk=False, Bool clone=True)
Constructor takes the image only.
Bool setNewImage(const ImageInterface< T > &image, Bool clone=True)
Set a new ImageInterface object.
virtual Bool _canDoFlux() const
Virtual Functions.
void setPrecision(Int precision)
Bool _computeFlux(Quantum< AccumType > &flux, AccumType sum, const IPosition &pos, Bool posInLattice)
Bool _computeFlux(Array< AccumType > &flux, const Array< AccumType > &npts, const Array< AccumType > &sum)
NumericTraits< T >::PrecisionType AccumType
vector< String > getMessages()
virtual void listMinMax(std::ostringstream &osMin, std::ostringstream &osMax, Int oWidth, DataType type)
List min and max with world coordinates.
std::shared_ptr< const ImageInterface< T > > _inImPtrMgr
ImageStatistics< T > & operator=(const ImageStatistics< T > &other)
Assignment operator.
virtual void getLabels(String &higherOrder, String &xAxis, const IPosition &dPos) const
Virtual functions.
IPosition getBlc() const
void showRobust(const Bool show)
list robust statistics?
Bool doRobust_p
doRobust means that when the storage lattice is generated, the robust statistics are generated as wel...
void setStream(std::ostream &os, Int oPrec)
Non-virtual functions.
IPosition locInLattice(const IPosition &storagePosition, Bool relativeToParent=True) const
Given a location in the storage lattice, convert those locations on the non-statistics axis (the last...
LatticeStatistics(const MaskedLattice< T > &lattice, LogIO &os, Bool showProgress=True, Bool forceDisk=False, Bool clone=True)
Constructor takes the lattice and a LogIO object for logging.
@ NPTS
The number of points.
@ MEDIAN
The median - the robust stats does not fit well into storage lattice approach.
@ SIGMA
The standard deviation about the mean.
@ FLUX
The flux density (can't always compute this - needs the beam).
Char PrecisionType
Higher precision type (Float->Double).
String: the storage and methods of handling collections of characters.
Definition String.h:355
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
LatticeExprNode mean(const LatticeExprNode &expr)
LatticeExprNode sum(const LatticeExprNode &expr)
int Int
Definition aipstype.h:48
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
LatticeExprNode median(const LatticeExprNode &expr)
RecordInterface * clone() const override
Make a copy of this object.
Definition Polynomial.h:125
TableExprNode rms(const TableExprNode &array)
Definition ExprNode.h:1430