LCOV - code coverage report
Current view: top level - components/SpectralComponents - SpectralElement.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 5 0.0 %
Date: 2024-10-10 15:00:01 Functions: 0 4 0.0 %

          Line data    Source code
       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: casa-feedback@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 <casacore/casa/aips.h>
      33             : #include <casacore/casa/Arrays/Vector.h>
      34             : #include <casacore/casa/Containers/RecordInterface.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             : 
      82             : class SpectralElement {
      83             : public:
      84             : 
      85             :         //# Enumerations
      86             :         // Supported spectral components
      87             :         enum Types {
      88             :                 // A gaussian profile
      89             :                 GAUSSIAN,
      90             :                 // A polynomial baseline
      91             :                 POLYNOMIAL,
      92             :                 // Any compiled string functional
      93             :                 COMPILED,
      94             :                 // Gaussian multiplet
      95             :                 GMULTIPLET,
      96             :                 // Lorentzian
      97             :                 LORENTZIAN,
      98             :                 // power log polynomial
      99             :                 POWERLOGPOLY,
     100             :                 // log transformed polynomial
     101             :                 LOGTRANSPOLY,
     102             :                 N_Types
     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
     124             :         static const casacore::String &fromType(SpectralElement::Types tp);
     125             :         // Get a type from a (non-case sensitive; minimum match) String
     126             :         static casacore::Bool toType(SpectralElement::Types &tp,
     127             :                         const casacore::String &typName);
     128             : 
     129             :         // Get type of this element
     130           0 :         SpectralElement::Types getType() const { return _type; }
     131             : 
     132             :         // Get all parameters
     133             :         void get(casacore::Vector<casacore::Double>& params) const;
     134             : 
     135             :         casacore::Vector<casacore::Double> get() const;
     136             : 
     137             :         // Get error estimates of parameters
     138             :         void getError(casacore::Vector<casacore::Double> &err) const;
     139             :         casacore::Vector<casacore::Double> getError() const;
     140             : 
     141             :         // Get the order (i.e. the number of parameters)
     142           0 :         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]
     156             :         const casacore::Vector<casacore::Bool> &fixed() const;
     157             : 
     158             :         // Save to a record.
     159             :         virtual casacore::Bool toRecord(casacore::RecordInterface& out) const;
     160             : 
     161             :         // set parameters
     162             :         virtual void set(const casacore::Vector<casacore::Double>& params);
     163             : 
     164             : protected:
     165             : 
     166           0 :         SpectralElement() {}
     167             : 
     168             :         SpectralElement(Types type, const casacore::Vector<casacore::Double>& parms=casacore::Vector<casacore::Double>(0));
     169             : 
     170             :         SpectralElement(const SpectralElement& other);
     171             : 
     172             :         SpectralElement &operator=(const SpectralElement& other);
     173             : 
     174             :         void _set(const casacore::Vector<casacore::Double>& params);
     175             : 
     176             :         void _setType(const Types type);
     177             : 
     178             :         void _setFunction(const std::shared_ptr<casacore::Function<casacore::Double, casacore::Double> >& f);
     179             : 
     180           0 :         virtual std::shared_ptr<casacore::Function<casacore::Double, casacore::Double> > _getFunction() const {
     181           0 :                 return _function;
     182             :         }
     183             : 
     184             : private:
     185             :         //#Data
     186             :         // type of element
     187             :         Types _type;
     188             : 
     189             :         // The parameters of the function. I.e. the polynomial coefficients;
     190             :         // amplitude, center and sigma of a Gaussian.
     191             :         casacore::Vector<casacore::Double> _params;
     192             :         // The errors of the parameters
     193             :         casacore::Vector<casacore::Double> _errors;
     194             :         // The indication if the parameter has to be fixed (true) or solved (false).
     195             :         // Solved is the default.
     196             :         casacore::Vector<casacore::Bool> _fixed;
     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             : 

Generated by: LCOV version 1.16