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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1