00001 //# SolveDataBuffer.h: A container for data and residuals for solving 00002 //# Copyright (C) 2008 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: VisBuffer.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $ 00027 00028 #ifndef SYNTHESIS_SOLVEDATABUFFER_H 00029 #define SYNTHESIS_SOLVEDATABUFFER_H 00030 00031 #include <casa/aips.h> 00032 #include <msvis/MSVis/VisBuffer2.h> 00033 #include <casa/Arrays/Array.h> 00034 #include <casa/Arrays/Cube.h> 00035 #include <casa/Arrays/Matrix.h> 00036 namespace casa { //# NAMESPACE CASA - BEGIN 00037 00038 //#forward 00039 00040 //<summary>SolveDataBuffer is a container for VisBuffer2 data and related residual and differentiation results related to generic calibration solving </summary> 00041 // 00042 // <use visibility=export> 00043 // 00044 // <reviewed reviewer="" date="" tests="" demos=""> 00045 00046 // <prerequisite> 00047 // <li> <linkto class="VisBuffer">VisBuffer</linkto> 00048 // </prerequisite> 00049 // 00050 // <etymology> 00051 // SolveDataBuffer is a Buffer for Solving Data 00052 // </etymology> 00053 // 00054 //<synopsis> 00055 // 00056 // 00057 //</synopsis> 00058 00059 //<todo> 00060 // <li> write todo list 00061 //</todo> 00062 00063 00064 00065 class SolveDataBuffer 00066 { 00067 public: 00068 // Generic ctor 00069 SolveDataBuffer(); 00070 00071 // Create from a VisBuffer2 00072 SolveDataBuffer(const vi::VisBuffer2& vb); 00073 00074 // Copy construct 00075 // current iteration (or reattach). 00076 SolveDataBuffer(const SolveDataBuffer& sdb); 00077 00078 // Destructor 00079 ~SolveDataBuffer(); 00080 00081 // Assignment 00082 SolveDataBuffer& operator=(const SolveDataBuffer& sdb); 00083 00084 // Does SDB contain finite weight? 00085 Bool Ok(); 00086 00087 // Apply amp-only or phase-only to data 00088 void enforceAPonData(const String& apmode); 00089 00090 // Zero flagged weights, and optionally the cross-hand weights 00091 void enforceSolveWeights(const Bool pHandOnly); 00092 00093 // Set the focus channel 00094 // (forms references to focus-channel flag/data/model) 00095 void setFocusChan(const Int focusChan=-1); 00096 00097 // Size/init/finalize the residuals workspaces 00098 void sizeResiduals(const Int& nPar,const Int& nDiff); 00099 void initResidWithModel(); 00100 void finalizeResiduals(); 00101 00102 // Delete the workspaces 00103 void cleanUp(); 00104 00105 00106 // VB2-like data access methods (mostly const) 00107 Int nRows() const { return vb_->nRows(); }; 00108 const Vector<Int>& observationId() const { return vb_->observationId(); }; 00109 const Vector<Int>& arrayId() const { return vb_->arrayId(); }; 00110 const Vector<Int>& antenna1() const { return vb_->antenna1(); }; 00111 const Vector<Int>& antenna2() const { return vb_->antenna2(); }; 00112 const Vector<Int>& dataDescriptionIds() const { return vb_->dataDescriptionIds(); }; 00113 const Vector<Int>& spectralWindow() const { return vb_->spectralWindows(); }; 00114 const Vector<Int>& scan() const { return vb_->scan(); }; 00115 const Vector<Double>& time() const { return vb_->time(); }; 00116 const Vector<Int>& fieldId() const { return vb_->fieldId(); }; 00117 const Vector<Double>& freqs() const { return freqs_; }; 00118 Int nChannels() const { return vb_->nChannels(); }; 00119 Int nCorrelations() const { return vb_->nCorrelations(); }; 00120 const Cube<Complex>& visCubeModel() const { return vb_->visCubeModel(); }; 00121 const Cube<Complex>& visCubeCorrected() const { return vb_->visCubeCorrected(); }; 00122 // These are not const, because we will generally amend them: 00123 Vector<Bool>& flagRow() {fR_.reference(vb_->flagRow());return fR_;}; 00124 Cube<Bool>& flagCube() {fC_.reference(vb_->flagCube());return fC_;}; 00125 Cube<Float>& weightSpectrum() {wS_.reference(vb_->weightSpectrum());return wS_;}; 00126 00127 // <group> 00128 00129 // Access functions 00130 // 00131 // Access to focus-channel slices of the flags, data, and model 00132 Cube<Bool>& infocusFlagCube() { return infocusFlagCube_p; } 00133 const Cube<Bool>& infocusFlagCube() const {return this->infocusFlagCube();} 00134 00135 Cube<Complex>& infocusVisCube() { return infocusVisCube_p; } 00136 const Cube<Complex>& infocusVisCube() const {return this->infocusVisCube();} 00137 00138 Cube<Float>& infocusWtSpec() { return infocusWtSpec_p; } 00139 const Cube<Float>& infocusWtSpec() const {return this->infocusWtSpec();} 00140 00141 Cube<Complex>& infocusModelVisCube() { return infocusModelVisCube_p; } 00142 const Cube<Complex>& infocusModelVisCube() const {return this->infocusModelVisCube();} 00143 00144 // Workspace for the residual visibilities 00145 Cube<Complex>& residuals() { return residuals_p; } 00146 const Cube<Complex>& residuals() const {return this->residuals();} 00147 00148 // Workspace for flags of the residuals 00149 Cube<Bool>& residFlagCube() { return residFlagCube_p; } 00150 const Cube<Bool>& residFlagCube() const {return this->residFlagCube();} 00151 00152 // Workspace for the differentiated residuals 00153 Array<Complex>& diffResiduals() { return diffResiduals_p; } 00154 const Array<Complex>& diffResiduals() const {return this->diffResiduals();} 00155 00156 //</group> 00157 00158 protected: 00159 00160 // Handle copy from the input VB2 00161 void initFromVB(const vi::VisBuffer2& vb); 00162 00163 00164 private: 00165 00166 // The underlying VisBuffer2 00167 vi::VisBuffer2* vb_; 00168 00169 // The frequencies 00170 // Currently, assumed uniform over rows 00171 Vector<Double> freqs_; 00172 00173 // Array reference objects for things in the vb we need to mess with 00174 Vector<Bool> fR_; 00175 Cube<Bool> fC_; 00176 Cube<Float> wS_; 00177 00178 // The current in-focus channel 00179 Int focusChan_p; 00180 00181 // actual storage for the data 00182 Cube<Bool> infocusFlagCube_p; 00183 Cube<Float> infocusWtSpec_p; 00184 Cube<Complex> infocusVisCube_p; 00185 Cube<Complex> infocusModelVisCube_p; 00186 00187 Cube<Complex> residuals_p; 00188 Cube<Bool> residFlagCube_p; 00189 Array<Complex> diffResiduals_p; 00190 }; 00191 00192 00193 class SDBList 00194 { 00195 public: 00196 00197 // Construct empty list 00198 SDBList(); 00199 00200 // Destructor 00201 ~SDBList(); 00202 00203 // How many SDBs? 00204 Int nSDB() const { return nSDB_; }; 00205 00206 // Generate a new SDB from an input VB2 00207 void add(const vi::VisBuffer2& vb); 00208 00209 // Access an SDB by index 00210 SolveDataBuffer& operator()(Int i); 00211 00212 // Aggregate meta info 00213 Int aggregateObsId() const; 00214 Int aggregateScan() const; 00215 Int aggregateSpw() const; 00216 Int aggregateFld() const; 00217 Double aggregateTime() const; 00218 00219 // How many data chans? 00220 // Currently, this insists on uniformity over all SDBs 00221 Int nChannels() const; 00222 00223 // The frequencies 00224 // Currently, this insists on uniformity over all SDBs 00225 const Vector<Double>& freqs() const; 00226 00227 // Does the SDBList contain usable data? 00228 // (at least one SDB, with non-zero net weight) 00229 Bool Ok(); 00230 00231 // Aggregated methods 00232 void enforceAPonData(const String& apmode); 00233 void enforceSolveWeights(const Bool pHandOnly); 00234 void sizeResiduals(const Int& nPar, const Int& nDiff); 00235 void initResidWithModel(); 00236 void finalizeResiduals(); 00237 00238 private: 00239 00240 // How many SDBs contained herein 00241 Int nSDB_; 00242 00243 // Keep SDBs as a list of pointers 00244 PtrBlock<SolveDataBuffer*> SDB_; 00245 00246 }; 00247 00248 00249 00250 } //# NAMESPACE CASA - END 00251 00252 #endif 00253