Fit2D.h
Classes
- Fit2D -- Fit 2-D objects to 2-D Lattices or Arrays (full description)
Types
- GAUSSIAN = 0
-
- DISK = 1
-
- LEVEL = 2
-
- nTypes
-
- OK = 0
-
ok
- NOCONVERGE = 1
-
Did not converge
- FAILED = 2
-
Solution failed
- NOGOOD = 3
-
There were no unmasked points
- NOMODELS = 4
-
No models set
- nErrorTypes
-
Number of conditions
Interface
- Public Members
- explicit Fit2D(LogIO& logger)
- ~Fit2D()
- Fit2D(const Fit2D& other)
- Fit2D& operator=(const Fit2D& other)
- uInt addModel (Fit2D::Types type, const Vector<Double>& parameters, const Vector<Bool>& parameterMask)
- uInt addModel(Fit2D::Types type, const Vector<Double>& parameters)
- static Vector<Bool> convertMask (const String fixedmask, Fit2D::Types type)
- void setIncludeRange (Double minVal, Double maxVal)
- void setExcludeRange (Double minVal, Double maxVal)
- void resetRange()
- static uInt nParameters (Fit2D::Types type)
- uInt nModels() const
- Vector<Double> estimate(Fit2D::Types type, const MaskedLattice<Float>& data)
- Vector<Double> estimate(Fit2D::Types type, const Lattice<Float>& data)
- Vector<Double> estimate(Fit2D::Types type, const Array<Float>& data)
- Vector<Double> estimate(Fit2D::Types type, const Array<Float>& data, const Array<Bool>& mask)
- Fit2D::ErrorTypes fit(const MaskedLattice<Float>& data, const Lattice<Float>& sigma)
- Fit2D::ErrorTypes fit(const Lattice<Float>& data, const Lattice<Float>& sigma)
- Fit2D::ErrorTypes fit(const Array<Float>& data, const Array<Float>& sigma)
- Fit2D::ErrorTypes fit(const Array<Float>& data, const Array<Bool>& mask, const Array<Float>& sigma)
- Fit2D::ErrorTypes residual(Array<Float>& resid, const Array<Float>& data)
- Fit2D::ErrorTypes residual(Array<Float>& resid, const MaskedLattice<Float>& data)
- Fit2D::ErrorTypes residual(Array<Float>& resid, const Lattice<Float>& data)
- String errorMessage () const
- Vector<Double> availableSolution () const
- Vector<Double> availableSolution (uInt which) const
- Vector<Double> availableErrors() const
- Vector<Double> availableErrors(uInt which) const
- uInt numberIterations() const
- Double chiSquared () const
- uInt numberPoints () const
- static String type(Fit2D::Types type)
- static Fit2D::Types type(const String& type)
- Fit2D::Types type(uInt which)
- static Double paToGauss2D (Double pa)
- static Double paFromGauss2D (Double pa)
- Private Members
- Fit2D::ErrorTypes fitData(const Vector<Double>& values, const Matrix<Double>& pos, const Vector<Double>& sigma)
- Vector<Double> availableSolution (uInt& iStart, uInt which) const
- Vector<Double> availableErrors (uInt& iStart, uInt which) const
- Vector<Double> getParams(uInt which) const
- void setParams(const Vector<Double>& params, uInt which)
- Bool includeIt (Float value, const Vector<Float>& range, Int includeIt) const
- Bool selectData (Matrix<Double>& pos, Vector<Double>& values, Vector<Double>& weights, const Array<Float>& pixels, const Array<Bool>& mask, const Array<Float>& sigma)
- void piRange (Double& pa) const
Prerequisite
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
Member Description
Enum describing the different models you can fit
Enum describing output error conditions
explicit Fit2D(LogIO& logger)
Constructor
Destructor
Fit2D(const Fit2D& other)
Copy constructor. Uses copy semantics except for the logger
for which a reference copy is made
Fit2D& operator=(const Fit2D& other)
Assignment operator. Uses copy semantics except for the logger
for which a reference copy is made
uInt addModel (Fit2D::Types type, const Vector<Double>& parameters, const Vector<Bool>& parameterMask)
uInt addModel(Fit2D::Types type, const Vector<Double>& parameters)
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)
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)
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.
Return number of parameters for this type of model
Recover number of models
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.
Fit2D::ErrorTypes fit(const MaskedLattice<Float>& data, const Lattice<Float>& sigma)
Fit2D::ErrorTypes fit(const Lattice<Float>& data, const Lattice<Float>& sigma)
Fit2D::ErrorTypes fit(const Array<Float>& data, const Array<Float>& sigma)
Fit2D::ErrorTypes fit(const Array<Float>& data, const Array<Bool>& mask, const Array<Float>& 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
Find the residuals to the fit.
If function fit failed, you will find a message here
saying why it failed
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.
The errors. All available parameters (fixed and adjustable) are
included in the error vectors. Unsolved for parameters will
have error 0.
The number of iterations that the fitter finished with
The chi squared of the fit. Returns 0 if fit has been done.
The number of points used for the last fit
Return type as a string
Return string type as enum (min match)
Fit2D::Types type(uInt which)
Find type of specific model
static Double paToGauss2D (Double pa)
Convert p.a. (radians) from positive +x -> +y
(Fit2D) to positive +y -> -x (Gaussian2D)
Convert p.a. (radians) from positive +y -> -x
(Gaussian2D) to positive +x -> +y (Fit2D)
Fit2D::ErrorTypes fitData(const Vector<Double>& values, const Matrix<Double>& pos, const Vector<Double>& sigma)
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
void setParams(const Vector<Double>& params, uInt which)
Bool includeIt (Float value, const Vector<Float>& range, Int includeIt) const
Bool selectData (Matrix<Double>& pos, Vector<Double>& values, Vector<Double>& weights, const Array<Float>& pixels, const Array<Bool>& mask, const Array<Float>& sigma)
void piRange (Double& pa) const