casa
$Rev:20696$
|
00001 //# VisBuffer.h: buffer for iterating through MS in large blocks 00002 //# Copyright (C) 1996,1997,1998,1999,2000,2002,2003 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 VISBUFFER_ASYNC_WRAPPER_H 00029 #define VISBUFFER_ASYNC_WRAPPER_H 00030 00031 #include <casa/aips.h> 00032 #include <casa/Arrays/Cube.h> 00033 #include <casa/Arrays/Vector.h> 00034 #include <casa/Arrays/Matrix.h> 00035 #include <casa/BasicSL/Complex.h> 00036 #include <synthesis/MSVis/VisBuffer2.h> 00037 00038 namespace casa { //# NAMESPACE CASA - BEGIN 00039 00040 namespace vi { 00041 00042 //#forward 00043 00044 //<summary>VisBuffers encapulsate one chunk of visibility data for processing.</summary> 00045 // 00046 // <use visibility=export> 00047 // 00048 // <reviewed reviewer="" date="" tests="" demos=""> 00049 00050 // <prerequisite> 00051 // <li> <linkto class="VisSet">VisSet</linkto> 00052 // <li> <linkto class="VisibilityIterator">VisibilityIterator</linkto> 00053 // </prerequisite> 00054 // 00055 // <etymology> 00056 // VisBuffer is a buffer for visibility data 00057 // </etymology> 00058 // 00059 //<synopsis> 00060 // This class contains 'one iteration' of the 00061 // <linkto class="VisibilityIterator">VisibilityIterator</linkto> 00062 // It is a modifiable 00063 // buffer of values to which calibration and averaging can be applied. 00064 // This allows processing of the data in larger blocks, avoiding some 00065 // overheads for processing per visibility point or spectrum. 00066 // 00067 // See <linkto module="MeasurementEquations">MeasurementEquations</linkto> 00068 // for more details on how the VisBuffer is to be used. 00069 //</synopsis> 00070 00071 //<todo> 00072 // <li> reconcile vis/visCube usage: visCube, flagCube and weightMatrix 00073 // are currently only correct when this VisBuffer got them from a 00074 // VisIter, operations like -=, freqAverage() are only done for 00075 // visibility() and flag(). 00076 //</todo> 00077 class VisBufferWrapperAsync2 : public VisBuffer2 { 00078 00079 friend class ViReadImplAsync; 00080 00081 public: 00082 00083 // Destructor (detaches from VisIter) 00084 00085 virtual ~VisBufferWrapperAsync2(); 00086 00087 00088 //--------------------------------------------------------------------- 00089 // 00090 // Copying methods 00091 // 00092 // These methods allow copying portions of the data between two 00093 // VisBuffers. Because of the complicated semantics of a VisBuffer the 00094 // assignment and copy-construction methods are not used as they are likely 00095 // to confuse VisBuffer users. 00096 00097 00098 // Copies all of the components from the specified VisBuffer into this one. 00099 // Uncached values will be cleared in this VB. 00100 00101 virtual void copy (const VisBuffer2 & other, Bool fetchIfNeeded); 00102 00103 // Copies the specified components (or just the one in the cache) from 00104 // the specified VisBuffer into this one. 00105 00106 virtual void copyComponents (const VisBuffer2 & other, 00107 const VisBufferComponents2 & components, 00108 Bool fetchIfNeeded = True); 00109 00110 // Copies the coordinate components from the specified VisBuffer into this one. 00111 // Depending on includeDirections the direction related ones are copied or not. 00112 00113 virtual void copyCoordinateInfo(const VisBuffer2 * other, Bool includeDirections, 00114 Bool fetchIfNeeded = True); 00115 00116 virtual void setShape (Int nCorrelations, Int nChannels, Int nRows); 00117 00118 // For attached VBs this returns the VI the VB is attached to. For free 00119 // VBs this method returns False. 00120 00121 virtual const VisibilityIterator2 * getVi () const; 00122 00123 virtual Bool isAttached () const; 00124 virtual Bool isFillable () const; 00125 00126 //--------------------------------------------------------------------- 00127 // 00128 // Dirty component methods 00129 // 00130 // The dirtyComponent methods support the data-flow approach to using 00131 // VisBuffers (the Visibility Processing Framework). In this approach 00132 // a VisBuffer is passed to successive processing nodes (e.g., applycal, 00133 // flagging, etc.) which operate on it and pass it on to the next node 00134 // in the algorithm. The dirtyComponents mechanism allows a processing 00135 // node to mark portions of the VisBuffer as modified. If the VisBuffer 00136 // reaches an write-to-disk node then the modified portions of the 00137 // VisBuffer will be written out. The user can also explicitly direct 00138 // that the changes be written out using the writeChangesBack method. 00139 // 00140 // Using a setter on a VisBuffer component will also set the dirty flag for 00141 // that component. Normally the user should not need to use these methods; 00142 // however, they are available in case unexpected situations should arise 00143 // in the future. 00144 00145 virtual void writeChangesBack (); 00146 00147 virtual void dirtyComponentsAdd (const VisBufferComponents2 & additionalDirtyComponents); 00148 virtual void dirtyComponentsAdd (VisBufferComponent2 component); 00149 virtual void dirtyComponentsClear (); 00150 virtual VisBufferComponents2 dirtyComponentsGet () const; 00151 virtual void dirtyComponentsSet (const VisBufferComponents2 & dirtyComponents); 00152 virtual void dirtyComponentsSet (VisBufferComponent2 component); 00153 00154 // This method returns the imaging weights associated with the VisBuffer. 00155 // If an imaging weight generator has not been supplied to the associated 00156 // VisibilityIterator then this method will throw an exception. 00157 00158 virtual const Matrix<Float> & imagingWeight() const; 00159 00160 //--------------------------------------------------------------------------- 00161 // 00162 // Frequency reporting methods. 00163 // 00164 // These methods provide information about the frequencies returned in the 00165 // visibility cubes. The information can returned as the channel numbers 00166 // (numbered as in the underlying MS data) or in a frame-based frequency. 00167 // This information reported need not be in the same frame of reference 00168 // used to select the data. If the frame of reference is specified in the 00169 // call, then that is the frame that is used to calculate the frequencies. 00170 // If it is not specified, then the VisibilityIterator will be queried for 00171 // virtual the reportingFrame; if the user has specified a reporting frame to the 00172 // virtual VI then that frame will be used; otherwise the frame used to select 00173 // the frequencies will be used. If the user provides no frequency selection 00174 // to the VI then the selection frame will TOPO. 00175 // 00176 // Both the channelNumber and frequency reporting methods come in two versions: 00177 // one returns a single frequency for the specified frequency index and row 00178 // while the other provides all of the frequencies for the specified row. 00179 // The frequency index is the zero-based index along the frequency axis of 00180 // a visibility cube. 00181 00182 virtual Double getFrequency (Int rowInBuffer, Int frequencyIndex, 00183 Int frame = FrameNotSpecified) const; 00184 virtual const Vector<Double> & getFrequencies (Int rowInBuffer, 00185 Int frame = FrameNotSpecified) const; 00186 virtual Int getChannelNumber (Int rowInBuffer, Int frequencyIndex) const; 00187 virtual const Vector<Int> & getChannelNumbers (Int rowInBuffer) const; 00188 00189 // Sort/unsort the correlations, if necessary 00190 // (Rudimentary handling of non-canonically sorted correlations--use with care!) 00191 // 00192 // The sorting functionality is a horrible kluge that puts the VisBuffer into a 00193 // somewhat incoherent state (e.g., after sorting the correlation types array 00194 // does not correspond to the data) and appears to serve the needs 00195 // of a tiny piece of code. As such, this refactor is initially not going to 00196 // support this functionality since it is probably better implemented in the one 00197 // place that actually needs it. (jjacobs 10/3/12) 00198 // 00199 //virtual void sortCorr (); 00200 //virtual void unSortCorr(); 00201 00202 // Normalize the visCube by the modelVisCube. 00203 00204 virtual void normalize(); 00205 00206 // Set the weight cube using the sigma cube. Each weight will be 00207 // the reciprocal of the square of the corresponding element in the model 00208 // VisCube multiplied by the number of channels in the spectral window. 00209 // If an element in sigma is zero then the corresponding weight element 00210 // will also be set to zero. 00211 00212 virtual void resetWeightsUsingSigma ();//void resetWeightMat(); 00213 00214 //---------------------------------------------------------------------- 00215 // 00216 // Subhchunk information methods 00217 // 00218 // These methods provide information related to the current subchunk. 00219 // The isNewXXX methods return True if the XXX property of the subchunk 00220 // differs from the previous subchunk. 00221 // 00222 // The methods msId and msName provide information about the MS 00223 // related to the current subchunk. The msID is the zero-based index 00224 // of the MS in the sequence of MSs being iterated over. 00225 // 00226 // The isWritable method is True when the attached iterator is writable 00227 // and False otherwise. 00228 // 00229 // The isRekeyable method is True when the VisBuffer is writable and also 00230 // allows the modification of non-data fields (e.g., antenna1, fieldId, etc.) 00231 // A rekeyable VB is one that could be used to create data for a brand new 00232 // MS. 00233 00234 virtual Bool isNewArrayId () const; 00235 virtual Bool isNewFieldId () const; 00236 virtual Bool isNewMs() const; 00237 virtual Bool isNewSpectralWindow () const; 00238 virtual Bool isWritable () const; 00239 virtual Int msId() const; 00240 virtual String msName (Bool stripPath = False) const; 00241 virtual Subchunk getSubchunk () const; 00242 00244 // 00245 // Data accessors and setters (where appropriate) 00246 // 00247 // There are the methods that allows access to the items cached in the 00248 // VisBuffer. The straight accessors provide read-only access to the 00249 // item. Where the item is allowed to be modified, one or more set 00250 // methods are provided. 00251 // 00252 // The dimensionality of the major object in in accessor/setter is 00253 // shown in a trailing comment using the following abbreviations: 00254 // 00255 // nA :== number of antennas 00256 // nF :== number of frequencies (or channels) 00257 // nC :== number of correlations 00258 // nR :== number of table rows contained in the buffer 00259 00260 //-------------------------------------------------------- 00261 // 00262 // Accessors for data contained in the main MeasurementSet main table 00263 // The actual visibility data are at the end. 00264 // 00265 // *** N.B.: the VB usually caches the information 00266 // in the representation requested so that using a setter to modify 00267 // one value type (e.g., weight or visibility) will not modify the 00268 // cached value in a different representation (e.g., weightMat or 00269 // visCube). This should not be a problem in normal usage. 00270 00271 virtual const Vector<Int> & antenna1 () const = 0; // [nR] 00272 virtual void setAntenna1 (const Vector<Int> & value) = 0; // [nR] 00273 virtual const Vector<Int> & antenna2 () const = 0; // [nR] 00274 virtual void setAntenna2 (const Vector<Int> & value) = 0; // [nR] 00275 virtual const Vector<Int>& arrayId () const = 0; 00276 virtual void setArrayId (const Vector<Int>&) = 0; 00277 virtual Int dataDescriptionId () const = 0; 00278 virtual void setDataDescriptionId (Int value) = 0; 00279 virtual const Vector<MDirection> & direction1 () const = 0; // [nR] 00280 virtual const Vector<MDirection> & direction2 () const = 0; // [nR] 00281 virtual const Vector<Double> & exposure () const = 0; // [nR] 00282 virtual void setExposure (const Vector<Double> & value) = 0; // [nR] 00283 virtual const Vector<Int> & feed1 () const = 0; // [nR] 00284 virtual void setFeed1 (const Vector<Int> & value) = 0; // [nR] 00285 virtual const Vector<Int> & feed2 () const = 0; // [nR] 00286 virtual void setFeed2 (const Vector<Int> & value) = 0; // [nR] 00287 virtual const Vector<Int>& fieldId () const = 0; 00288 virtual void setFieldId (const Vector<Int>&) = 0; 00289 virtual const Matrix<Bool> & flag () const = 0; // [nF,nR] 00290 virtual void setFlag (const Matrix<Bool>& value) = 0; // [nF,nR] 00291 virtual const Array<Bool> & flagCategory () const = 0; // [nC,nF,nCategories,nR] 00292 virtual void setFlagCategory (const Array<Bool>& value) = 0; // [nC,nF,nCategories,nR] 00293 virtual const Cube<Bool> & flagCube () const = 0; // [nC,nF,nR] 00294 virtual void setFlagCube (const Cube<Bool>& value) = 0; // [nC,nF,nR] 00295 virtual const Vector<Bool> & flagRow () const = 0; // [nR] 00296 virtual void setFlagRow (const Vector<Bool>& value) = 0; // [nR] 00297 virtual const Vector<Int> & observationId () const = 0; // [nR] 00298 virtual void setObservationId (const Vector<Int> & value) = 0; // [nR] 00299 virtual const Vector<Int> & processorId () const = 0; // [nR] 00300 virtual void setProcessorId (const Vector<Int> & value) = 0; // [nR] 00301 virtual const Vector<Int> & scan () const = 0; // [nR] 00302 virtual void setScan (const Vector<Int> & value) = 0; // [nR] 00303 virtual const Matrix<Float> & sigma () const = 0; // [nR] 00304 virtual void setSigma (const Matrix<Float> & value) = 0; // [nR] 00305 //virtual const Matrix<Float> & sigmaMat () const = 0; // [nC,nR] 00306 virtual const Vector<Int> & stateId () const = 0; // [nR] 00307 virtual void setStateId (const Vector<Int> & value) = 0; // [nR] 00308 virtual const Vector<Double> & time () const = 0; // [nR] 00309 virtual void setTime (const Vector<Double> & value) = 0; // [nR] 00310 virtual const Vector<Double> & timeCentroid () const = 0; // [nR] 00311 virtual void setTimeCentroid (const Vector<Double> & value) = 0; // [nR] 00312 virtual const Vector<Double> & timeInterval () const = 0; // [nR] 00313 virtual void setTimeInterval (const Vector<Double> & value) = 0; // [nR] 00314 virtual const Matrix<Double> & uvw () const = 0; // [3,nR] 00315 virtual void setUvw (const Matrix<Double> & value) = 0; // [3,nR] 00316 virtual const Matrix<Float> & weight () const = 0; // [nR] 00317 virtual void setWeight (const Matrix<Float>& value) = 0; // [nR] 00318 // virtual const Matrix<Float> & weightMat () const = 0; // [nC,nR] 00319 // virtual void setWeightMat (const Matrix<Float>& value) = 0; // [nC,nR] 00320 virtual const Cube<Float> & weightSpectrum () const = 0; // [nC,nF,nR] 00321 virtual void setWeightSpectrum (const Cube<Float>& value) = 0; // [nC,nF,nR] 00322 00323 // -------------------------------------------------------------- 00324 // Visibility data accessors in order of observed, corrected, 00325 // float, & model 00326 00327 virtual const Cube<Complex> & visCube () const; // [nC,nF,nR] 00328 virtual void setVisCube(const Complex & c); 00329 virtual void setVisCube (const Cube<Complex> &); // [nC,nF,nR] 00330 virtual const Matrix<CStokesVector> & vis () const; // [nF,nR] 00331 virtual void setVis (Matrix<CStokesVector> &); // [nF,nR] 00332 00333 virtual const Cube<Complex> & visCubeCorrected () const; // [nC,nF,nR] 00334 virtual void setVisCubeCorrected (const Cube<Complex> &); // [nC,nF,nR] 00335 virtual const Matrix<CStokesVector> & visCorrected () const; // [nF,nR] 00336 virtual void setVisCorrected (const Matrix<CStokesVector> &); // [nF,nR] 00337 00338 virtual const Cube<Float> & visCubeFloat () const; // [nC,nF,nR] 00339 virtual void setVisCubeFloat (const Cube<Float> &); // [nC,nF,nR] 00340 00341 virtual const Cube<Complex> & visCubeModel () const; // [nC,nF,nR] 00342 virtual void setVisCubeModel(const Complex & c); 00343 virtual void setVisCubeModel(const Cube<Complex>& vis); // [nC,nF,nR] 00344 virtual void setVisCubeModel(const Vector<Float>& stokes); // [1..4] 00345 virtual const Matrix<CStokesVector> & visModel () const; // [nF,nR] 00346 virtual void setVisModel (Matrix<CStokesVector> &); // [nF,nR] 00347 00348 //-------------------------------------------------------- 00349 // 00350 // Accessors for data derived from the MS main table data 00351 00352 // Returns the pointing angle for the array as a whole at the 00353 // specified time. 00354 00355 virtual MDirection azel0 (Double time) const; 00356 00357 // Returns the pointing angle for each antenna in the array 00358 // at the specified time. 00359 00360 virtual const Vector<MDirection> & azel(Double time) const; // [nA] 00361 00362 // Returns the Jones C matrix for each antenna. 00363 00364 virtual const Vector<SquareMatrix<Complex, 2> > & cjones () const; // [nA] 00365 00366 // Returns the correlation type of each correlation in the 00367 // VisCube. 00368 00369 virtual const Vector<Int> & correlationTypes () const; // [nC] 00370 00371 // Calculates the parallactic angle for the first receptor of 00372 // each antenna at the specified time. 00373 00374 virtual const Vector<Float> & feedPa(Double time) const; // [nR] 00375 00376 // Calculates the parallactic angle for feed 0 of the 00377 // row's Antenna1. 00378 00379 virtual const Vector<Float> & feedPa1 () const; // [nR] 00380 00381 // Calculates the parallactic angle for feed 0 of the 00382 // row's Antenna2. 00383 00384 virtual const Vector<Float> & feedPa2 () const; // [nR] 00385 00386 // Returns the hour angle of the array at the specified time. 00387 00388 virtual Double hourang(Double time) const; 00389 00390 virtual Int nAntennas () const; 00391 00392 virtual Int nChannels () const; 00393 00394 // Returns the number of correlations along the visCube 00395 // correlation axis. 00396 00397 virtual Int nCorrelations () const; 00398 00399 // Returns the number of rows in this VisBuffer 00400 00401 virtual Int nRows () const; 00402 00403 // Calculates the parallactic angle of the array as a whole 00404 // at the specified time. 00405 00406 virtual Float parang0(Double time) const; 00407 00408 // Calculates the parallactic angle of each antenna in the 00409 // array at the specified time. 00410 00411 virtual const Vector<Float> & parang(Double time) const; // [nA] 00412 00413 // Returns the phase center of the array for the specified 00414 // row. 00415 00416 virtual const MDirection& phaseCenter () const; 00417 00418 // Returns the polarization frame for the specified row. 00419 00420 virtual Int polarizationFrame () const; 00421 00422 virtual Int polarizationId () const; 00423 00424 // The returned Vector serves as a map between the rows in 00425 // the VisBuffer and the row IDs in the underlying MS main 00426 // virtual table: mainTableID [i] = rowIds () [ i]; 00427 00428 virtual const Vector<uInt> & rowIds () const; // [nR] 00429 00430 // Returns the spectral window ID for the specified row. 00431 00432 virtual Int spectralWindow () const; 00433 00434 00435 protected: 00436 00437 VisBufferWrapperAsync2 (VisibilityIterator2 & iter); 00438 00439 VisBuffer2 * getWrappedVisBuffer () const; 00440 void wrap (VisBuffer2 * vba); 00441 00442 private: 00443 00444 VisBuffer2 * wrappedVb_p; 00445 VisibilityIterator2 * wrappedVisIterAsync_p; 00446 00447 00448 }; 00449 00450 } // end namespace vi 00451 00452 } //# NAMESPACE CASA - END 00453 00454 #endif