LCOV - code coverage report
Current view: top level - imageanalysis/ImageAnalysis - SpectralFitter.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 1 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 1 0.0 %

          Line data    Source code
       1             : //# SpectralCollapser.h: Header file for class SpectralCollapser
       2             : //# Copyright (C) 1998,1999,2000,2001,2003
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This program is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU General Public License as published by the Free
       7             : //# Software Foundation; either version 2 of the License, or (at your option)
       8             : //# any later version.
       9             : //#
      10             : //# This program 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 General Public License for
      13             : //# more details.
      14             : //#
      15             : //# You should have received a copy of the GNU General Public License along
      16             : //# with this program; if not, write to the Free Software Foundation, Inc.,
      17             : //# 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             : //# $Id: $
      27             : 
      28             : #ifndef IMAGEANALYSIS_SPECTRALFITTER_H
      29             : #define IMAGEANALYSIS_SPECTRALFITTER_H
      30             : 
      31             : #include <components/SpectralComponents/SpectralList.h>
      32             : #include <components/SpectralComponents/ProfileFit1D.h>
      33             : 
      34             : #include <casacore/casa/namespace.h>
      35             : 
      36             : namespace casacore{
      37             : 
      38             : //class SpectralCoordinate;
      39             : class LogIO;
      40             : }
      41             : 
      42             : namespace casa {
      43             : 
      44             : template <class T> class ProfileFit1D;
      45             : 
      46             : class SpectralList;
      47             : 
      48             : class SpectralFitter {
      49             :         // <summary>
      50             :         // Does a simple fit to data in vectors. It is possible to specify weights (or errors)
      51             :         // for each element. A single Gaussian and a polynimial of order N are the only
      52             :         // component that can be fitted.
      53             :         // </summary>
      54             : 
      55             :         // <reviewed reviewer="" date="" tests="" demos="">
      56             :         // </reviewed>
      57             : 
      58             :         // <prerequisite>
      59             :         //   <li> ProfileFit1D
      60             :         // </prerequisite>
      61             : 
      62             :         // <etymology>
      63             :         // Created to fit components to spectra from the spectral profiler, hence
      64             :         // SpectralFitter.
      65             :         // </etymology>
      66             : 
      67             :         // <synopsis>
      68             :         // </synopsis>
      69             : 
      70             : public:
      71             :         enum FitStatus {// report the status of the last fit
      72             :                 UNKNOWN,     // mostly means not fit has yet been executed
      73             :                 FAILED,
      74             :                 SUCCESS,
      75             :         };
      76             : 
      77             :         // default constructor
      78             :         SpectralFitter();
      79             : 
      80             :         // destructor
      81             :         virtual ~SpectralFitter();
      82             : 
      83             :         // Parameters:
      84             :         // <src>spcVals</src>  - independent values
      85             :         // <src>yVals</src>    - dependent values
      86             :         // <src>eVals</src>    - error values
      87             :         // <src>startVal</src> - lower boundary for independent values to be included in the fit
      88             :         // <src>endVal</src>   - upper boundary for independent values to be included in the fit
      89             :         // <src>fitGauss</src> - fit Gaussian component
      90             :         // <src>fitPoly</src>  - fit polynomial
      91             :         // <src>nPoly</src>    - order of polynomial to be fitted
      92             :         // <src>msg</src>      - message back to the calling routine
      93             :         virtual casacore::Bool fit(const casacore::Vector<casacore::Float> &spcVals, const casacore::Vector<casacore::Float> &yVals, const casacore::Vector<casacore::Float> &eVals,
      94             :                         const casacore::Float startVal, const casacore::Float endVal, const casacore::Bool fitGauss, const casacore::Bool fitPoly, const casacore::uInt nPoly, casacore::String &msg);
      95             : 
      96             :         // get the status of the last fit
      97             :         const SpectralFitter::FitStatus &getStatus(){return _fitStatus;};
      98             : 
      99             :         // get Chi Squared of the last fit
     100             :         casacore::Double getChiSquared () const {return _fit.getChiSquared();}
     101             : 
     102             :         // get number of iterations for the last fit
     103             :         casacore::Double getNumberIterations() const {return _fit.getNumberIterations();}
     104             : 
     105             :         const SpectralList &getList() const {return _fit.getList();};
     106             : 
     107             :         // get all values for the last fit
     108           0 :         casacore::Vector<casacore::Double> getFit() const {return _fit.getFit();};
     109             : 
     110             :         // get the values in the specified data range for the last fit
     111             :         void getFit(const casacore::Vector<casacore::Float> &spcVals, casacore::Vector<casacore::Float> &spcFit, casacore::Vector<casacore::Float> &yFit) const;
     112             : 
     113             :         // get all residuals for the last fit
     114             :         casacore::Vector<casacore::Double> getResidual() const {return _fit.getResidual();};
     115             : 
     116             :         // report on the last fit to a stream
     117             :         casacore::String report(casacore::LogIO &os, const casacore::String &xUnit="", const casacore::String &yUnit="", const casacore::String &yPrefixUnit="") const;
     118             : 
     119             : private:
     120             :    casacore::LogIO *_log;
     121             : 
     122             :    ProfileFit1D<casacore::Double> _fit;
     123             : 
     124             :         SpectralFitter::FitStatus _fitStatus;
     125             : 
     126             :         casacore::Double _startVal;
     127             :         casacore::Double _endVal;
     128             :         casacore::uInt   _startIndex;
     129             :         casacore::uInt   _endIndex;
     130             : 
     131             :         casacore::String _resultMsg;
     132             : 
     133             :         // do all necessary setup
     134             :    void _setUp();
     135             : 
     136             :    // prepare the data which means give all data (independent, dependent, weights)
     137             :    // to the fitting class
     138             :    casacore::Bool _prepareData(const casacore::Vector<casacore::Float> &xVals, const casacore::Vector<casacore::Float> &eVals,
     139             :                 const casacore::Int &startIndex, const casacore::Int &endIndex, casacore::Vector<casacore::Bool> &maskVals, casacore::Vector<casacore::Double> &weightVals) const;
     140             : 
     141             :    // prepare the components that shall be fitted; this includes the setting
     142             :    // of reasonable initial parameters
     143             :    casacore::Bool _prepareElems(const casacore::Bool fitGauss, const casacore::Bool fitPoly, const casacore::uInt nPoly, casacore::Vector<casacore::Double> &xVals,
     144             :                 casacore::Vector<casacore::Double> &yVals, SpectralList& list);
     145             : 
     146             :    // report on a list of spectral elements to a stream
     147             :    casacore::String _report(casacore::LogIO &os, const SpectralList &list, const casacore::String &xUnit="", const casacore::String &yUnit="", const casacore::String &yPrefixUnit="") const;
     148             : };
     149             : }
     150             : 
     151             : #endif

Generated by: LCOV version 1.16