Fit spectral components to a Vector of data from an image. More...
#include <ImageFit1D.h>
Public Types | |
enum | AbcissaType { PIXEL, IM_NATIVE, VELOCITY, N_TYPES } |
Public Member Functions | |
ImageFit1D (SHARED_PTR< const ImageInterface< T > > image, uInt axis=0) | |
Constructor. | |
ImageFit1D (SHARED_PTR< const ImageInterface< T > > image, SHARED_PTR< const ImageInterface< T > > weights, uInt axis=0) | |
Constructor with fitting weights image. | |
~ImageFit1D () | |
Destructor. | |
ImageFit1D (const ImageFit1D &other) | |
Copy constructor. | |
ImageFit1D & | operator= (const ImageFit1D &other) |
Assignment operator. | |
void | setData (const IPosition &pos, Array< FitterType >(*yfunc)(const Array< FitterType > &)=0) |
Set the data to be fit. | |
void | setData (const IPosition &pos, const ImageFit1D< T >::AbcissaType type, const Bool doAbs=True, const Double *const &abscissaDivisor=0, Array< Double >(*xfunc)(const Array< Double > &)=0, Array< FitterType >(*yfunc)(const Array< FitterType > &)=0) |
void | setElements (const SpectralList &list) |
Set a SpectralList of SpectralElements to fit for. | |
void | addElement (const SpectralElement &el) |
Add new SpectralElement(s) to the SpectralList (can be empty) of SpectralElements to be fit for. | |
void | addElements (const SpectralList &list) |
void | setGaussianElements (uInt nGauss) |
Set a SpectralList of Gaussian SpectralElements to fit for. | |
void | clearList () |
Clear the SpectralList of elements to be fit for. | |
Bool | fit () |
Do the fit and return convergence status. | |
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. | |
Vector< T > | getEstimate (Int which=-1) const |
Recover vectors for the estimate, fit and residual. | |
Vector< T > | getFit (Int which=-1) const |
Vector< T > | getResidual (Int which=-1, Bool fit=True) const |
Bool | setXMask (const std::set< uInt > &indices, Bool specifiedPixelsAreGood) |
Vector< Bool > | getDataMask () const |
get data mask | |
Vector< Bool > | getTotalMask () const |
Get Total Mask (data and range mask). | |
Bool | succeeded () const |
did the fit succeed? should only be called after fit(). | |
Bool | converged () const |
did the fit converge? should only be called after fit(). | |
void | invalidate () |
flag the solution as invalid based on external criteria. | |
Bool | isValid () const |
is the solution valid? If False, some external logic has called invalidate() | |
void | setAbscissa (const Vector< Double > &x) |
Set the abscissa values prior to running setData. | |
Vector< Double > | makeAbscissa (ImageFit1D< T >::AbcissaType type, Bool doAbs, const Double *const &abscissaDivisor) |
make the abscissa values, x . | |
Static Public Member Functions | |
static Bool | setAbcissaState (String &errMsg, ImageFit1D< T >::AbcissaType &type, CoordinateSystem &cSys, const String &xUnit, const String &doppler, uInt pixelAxis) |
Helper function. | |
Private Member Functions | |
ImageFit1D () | |
Disallow default constructor. | |
void | check () const |
void | checkType () const |
void | _construct () |
void | copy (const ImageFit1D< T > &other) |
void | _resetFitter () |
void setWeightsImage (const ImageInterface<T>& im); | |
Private Attributes | |
SHARED_PTR< const ImageInterface< T > > | _image |
SHARED_PTR< const ImageInterface< T > > | _weights |
uInt | _axis |
ProfileFit1D< FitterType > | _fitter |
In the future I will be able to template the fitter on T. | |
Bool | _converged |
Bool | _success |
Bool | _isValid |
Vector< Double > | _x |
Vector< Double > | _unityWeights |
Vector< Double > | _weightSlice |
IPosition | _sliceShape |
Fit spectral components to a Vector of data from an image.
Public interface
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.
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 }
Definition at line 117 of file ImageFit1D.h.
enum casa::ImageFit1D::AbcissaType |
Definition at line 122 of file ImageFit1D.h.
casa::ImageFit1D< T >::ImageFit1D | ( | SHARED_PTR< const ImageInterface< T > > | image, | |
uInt | axis = 0 | |||
) |
Constructor.
Fitting weights are assumed all unity.
casa::ImageFit1D< T >::ImageFit1D | ( | SHARED_PTR< const ImageInterface< T > > | image, | |
SHARED_PTR< const ImageInterface< T > > | weights, | |||
uInt | axis = 0 | |||
) |
Constructor with fitting weights image.
The data and weights images must be the same shape.
casa::ImageFit1D< T >::~ImageFit1D | ( | ) |
Destructor.
casa::ImageFit1D< T >::ImageFit1D | ( | const ImageFit1D< T > & | other | ) |
Copy constructor.
Uses reference semantics.
casa::ImageFit1D< T >::ImageFit1D | ( | ) | [inline, private] |
Disallow default constructor.
Definition at line 304 of file ImageFit1D.h.
void casa::ImageFit1D< T >::_construct | ( | ) | [private] |
void casa::ImageFit1D< T >::_resetFitter | ( | ) | [private] |
void setWeightsImage (const ImageInterface<T>& im);
reset the fitter, for example if we've done a fit and want to move to the next position in the image
void casa::ImageFit1D< T >::addElement | ( | const SpectralElement & | el | ) | [inline] |
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.
Definition at line 204 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, and casa::ProfileFit1D< T >::addElement().
void casa::ImageFit1D< T >::addElements | ( | const SpectralList & | list | ) | [inline] |
Definition at line 205 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, and casa::ProfileFit1D< T >::addElements().
void casa::ImageFit1D< T >::check | ( | ) | const [private] |
void casa::ImageFit1D< T >::checkType | ( | ) | const [private] |
void casa::ImageFit1D< T >::clearList | ( | ) | [inline] |
Clear the SpectralList of elements to be fit for.
Definition at line 217 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, and casa::ProfileFit1D< T >::clearList().
Bool casa::ImageFit1D< T >::converged | ( | ) | const |
did the fit converge? should only be called after fit().
void casa::ImageFit1D< T >::copy | ( | const ImageFit1D< T > & | other | ) | [private] |
Bool casa::ImageFit1D< T >::fit | ( | ) |
Do the fit and return convergence status.
Errors in the fitting process will generate an AipsError exception and you should catch these yourself.
Referenced by casa::ImageFit1D< T >::getList().
Double casa::ImageFit1D< T >::getChiSquared | ( | ) | const [inline] |
Get Chi Squared of fit.
Definition at line 225 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, and casa::ProfileFit1D< T >::getChiSquared().
Vector<Bool> casa::ImageFit1D< T >::getDataMask | ( | ) | const [inline] |
get data mask
Definition at line 252 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, and casa::ProfileFit1D< T >::getDataMask().
Vector<T> casa::ImageFit1D< T >::getEstimate | ( | Int | which = -1 |
) | 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<T> casa::ImageFit1D< T >::getFit | ( | Int | which = -1 |
) | const |
const SpectralList& casa::ImageFit1D< T >::getList | ( | Bool | fit = True |
) | const [inline] |
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.
Definition at line 234 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, casa::ImageFit1D< T >::fit(), and casa::ProfileFit1D< T >::getList().
Double casa::ImageFit1D< T >::getNumberIterations | ( | ) | const [inline] |
Get number of iterations for last fit.
Definition at line 228 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, and casa::ProfileFit1D< T >::getNumberIterations().
Vector<T> casa::ImageFit1D< T >::getResidual | ( | Int | which = -1 , |
|
Bool | fit = True | |||
) | const |
Vector<Bool> casa::ImageFit1D< T >::getTotalMask | ( | ) | const [inline] |
Get Total Mask (data and range mask).
Definition at line 255 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, and casa::ProfileFit1D< T >::getTotalMask().
void casa::ImageFit1D< T >::invalidate | ( | ) |
flag the solution as invalid based on external criteria.
Bool casa::ImageFit1D< T >::isValid | ( | ) | const |
is the solution valid? If False, some external logic has called invalidate()
Vector<Double> casa::ImageFit1D< T >::makeAbscissa | ( | ImageFit1D< T >::AbcissaType | type, | |
Bool | doAbs, | |||
const Double *const & | abscissaDivisor | |||
) |
make the abscissa values, x
.
If type
=IN_NATIVE and abscissaDivisor is not null, then divide the native values by the value pointed to by <src>abscissaDivisor
in making the abscissa values.
ImageFit1D& casa::ImageFit1D< T >::operator= | ( | const ImageFit1D< T > & | other | ) |
Assignment operator.
Uses reference semantics.
static Bool casa::ImageFit1D< T >::setAbcissaState | ( | String & | errMsg, | |
ImageFit1D< T >::AbcissaType & | type, | |||
CoordinateSystem & | cSys, | |||
const String & | xUnit, | |||
const String & | doppler, | |||
uInt | pixelAxis | |||
) | [static] |
Helper function.
Sets up the CoordinateSystem to reflect the choice of abcissa unit and the doppler (if the axis is spectral).
void casa::ImageFit1D< T >::setAbscissa | ( | const Vector< Double > & | x | ) | [inline] |
Set the abscissa values prior to running setData.
If this is done, then the abscissa values will not be recomputed when setData is called. This can imporove performance if, for example, you are looping over several fitters for which you know the abscissa values do not change.
Definition at line 281 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_x.
void casa::ImageFit1D< T >::setData | ( | const IPosition & | pos, | |
const ImageFit1D< T >::AbcissaType | type, | |||
const Bool | doAbs = True , |
|||
const Double *const & | abscissaDivisor = 0 , |
|||
Array< Double >(*)(const Array< Double > &) | xfunc = 0 , |
|||
Array< FitterType >(*)(const Array< FitterType > &) | yfunc = 0 | |||
) |
void casa::ImageFit1D< T >::setData | ( | const IPosition & | pos, | |
Array< FitterType >(*)(const Array< FitterType > &) | yfunc = 0 | |||
) |
Set the data to be fit.
All non-profile axes data are averaged. For the profile axis, the full spectrum is taken. The abscissa world values are computed when you call these functions unless they have been set previously by a call to setAbscissa() in which case the values that were passed to that method are used. Use the first form of setData() in this case. The domain of the abscissa values is controlled by AbcissaType
and doAbs
(absolute coordinates). The CoordinateSystem in the image is used to convert from pixels to world values. If type
=IN_NATIVE and abscissaDivisor
is not null, the world abscissa values will be divided by the value pointed to by abscissaDivisor
. This mitigates having very large or very small abscissa values when fitting. If xfunc and/or yfunc is not NULL, the x and/or y values are fed to the specified function and the resultant values are what are used for the x and/or y values in the fit. If xfunc is not NULL and setAbscissa values has been called prior, no abscissa value transformation occurs. Thus if you want to apply a function to the abscissa values, the caller should pass the result of that function into setAbscissaValues.
void casa::ImageFit1D< T >::setElements | ( | const SpectralList & | list | ) | [inline] |
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.
Definition at line 198 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, and casa::ProfileFit1D< T >::setElements().
void casa::ImageFit1D< T >::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
Bool casa::ImageFit1D< T >::setXMask | ( | const std::set< uInt > & | indices, | |
Bool | specifiedPixelsAreGood | |||
) | [inline] |
Definition at line 247 of file ImageFit1D.h.
References casa::ImageFit1D< T >::_fitter, and casa::ProfileFit1D< T >::setXMask().
Bool casa::ImageFit1D< T >::succeeded | ( | ) | const |
did the fit succeed? should only be called after fit().
uInt casa::ImageFit1D< T >::_axis [private] |
Definition at line 293 of file ImageFit1D.h.
Bool casa::ImageFit1D< T >::_converged [private] |
Definition at line 299 of file ImageFit1D.h.
ProfileFit1D<FitterType> casa::ImageFit1D< T >::_fitter [private] |
In the future I will be able to template the fitter on T.
For now it must be Double.
Definition at line 298 of file ImageFit1D.h.
Referenced by casa::ImageFit1D< T >::addElement(), casa::ImageFit1D< T >::addElements(), casa::ImageFit1D< T >::clearList(), casa::ImageFit1D< T >::getChiSquared(), casa::ImageFit1D< T >::getDataMask(), casa::ImageFit1D< T >::getList(), casa::ImageFit1D< T >::getNumberIterations(), casa::ImageFit1D< T >::getTotalMask(), casa::ImageFit1D< T >::setElements(), and casa::ImageFit1D< T >::setXMask().
SHARED_PTR<const ImageInterface<T> > casa::ImageFit1D< T >::_image [private] |
Definition at line 292 of file ImageFit1D.h.
Bool casa::ImageFit1D< T >::_isValid [private] |
Definition at line 299 of file ImageFit1D.h.
IPosition casa::ImageFit1D< T >::_sliceShape [private] |
Definition at line 301 of file ImageFit1D.h.
Bool casa::ImageFit1D< T >::_success [private] |
Definition at line 299 of file ImageFit1D.h.
Vector<Double> casa::ImageFit1D< T >::_unityWeights [private] |
Definition at line 300 of file ImageFit1D.h.
SHARED_PTR<const ImageInterface<T> > casa::ImageFit1D< T >::_weights [private] |
Definition at line 292 of file ImageFit1D.h.
Vector<Double> casa::ImageFit1D< T >::_weightSlice [private] |
Definition at line 300 of file ImageFit1D.h.
Vector<Double> casa::ImageFit1D< T >::_x [private] |
Definition at line 300 of file ImageFit1D.h.
Referenced by casa::ImageFit1D< T >::setAbscissa().