LCOV - code coverage report
Current view: top level - flagging/Flagging - FlagAgentElevation.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 59 74 79.7 %
Date: 2023-10-25 08:47:59 Functions: 7 7 100.0 %

          Line data    Source code
       1             : //# FlagAgentElevation.cc: This file contains the implementation of the FlagAgentElevation class.
       2             : //#
       3             : //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
       4             : //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
       5             : //#  Copyright (C) European Southern Observatory, 2011, All rights reserved.
       6             : //#
       7             : //#  This library is free software; you can redistribute it and/or
       8             : //#  modify it under the terms of the GNU Lesser General Public
       9             : //#  License as published by the Free software Foundation; either
      10             : //#  version 2.1 of the License, or (at your option) any later version.
      11             : //#
      12             : //#  This library is distributed in the hope that it will be useful,
      13             : //#  but WITHOUT ANY WARRANTY, without even the implied warranty of
      14             : //#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             : //#  Lesser General Public License for more details.
      16             : //#
      17             : //#  You should have received a copy of the GNU Lesser General Public
      18             : //#  License along with this library; if not, write to the Free Software
      19             : //#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      20             : //#  MA 02111-1307  USA
      21             : //# $Id: $
      22             : 
      23             : #include <flagging/Flagging/FlagAgentElevation.h>
      24             : 
      25             : using namespace casacore;
      26             : namespace casa { //# NAMESPACE CASA - BEGIN
      27             : 
      28             : // Definition of static members for common pre-processing
      29             : vector< vector<Double> > FlagAgentElevation::antennaPointingMap_p;
      30             : casa::async::Mutex FlagAgentElevation::staticMembersMutex_p;
      31             : vector<bool> FlagAgentElevation::startedProcessing_p;
      32             : bool FlagAgentElevation::preProcessingDone_p = false;
      33             : uShort FlagAgentElevation::nAgents_p = 0;
      34             : 
      35             : 
      36           8 : FlagAgentElevation::FlagAgentElevation(FlagDataHandler *dh, Record config, Bool writePrivateFlagCube, Bool flag):
      37           8 :                 FlagAgentBase(dh,config,ROWS_PREPROCESS_BUFFER,writePrivateFlagCube,flag)
      38             : {
      39           8 :         setAgentParameters(config);
      40             : 
      41             :         // Request loading antenna pointing map to FlagDataHandler
      42           8 :         flagDataHandler_p->setMapAntennaPointing(true);
      43             : 
      44             :         // FlagAgentElevation counters and ids to handle static variables
      45           8 :         staticMembersMutex_p.acquirelock();
      46           8 :         agentNumber_p = nAgents_p;
      47           8 :         nAgents_p += 1;
      48           8 :         staticMembersMutex_p.unlock();
      49           8 : }
      50             : 
      51          16 : FlagAgentElevation::~FlagAgentElevation()
      52             : {
      53             :         // Compiler automagically calls FlagAgentBase::~FlagAgentBase()
      54             : 
      55             :         // NOTE: The following is necessary because the static variables
      56             :         // persist even if all the instances of the class were deleted!
      57           8 :         staticMembersMutex_p.acquirelock();
      58           8 :         agentNumber_p = nAgents_p;
      59           8 :         nAgents_p -= 1;
      60           8 :         staticMembersMutex_p.unlock();
      61          16 : }
      62             : 
      63             : void
      64           8 : FlagAgentElevation::setAgentParameters(Record config)
      65             : {
      66           8 :         logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE));
      67             :         int exists;
      68             : 
      69           8 :         exists = config.fieldNumber ("lowerlimit");
      70           8 :         if (exists >= 0)
      71             :         {
      72           8 :                 if( config.type(exists) != TpDouble && config.type(exists) != TpFloat  && config.type(exists) != TpInt)
      73             :                 {
      74           0 :                          throw( AipsError ( "Parameter 'lowerlimit' must be of type 'double'" ) );
      75             :                 }
      76             :                 
      77           8 :                 lowerlimit_p = config.asDouble("lowerlimit");
      78             :         }
      79             :         else
      80             :         {
      81           0 :                 lowerlimit_p = 0.0;
      82             :         }
      83             : 
      84           8 :         *logger_p << logLevel_p << " lowerlimit is " << lowerlimit_p << LogIO::POST;
      85             : 
      86           8 :         exists = config.fieldNumber ("upperlimit");
      87           8 :         if (exists >= 0)
      88             :         {
      89           8 :                 if( config.type(exists) != TpDouble && config.type(exists) != TpFloat  && config.type(exists) != TpInt)
      90             :                 {
      91           0 :                          throw( AipsError ( "Parameter 'upperlimit' must be of type 'double'" ) );
      92             :                 }
      93             :                 
      94           8 :                 upperlimit_p = config.asDouble("upperlimit");
      95             :         }
      96             :         else
      97             :         {
      98           0 :                 upperlimit_p = 90.0;
      99             :         }
     100             : 
     101           8 :         *logger_p << logLevel_p << " upperlimit is " << upperlimit_p << LogIO::POST;
     102             : 
     103             : 
     104           8 :         return;
     105             : }
     106             : 
     107             : void
     108         420 : FlagAgentElevation::preProcessBuffer(const vi::VisBuffer2 &visBuffer)
     109             : {
     110         420 :         if (nAgents_p > 1)
     111             :         {
     112           0 :                 staticMembersMutex_p.acquirelock();
     113             : 
     114           0 :                 if (!preProcessingDone_p)
     115             :                 {
     116             :                         // Reset processing state variables
     117           0 :                         if (startedProcessing_p.size() != nAgents_p) startedProcessing_p.resize(nAgents_p,false);
     118           0 :                         for (vector<bool>::iterator iter = startedProcessing_p.begin();iter != startedProcessing_p.end();iter++)
     119             :                         {
     120           0 :                                 *iter = false;
     121             :                         }
     122             : 
     123             :                         // Do actual pre-processing
     124           0 :                         preProcessBufferCore(visBuffer);
     125             : 
     126             :                         // Mark pre-processing as done so that other agents don't redo it
     127           0 :                         preProcessingDone_p = true;
     128             :                 }
     129             : 
     130           0 :                 staticMembersMutex_p.unlock();
     131             :         }
     132             :         else
     133             :         {
     134         420 :                 preProcessBufferCore(visBuffer);
     135             :         }
     136             : 
     137         420 :         return;
     138             : }
     139             : 
     140             : void
     141         420 : FlagAgentElevation::preProcessBufferCore(const vi::VisBuffer2 &visBuffer)
     142             : {
     143         840 :         Vector<Double> time = visBuffer.time();
     144         420 :         uInt nRows = time.size();
     145         420 :         antennaPointingMap_p.clear();
     146         420 :         antennaPointingMap_p.reserve(nRows);
     147      158991 :         for (uInt row_i=0;row_i<nRows;row_i++)
     148             :         {
     149      317142 :                 Vector<MDirection> azimuth_elevation = visBuffer.azel(time[row_i]);
     150      158571 :                 Int ant1 = visBuffer.antenna1()[row_i];
     151      158571 :                 Int ant2 = visBuffer.antenna2()[row_i];
     152             : 
     153      158571 :                 double antenna1_elevation = azimuth_elevation[ant1].getAngle("deg").getValue()[1];
     154      158571 :                 double antenna2_elevation = azimuth_elevation[ant2].getAngle("deg").getValue()[1];
     155             : 
     156      317142 :                 vector<Double> item(2);
     157      158571 :                 item[0] = antenna1_elevation;
     158      158571 :                 item[1] = antenna2_elevation;
     159      158571 :                 antennaPointingMap_p.push_back(item);
     160             :         }
     161             : 
     162         840 :         return;
     163             : }
     164             : 
     165             : bool
     166      158571 : FlagAgentElevation::computeRowFlags(const vi::VisBuffer2 &/*visBuffer*/, FlagMapper &/*flags*/, uInt row)
     167             : {
     168      158571 :     double antenna1_elevation = antennaPointingMap_p.at(row).at(0);
     169      158571 :     double antenna2_elevation = antennaPointingMap_p.at(row).at(1);
     170      158571 :     bool flagRow = false;
     171             : 
     172      158571 :     if ( antenna1_elevation < lowerlimit_p ||
     173      113994 :          antenna2_elevation < lowerlimit_p ||
     174      113994 :          antenna1_elevation > upperlimit_p ||
     175       91368 :          antenna2_elevation > upperlimit_p )
     176             :     {
     177       67203 :         flagRow = true;
     178             :     }
     179             : 
     180      158571 :         if ((nAgents_p > 1) and preProcessingDone_p)
     181             :         {
     182           0 :                 startedProcessing_p[agentNumber_p] = true;
     183           0 :                 if (std::find (startedProcessing_p.begin(), startedProcessing_p.end(), false) == startedProcessing_p.end())
     184             :                 {
     185           0 :                         preProcessingDone_p = false;
     186             :                 }
     187             :         }
     188             : 
     189      158571 :         return flagRow;
     190             : }
     191             : 
     192             : } //# NAMESPACE CASA - END
     193             : 
     194             : 

Generated by: LCOV version 1.16