source: branches/casa-release-4_3-test/external-alma/components/SpectralComponents/ProfileFit1D.h@ 3026

Last change on this file since 3026 was 2980, checked in by Malte Marquarding, 10 years ago

Add a copy of casacore/components/SpectralComponents to external-alma directory to prepare for its removal from casacore-trunk. DOn;t activate in SConscript yet.

File size: 9.1 KB
Line 
1//# ProfileFit1D.h: Class to fit profiles to vectors
2//# Copyright (C) 2004
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: aips2-request@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25//#
26//# $Id: ProfileFit1D.h 20299 2008-04-03 05:56:44Z gervandiepen $
27
28#ifndef COMPONENTS_PROFILEFIT1D_H
29#define COMPONENTS_PROFILEFIT1D_H
30
31//# Includes
32#include <casa/aips.h>
33#include <casa/Arrays/Vector.h>
34
35#include <components/SpectralComponents/SpectralList.h>
36#include <components/SpectralComponents/SpectralFit.h>
37
38namespace casa {
39
40class SpectralElement;
41
42// <summary>
43// Fit spectral components to a Vector of data
44// </summary>
45
46// <use visibility=export>
47
48// <reviewed reviewer="" date="" tests="tProfileFit1D.cc">
49// </reviewed>
50
51// <prerequisite>
52// <li> <linkto class="SpectralElement">SpectralElement</linkto>
53// <li> <linkto class="SpectralList">SpectralList</linkto>
54// <li> <linkto class="SpectralFit">SpectralFit</linkto>
55// </prerequisite>
56
57// <synopsis>
58// Fit lists (held in class SpectralList) of SpectralElements to a
59// Vector of data. Each SpectralElement can be one from a variety
60// of types. The values of the parameters for each SpectralElement
61// provide the initial starting guesses for the fitting process.
62// Also, a SpectralElement object holds a mask indicating whether
63// a parameter should be held fixed or solved for. After the
64// fitting is done, a new SpectralList holding SpectralElements with
65// the fitted parameters is created.
66//
67// For all the functions that return a status Bool, True is good. If
68// False is returned, an error message can be recovered with function
69// <src>errorMessage</src>, You should not proceed if False is returned.
70// </synopsis>
71
72// <example>
73// <srcblock>
74// const uInt n = 512;
75// Vector<Double> x(n);
76// Vector<Double> y(n);
77// Vector<Bool> m(n);
78//
79// // Code to fill data vectors x,y,m
80//
81// ProfileFit1D<Float> fitter;
82// Bool ok = fitter.setData (x, y, m);
83// ok = fitter.setGaussianElements (2);
84// ok = fitter.fit();
85// const SpectralList& fitList = fitter.getList(True);
86// </srcblock>
87// </example>
88
89// <todo asof="2004/07/10">
90// <li> Add constraints
91// </todo>
92//
93//
94// <note role=caution>
95// At the moment, because of templating limitations of the underlying
96// fitting classes, you must use template type Double. This restriction
97// will be lifted in the future.
98// </note>
99//
100
101template <class T> class ProfileFit1D
102{
103public:
104 // Constructor
105 ProfileFit1D();
106
107 // Destructor
108 ~ProfileFit1D();
109
110 // Copy constructor. Uses copy semantics.
111 ProfileFit1D(const ProfileFit1D& other);
112
113 // Assignment operator. Uses copy semantics.
114 ProfileFit1D& operator=(const ProfileFit1D& other);
115
116 // Set abcissa, ordinate, mask and weights. A True mask value means the
117 // data are good. If you don't specify the weights vector, all weights
118 // are assumed to be unity. If you don't specify a mask it will be
119 // created as all good.
120 // Status is returned, if False, error message can be recovered with <src>errorMessage</src>
121 // <group>
122 Bool setData (const Vector<Double>& x, const Vector<T>& y, const Vector<Bool>& mask,
123 const Vector<Double>& weight);
124 Bool setData (const Vector<Double>& x, const Vector<T>& y, const Vector<Bool>& mask);
125 Bool setData (const Vector<Double>& x, const Vector<T>& y);
126 // </group>
127
128 // Set a SpectralList of SpectralElements to fit for.
129 // The SpectralElements in the list hold the
130 // initial estimates and must reflect the abcissa and ordinate units.
131 // They also contain the information about whether
132 // specific parameters are to be held fixed or allowed to vary in
133 // the fitting process.
134 // You can recover the list of elements with function getList.
135 void setElements (const SpectralList& list);
136
137 // Set a SpectralList of Gaussian SpectralElements to fit for.
138 // The initial estimates for the Gaussians will be automatically determined.
139 // All of the parameters created by this function will be solved for
140 // by default. You can recover the list of elements with function getList.
141 // Status is returned, if False, error message can be
142 // recovered with <src>errorMessage</src>
143 Bool setGaussianElements (uInt nGauss);
144
145 // Add new SpectralElement(s) to the SpectralList (can be empty)
146 // of SpectralElements to be fit for.
147 //<group>
148 void addElement (const SpectralElement& el);
149 void addElements (const SpectralList& list);
150 // </group>
151
152 // Clear the SpectralList of elements to be fit for
153 void clearList ();
154
155 // Set range mask. You can specify a number of ranges
156 // via a vector of start indices (or X values) and a vector of end
157 // indices (or X values). When argument insideIsGood is True,
158 // a mask will be created which
159 // will be True (good) inside the ranges and bad (False)
160 // outside of those ranges. When argument insideIsGood is False,
161 // the mask will be False (bad) inside the ranges and
162 // True (good) outside of those ranges. When the data are fit, a total
163 // mask is formed combining (via a logical AND) the
164 // data mask (setData) and this range mask.
165 // Status is returned, if False, error message can be recovered with <src>errorMessage</src>
166 // <group>
167 Bool setRangeMask (const Vector<uInt>& startIndex,
168 const Vector<uInt>& endIndex,
169 Bool insideIsGood=True);
170 Bool setRangeMask (const Vector<T>& startIndex,
171 const Vector<T>& endIndex,
172 Bool insideIsGood=True);
173 // </group>
174
175 // Recover masks. These are the data mask (setData) the range
176 // mask (setRangeMask may be length zero) and the total
177 // mask combining the two.
178 // <group>
179 Vector<Bool> getDataMask() const {return itsDataMask;};
180 Vector<Bool> getRangeMask() const {return itsRangeMask;}
181 Vector<Bool> getTotalMask() const {return makeTotalMask();};
182 // </group>
183
184 // Do the fit and return status. Returns convergence status.
185 // Error conditions in the solution process will generate
186 // an AipsError exception and you should catch these yourself.
187 Bool fit ();
188
189 // Get Chi Squared of fit
190 Double getChiSquared () const {return itsFitter.chiSq();}
191
192 // Get number of iterations for last fit
193 Double getNumberIterations () const {return itsFitter.nIterations();}
194
195 // Recover the list of elements. You can get the elements
196 // as initially estimated (fit=False), or after fitting
197 // (fit=True). In the latter case, the SpectralElements
198 // hold the parameters and errors of the fit.
199 const SpectralList& getList (Bool fit=True) const;
200
201 // Recover vectors for the estimate, fit and residual.
202 // If you don't specify which element, all elements are included
203 // If the Vectors are returned with zero length, it means an error
204 // condition exists (e.g. asking for fit before you do one). In this
205 // case an error message can be recovered with function <src>errorMessage</src>.
206 //<group>
207 Vector<T> getEstimate (Int which=-1) const;
208 Vector<T> getFit (Int which=-1) const;
209 Vector<T> getResidual (Int which=-1, Bool fit=True) const;
210 //</group>
211
212 // Recover the error message
213 String errorMessage () const {return itsError;};
214
215private:
216 Vector<Double> itsX; // Abcissa (really should not be type T)
217 Vector<T> itsY; // Ordinate
218 Vector<Double> itsWeight; // Weights
219 Vector<Bool> itsDataMask; // Data mask
220 Vector<Bool> itsRangeMask; // Mask associated with ranges
221//
222 SpectralList itsList; // List of elements to fit for
223//
224 SpectralFit itsFitter; // Fitter
225 mutable String itsError; // Error message
226
227// Functions
228 Vector<Bool> makeTotalMask() const;
229 SpectralList getSubsetList (const SpectralList& list, Int which) const;
230 void checkType() const;
231 void copy(const ProfileFit1D<T>& other);
232};
233
234} //#End casa namespace
235#ifndef CASACORE_NO_AUTO_TEMPLATES
236#include <components/SpectralComponents/ProfileFit1D.tcc>
237#endif //# CASACORE_NO_AUTO_TEMPLATES
238#endif
Note: See TracBrowser for help on using the repository browser.