LCOV - code coverage report
Current view: top level - components/ComponentModels - FluxStdSrcs.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 136 0.0 %
Date: 2024-10-29 13:38:20 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: 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             : #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             :       }
     164             :       else {
     165           0 :           fcaldatapath = "./"+tabName;
     166             :       }
     167           0 :       if (!Table::isReadable(fcaldatapath)) {
     168             :           os << LogIO::NORMAL
     169             :              << "No flux calibrator table: " <<  tabName
     170             :              << " in the current directory or in datapath/measurespath. Skip a cone search "
     171           0 :              << LogIO::POST;
     172           0 :           return srcEnum;
     173             :       }
     174             :       // input source coordinates (input dir must be in J2000)
     175           0 :       Quantum<Vector<Double> > radec = dir.getAngle();
     176           0 :       String srcRA = String::toString(radec.getValue("rad")[0])+"rad";
     177           0 :       String srcDec = String::toString(radec.getValue("rad")[1])+"rad";
     178             :       //String radius("0.0001454441rad"); //search radius is set to 30arcsec
     179           0 :       String radius("4.8481367e-06rad"); //search radius is set to 1arcsec
     180           0 :       String taql="select Name, RA_J2000, Dec_J2000 from "+fcaldatapath+
     181           0 :                  " where anycone([RA_J2000,Dec_J2000]"+",["+srcRA+","+srcDec+"],"+radius+")";
     182             :       //cerr<<"taql command="<<taql<<endl;
     183             :       os << LogIO::NORMAL
     184             :          << "Trying to determine source match by position..."
     185           0 :          << LogIO::POST;
     186           0 :       Table tmpsubtab = tableCommand(taql).table();
     187           0 :       if(tmpsubtab.nrow()) {
     188           0 :           ScalarColumn<String> srcNameCol(tmpsubtab,"Name");
     189           0 :           String srcNameInTable = srcNameCol.getColumnCells(RefRows(0,0))[0];
     190             :           //cerr<<"srcNameInTable="<<srcNameInTable<<endl;
     191           0 :           for (std::map<FSS::Source, Vector<String> >::const_iterator it2 = names_p.begin(); 
     192           0 :                it2 != names_p.end(); ++it2) {
     193           0 :               if (srcNameInTable.contains(it2->second[0])) {
     194           0 :                   srcEnum = it2->first;
     195             :                   os << LogIO::NORMAL
     196             :                      << "Found "<<srcNameInTable
     197             :                      <<" as a match for the input field, "
     198             :                      <<srcName<<" in the cone search within radius of "<<radius
     199           0 :                      << LogIO::POST;
     200           0 :                   break;
     201             :               }
     202             :           }
     203           0 :      }
     204             :      else {
     205             :      os << LogIO::NORMAL
     206             :         << " no match was found"
     207           0 :         << LogIO::POST;
     208             :      }
     209           0 :   }
     210           0 :   return srcEnum;
     211           0 : }
     212             : 
     213           0 : String FluxStdSrcs::EnumToSrcName(const FSS::Source srcEnum) const
     214             : {
     215           0 :    return names_p.find(srcEnum)->second[0];
     216             : }
     217             : 
     218           0 : MDirection FluxStdSrcs::getDirection(const FSS::Source srcEnum) const
     219             : {
     220           0 :   return directions_p.find(srcEnum)->second;
     221             : }
     222             : 
     223             : } //# NAMESPACE CASA - END

Generated by: LCOV version 1.16