Loading...
Searching...
No Matches
casacore::Fit2D Class Reference
lattices package (libcasa_lattices) » LatticeMath_module

More...

`#include <Fit2D.h>`

## Public Types

enum | Types { GAUSSIAN , DISK , LEVEL , PLANE , nTypes }
| Enum describing the different models you can fit. More...
enum | ErrorTypes { OK , NOCONVERGE , FAILED , NOGOOD , NOMODELS , nErrorTypes }
| Enum describing output error conditions. More...

## Public Member Functions

| Fit2D (LogIO &logger)
| Constructor.
| ~Fit2D ()
| Destructor.
| Fit2D (const Fit2D &other)
| Copy constructor.
Fit2D & | operator= (const Fit2D &other)
| Assignment operator.
uInt | addModel (Fit2D::Types type, const Vector< Double > &parameters, const Vector< Bool > &parameterMask)
| Add a model to the list to be simultaneously fit and return its index.
uInt | addModel (Fit2D::Types type, const Vector< Double > &parameters)
void | setIncludeRange (Double minVal, Double maxVal)
| Set a pixel selection range.
void | setExcludeRange (Double minVal, Double maxVal)
void | resetRange ()
uInt | nModels () const
| Recover number of models.
template<class T>
Vector< Double > | estimate (Fit2D::Types type, const MaskedLattice< T > &data)
| Determine an initial estimate for the solution of the specified model type to the given data - no compound models are allowable in this function.
template<class T>
Vector< Double > | estimate (Fit2D::Types type, const Lattice< T > &data)
template<class T>
Vector< Double > | estimate (Fit2D::Types type, const Array< T > &data)
template<class T>
Vector< Double > | estimate (Fit2D::Types type, const Array< T > &data, const Array< Bool > &mask)
template<class T>
Fit2D::ErrorTypes | fit (const MaskedLattice< T > &data, const Lattice< T > &sigma)
| Do the fit.
template<class T>
Fit2D::ErrorTypes | fit (const Lattice< T > &data, const Lattice< T > &sigma)
template<class T>
Fit2D::ErrorTypes | fit (const Array< T > &data, const Array< T > &sigma)
template<class T>
Fit2D::ErrorTypes | fit (const Array< T > &data, const Array< Bool > &mask, const Array< T > &sigma)
template<class T>
Fit2D::ErrorTypes | residual (Array< T > &resid, Array< T > &model, const Array< T > &data, Int xOffset=0, int yOffset=0) const
| Find the residuals to the fit.
Fit2D::ErrorTypes | residual (Array< Float > &resid, Array< Float > &model, const MaskedLattice< Float > &data)
Fit2D::ErrorTypes | residual (Array< Float > &resid, Array< Float > &model, const Lattice< Float > &data)
String | errorMessage () const
| If function fit failed, you will find a message here saying why it failed.
Vector< Double > | availableSolution () const
| Recover solution for either all model components or a specific one.
Vector< Double > | availableSolution (uInt which) const
Vector< Double > | availableErrors () const
| The errors.
Vector< Double > | availableErrors (uInt which) const
uInt | numberIterations () const
| The number of iterations that the fitter finished with.
Double | chiSquared () const
| The chi squared of the fit.
uInt | numberPoints () const
| The number of points used for the last fit.
Fit2D::Types | type (uInt which)
| Find type of specific model.

## Static Public Member Functions

static Vector< Bool > | convertMask (const String fixedmask, Fit2D::Types type)
| Convert mask from a string to a vector.
static uInt | nParameters (Fit2D::Types type)
| Return number of parameters for this type of model.
static String | type (Fit2D::Types type)
| Return type as a string.
static Fit2D::Types | type (const String &type)
| Return string type as enum (min match).
static Double | paToGauss2D (Double pa)
| Convert p.a.
static Double | paFromGauss2D (Double pa)
| Convert p.a.

## Private Member Functions

Fit2D::ErrorTypes | fitData (const Vector< Double > &values, const Matrix< Double > &pos, const Vector< Double > &sigma)
Vector< Double > | availableSolution (uInt &iStart, uInt which) const
| Returns available (adjustable + fixed) solution for model of interest and tells you where it began in the full solution vector Does no axial ratio nor position angle conversions from direct fit solution vector.
Vector< Double > | availableErrors (uInt &iStart, uInt which) const
Vector< Double > | getParams (uInt which) const
void | setParams (const Vector< Double > &params, uInt which)
Bool | includeIt (Double value, const Vector< Double > &range, Int includeIt) const
template<class T>
Bool | selectData (Matrix< Double > &pos, Vector< Double > &values, Vector< Double > &weights, const Array< T > &pixels, const Array< Bool > &mask, const Array< T > &sigma)
void | piRange (Double &pa) const

## Private Attributes

