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

          Line data    Source code
       1             : //# FluxStdSrcs.cc: Implementation of FluxStdSrcs.h
       2             : //# Copyright (C) 2013
       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/FluxStdSrcs.h>
      27             : #include <casacore/casa/Arrays/Vector.h>
      28             : #include <casacore/casa/BasicSL/String.h>
      29             : #include <casacore/casa/System/Aipsrc.h>
      30             : #include <casacore/measures/Measures/MDirection.h>
      31             : #include <casacore/tables/TaQL/TableParse.h>
      32             : #include <casacore/tables/Tables/ScalarColumn.h>
      33             : #include <casatools/Config/State.h>
      34             : 
      35             : // Handy for passing anonymous arrays to functions.
      36             : #include <casacore/scimath/Mathematics/RigidVector.h>
      37             : #include <map>
      38             : 
      39             : 
      40             : using namespace casacore;
      41             : namespace casa { //# NAMESPACE CASA - BEGIN
      42             : 
      43           0 : FluxStdSrcs::FluxStdSrcs()
      44             : {
      45           0 :   names_p[FSS::THREEC286] = RVS6("3C286", "3C 286", "3C_286", "1328+307", "1331+305", "J1331+3030").vector();
      46           0 :   directions_p[FSS::THREEC286] = MDirection(MVDirection(3.539257626070549, 0.5324850225220917),
      47           0 :                                              MDirection::J2000);
      48           0 :   names_p[FSS::THREEC48]  = RVS6("3C48", "3C 48", "3C_48", "0134+329",
      49             :                                   "0137+331",              // Together these match 33d09m35s
      50           0 :                                   "J0137+3309").vector();  // for dd.d or ddmm with a margin.
      51           0 :   directions_p[FSS::THREEC48] = MDirection(MVDirection(0.4262457643630985, 0.5787463318245085),
      52           0 :                                             MDirection::J2000);
      53           0 :   names_p[FSS::THREEC147] = RVS6("3C147", "3C 147", "3C_147", "0538+498", "0542+498", 
      54           0 :                                   "J0542+4951").vector();          // Jhhmm+ddmm, CAS-2020
      55           0 :   directions_p[FSS::THREEC147] = MDirection(MVDirection(1.4948817765383597, 0.8700805690768509),
      56           0 :                                              MDirection::J2000);
      57           0 :   names_p[FSS::THREEC138] = RVS6("3C138", "3C 138", "3C_138", "0518+165", "0521+166",
      58           0 :                                   "J0521+1638").vector();          // Jhhmm+ddmm, CAS-2020
      59           0 :   directions_p[FSS::THREEC138] = MDirection(MVDirection(1.401346673041897, 0.2904130912582342),
      60           0 :                                              MDirection::J2000);
      61           0 :   names_p[FSS::NINETEEN34M638] = RigidVector<String, 2>("1934-638","J1939-6342").vector();
      62           0 :   directions_p[FSS::NINETEEN34M638] = MDirection(MVDirection(5.146176021557448, -1.1119977478136984),
      63           0 :                                                   MDirection::J2000);
      64           0 :   names_p[FSS::THREEC295] = RVS6("3C295", "3C 295", "3C_295", "1409+524", "1411+522",
      65           0 :                                   "J1411+5212").vector();          // Jhhmm+ddmm, CAS-2020
      66           0 :   directions_p[FSS::THREEC295] = MDirection(MVDirection(3.7146787856873478, 0.9111103509091509),
      67           0 :                                              MDirection::J2000);
      68           0 :   names_p[FSS::THREEC196] = RVS6("3C196", "3C 196", "3C_196", "0809+483", "0813+482",
      69           0 :                                   "J0813+4813").vector();          // Jhhmm+ddmm, CAS-2020
      70           0 :   directions_p[FSS::THREEC196] = MDirection(MVDirection(2.1537362969610023, 0.8415541320803659),
      71           0 :                                              MDirection::J2000);
      72             :   // added for Perley-Butler 2013 4h 37m 4.375301s 29d 40' 13.819008" CAS-4489 (other alias:B0433+2934)
      73           0 :   names_p[FSS::THREEC123] = RVS6("3C123", "3C 123", "3C_123", "0433+295", "0437+296",
      74           0 :                                   "J0437+2940").vector();
      75           0 :   directions_p[FSS::THREEC123] = MDirection(MVDirection(1.2089586878736391, 0.51784800786636209),
      76           0 :                                              MDirection::J2000);
      77           0 :   names_p[FSS::THREEC380] = RVS6("3C380", "3C 380", "3C_380", "1828+487", "1829+487",
      78           0 :                                   "J1829+4845").vector();          // Jhhmm+ddm, CAS-2020
      79           0 :   directions_p[FSS::THREEC380] = MDirection(MVDirection(4.84123669, 0.85078092),
      80           0 :                                              MDirection::J2000);
      81             :   // added for Perley-Butler 2017
      82             :   // use C++11 vector initialization
      83             :   // Note: source name match (srcNameToEnum)is case-insensitve (e.g. "ForA" and "FORA" is allowed)
      84           0 :   std::vector<String> templist;
      85           0 :   templist = {"J0133-3629"};
      86           0 :   names_p[FSS::J0133] = Vector<String> (templist);  
      87           0 :   directions_p[FSS::J0133] = MDirection(MVDirection(0.40998511349868466,-0.636928821694464), 
      88           0 :                                              MDirection::J2000);
      89           0 :   templist = {"FORNAX_A", "FORNAX A", "FOR-A", "FOR A", "ForA", "J0322-3712"};
      90           0 :   names_p[FSS::FORNAXA] = Vector<String> (templist);
      91           0 :   directions_p[FSS::FORNAXA] = MDirection(MVDirection(0.8844302540951193,-0.649405598740554), 
      92           0 :                                              MDirection::J2000);
      93           0 :   templist = {"J0444-2809"};
      94           0 :   names_p[FSS::J0444] = Vector<String> (templist);
      95           0 :   directions_p[FSS::J0444] = MDirection(MVDirection(1.2419253902826484,-0.49157683196101404), 
      96           0 :                                              MDirection::J2000);
      97           0 :   templist = {"PICTOR_A","PICTOR A", "PIC-A", "PIC A", "PicA", "J0519-4546"};  
      98           0 :   names_p[FSS::PICTORA] = Vector<String> (templist);
      99           0 :   directions_p[FSS::PICTORA] = MDirection(MVDirection(1.3955160370653494,-0.7989916117952379), 
     100           0 :                                              MDirection::J2000);
     101           0 :   templist= {"TAURUS_A", "TAURUS A", "TAU-A", "TAU A", "TauA", "J0534+2200", "3C144", "3C 144", "3C_144", "CRAB"};
     102           0 :   names_p[FSS::TAURUSA] = Vector<String> (templist); 
     103           0 :   directions_p[FSS::TAURUSA] = MDirection(MVDirection(1.4596748494230258,0.3842250233666105), 
     104           0 :                                              MDirection::J2000);
     105           0 :   templist = {"HYDRA_A", "HYDRA A", "HYA-A", "HYA A", "HyaA", "J0918-1205", "3C218", "3C 218", "3C_218"};
     106           0 :   names_p[FSS::HYDRAA] = Vector<String> (templist);
     107           0 :   directions_p[FSS::HYDRAA] = MDirection(MVDirection(2.4351465533014114,-0.21110704143990625), 
     108           0 :                                              MDirection::J2000);
     109           0 :   templist = {"VIRGO_A", "VIRGO A", "VIR-A", "VIR A", "VirA", "J1230+1223", "3C274", "3C 274", "3C_274", "M87"};
     110           0 :   names_p[FSS::VIRGOA] = Vector<String> (templist);
     111           0 :   directions_p[FSS::VIRGOA] = MDirection(MVDirection(-3.0070987886171765,0.2162659001873615), 
     112           0 :                                              MDirection::J2000);
     113           0 :   templist = {"HERCULES_A", "HERCULES A", "HER-A", "HER A", "HerA", "J1651+0459", "3C348", "3C 348", "3C_348"};
     114           0 :   names_p[FSS::HERCULESA] = Vector<String> (templist); 
     115           0 :   directions_p[FSS::HERCULESA] = MDirection(MVDirection(-1.871273156204919,0.08713711430959646), 
     116           0 :                                              MDirection::J2000);
     117           0 :   templist = {"3C353", "3C 353", "3C_353", "J1720-0059"};
     118           0 :   names_p[FSS::THREEC353] = Vector<String> (templist);
     119           0 :   directions_p[FSS::THREEC353] = MDirection(MVDirection(-1.7432823443920011,-0.017099960309150668), 
     120           0 :                                              MDirection::J2000);
     121           0 :   templist = {"CYGNUS_A", "CYGNUS A", "CYG-A", "CYG A", "CygA", "J1959+4044", "3C405", "3C 405", "3C_405"};
     122           0 :   names_p[FSS::CYGNUSA] =  Vector<String> (templist);
     123           0 :   directions_p[FSS::CYGNUSA] = MDirection(MVDirection(-1.0494987241821205,0.7109409485219165), 
     124           0 :                                              MDirection::J2000);
     125           0 :   templist = {"3C444", "3C 444", "3C_444", "J2214-1701"};
     126           0 :   names_p[FSS::THREEC444] = Vector<String> (templist);
     127           0 :   directions_p[FSS::THREEC444] = MDirection(MVDirection(-0.46063951349110815,-0.2971727999325764), 
     128           0 :                                               MDirection::J2000);
     129           0 :   templist = {"CASSIOPEIA_A", "CASSIOPEIA A", "CAS-A", "CAS A", "CasA", "J2323+5848", "3C461", "3C 461", "3C_461"};
     130           0 :   names_p[FSS::CASSIOPEIAA] = Vector<String> (templist);
     131           0 :   directions_p[FSS::CASSIOPEIAA] = MDirection(MVDirection(-0.15969762655748126,1.0265153995604648), 
     132           0 :                                             MDirection::J2000);
     133             :    
     134           0 :   directions_p[FSS::UNKNOWN_SOURCE] = MDirection();     // Default.
     135           0 : }
     136             : 
     137           0 : FluxStdSrcs::~FluxStdSrcs(){ }
     138             : 
     139           0 : FluxStdSrcs::Source FluxStdSrcs::srcNameToEnum(const String& srcName, const MDirection& dir) const
     140             : {
     141           0 :   FSS::Source srcEnum = FSS::UNKNOWN_SOURCE;  
     142           0 :   String tmpSrcName(srcName);
     143           0 :   tmpSrcName.upcase();
     144           0 :   for(std::map<FSS::Source, Vector<String> >::const_iterator it = names_p.begin();
     145           0 :       it != names_p.end(); ++it){
     146           0 :     for(Int i = it->second.nelements(); i--;){
     147           0 :       if(tmpSrcName.contains(it->second[i])){
     148           0 :         srcEnum = it->first;
     149           0 :         break;
     150             :       }
     151             :     }
     152           0 :     if(srcEnum != FSS::UNKNOWN_SOURCE)
     153           0 :       break;
     154             :   }
     155             :   // now try cone search usng the flux calibrator table
     156           0 :   if(srcEnum == FSS::UNKNOWN_SOURCE) {
     157           0 :       LogIO os(LogOrigin("FluxStdSrcs", "srcNameToEnum"));
     158           0 :       String fcaldatapath;
     159           0 :       String tabName("fluxcalibrator.data");
     160           0 :       String resolvepath = casatools::get_state( ).resolve("nrao/VLA/standards/"+tabName);
     161           0 :       if (resolvepath != "nrao/VLA/standards/"+tabName) {
     162           0 :           fcaldatapath = resolvepath;
     163           0 :       } else if(!Aipsrc::findDir(fcaldatapath,"./"+tabName)) {
     164           0 :           if(!Aipsrc::findDir(fcaldatapath, Aipsrc::aipsRoot()+"/data/nrao/VLA/standards/"+tabName)) {
     165             :               //LogIO os(LogOrigin("FluxStdSrcs", "srcNameToEnum", WHERE));
     166             :                os << LogIO::NORMAL
     167             :                   << "No flux calibrator table: " <<  tabName
     168             :                   << " ./ or in ~/data/nrao/VLA/standards/. Skip a cone search "
     169           0 :                   << LogIO::POST;
     170           0 :                return srcEnum;
     171             :           }
     172             :       }
     173             :       // input source coordinates (input dir must be in J2000)
     174           0 :       Quantum<Vector<Double> > radec = dir.getAngle();
     175           0 :       String srcRA = String::toString(radec.getValue("rad")[0])+"rad";
     176           0 :       String srcDec = String::toString(radec.getValue("rad")[1])+"rad";
     177             :       //String radius("0.0001454441rad"); //search radius is set to 30arcsec
     178           0 :       String radius("4.8481367e-06rad"); //search radius is set to 1arcsec
     179           0 :       String taql="select Name, RA_J2000, Dec_J2000 from "+fcaldatapath+
     180           0 :                  " where anycone([RA_J2000,Dec_J2000]"+",["+srcRA+","+srcDec+"],"+radius+")";
     181             :       //cerr<<"taql command="<<taql<<endl;
     182             :       os << LogIO::NORMAL
     183             :          << "Trying to determine source match by position..."
     184           0 :          << LogIO::POST;
     185           0 :       Table tmpsubtab = tableCommand(taql).table();
     186           0 :       if(tmpsubtab.nrow()) {
     187           0 :           ScalarColumn<String> srcNameCol(tmpsubtab,"Name");
     188           0 :           String srcNameInTable = srcNameCol.getColumnCells(RefRows(0,0))[0];
     189             :           //cerr<<"srcNameInTable="<<srcNameInTable<<endl;
     190           0 :           for (std::map<FSS::Source, Vector<String> >::const_iterator it2 = names_p.begin(); 
     191           0 :                it2 != names_p.end(); ++it2) {
     192           0 :               if (srcNameInTable.contains(it2->second[0])) {
     193           0 :                   srcEnum = it2->first;
     194             :                   os << LogIO::NORMAL
     195             :                      << "Found "<<srcNameInTable
     196             :                      <<" as a match for the input field, "
     197             :                      <<srcName<<" in the cone search within radius of "<<radius
     198           0 :                      << LogIO::POST;
     199           0 :                   break;
     200             :               }
     201             :           }
     202             :      }
     203             :      else {
     204             :      os << LogIO::NORMAL
     205             :         << " no match was found"
     206           0 :         << LogIO::POST;
     207             :      }
     208             :   }
     209           0 :   return srcEnum;
     210             : }
     211             : 
     212           0 : String FluxStdSrcs::EnumToSrcName(const FSS::Source srcEnum) const
     213             : {
     214           0 :    return names_p.find(srcEnum)->second[0];
     215             : }
     216             : 
     217           0 : MDirection FluxStdSrcs::getDirection(const FSS::Source srcEnum) const
     218             : {
     219           0 :   return directions_p.find(srcEnum)->second;
     220             : }
     221             : 
     222             : } //# NAMESPACE CASA - END

Generated by: LCOV version 1.16