casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FlagAgentTimeFreqCrop.h
Go to the documentation of this file.
00001 //# FlagAgentTimeFreqCrop.h: This file contains the interface definition of the FlagAgentTimeFreqCrop class.
00002 //#
00003 //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
00004 //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
00005 //#  Copyright (C) European Southern Observatory, 2011, All rights reserved.
00006 //#
00007 //#  This library is free software; you can redistribute it and/or
00008 //#  modify it under the terms of the GNU Lesser General Public
00009 //#  License as published by the Free software Foundation; either
00010 //#  version 2.1 of the License, or (at your option) any later version.
00011 //#
00012 //#  This library is distributed in the hope that it will be useful,
00013 //#  but WITHOUT ANY WARRANTY, without even the implied warranty of
00014 //#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015 //#  Lesser General Public License for more details.
00016 //#
00017 //#  You should have received a copy of the GNU Lesser General Public
00018 //#  License along with this library; if not, write to the Free Software
00019 //#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00020 //#  MA 02111-1307  USA
00021 //# $Id: $
00022 
00023 #ifndef FlagAgentTimeFreqCrop_H_
00024 #define FlagAgentTimeFreqCrop_H_
00025 
00026 #include <flagging/Flagging/FlagAgentBase.h>
00027 
00028 namespace casa { //# NAMESPACE CASA - BEGIN
00029 
00030 class FlagAgentTimeFreqCrop : public FlagAgentBase {
00031 
00032 public:
00033 
00034         FlagAgentTimeFreqCrop(FlagDataHandler *dh, Record config, Bool writePrivateFlagCube = false, Bool flag = true);
00035         ~FlagAgentTimeFreqCrop();
00036 
00037 protected:
00038 
00039         // Compute flags for a given (time,freq) map
00040         bool computeAntennaPairFlags(const vi::VisBuffer2 &visBuffer, VisMapper &visibilities,FlagMapper &flags,Int antenna1,Int antenna2,vector<uInt> &rows);
00041 
00042         // Parse configuration parameters
00043         void setAgentParameters(Record config);
00044 
00045 private:
00046 
00048 
00049   // Flag threshold in time.
00050   // (flag all data-points further than N-stddev from the fit).
00051   Double time_cutoff_p;
00052   // Flag threshold in frequency.
00053   // (flag all data-points further than N-stddev from the fit).
00054   Double freq_cutoff_p;
00055   // Maximum number of pieces to allow in the piecewise-polynomial fits (1-9)
00056   Int maxNPieces_p;
00057   // Fitting function for the time direction  ('line' or 'poly')
00058   String timeFitType_p;
00059   // Fitting function for the frequency direction  ('line' or 'poly')
00060   String freqFitType_p;
00061   // Choose the directions along which to perform flagging
00062   // ('time', 'freq', 'timefreq', 'freqtime')
00063   String flagDimension_p;
00064   // Half width of sliding window to use with 'usewindowstats' 
00065   // (1,2,3 for 3-point, 5-point or 7-point window sizes)
00066   Int halfWin_p;
00067   // Use sliding-window statistics to find additional flags
00068   // ('none', 'sum', 'std', 'both' )
00069   String winStats_p;
00070   // Read original flags or not. 
00071   // Note : original flags are those in the MS (and not those generated by agents)
00072   // True/False 
00073   //  Bool usePreFlags_p;
00074   
00075   
00077   
00078   // Average the data, fit a piecewise polynomial, divide it out, flag outliers.
00079   void fitBaseAndFlag(String fittype, String direction, VisMapper &visibilities,FlagMapper &flags);
00080   
00081   // Calculate Mean, Variance, Stddev while accounting for flags
00082   Float calcMean(Vector<Float> &vect, Vector<Bool> &flag);
00083   Float calcVar(Vector<Float> &vect, Vector<Bool> &flag, Vector<Float> &fit);
00084   Float calcStd(Vector<Float> &vect, Vector<Bool> &flag, Vector<Float> &fit);
00085   Float calcStd(Vector<Float> &vect, Vector<Bool> &flag, Float mean);
00086   
00087   // Fit a piece-wise polynomial according to the supplied specs
00088   void fitPiecewisePoly(Vector<Float> &data,Vector<Bool> &flag, Vector<Float> &fit, uInt maxnpieces, uInt maxdeg);
00089   
00090   // Fit a polynomial of specified degree to a range of data points
00091   void polyFit(Vector<Float> &data,Vector<Bool> &flag, Vector<Float> &fit, uInt lim1, uInt lim2,uInt deg);
00092   
00093   // Fit a line to a range of data points
00094   void lineFit(Vector<Float> &data,Vector<Bool> &flag, Vector<Float> &fit, uInt lim1, uInt lim2);
00095   
00096 
00097 
00098 };
00099 
00100 
00101 } //# NAMESPACE CASA - END
00102 
00103 #endif /* FlagAgentTimeFreqCrop_H_ */
00104