LogIO | itsLogger
Bool | itsValid
Bool | itsValidSolution
Bool | itsHasSigma
Bool | itsInclude
Vector< Double > | itsPixelRange
CompoundFunction< AutoDiff< Double > > | itsFunction
NonLinearFitLM< Double > | itsFitter
Vector< Double > | itsSolution
Vector< Double > | itsErrors
Double | itsChiSquared
String | itsErrorMessage
uInt | itsNumberPoints
Vector< uInt > | itsTypeList

## Detailed Description

Fit 2-D objects to 2-D Lattices or Arrays

### Intended use:

Public interface

### Prerequisite

- Lattice

### Synopsis

This class allows you to fit different types of 2-D models to either Lattices or Arrays. These must be 2 dimensional; for Lattices, the appropriate 2-D Lattice can be made with the SubLattice class.

You may fit more than one model simultaneously to the data. Models are added with the addModel method. With this method, you also specify the initial guesses of the parameters of the model. Any parameters involving coordinates are expected in zero-relative absolute pixel coordinates (e.g. the centre of a model). Additionally with the addModel method, you may specify which parameters are to be held fixed during the fitting process. This is done with the parameterMask Vector which is in the same order as the parameter Vector. A value of True indicates the parameter will be fitted for. Presently, when you say fix the minor axis, you really end up fixing the axial ratio (internals). I don't have a solution for this presently.

For Gaussians, the parameter Vector (input or output) consists, in order, of the peak, x location, y location, FWHM of major axis, FWHM of minor axis, and position angle of the major axis (in radians). The position angle is positive +x to +y in the pixel coordinate system ([0,0] in center of image) and in the range -2pi to 2pi. When the solution is recovered, the position angle will be in the range 0 to pi.

### Example

### To Do

- template it
- Speed up some Array calculations indexed with IPositions
- Don't handle Lattices simply by getting pixels into Arrays
- make an addModel interface taking functionals

Definition at line 96 of file Fit2D.h.

## Member Enumeration Documentation

## ErrorTypes

enum casacore::Fit2D::ErrorTypes

Enum describing output error conditions.

Enumerator
OK | ok
NOCONVERGE | Did not converge.
FAILED | Solution failed.
NOGOOD | There were no unmasked points.
NOMODELS | No models set.
nErrorTypes | Number of conditions.

Definition at line 110 of file Fit2D.h.

## Types

enum casacore::Fit2D::Types

Enum describing the different models you can fit.

Enumerator
GAUSSIAN |
DISK |
LEVEL |
PLANE |
nTypes |

Definition at line 101 of file Fit2D.h.

## Constructor & Destructor Documentation

## Fit2D() [1/2]

casacore::Fit2D::Fit2D | ( | LogIO & | logger | ) |

explicit

Constructor.

Referenced by Fit2D(), and operator=().

## ~Fit2D()

casacore::Fit2D::~Fit2D | ( |  | ) |

Destructor.

## Fit2D() [2/2]

casacore::Fit2D::Fit2D | ( | const Fit2D & | other | ) |

Copy constructor.

Uses copy semantics except for the logger for which a reference copy is made

References Fit2D().

## Member Function Documentation

## addModel() [1/2]

uInt casacore::Fit2D::addModel | ( | Fit2D::Types | type,
|  | const Vector< Double > & | parameters )

References type().

## addModel() [2/2]

uInt casacore::Fit2D::addModel | ( | Fit2D::Types | type,
|  | const Vector< Double > & | parameters,
|  | const Vector< Bool > & | parameterMask )

Add a model to the list to be simultaneously fit and return its index.

Specify the initial guesses for the model and a mask indicating whether the parameter is fixed (False) during the fit or not. Returns the the model number added (0, 1, 2 etc)

References type().

## availableErrors() [1/3]

Vector< Double > casacore::Fit2D::availableErrors | ( |  | ) | const

The errors.

All available parameters (fixed and adjustable) are included in the error vectors. Unsolved for parameters will have error 0.

## availableErrors() [2/3]

Vector< Double > casacore::Fit2D::availableErrors | ( | uInt & | iStart,
|  | uInt | which ) const

private

## availableErrors() [3/3]

Vector< Double > casacore::Fit2D::availableErrors | ( | uInt | which | ) | const

## availableSolution() [1/3]

Vector< Double > casacore::Fit2D::availableSolution | ( |  | ) | const

Recover solution for either all model components or a specific one.

These functions will return an empty vector if there is no valid solution. All available parameters (fixed and adjustable) are included in the solution vectors.

## availableSolution() [2/3]

Vector< Double > casacore::Fit2D::availableSolution | ( | uInt & | iStart,
|  | uInt | which ) const

private

Returns available (adjustable + fixed) solution for model of interest and tells you where it began in the full solution vector Does no axial ratio nor position angle conversions from direct fit solution vector.

## availableSolution() [3/3]

