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

Generated by: LCOV version 1.16