casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpectralFit.h
Go to the documentation of this file.
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>
35 
36 namespace casacore{
37 
38 template <class T> class Vector;
39 }
40 
41 namespace casa { //# NAMESPACE CASA - BEGIN
42 
43 //# Forward Declarations
44 class SpectralElement;
45 
46 // <summary>
47 // Least Squares fitting of spectral elements to spectrum
48 // </summary>
49 
50 // <use visibility=export>
51 
52 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos="">
53 // </reviewed>
54 
55 // <prerequisite>
56 // <li> <linkto module=Functionals>Functionals</linkto> module
57 // <li> <linkto class=SpectralElement>SpectralElement</linkto> class
58 // </prerequisite>
59 //
60 // <etymology>
61 // From spectral line and fitting
62 // </etymology>
63 //
64 // <synopsis>
65 // The SpectralFit class will do a non-linear least squares solution
66 // for a number of simultaneous spectral components. The initial guess
67 // of the elements is given in a set of SpectralElements. The final solution
68 // is returned in the same set.
69 //
70 // </synopsis>
71 //
72 // <example>
73 // </example>
74 //
75 // <motivation>
76 // To have a contained fitting of spectral profiles to an observed spectrum
77 // </motivation>
78 //
79 // <todo asof="2001/02/04">
80 // <li> add more profile types
81 // </todo>
82 
83 class SpectralFit {
84  public:
85 
86  //# Constructors
87  // Default constructor creates a default fitter without elements
88  SpectralFit();
89  // Construct for the given elements
90  explicit SpectralFit(const SpectralList &in);
91  // Copy constructor (deep copy)
92  SpectralFit(const SpectralFit &other);
93  // Destructor
94  ~SpectralFit();
95 
96  //# Operators
97  // Assignment (copy semantics)
98  SpectralFit &operator=(const SpectralFit &other);
99 
100  //# Member functions
101  // Set an element to be fitted
102  // <thrown>
103  // <li> casacore::AipsError if index too large
104  // </thrown>
105  void setFitElement(casacore::uInt index, const SpectralElement &elem);
106 
107  // Add elements to be fitted
108  // <group>
109  void addFitElement(const SpectralElement &elem);
110  void addFitElement(const SpectralList &elem);
111  // </group>
112 
113  // Clear the list to be fitted (for a re-use of the SpectralFit object)
114  void clear();
115 
116  // Get the list being fitted
117  const SpectralList &list() const { return slist_p; };
118 
119  // Fit the elements as given by the specified spectral elements
120  // at the frequencies x with values y. Weights of all points are equal.
121  // The mask (if specified) means: use point if true. Returns
122  // the convergence status.
123  // <group>
124  template <class MT>
126  return fit(y, x, static_cast<const casacore::Vector<casacore::Bool> *const>(0)); }
127  template <class MT>
130  return fit(y, x, &mask); }
131  // </group>
132 
133  // Fit the elements as given by the specified spectral elements
134  // at the frequencies x with values y and weights sigma.
135  // The mask (if specified) means: use point if true.
136  // <group>
137  template <class MT>
139  const casacore::Vector<MT> &y,
140  const casacore::Vector<MT> &x) {
141  return fit(sigma, y, x, static_cast<const casacore::Vector<casacore::Bool> *const>(0)); }
142  template <class MT>
144  const casacore::Vector<MT> &y,
146  return fit(sigma, y, x, &mask); }
147  // </group>
148 
149  // Get the number of iterations last fit
150  casacore::uInt nIterations() const { return iter_p; }
151 
152  // Get ChiSq of the last fit
153  casacore::Double chiSq () const { return chiSq_p; }
154 
155  private:
156  //#Data
157  // Elements to be fitted
159  // Number of iterations last fit
161  // ChiSq of last fit
163 
164  //# Member functions
165  // Real fitters
166  // <group>
167  template <class MT>
169  const casacore::Vector<MT> &x,
171  template <class MT>
173  const casacore::Vector<MT> &y,
174  const casacore::Vector<MT> &x,
176  // </group>
177 };
178 
179 
180 } //# NAMESPACE CASA - END
181 
182 #ifndef CASACORE_NO_AUTO_TEMPLATES
183 #include <components/SpectralComponents/SpectralFit2.tcc>
184 #endif //# CASACORE_NO_AUTO_TEMPLATES
185 #endif
SpectralFit()
Default constructor creates a default fitter without elements.
A 1-D Specialization of the Array class.
std::vector< double > Vector
Definition: ds9context.h:24
~SpectralFit()
Destructor.
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
void clear()
Clear the list to be fitted (for a re-use of the SpectralFit object)
void setFitElement(casacore::uInt index, const SpectralElement &elem)
Set an element to be fitted.
Least Squares fitting of spectral elements to spectrum.
Definition: SpectralFit.h:83
Describes (a set of related) spectral lines.
casacore::Bool fit(const casacore::Vector< MT > &y, const casacore::Vector< MT > &x, const casacore::Vector< casacore::Bool > &mask)
Definition: SpectralFit.h:128
double Double
Definition: aipstype.h:55
const SpectralList & list() const
Get the list being fitted.
Definition: SpectralFit.h:117
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
void addFitElement(const SpectralElement &elem)
Add elements to be fitted.
casacore::uInt nIterations() const
Get the number of iterations last fit.
Definition: SpectralFit.h:150
casacore::Double chiSq_p
ChiSq of last fit.
Definition: SpectralFit.h:162
A set of SpectralElements.
Definition: SpectralList.h:85
SpectralFit & operator=(const SpectralFit &other)
Assignment (copy semantics)
SpectralList slist_p
Elements to be fitted.
Definition: SpectralFit.h:158
casacore::uInt iter_p
Number of iterations last fit.
Definition: SpectralFit.h:160
casacore::Bool fit(const casacore::Vector< MT > &sigma, const casacore::Vector< MT > &y, const casacore::Vector< MT > &x, const casacore::Vector< casacore::Bool > &mask)
Definition: SpectralFit.h:143
casacore::Double chiSq() const
Get ChiSq of the last fit.
Definition: SpectralFit.h:153
casacore::Bool fit(const casacore::Vector< MT > &sigma, const casacore::Vector< MT > &y, const casacore::Vector< MT > &x)
Fit the elements as given by the specified spectral elements at the frequencies x with values y and w...
Definition: SpectralFit.h:138
casacore::Bool fit(const casacore::Vector< MT > &y, const casacore::Vector< MT > &x)
Fit the elements as given by the specified spectral elements at the frequencies x with values y...
Definition: SpectralFit.h:125
unsigned int uInt
Definition: aipstype.h:51
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42