casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CalSet.h
Go to the documentation of this file.
00001 //# CalSet.h: Definition for Calibration parameter cache
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 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 
00028 #ifndef CALTABLES_CALSET_H
00029 #define CALTABLES_CALSET_H
00030 #include <casa/aips.h>
00031 #include <casa/BasicSL/Constants.h>
00032 #include <casa/BasicSL/Complex.h>
00033 #include <casa/Arrays.h>
00034 #include <casa/OS/File.h>
00035 #include <casa/Logging/LogMessage.h>
00036 #include <casa/Logging/LogSink.h>
00037 #include <synthesis/CalTables/CalTableDesc2.h>
00038 #include <synthesis/CalTables/CalTable2.h>
00039 #include <synthesis/CalTables/SolvableCalSetMCol.h>
00040 #include <synthesis/CalTables/VisCalEnum.h>
00041 //#include <synthesis/CalTables/BaseCalSet.h>
00042 
00043 // #include <synthesis/MeasurementComponents/VisJones.h>
00044 // #include <synthesis/MeasurementEquations/VisEquation.h>
00045 
00046 namespace casa { //# NAMESPACE CASA - BEGIN
00047 
00048 
00049 template<class T>
00050 class CalSet 
00051 {
00052 public:
00053 
00054   // Null ctor does nothing
00055   CalSet() {};
00056 
00057   // Minimal, knows only how many potential spws
00058   //   (solve context)
00059   CalSet(const Int& nSpw);
00060 
00061   // From full shape
00062   CalSet(const Int& nSpw,
00063          const Int& nPar,
00064          const Vector<Int>& nChan,
00065          const Int& nElem,
00066          const Vector<Int>& nTime);
00067 
00068 
00069   // From existing CalTable
00070   //   (apply context)
00071   //   (for now, we will verify that filled solutions match nPar,nElem,nSpw)
00072   CalSet(const String& calTableName,
00073          const String& select,
00074          const Int& nSpw,
00075          const Int& nPar,
00076          const Int& nElem);
00077 
00078   // Copy
00079   CalSet(const CalSet& other);
00080 
00081   // Assignment
00082   //  virtual CalSet& operator=(const CalSet& other);
00083 
00084   // Destructor
00085   virtual ~CalSet();
00086 
00087   // Resize caches
00088   void resize(const Int& nPar,
00089               const Vector<Int>& nChan,
00090               const Int& nElem,
00091               const Vector<Int>& nTime);
00092 
00093   // Access to shape info:
00094   Int& nSpw() { return nSpw_; };
00095   Int& nPar() { return nPar_; };
00096   Vector<Int>& nChan()  { return nChan_; };
00097   Int& nChan(const Int& spw)  { return nChan_(spw); };
00098   Int& nElem()  { return nElem_; };
00099   Vector<Int>& nTime()  { return nTime_; };
00100   Int& nTime(const Int& spw) { return nTime_(spw); };
00101 
00102   //  IPosition& shape(const Int& spw) { return IPosition(4,nPar(),nChan(spw),nElem(),nTime(spw)); };
00103   IPosition shape(const Int& spw) { return IPosition(4,nPar_,nChan_(spw),nElem_,nTime_(spw)); };
00104 
00105   // Set up spwOK according to solution availability
00106   inline void setSpwOK() { spwOK_ = (nTime()!=0); };
00107 
00108   // Report if solutions available for specified spw
00109   Vector<Bool> spwOK() { return spwOK_; };
00110 
00111   // Freq list per spw
00112   Vector<Double>& frequencies(const Int& spw) { return *freq_[spw]; };
00113 
00114   // Temporary method to support current conventions in SVJ
00115   void setStartChan(const Vector<Int>& startChan) {startChan_ = startChan;};
00116   Vector<Int>& startChan() {return startChan_;};
00117 
00118   // Access to whole solution caches 
00119   Vector<Double>& startTime(const Int& spw)    { return *MJDStart_[spw]; };
00120   Vector<Double>& stopTime(const Int& spw)     { return *MJDStop_[spw]; };
00121   Vector<Double>& time(const Int& spw)         { return *MJDTimeStamp_[spw]; };
00122   Vector<Int>&    fieldId(const Int& spw)      { return *fieldId_[spw]; };
00123   Vector<String>& fieldName(const Int& spw)    { return *fieldName_[spw]; };
00124   Vector<String>& sourceName(const Int& spw)   { return *sourceName_[spw]; };
00125   Array<T>&       par(const Int& spw)          { return *par_[spw]; };
00126   Array<Bool>&    parOK(const Int& spw)        { return *parOK_[spw]; };
00127   Array<Float>&   parErr(const Int& spw)       { return *parErr_[spw]; };
00128   Array<Float>&   parSNR(const Int& spw)       { return *parSNR_[spw]; };
00129 
00130   // Statistics
00131   //  Matrix<Bool>&   iSolutionOK(const Int& spw)  { return *iSolutionOK_[spw]; };
00132   Matrix<Float>&  iFit(const Int& spw)         { return *iFit_[spw]; };
00133   Matrix<Float>&  iFitwt(const Int& spw)       { return *iFitwt_[spw]; };
00134   Vector<Bool>&   solutionOK(const Int& spw)   { return *solutionOK_[spw]; };
00135   Vector<Float>&  fit(const Int& spw)          { return *fit_[spw]; };
00136   Vector<Float>&  fitwt(const Int& spw)        { return *fitwt_[spw]; };
00137 
00138   // Store/Retrieve solutions to/from a table.
00139   //  (will evolve to use table iteration)
00140   virtual void initCalTableDesc(const String& type, const Int& parType);
00141   virtual void attach();
00142   virtual void store(const String& file, const String& type, const Bool& append,
00143                      const String& msname="");
00144 //   virtual void store(const String& file, const String& type, 
00145 //                   const String& msname, const Bool& append);
00146   virtual void load(const String& file, const String& select);
00147 
00148 protected:
00149 
00150 
00151 private:
00152 
00153   // new/delete of cache
00154   void inflate();
00155   void deflate();
00156 
00157 
00158   // Table name
00159   String calTableName_;
00160 
00161   // Number of Spectral windows
00162   Int nSpw_;
00163 
00164   // Number of parameters describing this calibration component
00165   Int nPar_;
00166 
00167   // Number of channels
00168   Vector<Int> nChan_;          // (nSpw_) number of _soln_ channels per spw
00169 
00170   // Number of elements (ants or baselines)
00171   Int nElem_;
00172 
00173   // Number of time slots
00174   Vector<Int> nTime_;         // (nSpw_) number of slots per spw
00175 
00176   // Spw OK?
00177   Vector<Bool> spwOK_;
00178 
00179   // Channel frequencies, etc.
00180   Vector<Int> startChan_;            // (nSpw_) start data channel per spw
00181   PtrBlock<Vector<Double>*> freq_;   // [nSpw_](nChan_)
00182 
00183   // Per spw, per slot Meta information
00184   PtrBlock<Vector<Double>*> MJDStart_;       // (nSpw_)(numberSlots_)
00185   PtrBlock<Vector<Double>*> MJDStop_;        // (nSpw_)(numberSlots_)
00186   PtrBlock<Vector<Double>*> MJDTimeStamp_;   // (nSpw_)(numberSlots_)
00187   PtrBlock<Vector<Int>*>    fieldId_;        // (nSpw_)(numberSlots_)
00188   PtrBlock<Vector<String>*> fieldName_;      // (nSpw_)(numberSlots_)
00189   PtrBlock<Vector<String>*> sourceName_;     // (nSpw_)(numberSlots_)
00190 
00191   // Per spw, per channel, per element, per slot solution generic PARAMETER storage  
00192   PtrBlock<Array<T>*>      par_;    // (nSpw_)(nPar_,nSolnChan_,nElem_,numberSlots_)
00193   PtrBlock<Array<Bool>*>   parOK_;  // (nSpw_)(nPar_,nSolnChan_,nElem_,numberSlots_)
00194   PtrBlock<Array<Float>*>  parErr_; // (nSpw_)(nPar_,nSolnChan_,nElem_,numberSlots_)
00195   PtrBlock<Array<Float>*>  parSNR_; // (nSpw_)(nPar_,nSolnChan_,nElem_,numberSlots_)
00196 
00197   // Statistics
00198   //  PtrBlock<Matrix<Bool>*> iSolutionOK_;  // [nSpw_](nElem_,nSlots_)
00199   PtrBlock<Matrix<Float>*> iFit_;        // [nSpw_](nElem_,nSlots_)
00200   PtrBlock<Matrix<Float>*> iFitwt_;      // [nSpw_](nElem_,nSlots_)
00201 
00202   PtrBlock<Vector<Bool>*> solutionOK_;   // [nSpw_](numberSlots_)
00203   PtrBlock<Vector<Float>*> fit_;         // [nSpw_](numberSlots_)
00204   PtrBlock<Vector<Float>*> fitwt_;       // [nSpw_](numberSlots_)
00205 
00206   LogSink logSink_p;
00207   LogSink& logSink() {return logSink_p;};
00208 
00209   CalTableDesc2 *calTabDesc_;
00210   CalTable2 *calTab_;
00211   SolvableCalSetMCol<T> *svjmcol_;
00212 
00213 };
00214 
00215 // Globals
00216 
00217 // Smooth the solutions in a CalSet
00218   void smooth(CalSet<Complex>& cs,
00219               const String& smtype,
00220               const Double& smtime,
00221               Vector<Int> selfields);
00222 
00223 } //# NAMESPACE CASA - END
00224 
00225 #ifndef AIPS_NO_TEMPLATE_SRC
00226 #include <synthesis/CalTables/CalSet.tcc>
00227 #endif
00228 
00229 #endif