source: branches/casa-release-4_3/external-alma/components/SpectralComponents/SpectralFit.h@ 3116

Last change on this file since 3116 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: 5.4 KB
Line 
1//# SpectralFit.h: Least Squares fitting of spectral elements to spectrum
2//# Copyright (C) 2001,2002
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//#
27//# $Id: SpectralFit.h 20229 2008-01-29 15:19:06Z gervandiepen $
28
29#ifndef COMPONENTS_SPECTRALFIT_H
30#define COMPONENTS_SPECTRALFIT_H
31
32//# Includes
33#include <casa/aips.h>
34#include <components/SpectralComponents/SpectralList.h>
35
36namespace casa { //# NAMESPACE CASA - BEGIN
37
38//# Forward Declarations
39class SpectralElement;
40template <class T> class Vector;
41
42// <summary>
43// Least Squares fitting of spectral elements to spectrum
44// </summary>
45
46// <use visibility=export>
47
48// <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos="">
49// </reviewed>
50
51// <prerequisite>
52// <li> <linkto module=Functionals>Functionals</linkto> module
53// <li> <linkto class=SpectralElement>SpectralElement</linkto> class
54// </prerequisite>
55//
56// <etymology>
57// From spectral line and fitting
58// </etymology>
59//
60// <synopsis>
61// The SpectralFit class will do a non-linear least squares solution
62// for a number of simultaneous spectral components. The initial guess
63// of the elements is given in a set of SpectralElements. The final solution
64// is returned in the same set.
65//
66// </synopsis>
67//
68// <example>
69// </example>
70//
71// <motivation>
72// To have a contained fitting of spectral profiles to an observed spectrum
73// </motivation>
74//
75// <todo asof="2001/02/04">
76// <li> add more profile types
77// </todo>
78
79class SpectralFit {
80 public:
81
82 //# Constructors
83 // Default constructor creates a default fitter without elements
84 SpectralFit();
85 // Construct for the given elements
86 explicit SpectralFit(const SpectralList &in);
87 // Copy constructor (deep copy)
88 SpectralFit(const SpectralFit &other);
89 // Destructor
90 ~SpectralFit();
91
92 //# Operators
93 // Assignment (copy semantics)
94 SpectralFit &operator=(const SpectralFit &other);
95
96 //# Member functions
97 // Set an element to be fitted
98 // <thrown>
99 // <li> AipsError if index too large
100 // </thrown>
101 void setFitElement(uInt index, const SpectralElement &elem);
102
103 // Add elements to be fitted
104 // <group>
105 void addFitElement(const SpectralElement &elem);
106 void addFitElement(const SpectralList &elem);
107 // </group>
108
109 // Clear the list to be fitted (for a re-use of the SpectralFit object)
110 void clear();
111
112 // Get the list being fitted
113 const SpectralList &list() const { return slist_p; };
114
115 // Fit the elements as given by the specified spectral elements
116 // at the frequencies x with values y. Weights of all points are equal.
117 // The mask (if specified) means: use point if True. Returns
118 // the convergence status.
119 // <group>
120 template <class MT>
121 Bool fit(const Vector<MT> &y, const Vector<MT> &x) {
122 return fit(y, x, static_cast<const Vector<Bool> *const>(0)); }
123 template <class MT>
124 Bool fit(const Vector<MT> &y,
125 const Vector<MT> &x, const Vector<Bool> &mask) {
126 return fit(y, x, &mask); }
127 // </group>
128
129 // Fit the elements as given by the specified spectral elements
130 // at the frequencies x with values y and weights sigma.
131 // The mask (if specified) means: use point if True.
132 // <group>
133 template <class MT>
134 Bool fit(const Vector<MT> &sigma,
135 const Vector<MT> &y,
136 const Vector<MT> &x) {
137 return fit(sigma, y, x, static_cast<const Vector<Bool> *const>(0)); }
138 template <class MT>
139 Bool fit(const Vector<MT> &sigma,
140 const Vector<MT> &y,
141 const Vector<MT> &x, const Vector<Bool> &mask) {
142 return fit(sigma, y, x, &mask); }
143 // </group>
144
145 // Get the number of iterations last fit
146 uInt nIterations() const { return iter_p; }
147
148 // Get ChiSq of the last fit
149 Double chiSq () const { return chiSq_p; }
150
151 private:
152 //#Data
153 // Elements to be fitted
154 SpectralList slist_p;
155 // Number of iterations last fit
156 uInt iter_p;
157 // ChiSq of last fit
158 Double chiSq_p;
159
160 //# Member functions
161 // Real fitters
162 // <group>
163 template <class MT>
164 Bool fit(const Vector<MT> &y,
165 const Vector<MT> &x,
166 const Vector<Bool> *mask);
167 template <class MT>
168 Bool fit(const Vector<MT> &sigma,
169 const Vector<MT> &y,
170 const Vector<MT> &x,
171 const Vector<Bool> *mask);
172 // </group>
173};
174
175
176} //# NAMESPACE CASA - END
177
178#ifndef CASACORE_NO_AUTO_TEMPLATES
179#include <components/SpectralComponents/SpectralFit2.tcc>
180#endif //# CASACORE_NO_AUTO_TEMPLATES
181#endif
Note: See TracBrowser for help on using the repository browser.