MomentCalculator.h

Classes

MomentCalcBase -- Abstract base class for moment calculator classes (full description)
MomentClip -- Computes simple clipped, and masked moments (full description)
MomentWindow -- Computes moments from a windowed profile (full description)
MomentFit -- Compute moments from a Gaussian fitted to a profile (full description)

template <class T> class MomentCalcBase : public LineCollapser<T,T>

Interface

Public Members
virtual ~MomentCalcBase()
virtual uInt nFailedFits() const
Protected Members
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
uInt allNoise(T& dMean, const Vector<T>& data, const Vector<Bool>& mask, const T peakSNR, const T stdDeviation) const
void constructorCheck(Vector<T>& calcMoments, Vector<Bool>& calcMomentsMask, const Vector<Int>& selectMoments, const uInt nLatticeOut) const
static Float convertT(const T value)
static T convertF(const Float value)
void costlyMoments(ImageMoments<T>& iMom, Bool& doMedianI, Bool& doMedianV, Bool& doAbsDev) const
PGPlotter& device(ImageMoments<T>& iMom) const
Bool doAuto(const ImageMoments<T>& iMom) const
void doCoordCalc(Bool& doCoordProfile, Bool& doCoordRandom, const ImageMoments<T>& iMom) const
Bool doFit(const ImageMoments<T>& iMom) const
void drawHorizontal(const T& y, PGPlotter& plotter) const
void drawLine (const Vector<T>& x, const Vector<T>& y, PGPlotter& plotter) const
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, String& plotter) const
void drawMeanSigma (const T dMean, const T dSigma, PGPlotter& plotter) const
void drawVertical(const T x, const T yMin, const T yMax, PGPlotter& plotter) const
Bool findNextDatum (uInt& iFound, const uInt& n, const Vector<Bool>& mask, const uInt& iStart, const Bool& findGood) const
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
Bool fixedYLimits(const ImageMoments<T>& iMom) const
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 PGPlotter xLabel, const PGPlotter yLabel, const PGPlotter title) const
Bool getAutoGaussianGuess(T& peakGuess, T& posGuess, T& widthGuess, T& levelGuess, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask) const
void getButton(Bool& reject, Bool& redo, PGPlotter& plotter) const
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 LogIO xLabel, const LogIO yLabel, const LogIO title, String& plotter) const
void getInterGaussianGuess(T& peakGuess, T& posGuess, T& widthGuess, Vector<Int>& window, Bool& reject, Vector& os, const Int nPts, LogIO& plotter) const
Bool getLoc(T& x, Bool& allSubsequent, Bool& ditch, Bool& redo, const Bool final, PGPlotter& plotter) const
Double getMomentCoord(ImageMoments<T>& iMom, Vector<Double>& pixelIn, Vector<Double>& worldOut, const Double momentPixel) const
void lineSegments (uInt& nSeg, Vector<uInt>& start, Vector<uInt>& nPts, const Vector<Bool>& mask) const
void makeAbcissa(Vector<T>& x, const Int& n) const
Int& momentAxis(ImageMoments<T>& iMom) const
String momentAxisName(const CoordinateSystem&, const ImageMoments<T>& iMom) const
uInt nMaxMoments() const
T& peakSNR(ImageMoments<T>& iMom) const
void selectRange(Vector<T>& pixelRange, Bool& doInclude, Bool& doExlude, ImageMoments<T>& iMom) const
Vector<Int> selectMoments(ImageMoments<T>& iMom) const
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
void setPosLabel(String& title, const IPosition& pos) const
void setCoordinateSystem (CoordinateSystem& cSys, const ImageMoments<T>& iMom)
void setUpCoords (ImageMoments<T>& iMom, Vector<Double>& pixelIn, Vector<Double>& worldOut, Vector<Double>& sepWorldCoord, Vector& os, Double& integratedScaleFactor, const LogIO& cSys, Bool doCoordProfile, Bool doCoordRandom) const
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, Vector& plotter) const
Bool stats(T& dMin, T& dMax, uInt& minPos, uInt& maxPos, T& mean, const Vector<T>& profile, const Vector<Bool>& mask) const
T& stdDeviation(ImageMoments<T>& iMom) const
void yAutoMinMax(T& yMin, T& yMax, ImageMoments<T>& iMom) const
virtual void init (uInt nOutPixelsPerCollapse)

Description

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

Member Description

virtual ~MomentCalcBase()

virtual uInt nFailedFits() const

Returns the number of failed fits if doing fitting

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 a vector

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

static Float convertT(const T value)

Convert from to for plotting

static T convertF(const Float value)

