SolvableVisCal.h

Go to the documentation of this file.
00001 //# SolvableVisCal.h: Definitions of interface for SolvableVisCal 
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_SOLVABLEVISCAL_H
00029 #define SYNTHESIS_SOLVABLEVISCAL_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Containers/Record.h>
00033 #include <casa/BasicSL/Complex.h>
00034 #include <casa/BasicSL/Constants.h>
00035 #include <synthesis/MeasurementComponents/VisCal.h>
00036 #include <synthesis/MeasurementComponents/Mueller.h>
00037 #include <synthesis/MeasurementComponents/Jones.h>
00038 #include <synthesis/MeasurementComponents/VisVector.h>
00039 #include <synthesis/MeasurementComponents/SynthesisError.h>
00040 #include <calibration/CalTables/CalSet.h>
00041 #include <calibration/CalTables/CalSetMetaInfo.h>
00042 #include <calibration/CalTables/CalInterp.h>
00043 #include <calibration/CalTables/VisCalEnum.h>
00044 #include <msvis/MSVis/VisSet.h>
00045 #include <msvis/MSVis/CalVisBuffer.h>
00046 #include <msvis/MSVis/VisBuffGroupAcc.h>
00047 
00048 #include <casa/Logging/LogMessage.h>
00049 #include <casa/Logging/LogSink.h>
00050 #include <casa/Logging/LogIO.h>
00051 #include <casa/OS/Timer.h>
00052 
00053 namespace casa { //# NAMESPACE CASA - BEGIN
00054 
00055 
00056 // **********************************************************
00057 //  SolvableVisCal
00058 //
00059 
00060 // Forward
00061 class VisEquation;
00062 
00063 // for simulating corruptions
00064 class CalCorruptor {
00065   
00066  public:
00067   
00068   CalCorruptor(const Int nSim);
00069   virtual ~CalCorruptor();
00070   inline Int& nSim() { return nSim_; };
00071   inline Bool& initialized() { return initialized_; };
00072   inline Int& prtlev() { return prtlev_; };
00073   inline Int& curr_slot() { return curr_slot_; };
00074   inline Double& curr_time() { return curr_time_; };
00075   inline Double& startTime() { return starttime_; };
00076   inline Double& stopTime() { return stoptime_; };
00077   inline Double& slot_time(const Int i) { return slot_times_(i); };
00078   inline Double& slot_time() { return slot_times_(curr_slot()); };
00079   inline Int& currAnt() { return curr_ant_; };
00080   inline Int& currSpw() { return curr_spw_; };
00081   inline Int& nAnt() { return nAnt_; };
00082   inline Int& nSpw() { return nSpw_; };  
00083   inline Int& currChan() { return curr_chan_; };  
00084   inline Int& nChan() { return fnChan_[currSpw()]; };  
00085   inline Vector<Float>& fRefFreq() { return fRefFreq_; };
00086   inline Vector<Float>& fWidth() { return fWidth_; };
00087   inline Vector<Int>& fnChan() { return fnChan_; };
00088   virtual void initialize()=0;
00089  
00090  protected:
00091    
00092    Int nSim_;
00093    Bool initialized_;
00094    Int prtlev_;
00095    Int curr_slot_;
00096    Int nAnt_,curr_ant_;
00097    Int nSpw_,curr_spw_,curr_chan_;
00098    Double curr_time_,starttime_,stoptime_;
00099    Vector<Double> slot_times_;   
00100    Vector<Float> fRefFreq_,fWidth_; // for each spw
00101    Vector<Int> fnChan_;
00102 
00103  private:
00104 
00105 };
00106 
00107 
00108 
00109 class SolvableVisCal : virtual public VisCal {
00110 public:
00111 
00112   SolvableVisCal(VisSet& vs);
00113   
00114   SolvableVisCal(const Int& nAnt);
00115 
00116   virtual ~SolvableVisCal();
00117 
00118   // Access to user-supplied parameters
00119   inline String&      calTableName()   { return calTableName_; };
00120   inline String&      calTableSelect() { return calTableSelect_; };
00121   inline Bool&        append()         { return append_; };
00122   inline String&      tInterpType()    { return tInterpType_; };
00123   inline String&      fInterpType()    { return fInterpType_; };
00124   inline Vector<Int>& spwMap()         { return spwMap_; };
00125   inline Int&         refant()         { return refant_; };
00126   inline Int&         minblperant()    { return minblperant_; };
00127   inline String&      apmode()         { return apmode_; };
00128   inline String&      solint()         { return solint_; };
00129   inline Double&      preavg()         { return preavg_; };
00130   inline Bool&        solnorm()        { return solnorm_;};
00131   inline Float&       minSNR()         { return minSNR_; };
00132 
00133   inline String&      combine()        { return combine_; };
00134   inline Bool         combspw()        { return upcase(combine_).contains("SPW"); };
00135   inline Bool         combfld()        { return upcase(combine_).contains("FIELD"); };
00136   inline Bool         combscan()       { return upcase(combine_).contains("SCAN"); };
00137 
00138   // Total number of (complex) parameters per solve
00139   //  (specialize to jive with ant- or bln-basedness, etc.)
00140   virtual Int nTotalPar()=0;
00141 
00142   // Report if calibration available for specified spw
00143   //  (if no CalInterp available, assume True)
00144   virtual Vector<Bool> spwOK() { 
00145     return cint_ ? ci().spwOK() : Vector<Bool>(nSpw(),True); };
00146 
00147   // Use standard VisCal solving mechanism?
00148   virtual Bool standardSolve() { return True; };
00149 
00150   // Solve for point-source X or Q,U?
00151   //  nominally no (0)
00152   virtual Int solvePol() { return 0; };
00153 
00154   // Does normalization by MODEL_DATA commute with this VisCal?
00155   //   (if so, permits pre-solve time-averaging)
00156   virtual Bool normalizable()=0;
00157 
00158   // Is this type capable of accumulation?  (nominally no)
00159   virtual Bool accumulatable() { return False; };
00160 
00161   // Is this type capable of smoothing?  (nominally no)
00162   virtual Bool smoothable() { return False; };
00163 
00164   // Access to focus channel
00165   inline Int&         focusChan()      { return focusChan_; };
00166 
00167   // Is this ready to solve?
00168   inline Bool isSolved() {return solved_;};
00169 
00170   // Is this solveable? (via this interface, nominally yes)
00171   virtual Bool isSolvable() {return True;};
00172 
00173   // Set the application parameters 
00174   virtual void setApply();
00175   virtual void setApply(const Record& apply);
00176   virtual void setModel(const String& modelImage) 
00177   {throw(SynthesisError("Internal error: setModel() not yet supported for non EPJones type."));};
00178 
00179   // Report apply info/params, e.g. for logging
00180   virtual String applyinfo();
00181 
00182   // Set the solving parameters
00183   virtual void setSolve();
00184   virtual void setSolve(const Record& solve);
00185 
00186   // Report solve info/params, e.g., for logging
00187   virtual String solveinfo();
00188 
00189   // Arrange for accumulation
00190   virtual void setAccumulate(VisSet& vs,
00191                              const String& table,
00192                              const String& select,
00193                              const Double& t,
00194                              const Int& refAnt=-1);
00195 
00196   // Size up the solving arrays, etc.  (supports combine)
00197   Int sizeUpSolve(VisSet& vs, Vector<Int>& nChunkPerSol);
00198 
00199   // Initialize internal shapes for solving
00200   void initSolve(VisSet& vs);
00201 
00202   // Inflate the pristine CalSet (from VisSet info)
00203   void inflate(VisSet& vs, const Bool& fillMeta=False);
00204 
00205   // Inflate the pristine CalSet (generically)
00206   void inflate(const Vector<Int>& nChanDat,
00207                const Vector<Int>& startChanDat,
00208                const Vector<Int>& nSlot);
00209 
00210   // Hazard a guess at the parameters (solveCPar) given the data
00211   virtual void guessPar(VisBuffer& vb)=0;
00212 
00213   // Access to current solution parameters and matrices
00214   inline virtual Cube<Complex>& solveCPar()   {return (*solveCPar_[currSpw()]);};
00215   inline virtual Cube<Float>&   solveRPar()   {return (*solveRPar_[currSpw()]);};
00216   inline virtual Cube<Bool>&    solveParOK()  {return (*solveParOK_[currSpw()]);};
00217   inline virtual Cube<Float> &  solveParErr() {return (*solveParErr_[currSpw()]);};
00218   inline virtual Cube<Float> &  solveParSNR() {return (*solveParSNR_[currSpw()]);};
00219 
00220   // Access to source pol parameters
00221   inline Vector<Complex>& srcPolPar() { return srcPolPar_; };
00222 
00223   // Synchronize the meta data with a solvable VisBuffer
00224   //   (returns False if VisBuffer has no valid data)
00225   Bool syncSolveMeta(VisBuffer& vb, const Int& fieldId);
00226   Bool syncSolveMeta(VisBuffGroupAcc& vbga);
00227 
00228   // Make vb phase-only
00229   virtual void enforceAPonData(VisBuffer& vb);
00230 
00231   // Verify VisBuffer data sufficient for solving (wts, etc.)
00232   virtual Bool verifyConstraints(VisBuffGroupAcc& vbag);
00233   virtual Bool verifyForSolve(VisBuffer& vb);
00234   
00235   // Self-solving mechanism
00236   virtual void selfSolve(VisSet& vs, VisEquation& ve);
00237   virtual void selfSolve2(VisBuffGroupAcc& vs);
00238 
00239   // Set up data and model for pol solve
00240   void setUpForPolSolve(VisBuffer& vb);
00241 
00242   // Differentiate VB model w.r.t. Cal  parameters (no 2nd derivative yet)
00243   virtual void differentiate(CalVisBuffer& cvb)=0;
00244   virtual void differentiate(VisBuffer& vb,        
00245                              Cube<Complex>& V,     
00246                              Array<Complex>& dV,
00247                              Matrix<Bool>& Vflg)=0;
00248   virtual void differentiate(VisBuffer& vb,          // vb.visCube() has the obs. data.  vb.modelVisCube() will receive the residuals
00249                              VisBuffer& dV0  ,       // 1st. Derivative w.r.t. first parameter
00250                              VisBuffer& dV1,         // 1st. Derivative w.r.t. second parameter
00251                              Matrix<Bool>& Vflg){ throw(AipsError("Invalid use of differentiate(vb,dV0,dv1)")); };
00252 
00253 
00254   // Differentiate VB model w.r.t. Source parameters
00255   virtual void diffSrc(VisBuffer& vb,        
00256                        Array<Complex>& dV)=0;
00257 
00258   // Update solve parameters incrementally (additive)
00259   virtual void updatePar(const Vector<Complex> dCalPar,const Vector<Complex> dSrcPar);
00260 
00261   // Form solution SNR
00262   virtual void formSolveSNR();
00263 
00264   // Apply SNR threshold
00265   virtual void applySNRThreshold();
00266 
00267   // Apply refant (implemented in SVJ)
00268   virtual void reReference()=0;
00269 
00270   // Accumulate another VisCal onto this one
00271   virtual void accumulate(SolvableVisCal* incr,
00272                           const Vector<Int>& fields)=0;
00273 
00274   virtual void smooth(Vector<Int>& fields,
00275                       const String& smtype,
00276                       const Double& smtime);
00277 
00278   // Report solved-for QU
00279   virtual void reportSolvedQU();
00280 
00281   // File the current solved solution into a slot in the CalSet
00282   virtual void keep(const Int& slot);
00283 
00284   // Post solve tinkering (generic version)
00285   virtual void globalPostSolveTinker();
00286 
00287   // Divide all solutions by their amplitudes
00288   virtual void enforceAPonSoln();
00289 
00290   // Normalize a solution (generic implementation)
00291   virtual void normalize();
00292 
00293   // Determine and apply flux density scaling
00294   virtual void fluxscale(const Vector<Int>& refFieldIn,
00295                          const Vector<Int>& tranFieldIn,
00296                          const Vector<Int>& inRefSpwMap,
00297                          const Vector<String>& fldNames,
00298                          Matrix<Double>& fluxScaleFactor)=0;
00299 
00300   // Tell the CalSet to write a CalTable
00301   void store();
00302   void store(const String& tableName,const Bool& append);
00303 
00304   // Report state:
00305   inline virtual void state() { stateSVC(True); };
00306   inline virtual Int nSlots(Int spw)
00307   {
00308     Int nslots=0;
00309     if (parType() == VisCalEnum::COMPLEX) nslots=cs().nTime(spw);
00310     else if (parType() == VisCalEnum::REAL) nslots=rcs().nTime(spw);
00311     return nslots;
00312   };
00313   virtual VisCalEnum::VCParType setParType(VisCalEnum::VCParType type) 
00314   {parType_ = type;return (VisCalEnum::VCParType)parType_;};
00315   virtual void currMetaNote();
00316 
00317   virtual void listCal(const Vector<Int> ufldids, const Vector<Int> uantids,
00318                        const Matrix<Int> uchanids,  //const Int& spw, const Int& chan,
00319                        const String& listfile="",const Int& pagerows=50)=0;
00320 
00321   // Handle external channel mask
00322   inline void setChanMask(PtrBlock<Vector<Bool>*>& chanmask) { chanmask_=&chanmask; };
00323   inline void clearChanMask() { chanmask_=NULL; };
00324   void applyChanMask(VisBuffer& vb);
00325   // Log periodic solver activity
00326   virtual void printActivity(const Int nSlots, const Int slotNo, 
00327                              const Int fieldId, const Int spw, 
00328                              const Int nSolutions);
00329   virtual void markTimer() {timer_p.mark();};
00330 
00331 
00332   // -------------
00333   // Set the simulation parameters
00334   virtual void setSimulate(const Record& simpar);
00335 
00336   // Set up simulated params wrt visset
00337   virtual Int setupSim(VisSet& vs, const Record& simpar, Vector<Int>& nChunkPerSol, Vector<Double>& solTimes);
00338 
00339   // Calculate simulated parameters by some means 
00340   virtual Bool simPar(VisBuffGroupAcc& vbga);
00341 
00342   // access to simulation variables that are general to all VisCals
00343   inline String& simint() { return simint_; };
00344 
00345   // Simulation info/params, suitable for logging
00346   virtual String siminfo();
00347 
00348   // Is this calibration simulated?
00349   inline Bool isSimulated() {return simulated_;};
00350 
00351   // object that can simulate the corruption terms
00352   CalCorruptor *corruptor_p;
00353 
00354   // RI TODO simplify? i.e. do we need full comb machinery?
00355   Int sizeUpSim(VisSet& vs, Vector<Int>& nChunkPerSol, Vector<Double>& solTimes);
00356   //inline virtual Int sizeUpSim(VisSet& vs, Vector<Int>& nChunkPerSol) {
00357   //  return sizeUpSolve(vs,nChunkPerSol) ; }
00358  
00359 
00360 protected:
00361 
00362   // Set to-be-solved-for flag
00363   inline void setSolved(const Bool& flag) {solved_=flag;};
00364 
00365   // Access to CalSet/CalInterp
00366   inline virtual CalSet<Complex>& cs() { return *cs_; };
00367   inline virtual CalSet<Float>& rcs() { return *rcs_; };
00368   inline virtual CalInterp& ci() { return *cint_; };
00369 
00370   // Initialize solve parameters (shape)
00371   virtual void initSolvePar()=0;
00372 
00373   // Invalidate diff cal matrices generically 
00374   inline virtual void invalidateDiffCalMat()=0;
00375 
00376   // Explicitly synchronize pars with a CalSet slot
00377   using VisCal::syncPar;
00378   void syncPar(const Int& spw, const Int& slot);
00379 
00380   // Set matrix channelization according to a VisSet
00381   void setSolveChannelization(VisSet& vs);
00382 
00383   // Fill CalSet meta-data according to a VisSet
00384   void fillMetaData(VisSet& vs);
00385 
00386   // Synchronize calibration for solve context
00387   void syncSolveCal();
00388 
00389   // Synchronize parameters for solve context
00390   void syncSolvePar();
00391 
00392   // Calculate parameters by some means (e.g., interpolation from a CalSet)
00393   virtual void calcPar();
00394 
00395   // Synchronize the differentiated calibration 
00396   virtual void syncDiffMat()=0;
00397 
00398   // Report the SVC-specific state, w/ option for VC::state()
00399   virtual void stateSVC(const Bool& doVC);
00400 
00401   // Normalize a (complex) solution array (generic)
00402   void normSolnArray(Array<Complex>& sol,
00403                      const Array<Bool>& solOK,
00404                      const Bool doPhase=False);
00405 
00406   // Logger
00407   LogIO& logSink() { return logsink_p; };
00408 
00409   void makeCalSet();
00410 
00411   // Check if a cal table is appropriate
00412   void verifyCalTable(const String& caltablename);
00413 
00414   Int parType_;
00415   // Solution/Interpolation 
00416   CalSet<Complex> *cs_;
00417   CalSet<Float> *rcs_;
00418   CalInterp *cint_;
00419   CalSetMetaInfo csmi;
00420 
00421   Double maxTimePerSolution_p, minTimePerSolution_p, avgTimePerSolution_p;
00422   Float userPrintActivityInterval_p, userPrintActivityFraction_p;
00423   uInt caiRC_p, cafRC_p;
00424   Timer timer_p;
00425 
00426   // Set state flag to simulate cal terms
00427   inline void setSimulated(const Bool& flag) {simulated_=flag;};
00428 
00429 
00430 
00431 private:
00432 
00433   // Default ctor is private
00434   SolvableVisCal();
00435 
00436   // Initialize pointers, etc.
00437   void initSVC();
00438 
00439   // Delete pointers
00440   void deleteSVC();
00441 
00442 
00443   // Cal table name
00444   String calTableName_;
00445   String calTableSelect_;
00446   Bool append_;
00447 
00448   // Interpolation types
00449   String tInterpType_;
00450   String fInterpType_;
00451 
00452   // Spw mapping
00453   Vector<Int> spwMap_;
00454 
00455   // Refant
00456   Int refant_;
00457 
00458   // Min baselines per ant for solve
00459   Int minblperant_;
00460 
00461   // Solved-for flag
00462   Bool solved_;
00463 
00464   // Solving mode
00465   String apmode_;
00466 
00467   // User-specified solint (string)
00468   String solint_;
00469 
00470   // Preavering interval
00471   Double preavg_;
00472 
00473   // Do solution normalization after a solve
00474   Bool solnorm_;
00475 
00476   // SNR threshold
00477   Float minSNR_;
00478 
00479   // axes to combine for solve
00480   String combine_;
00481 
00482   // In-focus channel for single-chan solves on multi-chan data
00483   Int focusChan_;
00484 
00485   // Solving meta-data
00486   Double dataInterval_;
00487   Double fitWt_;
00488   Double fit_;
00489 
00490 
00491   // Current parameters
00492   PtrBlock<Cube<Complex>*> solveCPar_;  // [nSpw](nPar,1,{1|nElem})
00493   PtrBlock<Cube<Float>*>   solveRPar_;  // [nSpw](nPar,1,{1|nElem})
00494   PtrBlock<Cube<Bool>*>    solveParOK_; // [nSpw](nPar,1,{1|nElm})
00495   PtrBlock<Cube<Float>*>   solveParErr_; // [nSpw](nPar,1,{1|nElm})
00496   PtrBlock<Cube<Float>*>   solveParSNR_; // [nSpw](nPar,1,{1|nElm})
00497 
00498   Vector<Complex> srcPolPar_;
00499 
00500   // A _pointer_ to the external channel mask
00501   PtrBlock<Vector<Bool>*> *chanmask_;
00502 
00503   // LogIO
00504   LogIO logsink_p;
00505 
00506   // Simulation flag
00507   Bool simulated_;
00508 
00509   // simulation interval
00510   String simint_;
00511 
00512 
00513 };
00514 
00515 
00516 
00517 // **********************************************************
00518 //  SolvableVisMueller
00519 //
00520 
00521 class SolvableVisMueller : public SolvableVisCal, virtual public VisMueller
00522 {
00523 
00524 public:
00525 
00526   SolvableVisMueller(VisSet& vs);
00527 
00528   SolvableVisMueller(const Int& nAnt);
00529 
00530   virtual ~SolvableVisMueller();
00531 
00532   // Total number of (complex) parameters per solve
00533   //  Mueller version:  just return number of per-Bln parameters
00534   virtual Int nTotalPar() { return nPar(); };
00535 
00536   // Does normalization by MODEL_DATA commute with this VisCal?
00537   virtual Bool normalizable() { return (this->muellerType() < Mueller::General); };
00538 
00539   // Hazard a guess at the parameters (solvePar) given the data
00540   virtual void guessPar(VisBuffer& vb) { throw(AipsError("NYI")); };
00541 
00542   // Differentiate VB model w.r.t. Mueller parameters (no 2nd derivative yet)
00543   virtual void differentiate(CalVisBuffer& cvb) {throw(AipsError("NYI")); };
00544   virtual void differentiate(VisBuffer& vb,          // input data
00545                              Cube<Complex>& V,       // trial apply (nCorr,nChan,nRow)
00546                              Array<Complex>& dV,     // 1st deriv   (nCorr,nPar,nChan,nRow)
00547                              Matrix<Bool>& Vflg) { throw(AipsError("NYI")); };
00548   using SolvableVisCal::differentiate;
00549 
00550   // Differentiate VB model w.r.t. Source parameters
00551   virtual void diffSrc(VisBuffer& vb,        
00552                        Array<Complex>& dV) {throw(AipsError("NYI")); };
00553 
00554   // Apply refant (no-op for Muellers)
00555   virtual void reReference() {};
00556 
00557   // Accumulate another VisCal onto this one
00558   virtual void accumulate(SolvableVisCal* incr,
00559                           const Vector<Int>& fields) { throw(AipsError("NYI")); };
00560 
00561   // Scale solutions
00562   virtual void fluxscale(const Vector<Int>& refFieldIn,
00563                          const Vector<Int>& tranFieldIn,
00564                          const Vector<Int>& inRefSpwMap,
00565                          const Vector<String>& fldNames,
00566                          Matrix<Double>& fluxScaleFactor) { throw(AipsError("NYI")); };
00567 
00568   // Report state:
00569   inline virtual void state() { stateSVM(True); };
00570 
00571   // List calibration solutions in tabular form.
00572   virtual void listCal(const Vector<Int> ufldids, 
00573                        const Vector<Int> uantids,
00574                        const Matrix<Int> uchanids,
00575                                const String& listfile = "",
00576                        const Int& pagerows = 50) 
00577   { throw(AipsError(String("Calibration listing not supported for "+typeName()))); };
00578 
00579 protected:
00580 
00581   // Number of Cal Matrices to form on baseline axis
00582   //  (Mueller, solve context: 1)
00583   virtual Int nCalMat() { return isSolved() ? 1 : nBln(); };
00584 
00585   // Are differentiated M matrices constant in chan & bln?
00586   virtual Bool trivialDM() { return False; };
00587 
00588   // Initialize solve parameter shape
00589   //  Mueller version:  (nPar(),1,1)   (one chan, one baseline)
00590   virtual void initSolvePar();
00591 
00592   // Access to matrix rendering of dM (per par)
00593   inline Mueller& dM() { return *dM_; };
00594 
00595   // Access to differentiated Mueller elements
00596   inline Array<Complex>& diffMElem() {return diffMElem_;};
00597 
00598   // Invalidate diff cal matrices generically (at this level, just M, dM)
00599   inline virtual void invalidateDiffCalMat() { invalidateM(); invalidateDM(); };
00600 
00601   // Validation of diffMueller matrices
00602   inline void invalidateDM() {DMValid_=False;};
00603   inline void validateDM()   {DMValid_=True;};
00604   inline Bool DMValid()      {return DMValid_;};
00605 
00606   // Synchronize the differentiated calibration (specialization for Mueller);
00607   virtual void syncDiffMat();
00608 
00609   // Synchronize the Muellers AND diffMuellers
00610   virtual void syncDiffMueller();
00611 
00612   // Calculate the ensemble of diff'd Mueller Elements
00613   virtual void calcAllDiffMueller();
00614 
00615   // Calculate one diffMElem 
00616   virtual void calcOneDiffMueller(Matrix<Complex>& mat, const Vector<Complex>& par);
00617 
00618   // Create matrix renderers for dMs
00619   void createDiffMueller();
00620 
00621   // Initialize trivial diff'd Muellers
00622   virtual void initTrivDM();
00623 
00624   // SVM-specific state
00625   virtual void stateSVM(const Bool& doVC);
00626 
00627 private:
00628 
00629   // Default ctor is private
00630   SolvableVisMueller();
00631 
00632   // Mueller wrapper for diffMElem_;
00633   Mueller *dM_;
00634 
00635   // Differentiated Mueller matrix elements
00636   Array<Complex> diffMElem_;    // (nDMEl,nPar,nChanMat,nBln)
00637 
00638   // diffMueller validation
00639   Bool DMValid_;
00640 
00641 
00642 };
00643 
00644 // **********************************************************
00645 //  SolvableVisJones
00646 //
00647 
00648 class SolvableVisJones : public SolvableVisMueller, public VisJones {
00649 
00650 public:
00651 
00652   SolvableVisJones(VisSet& vs);
00653 
00654   SolvableVisJones(const Int& nAnt);
00655 
00656   virtual ~SolvableVisJones();
00657 
00658   // Total number of (complex) parameters per solve
00659   //  Jones version:  nPar()*nAnt()
00660   virtual Int nTotalPar() { return nPar()*nAnt(); };
00661 
00662   // Does normalization by MODEL_DATA commute with this VisCal?
00663   virtual Bool normalizable() { return (this->jonesType() < Jones::GenLinear); };
00664 
00665   // Differentiate VB model w.r.t. Jones parameters
00666   virtual void differentiate(CalVisBuffer& cvb);
00667   virtual void differentiate(VisBuffer& vb,          // input data
00668                              Cube<Complex>& V,       // trial apply (nCorr,nChan,nRow)
00669                              Array<Complex>& dV,     // 1st deriv   (nCorr,nPar,nChan,nRow,2)
00670                              Matrix<Bool>& Vflg);
00671   using SolvableVisMueller::differentiate;
00672 
00673   // Differentiate VB model w.r.t. Source parameters
00674   virtual void diffSrc(VisBuffer& vb,        
00675                        Array<Complex>& dV);
00676 
00677   // Apply refant
00678   virtual void reReference();
00679 
00680   // Accumulate another VisCal onto this one
00681   virtual void accumulate(SolvableVisCal* incr,
00682                           const Vector<Int>& fields);
00683 
00684   // Post solve tinkering (Jones version: includes refant application)
00685   virtual void globalPostSolveTinker();
00686 
00687   // Apply reference antenna (generic Jones version)
00688   virtual void applyRefAnt();
00689 
00690   // Fluxscale is implemented here
00691   void fluxscale(const Vector<Int>& refFieldIn,
00692                  const Vector<Int>& tranFieldIn,
00693                  const Vector<Int>& inRefSpwMap,
00694                  const Vector<String>& fldNames,
00695                  Matrix<Double>& fluxScaleFactor);
00696                              
00697   // Report state:
00698   inline virtual void state() { stateSVJ(True); };
00699 
00700   // Write calibration solutions to the terminal
00701   virtual void listCal(const Vector<Int> ufldids, const Vector<Int> uantids,
00702                        const Matrix<Int> uchanids,
00703                        const String& listfile="",const Int& pagerows=50);
00704 
00705   // Write header for listCal output
00706   int writeHeader(const uInt numAntCols, 
00707                   const uInt numAnts,
00708                   const uInt iElem);
00709 
00710 protected:
00711  
00712   // Number of Cal Matrices to form on baseline axis
00713   //  (Jones, all contexts: nAnt())
00714   virtual Int nCalMat() { return nAnt(); };
00715 
00716   // DM never trivial for SVJ
00717   virtual Bool trivialDM() { return False; };
00718 
00719   // Are differentiated J matrices constant in chan & ant?
00720   inline virtual Bool trivialDJ() { return False; };
00721 
00722   // Initialize solve parameter shape
00723   //  Jones version:  (nPar(),1,nAnt())   (one chan, all antennas)
00724   virtual void initSolvePar();
00725 
00726   // Access to matrix rendering of dJ1, dJ2
00727   inline Jones& dJ1() { return *dJ1_; };
00728   inline Jones& dJ2() { return *dJ2_; };
00729 
00730   // Access to differentiated Joness
00731   Array<Complex>& diffJElem() { return diffJElem_; };
00732 
00733   // Invalidate diff cal matrices generically (at this level, M, dM, J, dJ)
00734   inline virtual void invalidateDiffCalMat() { 
00735     SolvableVisMueller::invalidateDiffCalMat(); invalidateJ(); invalidateDJ(); };
00736 
00737   // Validation of Jones matrix derivatives
00738   inline void invalidateDJ() {DJValid_=False;};
00739   inline void validateDJ()   {DJValid_=True;};
00740   inline Bool DJValid()      {return DJValid_;};
00741 
00742   // Synchronize the differentiated calibration (specialization for Jones)
00743   virtual void syncDiffMat();
00744 
00745   // Synchronize the Jones AND diffJones matrices
00746   virtual void syncDiffJones();
00747 
00748   // Calculate the ensemble of diff'd Jones Elements
00749   virtual void calcAllDiffJones();
00750 
00751   // Calculate one ant/chan's diffJElem w.r.t. each par
00752   virtual void calcOneDiffJones(Matrix<Complex>& mat, const Vector<Complex>& par);
00753 
00754   // Create matrix renderers for dJs
00755   void createDiffJones();
00756 
00757   // Initialize trivial diff'd Jones
00758   virtual void initTrivDJ();
00759 
00760   virtual void stateSVJ(const Bool& doVC);
00761 private:
00762 
00763   // Default ctor is private
00764   SolvableVisJones();
00765 
00766   // Jones wrappers for diffJElem_;
00767   Jones *dJ1_;
00768   Jones *dJ2_;
00769 
00770   // Differentiated Jones matrix elements
00771   Array<Complex> diffJElem_;    // (nJME,nPar,nChanMat,nAnt,2)
00772 
00773   // Validity of Jones matrix derivatives
00774   Bool DJValid_;
00775 
00776   // Column widths for listing
00777   uInt wTime_p,  wField_p, wChan_p, wAmp_p, 
00778        wPhase_p, wFlag_p,  wPol_p,  wAntCol_p, 
00779        wTotal_p, wPreAnt_p;
00780           
00781 };
00782 
00783 // Global methods
00784 
00785 // Discern cal table type from the table itself
00786 String calTableType(const String& tablename);
00787 
00788 
00789 
00790 
00791 
00792 } //# NAMESPACE CASA - END
00793 
00794 #endif

Generated on Thu Aug 27 21:08:49 2009 for NRAOCASA by  doxygen 1.5.1