casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CalInterp.h
Go to the documentation of this file.
00001 //# CalInterp.h: Definition for Calibration parameter Interpolation
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_CALINTERP_H
00029 #define CALTABLES_CALINTERP_H
00030 #include <casa/aips.h>
00031 #include <casa/BasicSL/Constants.h>
00032 #include <synthesis/CalTables/CalSet.h>
00033 #include <casa/OS/File.h>
00034 #include <casa/Logging/LogMessage.h>
00035 #include <casa/Logging/LogSink.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 
00040 class CalInterp
00041 {
00042 public:
00043 
00044   // Null ctor does nothing
00045   CalInterp() {};
00046 
00047   // From CalSet 
00048   CalInterp(CalSet<Complex>& cs,
00049             const String& timetype,
00050             const String& freqtype);
00051 
00052   // Destructor
00053   virtual ~CalInterp();
00054 
00055 
00056   // Set non-trivial spw mapping
00057   void setSpwMap(const Vector<Int>& spwmap) {spwMap_ = spwmap; setSpwOK();};
00058 
00059   // Interpolate, given timestamp, spw, freq list; returns T if new result
00060   Bool interpolate(const Double& time,
00061                    const Int& spw,
00062                    const Vector<Double>& freq=Vector<Double>());
00063 
00064   // Do time-dep interpolation (called by interpolate)
00065   Bool interpTime(const Double& time);
00066 
00067   // Do freq-dep interpolation (called by interpolate)
00068   void interpFreq(const Vector<Double>& freq);
00069 
00070   // Timestamp of current Slot
00071   Double slotTime() { return csTimes()(currSlot()); };
00072 
00073   // Access to result (by reference)
00074   inline Cube<Complex>& result() { return r; };
00075   inline Cube<Bool>& resultOK() { return ok; };
00076 
00077   // Spwmap-sensitive spwOK()
00078   inline Vector<Bool> spwOK() { return spwOK_; };
00079 
00080   // Set spwOK_ according to spwmap  RI made public 200910
00081   void setSpwOK();
00082 
00083 protected:
00084 
00085   // Find the reference timeslot for requested time
00086   Bool findSlot(const Double& time);
00087 
00088   void updTimeCoeff();
00089 
00090   void interpTimeCalc(const Double& time);
00091 
00092   void initFreqInterp(const Vector<Double> freq);
00093 
00094   void calcAPC();
00095 
00096   void updFreqCoeff();
00097 
00098   void interpFreqCalc();
00099 
00100   void finalize();
00101 
00102   void inflTimeC();
00103   void inflFreqC();
00104   void deflTimeC();
00105   void deflFreqC();
00106   void deflFreqA();
00107 
00108   // Access to private shape data (reflecting CalSet)
00109   inline Int& nSpw()  { return cs_->nSpw();  };
00110   inline Int& nPar()  { return cs_->nPar();  };
00111   inline Int& nElem() { return cs_->nElem(); };
00112 
00113   // Access to imutable private data
00114   inline String& timeType()  { return timeType_; };
00115   inline Bool   nearestT() { return (timeType()=="nearest"); };
00116   inline Bool   linearT()  { return (timeType()=="linear"); };
00117   inline Bool   aipslinT() { return (timeType()=="aipslin"); };
00118   inline String& freqType()  { return freqType_; };
00119   inline Bool   nearestF() { return (freqType()=="nearest"); };
00120   inline Bool   linearF()  { return (freqType()=="linear"); };
00121   inline Bool   aipslinF() { return (freqType()=="aipslin"); };
00122 
00123   inline Vector<Int>& spwMap()  { return spwMap_; };
00124   inline Int spwMap(const Int& spw) { return ((spwMap_(spw)>-1) ? spwMap_(spw) : spw); };
00125 
00126   // Access to info relevant to currSpw
00127   inline Int& currSpw()     { return currSpw_; };
00128   inline Int currSpwMap()  { return spwMap(currSpw()); };
00129   inline Int& currSlot()    { return currSlot_(currSpw()); };
00130   inline Int& nFreq()       { return nFreq_(currSpw()); };
00131   inline Vector<Double>& datFreq() { return (*datFreq_[currSpw()]); };
00132   inline Bool& finit()      { return finit_(currSpw()); };
00133   inline Double& lastTime() { return lastTime_(currSpw_); };
00134   inline Bool& exactTime()  { return exactTime_; };
00135 
00136   // Access to in-focus portion of CalSet (spwmap'd)
00137   inline Int& nTime()              { return cs_->nTime(currSpwMap()); };
00138   inline Int& nChan()              { return cs_->nChan(currSpwMap()); }
00139   inline Vector<Double>& csTimes() { return cs_->time(currSpwMap()); };
00140   inline Vector<Double>& csFreq()  { return cs_->frequencies(currSpwMap()); };
00141   inline Array<Complex>& csPar()   { return cs_->par(currSpwMap()); };
00142   inline Array<Bool>&    csParOK() { return cs_->parOK(currSpwMap()); };
00143 
00144   // Access to IPositions
00145   inline IPosition&  ip4d() { return (*ip4d_[currSpw_]); };
00146   inline IPosition&  ip3d() { return (*ip3d_[currSpw_]); };
00147   inline IPosition&  ip2d() { return (*ip2d_[currSpw_]); };
00148 
00149   // Access to in-focus interpolation abscissa data
00150   inline Double&         t0()  {return t0_(currSpw_);};
00151   inline Double&         tS()  {return tS_(currSpw_);};
00152   inline Int&        lastlo()  {return lastlo_(currSpw_); };
00153 
00154   inline Vector<Int>&    ch0() {return (*ch0_[currSpw_]); };
00155   inline Vector<Bool>&   ef()  {return (*ef_[currSpw_]); };
00156   inline Vector<Double>& df()  {return (*df_[currSpw_]); };
00157   inline Vector<Double>& fdf() {return (*df_[currSpw_]); };
00158 
00159   // In-focus Time Interpolation coefficients 
00160   inline Array<Float>&   tAC() {return (*tAC_[currSpw()]); };
00161   inline Array<Float>&   tPC() {return (*tPC_[currSpw()]); };
00162   inline Array<Complex>& tCC() {return (*tCC_[currSpw()]); };
00163   inline Cube<Bool>&     tOk() {return (*tOk_[currSpw()]); };
00164 
00165   // In-focus Freq Interpolation coefficients
00166   inline Array<Float>&   fAC() {return (*fAC_[currSpw()]); };
00167   inline Array<Float>&   fPC() {return (*fPC_[currSpw()]); };
00168   inline Array<Complex>& fCC() {return (*fCC_[currSpw()]); };
00169   inline Cube<Bool>&     fOk() {return (*fOk_[currSpw()]); };
00170 
00171   inline void rPart(Array<Complex>& c,Array<Float>& rp) { return part(c,0,rp); };
00172   inline void iPart(Array<Complex>& c,Array<Float>& ip) { return part(c,1,ip); };
00173 
00174   void asFloatArr(const Array<Complex>& in, Array<Float>& out);
00175 
00176   void part(const Array<Complex>& c, const Int& which, Array<Float>& f);
00177 
00178 private:
00179 
00180   // The CalSet from which we interpolate
00181   CalSet<Complex>* cs_;
00182 
00183   // Interpolation modes
00184   String timeType_, freqType_;
00185 
00186   // Spw map
00187   Vector<Int> spwMap_;
00188 
00189   // SpwOK
00190   Vector<Bool> spwOK_;
00191 
00192   // Prior interp time, per spw
00193   Vector<Double> lastTime_;
00194 
00195   // Frequency initialization flag (True if init complete)
00196   Vector<Bool> finit_;
00197 
00198   // Number of channels
00199   Vector<Int> nFreq_;          // (nSpw_) number of _data_ channels per spw
00200 
00201   // Freq lists
00202   PtrBlock<Vector<Double>*> solFreq_;   // [nSpw](nChan)
00203   PtrBlock<Vector<Double>*> datFreq_;   // [nSpw](nFreq)
00204 
00205   Int currSpw_;
00206   Vector<Int> currSlot_;
00207 
00208   // Exact time match flag
00209   Bool exactTime_;
00210 
00211   Cube<Float> a,p;    // For referencing interp results
00212   Cube<Complex> c;
00213   Cube<Bool> ok;
00214 
00215   Cube<Complex> r, r_;
00216 
00217   // Array shapes
00218   PtrBlock<IPosition*> ip4d_;     // [nSpw]
00219   PtrBlock<IPosition*> ip3d_;     // [nSpw]
00220   PtrBlock<IPosition*> ip2d_;     // [nSpw]
00221 
00222   // Time Interpolation ordinate info (per spw)
00223   Vector<Double>            t0_;         // (nSpw)
00224   Vector<Double>            tS_;         // (nSpw)
00225   Vector<Int>               lastlo_;     // (nSpw)
00226 
00227   // Time Interpolation coefficients (per spw)
00228   PtrBlock<Array<Float>*>   tAC_, tPC_;  // [nSpw](2,nPar,nChan,nElem)
00229   PtrBlock<Array<Complex>*> tCC_;        // [nSpw](2,nPar,nChan,nElem)
00230   PtrBlock<Cube<Bool>*>     tOk_;        // [nSpw](nPar,nChan,nElem)
00231 
00232   // Time Interpolation results (currSpw)
00233   Cube<Float>    tA_, tP_;    // (nPar,nChan,nElem)
00234   Cube<Complex>  tC_;         // (nPar,nChan,nElem)
00235 
00236   // Freq Interpolation ordinate info (per spw)
00237   PtrBlock<Vector<Int>*>    ch0_;        // [nSpw](nFreq)
00238   PtrBlock<Vector<Bool>*>   ef_;         // [nSpw](nFreq)
00239   PtrBlock<Vector<Double>*> df_;         // [nSpw](nFreq)
00240   PtrBlock<Vector<Double>*> fdf_;        // [nSpw](nFreq)
00241 
00242   // Freq Interpolation coefficients (per spw)
00243   PtrBlock<Array<Float>*>   fAC_, fPC_;  // [nSpw](2,nPar,nFreq,nElem)
00244   PtrBlock<Array<Complex>*> fCC_;        // [nSpw](2,nPar,nFreq,nElem)
00245   PtrBlock<Cube<Bool>*>     fOk_;        // [nSpw](nPar,nFreq,nElem)
00246 
00247   // Freq Interpolation results (currSspw)
00248   Cube<Float>    fA_, fP_;               // (nPar,nFreq,nElem)
00249   Cube<Complex>  fC_;                    // (nPar,nFreq,nElem)
00250 
00251   LogSink logSink_p;
00252   LogSink& logSink() {return logSink_p;};
00253 
00254   Bool verbose_;
00255 
00256 };
00257 
00258 
00259 } //# NAMESPACE CASA - END
00260 
00261 #endif