Vector< Double > casacore::Fit2D::availableSolution | ( | uInt | which | ) | const

## chiSquared()

Double casacore::Fit2D::chiSquared | ( |  | ) | const

The chi squared of the fit.

Returns 0 if fit has been done.

## convertMask()

Vector< Bool > casacore::Fit2D::convertMask | ( | const String | fixedmask,
|  | Fit2D::Types | type )

static

Convert mask from a string to a vector.

The string gives the parameters to keep fixed in the fit (f (flux), x (x position), y (y position), a (FWHM major axis), b (FWHM minor axis), p (position angle)

References type().

## errorMessage()

String casacore::Fit2D::errorMessage | ( |  | ) | const

If function fit failed, you will find a message here saying why it failed.

## estimate() [1/4]

template<class T>

Vector< Double > casacore::Fit2D::estimate | ( | Fit2D::Types | type,
|  | const Array< T > & | data )

References type().

## estimate() [2/4]

template<class T>

Vector< Double > casacore::Fit2D::estimate | ( | Fit2D::Types | type,
|  | const Array< T > & | data,
|  | const Array< Bool > & | mask )

References casacore::mask(), and type().

## estimate() [3/4]

template<class T>

Vector< Double > casacore::Fit2D::estimate | ( | Fit2D::Types | type,
|  | const Lattice< T > & | data )

References type().

## estimate() [4/4]

template<class T>

Vector< Double > casacore::Fit2D::estimate | ( | Fit2D::Types | type,
|  | const MaskedLattice< T > & | data )

Determine an initial estimate for the solution of the specified model type to the given data - no compound models are allowable in this function.

If you have specified an include or exclude pixel range to the fitter, that will be honoured. This function does not interact with the addModel function. Returns a zero length vector if it fails to make an estimate.

References type().

## fit() [1/4]

template<class T>

Fit2D::ErrorTypes casacore::Fit2D::fit | ( | const Array< T > & | data,
|  | const Array< Bool > & | mask,
|  | const Array< T > & | sigma )

References casacore::mask().

## fit() [2/4]

template<class T>

Fit2D::ErrorTypes casacore::Fit2D::fit | ( | const Array< T > & | data,
|  | const Array< T > & | sigma )

## fit() [3/4]

template<class T>

Fit2D::ErrorTypes casacore::Fit2D::fit | ( | const Lattice< T > & | data,
|  | const Lattice< T > & | sigma )

## fit() [4/4]

template<class T>

Fit2D::ErrorTypes casacore::Fit2D::fit | ( | const MaskedLattice< T > & | data,
|  | const Lattice< T > & | sigma )

Do the fit.

Returns an enum value to tell you what happened if the fit failed for some reasons. A message can also be found with function errorMessage if the fit was not successful. For Array(i,j) i is x and j is y

## fitData()

Fit2D::ErrorTypes casacore::Fit2D::fitData | ( | const Vector< Double > & | values,
|  | const Matrix< Double > & | pos,
|  | const Vector< Double > & | sigma )

private

## getParams()

Vector< Double > casacore::Fit2D::getParams | ( | uInt | which | ) | const

private

## includeIt()

Bool casacore::Fit2D::includeIt | ( | Double | value,
|  | const Vector< Double > & | range,
|  | Int | includeIt ) const

inline private

Definition at line 321 of file Fit2D.h.

References casacore::False, includeIt(), casacore::NewDelAllocator< T >::value, and casacore::True.

Referenced by includeIt(), and setParams().

## nModels()

uInt casacore::Fit2D::nModels | ( |  | ) | const

Recover number of models.

## nParameters()

uInt casacore::Fit2D::nParameters | ( | Fit2D::Types | type | ) |

static

Return number of parameters for this type of model.

References type().

## numberIterations()

uInt casacore::Fit2D::numberIterations | ( |  | ) | const

The number of iterations that the fitter finished with.

## numberPoints()

uInt casacore::Fit2D::numberPoints | ( |  | ) | const

The number of points used for the last fit.

## operator=()

Fit2D & casacore::Fit2D::operator= | ( | const Fit2D & | other | ) |

Assignment operator.

Uses copy semantics except for the logger for which a reference copy is made

References Fit2D().

## paFromGauss2D()

Double casacore::Fit2D::paFromGauss2D | ( | Double | pa | ) |

inline static

Convert p.a.

(radians) from positive +y -> -x (Gaussian2D) to positive +x -> +y (Fit2D)

Definition at line 274 of file Fit2D.h.

References casacore::pa().

## paToGauss2D()

Double casacore::Fit2D::paToGauss2D | ( | Double | pa | ) |

inline static

Convert p.a.

(radians) from positive +x -> +y (Fit2D) to positive +y -> -x (Gaussian2D)

Definition at line 270 of file Fit2D.h.

References casacore::pa().

## piRange()

void casacore::Fit2D::piRange | ( | Double & | pa | ) | const

private

References casacore::pa().

## resetRange()

void casacore::Fit2D::resetRange | ( |  | ) |

## residual() [1/3]

Fit2D::ErrorTypes casacore::Fit2D::residual | ( | Array< Float > & | resid,
|  | Array< Float > & | model,
|  | const Lattice< Float > & | data )

## residual() [2/3]

Fit2D::ErrorTypes casacore::Fit2D::residual | ( | Array< Float > & | resid,
|  | Array< Float > & | model,
|  | const MaskedLattice< Float > & | data )

## residual() [3/3]

template<class T>

Fit2D::ErrorTypes casacore::Fit2D::residual | ( | Array< T > & | resid,
|  | Array< T > & | model,
|  | const Array< T > & | data,
|  | Int | xOffset = 0,
|  | int | yOffset = 0 ) const

Find the residuals to the fit.

xOffset and yOffset allow one to provide a data array that is offset in space from the grid that was fit. In this way, one can fill out a larger image than the subimage that was fit, for example. A negative value of xOffset means the supplied data array represents a grid that has a y axis left of the grid of pixels that was fit. A negative yOffset value means the supplied data array represents a grid that has an x axis that is below the x axis of the grid of pixels that was fit. NOTE these may need to be templated at some point in the future. My current need does not require they be templated. - dmehring 29jun2018

## selectData()

template<class T>

Bool casacore::Fit2D::selectData | ( | Matrix< Double > & | pos,
|  | Vector< Double > & | values,
|  | Vector< Double > & | weights,
|  | const Array< T > & | pixels,
|  | const Array< Bool > & | mask,
|  | const Array< T > & | sigma )

private

References casacore::mask().

## setExcludeRange()

void casacore::Fit2D::setExcludeRange | ( | Double | minVal,
|  | Double | maxVal )

## setIncludeRange()

void casacore::Fit2D::setIncludeRange | ( | Double | minVal,
|  | Double | maxVal )

Set a pixel selection range.

When the fit is done, only pixels in the specified range are included/excluded. Only the last call of either of these will be active.

## setParams()

void casacore::Fit2D::setParams | ( | const Vector< Double > & | params,
|  | uInt | which )

private

References includeIt(), and casacore::NewDelAllocator< T >::value.

## type() [1/3]

Fit2D::Types casacore::Fit2D::type | ( | const String & | type | ) |

static

Return string type as enum (min match).

References type().

## type() [2/3]

String casacore::Fit2D::type | ( | Fit2D::Types | type | ) |

static

Return type as a string.

References type().

Referenced by addModel(), addModel(), convertMask(), estimate(), estimate(), estimate(), estimate(), nParameters(), type(), and type().

## type() [3/3]

Fit2D::Types casacore::Fit2D::type | ( | uInt | which | ) |

Find type of specific model.

## Member Data Documentation

## itsChiSquared

Double casacore::Fit2D::itsChiSquared

private

Definition at line 286 of file Fit2D.h.

## itsErrorMessage

String casacore::Fit2D::itsErrorMessage

private

Definition at line 287 of file Fit2D.h.

## itsErrors

Vector<Double> casacore::Fit2D::itsErrors

private

Definition at line 285 of file Fit2D.h.

## itsFitter

NonLinearFitLM<Double> casacore::Fit2D::itsFitter

private

Definition at line 283 of file Fit2D.h.

## itsFunction

CompoundFunction<AutoDiff<Double> > casacore::Fit2D::itsFunction

private

Definition at line 282 of file Fit2D.h.

## itsHasSigma

Bool casacore::Fit2D::itsHasSigma

private

Definition at line 279 of file Fit2D.h.

## itsInclude

Bool casacore::Fit2D::itsInclude

private

Definition at line 280 of file Fit2D.h.

## itsLogger

LogIO casacore::Fit2D::itsLogger

mutable private

Definition at line 278 of file Fit2D.h.

## itsNumberPoints

uInt casacore::Fit2D::itsNumberPoints

private

Definition at line 288 of file Fit2D.h.

## itsPixelRange

Vector<Double> casacore::Fit2D::itsPixelRange

private

Definition at line 281 of file Fit2D.h.

## itsSolution

Vector<Double> casacore::Fit2D::itsSolution

private

Definition at line 284 of file Fit2D.h.

## itsTypeList

Vector<uInt> casacore::Fit2D::itsTypeList

private

Definition at line 290 of file Fit2D.h.

## itsValid

Bool casacore::Fit2D::itsValid

private

Definition at line 279 of file Fit2D.h.

## itsValidSolution

Bool casacore::Fit2D::itsValidSolution

private

Definition at line 279 of file Fit2D.h.

The documentation for this class was generated from the following file:

- lattices/LatticeMath/Fit2D.h