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

          Line data    Source code
       1             : //# FluxCalcLogFreqPolynomial.cc: Implementation of FluxCalcLogFreqPolynomial.h
       2             : //# Copyright (C) 2010
       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             : #include <components/ComponentModels/FluxCalcLogFreqPolynomial.h>
      27             : #include <casacore/casa/BasicSL/String.h>
      28             : #include <casacore/measures/Measures/MFrequency.h>
      29             : 
      30             : // Handy for passing anonymous arrays to functions.
      31             : #include <casacore/scimath/Mathematics/RigidVector.h>
      32             : 
      33             : #include <map>
      34             : 
      35             : #include <casacore/casa/Logging/LogIO.h>
      36             : 
      37             : using namespace casacore;
      38             : namespace casa { //# NAMESPACE CASA - BEGIN
      39             : 
      40           0 : Bool FluxCalcLogFreqPolynomial::operator()(Flux<Double>& value,
      41             :                                            Flux<Double>& error,
      42             :                                            const MFrequency& mfreq,
      43             :                                            const Bool updatecoeffs)
      44             : {
      45           0 :   LogIO os(LogOrigin("FluxCalcLogFreqPolynomial", "()", WHERE));
      46           0 :   Double dt = log10(mfreq.get(freqUnit_p).getValue());
      47           0 :   if (updatecoeffs || coeffs_p(0).nelements()==0) {
      48           0 :     coeffs_p(0).resize();
      49           0 :     coeffs_p(1).resize();
      50           0 :     coeffs_p=getCurrentCoeffs();
      51             :   }
      52             :   {
      53           0 :      validfrange_p=getValidFreqRange();
      54           0 :      Double ghzinfreq = mfreq.get("GHz").getValue();
      55           0 :      Double minfreq = validfrange_p(0).get("GHz").getValue();
      56           0 :      Double maxfreq = validfrange_p(1).get("GHz").getValue();
      57           0 :      if (!(minfreq==0.0 && maxfreq ==0.0)) {
      58             :        //cerr<<" range:"<<minfreq<<","<<maxfreq<<"  infreq="<<ghzinfreq<<endl;
      59           0 :         if (minfreq > ghzinfreq || maxfreq < ghzinfreq) {
      60             :           //cerr<<"Input "<<String::toString(mfreq)<<" is out of the valid frequency range of the flux model: "<<String::toString(validfrange_p)<<endl;
      61           0 :           os<<LogIO::WARN<<"Input "<<String::toString(mfreq) 
      62             :                          <<" (Hz) is out of the valid frequency range of the flux model: "
      63           0 :                          <<String::toString(validfrange_p)<<" (Hz)"<<LogIO::POST;
      64             :         }
      65             :     }
      66             :   }
      67           0 :   Double fluxCoeff = coeffs_p(0)[coeffs_p(0).nelements() - 1];
      68           0 :   for(Int order = coeffs_p(0).nelements() - 2; order >= 0; --order)
      69           0 :     fluxCoeff = fluxCoeff * dt + coeffs_p(0)[order];
      70             :   
      71           0 :   Double coeffErr = 0.0;
      72           0 :   Double dtpow = 1.0;
      73           0 :   for(uInt order = 0; order < coeffs_p(1).nelements(); ++order){
      74           0 :     coeffErr += square(coeffs_p(1)[order] * dtpow);
      75           0 :     dtpow *= dt;
      76             :   }
      77             : 
      78           0 :   Double fluxDensity = pow(10.0, fluxCoeff);
      79           0 :   Double fluxError = coeffErr > 0.0 ? C::ln10 * fluxDensity * sqrt(coeffErr) : 0.0;
      80             : 
      81             :   //cerr<<"FluxDensity=="<<fluxDensity<<endl;
      82           0 :   value.setValue(fluxDensity);
      83           0 :   error.setValue(fluxError);
      84             : 
      85             :   // In this case the hard part of matching the std and src has already been done.
      86           0 :   return true;
      87             : }
      88             : 
      89           0 : Bool FluxCalcLogFreqPolynomial::setSource(const String& sourceName, const MDirection& sourceDir)
      90             : {
      91           0 :   Bool success = FluxCalcVQS::setSource(sourceName, sourceDir);
      92             : 
      93           0 :   if(success)
      94           0 :     success = setSourceCoeffs();
      95           0 :   return success;
      96             : }
      97             : 
      98           0 : void FluxCalcLogFreqPolynomial::setFreqUnit(const String& freqUnit)
      99             : {
     100           0 :   freqUnit_p = freqUnit;
     101           0 : }
     102             : 
     103           0 : void FluxCalcLogFreqPolynomial::fill_coeffs(const Vector<Float>& lfv)
     104             : {
     105           0 :   coeffs_p(0).resize();
     106           0 :   coeffs_p(1).resize();
     107           0 :   coeffs_p(0) = lfv;
     108           0 : }
     109             : 
     110             : 
     111           0 : FluxCalcLogFreqBrokenPolynomial::FluxCalcLogFreqBrokenPolynomial() :
     112             :   FluxCalcLogFreqPolynomial::FluxCalcLogFreqPolynomial(),
     113           0 :   break_freq_p(Quantity(0.0, "Hz"))
     114             : {
     115           0 : }
     116             : 
     117           0 : Bool FluxCalcLogFreqBrokenPolynomial::operator()(Flux<Double>& value,
     118             :                                                  Flux<Double>& error,
     119             :                                                  const MFrequency& mfreq,
     120             :                                                  const Bool updatecoeffs)
     121             : {
     122             :   if (updatecoeffs) {
     123             :     //do nothing for now
     124             :     ;
     125             :   }
     126           0 :   Double break_freq_in_Hz = break_freq_p.get("Hz").getValue();
     127             :   
     128           0 :   if(break_freq_in_Hz > 0.0){
     129           0 :     if(mfreq.get("Hz").getValue() > break_freq_in_Hz){
     130           0 :       if(in_low_state_p)
     131           0 :         fill_coeffs(high_coeffs_p);
     132             :     }
     133           0 :     else if(!in_low_state_p)
     134           0 :       fill_coeffs(low_coeffs_p);
     135             :   }
     136             : 
     137             :   // Proceed...
     138           0 :   return FluxCalcLogFreqPolynomial::operator()(value, error, mfreq);
     139             : }
     140             : 
     141           0 : Bool FluxCalcLogFreqPolynomialSH :: operator()( Flux<Double>& value,
     142             :                                                 Flux<Double>& error,
     143             :                                                 const MFrequency& mfreq,
     144             :                                                 const Bool /* updatecoeffs */)
     145             : {
     146           0 :   Double S = 0.;
     147           0 :   Double dS2 = 0.;
     148           0 :   coeffs_p(0).resize();
     149           0 :   coeffs_p(1).resize();
     150           0 :   coeffs_p=getCurrentCoeffs();
     151           0 :   if ( coeffs_p( 0 ).nelements() > 0 ) {
     152           0 :     Double logF = log10( mfreq.get( freqUnit_p ).getValue() / 0.150 );
     153           0 :     Double logS = 0.;
     154           0 :     for ( uInt order = coeffs_p( 0 ).nelements() - 1; order >= 1; --order)
     155           0 :       logS = ( logS + coeffs_p( 0 )[ order ] ) * logF;
     156           0 :     S = coeffs_p( 0 )[ 0 ] * pow( 10.0, logS );
     157           0 :     if ( coeffs_p( 1 ).nelements() > 0 ) {
     158           0 :       for ( uInt order = coeffs_p( 1 ).nelements() - 1; order >= 1; --order)
     159           0 :         dS2 = ( dS2 + square( coeffs_p( 1 )[ order ] ) ) * square( logF );
     160           0 :       dS2 = square( S * coeffs_p( 1 )[ 0 ] / coeffs_p( 0 )[ 0 ] ) +
     161           0 :             square( C::ln10 * S ) * dS2;
     162             :     }
     163             :   }
     164             : 
     165           0 :   Double dS = ( dS2 > 0.0 ) ? sqrt( dS2 ) : 0.0;
     166           0 :   value.setValue( S );
     167           0 :   error.setValue( dS );
     168             : 
     169           0 :   return true;
     170             : }
     171           0 : Bool FluxCalcLogFreqPolynomialSH::setSource(const String& sourceName, const MDirection& sourceDir)
     172             : {
     173           0 :   Bool success = FluxCalcVQS::setSource(sourceName, sourceDir);
     174             : 
     175           0 :   if(success)
     176           0 :     success = setSourceCoeffs();
     177           0 :   return success;
     178             : }
     179             : 
     180           0 : void FluxCalcLogFreqPolynomialSH::setFreqUnit(const String& freqUnit)
     181             : {
     182           0 :   freqUnit_p = freqUnit;
     183           0 : }
     184             : } //# NAMESPACE CASA - END

Generated by: LCOV version 1.16