casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
FlagAgentRFlag.h
Go to the documentation of this file.
00001 //# FlagAgentRFlag.h: This file contains the interface definition of the FlagAgentRFlag class.
00002 //#
00003 //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
00004 //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2012, All rights reserved.
00005 //#  Copyright (C) European Southern Observatory, 2012, 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 FlagAgentRFlag_H_
00024 #define FlagAgentRFlag_H_
00025 
00026 #include <flagging/Flagging/FlagAgentBase.h>
00027 #include <casa/Utilities/DataType.h>
00028 
00029 namespace casa { //# NAMESPACE CASA - BEGIN
00030 
00031 class FlagAgentRFlag : public FlagAgentBase {
00032 
00033         enum optype {
00034 
00035                 MEAN,
00036                 ROBUST_MEAN,
00037                 MEDIAN,
00038                 ROBUST_MEDIAN
00039         };
00040 
00041 public:
00042 
00043         FlagAgentRFlag(FlagDataHandler *dh, Record config, Bool writePrivateFlagCube = false, Bool flag = true);
00044         ~FlagAgentRFlag();
00045 
00046 protected:
00047 
00048         // Parse configuration parameters
00049         void setAgentParameters(Record config);
00050 
00051         // Compute flags for a given (time,freq) map
00052         bool computeAntennaPairFlags(const vi::VisBuffer2 &visBuffer, VisMapper &visibilities,FlagMapper &flags,Int antenna1,Int antenna2,vector<uInt> &rows);
00053 
00054         // Extract automatically computed thresholds to use them in the next pass
00055         void passIntermediate(const vi::VisBuffer2 &visBuffer);
00056 
00057         // Remove automatically computed thresholds for the following scans
00058         void passFinal(const vi::VisBuffer2 &visBuffer);
00059 
00060         // Convenience function to get simple averages
00061         Double mean(vector<Double> &data,vector<Double> &counts);
00062 
00063         // Convenience function to compute median
00064         Double median(vector<Double> &data);
00065 
00066         //
00067         void noiseVsRef(vector<Double> &data, Double ref);
00068 
00069         // Convenience function to get simple averages
00070         Double computeThreshold(vector<Double> &data, vector<Double> &dataSquared, vector<Double> &counts);
00071 
00072         // Function to be called for each timestep/channel
00073         void computeAntennaPairFlagsCore(       pair<Int,Int> spw_field,
00074                                                                                 Double noise,
00075                                                                                 Double scutof,
00076                                                                                 uInt timeStart,
00077                                                                                 uInt timeStop,
00078                                                                                 uInt centralTime,
00079                                                                                 VisMapper &visibilities,
00080                                                                                 FlagMapper &flags);
00081 
00082         void robustMean(        uInt timestep_i,
00083                                                 uInt pol_k,
00084                                                 uInt nChannels,
00085                                                 Double &AverageReal,
00086                                                 Double &AverageImag,
00087                                                 Double &StdReal,
00088                                                 Double &StdImag,
00089                                                 Double &SumWeightReal,
00090                                                 Double &SumWeightImag,
00091                                                 VisMapper &visibilities,
00092                                                 FlagMapper &flags);
00093 
00094         void simpleMedian(      uInt timestep_i,
00095                                                 uInt pol_k,
00096                                                 uInt nChannels,
00097                                                 Double &AverageReal,
00098                                                 Double &AverageImag,
00099                                                 Double &StdReal,
00100                                                 Double &StdImag,
00101                                                 Double &SumWeightReal,
00102                                                 Double &SumWeightImag,
00103                                                 VisMapper &visibilities,
00104                                                 FlagMapper &flags);
00105 
00106         // Function to return histograms
00107         FlagReport getReport();
00108 
00109         // Function to return histograms
00110         FlagReport getReportCore(       map< pair<Int,Int>,vector<Double> > &data,
00111                                                                 map< pair<Int,Int>,vector<Double> > &dataSquared,
00112                                                                 map< pair<Int,Int>,vector<Double> > &counts,
00113                                                                 map< pair<Int,Int>,Double > &threshold,
00114                                                                 FlagReport &totalReport,
00115                                                                 string label,
00116                                                                 Double scale);
00117 
00118 private:
00119 
00120         // General parameters
00121         Bool doflag_p;
00122         Bool doplot_p;
00123         uInt nTimeSteps_p;
00124         Double noiseScale_p;
00125         Double scutofScale_p;
00126 
00127         // Spectral Robust fit
00128         uInt nIterationsRobust_p;
00129         vector<Double> thresholdRobust_p;
00130         Double spectralmin_p;
00131         Double spectralmax_p;
00132         uInt optype_p;
00133         void (casa::FlagAgentRFlag::*spectralAnalysis_p)(uInt,uInt,uInt,Double&,Double&,Double&,Double&,Double&,Double&,VisMapper&,FlagMapper&);
00134 
00135         // Store frequency to be used in Reports
00136         map< pair<Int,Int>,vector<Double> > field_spw_frequency_p;
00137         map< pair<Int,Int>,Double > field_spw_frequencies_p;
00138 
00139         // Time-direction analysis
00140         Double noise_p;
00141         map< pair<Int,Int>,Double > field_spw_noise_map_p;
00142         map< pair<Int,Int>,Bool > user_field_spw_noise_map_p;
00143         map< pair<Int,Int>,vector<Double> > field_spw_noise_histogram_sum_p;
00144         map< pair<Int,Int>,vector<Double> > field_spw_noise_histogram_sum_squares_p;
00145         map< pair<Int,Int>,vector<Double> > field_spw_noise_histogram_counts_p;
00146 
00147         // Spectral analysis
00148         Double scutof_p;
00149         map< pair<Int,Int>,Double > field_spw_scutof_map_p;
00150         map< pair<Int,Int>,Bool > user_field_spw_scutof_map_p;
00151         map< pair<Int,Int>,vector<Double> > field_spw_scutof_histogram_sum_p;
00152         map< pair<Int,Int>,vector<Double> > field_spw_scutof_histogram_sum_squares_p;
00153         map< pair<Int,Int>,vector<Double> > field_spw_scutof_histogram_counts_p;
00154 };
00155 
00156 
00157 } //# NAMESPACE CASA - END
00158 
00159 #endif /* FlagAgentRFlag_H_ */
00160