casa::MomentCalcBase< T > Class Template Reference
[Images]

#include <MomentCalculator.h>

Inheritance diagram for casa::MomentCalcBase< T >:

Inheritance graph
[legend]
Collaboration diagram for casa::MomentCalcBase< T >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<class T>
class casa::MomentCalcBase< T >

Abstract base class for moment calculator classes.

Intended use:

Part of API

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Synopsis

This class, its concrete derived classes, and the classes LineCollapser, ImageMoments and LatticeApply are connected as follows. LatticeApply offers functions so that the application programmer does not need to worry about how to optimally iterate through a Lattice; it deals with tiling and to a lesser extent memory. LatticeApply functions are used by offering a class object to them that has a member function with a name and signature specified by an abstract base class that LatticeApply uses and the offered class inherits from. Specifically, in this case, MomentCalcBase inherits from LineCollapser and LatticeApply uses objects and methods of this class (but does not inherit from it). This defines the functions collapse and multiProcess which operate on a vector extracted from a Lattice. The former returns one number, the latter a vector of numbers from that profile. MomentCalcBase is a base class for for moment calculation and the multiProcess functions are used to compute moments (e.g., mean, sum, sum squared, intensity weighted velocity etc).

It is actually the concrete classes derived from MomentCalcBase (call them, as a group, the MomentCalculator classes) that implement the multiProcess functions. These derived classes allow different algorithms to be written with which moments of the vector can be computed.

Now, so far, we have a LatticeApply function which iterates through Lattices, extracts vectors, and offers them up to functions implemented in the derived MomentCalculator classes to compute the moments. As well as that, we need some class to actually construct the MomentCalculator classes and to feed them to LatticeApply. This is the role of the ImageMoments class. It is a high level class which takes control information from users specifying which moments they would like to calculate and how. It also provides the ancilliary masking lattice to the MomentCalculator constructors. The actual computational work is done by the MomentCalculator classes. So ImageMoments, MomentCalcBase and its derived MomentCalculator classes are really one unit; none of them are useful without the others. The separation of functionality is caused by having the LatticeApply class that knows all about optimally iterating through Lattices.

The coupling between these classes is done partly by the "friendship". ImageMoments grants friendship to MomentCalcBase so that the latter has access to the private data and private functions of ImageMoments. MomentCalcBase then operates as an interface between its derived MomentCalculator classes and ImageMoments. It retrieves private data from ImageMoments, and also activates private functions in ImageMoments, on behalf of the MomentCalculator classes. The rest of the coupling is done via the constructors of the derived MomentCalculator classes.

Finally, MomentCalcBase also has a number of protected functions that are common to its derived classes (e.g. plotting, fitting, accumulating sums etc). It also has protected data that is common to all the MomentCalculator classes. This protected data is accessed directly by name rather than with interface functions as there is too much of it. Of course, since MomentCalcBase is an abstract base class, it is up to the MomentCalculator classes to give the MomentCalcBase protected data objects values.

For discussion about different moments and algorithms to compute them see the discussion in ImageMoments and also in the derived classes documentation.

Example

Since MomentCalcBase is an abstract class, we defer code examples to the derived classes.

Motivation

We were desirous of writing functions to optimally iterate through Lattices so that the application programmer did not have to know anything about tiling or memory if possible. These are the LatticeApply functions. To incorporate ImageMoments into this scheme required some of it to be shifted into MomentCalcBase and its derived classes.

Tip: Note that there are is assignment operator or copy constructor. Do not use the ones the system would generate either.

To Do

more classes !

Definition at line 139 of file MomentCalculator.h.

Public Member Functions

virtual ~MomentCalcBase ()
virtual uInt nFailedFits () const
 Returns the number of failed fits if doing fitting.

Protected Member Functions

void accumSums (typename NumericTraits< T >::PrecisionType &s0, typename NumericTraits< T >::PrecisionType &s0Sq, typename NumericTraits< T >::PrecisionType &s1, typename NumericTraits< T >::PrecisionType &s2, Int &iMin, Int &iMax, T &dMin, T &dMax, const Int i, const T datum, const Double coord) const
 Accumulate statistical sums from this datum.
