casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SpectralElement.h
Go to the documentation of this file.
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 20652 2009-07-06 05:04:32Z Malte.Marquarding $
28 
29 #ifndef COMPONENTS_SPECTRALELEMENT_H
30 #define COMPONENTS_SPECTRALELEMENT_H
31 
32 #include <casa/aips.h>
33 #include <casa/Arrays/Vector.h>
35 
36 namespace casacore{
37 
38 template <class T, class U> class Function;
39 }
40 
41 namespace casa { //# NAMESPACE CASA - BEGIN
42 
43 
44 // <summary>
45 // Describes (a set of related) spectral lines
46 // </summary>
47 
48 // <use visibility=export>
49 
50 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos="">
51 // </reviewed>
52 
53 // <prerequisite>
54 // <li> <linkto module=Functionals>Functionals</linkto> module
55 // </prerequisite>
56 //
57 // <etymology>
58 // From spectral line and element
59 // </etymology>
60 //
61 // <synopsis>
62 // The SpectralElement class is the abstract base class for classes
63 // describing spectral components (Gaussian, Polynonomial, etc).
64 //
65 // The element can be used in the
66 // <linkto class=SpectralFit>SpectralFit</linkto> class and in the
67 // <linkto class=SpectralEstimate>SpectralEstimate</linkto> class.
68 //
69 // </synopsis>
70 //
71 // <example>
72 // </example>
73 //
74 // <motivation>
75 // To have a container for fitting of spectral profiles to an observed spectrum
76 // </motivation>
77 //
78 // <todo asof="2001/02/04">
79 // <li> add more profile types
80 // </todo>
81 
83 public:
84 
85  //# Enumerations
86  // Supported spectral components
87  enum Types {
88  // A gaussian profile
90  // A polynomial baseline
92  // Any compiled string functional
94  // Gaussian multiplet
96  // Lorentzian
98  // power log polynomial
100  // log transformed polynomial
103  };
104 
105  virtual ~SpectralElement();
106 
107  virtual SpectralElement* clone() const = 0;
108 
109  // Evaluate the value of the element at x
110  virtual casacore::Double operator()(const casacore::Double x) const;
111 
112  casacore::Bool operator==(const SpectralElement& other) const;
113 
114  // Get parameter n
115  // <thrown>
116  // <li> casacore::AipsError if illegal n
117  // </thrown>
118  virtual casacore::Double operator[](const casacore::uInt n) const;
119 
120  // Get all the types available as casacore::String and codes, and number available
121  static const casacore::String* allTypes(casacore::Int &nall,
122  const SpectralElement::Types *&typ);
123  // Get a string from the type
125  // Get a type from a (non-case sensitive; minimum match) String
127  const casacore::String &typName);
128 
129  // Get type of this element
131 
132  // Get all parameters
133  void get(casacore::Vector<casacore::Double>& params) const;
134 
136 
137  // Get error estimates of parameters
140 
141  // Get the order (i.e. the number of parameters)
142  casacore::uInt getOrder() const { return _params.size(); };
143 
144  // Set the error fields
145  virtual void setError(const casacore::Vector<casacore::Double> &err);
146 
147  // Set fixed parameters (true) or unset them (false)
148  // <thrown>
149  // <li> casacore::AipsError if incorrect number of parameters (e.g. not 3 for GAUSSIAN)
150  // </thrown>
151 
152  // Fix/unfix all in one go
153  virtual void fix(const casacore::Vector<casacore::Bool>& fix);
154 
155  // Get the fix state[s]
157 
158  // Save to a record.
160 
161  // set parameters
162  virtual void set(const casacore::Vector<casacore::Double>& params);
163 
164 protected:
165 
167 
169 
170  SpectralElement(const SpectralElement& other);
171 
173 
174  void _set(const casacore::Vector<casacore::Double>& params);
175 
176  void _setType(const Types type);
177 
179 
180  virtual std::shared_ptr<casacore::Function<casacore::Double, casacore::Double> > _getFunction() const {
181  return _function;
182  }
183 
184 private:
185  //#Data
186  // type of element
188 
189  // The parameters of the function. I.e. the polynomial coefficients;
190  // amplitude, center and sigma of a Gaussian.
192  // The errors of the parameters
194  // The indication if the parameter has to be fixed (true) or solved (false).
195  // Solved is the default.
197 
198  std::shared_ptr<casacore::Function<casacore::Double, casacore::Double> > _function;
199 
200 };
201 
202 std::ostream &operator<<(std::ostream& os, const SpectralElement& elem);
203 
204 bool near(const SpectralElement& s1, const SpectralElement& s2, const casacore::Double tol);
205 
206 bool nearAbs(const SpectralElement& s1, const SpectralElement& s2, const casacore::Double tol);
207 
208 
209 } //# NAMESPACE CASA - END
210 
211 #endif
212 
virtual void setError(const casacore::Vector< casacore::Double > &err)
Set the error fields.
int Int
Definition: aipstype.h:50
Types _type
type of element
casacore::uInt getOrder() const
Get the order (i.e.
virtual casacore::Double operator[](const casacore::uInt n) const
Get parameter n.
bool nearAbs(const SpectralElement &s1, const SpectralElement &s2, const casacore::Double tol)
virtual casacore::Double operator()(const casacore::Double x) const
Evaluate the value of the element at x.
casacore::Bool operator==(const SpectralElement &other) const
ostream & operator<<(ostream &os, const PageHeaderCache &cache)
SpectralElement::Types getType() const
Get type of this element.
virtual Type type()
Return the type enum.
virtual SpectralElement * clone() const =0
static const casacore::String & fromType(SpectralElement::Types tp)
Get a string from the type.
casacore::Vector< casacore::Double > _errors
The errors of the parameters.
casacore::Vector< casacore::Double > _params
The parameters of the function.
Describes (a set of related) spectral lines.
log transformed polynomial
casacore::Vector< casacore::Bool > _fixed
The indication if the parameter has to be fixed (true) or solved (false).
virtual std::shared_ptr< casacore::Function< casacore::Double, casacore::Double > > _getFunction() const
std::shared_ptr< casacore::Function< casacore::Double, casacore::Double > > _function
casacore::Vector< casacore::Double > getError() const
Numerical functional interface class.
void _set(const casacore::Vector< casacore::Double > &params)
virtual ~SpectralElement()
double Double
Definition: aipstype.h:55
virtual void fix(const casacore::Vector< casacore::Bool > &fix)
Set fixed parameters (true) or unset them (false)
static const casacore::String * allTypes(casacore::Int &nall, const SpectralElement::Types *&typ)
Get all the types available as casacore::String and codes, and number available.
const casacore::Vector< casacore::Bool > & fixed() const
Get the fix state[s].
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
virtual void set(const casacore::Vector< casacore::Double > &params)
set parameters
Any compiled string functional.
static casacore::Bool toType(SpectralElement::Types &tp, const casacore::String &typName)
Get a type from a (non-case sensitive; minimum match) String.
bool near(const SpectralElement &s1, const SpectralElement &s2, const casacore::Double tol)
String: the storage and methods of handling collections of characters.
Definition: String.h:223
size_t size() const
Definition: ArrayBase.h:101
Types
Supported spectral components.
Abstract base class for Record classes.
void _setType(const Types type)
void _setFunction(const std::shared_ptr< casacore::Function< casacore::Double, casacore::Double > > &f)
SpectralElement & operator=(const SpectralElement &other)
virtual casacore::Bool toRecord(casacore::RecordInterface &out) const
Save to a record.
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