LCOV - code coverage report
Current view: top level - components/SpectralComponents - SpectralFit.h (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 4 7 57.1 %
Date: 2023-10-25 08:47:59 Functions: 3 5 60.0 %

          Line data    Source code
       1             : //# SpectralFit.h: Least Squares fitting of spectral elements to spectrum
       2             : //# Copyright (C) 2001,2002
       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: SpectralFit.h 20229 2008-01-29 15:19:06Z gervandiepen $
      28             : 
      29             : #ifndef COMPONENTS_SPECTRALFIT_H
      30             : #define COMPONENTS_SPECTRALFIT_H
      31             : 
      32             : //# Includes
      33             : #include <casacore/casa/aips.h>
      34             : #include <components/SpectralComponents/SpectralList.h>
      35             : #include <casacore/casa/Arrays/ArrayFwd.h>
      36             : 
      37             : namespace casa { //# NAMESPACE CASA - BEGIN
      38             : 
      39             : //# Forward Declarations
      40             : class SpectralElement;
      41             : 
      42             : // <summary>
      43             : // Least Squares fitting of spectral elements to spectrum
      44             : // </summary>
      45             : 
      46             : // <use visibility=export>
      47             : 
      48             : // <reviewed reviewer="" date="yyyy/mm/dd" tests="tSpectralFit" demos="">
      49             : // </reviewed>
      50             : 
      51             : // <prerequisite>
      52             : //   <li> <linkto module=Functionals>Functionals</linkto> module
      53             : //   <li> <linkto class=SpectralElement>SpectralElement</linkto> class
      54             : // </prerequisite>
      55             : //
      56             : // <etymology>
      57             : // From spectral line and fitting
      58             : // </etymology>
      59             : //
      60             : // <synopsis>
      61             : // The SpectralFit class will do a non-linear least squares solution
      62             : // for a number of simultaneous spectral components. The initial guess
      63             : // of the elements is given in a set of SpectralElements. The final solution
      64             : // is returned in the same set.
      65             : //
      66             : // </synopsis>
      67             : //
      68             : // <example>
      69             : // </example>
      70             : //
      71             : // <motivation>
      72             : // To have a contained fitting of spectral profiles to an observed spectrum
      73             : // </motivation>
      74             : //
      75             : // <todo asof="2001/02/04">
      76             : //   <li> add more profile types
      77             : // </todo>
      78             : 
      79             : class SpectralFit {
      80             :  public:
      81             : 
      82             :   //# Constructors
      83             :   // Default constructor creates a default fitter without elements
      84             :   SpectralFit();
      85             :   // Construct for the given elements
      86             :   explicit SpectralFit(const SpectralList &in);
      87             :   // Copy constructor (deep copy)
      88             :   SpectralFit(const SpectralFit &other);
      89             :   // Destructor
      90             :   ~SpectralFit();
      91             : 
      92             :   //# Operators
      93             :   // Assignment (copy semantics)
      94             :   SpectralFit &operator=(const SpectralFit &other);
      95             : 
      96             :   //# Member functions
      97             :   // Set an element to be fitted
      98             :   // <thrown>
      99             :   //   <li> casacore::AipsError if index too large
     100             :   // </thrown>
     101             :   void setFitElement(casacore::uInt index, const SpectralElement &elem);
     102             : 
     103             :   // Add elements to be fitted
     104             :   // <group>
     105             :   void addFitElement(const SpectralElement &elem);
     106             :   void addFitElement(const SpectralList &elem);
     107             :   // </group>
     108             : 
     109             :   // Clear the list to be fitted (for a re-use of the SpectralFit object)
     110             :   void clear();
     111             : 
     112             :   // Get the list being fitted
     113     1617125 :   const SpectralList &list() const { return slist_p; };
     114             : 
     115             :   // Fit the elements as given by the specified spectral elements
     116             :   // at the frequencies x with values y. Weights of all points are equal.
     117             :   // The mask (if specified) means: use point if true. Returns 
     118             :   // the convergence status.
     119             :   // <group>
     120             :   template <class MT>
     121             :     casacore::Bool fit(const casacore::Vector<MT> &y, const casacore::Vector<MT> &x) {
     122             :        return fit(y, x, static_cast<const casacore::Vector<casacore::Bool> *const>(0)); }
     123             :   template <class MT> 
     124           0 :     casacore::Bool fit(const casacore::Vector<MT> &y,
     125             :              const casacore::Vector<MT> &x, const casacore::Vector<casacore::Bool> &mask) {
     126           0 :     return fit(y, x, &mask); }
     127             :   // </group>
     128             : 
     129             :   // Fit the elements as given by the specified spectral elements
     130             :   // at the frequencies x with values y and weights sigma.
     131             :   // The mask (if specified) means: use point if true.
     132             :   // <group>
     133             :   template <class MT>
     134             :     casacore::Bool fit(const casacore::Vector<MT> &sigma,
     135             :              const casacore::Vector<MT> &y,
     136             :              const casacore::Vector<MT> &x) {
     137             :     return fit(sigma, y, x, static_cast<const casacore::Vector<casacore::Bool> *const>(0)); }
     138             :   template <class MT> 
     139      545637 :     casacore::Bool fit(const casacore::Vector<MT> &sigma,
     140             :              const casacore::Vector<MT> &y,
     141             :              const casacore::Vector<MT> &x, const casacore::Vector<casacore::Bool> &mask) {
     142      545637 :     return fit(sigma, y, x, &mask); }
     143             :   // </group>
     144             : 
     145             :   // Get the number of iterations last fit
     146       16755 :   casacore::uInt nIterations() const { return iter_p; }
     147             : 
     148             :   // Get ChiSq of the last fit
     149           0 :   casacore::Double chiSq () const { return chiSq_p; }
     150             : 
     151             :  private:
     152             :   //#Data
     153             :   // Elements to be fitted
     154             :   SpectralList slist_p;
     155             :   // Number of iterations last fit
     156             :   casacore::uInt iter_p;
     157             :   // ChiSq of last fit
     158             :   casacore::Double chiSq_p;
     159             : 
     160             :   //# Member functions
     161             :   // Real fitters
     162             :   // <group>
     163             :   template <class MT>
     164             :     casacore::Bool fit(const casacore::Vector<MT> &y,
     165             :              const casacore::Vector<MT> &x,
     166             :              const casacore::Vector<casacore::Bool> *mask);
     167             :   template <class MT>
     168             :     casacore::Bool fit(const casacore::Vector<MT> &sigma,
     169             :              const casacore::Vector<MT> &y,
     170             :              const casacore::Vector<MT> &x,
     171             :              const casacore::Vector<casacore::Bool> *mask);
     172             :   // </group>
     173             : };
     174             : 
     175             : 
     176             : } //# NAMESPACE CASA - END
     177             : 
     178             : #ifndef CASACORE_NO_AUTO_TEMPLATES
     179             : #include <components/SpectralComponents/SpectralFit2.tcc>
     180             : #endif //# CASACORE_NO_AUTO_TEMPLATES
     181             : #endif

Generated by: LCOV version 1.16