casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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 // <summary>
00039 // Describes (a set of related) spectral lines
00040 // </summary>
00041 
00042 // <use visibility=export>
00043 
00044 // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos="">
00045 // </reviewed>
00046 
00047 // <prerequisite>
00048 //   <li> <linkto module=Functionals>Functionals</linkto> module
00049 // </prerequisite>
00050 //
00051 // <etymology>
00052 // From spectral line and element
00053 // </etymology>
00054 //
00055 // <synopsis>
00056 // The SpectralElement class is the abstract base class for classes
00057 // describing spectral components (Gaussian, Polynonomial, etc).
00058 //
00059 // The element can be used in the
00060 // <linkto class=SpectralFit>SpectralFit</linkto> class and in the
00061 // <linkto class=SpectralEstimate>SpectralEstimate</linkto> class.
00062 //
00063 // </synopsis>
00064 //
00065 // <example>
00066 // </example>
00067 //
00068 // <motivation>
00069 // To have a container for fitting of spectral profiles to an observed spectrum
00070 // </motivation>
00071 //
00072 // <todo asof="2001/02/04">
00073 //   <li> add more profile types
00074 // </todo>
00075 
00076 class SpectralElement { // : public RecordTransformable {
00077 public:
00078 
00079         //# Enumerations
00080         // Types of spectral lines known
00081         enum Types {
00082                 // A gaussian profile
00083                 GAUSSIAN,
00084                 // A polynomial baseline
00085                 POLYNOMIAL,
00086                 // Any compiled string functional
00087                 COMPILED,
00088                 // Gaussian multiplet
00089                 GMULTIPLET,
00090                 // Lorentzian
00091                 LORENTZIAN,
00092                 N_Types
00093         };
00094 
00095         virtual ~SpectralElement();
00096 
00097         virtual SpectralElement* clone() const = 0;
00098 
00099         // Evaluate the value of the element at x
00100         virtual Double operator()(const Double x) const = 0;
00101 
00102         virtual Bool operator==(const SpectralElement& other) const;
00103 
00104         // Get parameter n
00105         // <thrown>
00106         //  <li> AipsError if illegal n
00107         // </thrown>
00108         virtual Double operator[](const uInt n) const;
00109 
00110         // Get all the types available as String and codes, and number available
00111         static const String* allTypes(Int &nall,
00112                         const SpectralElement::Types *&typ);
00113         // Get a string from the type
00114         static const String &fromType(SpectralElement::Types tp);
00115         // Get a type from a (non-case sensitive; minimum match) String
00116         static Bool toType(SpectralElement::Types &tp,
00117                         const String &typName);
00118 
00119         // Get the data for this element
00120         // <thrown>
00121         //  <li> AipsError if element does not have data
00122         //         (e.g. amplitude for POLYNOMIAL)
00123         // </thrown>
00124         // <group>
00125         // Get type of this element
00126         SpectralElement::Types getType() const { return tp_p; }
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 par_p.nelements(); };
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         SpectralElement() {}
00162 
00163         SpectralElement(const SpectralElement& other);
00164 
00165         SpectralElement &operator=(const SpectralElement& other);
00166 
00167         void _construct(const Types type, const Vector<Double>& params);
00168 
00169         void _set(const Vector<Double>& params);
00170 
00171         void _setType(const Types type);
00172 
00173 private:
00174         //#Data
00175         // type of element
00176         Types tp_p;
00177 
00178         // The parameters of the function. I.e. the polynomial coefficients;
00179         // amplitude, center and sigma of a Gaussian.
00180         Vector<Double> par_p;
00181         // The errors of the parameters
00182         Vector<Double> err_p;
00183         // The indication if the parameter has to be fixed (True) or solved (False).
00184         // Solved is the default.
00185         Vector<Bool> fix_p;
00186 
00187 };
00188 
00189 ostream &operator<<(ostream& os, const SpectralElement& elem);
00190 
00191 Bool near(const SpectralElement& s1, const SpectralElement& s2, const Double tol);
00192 
00193 Bool nearAbs(const SpectralElement& s1, const SpectralElement& s2, const Double tol);
00194 
00195 
00196 } //# NAMESPACE CASA - END
00197 
00198 #endif
00199