casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LJJones.h
Go to the documentation of this file.
00001 //# LJJones.h: Declaration of LJJones (Solvable)VisCal type
00002 //# Copyright (C) 1996,1997,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 SYNTHESIS_LJJONES_H
00029 #define SYNTHESIS_LJJONES_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Containers/Record.h>
00033 #include <casa/BasicSL/Complex.h>
00034 #include <synthesis/MeasurementComponents/SolvableVisCal.h>
00035 //#include <synthesis/MeasurementComponents/nPBWProjectFT.h>
00036 #include <synthesis/TransformMachines/GridFT.h>
00037 #include <ms/MeasurementSets/MeasurementSet.h>
00038 #include <images/Images/PagedImage.h>
00039 #include <images/Images/ImageInterface.h>
00040 #include <images/Images/ImageInfo.h>
00041 #include <synthesis/TransformMachines/StokesImageUtil.h>
00042 #include <synthesis/MSVis/VisSet.h>
00043 #include <synthesis/CalTables/CalSet.h>
00044 #include <casa/OS/Timer.h>
00045 #include <synthesis/MSVis/VisBuffAccumulator.h>
00046 namespace casa { //# NAMESPACE CASA - BEGIN
00047 
00048 // Forward declaration
00049 class VisEquation;
00050 class nPBWProjectFT;
00051 
00052 // **********************************************************
00053 //  LJJones (pointing errors)
00054 //
00055 
00056 class LJJones : public SolvableVisJones {
00057 public:
00058 
00059   // Constructor
00060   LJJones(VisSet& vs);
00061          //  {throw(AipsError("Use the constructor LJJones(VisSet&, MeasurementSet&) instead"));};
00062   LJJones(VisSet& vs, MeasurementSet& ms);
00063   //   LJJones(const Int& nAnt);  // NYI
00064 
00065   virtual ~LJJones();
00066 
00067   // Return the type enum
00068   virtual Type type() { return VisCal::E; };
00069 
00070   // Return type name as string
00071   virtual String typeName()     { return "LJ Jones"; };
00072   virtual String longTypeName() { return "LeakyJ Jones"; };
00073   // Frequency-dependent Parameters?  Nominally not.
00074   virtual Bool freqDepPar() { return False; };
00075 
00076   // Type of Jones matrix according to nPar()
00077   Jones::JonesType jonesType() { return Jones::General; };
00078   
00079   virtual VisCalEnum::VCParType parType() { return setParType(VisCalEnum::COMPLEX);};
00080 
00081   // Specialized access to pointing parameters (no chan axis)
00082   Cube<Complex>& loadPar();
00083 
00084   virtual void setModel(const String& modelImage);
00085   // Set the solving parameters
00086   virtual void setSolve();
00087   virtual void setSolve(const Record& solve);
00088   virtual void setNiter(const Int& niter) {niter_p=niter;}
00089   virtual void setTolerance(const Float& tol) {tolerance_p = tol;}
00090   virtual void setGain(const Float& gain) {gain_p = gain;}
00091 
00092   // Arrange to apply (corrupt only)
00093   using SolvableVisCal::setApply;
00094   virtual void setApply(const Record& applypar);
00095 
00096   // Apply calibration to a VisBuffer 
00097   virtual void applyCal(VisBuffer& vb, 
00098                         Cube<Complex>& Mout);
00099 
00100   // Differentiate a VisBuffer w.r.t. pointng parameters
00101   //
00102   // These effectively compute residuals and derivatives for
00103   // a time-averaged VisBuffer
00104   //
00105   virtual void differentiate(VisBuffer& vb,
00106                              Cube<Complex>& Mout,
00107                              Array<Complex>& dMout,
00108                              Matrix<Bool>& Mflg);
00109   // Differentiate a VisBuffer w.r.t. pointng parameters
00110   virtual void differentiate(VisBuffer& vb,
00111                              VisBuffer& dvb0,
00112                              VisBuffer& dvb1,
00113                              Matrix<Bool>& Mflg);
00114   //
00115   // This one averages the residuals and the derivatives in time.
00116   //
00117   virtual void diffResiduals(VisIter& vi, VisEquation& ve,
00118                             VisBuffer& residuals, 
00119                             VisBuffer& dVr1, 
00120                             VisBuffer& dVr2, 
00121                             Matrix<Bool>& flags);  
00122   // Guess (throws error because we don't yet solve for this)
00123   virtual void guessPar(VisBuffer& vb);
00124   virtual void guessPar() {pointPar_=0;}
00125   
00126   virtual Cube<Complex>& solvePar() {return pointPar_;}
00127   virtual void setRPar(Cube<Complex>& val) {pointPar_.resize(val.shape());pointPar_=val;}
00128   virtual void setRPar(Double val) {pointPar_=val;}
00129   
00130   //  virtual void keep(const Int& slot);
00131 
00132   virtual Bool normalizable() { return False; };
00133 
00134   //  virtual BaseCalSet& cs() {return *cs_;};
00135   virtual void keep(const Int& slot);
00136   
00137   inline virtual CalSet<Complex>& cs() {return *cs_;};
00138 
00139   virtual void inflate(const Vector<Int>& nChan,
00140                        const Vector<Int>& startChan,
00141                        const Vector<Int>& nSlot);
00142   void initSolve(VisSet& vs);
00143   void initSolvePar();
00144   void store();
00145   void store(const String& table,const Bool& append);
00146   Bool verifyForSolve(VisBuffer& vb);
00147   virtual void postSolveMassage(const VisBuffer&);
00148   virtual void selfGatherAndSolve(VisSet& vs,VisEquation& ve);
00149   virtual Bool useGenericGatherForSolve() { return False; };
00150   virtual Float printFraction(const Int& /*nSlots*/) {return 0.1;};
00151   Array<Complex> getOffsets(const Int& spw) {return cs().par(spw);}
00152   Array<Double> getTime(const Int& spw) {return cs().time(spw);}
00153   void nearest(const Double time, Array<Complex>& vals);
00154   void printRPar();  
00155 
00156   void setByPassMode(Int& b) {byPass_p = b;}
00157   void getAvgVB(VisIter& vi, VisEquation& ve, VisBuffer& vb);
00158 protected:
00159 
00160   // EP has a pair of real parameters per feed
00161   virtual Int nPar() { return 4; };
00162 
00163   // Jones matrix elements are NOT trivial
00164   virtual Bool trivialJonesElem() { return False; };
00165 
00166   // Fill-in a complex grid with the image values in prepration for 
00167   // computing it's FT
00168   virtual void makeComplexGrid(TempImage<Complex>& Grid, 
00169                                         PagedImage<Float>& ModelImage,
00170                                         VisBuffer& vb);
00171   void printActivity(const Int slotNo, const Int fieldId, const Int spw, const Int nSolutions);
00172   //  inline virtual CalSet<Float> cs() {return *cs_;}
00173 
00174   void reformVisibilities(const VisBuffer& vb, const Int whichChan, const Int whichPol,
00175                           Array<Complex>& visArray, Array<Float>& visWts);
00176 
00177   Int getRefAnt(const Array<Float>& visWts);
00178 private:
00179 
00180   // Local Matrix for referencing pointing pars in a convenient way
00181   Cube<Complex>  pointPar_;
00182   GridFT *pbwp_p;
00183   MeasurementSet *ms_p;
00184   VisSet *vs_p;
00185   //  Array<Float> azOff, elOff;
00186   TempImage<Complex> targetVisModel_;
00187   CalSet<Complex> *cs_;
00188   Double maxTimePerSolution, minTimePerSolution, avgTimePerSolution;
00189   Timer timer;
00190   Vector<Int> polMap_p;
00191   Float tolerance_p, gain_p;
00192   Int niter_p,byPass_p;
00193   String modelImageName_p;
00194 };
00195 
00196 
00197 
00198 
00199 
00200 } //# NAMESPACE CASA - END
00201 
00202 #endif
00203