casa
$Rev:20696$
|
00001 //# VisibilityIterator.h: Step through the MeasurementEquation by visibility 00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,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: VisibilityIterator.h,v 19.14 2006/02/28 04:48:58 mvoronko Exp $ 00027 00028 #ifndef MSVIS_VISIBILITYITERATOR2_H 00029 #define MSVIS_VISIBILITYITERATOR2_H 00030 00031 #include <casa/aips.h> 00032 00033 //#include <casa/Arrays/Cube.h> 00034 //#include <casa/Arrays/Matrix.h> 00035 //#include <casa/Arrays/Slicer.h> 00036 //#include <casa/BasicSL/String.h> 00037 //#include <casa/Containers/Stack.h> 00038 //#include <casa/Quanta/MVDoppler.h> 00039 //#include <measures/Measures/MCDoppler.h> 00040 //#include <measures/Measures/MDoppler.h> 00041 //#include <measures/Measures/MeasConvert.h> 00042 //#include <measures/Measures/Stokes.h> 00043 //#include <ms/MeasurementSets/MSDerivedValues.h> 00044 #include <ms/MeasurementSets/MSIter.h> 00045 #include <ms/MeasurementSets/MeasurementSet.h> 00046 //#include <ms/MeasurementSets/MSSelection.h> 00047 //#include <scimath/Mathematics/RigidVector.h> 00048 //#include <scimath/Mathematics/SquareMatrix.h> 00049 //#include <synthesis/MSVis/StokesVector.h> 00050 //#include <synthesis/MSVis/UtilJ.h> 00051 #include <synthesis/MSVis/VisBufferComponents2.h> 00052 //#include <synthesis/MSVis/ViFrequencySelection.h> 00053 //#include <synthesis/MSVis/VisImagingWeight.h> 00054 //#include <tables/Tables/ArrayColumn.h> 00055 //#include <tables/Tables/ScalarColumn.h> 00056 00057 #include <boost/noncopyable.hpp> 00058 #include <map> 00059 #include <set> 00060 #include <utility> 00061 #include <vector> 00062 00063 namespace casa { //# NAMESPACE CASA - BEGIN 00064 00065 //# forward decl 00066 00067 //class CStokesVector; 00068 class MDirection; 00069 class MSDerivedValues; 00070 class MSIter; 00071 class RecordInterface; 00072 class ROMSAntennaColumns; 00073 class ROMSDataDescColumns; 00074 class ROMSFeedColumns; 00075 class ROMSFieldColumns; 00076 class ROMSFlagCmdColumns; 00077 class ROMSHistoryColumns; 00078 class ROMSObservationColumns; 00079 class ROMSPointingColumns; 00080 class ROMSPolarizationColumns; 00081 class ROMSProcessorColumns; 00082 class ROMSSpWindowColumns; 00083 class ROMSStateColumns; 00084 class ROMSDopplerColumns; 00085 class ROMSFreqOffsetColumns; 00086 class ROMSSourceColumns; 00087 class ROMSSysCalColumns; 00088 class ROMSWeatherColumns; 00089 template <typename T, Int N> class RigidVector; 00090 template <typename T, Int N> class SquareMatrix; 00091 class VisImagingWeight; 00092 00093 namespace asyncio { 00094 00095 class VLAT; 00096 00097 } // end namespace asyncio 00098 00099 namespace vi { 00100 00101 class FrequencySelection; 00102 class FrequencySelections; 00103 class VisBuffer2; 00104 class VisBufferComponents2; 00105 class VisBufferImpl2; 00106 class ViImplementation2; 00107 00108 class SubtableColumns { 00109 00110 public: 00111 00112 // Simple wrapper class to limit access to only the columns associated with the 00113 // current MS's subtables. This prevents misuse of the main table data columns 00114 // which are provided as part of the MSColumns object returned by 00115 // MSIter::msColumns. 00116 00117 SubtableColumns (const MSIter & msIter); 00118 00119 const ROMSAntennaColumns& antenna() const; 00120 const ROMSDataDescColumns& dataDescription() const; 00121 const ROMSFeedColumns& feed() const; 00122 const ROMSFieldColumns& field() const; 00123 const ROMSFlagCmdColumns& flagCmd() const; 00124 const ROMSHistoryColumns& history() const; 00125 const ROMSObservationColumns& observation() const; 00126 const ROMSPointingColumns& pointing() const; 00127 const ROMSPolarizationColumns& polarization() const; 00128 const ROMSProcessorColumns& processor() const; 00129 const ROMSSpWindowColumns& spectralWindow() const; 00130 const ROMSStateColumns& state() const; 00131 const ROMSDopplerColumns& doppler() const; 00132 const ROMSFreqOffsetColumns& freqOffset() const; 00133 const ROMSSourceColumns& source() const; 00134 const ROMSSysCalColumns& sysCal() const; 00135 const ROMSWeatherColumns& weather() const; 00136 00137 private: 00138 00139 const MSIter & msIter_p; 00140 00141 }; 00142 00144 // 00145 // Subchunk class 00146 // 00147 // Provides the ordered pair identifying the current subchunk. The first 00148 // component is the chunk (goes from 0 to nChunks-1 during the outer loop 00149 // iteration). The second component is the subchunk number which is 00150 // zero after VisibilityIterator::origin is called and is increment 00151 // until ROVI::more returns False. 00152 00153 class Subchunk : public std::pair<Int, Int>{ 00154 00155 public: 00156 00157 // First component is Chunk and second is Subchunk 00158 00159 Subchunk () { resetToOrigin ();} 00160 Subchunk (Int a , Int b) : std::pair<Int,Int> (a,b) {} 00161 00162 Bool operator== (const Subchunk & other){ 00163 return first == other.first && second == other.second; 00164 } 00165 00166 Bool operator< (const Subchunk & other){ 00167 return first < other.first || 00168 (first == other.first && second < other.second); 00169 } 00170 00171 Bool atOrigin () const { return * this == Subchunk ();} 00172 Int chunk () const { return first;} 00173 void incrementSubChunk () { second ++;} 00174 void incrementChunk () { first ++; second = 0; } 00175 00176 void resetSubChunk () { second = 0;} // position to start of chunk 00177 00178 void resetToOrigin () { first = 0; second = 0; } 00179 // Make a subchunk pair that is positioned to the first subchunk of the 00180 // first chunk (i.e., 0,0) 00181 00182 Int subchunk () const { return second;} 00183 String toString () const; 00184 00185 static Subchunk noMoreData (); 00186 00187 private: 00188 00189 }; 00190 00192 // 00193 // Code to provide interface to weight function 00194 00195 class WeightFunction { 00196 public: 00197 00198 virtual ~WeightFunction () {} 00199 Float operator() (Float f) { return apply (f);} 00200 virtual Float apply (Float) = 0; 00201 00202 static WeightFunction * generateUnityWeightFunction (); 00203 static WeightFunction * generateIdentityWeightFunction (); 00204 static WeightFunction * generateSquareWeightFunction (); 00205 00206 protected: 00207 00208 static Float unity (Float); 00209 static Float identity (Float x); 00210 static Float square (Float x); 00211 00212 }; 00213 00214 template<typename F> 00215 class WeightFunctionImpl : public WeightFunction { 00216 public: 00217 00218 // Provide either a unary function, Float (*) (Float), or 00219 // a functor class having a Float operator() (Float) method. 00220 00221 WeightFunctionImpl (F f) : function_p (f) {} 00222 00223 Float apply (Float f) { return function_p (f);} 00224 00225 private: 00226 00227 F function_p; 00228 }; 00229 00230 template<typename F> 00231 WeightFunction * generateWeightFunction (F f) { return new WeightFunctionImpl<F> (f);} 00232 00233 class SortColumns { 00234 public: 00235 00236 SortColumns (const Block<Int> & columns = Block<Int> (), Bool addDefaultColumns = True); 00237 00238 Bool addDefaultSortColumns () const; 00239 const Block<Int> & getColumns () const; 00240 00241 private: 00242 00243 Bool addDefaultColumns_p; 00244 Block<Int> columns_p; 00245 00246 00247 }; 00248 00249 00250 class VisibilityIterator2; 00251 00252 class ViFactory { 00253 00254 public: 00255 00256 virtual ~ViFactory () {} 00257 00258 virtual VisibilityIterator2 * createVi () = 0; 00259 }; 00260 00261 // <summary> 00262 // VisibilityIterator2 iterates through one or more readonly MeasurementSets 00263 // </summary> 00264 // <use visibility=export> 00265 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00266 // </reviewed> 00267 // <prerequisite> 00268 // <li> <linkto class="MSIter">MSIter</linkto> 00269 // <li> <linkto class="MeasurementSet">MeasurementSet</linkto> 00270 // <li> <linkto class="VisSet">VisSet</linkto> 00271 // <li> <linkto class="PrefetchColumns">PrefetchColumns</linkto> 00272 // </prerequisite> 00273 // 00274 // <etymology> 00275 // The VisibilityIterator2 is a readonly iterator returning visibilities 00276 // </etymology> 00277 // 00278 // <synopsis> 00279 // VisibilityIterator2 provides iteration with various sort orders 00280 // for one or more MSs. It has member functions to retrieve the fields 00281 // commonly needed in synthesis calibration and imaging. 00282 // 00283 // One should use <linkto class="VisBuffer">VisBuffer</linkto> 00284 // to access chunks of data. 00285 // 00286 // VisibilityIterator2s can be either synchronous or asynchronous, depending 00287 // on the constructor used to create them as well as the current value of 00288 // a CASARC file setting. A synchronous instance is works the same as 00289 // this class ever worked; an asynchronous instance uses a second thread 00290 // (the Visibility Lookahead Thread or VLAT) to fill the VisBuffers in 00291 // advance of their use by the original thread. 00292 // 00293 // To create an asynchronous instance of ROVI you must use one of the two 00294 // constructors which have a pointer to a PrefetchColumns object as the 00295 // first argument. This object specifies which VisBuffer components should be 00296 // prefetched by the VLAT; accessing components not specified in the PrefetchColumns 00297 // object will result in an exception containing an error message indicating 00298 // that the VisBuffer does not contain the requested column. In addition 00299 // to using the appropriate constructor, the CASARC file setting 00300 // VisibilityIterator2.async.enabled can be used to turn asynchronous I/O 00301 // off globally; if it's globally enabled then it is still possible for the 00302 // user to choose to enable/disable it on a VI by VI basis. 00303 // 00304 // +-------------------+ 00305 // | | 00306 // | *** Nota Bene *** | 00307 // | | 00308 // +-------------------+ 00309 // 00310 // Because of the multithreaded nature of asynchronous I/O, the user 00311 // needs to be a bit more careful in the use of the VI and it's attached VisBuffer. 00312 // Data access operations need to be directed to the VisBuffer. Additionally 00313 // the user must not attempt to access the data using a separate VI since 00314 // the underlying casacore objects are not threadsafe and bizarre errors 00315 // will likely occur. 00316 // 00317 // CASARC Settings 00318 // =============== 00319 // 00320 // Normal settings 00321 // --------------- 00322 // 00323 // VisibilityIterator2.async.enabled - Boolean value that enables or disables 00324 // async I/O. The default value is currently False (i.e., disabled). 00325 // VisibilityIterator2.async.nBuffers - The number of lookahead buffers. This 00326 // defaults to 2. 00327 // 00328 // 00329 // Debug settings 00330 // -------------- 00331 // 00332 // VisibilityIterator2.async.doStats: true 00333 // VisibilityIterator2.async.debug.logFile: stderr 00334 // VisibilityIterator2.async.debug.logLevel: 1 00335 // 00336 00337 // </synopsis> 00338 // 00339 // <example> 00340 // <code> 00341 // // 00342 // </code> 00343 // </example> 00344 // 00345 // <motivation> 00346 // For imaging and calibration you need to access an MS in some consistent 00347 // order (by field, spectralwindow, time interval etc.). This class provides 00348 // that access. 00349 // </motivation> 00350 // 00351 // <thrown> 00352 // <li> 00353 // <li> 00354 // </thrown> 00355 // 00356 // <todo asof="1997/05/30"> 00357 // <li> cleanup the currently dual interface for visibilities and flags 00358 // <li> sort out what to do with weights when interpolating 00359 // </todo> 00360 class VisibilityIterator2 : private boost::noncopyable 00361 { 00362 // These classes are members of the VI/VB framework and need extra 00363 // access to the non-public methods of this class. Any additions of 00364 // classes not in this framework is strongly discouraged. 00365 // 00366 // Friends of the class should limit themselves to accessing the protected 00367 // area of this class so that items in the private area can remeain de 00368 // facto private. 00369 00370 friend class VisibilityIteratorImpl2; 00371 friend class VisBuffer2Adapter; 00372 friend class VisBufferImpl2; 00373 friend class VisBufferState; 00374 friend class asyncio::VLAT; // allow VI lookahead thread class to access protected 00375 // functions VLAT should not access private parts, 00376 // especially variables 00377 00378 friend class AveragingTvi2Factory; 00379 00380 public: 00381 00382 00383 class Factory { // Interface for implementation creation factory 00384 00385 public: 00386 00387 virtual ~Factory () {} 00388 00389 virtual ViImplementation2 * 00390 operator() (const VisBufferComponents2 * /*prefetchColumns*/, 00391 const Block<MeasurementSet>& /*mss*/, 00392 const Block<Int>& /*sortColumns*/, 00393 const Bool /*addDefaultSortCols*/, 00394 Double /*timeInterval*/) const 00395 { 00396 return NULL; 00397 } 00398 }; 00399 00400 typedef enum MSIter::PolFrame PolFrame; 00401 00402 typedef enum DataColumn { 00403 Observed=0, // Observed data 00404 Model, // Model data 00405 Corrected // Corrected data 00406 } DataColumn; 00407 00408 // Construct from an MS and a Block of MS column enums specifying the 00409 // iteration order. These can be specified as MS::ANTENNA1, MS::ARRAY_ID, 00410 // etc.; they are defined in MSMainEnums.h. 00411 // If no order is specified, it uses the default sort 00412 // order of MSIter, which is not necessarily the raw order of ms! 00413 // The default ordering is ARRAY_ID, FIELD_ID, DATA_DESC_ID, 00414 // and TIME, but check MSIter.h to be sure. 00415 // These columns will be added first if they are not specified. 00416 // 00417 // An optional timeInterval (in seconds) can be given to iterate through 00418 // chunks of time. The default interval of 0 groups all times together. 00419 // Every 'chunk' of data contains all data within a certain time interval and 00420 // with identical values of the other iteration columns (e.g. DATA_DESC_ID 00421 // and FIELD_ID). 00422 // 00423 // A set of prefetch columns can be specified for asynchronous I/O use. These 00424 // roughly correspond to the fields accessible from the VisBuffer. Specifying 00425 // prefetch columns will cause an asynchronous VI to be created if asynchronous 00426 // I/O is globally enabled. If the user wishes to have application-specific 00427 // enable/disable of asynchronous I/O then they must implement logic that 00428 // either either provides prefetch columns (enables) or a null pointer (disables). 00429 00430 VisibilityIterator2 (const MeasurementSet& ms, 00431 const Block<Int>& sortColumns = Block<Int> (), 00432 Bool isWritable = False, 00433 const VisBufferComponents2 * prefetchColumns = 0, 00434 const Bool addDefaultSortCols = True, 00435 Double timeInterval = 0); 00436 00437 VisibilityIterator2 (const Block<MeasurementSet>& mss, 00438 const Block<Int>& sortColumns = Block<Int> (), 00439 Bool isWritable = False, 00440 const VisBufferComponents2 * prefetchColumns = 0, 00441 const Bool addDefaultSortCols = True, 00442 Double timeInterval = 0); 00443 00444 // Destructor 00445 00446 virtual ~VisibilityIterator2(); 00447 00449 // 00450 // BEGIN Experimental Section 00451 // 00452 00453 static VisibilityIterator2 * copyingViFactory (const MeasurementSet & srcMs, 00454 MeasurementSet & dstMs); 00455 00456 // 00457 // END Experimental Section 00458 // 00460 00462 // 00463 // Iteration movement methods 00464 // 00465 // The typical use case for VisibilityIteration looks like 00466 // 00467 // for (vi.originChunks(); vi.moreChunks(); nextChunk()){ 00468 // for (vi.origin (); vi.more(); vi++){ 00469 // } 00470 // } 00471 // 00472 // The outer loop is the "chunk" loop and the inner loop is the "subchunk" 00473 // loop. A chunk contains all the rows having identical values for the 00474 // sort columns values except time; time can have an optional interval 00475 // value specified either in the constructor or via the setInterval 00476 // method. If an interval is specified the set of rows will all have 00477 // timestamps that are within that interval of the first row in the 00478 // chunk; if no interval is specified then the chunk will contain only 00479 // rows having the identical timestamp. If multiple MSs are specified 00480 // in the constructor then changing from one MS to the next will occur 00481 // on a chunk boundary (i.e., a chunk will never contain data from more 00482 // than one MS). 00483 // 00484 // A subchunk typically contains all the rows in the chunk having identical 00485 // timestamps. The only exception is when the user calls setRowBlocking(N) 00486 // with a positive value. In this case, the subchunk *may* contain up to 00487 // N rows; however, this is only a suggestion to the VI. If there are 00488 // less than N rows remaining in the chunk then fewer than N rows will be 00489 // contained in the chunk. The number of rows in a subchunk will also be 00490 // less than N if a larger set of rows would create an inconsistently 00491 // shaped visibility cube; this could happen if the number of channels 00492 // changes from one timestamp to another or the framed frequency 00493 // selection selects a different number of channels from one timestamp to 00494 // the next. 00495 // 00496 // origin () - positions VI to the start of the current chunk 00497 // operator++ - advance VI to next subchunk if it exists 00498 // more - returns True if the VI is pointing to a valid subchunk 00499 // 00500 // originChunks - Move to the first chunk of data. 00501 // operator++ - advance VI to the next chunk if it exists 00502 // moreChunks - returns True if the VI is pointing to a valid chunk. 00503 00504 void origin(); // Reset to start of the chunk 00505 void next (); 00506 Bool more() const; 00507 00508 void originChunks(); 00509 void nextChunk(); 00510 Bool moreChunks() const; 00511 00512 // Returns the pair (chunk,subchunk) for the current position of the VI. Only 00513 // valid after origin has been called. 00514 00515 Subchunk getSubchunkId () const; 00516 00518 // 00519 // Iterator operation methods 00520 // 00521 // These methods alter the way that the VI operates. After applying any of these 00522 // (except slurp which should be called after originChunks) originChunks must be 00523 // called before the VI is advanced again; otherwise an exception will be thrown 00524 // (changing these values in the middle of a sweep can lead to unexpected behavior). 00525 // 00526 // Selecting ranges of frequencies involves initializing a 00527 // FrequencySelection(s) object and providing it to the VI. Once 00528 // properly applied the VI will only return data for the selected 00529 // frequencies. No interpolation is performed; the data returned is 00530 // simply the channels that currently map to the selected frequencies for 00531 // the specified frame of reference. 00532 00533 void setFrequencySelection (const FrequencySelection &); // for single MS 00534 void setFrequencySelection (const FrequencySelections &); // when using multiple MSs 00535 00536 // RowBlocking is a suggestion to the iterator that it try to use subchunks 00537 // having the suggested number of rows. The VI will attempt to honor the 00538 // suggestion except when there are not enough rows remaining in the chunk 00539 // or when putting the suggested number of rows in the subchunk cannot 00540 // be contained in a cube (e.g., there are sets of row with different 00541 // numbers of frequencies, etc.). The latter case will mainly occur 00542 // when the row visibility shape changes from one row to the next. 00543 00544 Int getRowBlocking() const; 00545 void setRowBlocking(Int nRows=0); 00546 00547 // In this context the interval determines what rows will be contained 00548 // in a chunk. A chunk is all the rows in an MS that have the same values 00549 // in the sort columns, except for time; all rows that otherwise have the 00550 // same values for the sort columns will be in the chunk if they are no 00551 // later than "interval" seconds after the first row in the chunk. 00552 // 00553 // *** This value is unrelated to the interval field of the MS main table. 00554 00555 Double getInterval() const; 00556 void setInterval(Double timeInterval); 00557 00558 // Call to use the slurp i/o method for all scalar columns. This 00559 // will set the BucketCache cache size to the full column length 00560 // and cause the full column to be cached in memory, if 00561 // any value of the column is used. In case of out-of-memory, 00562 // it will automatically fall-back on the smaller cache size. 00563 // Slurping the column is to be considered as a work-around for the 00564 // Table i/o code, which uses BucketCache and performs extremely bad 00565 // for random access. Slurping is useful when iterating non-sequentially 00566 // an MS or parts of an MS, it is not tested with multiple MSs. 00567 00568 void slurp() const; 00569 00571 // 00572 // Other methods 00573 // 00574 00575 // Returns True if this is an asynchronous VI 00576 00577 Bool isAsynchronous () const; 00578 00579 // Returns True if async I/O is globally enabled. 00580 00581 static Bool isAsynchronousIoEnabled(); 00582 00583 // Returns True if this VI is writable (always False for ROVI and 00584 // True for VI; see VisibilityIterator class). 00585 00586 Bool isWritable () const; 00587 00588 // Returns the columns that the VisibilityIterator2 is sorting by. These are 00589 // defined in MSMainEnums.h. These can be specified as MS::ANTENNA1, 00590 // MS::ARRAY_ID, etc. 00591 00592 const Block<Int>& getSortColumns() const; 00593 00594 // Returns the VisBuffer permanently attached to this VisibilityIterator. 00595 00596 VisBuffer2 * getVisBuffer (); 00597 00598 //reference to actual ms in interator 00599 00600 const MeasurementSet& ms() const; 00601 00602 const vi::SubtableColumns & subtableColumns () const; 00603 00604 00605 // The reporting frame of reference is the default frame of reference to be 00606 // used when the user requests the frequencies of the current data selection 00607 // in a VisBuffer. This is useful when the user wishes to select the data 00608 // using one frame of reference but use the frequencies from another frame 00609 // of reference. If not specified then the default will be to use the 00610 // frame of reference used to select the data. 00611 // 00612 // These *do not* change the selection in any way. 00613 00614 Int getReportingFrameOfReference () const; 00615 void setReportingFrameOfReference (Int); 00616 00617 // Return the numbers of rows in the current chunk 00618 00619 Int nRowsInChunk() const; 00620 00621 // Assign a VisImagingWeight object to this iterator. This object is used 00622 // to generate imaging weights. 00623 00624 void useImagingWeight(const VisImagingWeight& imWgt); 00625 const VisImagingWeight & getImagingWeightGenerator () const; 00626 00627 // Write/modify the flags in the data. 00628 // This will flag all channels in the original data that contributed to 00629 // the output channel in the case of channel averaging. 00630 // All polarizations have the same flag value. 00631 00632 void writeFlag(const Matrix<Bool>& flag); 00633 00634 // Write/modify the flags in the data. 00635 // This writes the flags as found in the MS, Cube(npol,nchan,nrow), 00636 // where nrow is the number of rows in the current iteration (given by 00637 // nRow()). 00638 00639 virtual void writeFlag(const Cube<Bool>& flag); 00640 00641 // Write/modify the flag row column; dimension Vector(nrow) 00642 00643 virtual void writeFlagRow(const Vector<Bool>& rowflags); 00644 00645 void writeFlagCategory(const Array<Bool>& fc); 00646 00647 // Write/modify the visibilities. 00648 // This is possibly only for a 'reference' MS which has a new DATA column. 00649 // The first axis of the matrix should equal the selected number of channels 00650 // in the original MS. 00651 // If the MS does not contain all polarizations, only the parallel 00652 // hand polarizations are used. 00653 00654 // void writeVisCorrected (const Matrix<CStokesVector>& vis); 00655 // void writeVisModel (const Matrix<CStokesVector>& vis); 00656 // void writeVisObserved (const Matrix<CStokesVector>& vis); 00657 00658 // Write/modify the visibilities 00659 // This writes the data as found in the MS, Cube(npol,nchan,nrow). 00660 00661 void writeVisCorrected (const Cube <Complex> & vis); 00662 void writeVisModel (const Cube <Complex> & vis); 00663 void writeVisObserved (const Cube <Complex> & vis); 00664 00665 // Write/modify the weights 00666 00667 void writeWeight(const Matrix<Float>& wt); 00668 00669 // Write/modify the weightMat 00670 00671 //virtual void writeWeightMat(const Matrix<Float>& wtmat); 00672 00673 // Write/modify the weightSpectrum 00674 00675 virtual void writeWeightSpectrum(const Cube<Float>& wtsp); 00676 00677 // Write/modify the Sigma 00678 00679 void writeSigma(const Matrix<Float>& sig); 00680 00681 // Write/modify the ncorr x nrow SigmaMat. 00682 00683 //void writeSigmaMat(const Matrix<Float>& sigmat); 00684 00685 // This puts a model into the descriptor of the current ms in the iterator 00686 // Set iscomponentlist to True if the record represent a componentlist 00687 // if False then it is a FTMachine Record that holds the model image 00688 // note the spw and fields selected are going to be associated with this model 00689 // incremetal =True implies add the model to previous any existant model 00690 // in the ms for the spw and fields 00691 // false means any existant model will be replaces. 00692 00693 void writeModel(const RecordInterface& rec, Bool iscomponentlist=True, 00694 Bool incremental=False); 00695 00696 // Requests that the modified VisBuffer2 be written back to the visibility 00697 // at the same spot that it came from. The dirtyComponents feature of 00698 // VisBuffer is used to mark which portions of the VisBuffer actually need 00699 // to be written back out. 00700 00701 void writeBackChanges (VisBuffer2 *); 00702 00703 //********************************************************************** 00704 // Internal methods below this line 00705 //********************************************************************** 00706 00707 protected: 00708 00709 00710 // VisibilityIterator2 (const VisBufferComponents2 * prefetchColumns, 00711 // const Block<MeasurementSet>& mss, 00712 // const Block<Int>& sortColumns, 00713 // const Bool addDefaultSortCols, 00714 // Double timeInterval, 00715 // Bool writable); 00716 00717 VisibilityIterator2(); 00718 00719 void construct (const VisBufferComponents2 * prefetchColumns, 00720 const Block<MeasurementSet>& mss, 00721 const Block<Int>& sortColumns, 00722 const Bool addDefaultSortCols, 00723 Double timeInterval, 00724 Bool writable); 00725 00726 ViImplementation2 * getImpl() const; 00727 00728 // +------------------+ 00729 // | | 00730 // | Data Accessors | 00731 // | | 00732 // +------------------+ 00733 00734 // These methods are protected and should only be used by subclasses or 00735 // befriended framework member classes. Others should access these values 00736 // via the VisBuffer attached to the VI (see getVisBuffer()). 00737 00738 // Return antenna1 00739 00740 void antenna1(Vector<Int>& ant1) const; 00741 00742 // Return antenna2 00743 00744 void antenna2(Vector<Int>& ant2) const; 00745 00746 // Return feed1 00747 00748 void feed1(Vector<Int>& fd1) const; 00749 00750 // Return feed2 00751 00752 void feed2(Vector<Int>& fd2) const; 00753 00754 // Returns True is this is a new MS from the last subchunk. 00755 00756 Bool isNewMS() const; 00757 00758 // Returns the zero-based index of the current MS in the collection 00759 // of MSs used to create the VI. 00760 00761 Int msId() const; 00762 00763 // Return number of Ant 00764 00765 Int nAntennas () const; 00766 00767 // Return number of rows in all selected ms's 00768 00769 Int nRowsViWillSweep () const; 00770 00771 // Return number of spws, polids, ddids 00772 00773 Int nSpectralWindows () const; 00774 Int nPolarizations () const; 00775 Int nDataDescriptionIds () const; 00776 00777 // Return the number of rows in the current iteration 00778 00779 Int nRows () const; 00780 00781 void jonesC (Vector<SquareMatrix<Complex,2> >& cjones) const; 00782 00783 // Return receptor angles for all antennae and feeds 00784 // First axis of the cube is a receptor number, 00785 // 2nd is antennaId, 3rd is feedId 00786 // Note: the method is intended to provide an access to MSIter::receptorAngles 00787 // for VisBuffer in the multi-feed case. It may be worth to change the 00788 // interface of feed_pa to return the information for all feeds. 00789 00790 const Cube<Double>& receptorAngles() const; 00791 00792 // return a string mount identifier for each antenna 00793 00794 const Vector<String>& antennaMounts() const; 00795 00796 // Return a cube containing pairs of coordinate offsets for each 00797 // receptor of each feed (values are in radians, coordinate system is fixed 00798 // with antenna and is the same one as used to define the BEAM_OFFSET 00799 // parameter in the feed table). The cube axes are receptor, antenna, feed. 00800 00801 const Cube<RigidVector<Double, 2> >& getBeamOffsets() const; 00802 00803 // True if all elements of the cube returned by getBeamOffsets are zero 00804 00805 Bool allBeamOffsetsZero() const; 00806 00807 // Return feed parallactic angles Vector(nant) (1 feed/ant) 00808 00809 const Vector<Float> & feed_pa(Double time) const; 00810 00811 static Vector<Float> feed_paCalculate(Double time, MSDerivedValues & msd, 00812 Int nAntennas, const MEpoch & mEpoch0, 00813 const Vector<Float> & receptor0Angle); 00814 00815 // Return nominal parallactic angle at specified time 00816 // (does not include feed position angle offset--see feed_pa) 00817 // A global value for all antennas (e.g., small array) 00818 00819 const Float& parang0(Double time) const; 00820 00821 static Float parang0Calculate (Double time, MSDerivedValues & msd, 00822 const MEpoch & epoch0); 00823 00824 // Per antenna: 00825 00826 const Vector<Float> & parang(Double time) const; 00827 00828 static Vector<Float> parangCalculate (Double time, MSDerivedValues & msd, 00829 int nAntennas, const MEpoch mEpoch0); 00830 00831 // Return the antenna AZ/EL Vector(nant) 00832 00833 MDirection azel0(Double time) const; 00834 00835 static void azel0Calculate (Double time, MSDerivedValues & msd, 00836 MDirection & azel0, const MEpoch & mEpoch0); 00837 const Vector<MDirection> & azel(Double time) const; 00838 static void azelCalculate (Double time, 00839 MSDerivedValues & msd, 00840 Vector<MDirection> & azel, 00841 Int nAnt, 00842 const MEpoch & mEpoch0); 00843 00844 // Return the hour angle for the specified time 00845 00846 Double hourang(Double time) const; 00847 static Double hourangCalculate (Double time, MSDerivedValues & msd, 00848 const MEpoch & mEpoch0); 00849 00850 // Return the current FieldId 00851 00852 void fieldIds(Vector<Int>&) const; 00853 00854 // Return the current ArrayId 00855 00856 void arrayIds (Vector<Int>&) const; 00857 00858 // Return the current Field Name 00859 00860 String fieldName() const; 00861 00862 // Return the current Source Name 00863 00864 String sourceName() const; 00865 00866 // Return flag for each polarization, channel and row 00867 00868 virtual void flag(Cube<Bool>& flags) const; 00869 00870 // Return flag for each channel & row 00871 00872 virtual void flag(Matrix<Bool>& flags) const; 00873 00874 // Determine whether FLAG_CATEGORY is valid. 00875 00876 Bool existsFlagCategory() const; 00877 00878 // Return flags for each polarization, channel, category, and row. 00879 00880 virtual void flagCategory(Array<Bool>& flagCategories) const; 00881 00882 // Return row flag 00883 00884 virtual void flagRow(Vector<Bool>& rowflags) const; 00885 00886 // Return scan number 00887 00888 virtual void scan(Vector<Int>& scans) const; 00889 00890 // Return the OBSERVATION_IDs 00891 00892 virtual void observationId(Vector<Int>& obsids) const; 00893 00894 // Return the PROCESSOR_IDs 00895 00896 virtual void processorId(Vector<Int>& procids) const; 00897 00898 // Return the STATE_IDs 00899 00900 virtual void stateId(Vector<Int>& stateids) const; 00901 00902 // Return the current phase center as an MDirection 00903 00904 virtual const MDirection& phaseCenter() const; 00905 00906 // Return frame for polarization (returns PolFrame enum) 00907 00908 virtual Int polFrame() const; 00909 00910 // Return the correlation type (returns Stokes enums) 00911 00912 virtual void corrType(Vector<Int>& corrTypes) const; 00913 00914 // Return sigma 00915 00916 virtual void sigma(Vector<Float>& sig) const; 00917 00918 // Return sigma matrix (pol-dep) 00919 00920 virtual void sigmaMat(Matrix<Float>& sigmat) const; 00921 00922 // Return current SpectralWindow 00923 00924 virtual Int spectralWindow() const; 00925 00926 virtual void spectralWindows(Vector<Int>& spws) const; 00927 00928 // Return current Polarization Id 00929 00930 virtual Int polarizationId() const; 00931 00932 // Return current DataDescription Id 00933 00934 virtual Int dataDescriptionId() const; 00935 00936 virtual void dataDescriptionIds(Vector<Int>& ddis) const; 00937 00938 // Return MJD midpoint of interval. 00939 00940 virtual void time(Vector<Double>& t) const; 00941 00942 // Return MJD centroid of interval. 00943 00944 virtual void timeCentroid(Vector<Double>& t) const; 00945 00946 // Return nominal time interval 00947 00948 virtual void timeInterval(Vector<Double>& ti) const; 00949 00950 // Return actual time interval 00951 00952 virtual void exposure(Vector<Double>& expo) const; 00953 00954 // Return the visibilities as found in the MS, Cube(npol,nchan,nrow). 00955 00956 virtual void visibilityCorrected (Cube<Complex> & vis) const; 00957 virtual void visibilityModel (Cube<Complex> & vis) const; 00958 virtual void visibilityObserved (Cube<Complex> & vis) const; 00959 00960 // Return FLOAT_DATA as a Cube (npol, nchan, nrow) if found in the MS. 00961 virtual void floatData (Cube<Float> & fcube) const; 00962 00963 // Return the visibility 4-vector of polarizations for each channel. 00964 // If the MS doesn't contain all polarizations, it is assumed it 00965 // contains one or two parallel hand polarizations. 00966 00967 // virtual void visibilityCorrected (Matrix<CStokesVector> & vis) const; 00968 // virtual void visibilityModel (Matrix<CStokesVector> & vis) const; 00969 // virtual void visibilityObserved (Matrix<CStokesVector> & vis) const; 00970 00971 // Return the shape of the visibility Cube 00972 00973 virtual IPosition visibilityShape() const; 00974 00975 // Return u,v and w (in meters) 00976 00977 virtual void uvw(Matrix<Double>& uvw) const; 00978 00979 // Return weight 00980 00981 virtual void weight(Vector<Float>& wt) const; 00982 00983 // Returns the nPol_p x curNumRow_p weight matrix 00984 00985 virtual void weightMat(Matrix<Float>& wtmat) const; 00986 00987 // Determine whether WEIGHT_SPECTRUM exists. 00988 00989 Bool existsWeightSpectrum() const; 00990 00991 // Return weightspectrum (a weight for each channel) 00992 00993 virtual void weightSpectrum(Cube<Float>& wtsp) const; 00994 00995 // Returns a vector of the correlation types that were selected 00996 // into the current subchunk's data. If Vector<Int> c = vi.getCorrelations(); 00997 // Then c[0] will return the correlation type (as defined in the polarization 00998 // table) of the first correlation part of a data item (e.g., for a visCube, 00999 // all elements having the first dimension index of zero will be c[0] type 01000 // correlations). 01001 01002 Vector<Int> getCorrelations () const; 01003 01004 01005 Vector<Double> getFrequencies (Double time, Int frameOfReference) const; 01006 Vector<Int> getChannels (Double time, Int frameOfReference) const; 01007 01008 // Convert the frequency from the observe frame to lsr frame. 01009 // Returns True in convert if given spw was not observed 01010 // in the LSRK frame 01011 //when ignoreconv=True...no conversion is done from data frame 01012 //frequency is served as is 01013 01014 Int getDataDescriptionId () const; 01015 const MeasurementSet & getMeasurementSet() const;; 01016 Int getMeasurementSetId() const; 01017 Int getNAntennas () const; 01018 MEpoch getEpoch () const; 01019 Vector<Float> getReceptor0Angle (); 01020 01021 // Return the row ids as from the original root table. This is useful 01022 // to find correspondance between a given row in this iteration to the 01023 // original ms row. 01024 01025 void getRowIds (Vector<uInt> &) const; 01026 01027 Bool newFieldId() const; 01028 01029 // Return True if arrayID has changed since last iteration 01030 01031 Bool newArrayId() const; 01032 01033 // Return True if SpectralWindow has changed since last iteration 01034 01035 Bool newSpectralWindow() const; 01036 01037 static String getAipsRcBase () { return "VisibilityIterator2.async";} 01038 01039 // +-------------------------------+ 01040 // | | 01041 // | Internal Management Methods | 01042 // | | 01043 // +-------------------------------+ 01044 01045 void getSpwInFreqRange(Block<Vector<Int> >& spw, 01046 Block<Vector<Int> >& start, 01047 Block<Vector<Int> >& nchan, 01048 Double freqStart, 01049 Double freqEnd, 01050 Double freqStep, 01051 MFrequency::Types freqFrame=MFrequency::LSRK); 01052 01053 //Get the frequency range of the data selection 01054 01055 void getFreqInSpwRange(Double& freqStart, 01056 Double& freqEnd, 01057 MFrequency::Types freqframe = MFrequency::LSRK); 01058 01059 bool existsColumn (VisBufferComponent2 id) const; 01060 01061 // advance the iteration 01062 01063 void originChunks(Bool forceRewind); 01064 01065 private: 01066 01067 ViImplementation2 * impl_p; 01068 }; 01069 01070 } // end namespace vi 01071 01072 } //# NAMESPACE CASA - END 01073 01074 #endif