casa
$Rev:20696$
|
00001 //# StatWT.h: Sets WEIGHT and SIGMA for a VisBuffGroup according to the scatter 00002 //# of its visibilities. 00003 //# Copyright (C) 2011 00004 //# Associated Universities, Inc. Washington DC, USA. 00005 //# 00006 //# This library is free software; you can redistribute it and/or modify it 00007 //# under the terms of the GNU Library General Public License as published by 00008 //# the Free Software Foundation; either version 2 of the License, or (at your 00009 //# option) any later version. 00010 //# 00011 //# This library is distributed in the hope that it will be useful, but WITHOUT 00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00013 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00014 //# License for more details. 00015 //# 00016 //# You should have received a copy of the GNU Library General Public License 00017 //# along with this library; if not, write to the Free Software Foundation, 00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00019 //# 00020 //# Correspondence concerning AIPS++ should be addressed as follows: 00021 //# Internet email: aips2-request@nrao.edu. 00022 //# Postal address: AIPS++ Project Office 00023 //# National Radio Astronomy Observatory 00024 //# 520 Edgemont Road 00025 //# Charlottesville, VA 22903-2475 USA 00026 //# 00027 00028 #ifndef MSVIS_STATWT_H 00029 #define MSVIS_STATWT_H 00030 00031 #include <casa/aips.h> 00032 #include <ms/MeasurementSets/MeasurementSet.h> 00033 #include <synthesis/MSVis/GroupWorker.h> 00034 #include <synthesis/MSVis/VisibilityIterator.h> 00035 #include <synthesis/MSVis/VisBufferComponents.h> 00036 #include <map> 00037 #include <set> 00038 00039 namespace casa { //# NAMESPACE CASA - BEGIN 00040 00041 //# forward decl 00042 class VisBuffGroup; 00043 00044 //<summary>StatWT sets WEIGHT and SIGMA statistically</summary> 00045 // 00046 // <use visibility=export> 00047 // 00048 // <reviewed reviewer="" date="" tests="" demos=""> 00049 00050 // <prerequisite> 00051 // <li> <linkto class="VisBuffGroup">VisBuffGroup</linkto> 00052 // <li> <linkto class="VisibilityIterator">VisibilityIterator</linkto> 00053 // <li> <linkto class="GroupProcessor">GroupProcessor</linkto> 00054 // <li> <linkto class="GroupWorker">GroupWorker</linkto> 00055 // </prerequisite> 00056 // 00057 // <etymology> 00058 // StatWT sets WEIGHT and SIGMA statistically. 00059 // </etymology> 00060 // 00061 //<synopsis> 00062 // Set the weights and sigmas according to the scatter of the 00063 // visibilities. 00064 //</synopsis> 00065 // 00066 //<todo> 00067 // <li> 00068 //</todo> 00069 class StatWT : public GroupWorker 00070 { 00071 public: 00072 // Construct an object that will set the weights and sigmas of vi's 00073 // MeasurementSet, as selected by outspw, according to the scatter of the 00074 // visibilities selected by fitspw. If dorms is true, assume that the true 00075 // mean is 0. Otherwise, use the standard sample variance. 00076 // 00077 // For each baseline and correlation, if fitspw does not select at least 00078 // minsamp unflagged visibilities, it will be flagged and weight and sigma 00079 // will not be calculated. minsamp is effectively at least 2. 00080 // 00081 StatWT(const ROVisibilityIterator& vi, 00082 const MS::PredefinedColumns datacol=MS::DATA, 00083 const String& fitspw="*", 00084 const String& outspw="*", 00085 const Bool dorms=false, 00086 const uInt minsamp=2, 00087 const vector<uInt> selcorrs=vector<uInt>()); 00088 00090 //StatWT(const StatWT& other) {} 00091 00092 // Destructor 00093 virtual ~StatWT(); 00094 00096 //virtual StatWT& operator=(const StatWT& gw) {} 00097 00098 // // Returns which columns need to be prefetched for process to work. 00099 // virtual asyncio::PrefetchColumns *prefetchColumns() const; 00100 00101 // This is where all the work gets done! 00102 virtual Bool process(VisBuffGroup& vbg); 00103 00104 private: 00105 // Disable null c'tor. 00106 StatWT(); 00107 00108 Bool update_variances(std::map<uInt, Vector<uInt> >& ns, 00109 std::map<uInt, Vector<Complex> >& means, 00110 std::map<uInt, Vector<Double> >& variances, 00111 const VisBuffer& vb, 00112 const Cube<Bool>& chanmaskedflags, const uInt maxAnt); 00113 00114 // ns and variances are effectively const here, but declaring them that way 00115 // would take some gymnastics. 00116 Bool apply_variances(VisBuffer& vb, 00117 std::map<uInt, Vector<uInt> >& ns, 00118 std::map<uInt, Vector<Double> >& variances, 00119 const uInt maxAnt); 00120 00121 // Compute a baseline (row) index (ant1, ant2). 00122 // It ASSUMES that ant1 and ant2 are both <= maxAnt. 00123 uInt hashFunction(const Int ant1, const Int ant2, const Int maxAnt) 00124 { 00125 return (maxAnt + 1) * ant1 - (ant1 * (ant1 - 1)) / 2 + ant2 - ant1; 00126 } 00127 00128 // Initialized by c'tor: 00129 00130 // Which of DATA, MODEL_DATA, or CORRECTED_DATA to fit. 00131 // It will always _write_ to DATA if datacols_p.nelements() == 1, and write 00132 // to all 3 otherwise. Thus datacols_p.nelements() should be either 1 or 3. 00133 // 4 and 2 are right out, and FLOAT_DATA isn't handled by this yet. 00134 MS::PredefinedColumns datacol_p; 00135 00136 String fitspw_p; // Line-free channels used for the fit. Can include ; 00137 String outspw_p; // Channels to write out. Does not yet support ;. 00138 Bool dorms_p; // If true, assume that the true mean is 0. 00139 uInt rowsdone_p; // How many rows have been written so far. 00140 std::set<Int> outspws_p; // Spws to reweight. 00141 // Otherwise, use the standard sample variance. 00142 uInt minsamp_p; // Minimum # of unflagged visibilities for calculating 00143 // a variance. 00144 vector<uInt> selcorrs_p; 00145 // Not initialized by c'tor: 00146 //std::set<Int> appliedSpWs_p; 00147 std::map<Int, Vector<Bool>*> fitmask_p; // spw -> a list of flags by chan 00148 }; 00149 00150 } //# NAMESPACE CASA - END 00151 00152 #endif 00153