casa
$Rev:20696$
|
00001 /* 00002 * VisBuffer2Adapter.h 00003 * 00004 * Created on: Oct 9, 2012 00005 * Author: jjacobs 00006 */ 00007 00008 #ifndef VISBUFFER2ADAPTER_H_ 00009 #define VISBUFFER2ADAPTER_H_ 00010 00011 #include <synthesis/MSVis/VisBuffer.h> 00012 #include <synthesis/MSVis/VisBuffer2.h> 00013 #include <casa/BasicSL/String.h> 00014 #include <synthesis/MSVis/UtilJ.h> 00015 #include <synthesis/MSVis/VisibilityIterator2.h> 00016 #include <synthesis/MSVis/VisibilityIteratorImpl2.h> 00017 00018 using casa::utilj::toStdError; 00019 00020 #define IllegalOperation() \ 00021 Throw (String::format ("Illegal operation: %s", __func__)); 00022 00023 #define CheckWritability() \ 00024 ThrowIf (vb2Rw_p == 0, String::format ("VB is not writable in %s", __func__)); 00025 00026 namespace casa { 00027 00028 namespace vi { 00029 00030 class VisBuffer2Adapter : public VisBuffer { 00031 00032 public: 00033 00034 VisBuffer2Adapter (VisBuffer2 * vb) : vb2_p (vb) , vb2Rw_p (vb) 00035 { 00036 construct(); 00037 } 00038 VisBuffer2Adapter (const VisBuffer2 * vb) : msColumns_p (0), vb2_p (vb), vb2Rw_p (0) 00039 { 00040 construct(); 00041 } 00042 00043 void 00044 construct () 00045 { 00046 const VisibilityIteratorImpl2 * vi = 00047 dynamic_cast<const VisibilityIteratorImpl2 *> (vb2_p->getVi()->getImpl()); 00048 00049 msColumns_p = vi->msColumnsKluge(); 00050 00051 vi->allSpectralWindowsSelected (spectralWindows_p, nChannels_p); 00052 00053 } 00054 00055 ~VisBuffer2Adapter () {} 00056 00057 virtual VisBuffer & assign(const VisBuffer &, Bool = True) {IllegalOperation();} 00058 00059 virtual VisBuffer * clone () const {IllegalOperation();} 00060 00061 virtual void invalidate(){IllegalOperation();} 00062 00063 //#if 0 00064 00065 // <group> 00066 // Access functions 00067 // 00068 virtual Int & nCorr() { nCorr_p = vb2_p->nCorrelations(); return nCorr_p;} 00069 virtual Int nCorr() const { return vb2_p-> nCorrelations(); } 00070 00071 virtual Int & nChannel() { nChannelsScalar_p = vb2_p-> nChannels(); return nChannelsScalar_p;} 00072 virtual Int nChannel() const { return vb2_p-> nChannels(); } 00073 00074 virtual Vector<Int>& channel() { IllegalOperation (); } 00075 virtual const Vector<Int>& channel() const { IllegalOperation(); } 00076 00077 virtual Int & nRow() { nRows_p = vb2_p->nRows (); return nRows_p;} 00078 00079 virtual Vector<Int>& antenna1() { return const_cast<Vector<Int>&> (vb2_p-> antenna1());} 00080 virtual const Vector<Int>& antenna1() const { return vb2_p-> antenna1(); } 00081 00082 virtual Vector<Int>& antenna2() { return const_cast<Vector<Int>&> (vb2_p-> antenna2());} 00083 virtual const Vector<Int>& antenna2() const { return vb2_p-> antenna2(); } 00084 00085 virtual Vector<Int>& feed1() { return const_cast<Vector<Int>&> (vb2_p-> feed1());} 00086 virtual const Vector<Int>& feed1() const { return vb2_p-> feed1(); } 00087 00088 virtual Vector<Int>& feed2() { return const_cast<Vector<Int>&> (vb2_p-> feed2());} 00089 virtual const Vector<Int>& feed2() const { return vb2_p-> feed2(); } 00090 00091 // feed1_pa() and feed2_pa() return an array of parallactic angles 00092 // (each corresponds to the first receptor of the feed) one for each 00093 // row in the current buffer. In contrast, feed_pa() calculates 00094 // the angles for each antenna. These methods are implemented for 00095 // VisBuffer only to benefit from caching of the feed and antenna IDs. 00096 00097 virtual Vector<Float>& feed1_pa() { IllegalOperation (); } 00098 virtual const Vector<Float>& feed1_pa() const { return vb2_p-> feedPa1(); } 00099 00100 virtual Vector<Float>& feed2_pa() { IllegalOperation (); } 00101 virtual const Vector<Float>& feed2_pa() const { return vb2_p-> feedPa2(); } 00102 00103 virtual Vector<SquareMatrix<Complex, 2> >& CJones() { IllegalOperation (); } 00104 virtual const Vector<SquareMatrix<Complex, 2> >& CJones() const { return vb2_p-> cjones(); } 00105 00106 // Note that feed_pa is a function instead of a cached value 00107 virtual Vector<Float> feed_pa(Double time) const{ return vb2_p-> feedPa (time); } 00108 00109 // direction1() and direction2() return arrays of directions where 00110 // the first and the second antenna/feed are pointed to. One value for 00111 // each row in the current buffer. 00112 virtual Vector<MDirection>& direction1() { IllegalOperation (); } 00113 virtual const Vector<MDirection>& direction1() const { return vb2_p-> direction1(); } 00114 00115 virtual Vector<MDirection>& direction2() { IllegalOperation (); } 00116 virtual const Vector<MDirection>& direction2() const { return vb2_p-> direction2(); } 00117 00118 00119 // NOMINAL parallactic angle (feed p.a. offset NOT included) 00120 virtual Float parang0(Double time) const{ return vb2_p-> parang0(time); } 00121 virtual Vector<Float> parang(Double time) const{ return vb2_p-> parang(time); } 00122 00123 // Note that azel is a function instead of a cached value 00124 virtual MDirection azel0(Double time) const{ return vb2_p-> azel0(time); } 00125 virtual Vector<Double>& azel0Vec(Double , Vector<Double>& ) const{ IllegalOperation(); } 00126 virtual Vector<MDirection> azel(Double time) const{ return vb2_p-> azel(time); } 00127 virtual Matrix<Double>& azelMat(Double , Matrix<Double>& ) const{ IllegalOperation(); } 00128 00129 // Hour angle for specified time 00130 virtual Double hourang(Double time) const{ return vb2_p-> hourang(time); } 00131 00132 virtual Int fieldId() const { return vb2_p-> fieldId()(0); } 00133 00134 virtual Int& fieldIdRef() { IllegalOperation(); } 00135 00136 virtual Int& arrayIdRef() { IllegalOperation(); } 00137 00138 virtual Int arrayId() const { return vb2_p-> arrayId()(0); } 00139 00140 // Return flag for each channel & row 00141 virtual Matrix<Bool>& flag() { return const_cast<Matrix<Bool>&> (vb2_p-> flag());} 00142 virtual const Matrix<Bool>& flag() const { return vb2_p-> flag(); } 00143 00144 // Return flag for each polarization, channel and row 00145 virtual Cube<Bool>& flagCube() { return const_cast<Cube<Bool>&> (vb2_p-> flagCube());} 00146 virtual const Cube<Bool>& flagCube() const { return vb2_p-> flagCube(); } 00147 00148 virtual Vector<Bool>& flagRow() { return const_cast<Vector<Bool>&> (vb2_p-> flagRow());} 00149 virtual const Vector<Bool>& flagRow() const { return vb2_p-> flagRow(); } 00150 00151 // Return flags for each polarization, channel, category, and row. 00152 virtual Array<Bool>& flagCategory() { IllegalOperation (); } 00153 virtual const Array<Bool>& flagCategory() const { return vb2_p-> flagCategory(); } 00154 00155 virtual Vector<Int>& scan() { return const_cast<Vector<Int>&> (vb2_p-> scan());} 00156 virtual const Vector<Int>& scan() const { return vb2_p-> scan(); } 00157 00158 // scalar version for convenience, when scan known constant for 00159 // entire iteration/buffer. 00160 virtual Int scan0() { IllegalOperation(); } 00161 00162 virtual Vector<Int>& processorId() { return const_cast<Vector<Int>&> (vb2_p-> processorId());} 00163 virtual const Vector<Int>& processorId() const { return vb2_p-> processorId(); } 00164 00165 virtual Vector<Int>& observationId() { return const_cast<Vector<Int>&> (vb2_p-> observationId());} 00166 virtual const Vector<Int>& observationId() const { return vb2_p-> observationId(); } 00167 00168 virtual Vector<Int>& stateId() { return const_cast<Vector<Int>&> (vb2_p-> stateId());} 00169 virtual const Vector<Int>& stateId() const { return vb2_p-> stateId(); } 00170 00171 // Gets SPECTRAL_WINDOW/CHAN_FREQ (in Hz, acc. to the MS def'n v.2). 00172 virtual Vector<Double>& frequency() { 00173 return const_cast<Vector<Double>&> (vb2_p->getFrequencies(0)); 00174 } 00175 virtual const Vector<Double>& frequency() const 00176 { 00177 return vb2_p->getFrequencies(0); 00178 } 00179 00180 //if ignoreconv=True..frequency is served as is in the data frame 00181 virtual void lsrFrequency(const Int & spw, Vector<Double>& freq, Bool & convert, 00182 const Bool ignoreConv = False) const 00183 { 00184 const VisibilityIteratorImpl2 * vi = 00185 dynamic_cast<const VisibilityIteratorImpl2 *> (vb2_p->getVi()->getImpl()); 00186 00187 Int frame = -1; 00188 if (ignoreConv){ 00189 frame = vi->getObservatoryFrequencyType (); 00190 } 00191 else{ 00192 frame = MFrequency::LSRK; 00193 } 00194 00195 convert = frame != MFrequency::LSRK; // make this parameter write-only 00196 00197 freq = vi->getFrequencies (this->time()(0), frame, spw, vi->msId()); 00198 } 00199 00200 virtual Int numberCoh () const { IllegalOperation(); } 00201 00202 virtual MDirection & phaseCenter() { IllegalOperation (); } 00203 virtual MDirection phaseCenter() const { return vb2_p-> phaseCenter(); } 00204 00205 virtual Int polFrame() const { return vb2_p-> polarizationFrame(); } 00206 00207 virtual Vector<Int>& corrType() { return const_cast<Vector<Int> &> (vb2_p-> correlationTypes()); } 00208 virtual const Vector<Int>& corrType() const { return vb2_p-> correlationTypes(); } 00209 00210 virtual Vector<Float>& sigma() { IllegalOperation (); } 00211 virtual const Vector<Float>& sigma() const { IllegalOperation(); } 00212 00213 virtual Matrix<Float>& sigmaMat() { IllegalOperation (); } 00214 virtual const Matrix<Float>& sigmaMat() const { return vb2_p-> sigma(); } 00215 00216 virtual Int & spectralWindow() { spectralWindow_p = vb2_p->spectralWindows()(0); return spectralWindow_p;} 00217 virtual Int spectralWindow() const { return vb2_p-> spectralWindows()(0); } 00218 virtual Int polarizationId() const { return vb2_p-> polarizationId(); } 00219 virtual Int& dataDescriptionIdRef() { IllegalOperation(); } 00220 virtual Int dataDescriptionId() const { return vb2_p-> dataDescriptionIds()(0); } 00221 virtual Vector<Double>& time() { IllegalOperation (); } 00222 virtual const Vector<Double>& time() const { return vb2_p-> time(); } 00223 00224 virtual Vector<Double>& timeCentroid() { IllegalOperation (); } 00225 virtual const Vector<Double>& timeCentroid() const { return vb2_p-> timeCentroid(); } 00226 00227 virtual Vector<Double>& timeInterval() { IllegalOperation (); } 00228 virtual const Vector<Double>& timeInterval() const { return vb2_p-> timeInterval(); } 00229 00230 virtual Vector<Double>& exposure() { IllegalOperation (); } 00231 virtual const Vector<Double>& exposure() const { return vb2_p-> exposure(); } 00232 00233 virtual Vector<RigidVector<Double, 3> >& uvw() 00234 { 00235 if (uvw_p.empty()){ 00236 00237 const Matrix<Double> & u = vb2_p->uvw(); 00238 00239 Int nRows = u.shape()(1); 00240 uvw_p.resize (nRows); 00241 00242 for (Int i = 0; i < nRows; i++){ 00243 RigidVector<Double,3> t; 00244 for (Int j = 0; j < 3; j++){ 00245 t (j) = u (j, i); 00246 } 00247 uvw_p (i) = t; 00248 } 00249 } 00250 00251 return uvw_p; 00252 } 00253 00254 virtual const Vector<RigidVector<Double, 3> >& uvw() const { IllegalOperation(); } 00255 00256 virtual Matrix<Double>& uvwMat() { IllegalOperation (); } 00257 virtual const Matrix<Double>& uvwMat() const { return vb2_p-> uvw(); } 00258 00259 virtual Matrix<CStokesVector>& visibility() { IllegalOperation (); } 00260 virtual const Matrix<CStokesVector>& visibility() const { IllegalOperation (); } 00261 00262 virtual Matrix<CStokesVector>& modelVisibility() { IllegalOperation (); } 00263 virtual const Matrix<CStokesVector>& modelVisibility() const { IllegalOperation (); } 00264 00265 virtual Matrix<CStokesVector>& correctedVisibility() { IllegalOperation (); } 00266 virtual const Matrix<CStokesVector>& correctedVisibility() const { IllegalOperation (); } 00267 00268 virtual Cube<Complex>& visCube() { IllegalOperation (); } 00269 virtual const Cube<Complex>& visCube() const { return vb2_p-> visCube(); } 00270 00271 virtual Cube<Complex>& modelVisCube() { return const_cast<Cube<Complex> &> (vb2_p->visCubeModel()); } 00272 00273 virtual Cube<Complex>& modelVisCube(const Bool & ) { IllegalOperation (); } 00274 00275 virtual const Cube<Complex>& modelVisCube() const { return vb2_p->visCubeModel(); } 00276 00277 virtual Cube<Complex>& correctedVisCube() { IllegalOperation(); } 00278 virtual const Cube<Complex>& correctedVisCube() const { return vb2_p-> visCubeCorrected(); } 00279 00280 // Return visCube(), modelVisCube(), or correctedVisCube(), 00281 // according to whichcol. They throw an exception if whichcol is 00282 // unsupported, but note the encouraged default. 00283 // TODO: Optionally return DATA if whichcol is unavailable. 00284 Cube<Complex>& dataCube(const MS::PredefinedColumns whichcol=MS::DATA); 00285 const Cube<Complex>& dataCube(const MS::PredefinedColumns 00286 whichcol=MS::DATA) const; 00287 00288 virtual Cube<Float>& floatDataCube() { IllegalOperation(); } 00289 virtual const Cube<Float>& floatDataCube() const { return vb2_p-> visCubeFloat (); } 00290 00291 // Returns the weights for each row averaged over the parallel hand correlations. 00292 virtual Vector<Float>& weight() { IllegalOperation(); } 00293 virtual const Vector<Float>& weight() const { IllegalOperation(); } 00294 00295 // Returns the nPol_p x curNumRow_p weight matrix. 00296 virtual Matrix<Float>& weightMat() { IllegalOperation(); } 00297 virtual const Matrix<Float>& weightMat() const { return vb2_p-> weight(); } 00298 00299 // Is a valid WEIGHT_SPECTRUM available? 00300 virtual Bool existsWeightSpectrum() const { IllegalOperation(); } 00301 00302 virtual Cube<Float>& weightSpectrum() { IllegalOperation();; } 00303 virtual const Cube<Float>& weightSpectrum() const { return vb2_p-> weightSpectrum(); } 00304 00305 virtual Matrix<Float>& imagingWeight(){ IllegalOperation(); } 00306 virtual const Matrix<Float>& imagingWeight() const{ return vb2_p-> imagingWeight(); } 00307 00308 virtual Cube<Float>& weightCube() { IllegalOperation(); } 00309 //</group> 00310 00311 //<group> 00312 // Utility functions to provide coordinate or column ranges of the 00313 // data in the VisBuffer. Flagging is applied before computing the ranges. 00314 // 00315 // Generic accessor to column ranges of integer type, as specified by 00316 // enumerations defined in class MSCalEnums. Throws an exception 00317 // if the enum is not for a recognized integer column. 00318 virtual Vector<Int> vecIntRange(const MSCalEnums::colDef & ) const{ IllegalOperation(); } 00319 00320 // Antenna id. range (includes both ANTENNA1 and ANTENNA2 columns) 00321 virtual Vector<Int> antIdRange() const{ IllegalOperation(); } 00322 00323 // Time range 00324 virtual Bool timeRange(MEpoch & , MVEpoch & , MVEpoch & ) const 00325 { IllegalOperation(); } 00326 00327 // Return the row Ids from the original ms. If the ms used is a subset of 00328 // another ms then rowIds() return the row ids of the original ms. 00329 virtual Vector<uInt>& rowIds(){ IllegalOperation(); } 00330 00331 virtual const Vector<uInt>& rowIds() const { return vb2_p-> rowIds(); }; 00332 00333 //</group> 00334 00335 // Frequency average the buffer (visibility() column only) 00336 virtual void freqAverage(){ IllegalOperation(); } 00337 00338 // Frequency average the buffer (visCube and [if present] modelVisCube) 00339 void freqAveCubes(){ IllegalOperation(); } 00340 00341 // Average channel axis according to chanavebounds, for whichever of DATA, 00342 // MODEL_DATA, CORRECTED_DATA, FLOAT_DATA, FLAG, and WEIGHT_SPECTRUM are 00343 // present. It will only treat the first 5 as present if they have already 00344 // been loaded into the buffer! 00345 void channelAve(const Matrix<Int>& ){ IllegalOperation(); } 00346 00347 // Average channel axis by factor. 00348 template<class T> void chanAveVisCube(Cube<T>& , Int ){ IllegalOperation(); } 00349 00350 // Accumulate channel axis by factor, without applying WEIGHT_SPECTRUM even 00351 // if it is present. 00352 // It is primarily intended for averaging WEIGHT_SPECTRUM itself. 00353 template<class T> void chanAccCube(Cube<T>& , Int ){ IllegalOperation(); } 00354 00355 // This defaults to no conceptual side effects, but usually it is more 00356 // efficient to let it leave weightSpectrum() in a channel averaged state. 00357 // restoreWeightSpectrum has no effect if !existsWeightSpectrum(). 00358 virtual void chanAveFlagCube(Cube<Bool>& , const Int , 00359 const Bool = True){ IllegalOperation(); } 00360 00361 // Doesn't do anything if flagcat is degenerate. 00362 void chanAveFlagCategory(Array<Bool>& flagcat, const Int nChanOut); 00363 00364 // Form Stokes parameters from correlations 00365 // (these are preliminary versions) 00366 virtual void formStokes(){ IllegalOperation(); } 00367 virtual void formStokesWeightandFlag(){ IllegalOperation(); } 00368 virtual void formStokes(Cube<Complex>& ){ IllegalOperation(); } 00369 virtual void formStokes(Cube<Float>& ){ IllegalOperation(); } // Will throw up if asked to do all 4. 00370 00371 // Sort/unsort the correlations, if necessary 00372 // (Rudimentary handling of non-canonically sorted correlations--use with care!) 00373 virtual void sortCorr(){ IllegalOperation(); } 00374 virtual void unSortCorr(){ IllegalOperation(); } 00375 00376 // Normalize the visCube by the modelVisCube 00377 // (and optionally also divide visCube_p by its normalized amp) 00378 virtual void normalize(const Bool & = False){ CheckWritability(); vb2Rw_p-> normalize(); } 00379 00380 // Fill weightMat according to sigma column 00381 virtual void resetWeightMat(){ IllegalOperation(); } 00382 00383 // Rotate visibility phase for given vector (dim = nrow of vb) of phases (metres) 00384 virtual void phaseCenterShift(const Vector<Double>& ){ IllegalOperation(); } 00385 // Rotate visibility phase for phase center offsets (arcsecs) 00386 virtual void phaseCenterShift(Double , Double ){ IllegalOperation(); } 00387 00388 // Update coordinate info - useful for copied VisBuffers that need 00389 // to retain some state for later reference. 00390 // Presently this fills antenna, array, field and spectralWindow ids, time, 00391 // frequency and number of rows. 00392 // if dirDependent is set to False the expensive direction dependent calculation of parallactic or direction of 00393 // antenna from pointing table is avoided 00394 //Add more as needed. 00395 virtual void updateCoordInfo(const VisBuffer * = NULL, const Bool =True){ IllegalOperation(); } 00396 00397 // Set the visibility to a constant, note that this only changes the buffer, 00398 // no values are written back to tables from here. 00399 virtual void setVisCube(Complex c){ CheckWritability(); vb2Rw_p-> setVisCube(c); } 00400 virtual void setModelVisCube(Complex c){ CheckWritability(); vb2Rw_p-> setVisCubeModel(c); } 00401 virtual void setCorrectedVisCube(Complex ){ IllegalOperation(); } 00402 00403 // Set the visibility, note that this only changes the buffer, 00404 // no values are written back to tables from here. 00405 virtual void setVisCube(const Cube<Complex>& vis){ CheckWritability(); vb2Rw_p-> setVisCube(vis); } 00406 virtual void setModelVisCube(const Cube<Complex>& vis){ CheckWritability(); vb2Rw_p-> setVisCubeModel(vis); } 00407 virtual void setCorrectedVisCube(const Cube<Complex>& vis){ CheckWritability(); vb2Rw_p-> setVisCubeCorrected(vis); } 00408 00409 // Like the above, but for FLOAT_DATA, keeping it as real floats. 00410 virtual void setFloatDataCube(const Cube<Float>& fcube){ CheckWritability(); vb2Rw_p-> setVisCubeFloat(fcube); } 00411 00412 // Set model according to a Stokes vector 00413 virtual void setModelVisCube(const Vector<Float>& /*stokes*/){ IllegalOperation (); } 00414 00415 // Reference external model visibilities 00416 virtual void refModelVis(const Matrix<CStokesVector>& ){ IllegalOperation(); } 00417 00418 // Remove scratch cols data from vb 00419 virtual void removeScratchCols(){ IllegalOperation(); } 00420 00421 // Access the current ROMSColumns object via VisIter 00422 virtual const ROMSColumns & msColumns() const 00423 { 00424 Assert (msColumns_p != 0); 00425 return * msColumns_p; 00426 } 00427 00428 virtual Int numberAnt () const{ return vb2_p-> nAntennas (); } 00429 00430 // Get all selected spectral windows not just the one in the actual buffer 00431 virtual void allSelectedSpectralWindows(Vector<Int>& spectralWindows, Vector<Int>& nChannels) 00432 { 00433 spectralWindows.assign (spectralWindows_p); 00434 nChannels.assign (nChannels_p); 00435 } 00436 00437 virtual void getChannelSelection(Block< Vector<Int> >& , 00438 Block< Vector<Int> >& , 00439 Block< Vector<Int> >& , 00440 Block< Vector<Int> >& , 00441 Block< Vector<Int> >& ) const { IllegalOperation(); } 00442 void allSelectedSpectralWindows(Vector<Int>& spws, Vector<Int>& nvischan) const ; 00443 00444 // Return the actual msid, useful if using multiple ms to monitor which 00445 // ms in the list is being dealt with 00446 virtual Int msId() const { return vb2_p-> msId(); } 00447 00448 //checked if the ms has changed since the last chunk processed 00449 virtual Bool newMS() const { return vb2_p-> isNewMs(); } 00450 //get the name of the ms the buffer is at empty string if no visiter is attached 00451 virtual String msName(Bool =False) const{ return vb2_p-> msName(); } 00452 00453 virtual Bool newArrayId () const{ return vb2_p-> isNewArrayId (); } 00454 virtual Bool newFieldId () const{ return vb2_p-> isNewFieldId (); } 00455 virtual Bool newSpectralWindow () const{ return vb2_p-> isNewSpectralWindow (); } 00456 00457 // 00458 00459 00460 private: 00461 00462 00463 const ROMSColumns * msColumns_p; // [use] 00464 Vector<Int> nChannels_p; 00465 Int nChannelsScalar_p; 00466 Int nCorr_p; 00467 Int nRows_p; 00468 Int spectralWindow_p; 00469 Vector<Int> spectralWindows_p; 00470 Vector<RigidVector<Double, 3> > uvw_p; 00471 const vi::VisBuffer2 * vb2_p; // [use] 00472 vi::VisBuffer2 * vb2Rw_p; // [use] 00473 00474 }; 00475 00476 } // end namespace vi 00477 00478 } // end namespace casa 00479 00480 00481 #endif /* VISBUFFER2ADAPTER_H_ */