casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RFADiffBase.h
Go to the documentation of this file.
00001 //# RFADiffBase.h: this defines RFADiffBase and RFADiffMapbase
00002 //# Copyright (C) 2000,2001,2002
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_RFADIFFBASE_H
00028 #define FLAGGING_RFADIFFBASE_H
00029 
00030 #include <flagging/Flagging/RFAFlagCubeBase.h> 
00031 #include <flagging/Flagging/RFDataMapper.h> 
00032 #include <flagging/Flagging/RFFloatLattice.h>
00033 #include <flagging/Flagging/RFRowClipper.h>
00034 #include <scimath/Mathematics/MedianSlider.h> 
00035 #include <casa/Arrays/LogiVector.h>
00036 #include <casa/Containers/RecordInterface.h>
00037 
00038 
00039 namespace casa { //# NAMESPACE CASA - BEGIN
00040 
00041 // min number of deviations for which average is considered valid
00042 const int   RFA_MIN_NAD = 20;
00043 // significant change in accumulated average
00044 const Float RFA_AAD_CHANGE = 0.05;
00045 
00046 // <summary>
00047 // RFADiffBase: abstract class for deviation-based flagging
00048 // </summary>
00049 
00050 // <use visibility=local>
00051 
00052 // <reviewed reviewer="" date="" tests="" demos="">
00053 // </reviewed>
00054 
00055 // <prerequisite>
00056 //   <li> RFCubeLattice
00057 //   <li> RFRowClipper
00058 // </prerequisite>
00059 //
00060 // <etymology>
00061 // Diff = Deviation. Well, almost...
00062 // </etymology>
00063 //
00064 // <synopsis>
00065 // Several flagging algorithms flag by analyzing the deviation w/respect
00066 // to something at each point. RFADiffBase provides common functions for
00067 // these classes. It will maintain a lattice of deviations, compute the 
00068 // noise level estimates, and flag points. It will also flag rows with 
00069 // excessive noise level (using RFRowClipper). Derived classes are
00070 // responsible for computing the deviation.
00071 // </synopsis>
00072 //
00073 // <todo asof="2001/04/16">
00074 //   <li> add this feature
00075 //   <li> fix this bug
00076 //   <li> start discussion of this possible extension
00077 // </todo>
00078 
00079 class RFADiffBase : public RFAFlagCubeBase
00080 {
00081 public:
00082   RFADiffBase  ( RFChunkStats &ch,const RecordInterface &parm );
00083   virtual ~RFADiffBase ();
00084   
00085   virtual uInt estimateMemoryUse ();  
00086   virtual Bool newChunk ( Int &maxmem );
00087   virtual void endChunk ();
00088   virtual void startData (bool verbose);
00089   virtual void startDry (bool verbose);
00090   virtual IterMode iterTime (uInt it);
00091   virtual IterMode iterDry  (uInt it);
00092   virtual IterMode endData  ();
00093   virtual IterMode endDry   ();
00094 
00095   virtual String getDesc ();
00096   static const RecordInterface & getDefaults ();
00097 
00098 protected:
00099   static Bool dummy_Bool;
00100 
00101 // prepares for a pass over one data row
00102   void startDataRow (uInt ifr);
00103 // updates the diff lattice with a value, and performs clipping
00104   Float setDiff (uInt ich,uInt ifr,Float d,Bool &flagged = dummy_Bool );
00105 // ends pass over single data row  
00106   void endDataRow   (uInt ifr);
00107   
00108 // updates noise estimates (sih0), returns the max change
00109   Float updateSigma ();     
00110   
00111 // computes a correlations mask. Called once for each chunk (since correlations
00112 // can change from chunk to chunk)
00113   virtual RFlagWord newCorrMask () =0;
00114 
00115   Double clip_level;      // clipping level, in AADs
00116   Double row_clip_level;  // clipping level for rows (based on noise estimates), <0 for disable
00117   Bool   disable_row_clip; // flag: row clipping _disabled_ globally
00118   Bool   clipping_rows;    // flag: row clipping active for this chunk
00119   
00120   RFFloatLattice diff;   // (Nchan,Nifr,Nt) cube of deviations
00121   FlagCubeIterator *     pflagiter; // flag iterator used by setDiff()
00122   RFRowClipper          rowclipper;
00123   
00124   Vector<Float> diffrow;   // one row of deviations, for noise computations
00125   int idiffrow;
00126 
00127   Matrix<Float> sig;       // current noise estimate for (it,ifr)
00128   Matrix<Float> sig0;      // reference estimate (boxcar average from previous pass)
00129   LogicalVector sigupdated;
00130 };
00131 
00132 // <summary>
00133 // Abstract base class for deviation-based flagging with a data mapper.
00134 // </summary>
00135 
00136 // <use visibility=local>
00137 
00138 // <reviewed reviewer="" date="" tests="" demos="">
00139 // </reviewed>
00140 
00141 // <prerequisite>
00142 //   <li> RFDataMapper
00143 // </prerequisite>
00144 //
00145 // <synopsis>
00146 // This is another abstract class on top of DiffBase. It is also inherited from
00147 // RFDataMapper, so it includes functions for mapping visibilities to a single
00148 // Float value.
00149 // </synopsis>
00150 //
00151 // <todo asof="2001/04/16">
00152 //   <li> add this feature
00153 //   <li> fix this bug
00154 //   <li> start discussion of this possible extension
00155 // </todo>
00156 
00157 class RFADiffMapBase : public RFADiffBase, protected RFDataMapper
00158 {
00159 public:
00160   RFADiffMapBase  ( RFChunkStats &ch,const RecordInterface &parm );
00161   virtual ~RFADiffMapBase ();
00162 
00163   virtual IterMode iterTime (uInt it);
00164   
00165   virtual String getDesc ();
00166   
00167 // returns a Record of all available parameters and their default values
00168   static const RecordInterface & getDefaults ();
00169   
00170 protected:
00171   virtual RFlagWord newCorrMask () 
00172     { return RFDataMapper::corrMask(chunk.visIter()); } 
00173   
00174   void setupMapper () 
00175     { RFDataMapper::setVisBuffer(chunk.visBuf()); }
00176 };
00177 
00178 } //# NAMESPACE CASA - END
00179 
00180 #endif