CLPatchPanel.h

Go to the documentation of this file.
00001 //# CLPatchPanel.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_CLPATCHPANEL_H
00029 #define CALTABLES_CLPATCHPANEL_H
00030 
00031 #include <synthesis/CalTables/NewCalTable.h>
00032 #include <synthesis/CalTables/CTColumns.h>
00033 #include <synthesis/CalTables/CTTimeInterp1.h>
00034 #include <synthesis/CalTables/RIorAParray.h>
00035 #include <synthesis/CalTables/VisCalEnum.h>
00036 #include <scimath/Mathematics/InterpolateArray1D.h>
00037 #include <casa/Arrays/Array.h>
00038 #include <casa/Arrays/Matrix.h>
00039 #include <casa/Arrays/Cube.h>
00040 #include <ms/MeasurementSets/MeasurementSet.h>
00041 #include <ms/MeasurementSets/MSField.h>
00042 #include <ms/MeasurementSets/MSColumns.h>
00043 #include <casa/aips.h>
00044 
00045 //#include <casa/BasicSL/Constants.h>
00046 //#include <casa/OS/File.h>
00047 //#include <casa/Logging/LogMessage.h>
00048 //#include <casa/Logging/LogSink.h>
00049 
00050 namespace casa { //# NAMESPACE CASA - BEGIN
00051 
00052 
00053 // A specialized key class for Calibration patch panel elements
00054 class CalPatchKey
00055 {
00056 public:
00057   CalPatchKey(IPosition keyids);
00058   virtual ~CalPatchKey() {};
00059   virtual Bool operator<(const CalPatchKey& other) const;
00060   virtual String print() const =0;
00061 private:
00062   Vector<Int> cpk_;
00063 };
00064 
00065 class MSCalPatchKey : virtual public CalPatchKey
00066 {
00067 public:
00068   MSCalPatchKey(Int obs,Int fld,Int ent,Int spw,Int ant=-1);
00069   virtual ~MSCalPatchKey(){};
00070   virtual String print() const;
00071 private:
00072   Int obs_,fld_,ent_,spw_,ant_;
00073 };
00074 
00075 
00076 class CTCalPatchKey : virtual public CalPatchKey
00077 {
00078 public:
00079   CTCalPatchKey(Int clsl,Int obs,Int fld,Int spw,Int ant=-1);
00080   virtual ~CTCalPatchKey(){};
00081   virtual String print() const;
00082 private:
00083   Int clsl_,obs_,fld_,spw_,ant_;
00084 };
00085 
00086 // A base class for calmaps
00087 class CalMap
00088 {
00089 public:
00090 
00091   // Null ctor (defaults everything)
00092   CalMap();
00093 
00094   // Construct from a Vector
00095   CalMap(const Vector<Int>& calmap);  
00096 
00097   // Construct from a Record (int:int; TBD: need an MS to parse strings)
00098   //  CalMap(const Record calmap):
00099 
00100   // Construct from a String (an algorithm or selection)
00101   //CalMap(String calmaptype,const NewCalTable& ct, const MeasurementSet ms,
00102   //     Vector<Int> availids=Vector<Int>());
00103   // Construct from String and 2 Vectors (default, and explict to/from override)
00104   // TBD
00105 
00106   // Index method returns the ct id mapped to the specified msid
00107   Int operator()(Int msid) const; // ,const Vector<Int> availids=Vector<Int>()) const;
00108 
00109   // Return the ctids required for a set a msids (from among those available)
00110   //  TBD: what to do if nominally required ctid is UNavailable (return only the avail ones?)
00111   Vector<Int> ctids(const Vector<Int>& msids) const;//   const Vector<Int> availctids=Vector<Int>(0)) const;
00112 
00113   // Return the msids that will be satisfied by a specific ctid
00114   Vector<Int> msids(Int ctid,const Vector<Int>& superset=Vector<Int>()) const;
00115 
00116   // Return the verbatim (Vector) map
00117   Vector<Int> vmap() const { return vcalmap_; };
00118 
00119 protected:
00120   Vector<Int> vcalmap_;  // simple
00121   //Matrix<Int> mcalmap_;  // per-id prioritized, e.g., 'nearest'
00122 };
00123 
00124 class FieldCalMap : public CalMap
00125 {
00126 public:
00127 
00128   // Null ctor
00129   FieldCalMap();
00130 
00131   // Construct from Vector<Int> (override CalMap)
00132   FieldCalMap(const Vector<Int>& calmap);
00133 
00134   // Algorithmic ctor that uses MS and CT meta info
00135   FieldCalMap(const String fieldcalmap, const MeasurementSet& ms, const NewCalTable& ct);
00136 
00137 private:
00138 
00139   // Calculate the simple nearest field map
00140   void setNearestFieldMap(const MeasurementSet& ms, const NewCalTable& ct);
00141   void setNearestFieldMap(const NewCalTable& ctasms, const NewCalTable& ct);
00142   void setNearestFieldMap(const ROMSFieldColumns& msfc, const ROCTColumns& ctc);
00143 
00144   // Parse field selection map
00145   void setSelectedFieldMap(const String& fieldsel,
00146                            const MeasurementSet& ms,const NewCalTable& ct);
00147 
00148   // User's specification
00149   String fieldcalmap_;
00150 
00151 
00152 };
00153 
00154 
00155 
00156 
00157 // A class to parse the contents of a single CalLib slice 
00158 //  i.e., for one caltable, one setup
00159 class CalLibSlice
00160 {
00161 public:
00162   CalLibSlice(String obs,String fld, String ent, String spw,
00163               String tinterp,String finterp,
00164               Vector<Int> obsmap=Vector<Int>(1,-1), 
00165               Vector<Int> fldmap=Vector<Int>(1,-1), 
00166               Vector<Int> spwmap=Vector<Int>(1,-1), 
00167               Vector<Int> antmap=Vector<Int>(1,-1));
00168   CalLibSlice(const Record& clslice,
00169               const MeasurementSet& ms=MeasurementSet(),
00170               const NewCalTable& ct=NewCalTable());
00171 
00172 
00173   String obs,fld,ent,spw;
00174   String tinterp,finterp;
00175   CalMap obsmap, fldmap, spwmap, antmap;
00176 
00177   // validation
00178   static Bool validateCLS(const Record& clslice);
00179 
00180   // Extract as a record
00181   Record asRecord();
00182 
00183   String state();
00184 
00185 };
00186 
00187 
00188 class CLPPResult
00189 {
00190 public:
00191 
00192   CLPPResult();
00193   CLPPResult(const IPosition& shape);
00194   CLPPResult(uInt nPar,uInt nFPar,uInt nChan,uInt nelem);
00195   CLPPResult& operator=(const CLPPResult& other); // avoids deep Array copies
00196 
00197   void resize(uInt nPar,uInt nFPar,uInt nChan,uInt nelem);
00198 
00199   Matrix<Float> operator()(Int ielem) { return result_.xyPlane(ielem); };
00200   Matrix<Float> result(Int ielem) { return result_.xyPlane(ielem); };
00201   Matrix<Bool> resultFlag(Int ielem) { return resultFlag_.xyPlane(ielem); };
00202 
00203   Cube<Float> result_;
00204   Cube<Bool> resultFlag_;
00205 
00206   //private:
00207 
00208 };
00209 
00210 
00211 
00212 
00213 
00214 class MSSelectableTable;
00215 
00216 class CLPatchPanel
00217 {
00218 public:
00219 
00220   // From caltable name and MS shapes
00221   CLPatchPanel(const String& ctname,
00222                const Record& callib,
00223                VisCalEnum::MatrixType mtype,
00224                Int nPar);
00225 
00226    // From caltable name and (selected) MS 
00227   CLPatchPanel(const String& ctname,
00228                const MeasurementSet& ms,
00229                const Record& callib,
00230                VisCalEnum::MatrixType mtype,
00231                Int nPar);
00232  
00233   // Destructor
00234   virtual ~CLPatchPanel();
00235 
00236   // Interpolate, given input obs, field, intent, spw, timestamp, & (optionally) freq 
00237   //    returns T if new result (anywhere,anyhow)
00238   //  For Complex params (calls Float version)
00239   Bool interpolate(Cube<Complex>& resultC, Cube<Bool>& resFlag,
00240                    Int obs, Int fld, Int ent, Int spw, 
00241                    Double time, Double freq=-1.0);
00242   //  For Float params
00243   Bool interpolate(Cube<Float>& resultR, Cube<Bool>& resFlag,
00244                    Int obs, Int fld, Int ent, Int spw, 
00245                    Double time, Double freq=-1.0);
00246 
00247   // Interpolate, given input obs, field, intent, spw, timestamp, & freq list
00248   //   This is for freqdep interpolation context
00249   //    returns T if new result (anywhere,anyhow)
00250   //  For Complex params (calls Float version)
00251   Bool interpolate(Cube<Complex>& resultC, Cube<Bool>& resFlag,
00252                    Int obs, Int fld, Int ent, Int spw, 
00253                    Double time, const Vector<Double>& freq);
00254   //  For Float params
00255   Bool interpolate(Cube<Float>& resultR, Cube<Bool>& resFlag,
00256                    Int obs, Int fld, Int ent, Int spw, 
00257                    Double time, const Vector<Double>& freq);
00258 
00259   // Const access to various state
00260   // TBD
00261 
00262   Bool getTresult(Cube<Float>& resultR, Cube<Bool>& resFlag,
00263                   Int obs, Int fld, Int ent, Int spw);
00264 
00265 
00266   // Access to CalTable's freq info
00267   //Vector<Double> freqIn(Int spw);  // NYI
00268   const Vector<Double>& refFreqIn() { return refFreqIn_; };  // indexed by spw
00269 
00270   // Report state
00271   void listmappings();
00272   void state();
00273 
00274 private:
00275 
00276   // Null ctor does nothing
00277   CLPatchPanel() :mtype_(VisCalEnum::GLOBAL) {};
00278 
00279 
00280 
00281   // Methods to support layered selection
00282   void selectOnCTorMS(Table& ctout,MSSelectableTable& msst,
00283                       const String& obs, const String& fld, 
00284                       const String& ent,
00285                       const String& spw, const String& ant,
00286                       const String& taql);
00287   void selectOnMS(MeasurementSet& msout,const MeasurementSet& msin,
00288                   const String& obs, const String& fld, 
00289                   const String& ent,
00290                   const String& spw, const String& ant);
00291   void selectOnCT(NewCalTable& ctout,const NewCalTable& ctin,
00292                   const String& obs, const String& fld, 
00293                   const String& spw, const String& ant1);
00294 
00295   // Extract unique indices from caltables
00296   Vector<Int> getCLuniqueObsIds(NewCalTable& ct) {return getCLuniqueIds(ct,"obs"); };
00297   Vector<Int> getCLuniqueFldIds(NewCalTable& ct) {return getCLuniqueIds(ct,"fld"); };
00298   Vector<Int> getCLuniqueSpwIds(NewCalTable& ct) {return getCLuniqueIds(ct,"spw"); };
00299   Vector<Int> getCLuniqueIds(NewCalTable& ct, String vcol);
00300 
00301   // Extract unique indices (net selected) from MS
00302   Vector<Int> getMSuniqueIds(MeasurementSet& ms, String vcol);
00303   
00304   // Set generic antenna/baseline map
00305   //  void setElemMap();
00306 
00307   // Resample in frequency
00308   void resampleInFreq(Matrix<Float>& fres,Matrix<Bool>& fflg,const Vector<Double>& fout,
00309                       Matrix<Float>& tres,Matrix<Bool>& tflg,const Vector<Double>& fin,
00310                       String finterp);
00311   void resampleFlagsInFreq(Vector<Bool>& flgout,const Vector<Double>& fout,
00312                            Vector<Bool>& flgin,const Vector<Double>& fin,
00313                            String finterp);
00314 
00315   // Baseline index from antenna indices: (assumes a1<=a2 !!)
00316   //  inline Int blnidx(const Int& a1, const Int& a2, const Int& nAnt) { return  a1*nAnt-a1*(a1+1)/2+a2; };
00317 
00318   // Translate freq axis interpolation string
00319   InterpolateArray1D<Double,Float>::InterpolationMethod ftype(String& strtype);
00320 
00321 
00322 
00323   // PRIVATE DATA:
00324   
00325   // The Caltable
00326   NewCalTable ct_, ctasms_;
00327 
00328   // Associated (selected) MS
00329   MeasurementSet ms_;
00330 
00331   // Matrix type
00332   VisCalEnum::MatrixType mtype_;
00333 
00334   // Are parameters fundamentally complex?
00335   Bool isCmplx_;
00336 
00337   // The number of (Float) parameters (per-chan, per-element)
00338   Int nPar_, nFPar_;
00339 
00340   //  InterpolateArray1D<Double,Float>::InterpolationMethod ia1dmethod_;
00341 
00342   // CalTable freq axis info
00343   Vector<Int> nChanIn_;
00344   Vector<Vector<Double> > freqIn_;
00345   Vector<Double> refFreqIn_;
00346 
00347   // Obs, Field, Spw, Ant _output_ (MS) sizes 
00348   //   calibration required for up to this many
00349   Int nMSObs_, nMSFld_, nMSSpw_, nMSAnt_, nMSElem_;
00350 
00351   // Obs, Field, Spw, Ant _input_ (CalTable) sizes
00352   //  patch panels should not violate these (point to larger indices)
00353   Int nCTObs_, nCTFld_, nCTSpw_, nCTAnt_, nCTElem_;
00354 
00355   // Maps
00356   std::map<CTCalPatchKey,CLPPResult> clTres_;
00357   std::map<CTCalPatchKey,String> ciname_;
00358   std::map<CTCalPatchKey,CTTimeInterp1*> ci_;
00359   
00360 
00361   std::map<MSCalPatchKey,CLPPResult> msTres_,msFres_;
00362   std::map<MSCalPatchKey,String> msciname_;
00363   std::map<MSCalPatchKey,Int> ctspw_;
00364   std::map<MSCalPatchKey,String> finterp_;
00365   std::map<MSCalPatchKey,CTTimeInterp1*> msci_;
00366 
00367   // Keep track of last cal result address (per spw)
00368   Vector<Float*> lastresadd_;  // [nMSspw_]
00369 
00370   // Control conjugation of baseline-based solutions when mapping requires
00371   //  Vector<Bool> conjTab_;
00372 
00373 
00374   Cube<Float> result_;
00375   Cube<Bool> resFlag_;
00376 
00377   LogIO logsink_;
00378 
00379 
00380 };
00381 
00382 
00383 } //# NAMESPACE CASA - END
00384 
00385 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1