casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RFATimeFreqCrop.h
Go to the documentation of this file.
00001 //# RFATimeFreqCrop.h : This defines RFATimeFreqCrop
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 
00028 #ifndef FLAGGING_RFATIMEFREQCROP_H
00029 #define FLAGGING_RFATIMEFREQCROP_H
00030 
00031 #include <flagging/Flagging/RFAFlagCubeBase.h> 
00032 #include <flagging/Flagging/RFDataMapper.h> 
00033 #include <flagging/Flagging/RFFlagCube.h> 
00034 #include <flagging/Flagging/RFRowClipper.h> 
00035 #include <flagging/Flagging/RFABase.h>
00036 #include <casa/Arrays/Vector.h>
00037 #include <scimath/Functionals/Polynomial.h>
00038 #include <scimath/Fitting.h>
00039 #include <scimath/Fitting/LinearFit.h>
00040 #include <scimath/Fitting/GenericL2Fit.h>
00041 #include <scimath/Mathematics/MedianSlider.h> 
00042 #include <synthesis/MSVis/VisibilityIterator.h>
00043 #include <synthesis/MSVis/VisBuffer.h>
00044 
00045 namespace casa { //# NAMESPACE CASA - BEGIN
00046 
00047 
00048 // <summary>
00049 // RFATimeFreqCrop : 2-Dimensional Time Frequency Autoflag agent 
00050 // </summary>
00051 
00052 // <use visibility=local>
00053 
00054 // <reviewed reviewer="" date="" tests="" demos="">
00055 // </reviewed>
00056 
00057 // <prerequisite>
00058 //   <li> RFDataMapper
00059 //   <li> RFFlagCubeBase
00060 //   <li> RFCubeLattice
00061 // </prerequisite>
00062 //
00063 // <synopsis>
00064 // </synopsis>
00065 //
00066 // <todo asof="2002/08/06">
00067 //   <li> 
00068 //   <li> 
00069 //   <li> 
00070 //   // </todo>
00071 
00072 
00073 
00074 //class RFATimeFreqCrop : public RFADiffMapBase
00075 class RFATimeFreqCrop : public RFAFlagCubeBase, public RFDataMapper
00076 {
00077 public:
00078   RFATimeFreqCrop  ( RFChunkStats &ch,const RecordInterface &parm );
00079   virtual ~RFATimeFreqCrop ();
00080 
00081   virtual Bool newChunk (Int &i);
00082   virtual void endChunk ();
00083   virtual void startData (bool verbose);
00084   virtual IterMode iterTime (uInt itime);
00085   virtual IterMode iterRow  (uInt irow);
00086   virtual IterMode endData  ();
00087   virtual void startFlag (bool verbose);
00088   virtual void iterFlag(uInt itime);
00089   static const RecordInterface & getDefaults ();
00090   
00091 private:
00092   
00093   Float UMean(Vector<Float> vect, Vector<Bool> flag);
00094   Float UStd(Vector<Float> vect, Vector<Bool> flag, Vector<Float> fit);
00095   Float UStd(Vector<Float> vect, Vector<Bool> flag, Float mean);
00096   void CleanBand(Vector<Float> data,Vector<Float> fit);
00097   void PolyFit(Vector<Float> data,Vector<Bool> flag, Vector<Float> fit, uInt lim1, uInt lim2,uInt deg);
00098   void LineFit(Vector<Float> data,Vector<Bool> flag, Vector<Float> fit, uInt lim1, uInt lim2);
00099   void Ants(uInt bs, uInt *a1, uInt *a2);
00100   uInt BaselineIndex(uInt row, uInt a1, uInt a2);
00101 
00102   void Display_ds9(Int xdim, Int ydim, Matrix<Float> &data, Int frame);
00103   void Plot_ds9(Int dim, Vector<Float> data1, Vector<Float> data2);
00104 
00105   void AllocateMemory();  
00106   void FlagZeros();
00107   void RunTFCrop();
00108   void FlagTimeSeries(uInt pl, uInt bs);
00109   void FitCleanBandPass(uInt pl, uInt bs);
00110   void FlagBandPass(uInt pl, uInt bs);
00111   void GrowFlags(uInt pl, uInt bs);
00112   RFA::IterMode ShowFlagPlots();
00113   void ExtendFlags();
00114   void FillChunkFlags();
00115 
00116   uInt itime;  
00117   VisibilityIterator &vi; 
00118   VisBuffer &vb;
00119   uInt TimeStamps;
00120   String msname;
00121   Vector<Int> ant1,ant2;
00122   
00123   Cube <Complex> *vv;   // visCube ptr - for one timestamp
00124   Cube <Complex> vc;    // visCube ptr - for one timestamp
00125   Cube <Bool> ff;       // flagCube ptr - for one timestamp
00126   Vector <Bool> fr;     // rowflag ptr - for one timestamp
00127   Cube<Float> visc;     // visCube
00128   Cube<Bool> flagc;     // flagCube
00129   Cube<Float> meanBP;   // mean bandpass - npol x nbaselines x nchannels
00130   Cube<Float> cleanBP;  // cleaned bandpasses - npol x nbaselines x nchannels
00131   Vector<Bool> rowflags; // rowflags from the MS - ntime x nbaselines
00132   Vector<Bool> baselineflags; // flags for baselines - NumB (for internal use)
00133 
00134   Cube<Bool> chunkflags; // Flags for the entire chunk.
00135   
00136   Vector<Float> tempBP; // temporary workspace - nchannels
00137   Vector<Float> tempTS; // temporary workspace - ntimes
00138   Vector<Bool> flagBP;  // temporary list of flags - nchannels
00139   Vector<Bool> flagTS;  // temporary list of flags - ntimes
00140   Vector<Float> fitBP;  // temporary fit array - nchannels
00141   Vector<Float> fitTS;  // temporary fit array - ntimes
00142  
00143   Float T_TOL,F_TOL,ANT_TOL,BASELN_TOL; // Input parameters
00144   uInt FlagLevel,CorrChoice,NumTime,MaxNPieces;//Input parameters
00145   Bool ShowPlots,DryRun,IgnorePreflags;
00146   uInt nPol;
00147   Bool FreqLineFit;
00148   Bool StopAndExit;
00149   String Column;
00150   Vector<String> Expr;
00151  
00152   Matrix<Bool> RowFlags; // Row Flags
00153   
00154   IPosition cubepos,matpos; 
00155 
00156   uInt passcnt;
00157   uInt iterRowcnt;
00158   uInt iterTimecnt;
00159   uInt timecnt;
00160 
00161   uInt NumT; // Number of timestamps in one block
00162   uInt NumB; // Number of baselines.
00163   uInt NumAnt; // Number of antennas.
00164   uInt NumC; // Number of channels
00165   uInt NumP; // Number of polarizations
00166  
00167   FlagCubeIterator flag_iter; // Local Flag Iterator
00168 };
00169 
00170     
00171 
00172 } //# NAMESPACE CASA - END
00173 
00174 #ifndef AIPS_NO_TEMPLATE_SRC
00175 #include <flagging/Flagging/RFATimeFreqCrop.tcc>
00176 #endif //# AIPS_NO_TEMPLATE_SRC
00177 #endif