casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
CTPatchedInterp.h
Go to the documentation of this file.
00001 //# CTPatchedInterp.h: Definition for Calibration patch panel
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_CTPATCHEDINTERP_H
00029 #define CALTABLES_CTPATCHEDINTERP_H
00030 
00031 #include <synthesis/CalTables/NewCalTable.h>
00032 #include <synthesis/CalTables/CTTimeInterp1.h>
00033 #include <synthesis/CalTables/RIorAParray.h>
00034 #include <synthesis/CalTables/VisCalEnum.h>
00035 #include <scimath/Mathematics/InterpolateArray1D.h>
00036 #include <casa/Arrays/Array.h>
00037 #include <casa/Arrays/Matrix.h>
00038 #include <casa/Arrays/Cube.h>
00039 #include <ms/MeasurementSets/MeasurementSet.h>
00040 #include <ms/MeasurementSets/MSField.h>
00041 #include <ms/MeasurementSets/MSColumns.h>
00042 #include <casa/aips.h>
00043 
00044 //#include <casa/BasicSL/Constants.h>
00045 //#include <casa/OS/File.h>
00046 //#include <casa/Logging/LogMessage.h>
00047 //#include <casa/Logging/LogSink.h>
00048 
00049 namespace casa { //# NAMESPACE CASA - BEGIN
00050 
00051 
00052 class CTPatchedInterp
00053 {
00054 public:
00055 
00056   // From NewCalTable only 
00057   CTPatchedInterp(NewCalTable& ct,
00058                   VisCalEnum::MatrixType mtype,
00059                   Int nPar,
00060                   const String& timetype,
00061                   const String& freqtype,
00062                   const String& fieldtype,
00063                   Vector<Int> spwmap=Vector<Int>());
00064 
00065   // From NewCalTable and MS 
00066   CTPatchedInterp(NewCalTable& ct,
00067                   VisCalEnum::MatrixType mtype,
00068                   Int nPar,
00069                   const String& timetype,
00070                   const String& freqtype,
00071                   const String& fieldtype,
00072                   const MeasurementSet& ms,
00073                   Vector<Int> spwmap=Vector<Int>());
00074 
00075   // From NewCalTable and MSColumns 
00076   CTPatchedInterp(NewCalTable& ct,
00077                   VisCalEnum::MatrixType mtype,
00078                   Int nPar,
00079                   const String& timetype,
00080                   const String& freqtype,
00081                   const String& fieldtype,
00082                   const ROMSColumns& mscol,
00083                   Vector<Int> spwmap=Vector<Int>());
00084 
00085 
00086   // Destructor
00087   virtual ~CTPatchedInterp();
00088 
00089   // Interpolate, given input field, spw, timestamp, & (optionally) freq list
00090   //    returns T if new result (anywhere)
00091   Bool interpolate(Int obs, Int fld, Int spw, Double time, Double freq=-1.0);
00092   Bool interpolate(Int obs, Int fld, Int spw, Double time, const Vector<Double>& freq);
00093 
00094   // Access to the result
00095   Array<Float>& resultF(Int obs, Int fld, Int spw) { return result_(spw,fld,thisobs(obs)); };
00096   Array<Complex> resultC(Int obs, Int fld, Int spw) { return RIorAPArray(result_(spw,fld,thisobs(obs))).c(); };
00097   Array<Bool>& rflag(Int obs, Int fld, Int spw) { return resFlag_(spw,fld,thisobs(obs)); };
00098 
00099   // Temporary public function for testing
00100   Array<Float>& tresultF(Int obs, Int fld, Int spw) { return timeResult_(spw,fld,thisobs(obs)); };
00101   Array<Bool>& tresultFlag(Int obs, Int fld, Int spw) { return timeResFlag_(spw,fld,thisobs(obs)); };
00102 
00103   // spwOK info for users
00104   Bool spwOK(Int spw) const;
00105   Bool spwInOK(Int spw) const;
00106 
00107   // Const access to various state
00108   // TBD
00109 
00110   // Report state
00111   void state();
00112 
00113 private:
00114 
00115   // Null ctor does nothing
00116   CTPatchedInterp() :mtype_(VisCalEnum::GLOBAL) {};
00117   
00118   // Setup methods
00119   void sliceTable();
00120   void makeInterpolators();
00121 
00122   Int thisobs(Int obs) { return (byObs_?obs:0); };
00123 
00124   // Methods to set up 1:1 patch-panel maps
00125   //  Private for now as not yet ready to control from outside
00126   // Field
00127   // default: all 0 (no field-dep yet)
00128   void setDefFldMap() {fldMap_.resize(nMSFld_); fldMap_.set(0);};
00129   void setFldMap(const MSField& msfld);           // via nearest on-sky
00130   void setFldMap(const ROMSFieldColumns& fcol);  // via nearest on-sky
00131   //void setFldMap(Vector<Int>& field);        // via ordered index list
00132   //void setFldMap(Vector<String>& field);     // via name matching
00133   //void setFldMap(uInt to, uInt from);        // via single to/from 
00134 
00135   // Spw
00136   // default: indgen (index identity)
00137   void setDefSpwMap() {spwMap_.resize(nMSSpw_); indgen(spwMap_);};
00138   void setSpwMap(Vector<Int>& spwmap);
00139   //void setSpwMap(Vector<Double>& refFreqs);  // via refFreq matching
00140   //void setSpwMap(uInt to, uInt from);        // via single to/from
00141 
00142   // Antenna
00143   // default: indgen (index identity) 
00144   void setDefAntMap() {antMap_.resize(nMSAnt_); indgen(antMap_);};
00145   //void setAntMap(Vector<Int>& ant);          // via ordered index list
00146   //void setAntMap(Vector<String>& ant);       // via name/station matching
00147   //void setAntMap(uInt to, uInt from);        // via single to/from
00148 
00149   // Set generic antenna/baseline map
00150   void setElemMap();
00151 
00152   // Resample in frequency
00153   void resampleInFreq(Matrix<Float>& fres,Matrix<Bool>& fflg,const Vector<Double>& fout,
00154                       Matrix<Float>& tres,Matrix<Bool>& tflg,const Vector<Double>& fin);
00155 
00156   // Baseline index from antenna indices: (assumes a1<=a2 !!)
00157   inline Int blnidx(const Int& a1, const Int& a2, const Int& nAnt) { return  a1*nAnt-a1*(a1+1)/2+a2; };
00158 
00159   // Translate freq axis interpolation string
00160   InterpolateArray1D<Double,Float>::InterpolationMethod ftype(String& strtype);
00161 
00162 
00163   // PRIVATE DATA:
00164   
00165   // The Caltable
00166   NewCalTable ct_;
00167 
00168   // Matrix type
00169   VisCalEnum::MatrixType mtype_;
00170 
00171   // Are parameters fundamentally complex?
00172   Bool isCmplx_;
00173 
00174   // The number of (Float) parameters (per-chan, per-element)
00175   Int nPar_, nFPar_;
00176 
00177   // Interpolation modes
00178   String timeType_, freqType_;
00179 
00180   InterpolateArray1D<Double,Float>::InterpolationMethod ia1dmethod_;
00181 
00182   // Are we slicing caltable by field?
00183   Bool byObs_,byField_;
00184 
00185   // CalTable freq axis info
00186   Vector<Int> nChanIn_;
00187   Vector<Vector<Double> > freqIn_;
00188 
00189 
00190   // Obs, Field, Spw, Ant _output_ (MS) sizes 
00191   //   calibration required for up to this many
00192   Int nMSObs_, nMSFld_, nMSSpw_, nMSAnt_, nMSElem_;
00193 
00194   // Alternate field indices
00195   Vector<Int> altFld_;
00196 
00197   // Obs, Field, Spw, Ant _input_ (CalTable) sizes
00198   //  patch panels should not violate these (point to larger indices)
00199   Int nCTObs_, nCTFld_, nCTSpw_, nCTAnt_, nCTElem_;
00200 
00201   // OK flag
00202   Vector<Bool> spwInOK_;
00203 
00204   // The patch panels
00205   //   Each has length from MS, values refer to CT
00206   Vector<Int> fldMap_, spwMap_, antMap_, elemMap_;
00207 
00208   // Control conjugation of baseline-based solutions when mapping requires
00209   Vector<Bool> conjTab_;
00210 
00211   // Internal result Arrays
00212   Cube<Cube<Float> > timeResult_,freqResult_;   // [nMSSpw_,nMSFld_,nMSObs_][nFpar,nChan,nAnt]
00213   Cube<Cube<Bool> >  timeResFlag_,freqResFlag_; // [nMSSpw_,nMSFld_,nMSObs_][nFpar,nChan,nAnt]
00214 
00215   // Current interpolation result Arrays
00216   //  These will reference time or freq result, depending on context,
00217   //  and may be referenced by external code
00218   Cube<Cube<Float> > result_;     // [nMSSpw_,nMSFld_,nMSObs_][nFpar,nChan,nAnt]
00219   Cube<Cube<Bool> >  resFlag_;    // [nMSSpw_,nMSFld_,nMSObs_][nFpar,nChan,nAnt]
00220 
00221   // The CalTable slices
00222   Array<NewCalTable> ctSlices_;  // [nCTElem_,nCTSpw_,nCTFld_,nCTObs_]
00223 
00224   // The pre-patched Time interpolation engines
00225   //   These are populated by the available caltables slices
00226   Array<CTTimeInterp1*> tI_;  // [nMSElem_,nMSSpw_,nMSFld_,nMSObs_]
00227   Array<Bool> tIdel_;         // [nMSElem_,nMSSpw_,nMSFld_,mMSObs_]
00228 
00229 };
00230 
00231 
00232 } //# NAMESPACE CASA - END
00233 
00234 #endif