Flagger.h

Go to the documentation of this file.
00001 //# Flagger.h: this defines Flagger
00002 //# Copyright (C) 2000,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id$
00027 #ifndef FLAGGING_FLAGGER_H
00028 #define FLAGGING_FLAGGER_H
00029 
00030 #include <flagging/Flagging/RFCommon.h>
00031 #include <flagging/Flagging/RFABase.h>
00032 #include <flagging/Flagging/FlagVersion.h>
00033 
00034 #include <ms/MeasurementSets/MeasurementSet.h>
00035 #include <ms/MSSel/MSSelection.h>
00036 #include <measures/Measures/MDirection.h>
00037 #include <measures/Measures/MPosition.h>
00038 #include <measures/Measures/MRadialVelocity.h>
00039 #include <casa/Logging/LogIO.h>
00040 #include <casa/Arrays/Vector.h>
00041 #include <casa/Containers/Record.h>
00042 #include <casa/Quanta/Quantum.h>
00043 
00044 namespace casa { //# NAMESPACE CASA - BEGIN
00045 
00046 class VisSet;
00047 class RFChunkStats;
00048         
00049 // <summary>
00050 // Flagger: high-performance automated flagging
00051 // </summary>
00052 
00053 // <use visibility=global>
00054 
00055 // <reviewed reviewer="" date="" tests="" demos="">
00056 // </reviewed>
00057 
00058 // <prerequisite>
00059 //   <li> implement/Flagger
00060 // </prerequisite>
00061 //
00062 // <etymology>
00063 // MSFlagger and plain flagger were already taken.
00064 // </etymology>
00065 //
00066 // <synopsis>
00067 // Flagger performs automated flagging operations on a measurement set.
00068 // The class is constructed from an MS. After that, the run method may be used
00069 // to run any number of flagging agents.
00070 // </synopsis>
00071 //
00072 // <example>
00073 //        // construct MS and flagger
00074 //        MeasurementSet ms("test.MS2",Table::Update);
00075 //        Flagger flagger(ms);
00076 //        // build record of global flagging options
00077 //        Record opt(Record::Variable);
00078 //        // build record of flagging agents to be run
00079 //        Record selopt( flagger.defaultAgents().asRecord("select") );
00080 //        selopt.define(RF_POLICY,"RESET");
00081 //        selopt.define(RF_AUTOCORR,True);
00082 //        Record agents(Record::Variable);
00083 //        agents.defineRecord("select",selopt);
00084 //        // perform the flagging
00085 //        flagger.run(agents,opt);
00086 // </example>
00087 //
00088 // <motivation>
00089 // We need an automated flagging tool. Existing tools (MSFlagger and flagger.g)
00090 // were too slow. Hence, Flagger was developed.
00091 // </motivation>
00092 //
00093 // <todo asof="2001/04/16">
00094 //   <li> add this feature
00095 //   <li> fix this bug
00096 //   <li> start discussion of this possible extension
00097 // </todo>
00098 
00099 
00100 class Flagger : public FlaggerEnums
00101 {
00102 protected:
00103 // creates an agent by name
00104   std::shared_ptr<RFABase> createAgent ( const String &name,RFChunkStats &chunk,const RecordInterface &parms, bool &only_selector );
00105 
00106 // sets up record of agents and default parameters
00107   const RecordInterface & setupAgentDefaults ();
00108 
00109 // print flagging reports from individual agents
00110   void printAgentReports  ( );
00111 
00112   void printSummaryReport ( RFChunkStats &chunk );
00113   Bool selectDataChannel();
00114  
00115   MeasurementSet   ms;
00116   MeasurementSet   originalms;
00117   std::vector<std::shared_ptr<RFABase> > acc;
00118 
00119   //new added
00120   MeasurementSet *mssel_p;
00121   VisSet *vs_p;
00122   bool scan_looping;     /* Is scan number part of visiter looping? */
00123   String msname_p;
00124   Bool nullSelect_p;
00125   Bool setdata_p;
00126   Bool selectdata_p;
00127   String dataMode_p;  
00128 
00129 //  Vector<Int> dataEnd_p;
00130 //  Vector<Int> dataStart_p, dataStep_p;
00131 //  Vector<Int> dataspectralwindowids_p;
00132 //  Vector<Int> spwidnchans_p;
00133   Vector<String> correlations_p;
00134   Vector<Int> datafieldids_p;
00135   Vector<Int> datadescids_p;
00136   MRadialVelocity mDataStart_p;
00137   MRadialVelocity mDataStep_p;
00138 
00139   //
00140   uInt nant,nifr,nfeed,nfeedcorr;
00141   Vector<Int> ifr2ant1,ifr2ant2;
00142   Vector<String> antnames;
00143   Vector<Double> spwfreqs;
00144     
00145   Record agent_defaults;
00146 
00147   static LogIO os;
00148 
00149 public:  
00150 // default constructor 
00151   Flagger  ();
00152 // construct and attach to a measurement set
00153   Flagger  ( MeasurementSet &ms );
00154   
00155   ~Flagger ();
00156   
00157 // Change or set the MS this Flagger refers to.
00158   bool attach( MeasurementSet &ms, Bool setupAgentDefaults=True );
00159 
00160   // Set the data selection parameters
00161   Bool selectdata(Bool useoriginalms=False, 
00162                   String field="", String spw="", String array="", String feed="", String scan="",
00163                   String baseline="", String uvrange="", String time="",
00164                   String correlation="", String intent="", String observation="");
00165 
00166   // Make a data selection
00167   Bool setdata(String field, String spw, String array, String feed, String scan,
00168                String baseline, String uvrange, String time,
00169                String correlation, String intent, String observation="");
00170   
00171   // Make a selection for manual flagging
00172   Bool setmanualflags(Bool autocorr,
00173                       Bool unflag, 
00174                       String clipexpr, 
00175                       Vector<Double> cliprange, 
00176                       String clipcolumn, 
00177                       Bool outside, 
00178                       Bool channel_average,
00179                       Double quackinterval=0.0, 
00180                       String quackmode=String("beg"),
00181                       Bool quackincrement=Bool(false),
00182                       String opmode=String("flag"),
00183                       Double diameter = -1.0,
00184                       Double lowerlimit = -1.0,
00185                       Double upperlimit = 91.0);
00186 
00187   // Clean up all agents of type "select".
00188   //Bool clearflagselections(Vector<Int> &recordlist,Vector<String> &agentlist);
00189   Bool clearflagselections(Int recordindex);
00190   Bool printflagselections();
00191 
00192   // Fill the selection record to attach to the list of agents
00193   Bool fillSelections(Record &rec);
00194 
00195   // Set autoflag params
00196   Bool setautoflagparams(String algorithm, Record &parameters);
00197 
00198   // Get default autoflag params
00199   Record getautoflagparams(String algorithm);
00200 
00201   Bool addAgent(RecordInterface &newAgent);
00202   
00203   // Detaches from the MS  
00204   void detach();
00205   
00206   Record run(Bool trial, Bool reset);    
00207 
00208   void summary ( const RecordInterface &agents ); 
00209 
00210     // flag version support.
00211   Bool  saveFlagVersion(String versionname, String comment, String merge);
00212   Bool  restoreFlagVersion(Vector<String> versionname, String merge);
00213   Bool  deleteFlagVersion(Vector<String> versionname);
00214   Bool  getFlagVersionList( Vector<String> &verlist);
00215  
00216   
00217   // returns current MS
00218   const MeasurementSet & measSet() const { return ms; }
00219     
00220 // number of antennas in MS
00221   uInt numAnt    () const 
00222       { return nant; };
00223 
00224 // number of IFRs in MS
00225   uInt numIfr    () const 
00226       { return nifr; };
00227 
00228 // number of feeds in MS
00229   uInt numFeed    () const 
00230       { return nfeed; };
00231 
00232 // number of feed correlations in MS
00233   uInt numFeedCorr    () const 
00234       { return nfeedcorr; };
00235 
00236 // names of antennas
00237   const Vector<String> & antNames() const 
00238       { return antnames; };
00239   
00240 // derives a flat IFR index from two antenna indices
00241   uInt ifrNumber ( Int ant1,Int ant2 ) const;
00242 
00243 // vector version of above
00244   Vector<Int> ifrNumbers ( Vector<Int> ant1,Vector<Int> ant2 ) const;
00245 
00246 // derives antenna indices from a flat IFR index
00247   void ifrToAnt ( uInt &ant1,uInt &ant2,uInt ifr ) const;
00248 
00249 // returns a record with all available agents and their default options
00250   const RecordInterface & defaultAgents () const 
00251       { return agent_defaults; }
00252 
00253 // returns a record of available options
00254   static const RecordInterface & defaultOptions ();
00255 
00256 // returns the log sink 
00257   static LogIO & logSink ()       { return os; }
00258 
00259   /* Get rid of negative indices (meaning negation of antenna) in baselinelist */
00260   static void reform_baselinelist(Matrix<Int> &baselinelist, unsigned nant);
00261   
00262   static int my_aipspp_sum(const Array<Bool> &a);
00263 
00264 private:
00265     
00266   Flagger( const Flagger & )          {};
00267 
00268   Flagger& operator=(const Flagger &)  { return *this; };
00269 
00270   void printAgentRecord(String &, uInt, const RecordInterface &);
00271 
00272   // Sink used to store history
00273   LogSink logSink_p;
00274 
00275   // Hold the original ms 
00276   MeasurementSet *originalms_p;
00277   
00278   // MS Selection
00279   MSSelection *msselection_p;
00280   bool spw_selection;  //non-trivial spw-selection
00281 
00282   // List of Agents
00283   Record *agents_p;
00284   Int agentCount_p;
00285 
00286   // List of extra options
00287   Record *opts_p;
00288 
00289   // Debug Message flag
00290   static const bool dbg;
00291 
00292   Bool quack_agent_exists;
00293   /* More initialization is required, if there exists a quacking agent */
00294 };
00295 
00296 
00297 } //# NAMESPACE CASA - END
00298 
00299 #endif
00300 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1