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

Last change on this file since 3130 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
RevLine 
[2980]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
[3029]32#include <memory>
[2980]33#include <casa/aips.h>
34#include <casa/Arrays/Vector.h>
35#include <casa/Containers/RecordInterface.h>
36
[3106]37using namespace casacore;
38
[2980]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
[3106]109 virtual casacore::Double operator()(const casacore::Double x) const;
[2980]110
[3106]111 casacore::Bool operator==(const SpectralElement& other) const;
[2980]112
113 // Get parameter n
114 // <thrown>
115 // <li> AipsError if illegal n
116 // </thrown>
[3106]117 virtual casacore::Double operator[](const uInt n) const;
[2980]118
[3106]119 // Get all the types available as casacore::String and codes, and number available
120 static const casacore::String* allTypes(Int &nall,
[2980]121 const SpectralElement::Types *&typ);
122 // Get a string from the type
[3106]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);
[2980]127
128 // Get type of this element
129 SpectralElement::Types getType() const { return _type; }
130
131 // Get all parameters
[3106]132 void get(casacore::Vector<casacore::Double>& params) const;
[2980]133
[3106]134 casacore::Vector<casacore::Double> get() const;
[2980]135
136 // Get error estimates of parameters
[3106]137 void getError(casacore::Vector<casacore::Double> &err) const;
138 casacore::Vector<casacore::Double> getError() const;
[2980]139
140 // Get the order (i.e. the number of parameters)
141 uInt getOrder() const { return _params.size(); };
142
143 // Set the error fields
[3106]144 virtual void setError(const casacore::Vector<casacore::Double> &err);
[2980]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
[3106]152 virtual void fix(const casacore::Vector<casacore::Bool>& fix);
[2980]153
154 // Get the fix state[s]
[3106]155 const casacore::Vector<casacore::Bool> &fixed() const;
[2980]156
157 // Save to a record.
[3106]158 virtual casacore::Bool toRecord(RecordInterface& out) const;
[2980]159
160 // set parameters
[3106]161 virtual void set(const casacore::Vector<casacore::Double>& params);
[2980]162
163protected:
164
165 SpectralElement() {}
166
[3106]167 SpectralElement(Types type, const casacore::Vector<casacore::Double>& parms=casacore::Vector<casacore::Double>(0));
[2980]168
169 SpectralElement(const SpectralElement& other);
170
171 SpectralElement &operator=(const SpectralElement& other);
172
[3106]173 void _set(const casacore::Vector<casacore::Double>& params);
[2980]174
175 void _setType(const Types type);
176
[3106]177 void _setFunction(const SHARED_PTR<Function<casacore::Double, casacore::Double> >& f);
[2980]178
[3106]179 virtual SHARED_PTR<Function<casacore::Double, casacore::Double> > _getFunction() const {
[2980]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.
[3106]190 casacore::Vector<casacore::Double> _params;
[2980]191 // The errors of the parameters
[3106]192 casacore::Vector<casacore::Double> _errors;
[2980]193 // The indication if the parameter has to be fixed (True) or solved (False).
194 // Solved is the default.
[3106]195 casacore::Vector<casacore::Bool> _fixed;
[2980]196
[3106]197 SHARED_PTR<Function<casacore::Double, casacore::Double> > _function;
[2980]198
199};
200
201ostream &operator<<(ostream& os, const SpectralElement& elem);
202
[3106]203casacore::Bool near(const SpectralElement& s1, const SpectralElement& s2, const casacore::Double tol);
[2980]204
[3106]205casacore::Bool nearAbs(const SpectralElement& s1, const SpectralElement& s2, const casacore::Double tol);
[2980]206
207
208} //# NAMESPACE CASA - END
209
210#endif
211
Note: See TracBrowser for help on using the repository browser.