LCOV - code coverage report
Current view: top level - flagging/Flagging - Flagger.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 11 0.0 %
Date: 2024-10-04 18:58:15 Functions: 0 6 0.0 %

          Line data    Source code
       1             : //# Flagger.h: this defines Flagger
       2             : //# Copyright (C) 2000,2001
       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             : //# $Id$
      27             : #ifndef FLAGGING_FLAGGER_H
      28             : #define FLAGGING_FLAGGER_H
      29             : 
      30             : #include <flagging/Flagging/RFCommon.h>
      31             : #include <flagging/Flagging/RFABase.h>
      32             : #include <flagging/Flagging/FlagVersion.h>
      33             : 
      34             : #include <casacore/ms/MeasurementSets/MeasurementSet.h>
      35             : #include <casacore/ms/MSSel/MSSelection.h>
      36             : #include <casacore/measures/Measures/MDirection.h>
      37             : #include <casacore/measures/Measures/MPosition.h>
      38             : #include <casacore/measures/Measures/MRadialVelocity.h>
      39             : #include <casacore/casa/Logging/LogIO.h>
      40             : #include <casacore/casa/Arrays/Vector.h>
      41             : #include <casacore/casa/Containers/Record.h>
      42             : #include <casacore/casa/Quanta/Quantum.h>
      43             : 
      44             : namespace casa { //# NAMESPACE CASA - BEGIN
      45             : 
      46             : class VisSet;
      47             : class RFChunkStats;
      48             :         
      49             : // <summary>
      50             : // Flagger: high-performance automated flagging
      51             : // </summary>
      52             : 
      53             : // <use visibility=global>
      54             : 
      55             : // <reviewed reviewer="" date="" tests="" demos="">
      56             : // </reviewed>
      57             : 
      58             : // <prerequisite>
      59             : //   <li> implement/Flagger
      60             : // </prerequisite>
      61             : //
      62             : // <etymology>
      63             : // casacore::MSFlagger and plain flagger were already taken.
      64             : // </etymology>
      65             : //
      66             : // <synopsis>
      67             : // Flagger performs automated flagging operations on a measurement set.
      68             : // The class is constructed from an MS. After that, the run method may be used
      69             : // to run any number of flagging agents.
      70             : // </synopsis>
      71             : //
      72             : // <example>
      73             : //        // construct casacore::MS and flagger
      74             : //        casacore::MeasurementSet ms("test.MS2",casacore::Table::Update);
      75             : //        Flagger flagger(ms);
      76             : //        // build record of global flagging options
      77             : //        casacore::Record opt(casacore::Record::Variable);
      78             : //        // build record of flagging agents to be run
      79             : //        casacore::Record selopt( flagger.defaultAgents().asRecord("select") );
      80             : //        selopt.define(RF_POLICY,"RESET");
      81             : //        selopt.define(RF_AUTOCORR,true);
      82             : //        casacore::Record agents(casacore::Record::Variable);
      83             : //        agents.defineRecord("select",selopt);
      84             : //        // perform the flagging
      85             : //        flagger.run(agents,opt);
      86             : // </example>
      87             : //
      88             : // <motivation>
      89             : // We need an automated flagging tool. Existing tools (casacore::MSFlagger and flagger.g)
      90             : // were too slow. Hence, Flagger was developed.
      91             : // </motivation>
      92             : //
      93             : // <todo asof="2001/04/16">
      94             : //   <li> add this feature
      95             : //   <li> fix this bug
      96             : //   <li> start discussion of this possible extension
      97             : // </todo>
      98             : 
      99             : 
     100             : class Flagger : public FlaggerEnums
     101             : {
     102             : protected:
     103             : // creates an agent by name
     104             :   std::shared_ptr<RFABase> createAgent ( const casacore::String &name,RFChunkStats &chunk,const casacore::RecordInterface &parms, bool &only_selector );
     105             : 
     106             : // sets up record of agents and default parameters
     107             :   const casacore::RecordInterface & setupAgentDefaults ();
     108             : 
     109             : // print flagging reports from individual agents
     110             :   void printAgentReports  ( );
     111             : 
     112             :   void printSummaryReport ( RFChunkStats &chunk );
     113             :   casacore::Bool selectDataChannel();
     114             :  
     115             :   casacore::MeasurementSet   ms;
     116             :   casacore::MeasurementSet   originalms;
     117             :   std::vector<std::shared_ptr<RFABase> > acc;
     118             : 
     119             :   //new added
     120             :   casacore::MeasurementSet *mssel_p;
     121             :   VisSet *vs_p;
     122             :   bool scan_looping;     /* Is scan number part of visiter looping? */
     123             :   casacore::String msname_p;
     124             :   casacore::Bool nullSelect_p;
     125             :   casacore::Bool setdata_p;
     126             :   casacore::Bool selectdata_p;
     127             :   casacore::String dataMode_p;  
     128             : 
     129             : //  casacore::Vector<casacore::Int> dataEnd_p;
     130             : //  casacore::Vector<casacore::Int> dataStart_p, dataStep_p;
     131             : //  casacore::Vector<casacore::Int> dataspectralwindowids_p;
     132             : //  casacore::Vector<casacore::Int> spwidnchans_p;
     133             :   casacore::Vector<casacore::String> correlations_p;
     134             :   casacore::Vector<casacore::Int> datafieldids_p;
     135             :   casacore::Vector<casacore::Int> datadescids_p;
     136             :   casacore::MRadialVelocity mDataStart_p;
     137             :   casacore::MRadialVelocity mDataStep_p;
     138             : 
     139             :   //
     140             :   casacore::uInt nant,nifr,nfeed,nfeedcorr;
     141             :   casacore::Vector<casacore::Int> ifr2ant1,ifr2ant2;
     142             :   casacore::Vector<casacore::String> antnames;
     143             :   casacore::Vector<casacore::Double> spwfreqs;
     144             :     
     145             :   casacore::Record agent_defaults;
     146             : 
     147             :   static casacore::LogIO os;
     148             : 
     149             : public:  
     150             : // default constructor 
     151             :   Flagger  ();
     152             : // construct and attach to a measurement set
     153             :   Flagger  ( casacore::MeasurementSet &ms );
     154             :   
     155             :   ~Flagger ();
     156             :   
     157             : // Change or set the casacore::MS this Flagger refers to.
     158             :   bool attach( casacore::MeasurementSet &ms, casacore::Bool setupAgentDefaults=true );
     159             : 
     160             :   // Set the data selection parameters
     161             :   casacore::Bool selectdata(casacore::Bool useoriginalms=false, 
     162             :                   casacore::String field="", casacore::String spw="", casacore::String array="", casacore::String feed="", casacore::String scan="",
     163             :                   casacore::String baseline="", casacore::String uvrange="", casacore::String time="",
     164             :                   casacore::String correlation="", casacore::String intent="", casacore::String observation="");
     165             : 
     166             :   // Make a data selection
     167             :   casacore::Bool setdata(casacore::String field, casacore::String spw, casacore::String array, casacore::String feed, casacore::String scan,
     168             :                casacore::String baseline, casacore::String uvrange, casacore::String time,
     169             :                casacore::String correlation, casacore::String intent, casacore::String observation="");
     170             :   
     171             :   // Make a selection for manual flagging
     172             :   casacore::Bool setmanualflags(casacore::Bool autocorr,
     173             :                       casacore::Bool unflag, 
     174             :                       casacore::String clipexpr, 
     175             :                       casacore::Vector<casacore::Double> cliprange, 
     176             :                       casacore::String clipcolumn, 
     177             :                       casacore::Bool outside, 
     178             :                       casacore::Bool channel_average,
     179             :                       casacore::Double quackinterval=0.0, 
     180             :                       casacore::String quackmode=casacore::String("beg"),
     181             :                       casacore::Bool quackincrement=casacore::Bool(false),
     182             :                       casacore::String opmode=casacore::String("flag"),
     183             :                       casacore::Double diameter = -1.0,
     184             :                       casacore::Double lowerlimit = -1.0,
     185             :                       casacore::Double upperlimit = 91.0);
     186             : 
     187             :   // Clean up all agents of type "select".
     188             :   //casacore::Bool clearflagselections(casacore::Vector<casacore::Int> &recordlist,casacore::Vector<casacore::String> &agentlist);
     189             :   casacore::Bool clearflagselections(casacore::Int recordindex);
     190             :   casacore::Bool printflagselections();
     191             : 
     192             :   // Fill the selection record to attach to the list of agents
     193             :   casacore::Bool fillSelections(casacore::Record &rec);
     194             : 
     195             :   // Set autoflag params
     196             :   casacore::Bool setautoflagparams(casacore::String algorithm, casacore::Record &parameters);
     197             : 
     198             :   // Get default autoflag params
     199             :   casacore::Record getautoflagparams(casacore::String algorithm);
     200             : 
     201             :   casacore::Bool addAgent(casacore::RecordInterface &newAgent);
     202             :   
     203             :   // Detaches from the casacore::MS  
     204             :   void detach();
     205             :   
     206             :   casacore::Record run(casacore::Bool trial, casacore::Bool reset);    
     207             : 
     208             :   void summary ( const casacore::RecordInterface &agents ); 
     209             : 
     210             :     // flag version support.
     211             :   casacore::Bool  saveFlagVersion(casacore::String versionname, casacore::String comment, casacore::String merge);
     212             :   casacore::Bool  restoreFlagVersion(casacore::Vector<casacore::String> versionname, casacore::String merge);
     213             :   casacore::Bool  deleteFlagVersion(casacore::Vector<casacore::String> versionname);
     214             :   casacore::Bool  getFlagVersionList( casacore::Vector<casacore::String> &verlist);
     215             :  
     216             :   
     217             :   // returns current MS
     218           0 :   const casacore::MeasurementSet & measSet() const { return ms; }
     219             :     
     220             : // number of antennas in MS
     221           0 :   casacore::uInt numAnt    () const 
     222           0 :       { return nant; };
     223             : 
     224             : // number of IFRs in MS
     225           0 :   casacore::uInt numIfr    () const 
     226           0 :       { return nifr; };
     227             : 
     228             : // number of feeds in MS
     229           0 :   casacore::uInt numFeed    () const 
     230           0 :       { return nfeed; };
     231             : 
     232             : // number of feed correlations in MS
     233           0 :   casacore::uInt numFeedCorr    () const 
     234           0 :       { return nfeedcorr; };
     235             : 
     236             : // names of antennas
     237           0 :   const casacore::Vector<casacore::String> & antNames() const 
     238           0 :       { return antnames; };
     239             :   
     240             : // derives a flat IFR index from two antenna indices
     241             :   casacore::uInt ifrNumber ( casacore::Int ant1,casacore::Int ant2 ) const;
     242             : 
     243             : // vector version of above
     244             :   casacore::Vector<casacore::Int> ifrNumbers ( casacore::Vector<casacore::Int> ant1,casacore::Vector<casacore::Int> ant2 ) const;
     245             : 
     246             : // derives antenna indices from a flat IFR index
     247             :   void ifrToAnt ( casacore::uInt &ant1,casacore::uInt &ant2,casacore::uInt ifr ) const;
     248             : 
     249             : // returns a record with all available agents and their default options
     250             :   const casacore::RecordInterface & defaultAgents () const 
     251             :       { return agent_defaults; }
     252             : 
     253             : // returns a record of available options
     254             :   static const casacore::RecordInterface & defaultOptions ();
     255             : 
     256             : // returns the log sink 
     257             :   static casacore::LogIO & logSink ()       { return os; }
     258             : 
     259             :   /* Get rid of negative indices (meaning negation of antenna) in baselinelist */
     260             :   static void reform_baselinelist(casacore::Matrix<casacore::Int> &baselinelist, unsigned nant);
     261             :   
     262             :   static int my_aipspp_sum(const casacore::Array<casacore::Bool> &a);
     263             : 
     264             : private:
     265             :     
     266             :   Flagger( const Flagger & )          {};
     267             : 
     268             :   Flagger& operator=(const Flagger &)  { return *this; };
     269             : 
     270             :   void printAgentRecord(casacore::String &, casacore::uInt, const casacore::RecordInterface &);
     271             : 
     272             :   // Sink used to store history
     273             :   casacore::LogSink logSink_p;
     274             : 
     275             :   // Hold the original ms 
     276             :   casacore::MeasurementSet *originalms_p;
     277             :   
     278             :   // casacore::MS Selection
     279             :   casacore::MSSelection *msselection_p;
     280             :   bool spw_selection;  //non-trivial spw-selection
     281             : 
     282             :   // casacore::List of Agents
     283             :   casacore::Record *agents_p;
     284             :   casacore::Int agentCount_p;
     285             : 
     286             :   // casacore::List of extra options
     287             :   casacore::Record *opts_p;
     288             : 
     289             :   // Debug Message flag
     290             :   static const bool dbg;
     291             : 
     292             :   casacore::Bool quack_agent_exists;
     293             :   /* More initialization is required, if there exists a quacking agent */
     294             : };
     295             : 
     296             : 
     297             : } //# NAMESPACE CASA - END
     298             : 
     299             : #endif
     300             : 

Generated by: LCOV version 1.16