casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VisSet.h
Go to the documentation of this file.
00001 //# VisSet.h: VisSet definitions
00002 //# Copyright (C) 1996,1997,1998,2001,2002
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 adressed 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 //#
00027 //# $Id$
00028 
00029 #ifndef MSVIS_VISSET_H
00030 #define MSVIS_VISSET_H
00031 
00032 #include <casa/aips.h>
00033 #include <casa/BasicSL/Complex.h>
00034 #include <casa/Arrays/Matrix.h>
00035 #include <synthesis/MSVis/StokesVector.h>
00036 #include <synthesis/MSVis/VisibilityIterator.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 // <summary> 
00041 // The interface to the MeasurementSet for synthesis processing
00042 // </summary>
00043 
00044 // <reviewed reviewer="" date="" tests="t" demos="">
00045 
00046 // <prerequisite>
00047 //   <li> <linkto module="MeasurementSet">MeasurementSet</linkto>
00048 // </prerequisite>
00049 //
00050 // <etymology>
00051 // VisSet is the Set of Visibilities
00052 // </etymology>
00053 //
00054 // <synopsis> 
00055 // The VisSet is a class that simplifies access to the visibility data
00056 // for the synthesis processing code. It holds a reference to an original
00057 // MeasurementSet with observed data and creates two extra data
00058 // columns for the storage of model visibilities and
00059 // corrected visibilities. All access to the MeasurementSet is done via
00060 // the <linkto class="VisibilityIterator">VisibilityIterator</linkto>
00061 // and the <linkto class="VisBuffer">VisBuffer</linkto>
00062 //
00063 // The VisSet allows selection and sorting of the MeasurementSet to be applied.
00064 // A number of columns can be specified to define the iteration order, a
00065 // a time interval can be given to iterate in chunks of time and a channel
00066 // selection can be made for each spectral window present in the data.
00067 // </synopsis> 
00068 //
00069 // <example>
00070 // <srcblock>
00071 //    MeasurementSet ms("Example.MS",Table::Update);
00072 //    cout << "Constructing VisSet"<<endl;
00073 //    Block<Int> bi(2); 
00074 //    bi[0]=MS::SPECTRAL_WINDOW_ID;
00075 //    bi[1]=MS::TIME; 
00076 //    Matrix<Int> chanSelection; // no channel selection
00077 //    // iterate in 600s chunks within each SpectralWindow
00078 //    Double interval=600.; 
00079 //    VisSet vs(ms,bi,chanSelection,interval);
00080 // </srcblock>
00081 // </example>
00082 //
00083 // <motivation>
00084 // This class provides an easy interface to the MS. 
00085 // It keeps the iterator around
00086 // for reuse, thus avoiding repeated sorting of the data.
00087 // </motivation>
00088 //
00089 // <todo asof="">
00090 // </todo>
00091 
00092 typedef uInt Antenna;
00093 typedef Double Frequency;
00094 typedef RigidVector<Float,3> Position;
00095 typedef RigidVector<Double,3> Direction;
00096 
00097 typedef Vector<CStokesVector> vvCoh;
00098 
00099 typedef ROVisibilityIterator ROVisIter;
00100 typedef VisibilityIterator VisIter;
00101 
00102 class VisSet {
00103 
00104 public:
00105   // default constructor, only useful to assign to later.
00106   VisSet() {}
00107 
00108   // Construct from a MeasurementSet, with iteration order specified in
00109   // columns (giving the MS enum for the column) 
00110   // Specify channel selection as a Matrix(3,nSpw) where for each
00111   // spectral window the three values are start,nChannel and
00112   // spectral window number. Spectral windows without an entry will have 
00113   // all channels selected.
00114   // Specify a time interval for iterating in 'chunks' of time.
00115   // The default time interval of 0 groups all times together.
00116   // This constructor creates two new columns:
00117   // MODEL_DATA and CORRECTED_DATA
00118   // If they already exist and have the
00119   // same channel selection applied, they are reused.
00120   // Note that the contents of these columns are NOT initialized,
00121   // you should fill them before trying to read the data.
00122   // The MS calibration scratch columns can be optionally compressed.
00123   VisSet(MeasurementSet & ms, const Block<Int>& columns, 
00124          const Matrix<Int>& chanSelection, Double timeInterval=0,
00125          Bool compress=False, Bool doModelData=True);
00126 
00127   // Same as above, but provide scratch column option
00128   VisSet(MeasurementSet& ms,const Block<Int>& columns, 
00129          const Matrix<Int>& chanSelection, 
00130          Bool addScratch,
00131          Double timeInterval=0,Bool compress=False, Bool doModelData=True);
00132 
00133   // This is a constructor for multiple MS...but everything is same as the one 
00134   // above
00135 
00136 
00137   VisSet(Block<MeasurementSet>& mss, const Block<Int>& columns, 
00138          const Block< Matrix<Int> >& chanSelections, Bool addStratch=False, Double timeInterval=0,
00139          Bool compress=False, Bool doModelData=True);
00140 
00141 
00142 
00143 
00144 
00145   // This is a no frills constructor, no re-sorting, the default order is used,
00146   // no scratch columns is made even if they don't exist. So if you use
00147   // this constructor and plan to use the scratch columns make sure 
00148   // that they exist prior to constructing the VisSet this way.
00149   VisSet(MeasurementSet & ms, const Matrix<Int>& chanSelection, 
00150          Double timeInterval=0);
00151 
00152   //Constructor from visibility iterator ....a temporary fix 
00153   //as EPJones as Imager stops using VisSet 
00154   VisSet(ROVisibilityIterator& vi);
00155   // Construct from an existing VisSet, this references the underlying
00156   // MeasurementSet(s) but allows a new iteration order and time interval
00157   // to be specified.
00158   VisSet(const VisSet & vs, const Block<Int>& columns, Double timeInterval=0);
00159 
00160   // Destructor, flushes the data to disk
00161   ~VisSet();
00162   // referencing assignment operator
00163   VisSet& operator=(const VisSet& other);
00164 
00165   // Re-initialize the VisibilityIterator (cf copy ctor)
00166   void resetVisIter(const Block<Int>& columns, Double timeInterval = 0,
00167                     asyncio::PrefetchColumns * prefetchColumns = NULL);
00168 
00169   // Initializes scratch columns
00170   void initCalSet(Int calSet=0);
00171 
00172   // Flushes the data to disk
00173   void flush();
00174   // Iterator access to the  data
00175   VisIter& iter();
00176 
00177   // Reset the channel selection. Only subsets of the original selection
00178   // (set in constructor) can be specified.
00179   // Note: this calls origin on the iterator.
00180   void selectChannel(Int nGroup,Int start, Int width, Int increment, 
00181                      Int spectralWindow);
00182   // call to VisIter origin optional:
00183   void selectChannel(Int nGroup,Int start, Int width, Int increment, 
00184                      Int spectralWindow, Bool callOrigin);
00185 
00186   // Collective selection via MSSelection channel selection Matrix
00187   void selectChannel(const Matrix<Int>& chansel);
00188 
00189   // Set nominal selection to ALL channels
00190   void selectAllChans();
00191 
00192   // number of antennas
00193   Int numberAnt();
00194 
00195   // number of fields
00196   Int numberFld();
00197 
00198   // number of spectral windows
00199   Int numberSpw();
00200 
00201   // number of channels in each spectral window
00202   Vector<Int> numberChan() const;
00203 
00204   // start channel of VisSet selection in each spectral window
00205   Vector<Int> startChan() const;
00206 
00207   // number of coherences
00208   Int numberCoh() const;
00209 
00210   // Lock and unlock the associated MS
00211   void lock() {ms_p.lock();};
00212   void unlock() {ms_p.unlock();};
00213 
00214   // Return the associated MS name
00215   String msName();
00216 
00217   // SYSCAL table name of the associated MS
00218   String sysCalTableName();
00219 
00220   // SPECTRAL_WINDOW table name of the associated MS
00221   String spectralWindowTableName();
00222 
00223   // FIELD table name of the associated MS
00224   String fieldTableName();
00225 
00226   // SYSPOWER table name of the associated MS
00227   String syspowerTableName();
00228 
00229   // CALDEVICE table name of the associated MS
00230   String caldeviceTableName();
00231 
00232 private:
00233 
00234   //Add the scratch columns
00235   void addScratchCols(MeasurementSet& ms, Bool compress=False, Bool doModelData=True);
00236 
00237   // Add a calibration set (comprising a set of CORRECTED_DATA and MODEL_DATA)
00238   // to the MeasurementSet (MS). Optionally compress these columns using the 
00239   // CompressComplex column engine.
00240   void addCalSet(MeasurementSet& ms, Bool compress=True, Bool doModelData=True);
00241   void addCalSet2(MeasurementSet& ms, Bool compress=False, Bool doModelData=True);
00242 
00243  
00244   MeasurementSet ms_p;
00245   VisIter* iter_p;
00246   Matrix<Int> selection_p;
00247   Block<MeasurementSet> *blockOfMS_p;
00248   Bool multims_p;
00249 
00250 };
00251 
00252 
00253 } //# NAMESPACE CASA - END
00254 
00255 #endif
00256 
00257