uInt allNoise (T &dMean, const Vector< T > &data, const Vector< Bool > &mask, const T peakSNR, const T stdDeviation) const
 Determine if the spectrum is pure noise.
void constructorCheck (Vector< T > &calcMoments, Vector< Bool > &calcMomentsMask, const Vector< Int > &selectMoments, const uInt nLatticeOut) const
 Check validity of constructor inputs.
void costlyMoments (ImageMoments< T > &iMom, Bool &doMedianI, Bool &doMedianV, Bool &doAbsDev) const
 Find out from the selectMoments array whether we want to compute the more expensive moments.
PGPlotterdevice (ImageMoments< T > &iMom) const
 Return reference plotting device from ImageMoments object.
Bool doAuto (const ImageMoments< T > &iMom) const
 Return automatic/interactive switch from the ImageMoments object.
void doCoordCalc (Bool &doCoordProfile, Bool &doCoordRandom, const ImageMoments< T > &iMom) const
 Return the Bool saying whether we need to compute coordinates or not for the requested moments.
Bool doFit (const ImageMoments< T > &iMom) const
 Return the Bool from the ImageMoments object saying whether we are going to fit Gaussians to the profiles or not.
void drawHorizontal (const T &y, PGPlotter &plotter) const
 Draw a horizontal line across the full x range of the plot.
void drawLine (const Vector< T > &x, const Vector< T > &y, PGPlotter &plotter) const
 Draw a spectrum on the current panel with the box already drawn on.
Bool drawSpectrum (const Vector< T > &x, const Vector< T > &y, const Vector< Bool > &mask, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const String xLabel, const String yLabel, const String title, const Bool advancePanel, PGPlotter &plotter) const
 Draw and label a spectrum on the current or next panel.
void drawMeanSigma (const T dMean, const T dSigma, PGPlotter &plotter) const
 Draw on lines marking the mean and +/- sigma.
void drawVertical (const T x, const T yMin, const T yMax, PGPlotter &plotter) const
 Draw a vertical line of the given length at a given abcissa.
Bool findNextDatum (uInt &iFound, const uInt &n, const Vector< Bool > &mask, const uInt &iStart, const Bool &findGood) const
 Find the next masked or unmasked point in a vector.
Bool fitGaussian (uInt &nFailed, T &peak, T &pos, T &width, T &level, const Vector< T > &x, const Vector< T > &y, const Vector< Bool > &mask, const T peakGuess, const T posGuess, const T widthGuess, const T levelGuess) const
 Fit a Gaussian to x and y arrays given guesses for the gaussian parameters.
Bool fixedYLimits (const ImageMoments< T > &iMom) const
 Return the fixed Y-plotting limits switch from the ImageMoments object.
Bool getAutoGaussianFit (uInt &nFailed, Vector< T > &gaussPars, const Vector< T > &x, const Vector< T > &y, const Vector< Bool > &mask, const T peakSNR, const T stdDeviation, PGPlotter &plotter, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const String xLabel, const String yLabel, const String title) const
 Automatically fit a Gaussian to a spectrum, including finding the starting guesses.
Bool getAutoGaussianGuess (T &peakGuess, T &posGuess, T &widthGuess, T &levelGuess, const Vector< T > &x, const Vector< T > &y, const Vector< Bool > &mask) const
 Automatically work out a guess for the Gaussian parameters Returns False if all pixels masked.
void getButton (Bool &reject, Bool &redo, PGPlotter &plotter) const
 Read the cursor button.
Bool getInterGaussianFit (uInt &nFailed, Vector< T > &gaussPars, LogIO &os, const Vector< T > &x, const Vector< T > &y, const Vector< Bool > &mask, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const String xLabel, const String yLabel, const String title, PGPlotter &plotter) const
 Interactively define a guess for a Gaussian fit, and then do the fit.
void getInterGaussianGuess (T &peakGuess, T &posGuess, T &widthGuess, Vector< Int > &window, Bool &reject, LogIO &os, const Int nPts, PGPlotter &plotter) const
 Interactively define a guess for the Gaussian parameters.
Bool getLoc (T &x, Bool &allSubsequent, Bool &ditch, Bool &redo, const Bool final, PGPlotter &plotter) const
 Read the cursor and return its coordinates if not off the plot.
