ImageFit1D.h

Classes

ImageFit1D -- Fit spectral components to a Vector of data from an image (full description)

template <class T> class ImageFit1D

Types

enum AbcissaType

PIXEL = 0
IM_NATIVE = 1
VELOCITY = 2
N_TYPES

Interface

Public Members
ImageFit1D()
ImageFit1D(const ImageInterface<T>& image, uInt axis=0)
ImageFit1D(const ImageInterface<T>& image, const ImageInterface<T>& weights, uInt axis=0)
~ImageFit1D()
ImageFit1D(const ImageFit1D& other)
ImageFit1D& operator=(const ImageFit1D& other)
void setImage (const ImageInterface<T>& im, const ImageInterface<T>& weights, uInt axis)
void setImage (const ImageInterface<T>& im, uInt axis)
Bool setData (const IPosition& pos, ImageFit1D<T>::AbcissaType type, Bool doAbs=True)
Bool setData (const ImageRegion& region, ImageFit1D<T>::AbcissaType type, Bool doAbs=True)
void setElements (const SpectralList& list)
void addElement (const SpectralElement& el)
void addElements (const SpectralList& list)
Bool setGaussianElements (uInt nGauss)
void clearList ()
Bool fit ()
Double getChiSquared () const
Double getNumberIterations () const
const SpectralList& getList (Bool fit=True) const
Vector<T> getEstimate (Int which=-1) const
Vector<T> getFit (Int which=-1) const
Vector<T> getResidual (Int which=-1, Bool fit=True) const
Vector<Bool> getTotalMask () const
String errorMessage () const
static Bool setAbcissaState (String& errMsg, ImageFit1D<T>::AbcissaType& type, CoordinateSystem& cSys, const String& xUnit, const String& doppler, uInt pixelAxis)
Private Members
void check() const
void checkType() const
void copy (const ImageFit1D<T>& other)
Bool makeAbcissa (Vector<Double>& x, ImageFit1D<T>::AbcissaType type, Bool doAbs)
void setWeightsImage (const ImageInterface<T>& im)

Description

Review Status

Programs:
Tests:

Prerequisite

Synopsis

Fit lists (held in class SpectralList) of SpectralElements to a Vector of data from the image. Each SpectralElement can be one from a variety of types. The values of the parameters for each SpectralElement provide the initial starting guesses for the fitting process.

You specify the domain in which the fit is to be done via the enum AbcissaType. The CoordinateSystem in the image is used to convert the pixel coordinates to the desired abcissa. You can change the units of the CoordinateSystem if you want to fit in different units. If you set an estimate yourself (function setElements or addElement) it is the callers responsibility that the elements are in the correct abcissa domain. Function setGaussianElements will automatically make an estimate in the correct domain.

Also, a SpectralElement object holds a mask indicating whether a parameter should be held fixed or solved for. After the fitting is done, a new SpectralList holding SpectralElements with the fitted parameters is created.

For all the functions that return a status Bool, True is good. If False is returned, an error message can be recovered with function errorMessage, You should not proceed if False is returned.

Exceptions will be thrown if you do not set the Image and axis via the constructor or setImage function.

Example

    PagedImage<Float> im("myimage");
    Int axis = 2;
    ImageFit1D<Float> fitter(image, axis);
    IPosition pos(in.ndim(),0);
    fitter.setData(pos, ImageFit1D<Float>::IM_NATIVE);     // Fit in native coordinate space
    fitter.setGaussianElements(3);                      // FIt 3 Gaussians
    if (fitter.fit()) {
       cerr << fitter.getList() << endl;                // Print result
    }
    
    

To Do

Member Description

enum AbcissaType

ImageFit1D()

Default Constructor (no image or axis set, so cannot be used). You must call setImage to use this object.

ImageFit1D(const ImageInterface<T>& image, uInt axis=0)

Constructor. Fitting weights are assumed all unity.

ImageFit1D(const ImageInterface<T>& image, const ImageInterface<T>& weights, uInt axis=0)

Constructor with fitting weights image. The data and weights images must be the same shape.

~ImageFit1D()

Destructor

ImageFit1D(const ImageFit1D& other)

Copy constructor. Uses reference semantics.

ImageFit1D& operator=(const ImageFit1D& other)

Assignment operator. Uses reference semantics.

void setImage (const ImageInterface<T>& im, const ImageInterface<T>& weights, uInt axis)
void setImage (const ImageInterface<T>& im, uInt axis)

Set Image(s) and axis

Bool setData (const IPosition& pos, ImageFit1D<T>::AbcissaType type, Bool doAbs=True)
Bool setData (const ImageRegion& region, ImageFit1D<T>::AbcissaType type, Bool doAbs=True)

Set the data to be fit. All non-profile axes data are averaged. For the profile axis, the full spectrum is taken. The abcissa world values are computed when you call these functions. The domain of the abcissa values is controlled by AbcissaType and doAbs (absolute coordinates). The CoordinateSystem in the image is used to convert from pixels to world values.

void setElements (const SpectralList& list)

Set a SpectralList of SpectralElements to fit for. These elements must be in the correct abcissa domain set in function setData. You must have already called setData to call this function. The SpectralElements in the list hold the initial estimates. They also contain the information about whether specific parameters are to be held fixed or allowed to vary in the fitting process. You can recover the list of elements with function getList.

void addElement (const SpectralElement& el)
void addElements (const SpectralList& list)

Add new SpectralElement(s) to the SpectralList (can be empty) of SpectralElements to be fit for. You must have already called setData to call this function.

Bool setGaussianElements (uInt nGauss)

Set a SpectralList of Gaussian SpectralElements to fit for. The initial estimates for the Gaussians will be automatically determined in the correct abcissa domain. All of the parameters created by this function will be solved for by default. You can recover the list of elements with function getList. Status is returned, if False, error message can be recovered with errorMessage

void clearList ()

Clear the SpectralList of elements to be fit for

Bool fit ()

Do the fit and return convergence status. Errors in the fitting process will generate an AipsError exception and you should catch these yourself.

Double getChiSquared () const

Get Chi Squared of fit

Double getNumberIterations () const

Get number of iterations for last fit

const SpectralList& getList (Bool fit=True) const

Recover the list of elements. You can get the elements as initially estimated (fit=False), or after fitting (fit=True). In the latter case, the SpectralElements hold the parameters and errors of the fit.

Vector<T> getEstimate (Int which=-1) const
Vector<T> getFit (Int which=-1) const
Vector<T> getResidual (Int which=-1, Bool fit=True) const

Recover vectors for the estimate, fit and residual. If you don't specify which element, all elements are included If the Vectors are returned with zero length, it means an error condition exists (e.g. asking for fit before you do one). In this case an error message can be recovered with function errorMessage.

Vector<Bool> getTotalMask () const

Get Total Mask (data and range mask)

String errorMessage () const

Recover the error message

static Bool setAbcissaState (String& errMsg, ImageFit1D<T>::AbcissaType& type, CoordinateSystem& cSys, const String& xUnit, const String& doppler, uInt pixelAxis)

Helper function. Sets up the CoordinateSystem to reflect the choice of abcissa unit and the doppler (if the axis is spectral).

void check() const

Error message

Functions

void checkType() const

void copy (const ImageFit1D<T>& other)

Bool makeAbcissa (Vector<Double>& x, ImageFit1D<T>::AbcissaType type, Bool doAbs)

void setWeightsImage (const ImageInterface<T>& im)