LCOV - code coverage report
Current view: top level - components/SpectralComponents - GaussianSpectralElement.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 0 84 0.0 %
Date: 2023-11-02 14:27:30 Functions: 0 22 0.0 %

          Line data    Source code
       1             : //# SpectralElement.cc: Describes (a set of related) spectral lines
       2             : //# Copyright (C) 2001,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: 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             : //# $Id: SpectralElement.cc 21024 2011-03-01 11:46:18Z gervandiepen $
      27             : 
      28             : //# Includes
      29             : #include <components/SpectralComponents/GaussianSpectralElement.h>
      30             : 
      31             : #include <casacore/casa/BasicSL/Constants.h>
      32             : 
      33             : #include <casacore/scimath/Functionals/Gaussian1D.h>
      34             : 
      35             : #include <iostream>
      36             : 
      37             : using namespace casacore;
      38             : namespace casa { //# NAMESPACE CASA - BEGIN
      39             : 
      40             : //# Constants
      41             : const Double GaussianSpectralElement::SigmaToFWHM = sqrt(8.0*C::ln2);
      42             : 
      43           0 : GaussianSpectralElement::GaussianSpectralElement()
      44           0 : : PCFSpectralElement(SpectralElement::GAUSSIAN, 1, 0, 2*sqrt(C::ln2)/C::pi) {
      45           0 :         _setFunction(
      46           0 :                 std::shared_ptr<Gaussian1D<Double> >(
      47           0 :                         new Gaussian1D<Double>(1, 0, 1)
      48             :                 )
      49             :         );
      50           0 : }
      51             : 
      52             : 
      53           0 : GaussianSpectralElement::GaussianSpectralElement(
      54             :         const Double ampl, const Double center, const Double sigma
      55           0 : ) : PCFSpectralElement(SpectralElement::GAUSSIAN, ampl, center, sigma) {
      56           0 :         _setFunction(
      57           0 :                 std::shared_ptr<Gaussian1D<Double> >(
      58           0 :                         new Gaussian1D<Double>(ampl, center, sigma*SigmaToFWHM)
      59             :                 )
      60             :         );
      61           0 : }
      62             : 
      63           0 : GaussianSpectralElement::GaussianSpectralElement(
      64             :         const Vector<Double> &param
      65           0 : ) : PCFSpectralElement(SpectralElement::GAUSSIAN, param) {
      66           0 :         std::shared_ptr<Gaussian1D<Double> >(
      67           0 :                 new Gaussian1D<Double>(param[AMP], param[CENTER], param[WIDTH]*SigmaToFWHM)
      68             :         );
      69           0 : }
      70             : 
      71           0 : GaussianSpectralElement::GaussianSpectralElement(
      72             :         const GaussianSpectralElement &other
      73           0 : ) : PCFSpectralElement(other) {}
      74             : 
      75           0 : GaussianSpectralElement::~GaussianSpectralElement() {}
      76             : 
      77             : 
      78           0 : SpectralElement* GaussianSpectralElement::clone() const {
      79           0 :         return new GaussianSpectralElement(*this);
      80             : }
      81             : 
      82           0 : Double GaussianSpectralElement::getSigma() const {
      83           0 :         return get()[2];
      84             : }
      85             : 
      86           0 : Double GaussianSpectralElement::getFWHM() const {
      87           0 :         return sigmaToFWHM(get()[WIDTH]);
      88             : }
      89             : 
      90           0 : Double GaussianSpectralElement::getSigmaErr() const {
      91           0 :         return getError()[WIDTH];
      92             : }
      93             : 
      94           0 : Double GaussianSpectralElement::getFWHMErr() const {
      95           0 :         return sigmaToFWHM(getError()[WIDTH]);
      96             : }
      97             : 
      98           0 : void GaussianSpectralElement::setSigma(Double sigma) {
      99           0 :         if (sigma < 0) {
     100           0 :                 sigma *= -1;
     101             :         }
     102           0 :         Vector<Double> p = get();
     103           0 :         p[WIDTH] = sigma;
     104           0 :         _set(p);
     105           0 :         Vector<Double> err = getError();
     106           0 :         err[WIDTH] = 0;
     107           0 :         setError(err);
     108           0 : }
     109             : 
     110           0 : void GaussianSpectralElement::set(const Vector<Double>& v) {
     111           0 :         PCFSpectralElement::set(v);
     112           0 :         (*_getFunction())[WIDTH] = sigmaToFWHM(v[WIDTH]);
     113           0 : }
     114             : 
     115           0 : void GaussianSpectralElement::_set(const Vector<Double>& v) {
     116           0 :         PCFSpectralElement::_set(v);
     117           0 :         (*_getFunction())[WIDTH] = sigmaToFWHM(v[WIDTH]);
     118           0 : }
     119             : 
     120           0 : void GaussianSpectralElement::setFWHM(Double fwhm) {
     121           0 :         setSigma(sigmaFromFWHM(fwhm));
     122           0 : }
     123             : 
     124           0 : void GaussianSpectralElement::fixSigma(const Bool isFixed) {
     125           0 :         Vector<Bool> myFixed = fixed();
     126           0 :         myFixed[WIDTH] = isFixed;
     127           0 :         fix(myFixed);
     128           0 : }
     129             : 
     130           0 : Bool GaussianSpectralElement::fixedSigma() const {
     131           0 :         return fixed()[WIDTH];
     132             : }
     133             : 
     134           0 : Double GaussianSpectralElement::getIntegral() const {
     135           0 :         static const Double c = sqrt(C::pi_4/C::ln2);
     136           0 :         return c * getAmpl() * getFWHM();
     137             : }
     138             : 
     139           0 : Bool GaussianSpectralElement::toRecord(
     140             :         RecordInterface& out
     141             : ) const {
     142           0 :         PCFSpectralElement::toRecord(out);
     143           0 :         Vector<Double> p = out.asArrayDouble("parameters");
     144           0 :         Vector<Double> e = out.asArrayDouble("errors");
     145           0 :         p[2] = getFWHM();
     146           0 :         out.define("parameters", p);
     147           0 :         e[2] = getFWHMErr();
     148           0 :         out.define("errors", e);
     149           0 :         return true;
     150             : }
     151             : 
     152           0 : ostream &operator<<(ostream &os, const GaussianSpectralElement &elem) {
     153           0 :         os << SpectralElement::fromType((elem.getType())) << " element: " << endl;
     154           0 :     os << "  Amplitude: " << elem.getAmpl() << ", " << elem.getAmplErr();
     155           0 :     if (elem.fixedAmpl()) os << " (fixed)";
     156           0 :     os << endl << "  Center:    " << elem.getCenter() << ", " << elem.getCenterErr();
     157           0 :     if (elem.fixedCenter()) os << " (fixed)";
     158           0 :     os << endl << "  Sigma:     " << elem.getSigma() << ", " << elem.getSigmaErr();
     159           0 :     if (elem.fixedSigma()) os << " (fixed)";
     160           0 :     os << endl;
     161           0 :     return os;
     162             : }
     163             : 
     164           0 : Double GaussianSpectralElement::sigmaToFWHM (const Double sigma) {
     165           0 :    return SigmaToFWHM * sigma;
     166             : }
     167             : 
     168           0 : Double GaussianSpectralElement::sigmaFromFWHM(const Double fwhm) {
     169           0 :   return fwhm / SigmaToFWHM;
     170             : }
     171             : 
     172             : } //# NAMESPACE CASA - END
     173             : 

Generated by: LCOV version 1.16