casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MomentsBase.h
Go to the documentation of this file.
1 //# MomentsBase.h: base class for moment generator
2 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,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: MomentsBase.h 20299 2008-04-03 05:56:44Z gervandiepen $
27 
28 #ifndef IMAGES_MOMENTSBASE_H
29 #define IMAGES_MOMENTSBASE_H
30 
31 #include <casa/aips.h>
33 #include <casa/Quanta/Quantum.h>
35 #include <casa/Logging/LogIO.h>
36 #include <casa/Arrays/Vector.h>
37 #include <casa/iosfwd.h>
38 
39 namespace casacore{
40 
41 class IPosition;
42 class String;
43 class Unit;
44 }
45 
46 namespace casa {
47 
48 template <class T> class MomentCalcBase;
49 
50 // <summary>
51 // This class is a base class for generating moments from an image or a spectral data.
52 // </summary>
53 
54 // <use visibility=export>
55 
56 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
57 // </reviewed>
58 
59 // <prerequisite>
60 // <li> <linkto class="ImageMoments">ImageMoments</linkto>
61 // <li> <linkto class="MSMoments">MSMoments</linkto>
62 // <li> <linkto class="casacore::LatticeApply">casacore::LatticeApply</linkto>
63 // <li> <linkto class="MomentCalcBase">MomentCalcBase</linkto>
64 // </prerequisite>
65 
66 // <etymology>
67 // This class is an abstract class to compute moments from images or spectral data.
68 // </etymology>
69 
70 // <synopsis>
71 // The primary goal of MSMoments, ImageMoments, and MSMoments are to help
72 // spectral-line astronomers analyze their multi-dimensional images or
73 // spectral data (in the form of casacore::MeasurementSet) by generating moments of
74 // a specified axis. ImageMoments is a specialized class to generate moments
75 // from images, while MSMoments is designed properly for casacore::MeasurementSet input.
76 // MSMoments class is an abstract class that is inherited by the above two
77 // concrete classes.
78 // MomentsBase provides interface layer to the MomentCalculators so that
79 // functionalities in MomentCalculators can be shared with ImageMoments and
80 // MSMoments.
81 // The word "moment" is used loosely here. It refers to collapsing an axis
82 // to one pixel and putting the value of that pixel (for all of the other
83 // non-collapsed axes) to something computed from the data values along
84 // the moment axis. For example, take an RA-DEC-Velocity cube, collapse
85 // the velocity axis by computing the mean intensity at each RA-DEC
86 // pixel. This class and its inheritances offer many different moments and a variety of
87 // interactive and automatic ways to compute them.
88 //
89 
90 // <motivation>
91 // MSMoments is defined so that moments can be generated from both images
92 // and spectral data (in the form of casacore::MeasurementSet).
93 // </motivation>
94 
95 
96 template <class T> class MomentsBase {
97 public:
98 
99  // Note that if I don't put MomentCalcBase as a forward declaration
100  // and use instead "friend class MomentCalcBase<T>" The gnu compiler
101  // fails with a typedef problem. But I can't solve it with say
102  // <src>typedef MomentCalcBase<T> gpp_type;</src> because you can only do a
103  // typedef with an actual type, not a <tt>T</tt> !
104  friend class MomentCalcBase<T>;
105 
106  // The <src>enum MethodTypes</src> is provided for use with the
107  // <src>setWinFitMethod</src> function. It gives the allowed moment
108  // methods which are available with this function. The use of these
109  // methods is described further with the description of this function
110  // as well as in the general documentation earlier.
111  enum MethodTypes {
112  // Invokes the spectral windowing method
114  // Invokes Gaussian fitting
117  };
118 
119  // This <src>enum MomentTypes</src> is provided for use with the
120  // <src>setMoments</src> function. It gives the allowed moment
121  // types that you can ask for.
122 
123  enum MomentTypes {
124  // The average intensity
126  // The integrated intensity
128  // The intensity weighted mean coordinate (usually velocity)
130  // The intensity weighted coordinate (usually velocity) dispersion
132  // The median intensity
134  // The median coordinate (usually velocity). Treat the spectrum as
135  // a probability distribution, generate the cumulative distribution,
136  // and find the coordinate corresponding to the 50% value.
138  // The standard deviation about the mean of the intensity
140  // The rms of the intensity
142  // The absolute mean deviation of the intensity
144  // The maximum value of the intensity
146  // The coordinate (usually velocity) of the maximum value of the intensity
148  // The minimum value of the intensity
150  // The coordinate (usually velocity) of the minimum value of the intensity
152  // Total number
154  // Default value is the integrated intensity
156  };
157 
158  // Destructor
159  virtual ~MomentsBase();
160 
161  // Set the desired moments via an <src>casacore::Int</src> array. Each <src>casacore::Int</src>
162  // specifies a different moment; the allowed values and their meanings
163  // are given by the <src>enum MomentTypes</src>. A return value
164  // of <src>false</src> indicates you asked for an out of range
165  // moment. If you don't call this function, the default state of the
166  // class is to request the integrated intensity.
168 
169  // Set the moment axis (0 relative). A return value of <src>false</src>
170  // indicates that the axis was not contained in the image. If you don't
171  // call this function, the default state of the class is to set the
172  // moment axis to the spectral axis if it can find one. Otherwise
173  // an error will result.
175 
176  // The method by which you compute the moments is specified by calling
177  // (or not calling) the <src>setWinFitMethod</src> and
178  // <src>setSmoothMethod</src> functions. The default state of the class
179  // is to compute directly on all (or some according to <src>setInExClude</src>)
180  // of the pixels in the spectrum. Calling these functions modifies the
181  // computational state to something more complicated.
182  //
183  // The <src>setWinMethod</src> function requires an <src>casacore::Int</src> array
184  // as its argument. Each <src>casacore::Int</src> specifies a different method
185  // that you can invoke (either separately or in combination). The
186  // allowed values and their meanings are given by the
187  // <src>enum MethodTypes</src>.
188  //
189  // Both the windowing and fitting methods have interactive modes. The
190  // windowing method also has a fitting flavour, so if you set both
191  // MomentsBase::WINDOW and MomentsBase::FIT, you would be invoking the
192  // windowing method but determining the window by fitting Gaussians
193  // automatically (as MomentsBase::INTERACTIVE) was not given.
194  //
195  // If you don't call this function, then neither the windowing nor fitting
196  // methods are invoked. A return value of <src>false</src> indicates
197  // that you asked for an illegal method.
199 
200  // This function invokes smoothing of the input image. Give <src>casacore::Int</src>
201  // arrays for the axes (0 relative) to be smoothed and the smoothing kernel
202  // types (use the <src>enum KernelTypes</src>) for each axis. Give a
203  // <src>casacore::Double</src> array for the widths (full width for BOXCAR and full
204  // width at half maximum for GAUSSIAN) in pixels of the smoothing kernels for
205  // each axis. For HANNING smoothing, you always get the quarter-half-quarter
206  // kernel (no matter what you might ask for). A return value of <src>false</src>
207  // indicates that you have given an inconsistent or invalid set of smoothing
208  // parameters. If you don't call this function the default state of the
209  // class is to do no smoothing. The kernel types are specified with
210  // the casacore::VectorKernel::KernelTypes enum
211  // <group>
215  ) = 0;
216 
218  const casacore::Vector<casacore::Int>& smoothAxes,
219  const casacore::Vector<casacore::Int>& kernelTypes,
220  const casacore::Vector<casacore::Double>& kernelWidths
221  );
222  // </group>
223 
224  // You may specify a pixel intensity range as either one for which
225  // all pixels in that range are included in the moment calculation,
226  // or one for which all pixels in that range are excluded from the moment
227  // calculations. One or the other of <src>include</src> and <src>exclude</src>
228  // must therefore be a zero length vector if you call this function.
229  // A return value of <src>false</src> indicates that you have given both
230  // an <src>include</src> and an <src>exclude</src> range. If you don't call
231  // this function, the default state of the class is to include all pixels.
232  void setInExCludeRange(
233  const casacore::Vector<T>& include, const casacore::Vector<T>& exclude
234  );
235 
236  // This function is used to help assess whether a spectrum along the moment
237  // axis is all noise or not. If it is all noise, there is not a lot of point
238  // to trying to computing the moment.
239  // <src>peakSNR</src> is the signal-to-noise ratio of the peak value in the
240  // spectrum below which the spectrum is considered pure noise.
241  // <src>stdDeviation</src> is the standard deviation of the noise for the
242  // input image.
243  //
244  // Default values for one or the other parameter are indicated by giving zero.
245  //
246  // The default state of the class then is to set <src>peakSNR=3</src>
247  // and/or to work out the noise level from a Gaussian fit to a histogram
248  // (above 25%) of the entire image (it is very hard to get an accurate
249  // estimate of the noise a single spectrum).
250  void setSnr(const T& peakSNR, const T& stdDeviation);
251 
252  // This is the output file name for the smoothed image. It can be useful
253  // to have access this to this image when trying to get the pixel
254  // <src>include</src> or <src>exclude</src> range correct for the smooth-clip
255  // method. The default state of the class is to not output the smoothed image.
257 
258  // Set Velocity type. This is used for moments for which the moment axis is
259  // a spectral axis for which the coordinate is traditionally presented in
260  // km/s You can select the velocity definition. The default state of the
261  // class is to use the radio definition.
263 
264  // Reset argument error condition. If you specify invalid arguments to
265  // one of the above functions, an internal flag will be set which will
266  // prevent the <src>createMoments</src> function, which is defined in its inheritances,
267  // from doing anything
268  // (should you have chosen to igmore the Boolean return values of the functions).
269  // This function allows you to reset that internal state to good.
270  void resetError () {goodParameterStatus_p = true; error_p = "";};
271 
272  // Recover last error message
274 
275  // Get CoordinateSystem
276  virtual const casacore::CoordinateSystem& coordinates() = 0;
277 
278  // Helper function to convert a string containing a list of desired methods to
279  // the correct <src>casacore::Vector<casacore::Int></src> required for the <src>setWinFitMethod</src> function.
280  // This may be usful if your user interface involves strings rather than integers.
281  // A new value is added to the output vector (which is resized appropriately) if any of the
282  // substrings "window", "fit" or "interactive" (actually "win", "box" and
283  // "inter" will do) is present.
285 
286  virtual casacore::IPosition getShape() const = 0;
287 
289 
290 protected:
291 
292  // Constructor takes an image and a <src>casacore::LogIO</src> object for logging purposes.
293  // You specify whether output images are automatically overwritten if pre-existing,
294  // or whether an intercative choice dialog widget appears (overWriteOutput=F)
295  // You may also determine whether a progress meter is displayed or not.
296  MomentsBase(
297  casacore::LogIO &os, casacore::Bool overWriteOutput=false,
298  casacore::Bool showProgress=true
299  );
300 
304  T peakSNR_p {T(3)};
305  T stdDeviation_p {T(0)};
306  T yMin_p {T(0)};
307  T yMax_p {T(0)};
317 
329 
330  // Check that the combination of methods that the user has requested is valid
331  // casacore::List a handy dandy table if not.
332  void _checkMethod();
333 
334  // Take the user's data inclusion and exclusion data ranges and
335  // generate the range and Booleans to say what sort it is
336  void _setIncludeExclude (
337  casacore::Vector<T>& range, casacore::Bool& noInclude,
338  casacore::Bool& noExclude, const casacore::Vector<T>& include,
339  const casacore::Vector<T>& exclude
340  );
341 
342  // Set the output image suffixes and units
344  casacore::String& suffix, casacore::Unit& momentUnits,
345  const casacore::Unit& imageUnits, const casacore::String& momentAxisUnits,
346  const casacore::Int moment, casacore::Bool convertToVelocity
347  );
348 
349  // Make output Coordinates
351  casacore::IPosition& outShape, const casacore::CoordinateSystem& cSysIn,
352  const casacore::IPosition& inShape, casacore::Int momentAxis,
353  casacore::Bool removeAxis
354  );
355 };
356 
357 }
358 
359 #ifndef AIPS_NO_TEMPLATE_SRC
360 #include <imageanalysis/ImageAnalysis/MomentsBase.tcc>
361 #endif
362 
363 #endif
A Vector of integers, for indexing into Array&lt;T&gt; objects.
Definition: IPosition.h:119
int Int
Definition: aipstype.h:50
Invokes Gaussian fitting.
Definition: MomentsBase.h:115
casacore::String out_p
Definition: MomentsBase.h:308
casacore::CoordinateSystem _makeOutputCoordinates(casacore::IPosition &outShape, const casacore::CoordinateSystem &cSysIn, const casacore::IPosition &inShape, casacore::Int momentAxis, casacore::Bool removeAxis)
Make output Coordinates.
casacore::Bool doSmooth_p
Definition: MomentsBase.h:313
casacore::Bool fixedYLimits_p
Definition: MomentsBase.h:316
casacore::Bool overWriteOutput_p
Definition: MomentsBase.h:325
The minimum value of the intensity.
Definition: MomentsBase.h:149
casacore::Int worldMomentAxis_p
Definition: MomentsBase.h:319
casacore::Bool setSmoothOutName(const casacore::String &smOut)
This is the output file name for the smoothed image.
casacore::Bool showProgress_p
Definition: MomentsBase.h:302
casacore::MDoppler::Types velocityType_p
Definition: MomentsBase.h:328
The standard deviation about the mean of the intensity.
Definition: MomentsBase.h:139
casacore::String errorMessage() const
Recover last error message.
Definition: MomentsBase.h:273
virtual Type type()
Return the type enum.
The maximum value of the intensity.
Definition: MomentsBase.h:145
casacore::Int momentAxisDefault_p
Definition: MomentsBase.h:303
Abstract base class for moment calculator classes.
ostream-like interface to creating log messages.
Definition: LogIO.h:167
casacore::Vector< casacore::Int > kernelTypes_p
Definition: MomentsBase.h:320
casacore::Vector< T > selectRange_p
Definition: MomentsBase.h:323
defines physical units
Definition: Unit.h:189
casacore::Bool doWindow_p
Definition: MomentsBase.h:311
The coordinate (usually velocity) of the minimum value of the intensity.
Definition: MomentsBase.h:151
Invokes the spectral windowing method.
Definition: MomentsBase.h:113
MethodTypes
The enum MethodTypes is provided for use with the setWinFitMethod function.
Definition: MomentsBase.h:111
casacore::Bool _setOutThings(casacore::String &suffix, casacore::Unit &momentUnits, const casacore::Unit &imageUnits, const casacore::String &momentAxisUnits, const casacore::Int moment, casacore::Bool convertToVelocity)
Set the output image suffixes and units.
The integrated intensity.
Definition: MomentsBase.h:127
casacore::Int momentAxis_p
Definition: MomentsBase.h:318
void _checkMethod()
Check that the combination of methods that the user has requested is valid casacore::List a handy dan...
casacore::Vector< casacore::Int > moments_p
Definition: MomentsBase.h:322
virtual ~MomentsBase()
Destructor.
casacore::Bool goodParameterStatus_p
Definition: MomentsBase.h:310
MomentsBase(casacore::LogIO &os, casacore::Bool overWriteOutput=false, casacore::Bool showProgress=true)
Constructor takes an image and a casacore::LogIO object for logging purposes.
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Bool shouldConvertToVelocity() const
Definition: MomentsBase.h:288
The median coordinate (usually velocity).
Definition: MomentsBase.h:137
The median intensity.
Definition: MomentsBase.h:133
casacore::Vector< casacore::Quantity > kernelWidths_p
Definition: MomentsBase.h:321
Types
Types of known MDopplers Warning: The order defines the order in the translation matrix FromTo in th...
Definition: MDoppler.h:149
void resetError()
Reset argument error condition.
Definition: MomentsBase.h:270
void setInExCludeRange(const casacore::Vector< T > &include, const casacore::Vector< T > &exclude)
You may specify a pixel intensity range as either one for which all pixels in that range are included...
casacore::Bool noInclude_p
Definition: MomentsBase.h:314
virtual casacore::Bool setSmoothMethod(const casacore::Vector< casacore::Int > &, const casacore::Vector< casacore::Int > &, const casacore::Vector< casacore::Quantum< casacore::Double > > &)=0
This function invokes smoothing of the input image.
void _setIncludeExclude(casacore::Vector< T > &range, casacore::Bool &noInclude, casacore::Bool &noExclude, const casacore::Vector< T > &include, const casacore::Vector< T > &exclude)
Take the user&#39;s data inclusion and exclusion data ranges and generate the range and Booleans to say w...
static casacore::Vector< casacore::Int > toMethodTypes(const casacore::String &methods)
Helper function to convert a string containing a list of desired methods to the correct casacore::Vec...
casacore::Bool doFit_p
Definition: MomentsBase.h:312
virtual const casacore::CoordinateSystem & coordinates()=0
Get CoordinateSystem.
casacore::Bool setMoments(const casacore::Vector< casacore::Int > &moments)
Set the desired moments via an casacore::Int array.
The coordinate (usually velocity) of the maximum value of the intensity.
Definition: MomentsBase.h:147
MomentTypes
This enum MomentTypes is provided for use with the setMoments function.
Definition: MomentsBase.h:123
The rms of the intensity.
Definition: MomentsBase.h:141
The absolute mean deviation of the intensity.
Definition: MomentsBase.h:143
virtual casacore::IPosition getShape() const =0
casacore::Bool setWinFitMethod(const casacore::Vector< casacore::Int > &method)
The method by which you compute the moments is specified by calling (or not calling) the setWinFitMet...
String: the storage and methods of handling collections of characters.
Definition: String.h:223
The average intensity.
Definition: MomentsBase.h:125
casacore::Bool noExclude_p
Definition: MomentsBase.h:315
casacore::LogIO os_p
Definition: MomentsBase.h:301
void setVelocityType(casacore::MDoppler::Types type)
Set Velocity type.
casacore::String error_p
Definition: MomentsBase.h:326
void setSnr(const T &peakSNR, const T &stdDeviation)
This function is used to help assess whether a spectrum along the moment axis is all noise or not...
casacore::Vector< casacore::Int > smoothAxes_p
Definition: MomentsBase.h:324
The intensity weighted mean coordinate (usually velocity)
Definition: MomentsBase.h:129
The intensity weighted coordinate (usually velocity) dispersion.
Definition: MomentsBase.h:131
Default value is the integrated intensity.
Definition: MomentsBase.h:155
casacore::String smoothOut_p
Definition: MomentsBase.h:309
Interconvert pixel and world coordinates.
casacore::Bool convertToVelocity_p
Definition: MomentsBase.h:327
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42
virtual casacore::Bool setMomentAxis(casacore::Int)=0
Set the moment axis (0 relative).