LCOV - code coverage report
Current view: top level - flagging/Flagging - FlagAgentClipping.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 97 0.0 %
Date: 2024-10-28 15:53:10 Functions: 0 11 0.0 %

          Line data    Source code
       1             : //# FlagAgentClipping.cc: This file contains the implementation of the FlagAgentClipping 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/FlagAgentClipping.h>
      24             : 
      25             : using namespace casacore;
      26             : namespace casa { //# NAMESPACE CASA - BEGIN
      27             : 
      28           0 : FlagAgentClipping::FlagAgentClipping(FlagDataHandler *dh, Record config, Bool writePrivateFlagCube, Bool flag):
      29           0 :                                                 FlagAgentBase(dh,config,IN_ROWS,writePrivateFlagCube,flag)
      30             : {
      31           0 :         setAgentParameters(config);
      32             : 
      33             :         // Request loading polarization map to FlagDataHandler
      34           0 :         flagDataHandler_p->setMapPolarizations(true);
      35           0 : }
      36             : 
      37           0 : FlagAgentClipping::~FlagAgentClipping()
      38             : {
      39             :         // Compiler automagically calls FlagAgentBase::~FlagAgentBase()
      40           0 : }
      41             : 
      42             : void
      43           0 : FlagAgentClipping::setAgentParameters(Record config)
      44             : {
      45           0 :         logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE));
      46             : 
      47             :         int exists;
      48             : 
      49             :         // First check basic configuration to see what modules are plugged in the check
      50           0 :         exists = config.fieldNumber ("clipzeros");
      51           0 :         if (exists >= 0)
      52             :         {
      53           0 :                 if( config.type(exists) != TpBool )
      54             :                 {
      55           0 :                         throw( AipsError ( "Parameter 'clipzeros' must be of type 'bool'" ) );
      56             :                 }
      57             : 
      58           0 :                 clipzeros_p = config.asBool("clipzeros");
      59             :         }
      60             :         else
      61             :         {
      62           0 :                 clipzeros_p = false;
      63             :         }
      64             : 
      65           0 :         *logger_p << logLevel_p << " clipzeros is " << clipzeros_p << LogIO::POST;
      66             : 
      67             : 
      68           0 :         exists = config.fieldNumber ("clipoutside");
      69           0 :         if (exists >= 0)
      70             :         {
      71           0 :                 if( config.type(exists) != TpBool )
      72             :                 {
      73           0 :                         throw( AipsError ( "Parameter 'clipoutside' must be of type 'bool'" ) );
      74             :                 }
      75             : 
      76           0 :                 clipoutside_p = config.asBool("clipoutside");
      77             :         }
      78             :         else
      79             :         {
      80           0 :                 clipoutside_p = true;
      81             :         }
      82             : 
      83           0 :         *logger_p << logLevel_p << " clipoutside is " << clipoutside_p << LogIO::POST;
      84             : 
      85           0 :         String datacol = "";
      86           0 :         weightcol_p = false;
      87           0 :         exists = config.fieldNumber ("datacolumn");
      88           0 :         if (exists >= 0)
      89             :         {
      90           0 :                 datacol = config.asString("datacolumn");
      91             :         }
      92             : 
      93           0 :         exists = config.fieldNumber ("clipminmax");
      94           0 :         if (exists >= 0)
      95             :         {
      96           0 :                 if( config.type(exists) != TpArrayDouble && config.type(exists) != TpArrayFloat && config.type(exists) != TpArrayInt )
      97             :                 {
      98           0 :                         throw( AipsError ( "Parameter 'clipminmax' must be of type 'array double' : [minval,maxval]" ) );
      99             :                 }
     100             : 
     101           0 :                 Array<Double> cliprange = config.asArrayDouble("clipminmax");
     102           0 :                 if (cliprange.size() == 2)
     103             :                 {
     104           0 :                         Bool deleteIt = false;
     105           0 :                         clipmin_p = cliprange.getStorage(deleteIt)[0];
     106           0 :                         clipmax_p = cliprange.getStorage(deleteIt)[1];
     107           0 :                         *logger_p << logLevel_p << " clipmin is " << clipmin_p << LogIO::POST;
     108           0 :                         *logger_p << logLevel_p << " clipmax is " << clipmax_p << LogIO::POST;
     109             : 
     110           0 :                         clipminmax_p = true;
     111             : 
     112             :                         // for the moment, treat WEIGHT as if it was WEIGHT_SPECTRUM,
     113             :                         // so the clipminmax given by the user is divided by the
     114             :                         // number of channels inside preProcessBuffer()
     115           0 :                         if (datacol.compare("WEIGHT") == 0)
     116             :                         {
     117           0 :                                 weightcol_p = true;
     118           0 :                                 original_clipmin_p = clipmin_p;
     119           0 :                                 original_clipmax_p = clipmax_p;
     120             :                         }
     121             :                 }
     122             :                 else
     123             :                 {
     124           0 :                         clipminmax_p = false;
     125           0 :                         *logger_p << logLevel_p << " clipminmax range not provided" << LogIO::POST;
     126             :                 }
     127             : 
     128           0 :         }
     129             :         else
     130             :         {
     131           0 :                 clipminmax_p = false;
     132           0 :                 *logger_p << logLevel_p << " clipminmax range not provided" << LogIO::POST;
     133             :         }
     134             : 
     135             : 
     136             :         // Then, point to the function covering for all the modules selected
     137           0 :         if (clipminmax_p)
     138             :         {
     139           0 :                 if (clipoutside_p)
     140             :                 {
     141           0 :                         if (clipzeros_p)
     142             :                         {
     143           0 :                                 checkVis_p = &FlagAgentClipping::checkVisForClipOutsideAndZeros;
     144           0 :                                 *logger_p << logLevel_p << " Clipping outside [" <<  clipmin_p << "," <<  clipmax_p << "], plus NaNs and zeros" << LogIO::POST;
     145             :                         }
     146             :                         else
     147             :                         {
     148           0 :                                 checkVis_p = &FlagAgentClipping::checkVisForClipOutside;
     149           0 :                                 *logger_p << logLevel_p << " Clipping outside [" <<  clipmin_p << "," <<  clipmax_p << "], plus NaNs" << LogIO::POST;
     150             :                         }
     151             :                 }
     152             :                 else
     153             :                 {
     154           0 :                         if (clipzeros_p)
     155             :                         {
     156           0 :                                 checkVis_p = &FlagAgentClipping::checkVisForClipInsideAndZeros;
     157           0 :                                 *logger_p << logLevel_p << " Clipping inside [" <<  clipmin_p << "," <<  clipmax_p << "], plus NaNs and zeros" << LogIO::POST;
     158             :                         }
     159             :                         else
     160             :                         {
     161           0 :                                 checkVis_p = &FlagAgentClipping::checkVisForClipInside;
     162           0 :                                 *logger_p << logLevel_p << " Clipping inside [" <<  clipmin_p << "," <<  clipmax_p << "], plus NaNs" << LogIO::POST;
     163             :                         }
     164             :                 }
     165             :         }
     166             :         else
     167             :         {
     168           0 :                 if (clipzeros_p)
     169             :                 {
     170           0 :                         checkVis_p = &FlagAgentClipping::checkVisForNaNsAndZeros;
     171           0 :                         *logger_p << logLevel_p << " Clipping range not provided, clipping NaNs and zeros" << LogIO::POST;
     172             :                 }
     173             :                 else
     174             :                 {
     175           0 :                         checkVis_p = &FlagAgentClipping::checkVisForNaNs;
     176           0 :                         *logger_p << logLevel_p << " Clipping range not provided, clipping only NaNs" << LogIO::POST;
     177             :                 }
     178             :         }
     179             : 
     180           0 :         return;
     181           0 : }
     182             : 
     183             : // jagonzal: With the new WEIGHT/SIGMA convention it is not longer
     184             : // necessary divide the clipping range between the number of channels
     185             : /*
     186             : void
     187             : FlagAgentClipping::preProcessBuffer(const vi::VisBuffer2 &visBuffer)
     188             : {
     189             : 
     190             :         logger_p->origin(LogOrigin(agentName_p,__FUNCTION__,WHERE));
     191             : 
     192             :         // Only done if datacolumn is WEIGHT
     193             :         if (weightcol_p)
     194             :         {
     195             :                 Int nChannels;
     196             :                 nChannels = visBuffer.nChannels();
     197             :                 clipmin_p = original_clipmin_p/nChannels;
     198             :                 clipmax_p = original_clipmax_p/nChannels;
     199             :         }
     200             :         *logger_p << LogIO::DEBUG1 << " clipmin is " << clipmin_p << LogIO::POST;
     201             :         *logger_p << LogIO::DEBUG1 << " clipmax is " << clipmax_p << LogIO::POST;
     202             : 
     203             : }
     204             : */
     205             : 
     206             : bool
     207           0 : FlagAgentClipping::computeInRowFlags(const vi::VisBuffer2 &/*visBuffer*/, VisMapper &visibilities,
     208             :                 FlagMapper &flags, uInt row)
     209             : {
     210             :         // Get flag cube size
     211             :         Float visExpression;
     212             :         Int nPols,nChannels,nTimesteps;
     213           0 :         visibilities.shape(nPols, nChannels, nTimesteps);
     214             : 
     215           0 :         for (uInt chan_i=0;chan_i<(uInt) nChannels;chan_i++)
     216             :         {
     217           0 :                 for (uInt pol_i=0;pol_i<(uInt) nPols;pol_i++)
     218             :                 {
     219           0 :                         visExpression = visibilities(pol_i,chan_i,row);
     220           0 :                         if ((*this.*checkVis_p)(visExpression))
     221             :                         {
     222           0 :                                 flags.applyFlag(pol_i,chan_i,row);
     223           0 :                                 visBufferFlags_p += 1;
     224             :                         }
     225             :                 }
     226             :         }
     227             : 
     228           0 :         return false;
     229             : }
     230             : 
     231             : bool
     232           0 : FlagAgentClipping::checkVisForClipOutside(Float visExpression)
     233             : {
     234           0 :         if ((visExpression >  clipmax_p) or (visExpression <  clipmin_p))
     235             :         {
     236           0 :                 return true;
     237             :         }
     238             :         else
     239             :         {
     240           0 :                 return isNaN(visExpression);
     241             :         }
     242             : }
     243             : 
     244             : bool
     245           0 : FlagAgentClipping::checkVisForClipInside(Float visExpression)
     246             : {
     247           0 :         if ((visExpression <=  clipmax_p) and (visExpression >=  clipmin_p))
     248             :         {
     249           0 :                 return true;
     250             :         }
     251             :         else
     252             :         {
     253           0 :                 return isNaN(visExpression);
     254             :         }
     255             : }
     256             : 
     257             : bool
     258           0 : FlagAgentClipping::checkVisForClipOutsideAndZeros(Float visExpression)
     259             : {
     260           0 :         if ((visExpression >  clipmax_p) or (visExpression <  clipmin_p))
     261             :         {
     262           0 :                 return true;
     263             :         }
     264             :         else
     265             :         {
     266           0 :                 return isNaNOrZero(visExpression);
     267             :         }
     268             : }
     269             : 
     270             : bool
     271           0 : FlagAgentClipping::checkVisForClipInsideAndZeros(Float visExpression)
     272             : {
     273           0 :         if ((visExpression <=  clipmax_p) and (visExpression >=  clipmin_p))
     274             :         {
     275           0 :                 return true;
     276             :         }
     277             :         else
     278             :         {
     279           0 :                 return isNaNOrZero(visExpression);
     280             :         }
     281             : }
     282             : 
     283             : bool
     284           0 : FlagAgentClipping::checkVisForNaNs(Float visExpression)
     285             : {
     286           0 :         return isNaN(visExpression);
     287             : }
     288             : 
     289             : bool
     290           0 : FlagAgentClipping::checkVisForNaNsAndZeros(Float visExpression)
     291             : {
     292           0 :         return isNaNOrZero(visExpression);
     293             : }
     294             : 
     295             : 
     296             : 
     297             : } //# NAMESPACE CASA - END
     298             : 
     299             : 

Generated by: LCOV version 1.16