SpectralElement.h

Go to the documentation of this file.
00001 //# SpectralElement.h: Describes (a set of related) spectral lines
00002 //# Copyright (C) 2001,2003,2004
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //# $Id: SpectralElement.h 20652 2009-07-06 05:04:32Z Malte.Marquarding $
00028 
00029 #ifndef COMPONENTS_SPECTRALELEMENT_H
00030 #define COMPONENTS_SPECTRALELEMENT_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/Containers/RecordInterface.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 template <class T, class U> class Function;
00039 
00040 // <summary>
00041 // Describes (a set of related) spectral lines
00042 // </summary>
00043 
00044 // <use visibility=export>
00045 
00046 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <linkto module=Functionals>Functionals</linkto> module
00051 // </prerequisite>
00052 //
00053 // <etymology>
00054 // From spectral line and element
00055 // </etymology>
00056 //
00057 // <synopsis>
00058 // The SpectralElement class is the abstract base class for classes
00059 // describing spectral components (Gaussian, Polynonomial, etc).
00060 //
00061 // The element can be used in the
00062 // <linkto class=SpectralFit>SpectralFit</linkto> class and in the
00063 // <linkto class=SpectralEstimate>SpectralEstimate</linkto> class.
00064 //
00065 // </synopsis>
00066 //
00067 // <example>
00068 // </example>
00069 //
00070 // <motivation>
00071 // To have a container for fitting of spectral profiles to an observed spectrum
00072 // </motivation>
00073 //
00074 // <todo asof="2001/02/04">
00075 //   <li> add more profile types
00076 // </todo>
00077 
00078 class SpectralElement {
00079 public:
00080 
00081         //# Enumerations
00082         // Supported spectral components
00083         enum Types {
00084                 // A gaussian profile
00085                 GAUSSIAN,
00086                 // A polynomial baseline
00087                 POLYNOMIAL,
00088                 // Any compiled string functional
00089                 COMPILED,
00090                 // Gaussian multiplet
00091                 GMULTIPLET,
00092                 // Lorentzian
00093                 LORENTZIAN,
00094                 // power log polynomial
00095                 POWERLOGPOLY,
00096                 // log transformed polynomial
00097                 LOGTRANSPOLY,
00098                 N_Types
00099         };
00100 
00101         virtual ~SpectralElement();
00102 
00103         virtual SpectralElement* clone() const = 0;
00104 
00105         // Evaluate the value of the element at x
00106         virtual Double operator()(const Double x) const;
00107 
00108         Bool operator==(const SpectralElement& other) const;
00109 
00110         // Get parameter n
00111         // <thrown>
00112         //  <li> AipsError if illegal n
00113         // </thrown>
00114         virtual Double operator[](const uInt n) const;
00115 
00116         // Get all the types available as String and codes, and number available
00117         static const String* allTypes(Int &nall,
00118                         const SpectralElement::Types *&typ);
00119         // Get a string from the type
00120         static const String &fromType(SpectralElement::Types tp);
00121         // Get a type from a (non-case sensitive; minimum match) String
00122         static Bool toType(SpectralElement::Types &tp,
00123                         const String &typName);
00124 
00125         // Get type of this element
00126         SpectralElement::Types getType() const { return _type; }
00127 
00128         // Get all parameters
00129         void get(Vector<Double>& params) const;
00130 
00131         Vector<Double> get() const;
00132 
00133         // Get error estimates of parameters
00134         void getError(Vector<Double> &err) const;
00135         Vector<Double> getError() const;
00136 
00137         // Get the order (i.e. the number of parameters)
00138         uInt getOrder() const { return _params.size(); };
00139 
00140         // Set the error fields
00141         virtual void setError(const Vector<Double> &err);
00142 
00143         // Set fixed parameters (True) or unset them (False)
00144         // <thrown>
00145         //   <li> AipsError if incorrect number of parameters (e.g. not 3 for GAUSSIAN)
00146         // </thrown>
00147 
00148         // Fix/unfix all in one go
00149         virtual void fix(const Vector<Bool>& fix);
00150 
00151         // Get the fix state[s]
00152         const Vector<Bool> &fixed() const;
00153 
00154         // Save to a record.
00155         virtual Bool toRecord(RecordInterface& out) const;
00156 
00157         // set parameters
00158         virtual void set(const Vector<Double>& params);
00159 
00160 protected:
00161 
00162         SpectralElement() {}
00163 
00164         SpectralElement(Types type, const Vector<Double>& parms=Vector<Double>(0));
00165 
00166         SpectralElement(const SpectralElement& other);
00167 
00168         SpectralElement &operator=(const SpectralElement& other);
00169 
00170         void _set(const Vector<Double>& params);
00171 
00172         void _setType(const Types type);
00173 
00174         void _setFunction(const SHARED_PTR<Function<Double, Double> >& f);
00175 
00176         virtual SHARED_PTR<Function<Double, Double> > _getFunction() const {
00177                 return _function;
00178         }
00179 
00180 private:
00181         //#Data
00182         // type of element
00183         Types _type;
00184 
00185         // The parameters of the function. I.e. the polynomial coefficients;
00186         // amplitude, center and sigma of a Gaussian.
00187         Vector<Double> _params;
00188         // The errors of the parameters
00189         Vector<Double> _errors;
00190         // The indication if the parameter has to be fixed (True) or solved (False).
00191         // Solved is the default.
00192         Vector<Bool> _fixed;
00193 
00194         SHARED_PTR<Function<Double, Double> > _function;
00195 
00196 };
00197 
00198 ostream &operator<<(ostream& os, const SpectralElement& elem);
00199 
00200 Bool near(const SpectralElement& s1, const SpectralElement& s2, const Double tol);
00201 
00202 Bool nearAbs(const SpectralElement& s1, const SpectralElement& s2, const Double tol);
00203 
00204 
00205 } //# NAMESPACE CASA - END
00206 
00207 #endif
00208 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1