casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
GSpline.h
Go to the documentation of this file.
00001 //# GJonesPoly.h: Electronic gain Jones matrix as polynomials over time
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 //# $Id: GJonesPoly.h,v 19.7 2004/11/30 17:50:48 ddebonis Exp $
00028 
00029 #ifndef SYNTHESIS_GSPLINE_H
00030 #define SYNTHESIS_GSPLINE_H
00031 
00032 #include <synthesis/MeasurementComponents/SolvableVisCal.h>
00033 #include <synthesis/MeasurementComponents/StandardVisCal.h>
00034 #include <synthesis/CalTables/GJonesMBuf.h>
00035 #include <casa/Containers/SimOrdMap.h>
00036 
00037 namespace casa { //# NAMESPACE CASA - BEGIN
00038 
00039 // <summary> Electronic gain Jones matrix as spline polynomial over time
00040 // </summary>
00041 
00042 // <use visibility=export>
00043 
00044 // <reviewed reviewer="" date="" tests="" demos="">
00045 
00046 // <prerequisite>
00047 //   <li> <linkto module="GJones">GJones</linkto> module
00048 //   <li> <linkto module="GJonesPoly">GJonesPoly</linkto> module
00049 // </prerequisite>
00050 //
00051 // <etymology>
00052 // GJonesSpline describes the electronic gain visibility Jones matrix 
00053 // parametrized as a spline polynomial over time.
00054 // </etymology>
00055 //
00056 // <synopsis> 
00057 //
00058 // See <linkto class="VisEquation">VisEquation</linkto> for definition of the
00059 // Visibility Measurement Equation.
00060 //
00061 // The elements of GJonesSpline are only non-zero on the diagonal.
00062 //
00063 // </synopsis> 
00064 //
00065 // <motivation>
00066 // Support electronic gain calibration using splines polynomials over time.
00067 // </motivation>
00068 //
00069 // <todo asof="02/02/01">
00070 // i) Support solution and pre-averaging intervals
00071 // </todo>
00072 
00073 class VisEquation;
00074 
00075 class GJonesSpline : public GJones {
00076 public:
00077 
00078   // Construct from a visibility data set
00079   GJonesSpline (VisSet& vs);
00080 
00081   // Destructor
00082   virtual ~GJonesSpline();
00083 
00084   // Return the type enum
00085   virtual Type type() { return VisCal::G; };
00086 
00087   // Return type name as a string
00088   virtual String typeName()     { return "GSPLINE"; };
00089   virtual String longTypeName() { return "G Jones SPLINE (elec. gain)"; };
00090 
00091 
00092   // GSpline gathers/solves for itself
00093   virtual Bool useGenericGatherForSolve() { return False; };
00094 
00095   // Type of Jones matrix according to nPar()
00096   // TBD:
00097   virtual Jones::JonesType jonesType() { return Jones::Diagonal; };
00098 
00099   // Set the solver parameters
00100   using GJones::setSolve;
00101   virtual void setSolve(const Record& solvepar);
00102 
00103   // Set the interpolation parameters
00104   using GJones::setApply;
00105   virtual void setApply(const Record& applypar);
00106 
00107   // Solve
00108   virtual void selfGatherAndSolve (VisSet& vs, VisEquation& ve);
00109 
00110 /*
00111   // Set raw phase transfer from another spw
00112   void setRawPhaseVisSet(VisSet& rawvs_p);
00113 
00114   // Set parameters for phase wrapping resolution
00115   void setPhaseWrapHelp(const Int& numpoi, const Double& phaseWrap);
00116 */
00117 
00118  protected:
00119 
00120   // GSPLINE has one trivial Complex parameter (single pol, for now)
00121   // TBD:
00122   virtual Int nPar() { return 2; };
00123 
00124   // Calc G pars from spline info
00125   virtual void calcPar();
00126 
00127  private:
00128 
00129   // The underlying VisSet
00130   VisSet* vs_p;
00131 
00132   // Private variables containing the solver parameters
00133   Bool solveAmp_p, solvePhase_p;
00134   Double splinetime_p;
00135 
00136   // Time for which the current calibration cache is valid
00137   Double cacheTimeValid_p;
00138 
00139   // Ptr to a calibration buffer associated with the calibration
00140   // solutions which are to be interpolated and applied to the data
00141   GJonesSplineMBuf* calBuffer_p;
00142 
00143 
00144   // Parameters for raw phase removal from another spw
00145   VisSet* rawvs_p;
00146   Bool rawPhaseRemoval_p;
00147   SimpleOrderedMap<String, Int> timeValueMap_p;
00148   Matrix<Double> rawPhase_p;
00149 
00150   // Solution timestamp
00151   Double solTimeStamp_p;
00152 
00153 
00154   // Create and fill an empty output calibration buffer
00155   void newCalBuffer (const Vector<Int>& fieldIdKeys, 
00156                      const Vector<Int>& antennaId);
00157 
00158   // Compute the number of spline knots required and their location
00159   Int getKnots (const Vector<Double>& times, Vector<Double>& knots);
00160 
00161   // Update the output calibration table
00162   virtual void updateCalTable (const Vector<Int>& fieldIdKeys,
00163                                const Vector<Int>& antennaId,
00164                                const Vector<String>& freqGrpName,
00165                                const Vector<String>& polyType,
00166                                const Vector<String>& polyMode,
00167                                const Vector<Complex>& scaleFactor,
00168                                const Matrix<Double>& polyCoeffAmp,
00169                                const Matrix<Double>& polyCoeffPhase,
00170                                const Vector<String>& phaseUnits,
00171                                const Vector<Double>& splineKnotsAmp,
00172                                const Vector<Double>& splineKnotsPhase,
00173                                const Vector<MFrequency>& refFreq,
00174                                const Vector<Int>& refAnt);
00175   
00176   // Compute a spline polynomial value
00177   Double getSplineVal (Double x, Vector<Double>& knots,
00178                        Vector<Double>& coeff);
00179 
00180 
00181 /*
00182   // fill the raw phase buffer for usage
00183   void fillRawPhaseBuff();
00184 
00185   // return the rawphase of 
00186   Double getRawPhase(Int ant1, Int ant2, Double time);
00187 
00188 */
00189 
00190   //Plot solutions as compare with data
00191   void plotsolve(const Vector<Double>& x, 
00192                  const Matrix<Double>& yall, 
00193                  const Matrix<Double>& weightall, 
00194                  const Vector<Double>& errall, 
00195                  Matrix<Double>& coeff, Bool phasesoln);
00196 
00197   // Return all field id.'s in the underlying MS
00198   Vector<Int> fieldIdRange();
00199 
00200   //Logging solution and rms
00201   void writeAsciiLog(const String& filename, const Matrix<Double>& coeff, const Vector<Double>& rmsFit, Bool phasesoln);
00202 
00203   Int numpoint_p;
00204   Double phaseWrap_p;
00205 
00206 
00207 };
00208 
00209 
00210 } //# NAMESPACE CASA - END
00211 
00212 #endif
00213 
00214