Double getMomentCoord (ImageMoments< T > &iMom, Vector< Double > &pixelIn, Vector< Double > &worldOut, const Double momentPixel) const
 Find the value of the world coordinate on the moment axis for the given moment axis pixel value.
void lineSegments (uInt &nSeg, Vector< uInt > &start, Vector< uInt > &nPts, const Vector< Bool > &mask) const
 Examine a mask and determine how many segments of unmasked points it consists of.
void makeAbcissa (Vector< T > &x, const Int &n) const
 Resize an abcissa vector for plotting.
IntmomentAxis (ImageMoments< T > &iMom) const
 Return the moment axis from the ImageMoments object.
String momentAxisName (const CoordinateSystem &, const ImageMoments< T > &iMom) const
 Return the name of the moment/profile axis.
uInt nMaxMoments () const
 Return the number of moments that the ImageMoments class can calculate.
T & peakSNR (ImageMoments< T > &iMom) const
 Return the peak SNR for determination of all noise spectra from the ImageMoments object.
void selectRange (Vector< T > &pixelRange, Bool &doInclude, Bool &doExlude, ImageMoments< T > &iMom) const
 Return the selected pixel intensity range from the ImageMoments object and the Bools describing whether it is inclusion or exclusion.
Vector< IntselectMoments (ImageMoments< T > &iMom) const
 The MomentCalculators compute a vector of all possible moments.
void setCalcMoments (ImageMoments< T > &iMom, Vector< T > &calcMoments, Vector< Bool > &calcMomentsMask, Vector< Double > &pixelIn, Vector< Double > &worldOut, Bool doCoord, Double integratedScaleFactor, T dMedian, T vMedian, Int nPts, typename NumericTraits< T >::PrecisionType s0, typename NumericTraits< T >::PrecisionType s1, typename NumericTraits< T >::PrecisionType s2, typename NumericTraits< T >::PrecisionType s0Sq, typename NumericTraits< T >::PrecisionType sumAbsDev, T dMin, T dMax, Int iMin, Int iMax) const
 Fill the ouput moments array.
void setPosLabel (String &title, const IPosition &pos) const
 Fill a string with the position of the cursor.
void setCoordinateSystem (CoordinateSystem &cSys, const ImageMoments< T > &iMom)
 Install CoordinateSystem and SpectralCoordinate in protected data members.
void setUpCoords (ImageMoments< T > &iMom, Vector< Double > &pixelIn, Vector< Double > &worldOut, Vector< Double > &sepWorldCoord, LogIO &os, Double &integratedScaleFactor, const CoordinateSystem &cSys, Bool doCoordProfile, Bool doCoordRandom) const
 Set up separable moment axis coordinate vector and conversion vectors if not separable.
void showGaussFit (const T peak, const T pos, const T width, const T level, const Vector< T > &x, const Vector< T > &y, const Vector< Bool > &mask, PGPlotter &plotter) const
 Plot the Gaussian fit.
Bool stats (T &dMin, T &dMax, uInt &minPos, uInt &maxPos, T &mean, const Vector< T > &profile, const Vector< Bool > &mask) const
 Find some statistics from teh masked vector.
T & stdDeviation (ImageMoments< T > &iMom) const
 Return standard deviation of image from ImageMoments object.
void yAutoMinMax (T &yMin, T &yMax, ImageMoments< T > &iMom) const
 Return the auto y min and max from the ImageMoments object.
virtual void init (uInt nOutPixelsPerCollapse)
 Check if #pixels is indeed 1.

Static Protected Member Functions

static Float convertT (const T value)
 Convert from <T> to <Float> for plotting.
static T convertF (const Float value)
 Convert from <Float> (from plotting) to a <T>.

Protected Attributes

CoordinateSystem cSys_p
 A number of private data members are kept here in the base class as they are common to the derived classes.
Vector< T > calcMoments_p
 This vector is a container for all the possible moments that can be calculated.
Vector< BoolcalcMomentsMask_p
Vector< IntselectMoments_p
 This vector tells us which elements of the calcMoments_p vector we wish to select.
