source: trunk/external-alma/components/SpectralComponents/SpectralElement.h@ 3006

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