LCOV - code coverage report
Current view: top level - flagging/Flagging - FlagAgentElevation.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 76 0.0 %
Date: 2024-10-28 15:53:10 Functions: 0 7 0.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           0 : FlagAgentElevation::FlagAgentElevation(FlagDataHandler *dh, Record config, Bool writePrivateFlagCube, Bool flag):
      37           0 :                 FlagAgentBase(dh,config,ROWS_PREPROCESS_BUFFER,writePrivateFlagCube,flag)
      38             : {
      39           0 :         setAgentParameters(config);
      40             : 
      41             :         // Request loading antenna pointing map to FlagDataHandler
      42           0 :         flagDataHandler_p->setMapAntennaPointing(true);
      43             : 
      44             :         // FlagAgentElevation counters and ids to handle static variables
      45           0 :         staticMembersMutex_p.acquirelock();
      46           0 :         agentNumber_p = nAgents_p;
      47           0 :         nAgents_p += 1;
      48           0 :         staticMembersMutex_p.unlock();
      49           0 : }
      50             : 
      51           0 : 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           0 :         staticMembersMutex_p.acquirelock();
      58           0 :         agentNumber_p = nAgents_p;
      59           0 :         nAgents_p -= 1;
      60           0 :         staticMembersMutex_p.unlock();
      61           0 : }
      62             : 
      63             : void
      64           0 : FlagAgentElevation::setAgentParameters(Record config)
      65             : {
      66           0 :         logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE));
      67             :         int exists;
      68             : 
      69           0 :         exists = config.fieldNumber ("lowerlimit");
      70           0 :         if (exists >= 0)
      71             :         {
      72           0 :                 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           0 :                 lowerlimit_p = config.asDouble("lowerlimit");
      78             :         }
      79             :         else
      80             :         {
      81           0 :                 lowerlimit_p = 0.0;
      82             :         }
      83             : 
      84           0 :         *logger_p << logLevel_p << " lowerlimit is " << lowerlimit_p << LogIO::POST;
      85             : 
      86           0 :         exists = config.fieldNumber ("upperlimit");
      87           0 :         if (exists >= 0)
      88             :         {
      89           0 :                 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           0 :                 upperlimit_p = config.asDouble("upperlimit");
      95             :         }
      96             :         else
      97             :         {
      98           0 :                 upperlimit_p = 90.0;
      99             :         }
     100             : 
     101           0 :         *logger_p << logLevel_p << " upperlimit is " << upperlimit_p << LogIO::POST;
     102             : 
     103             : 
     104           0 :         return;
     105             : }
     106             : 
     107             : void
     108           0 : FlagAgentElevation::preProcessBuffer(const vi::VisBuffer2 &visBuffer)
     109             : {
     110           0 :         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           0 :                 preProcessBufferCore(visBuffer);
     135             :         }
     136             : 
     137           0 :         return;
     138             : }
     139             : 
     140             : void
     141           0 : FlagAgentElevation::preProcessBufferCore(const vi::VisBuffer2 &visBuffer)
     142             : {
     143           0 :         Vector<Double> time = visBuffer.time();
     144           0 :         uInt nRows = time.size();
     145           0 :         antennaPointingMap_p.clear();
     146           0 :         antennaPointingMap_p.reserve(nRows);
     147           0 :         for (uInt row_i=0;row_i<nRows;row_i++)
     148             :         {
     149           0 :                 Vector<MDirection> azimuth_elevation = visBuffer.azel(time[row_i]);
     150           0 :                 Int ant1 = visBuffer.antenna1()[row_i];
     151           0 :                 Int ant2 = visBuffer.antenna2()[row_i];
     152             : 
     153           0 :                 double antenna1_elevation = azimuth_elevation[ant1].getAngle("deg").getValue()[1];
     154           0 :                 double antenna2_elevation = azimuth_elevation[ant2].getAngle("deg").getValue()[1];
     155             : 
     156           0 :                 vector<Double> item(2);
     157           0 :                 item[0] = antenna1_elevation;
     158           0 :                 item[1] = antenna2_elevation;
     159           0 :                 antennaPointingMap_p.push_back(item);
     160           0 :         }
     161             : 
     162           0 :         return;
     163           0 : }
     164             : 
     165             : bool
     166           0 : FlagAgentElevation::computeRowFlags(const vi::VisBuffer2 &/*visBuffer*/, FlagMapper &/*flags*/, uInt row)
     167             : {
     168           0 :     double antenna1_elevation = antennaPointingMap_p.at(row).at(0);
     169           0 :     double antenna2_elevation = antennaPointingMap_p.at(row).at(1);
     170           0 :     bool flagRow = false;
     171             : 
     172           0 :     if ( antenna1_elevation < lowerlimit_p ||
     173           0 :          antenna2_elevation < lowerlimit_p ||
     174           0 :          antenna1_elevation > upperlimit_p ||
     175           0 :          antenna2_elevation > upperlimit_p )
     176             :     {
     177           0 :         flagRow = true;
     178             :     }
     179             : 
     180           0 :         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           0 :         return flagRow;
     190             : }
     191             : 
     192             : } //# NAMESPACE CASA - END
     193             : 
     194             : 

Generated by: LCOV version 1.16