Bool doMedianI_p
 Although the general philosophy of these classes is to compute all the posisble moments and then select the ones we want, some of them are too expensive to calculate unless they are really wanted.
Bool doMedianV_p
Bool doAbsDev_p
Vector< DoublepixelIn_p
 These vectors are used to transform coordinates between pixel and world.
Vector< DoubleworldOut_p
Bool doCoordProfile_p
 All computations involving Coordinate conversions are relatively expensive These Bools signifies whether we need coordinate calculations or not for the full profile, and for some occaisional calculations.
Bool doCoordRandom_p
Vector< DoublesepWorldCoord_p
 This vector houses the world coordinate values for the profile if it was from a separable axis.
PGPlotter plotter_p
 This gives the plotter name.
Bool fixedYLimits_p
 This Bool tells us whether we want to see all profiles plotted with the Y range or whether they are to be scaled individually.
yMinAuto_p
 When we are plotting, if we have asked to all profiles with the same Y min and max, these are the values to use.
yMaxAuto_p
Vector< T > abcissa_p
 This vector is used to hold the abcissa values when plotting profiles.
String momAxisType_p
 This string tells us the name of the moment axis (VELO or FREQ etc).
uInt nFailed_p
 This is the number of Gaussian fits that failed.
Double integratedScaleFactor_p
 This scale factor is the increment along the moment axis applied so that units for the Integrated moment are like Jy/beam.km/s (or whatever is needed for the moment axis units) For non-linear velocities (e.g.


Constructor & Destructor Documentation

template<class T>
virtual casa::MomentCalcBase< T >::~MomentCalcBase (  )  [virtual]


Member Function Documentation

template<class T>
uInt casa::MomentCalcBase< T >::nFailedFits (  )  const [inline, virtual]

Returns the number of failed fits if doing fitting.

Definition at line 1064 of file MomentCalculator.h.

References casa::MomentCalcBase< T >::nFailed_p.

template<class T>
void casa::MomentCalcBase< T >::accumSums ( typename NumericTraits< T >::PrecisionType &  s0,
typename NumericTraits< T >::PrecisionType &  s0Sq,
typename NumericTraits< T >::PrecisionType &  s1,
typename NumericTraits< T >::PrecisionType &  s2,
Int iMin,
Int iMax,
T &  dMin,
T &  dMax,
const Int  i,
const T  datum,
const Double  coord 
) const [inline, protected]

Accumulate statistical sums from this datum.

Input: i Index datum Pixel value coord Coordinate value on moment axis Input/output: iMin,max index of dMin and dMax dMin,dMax minimum and maximum value Output: s0 sum (I) s0Sq sum (I*I) s1 sum (I*v) s2 sum (I*v*v)

Definition at line 1072 of file MomentCalculator.h.

template<class T>
uInt casa::MomentCalcBase< T >::allNoise ( T &  dMean,
const Vector< T > &  data,
const Vector< Bool > &  mask,
const T  peakSNR,
const T  stdDeviation 
) const [protected]

Determine if the spectrum is pure noise.

template<class T>
void casa::MomentCalcBase< T >::constructorCheck ( Vector< T > &  calcMoments,
Vector< Bool > &  calcMomentsMask,
const Vector< Int > &  selectMoments,
const uInt  nLatticeOut 
) const [protected]

Check validity of constructor inputs.

template<class T>
Float casa::MomentCalcBase< T >::convertT ( const T  value  )  [inline, static, protected]

Convert from <T> to <Float> for plotting.

Definition at line 1115 of file MomentCalculator.h.

template<class T>
T casa::MomentCalcBase< T >::convertF ( const Float  value  )  [inline, static, protected]

Convert from <Float> (from plotting) to a <T>.

Definition at line 1121 of file MomentCalculator.h.

template<class T>
void casa::MomentCalcBase< T >::costlyMoments ( ImageMoments< T > &  iMom,
Bool doMedianI,
Bool doMedianV,
Bool doAbsDev 
) const [protected]

Find out from the selectMoments array whether we want to compute the more expensive moments.

template<class T>
PGPlotter& casa::MomentCalcBase< T >::device ( ImageMoments< T > &  iMom  )  const [protected]

Return reference plotting device from ImageMoments object.

template<class T>
Bool casa::MomentCalcBase< T >::doAuto ( const ImageMoments< T > &  iMom  )  const [protected]

Return automatic/interactive switch from the ImageMoments object.

template<class T>
void casa::MomentCalcBase< T >::doCoordCalc ( Bool doCoordProfile,
Bool doCoordRandom,
const ImageMoments< T > &  iMom 
) const [protected]

Return the Bool saying whether we need to compute coordinates or not for the requested moments.

template<class T>
Bool casa::MomentCalcBase< T >::doFit ( const ImageMoments< T > &  iMom  )  const [protected]

Return the Bool from the ImageMoments object saying whether we are going to fit Gaussians to the profiles or not.

template<class T>
void casa::MomentCalcBase< T >::drawHorizontal ( const T &  y,
PGPlotter plotter 
) const [protected]

Draw a horizontal line across the full x range of the plot.

template<class T>
void casa::MomentCalcBase< T >::drawLine ( const Vector< T > &  x,
const Vector< T > &  y,
PGPlotter plotter 
) const [protected]

Draw a spectrum on the current panel with the box already drawn on.

template<class T>
Bool casa::MomentCalcBase< T >::drawSpectrum ( const Vector< T > &  x,
const Vector< T > &  y,
const Vector< Bool > &  mask,
const Bool  fixedYLimits,
const T  yMinAuto,
const T  yMaxAuto,
const String  xLabel,
const String  yLabel,
const String  title,
const Bool  advancePanel,
PGPlotter plotter 
) const [protected]

Draw and label a spectrum on the current or next panel.

template<class T>
void casa::MomentCalcBase< T >::drawMeanSigma ( const T  dMean,
const T  dSigma,
PGPlotter plotter 
) const [protected]

Draw on lines marking the mean and +/- sigma.

template<class T>
void casa::MomentCalcBase< T >::drawVertical ( const T  x,
const T  yMin,
const T  yMax,
PGPlotter plotter 
) const [protected]

Draw a vertical line of the given length at a given abcissa.

template<class T>
Bool casa::MomentCalcBase< T >::findNextDatum ( uInt iFound,
const uInt n,
const Vector< Bool > &  mask,
const uInt iStart,
const Bool findGood 
) const [protected]

Find the next masked or unmasked point in a vector.

template<class T>
Bool casa::MomentCalcBase< T >::fitGaussian ( uInt nFailed,
T &  peak,
T &  pos,
T &  width,
T &  level,
const Vector< T > &  x,
const Vector< T > &  y,
const Vector< Bool > &  mask,
const T  peakGuess,
const T  posGuess,
const T  widthGuess,
const T  levelGuess 
) const [protected]

Fit a Gaussian to x and y arrays given guesses for the gaussian parameters.

template<class T>
Bool casa::MomentCalcBase< T >::fixedYLimits ( const ImageMoments< T > &  iMom  )  const [protected]

Return the fixed Y-plotting limits switch from the ImageMoments object.

template<class T>
Bool casa::MomentCalcBase< T >::getAutoGaussianFit ( uInt nFailed,
Vector< T > &  gaussPars,
const Vector< T > &  x,
const Vector< T > &  y,
const Vector< Bool > &  mask,
const T  peakSNR,
const T  stdDeviation,
PGPlotter plotter,
const Bool  fixedYLimits,
const T  yMinAuto,
const T  yMaxAuto,
const String  xLabel,
const String  yLabel,
const String  title 
) const [protected]

Automatically fit a Gaussian to a spectrum, including finding the starting guesses.

template<class T>
Bool casa::MomentCalcBase< T >::getAutoGaussianGuess ( T &  peakGuess,
T &  posGuess,
T &  widthGuess,
T &  levelGuess,
const Vector< T > &  x,
const Vector< T > &  y,
const Vector< Bool > &  mask 
) const [protected]

Automatically work out a guess for the Gaussian parameters Returns False if all pixels masked.

template<class T>
void casa::MomentCalcBase< T >::getButton ( Bool reject,
Bool redo,
PGPlotter plotter 
) const [protected]

Read the cursor button.

template<class T>
Bool casa::MomentCalcBase< T >::getInterGaussianFit ( uInt nFailed,
Vector< T > &  gaussPars,
LogIO os,
const Vector< T > &  x,
const Vector< T > &  y,
const Vector< Bool > &  mask,
const Bool  fixedYLimits,
const T  yMinAuto,
const T  yMaxAuto,
const String  xLabel,
const String  yLabel,
const String  title,
PGPlotter plotter 
) const [protected]

Interactively define a guess for a Gaussian fit, and then do the fit.

Do this repeatedly until the user is content.

template<class T>
void casa::MomentCalcBase< T >::getInterGaussianGuess ( T &  peakGuess,
T &  posGuess,
T &  widthGuess,
Vector< Int > &  window,
Bool reject,
LogIO os,
const Int  nPts,
PGPlotter plotter 
) const [protected]

Interactively define a guess for the Gaussian parameters.

template<class T>
Bool casa::MomentCalcBase< T >::getLoc ( T &  x,
Bool allSubsequent,
Bool ditch,
Bool redo,
const Bool  final,
PGPlotter plotter 
) const [protected]

Read the cursor and return its coordinates if not off the plot.

Also interpret which button was pressed

template<class T>
Double casa::MomentCalcBase< T >::getMomentCoord ( ImageMoments< T > &  iMom,
Vector< Double > &  pixelIn,
Vector< Double > &  worldOut,
const Double  momentPixel 
) const [inline, protected]

Find the value of the world coordinate on the moment axis for the given moment axis pixel value.

Input momentPixel is the index in the profile extracted from the data Input/output pixelIn Pixels to convert. Must all be filled in except for pixelIn(momentPixel). worldOut Vector to hold result

Should really return a Fallible as I don't check and see if the coordinate transformation fails or not

Should really check the result is True, but for speed .\..

Definition at line 1128 of file MomentCalculator.h.

template<class T>
void casa::MomentCalcBase< T >::lineSegments ( uInt nSeg,
Vector< uInt > &  start,
Vector< uInt > &  nPts,
const Vector< Bool > &  mask 
) const [protected]

Examine a mask and determine how many segments of unmasked points it consists of.

template<class T>
void casa::MomentCalcBase< T >::makeAbcissa ( Vector< T > &  x,
const Int n 
) const [protected]

Resize an abcissa vector for plotting.

template<class T>
Int& casa::MomentCalcBase< T >::momentAxis ( ImageMoments< T > &  iMom  )  const [protected]

Return the moment axis from the ImageMoments object.

template<class T>
String casa::MomentCalcBase< T >::momentAxisName ( const CoordinateSystem ,
const ImageMoments< T > &  iMom 
) const [protected]

Return the name of the moment/profile axis.

template<class T>
uInt casa::MomentCalcBase< T >::nMaxMoments (  )  const [protected]

Return the number of moments that the ImageMoments class can calculate.

template<class T>
T& casa::MomentCalcBase< T >::peakSNR ( ImageMoments< T > &  iMom  )  const [protected]

Return the peak SNR for determination of all noise spectra from the ImageMoments object.

template<class T>
void casa::MomentCalcBase< T >::selectRange ( Vector< T > &  pixelRange,
Bool doInclude,
Bool doExlude,
ImageMoments< T > &  iMom 
) const [protected]

Return the selected pixel intensity range from the ImageMoments object and the Bools describing whether it is inclusion or exclusion.

template<class T>
Vector<Int> casa::MomentCalcBase< T >::selectMoments ( ImageMoments< T > &  iMom  )  const [protected]

The MomentCalculators compute a vector of all possible moments.

This function returns a vector which selects the desired moments from that "all moment" vector.

template<class T>
void casa::MomentCalcBase< T >::setCalcMoments ( ImageMoments< T > &  iMom,
Vector< T > &  calcMoments,
Vector< Bool > &  calcMomentsMask,
Vector< Double > &  pixelIn,
Vector< Double > &  worldOut,
Bool  doCoord,
Double  integratedScaleFactor,
dMedian,
vMedian,
Int  nPts,
typename NumericTraits< T >::PrecisionType  s0,
typename NumericTraits< T >::PrecisionType  s1,
typename NumericTraits< T >::PrecisionType