Convert from (from plotting) to a

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

PGPlotter& device(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, String& 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 PGPlotter xLabel, const PGPlotter yLabel, const PGPlotter 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 LogIO xLabel, const LogIO yLabel, const LogIO title, String& plotter) const

Interactively define a guess for a Gaussian fit, and then do the fit. Do this repeatedly until the user is content.

void getInterGaussianGuess(T& peakGuess, T& posGuess, T& widthGuess, Vector<Int>& window, Bool& reject, Vector& os, const Int nPts, LogIO& 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. Also interpret which button was pressed

Double getMomentCoord(ImageMoments<T>& iMom, Vector<Double>& pixelIn, Vector<Double>& worldOut, const Double momentPixel) const

Compute the world coordinate for the given moment axis pixel

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

Int& momentAxis(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<Int> selectMoments(ImageMoments<T>& iMom) const

The MomentCalculators compute a vector of all possible moments. This function returns a vector which selects the desired moments from that "all moment" vector.

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, Vector& os, Double& integratedScaleFactor, const LogIO& 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, Vector& 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. Returns False if no unmasked points.

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.


template <class T> class MomentClip : public MomentCalcBase<T>

Interface

Public Members
MomentClip(Lattice<T>* pAncilliaryLattice, ImageMoments<T>& iMom, ImageMoments& os, const uInt nLatticeOut)
~MomentClip()
virtual void process(T& out, Bool& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const Vector& pos)
virtual void multiProcess(Vector<T>& out, Vector<Bool>& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const IPosition& pos)
virtual Bool canHandleNullMask() const

Description

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Synopsis

This concrete class is derived from the abstract base class MomentCalcBase which provides an interface layer to the ImageMoments driver class. ImageMoments creates a MomentClip object and passes it to the LatticeApply function, lineMultiApply. This function iterates through a given lattice, and invokes the multiProcess member function of MomentClip on each vector of pixels that it extracts from the input lattice. The multiProcess function returns a vector of moments which are inserted into the output lattices also supplied to the LatticeApply function.

MomentClip computes moments directly from a vector of pixel intensities extracted from the primary lattice. An optional pixel intensity inclusion or exclusion range can be applied. It can also compute a mask based on the inclusion or exclusion ranges applied to an ancilliary lattice (the ancilliary vector corresponding to the primary vector is extracted). This mask is then applied to the primary vector for moment computation (ImageMoments offers a smoothed version of the primary lattice as the ancilliary lattice)

The constructor takes an ImageMoments object; the one that is constructing the MomentClip object of course. There is much control information embodied in the state of the ImageMoments object. This information is extracted by the MomentCalcBase class and passed on to MomentClip for consumption.

Note that the ancilliary lattice is only accessed if the ImageMoments object indicates that a pixel inclusion or exclusion range has been given as well as the pointer to the lattice having a non-zero value.

See the ImageMoments for discussion about the moments that are available for computation.

Example

This example comes from ImageMoments. outPt is a pointer block holding pointers to the output lattices. The ancilliary masking lattice is just a smoothed version of the input lattice.

    
    // Construct desired moment calculator object.  Use it polymorphically 
    // via a pointer to the base class.  os_P is a LogIO object.
    
      MomentCalcBase<T>* pMomentCalculator = 0;
      if (clipMethod || smoothClipMethod) {
         pMomentCalculator = new MomentClip<T>(pSmoothedImage, *this, os_p, outPt.nelements());
      } else if (windowMethod) {
         pMomentCalculator = new MomentWindow<T>(pSmoothedImage, *this, os_p, outPt.nelements());
      } else if (fitMethod) {
         pMomentCalculator = new MomentFit<T>(*this, os_p, outPt.nelements());
      }
    
    // Iterate optimally through the image, compute the moments, fill the output lattices
    
      LatticeApply<T>::lineMultiApply(outPt, *pInImage_p, *pMomentCalculator,   
                                      momentAxis_p, pProgressMeter);
      delete pMomentCalculator;
    
    

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

To Do

Member Description

MomentClip(Lattice<T>* pAncilliaryLattice, ImageMoments<T>& iMom, ImageMoments& os, const uInt nLatticeOut)

Constructor. The pointer is to an ancilliary lattice used as a mask. If no masking lattice is desired, the pointer value must be zero. We also need the ImageMoments object which is calling us, the ImageMoments logger, and the number of output lattices ImageMoments has created.

~MomentClip()

Destructor (does nothing).

virtual void process(T& out, Bool& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const Vector& pos)

This function is not implemented and throws an exception.

virtual void multiProcess(Vector<T>& out, Vector<Bool>& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const IPosition& pos)

This function returns a vector of numbers from each input vector. the output vector contains the moments known to the ImageMoments object passed into the constructor.

virtual Bool canHandleNullMask() const

Can handle null mask


template <class T> class MomentWindow : public MomentCalcBase<T>

Interface

MomentWindow(Lattice<T>* pAncilliaryLattice, ImageMoments<T>& iMom, ImageMoments& os, const uInt nLatticeOut)
~MomentWindow()
virtual void process(T& out, Bool& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const Vector& pos)
virtual void multiProcess(Vector<T>& out, Vector<Bool>& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const IPosition& pos)
Private Members
void drawWindow(const Vector<Int>& window, PGPlotter& plotter) const
Bool getAutoWindow(uInt& nFailed, Vector<Int>& window, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const T peakSNR, const T stdDeviation, const Bool doFit, PGPlotter& plotter, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const PGPlotter xLabel, const PGPlotter yLabel, const PGPlotter title) const
Bool getBosmaWindow (Vector<Int>& window, 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 PGPlotter xLabel, const PGPlotter yLabel, const PGPlotter title) const
Bool getInterDirectWindow(Bool& allSubsequent, LogIO& os, Vector<Int>& window, 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, String& plotter) const
Bool getInterWindow (uInt& nFailed, Bool& allSubsequent, LogIO& os, Vector<Int>& window, const Bool doFit, 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, String& plotter) const
Bool setNSigmaWindow(Vector<Int>& window, const T pos, const T width, const Int nPts, const Int N) const

Description

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Synopsis

This concrete class is derived from the abstract base class MomentCalcBase which provides an interface layer to the ImageMoments driver class. ImageMoments creates a MomentWindow object and passes it to the LatticeApply function lineMultiApply. This function iterates through a given lattice, and invokes the multiProcess member function of MomentWindow on each profile of pixels that it extracts from the input lattice. The multiProcess function returns a vector of moments which are inserted into the output lattices also supplied to the LatticeApply function.

MomentWindow computes moments from a subset of the pixels selected from the input profile. This subset is a simple index range, or window. The window is selected, for each profile, that is thought to surround the spectral feature of interest. This window can be found from the primary lattice, or from an ancilliary lattice (ImageMoments offers a smoothed version of the primary lattice as the ancilliary lattice). The moments are always computed from primary lattice data.

For each profile, the window can be found either interactively or automatically. There are two interactive methods. Either you just mark the window with the cursor, or you interactively fit a Gaussian to the profile and the +/- 3-sigma window is returned. There are two automatic methods. Either Bosma's converging mean algorithm is used, or an automatically fit Gaussian +/- 3-sigma window is returned.

The constructor takes an ImageMoments object; the one that is constructing the MomentWindow object of course. There is much control information embodied in the state of the ImageMoments object. This information is extracted by the MomentCalcBase class and passed on to MomentClip for consumption.

Note that the ancilliary lattice is only accessed if the pointer to it is non zero.

See the ImageMoments for discussion about the moments that are available for computation.

Example

    This example comes from ImageMoments.   outPt is a pointer block holding
    pointers to the output lattices.  The ancilliary masking lattice is
    just a smoothed version of the input lattice.  os_P is a LogIO object.
      
    <srcBlock>
    
    // Construct desired moment calculator object.  Use it polymorphically via 
    // a pointer to the base class.
     
      MomentCalcBase<T>* pMomentCalculator = 0;
      if (clipMethod || smoothClipMethod) {
         pMomentCalculator = new MomentClip<T>(pSmoothedImage, *this, os_p, outPt.nelements());
      } else if (windowMethod) {
         pMomentCalculator = new MomentWindow<T>(pSmoothedImage, *this, os_p, outPt.nelements());
      } else if (fitMethod) {
         pMomentCalculator = new MomentFit<T>(*this, os_p, outPt.nelements());
      }
     
    // Iterate optimally through the image, compute the moments, fill the output lattices
     
      LatticeApply<T>::lineMultiApply(outPt, *pInImage_p, *pMomentCalculator,   
                                      momentAxis_p, pProgressMeter);
      delete pMomentCalculator;
     
    

Motivation

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

To Do

Member Description

MomentWindow(Lattice<T>* pAncilliaryLattice, ImageMoments<T>& iMom, ImageMoments& os, const uInt nLatticeOut)

Constructor. The pointer is to a lattice containing the masking lattice (created by ImageMoments). We also need the ImageMoments object which is calling us, the ImageMoments logger, and the number of output lattices ImageMoments has created.

~MomentWindow()

Destructor (does nothing).

virtual void process(T& out, Bool& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const Vector& pos)

This function is not implemented and throws an exception.

virtual void multiProcess(Vector<T>& out, Vector<Bool>& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const IPosition& pos)

This function returns a vector of numbers from each input vector. the output vector contains the moments known to the ImageMoments object passed into the constructor.

void drawWindow(const Vector<Int>& window, PGPlotter& plotter) const

Draw two vertical lines marking a spectral window

Bool getAutoWindow(uInt& nFailed, Vector<Int>& window, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const T peakSNR, const T stdDeviation, const Bool doFit, PGPlotter& plotter, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const PGPlotter xLabel, const PGPlotter yLabel, const PGPlotter title) const

Automatically determine the spectral window

Bool getBosmaWindow (Vector<Int>& window, 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 PGPlotter xLabel, const PGPlotter yLabel, const PGPlotter title) const

Automatically determine the spectral window via Bosma's algorithm

Bool getInterDirectWindow(Bool& allSubsequent, LogIO& os, Vector<Int>& window, 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, String& plotter) const

Interactively specify the spectral window with the cursor

Bool getInterWindow (uInt& nFailed, Bool& allSubsequent, LogIO& os, Vector<Int>& window, const Bool doFit, 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, String& plotter) const

Interactively define the spectral window Returns false if can't define window.

Bool setNSigmaWindow(Vector<Int>& window, const T pos, const T width, const Int nPts, const Int N) const

Take the fitted Gaussian parameters and set an N-sigma window. If the window is too small return a Fail condition.


template <class T> class MomentFit : public MomentCalcBase<T>

Interface

Public Members
MomentFit(ImageMoments<T>& iMom, LogIO& os, const uInt nLatticeOut)
~MomentFit()
virtual void process(T& out, Bool& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const Vector& pos)
virtual void multiProcess(Vector<T>& out, Vector<Bool>& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const IPosition& pos)

Description

Review Status

Date Reviewed:
yyyy/mm/dd

Prerequisite

Synopsis

This concrete class is derived from the abstract base class MomentCalcBase which provides an interface layer to the ImageMoments driver class. ImageMoments creates a MomentFit object and passes it to the LatticeApply function, lineMultiApply. This function iterates through a given lattice, and invokes the multiProcess member function of MomentFit on each vector of pixels that it extracts from the input lattice. The multiProcess function returns a vector of moments which are inserted into the output lattices also supplied to the LatticeApply function.

MomentFit computes moments by fitting a Gaussian to each profile. The moments are then computed from that fit. The fitting can be done either interactively or automatically.

The constructor takes an ImageMoments object; the one that is constructing the MomentFit object of course. There is much control information embodied in the state of the ImageMoments object. This information is extracted by the MomentCalcBase class and passed on to MomentFit for consumption.

See the ImageMoments for discussion about the moments that are available for computation.

Example

    This example comes from ImageMoments.   outPt is a pointer block holding
    pointers to the output lattices.   os_P is a LogIO object.
                                        
    <srcBlock>
    
    // Construct desired moment calculator object.  Use it polymorphically via
    // a pointer to the base class.
    
      MomentCalcBase<T>* pMomentCalculator = 0;
      if (clipMethod || smoothClipMethod) {
         pMomentCalculator = new MomentClip<T>(pSmoothedImage, *this, os_p, outPt.nelements());
      } else if (windowMethod) {
         pMomentCalculator = new MomentWindow<T>(pSmoothedImage, *this, os_p, outPt.nelements());
      } else if (fitMethod) {
         pMomentCalculator = new MomentFit<T>(*this, os_p, outPt.nelements());
      }
    
    // Iterate optimally through the image, compute the moments, fill the output lattices
    
      LatticeApply<T>::lineMultiApply(outPt, *pInImage_p, *pMomentCalculator,   
                                      momentAxis_p, pProgressMeter);
      delete pMomentCalculator;
    

Motivation

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

To Do

Member Description

MomentFit(ImageMoments<T>& iMom, LogIO& os, const uInt nLatticeOut)

Constructor. We need the ImageMoments object which is calling us, the ImageMoments logger, and the number of output lattices ImageMoments has created.

~MomentFit()

Destructor (does nothing).

virtual void process(T& out, Bool& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const Vector& pos)

This function is not implemented and throws an exception.

virtual void multiProcess(Vector<T>& out, Vector<Bool>& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const IPosition& pos)

This function returns a vector of numbers from each input vector. the output vector contains the moments known to the ImageMoments object passed into the constructor.