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

Last change on this file since 3150 was 3106, checked in by Takeshi Nakazato, 8 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes/No

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...


Check-in asap modifications from Jim regarding casacore namespace conversion.

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