1 | //# SpectralElement.h: Describes (a set of related) spectral lines |
---|
2 | //# Copyright (C) 2001,2003,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 | //# |
---|
27 | //# $Id: SpectralElement.h 21465 2014-06-19 05:56:56Z gervandiepen $ |
---|
28 | |
---|
29 | #ifndef COMPONENTS_SPECTRALELEMENT_H |
---|
30 | #define COMPONENTS_SPECTRALELEMENT_H |
---|
31 | |
---|
32 | #include <memory> |
---|
33 | #include <casa/aips.h> |
---|
34 | #include <casa/Arrays/Vector.h> |
---|
35 | #include <casa/Containers/RecordInterface.h> |
---|
36 | |
---|
37 | namespace casa { //# NAMESPACE CASA - BEGIN |
---|
38 | |
---|
39 | template <class T, class U> class Function; |
---|
40 | |
---|
41 | // <summary> |
---|
42 | // Describes (a set of related) spectral lines |
---|
43 | // </summary> |
---|
44 | |
---|
45 | // <use visibility=export> |
---|
46 | |
---|
47 | // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos=""> |
---|
48 | // </reviewed> |
---|
49 | |
---|
50 | // <prerequisite> |
---|
51 | // <li> <linkto module=Functionals>Functionals</linkto> module |
---|
52 | // </prerequisite> |
---|
53 | // |
---|
54 | // <etymology> |
---|
55 | // From spectral line and element |
---|
56 | // </etymology> |
---|
57 | // |
---|
58 | // <synopsis> |
---|
59 | // The SpectralElement class is the abstract base class for classes |
---|
60 | // describing spectral components (Gaussian, Polynonomial, etc). |
---|
61 | // |
---|
62 | // The element can be used in the |
---|
63 | // <linkto class=SpectralFit>SpectralFit</linkto> class and in the |
---|
64 | // <linkto class=SpectralEstimate>SpectralEstimate</linkto> class. |
---|
65 | // |
---|
66 | // </synopsis> |
---|
67 | // |
---|
68 | // <example> |
---|
69 | // </example> |
---|
70 | // |
---|
71 | // <motivation> |
---|
72 | // To have a container for 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 | |
---|
79 | class SpectralElement { |
---|
80 | public: |
---|
81 | |
---|
82 | //# Enumerations |
---|
83 | // Supported spectral components |
---|
84 | enum Types { |
---|
85 | // A gaussian profile |
---|
86 | GAUSSIAN, |
---|
87 | // A polynomial baseline |
---|
88 | POLYNOMIAL, |
---|
89 | // Any compiled string functional |
---|
90 | COMPILED, |
---|
91 | // Gaussian multiplet |
---|
92 | GMULTIPLET, |
---|
93 | // Lorentzian |
---|
94 | LORENTZIAN, |
---|
95 | // power log polynomial |
---|
96 | POWERLOGPOLY, |
---|
97 | // log transformed polynomial |
---|
98 | LOGTRANSPOLY, |
---|
99 | N_Types |
---|
100 | }; |
---|
101 | |
---|
102 | virtual ~SpectralElement(); |
---|
103 | |
---|
104 | virtual SpectralElement* clone() const = 0; |
---|
105 | |
---|
106 | // Evaluate the value of the element at x |
---|
107 | virtual Double operator()(const Double x) const; |
---|
108 | |
---|
109 | Bool operator==(const SpectralElement& other) const; |
---|
110 | |
---|
111 | // Get parameter n |
---|
112 | // <thrown> |
---|
113 | // <li> AipsError if illegal n |
---|
114 | // </thrown> |
---|
115 | virtual Double operator[](const uInt n) const; |
---|
116 | |
---|
117 | // Get all the types available as String and codes, and number available |
---|
118 | static const String* allTypes(Int &nall, |
---|
119 | const SpectralElement::Types *&typ); |
---|
120 | // Get a string from the type |
---|
121 | static const String &fromType(SpectralElement::Types tp); |
---|
122 | // Get a type from a (non-case sensitive; minimum match) String |
---|
123 | static Bool toType(SpectralElement::Types &tp, |
---|
124 | const String &typName); |
---|
125 | |
---|
126 | // Get type of this element |
---|
127 | SpectralElement::Types getType() const { return _type; } |
---|
128 | |
---|
129 | // Get all parameters |
---|
130 | void get(Vector<Double>& params) const; |
---|
131 | |
---|
132 | Vector<Double> get() const; |
---|
133 | |
---|
134 | // Get error estimates of parameters |
---|
135 | void getError(Vector<Double> &err) const; |
---|
136 | Vector<Double> getError() const; |
---|
137 | |
---|
138 | // Get the order (i.e. the number of parameters) |
---|
139 | uInt getOrder() const { return _params.size(); }; |
---|
140 | |
---|
141 | // Set the error fields |
---|
142 | virtual void setError(const Vector<Double> &err); |
---|
143 | |
---|
144 | // Set fixed parameters (True) or unset them (False) |
---|
145 | // <thrown> |
---|
146 | // <li> AipsError if incorrect number of parameters (e.g. not 3 for GAUSSIAN) |
---|
147 | // </thrown> |
---|
148 | |
---|
149 | // Fix/unfix all in one go |
---|
150 | virtual void fix(const Vector<Bool>& fix); |
---|
151 | |
---|
152 | // Get the fix state[s] |
---|
153 | const Vector<Bool> &fixed() const; |
---|
154 | |
---|
155 | // Save to a record. |
---|
156 | virtual Bool toRecord(RecordInterface& out) const; |
---|
157 | |
---|
158 | // set parameters |
---|
159 | virtual void set(const Vector<Double>& params); |
---|
160 | |
---|
161 | protected: |
---|
162 | |
---|
163 | SpectralElement() {} |
---|
164 | |
---|
165 | SpectralElement(Types type, const Vector<Double>& parms=Vector<Double>(0)); |
---|
166 | |
---|
167 | SpectralElement(const SpectralElement& other); |
---|
168 | |
---|
169 | SpectralElement &operator=(const SpectralElement& other); |
---|
170 | |
---|
171 | void _set(const Vector<Double>& params); |
---|
172 | |
---|
173 | void _setType(const Types type); |
---|
174 | |
---|
175 | void _setFunction(const SHARED_PTR<Function<Double, Double> >& f); |
---|
176 | |
---|
177 | virtual SHARED_PTR<Function<Double, Double> > _getFunction() const { |
---|
178 | return _function; |
---|
179 | } |
---|
180 | |
---|
181 | private: |
---|
182 | //#Data |
---|
183 | // type of element |
---|
184 | Types _type; |
---|
185 | |
---|
186 | // The parameters of the function. I.e. the polynomial coefficients; |
---|
187 | // amplitude, center and sigma of a Gaussian. |
---|
188 | Vector<Double> _params; |
---|
189 | // The errors of the parameters |
---|
190 | Vector<Double> _errors; |
---|
191 | // The indication if the parameter has to be fixed (True) or solved (False). |
---|
192 | // Solved is the default. |
---|
193 | Vector<Bool> _fixed; |
---|
194 | |
---|
195 | SHARED_PTR<Function<Double, Double> > _function; |
---|
196 | |
---|
197 | }; |
---|
198 | |
---|
199 | ostream &operator<<(ostream& os, const SpectralElement& elem); |
---|
200 | |
---|
201 | Bool near(const SpectralElement& s1, const SpectralElement& s2, const Double tol); |
---|
202 | |
---|
203 | Bool nearAbs(const SpectralElement& s1, const SpectralElement& s2, const Double tol); |
---|
204 | |
---|
205 | |
---|
206 | } //# NAMESPACE CASA - END |
---|
207 | |
---|
208 | #endif |
---|
209 | |
---|