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/CalCorruptor.h>
00037 #include <synthesis/MeasurementComponents/Mueller.h>
00038 #include <synthesis/MeasurementComponents/Jones.h>
00039 #include <synthesis/MeasurementComponents/VisVector.h>
00040 #include <synthesis/TransformMachines/SynthesisError.h>
00041 #include <synthesis/CalTables/NewCalTable.h>
00042 #include <synthesis/CalTables/CLPatchPanel.h>
00043 #include <synthesis/CalTables/CTPatchedInterp.h>
00044 #include <synthesis/CalTables/CalSetMetaInfo.h>
00045 #include <synthesis/CalTables/VisCalEnum.h>
00046 #include <msvis/MSVis/VisSet.h>
00047 #include <msvis/MSVis/CalVisBuffer.h>
00048 #include <msvis/MSVis/VisBuffGroupAcc.h>
00049 
00050 #include <casa/Logging/LogMessage.h>
00051 #include <casa/Logging/LogSink.h>
00052 #include <casa/Logging/LogIO.h>
00053 #include <casa/OS/Timer.h>
00054 #include <casadbus/plotserver/PlotServerProxy.h>
00055 #include <casadbus/utilities/BusAccess.h>
00056 #include <casadbus/session/DBusSession.h>
00057 
00058 #include <iostream>
00059 #include <fstream>
00060 
00061 namespace casa { //# NAMESPACE CASA - BEGIN
00062 
00063 
00064 // **********************************************************
00065 //  SolvableVisCal
00066 //
00067 
00068 // Forward
00069 class VisEquation;
00070 class SolveDataBuffer;
00071 class SDBList;
00072 
00073 class SolvableVisCal : virtual public VisCal {
00074 public:
00075 
00076   typedef struct fluxScaleStruct {
00077     Matrix<Double> fd;
00078     Matrix<Double> fderr;
00079     Matrix<Int> numSol;
00080     Vector<Double> freq;
00081     Matrix<Double> spidx;
00082     Matrix<Double> spidxerr;
00083     Vector<Double> fitfd;
00084     Vector<Double> fitfderr;
00085     Vector<Double> fitreffreq;
00086   } fluxScaleStruct;
00087 
00088 
00089   SolvableVisCal(VisSet& vs);
00090   
00091   SolvableVisCal(String msname,Int MSnAnt,Int MSnSpw);
00092 
00093   SolvableVisCal(const MSMetaInfoForCal& msmc);
00094 
00095   SolvableVisCal(const Int& nAnt);
00096 
00097   virtual ~SolvableVisCal();
00098 
00099   // Access to user-supplied parameters
00100   inline String&      calTableName()   { return calTableName_; };
00101   inline String&      calTableSelect() { return calTableSelect_; };
00102   inline Bool&        append()         { return append_; };
00103   inline String&      tInterpType()    { return tInterpType_; };
00104   inline String&      fInterpType()    { return fInterpType_; };
00105   inline Vector<Int>& spwMap()         { return spwMap_; };
00106   inline Int&         refant()         { return refantlist()(0); };
00107   inline Vector<Int>& refantlist()     { return urefantlist_; };
00108   inline Int&         minblperant()    { return minblperant_; };
00109   inline String&      apmode()         { return apmode_; };
00110   inline String&      solint()         { return solint_; };
00111   inline String&      fsolint()        { return fsolint_; };
00112   inline Double&      preavg()         { return preavg_; };
00113   inline Bool&        solnorm()        { return solnorm_;};
00114   inline Float&       minSNR()         { return minSNR_; };
00115 
00116   inline String&      combine()        { return combine_; };
00117   inline Bool         combspw()        { return upcase(combine_).contains("SPW"); };
00118   inline Bool         combfld()        { return upcase(combine_).contains("FIELD"); };
00119   inline Bool         combscan()       { return upcase(combine_).contains("SCAN"); };
00120   inline Bool         combobs()        { return upcase(combine_).contains("OBS"); };
00121 
00122   // Total number of (complex) parameters per solve
00123   //  (specialize to jive with ant- or bln-basedness, etc.)
00124   virtual Int nTotalPar()=0;
00125 
00126   // Report if calibration available for specified spw
00127   //  (if no CalInterp available, assume True)
00128 
00129   // Use generic data gathering mechanism for solve
00130   virtual Bool useGenericGatherForSolve() { return True; };
00131 
00132   // Use generic solution engine for a single solve
00133   //  (usually inside the generic gathering mechanism)
00134   virtual Bool useGenericSolveOne() { return useGenericGatherForSolve(); };
00135 
00136   // Solve for point-source X or Q,U?
00137   //  nominally no (0)
00138   virtual Int solvePol() { return 0; };
00139 
00140   // Does normalization by MODEL_DATA commute with this VisCal?
00141   //   (if so, permits pre-solve time-averaging)
00142   virtual Bool normalizable()=0;
00143 
00144   // Is this type capable of accumulation?  (nominally no)
00145   virtual Bool accumulatable() { return False; };
00146 
00147   // Is this type capable of smoothing?  (nominally no)
00148   virtual Bool smoothable() { return False; };
00149 
00150   // Should only parallel-hands be used in solving?
00151   //  (generally no (default=False), but GJones and related
00152   //   will override, and eventually this will be a user-set-able
00153   //   parameter)
00154   virtual Bool phandonly() { return False; }
00155 
00156   // Access to focus channel
00157   inline Int&         focusChan()      { return focusChan_; };
00158 
00159   // Is this ready to solve?
00160   inline Bool isSolved() {return solved_;};
00161 
00162   // Is this solveable? (via this interface, nominally yes)
00163   virtual Bool isSolvable() {return True;};
00164 
00165   // Set the application parameters 
00166   virtual void setApply();
00167   virtual void setApply(const Record& apply);
00168   virtual void setCallib(const Record& callib,const MeasurementSet& selms);
00169 
00170   virtual void setModel(const String& )
00171   {throw(SynthesisError("Internal error: setModel() not yet supported for non EPJones type."));};
00172 
00173   // Report apply info/params, e.g. for logging
00174   virtual String applyinfo();
00175 
00176   // Set the solving parameters
00177   virtual void setSolve();
00178   virtual void setSolve(const Record& solve);
00179 
00180   // Report solve info/params, e.g., for logging
00181   virtual String solveinfo();
00182 
00183   // Arrange for accumulation
00184   virtual void setAccumulate(VisSet& vs,
00185                              const String& table,
00186                              const String& select,
00187                              const Double& t,
00188                              const Int& refAnt=-1);
00189 
00190   // Default value for parameters
00191   virtual Complex defaultPar() { return Complex(1.0); };
00192   virtual Float defaultRPar() { return Float(0.0); };
00193   virtual Complex defaultCPar() { return Complex(1.0); };
00194 
00195   // Arrange to build a cal table from specified values
00196   virtual void setSpecify(const Record& specify);
00197 
00198   // Fill a caltable with specified values
00199   virtual void specify(const Record& specify);
00200 
00201   // Size up the solving arrays, etc.  (supports combine)
00202   virtual Int sizeUpSolve(VisSet& vs, Vector<Int>& nChunkPerSol);
00203 
00204   // These inflate methods soon to deprecate (gmoellen, 20121212)
00205   // Inflate the pristine CalSet (from VisSet info)
00206   void inflate(VisSet& vs, const Bool& fillMeta=False);
00207   // Inflate the pristine CalSet (generically)
00208   virtual void inflate(const Vector<Int>& nChanDat,
00209                        const Vector<Int>& startChanDat,
00210                        const Vector<Int>& nSlot);
00211 
00212 
00213   // Hazard a guess at the parameters (solveCPar) given the data
00214   virtual void guessPar(VisBuffer& vb)=0;
00215   virtual void guessPar(SDBList&) { throw(AipsError("SVC::guessPar(SDBList&) NYI!!")); };  // VI2
00216 
00217   // Time-dep solution interval  (VI2)
00218   inline Double solTimeInterval() const { return solTimeInterval_; };
00219 
00220   // Freq-dep solint values 
00221   inline Double& fintervalHz() { return fintervalHz_; };
00222   inline Double& fintervalCh() { return fintervalCh_(currSpw()); };  // for current Spw
00223   Matrix<Int> chanAveBounds()  { return chanAveBounds_(currSpw()); }; // for current Spw
00224   Matrix<Int> chanAveBounds(Int spw)  { return chanAveBounds_(spw); }; 
00225 
00226   // Access to current solution parameters and matrices
00227   inline virtual Cube<Complex>& solveCPar()   {return (*solveCPar_[currSpw()]);};
00228   inline virtual Cube<Float>&   solveRPar()   {return (*solveRPar_[currSpw()]);};
00229   inline virtual Cube<Bool>&    solveParOK()  {return (*solveParOK_[currSpw()]);};
00230   inline virtual Cube<Float> &  solveParErr() {return (*solveParErr_[currSpw()]);};
00231   inline virtual Cube<Float> &  solveParSNR() {return (*solveParSNR_[currSpw()]);};
00232   inline virtual Cube<Complex>& solveAllCPar()   {return (*solveAllCPar_[currSpw()]);};
00233   inline virtual Cube<Float>&   solveAllRPar()   {return (*solveAllRPar_[currSpw()]);};
00234   inline virtual Cube<Bool>&    solveAllParOK()  {return (*solveAllParOK_[currSpw()]);};
00235   inline virtual Cube<Float> &  solveAllParErr() {return (*solveAllParErr_[currSpw()]);};
00236   inline virtual Cube<Float> &  solveAllParSNR() {return (*solveAllParSNR_[currSpw()]);};
00237 
00238   // Access to source pol parameters
00239   inline Vector<Complex>& srcPolPar() { return srcPolPar_; };
00240 
00241   // Synchronize the meta data with a solvable VisBuffer
00242   //   (returns False if VisBuffer has no valid data)
00243   Bool syncSolveMeta(VisBuffer& vb, const Int& fieldId);
00244   Bool syncSolveMeta(VisBuffGroupAcc& vbga);
00245   void syncSolveMeta(SDBList& sdbs);  // VI2   (valid data now checked elsewhere)
00246 
00247   // Provide for override of currScan and currObs
00248   void overrideObsScan(Int obs, Int scan);
00249 
00250   // If apmode() is "A", convert vb's visibilities to amp + 0i.
00251   // If it is "P", convert them to phase + 0i.
00252   // Otherwise (i.e. "AP"), leave them alone.
00253   virtual void enforceAPonData(VisBuffer& vb);
00254 
00255   // Verify VisBuffer data sufficient for solving (wts, etc.)
00256   virtual Bool verifyConstraints(VisBuffGroupAcc& vbag);
00257   virtual Bool verifyConstraints(SDBList& sdbs);  // VI2 
00258   virtual Bool verifyForSolve(VisBuffer& vb);
00259   
00260   // Self- gather and/or solve prototypes
00261   //  (triggered by useGenericGatherForSolve=F or useGenericSolveOne=F; 
00262   //   must be overridden in derived specializations)
00263   virtual void selfGatherAndSolve(VisSet& vs, VisEquation& ve);
00264   virtual void selfSolveOne(VisBuffGroupAcc& vs);
00265   virtual void selfSolveOne(SDBList&) { throw(AipsError("selfSolveOne for VI2/SDB usage NYI for "+typeName())); };
00266 
00267   // Set up data and model for pol solve
00268   void setUpForPolSolve(VisBuffer& vb);
00269 
00270   // Differentiate VB model w.r.t. Cal  parameters (no 2nd derivative yet)
00271   virtual void differentiate(CalVisBuffer& cvb)=0;
00272   virtual void differentiate(SolveDataBuffer&) { throw(AipsError("SVC::differentiate(SDB)  NYI!")); };  // VI2
00273   virtual void differentiate(VisBuffer& vb,        
00274                              Cube<Complex>& V,     
00275                              Array<Complex>& dV,
00276                              Matrix<Bool>& Vflg)=0;
00277   virtual void differentiate(VisBuffer& ,          // vb.visCube() has the obs. data.  vb.modelVisCube() will receive the residuals
00278                              VisBuffer&   ,       // 1st. Derivative w.r.t. first parameter
00279                              VisBuffer& ,         // 1st. Derivative w.r.t. second parameter
00280                              Matrix<Bool>& ){ throw(AipsError("Invalid use of differentiate(vb,dV0,dv1)")); };
00281 
00282 
00283   // Differentiate VB model w.r.t. Source parameters
00284   virtual void diffSrc(VisBuffer& vb,        
00285                        Array<Complex>& dV)=0;
00286 
00287   // Update solve parameters incrementally (additive)
00288   virtual void updatePar(const Vector<Complex> dCalPar,const Vector<Complex> dSrcPar);
00289   virtual void updatePar(const Vector<Complex> dCalPar);  //  (VI2)
00290 
00291   // Form solution SNR
00292   virtual void formSolveSNR();
00293 
00294   // Apply SNR threshold
00295   virtual void applySNRThreshold();
00296 
00297   // Apply refant (implemented in SVJ)
00298   virtual void reReference()=0;
00299 
00300   // Retrieve the cal flag info as a record
00301   virtual Record actionRec();
00302 
00303   // Accumulate another VisCal onto this one
00304   virtual void accumulate(SolvableVisCal* incr,
00305                           const Vector<Int>& fields)=0;
00306 
00307   virtual void smooth(Vector<Int>& fields,
00308                       const String& smtype,
00309                       const Double& smtime);
00310 
00311   // Report solved-for QU
00312   virtual void reportSolvedQU();
00313 
00314 
00315   // New CalTable handling
00316   virtual void createMemCalTable();
00317   virtual void keep1(Int ichan);
00318   virtual void keepNCT();
00319   virtual void storeNCT();
00320   void storeNCT(const String& tableName,const Bool& append);
00321 
00322   virtual void loadMemCalTable(String ctname,String field="");
00323 
00324   // New spwOK
00325   virtual Bool spwOK(Int ispw);
00326 
00327   // Post solve tinkering (generic version)
00328   virtual void globalPostSolveTinker();
00329 
00330   // Divide all solutions by their amplitudes
00331   virtual void enforceAPonSoln();
00332 
00333   // Normalize a solution (generic implementation)
00334   virtual void normalize();
00335 
00336   // Determine and apply flux density scaling
00337   virtual void fluxscale(const String& outfile,
00338                          const Vector<Int>& refFieldIn,
00339                          const Vector<Int>& tranFieldIn,
00340                          const Vector<Int>& inRefSpwMap,
00341                          const Vector<String>& fldNames,
00342                          const Float& inGainThres,
00343                          const String& antSel,
00344                          const String& timerangeSel,
00345                          const String& scanSel,
00346                          fluxScaleStruct& oFluxScaleStruct,
00347                          const String& oListFile,
00348                          const Bool& incremental,
00349                          const Int& fitorder,
00350                          const Bool& display)=0;
00351 
00352   // Report state:
00353   inline virtual void state() { stateSVC(True); };
00354 
00355   virtual VisCalEnum::VCParType setParType(VisCalEnum::VCParType type) 
00356   {parType_ = type;return (VisCalEnum::VCParType)parType_;};
00357   virtual void currMetaNote();
00358 
00359   virtual void listCal(const Vector<Int> ufldids, const Vector<Int> uantids,
00360                        const Matrix<Int> uchanids,  //const Int& spw, const Int& chan,
00361                        const String& listfile="",const Int& pagerows=50)=0;
00362 
00363   // Handle external channel mask
00364   inline void setChanMask(PtrBlock<Vector<Bool>*>& chanmask) { chanmask_=&chanmask; };
00365   inline void clearChanMask() { chanmask_=NULL; };
00366   void applyChanMask(VisBuffer& vb);
00367   // Log periodic solver activity
00368   virtual void printActivity(const Int nSlots, const Int slotNo, 
00369                              const Int fieldId, const Int spw, 
00370                              const Int nSolutions);
00371   virtual void markTimer() {timer_p.mark();};
00372 
00373 
00374   // -------------
00375   // Set the simulation parameters
00376   virtual void setSimulate(VisSet& vs, Record& simpar, Vector<Double>& solTimes);
00377 
00378   // make a corruptor in a VC-specific way
00379   virtual void createCorruptor(const VisIter& vi,const Record& simpar, const int nSim);
00380 
00381   // access to simulation variables that are general to all VisCals
00382   inline String& simint() { return simint_; };
00383 
00384   // Simulation info/params, suitable for logging
00385   virtual String siminfo();
00386 
00387   // Is this calibration simulated?
00388   inline Bool isSimulated() {return simulated_;};
00389 
00390   // object that can simulate the corruption terms
00391   CalCorruptor *corruptor_p;
00392 
00393   // calculate # required slots to simulate this SVC
00394   Int sizeUpSim(VisSet& vs, Vector<Int>& nChunkPerSol, Vector<Double>& solTimes);
00395 
00396 
00397   // VI2-related refactor--------------------------------------
00398 
00399   // Set "current" meta info, so internals are registered
00400   //  (VI2: replaces meta-inf part of syncSolveMeta; 
00401   //   NB: does _NOT_ check sum(wt)>0 older syncSolveMeta!)
00402   virtual void setMeta(Int obs, Int scan, Double time,
00403                        Int spw, const Vector<Double>& freq,
00404                        Int fld);
00405 
00406   // Reshape solvePar* arrays for the currSpw()  
00407   //  (ensitive to freqDepPar())
00408   //  (VI2: replaces initSolvePar part of sizeUpSolve)
00409   virtual Int sizeSolveParCurrSpw(Int nVisChan);
00410 
00411   // Set parameters to def values in the currSpw(), 
00412   //   and optionally sync everything
00413   virtual void setDefSolveParCurrSpw(Bool sync=False);
00414 
00415   // Parse solint in VI2 context
00416   void reParseSolintForVI2();
00417 
00418   // Generate the in-memory caltable (empty)
00419   //  NB: no subtable revisions
00420   virtual void createMemCalTable2();
00421 
00422   // Set (or verify) freq info in output cal table for specified spw
00423   virtual void setOrVerifyCTFrequencies(Int spw);
00424 
00425 
00426 protected:
00427 
00428   // Set to-be-solved-for flag
00429   inline void setSolved(const Bool& flag) {solved_=flag;};
00430 
00431   // Initialize solve parameters (shape)
00432   virtual void initSolvePar()=0;
00433 
00434   // Invalidate diff cal matrices generically 
00435   inline virtual void invalidateDiffCalMat()=0;
00436 
00437   // Explicitly synchronize pars with a CalSet slot
00438   using VisCal::syncPar;
00439 
00440   // Set matrix channelization according to a VisSet
00441   virtual void setSolveChannelization(VisSet& vs);
00442 
00443   // Calculate chan averaging bounds
00444   virtual void setFracChanAve();
00445 
00446   // Inflate an NCT w/ meta-data according to a VisSet 
00447   //   (for accum)
00448   void inflateNCTwithMetaData(VisSet& vs);
00449 
00450   // Synchronize calibration for solve context
00451   void syncSolveCal();
00452 
00453   // Synchronize parameters for solve context
00454   void syncSolvePar();
00455 
00456   // Calculate parameters by some means (e.g., interpolation from a CalSet)
00457   virtual void calcPar();
00458   virtual void calcParByCLPP();
00459 
00460   // Synchronize the differentiated calibration 
00461   virtual void syncDiffMat()=0;
00462 
00463   // Report the SVC-specific state, w/ option for VC::state()
00464   virtual void stateSVC(const Bool& doVC);
00465 
00466   // Normalize a (complex) solution array (generic)
00467   void normSolnArray(Array<Complex>& sol,
00468                      const Array<Bool>& solOK,
00469                      const Bool doPhase=False);
00470 
00471   virtual Float calcPowerNorm(Array<Float>& amp, const Array<Bool>& ok)=0;
00472 
00473   // Logger
00474   LogIO& logSink() { return logsink_p; };
00475 
00476   // Check if a cal table is appropriate
00477   void verifyCalTable(const String& caltablename);
00478 
00479   void sortVisSet(VisSet& vs, const Bool verbose=False);
00480 
00481   Int parType_;
00482 
00483   // New CalTable 
00484   NewCalTable *ct_;
00485   CTPatchedInterp *ci_;
00486   CLPatchPanel *cpp_;
00487   Vector<Bool> spwOK_;
00488 
00489   Double maxTimePerSolution_p, minTimePerSolution_p, avgTimePerSolution_p;
00490   Float userPrintActivityInterval_p, userPrintActivityFraction_p;
00491   uInt caiRC_p, cafRC_p;
00492   Timer timer_p;
00493 
00494   // Set state flag to simulate cal terms
00495   inline void setSimulated(const Bool& flag) {simulated_=flag;};
00496 
00497   // RI todo implement calcOneJones like calcAllMueller
00498   // calculate terms during apply, or up front during setSim?
00499   inline Bool& simOnTheFly() { 
00500     //    cout << "simOTF=" << onthefly_ << endl;
00501     return onthefly_; };
00502 
00503 
00504 
00505 private:
00506 
00507   // Default ctor is private
00508   SolvableVisCal();
00509 
00510   // Initialize pointers, etc.
00511   void initSVC();
00512 
00513   // Delete pointers
00514   void deleteSVC();
00515 
00516 
00517   // Cal table name
00518   String calTableName_;
00519   String calTableSelect_;
00520   Bool append_;
00521 
00522   // Interpolation types
00523   String tInterpType_;
00524   String fInterpType_;
00525 
00526   // Spw mapping
00527   Vector<Int> spwMap_;
00528 
00529   // Refant
00530   Vector<Int> urefantlist_;
00531 
00532   // Min baselines per ant for solve
00533   Int minblperant_;
00534 
00535   // Solved-for flag
00536   Bool solved_;
00537 
00538   // Signal apply by callib
00539   Bool byCallib_;
00540 
00541   // Solving mode
00542   String apmode_;
00543 
00544   // User-specified full solint string
00545   String usolint_;
00546 
00547   // User-specified time-dep solint (string)
00548   String solint_;
00549 
00550   // Derived time-dep solution interval (s) (VI2)
00551   Double solTimeInterval_;
00552 
00553   // User-specified freq-dep solint info
00554   String fsolint_;
00555 
00556   // Derived frequency intervals
00557   Double fintervalHz_;
00558   Vector<Double> fintervalCh_;   // (nSpw)
00559 
00560   // Channel averaging bounds
00561   Vector<Matrix<Int> > chanAveBounds_;  // (nSpw)(2,nOutChan)
00562 
00563   // Preavering interval
00564   Double preavg_;
00565 
00566   // Do solution normalization after a solve
00567   Bool solnorm_;
00568 
00569   // SNR threshold
00570   Float minSNR_;
00571 
00572   // axes to combine for solve
00573   String combine_;
00574 
00575   // In-focus channel for single-chan solves on multi-chan data
00576   Int focusChan_;
00577 
00578   // Solving meta-data
00579   Double dataInterval_;
00580   Double fitWt_;
00581   Double fit_;
00582 
00583 
00584   // Current parameters
00585   PtrBlock<Cube<Complex>*> solveCPar_;  // [nSpw](nPar,1,{1|nElem})
00586   PtrBlock<Cube<Float>*>   solveRPar_;  // [nSpw](nPar,1,{1|nElem})
00587   PtrBlock<Cube<Bool>*>    solveParOK_; // [nSpw](nPar,1,{1|nElm})
00588   PtrBlock<Cube<Float>*>   solveParErr_; // [nSpw](nPar,1,{1|nElm})
00589   PtrBlock<Cube<Float>*>   solveParSNR_; // [nSpw](nPar,1,{1|nElm})
00590 
00591   PtrBlock<Cube<Complex>*> solveAllCPar_;   // [nSpw](nPar,nChan,{1|nElem})
00592   PtrBlock<Cube<Float>*>   solveAllRPar_;   // [nSpw](nPar,nChan,{1|nElem})
00593   PtrBlock<Cube<Bool>*>    solveAllParOK_;  // [nSpw](nPar,nChan,{1|nElm})
00594   PtrBlock<Cube<Float>*>   solveAllParErr_; // [nSpw](nPar,nChan,{1|nElm})
00595   PtrBlock<Cube<Float>*>   solveAllParSNR_; // [nSpw](nPar,nChan,{1|nElm})
00596 
00597   Vector<Complex> srcPolPar_;
00598 
00599   // A _pointer_ to the external channel mask
00600   PtrBlock<Vector<Bool>*> *chanmask_;
00601 
00602   // LogIO
00603   LogIO logsink_p;
00604 
00605   // Simulation flag
00606   Bool simulated_;
00607 
00608   // simulation interval
00609   String simint_;
00610 
00611   Bool onthefly_;  
00612 
00613 };
00614 
00615 
00616 
00617 // **********************************************************
00618 //  SolvableVisMueller
00619 //
00620 
00621 class SolvableVisMueller : public SolvableVisCal, virtual public VisMueller
00622 {
00623 
00624 public:
00625 
00626   SolvableVisMueller(VisSet& vs);
00627 
00628   SolvableVisMueller(String msname,Int MSnAnt,Int MSnSpw);
00629 
00630   SolvableVisMueller(const MSMetaInfoForCal& msmc);
00631 
00632   SolvableVisMueller(const Int& nAnt);
00633 
00634   virtual ~SolvableVisMueller();
00635 
00636   // Total number of (complex) parameters per solve
00637   //  Mueller version:  just return number of per-Bln parameters
00638   virtual Int nTotalPar() { return nPar(); };
00639 
00640   // Does normalization by MODEL_DATA commute with this VisCal?
00641   virtual Bool normalizable() { return (this->muellerType() < Mueller::General); };
00642 
00643   // Hazard a guess at the parameters (solvePar) given the data
00644   virtual void guessPar(VisBuffer& ) { throw(AipsError("NYI")); };
00645 
00646   // Differentiate VB model w.r.t. Mueller parameters (no 2nd derivative yet)
00647   virtual void differentiate(CalVisBuffer& ) {throw(AipsError("SVM::differentiate(CVB): NYI")); };
00648   virtual void differentiate(SolveDataBuffer& ) {throw(AipsError("SVM::differentiate(SDB): NYI")); };  // VI2
00649   virtual void differentiate(VisBuffer& ,          // input data
00650                              Cube<Complex>& ,       // trial apply (nCorr,nChan,nRow)
00651                              Array<Complex>& ,     // 1st deriv   (nCorr,nPar,nChan,nRow)
00652                              Matrix<Bool>& ) { throw(AipsError("NYI")); };
00653   using SolvableVisCal::differentiate;
00654 
00655   // Differentiate VB model w.r.t. Source parameters
00656   virtual void diffSrc(VisBuffer& ,
00657                        Array<Complex>& ) {throw(AipsError("NYI")); };
00658 
00659   // Apply refant (no-op for Muellers)
00660   virtual void reReference() {};
00661 
00662   // Accumulate another VisCal onto this one
00663   virtual void accumulate(SolvableVisCal* ,
00664                           const Vector<Int>& ) { throw(AipsError("NYI")); };
00665 
00666   // Scale solutions
00667   virtual void fluxscale(const String&,
00668                          const Vector<Int>& ,
00669                          const Vector<Int>& ,
00670                          const Vector<Int>& ,
00671                          const Vector<String>& ,
00672                          const Float& ,
00673                          const String& ,
00674                          const String& ,
00675                          const String& ,
00676                          SolvableVisCal::fluxScaleStruct&,
00677                          const String&,
00678                          const Bool&,
00679                          const Int&,
00680                          const Bool&)
00681         { throw(AipsError("NYI")); };
00682 
00683   // SVM-specific write to caltable
00684   virtual void keepNCT();
00685 
00686   // Report state:
00687   inline virtual void state() { stateSVM(True); };
00688 
00689   // List calibration solutions in tabular form.
00690   virtual void listCal(const Vector<Int> ,
00691                        const Vector<Int> ,
00692                        const Matrix<Int> ,
00693                                const String& ,
00694                        const Int& )
00695   { throw(AipsError(String("Calibration listing not supported for "+typeName()))); };
00696 
00697 protected:
00698 
00699   // Number of Cal Matrices to form on baseline axis
00700   //  (Mueller, solve context: 1)
00701   virtual Int nCalMat() { return isSolved() ? 1 : nBln(); };
00702 
00703   // Are differentiated M matrices constant in chan & bln?
00704   virtual Bool trivialDM() { return False; };
00705 
00706   // Initialize solve parameter shape
00707   //  Mueller version:  (nPar(),1,1)   (one chan, one baseline)
00708   virtual void initSolvePar();
00709 
00710   // Access to matrix rendering of dM (per par)
00711   inline Mueller& dM() { return *dM_; };
00712 
00713   // Access to differentiated Mueller elements
00714   inline Array<Complex>& diffMElem() {return diffMElem_;};
00715 
00716   // Invalidate diff cal matrices generically (at this level, just M, dM)
00717   inline virtual void invalidateDiffCalMat() { invalidateM(); invalidateDM(); };
00718 
00719   // Validation of diffMueller matrices
00720   inline void invalidateDM() {DMValid_=False;};
00721   inline void validateDM()   {DMValid_=True;};
00722   inline Bool DMValid()      {return DMValid_;};
00723 
00724   // Synchronize the differentiated calibration (specialization for Mueller);
00725   virtual void syncDiffMat();
00726 
00727   // Synchronize the Muellers AND diffMuellers
00728   virtual void syncDiffMueller();
00729 
00730   // Calculate the ensemble of diff'd Mueller Elements
00731   virtual void calcAllDiffMueller();
00732 
00733   // Calculate one diffMElem 
00734   virtual void calcOneDiffMueller(Matrix<Complex>& mat, const Vector<Complex>& par);
00735 
00736   // Create matrix renderers for dMs
00737   void createDiffMueller();
00738 
00739   // Override VM::setMatByOk in solve context
00740   void setMatByOk() { if (!isSolved()) VisMueller::setMatByOk(); };
00741 
00742   // Initialize trivial diff'd Muellers
00743   virtual void initTrivDM();
00744 
00745   // SVM-specific state
00746   virtual void stateSVM(const Bool& doVC);
00747 
00748   // atomic power normalization calculation
00749   //   Mueller version assumes amp in power units
00750   virtual Float calcPowerNorm(Array<Float>& amp, const Array<Bool>& ok);
00751 
00752 private:
00753 
00754   // Default ctor is private
00755   SolvableVisMueller();
00756 
00757   // Mueller wrapper for diffMElem_;
00758   Mueller *dM_;
00759 
00760   // Differentiated Mueller matrix elements
00761   Array<Complex> diffMElem_;    // (nDMEl,nPar,nChanMat,nBln)
00762 
00763   // diffMueller validation
00764   Bool DMValid_;
00765 
00766 
00767 };
00768 
00769 // **********************************************************
00770 //  SolvableVisJones
00771 //
00772 
00773 class SolvableVisJones : public SolvableVisMueller, public VisJones {
00774 
00775 public:
00776 
00777   SolvableVisJones(VisSet& vs);
00778 
00779   SolvableVisJones(String msname,Int MSnAnt,Int MSnSpw);
00780 
00781   SolvableVisJones(const MSMetaInfoForCal& msmc);
00782 
00783   SolvableVisJones(const Int& nAnt);
00784 
00785   virtual ~SolvableVisJones();
00786 
00787   // Total number of (complex) parameters per solve
00788   //  Jones version:  nPar()*nAnt()
00789   virtual Int nTotalPar() { return nPar()*nAnt(); };
00790 
00791   // Does normalization by MODEL_DATA commute with this VisCal?
00792   virtual Bool normalizable() { return (this->jonesType() < Jones::GenLinear); };
00793 
00794   // Differentiate VB model w.r.t. Jones parameters
00795   virtual void differentiate(CalVisBuffer& cvb);
00796   virtual void differentiate(SolveDataBuffer& sdb);  // VI2
00797   virtual void differentiate(VisBuffer& vb,          // input data
00798                              Cube<Complex>& V,       // trial apply (nCorr,nChan,nRow)
00799                              Array<Complex>& dV,     // 1st deriv   (nCorr,nPar,nChan,nRow,2)
00800                              Matrix<Bool>& Vflg);
00801   using SolvableVisMueller::differentiate;
00802 
00803   // Differentiate VB model w.r.t. Source parameters
00804   virtual void diffSrc(VisBuffer& vb,        
00805                        Array<Complex>& dV);
00806 
00807   // Apply refant
00808   virtual void reReference();
00809 
00810   // Accumulate another VisCal onto this one
00811   virtual void accumulate(SolvableVisCal* incr,
00812                           const Vector<Int>& fields);
00813 
00814   // Post solve tinkering (Jones version: includes refant application)
00815   virtual void globalPostSolveTinker();
00816 
00817   // Apply reference antenna (generic Jones version)
00818   virtual void applyRefAnt();
00819 
00820   // Fluxscale is implemented here
00821   void fluxscale(const String& outfile,
00822                  const Vector<Int>& refFieldIn,
00823                  const Vector<Int>& tranFieldIn,
00824                  const Vector<Int>& inRefSpwMap,
00825                  const Vector<String>& fldNames,
00826                  const Float& inGainThres,
00827                  const String& antSel,
00828                  const String& timerangeSel,
00829                  const String& scanSel,
00830                  SolvableVisCal::fluxScaleStruct& oFluxScaleStruct,
00831                  const String& oListFile,
00832                  const Bool& incremental=False,
00833                  const Int& fitorder=1,
00834                  const Bool& display=False);
00835 
00836   // SVJ-specific write to caltable
00837   virtual void keepNCT();
00838 
00839   // Report state:
00840   inline virtual void state() { stateSVJ(True); };
00841 
00842   // Write calibration solutions to the terminal
00843   virtual void listCal(const Vector<Int> ufldids, const Vector<Int> uantids,
00844                        const Matrix<Int> uchanids,
00845                        const String& listfile="",const Int& pagerows=50);
00846 
00847   // Write header for listCal output
00848   int writeHeader(const uInt numAntCols, 
00849                   const uInt numAnts,
00850                   const uInt iElem);
00851 
00852   virtual void nearest(const Double , Array<Float>& ) {};
00853   virtual void nearest(const Double , Array<Complex>& ) {};
00854 
00855   //plotting historgram
00856   void setupPlotter();
00857   void plotHistogram(const String& title, const Int index,
00858                      const Vector<Double>& data, const Int nbin);
00859 
00860 protected:
00861  
00862   // Number of Cal Matrices to form on baseline axis
00863   //  (Jones, all contexts: nAnt())
00864   virtual Int nCalMat() { return nAnt(); };
00865 
00866   // DM never trivial for SVJ
00867   virtual Bool trivialDM() { return False; };
00868 
00869   // Are differentiated J matrices constant in chan & ant?
00870   inline virtual Bool trivialDJ() { return False; };
00871 
00872   // Initialize solve parameter shape
00873   //  Jones version:  (nPar(),1,nAnt())   (one chan, all antennas)
00874   virtual void initSolvePar();
00875 
00876   // Access to matrix rendering of dJ1, dJ2
00877   inline Jones& dJ1() { return *dJ1_; };
00878   inline Jones& dJ2() { return *dJ2_; };
00879 
00880   // Access to differentiated Joness
00881   Array<Complex>& diffJElem() { return diffJElem_; };
00882 
00883   // Invalidate diff cal matrices generically (at this level, M, dM, J, dJ)
00884   inline virtual void invalidateDiffCalMat() { 
00885     SolvableVisMueller::invalidateDiffCalMat(); invalidateJ(); invalidateDJ(); };
00886 
00887   // Validation of Jones matrix derivatives
00888   inline void invalidateDJ() {DJValid_=False;};
00889   inline void validateDJ()   {DJValid_=True;};
00890   inline Bool DJValid()      {return DJValid_;};
00891 
00892   // Synchronize the differentiated calibration (specialization for Jones)
00893   virtual void syncDiffMat();
00894 
00895   // Synchronize the Jones AND diffJones matrices
00896   virtual void syncDiffJones();
00897 
00898   // Calculate the ensemble of diff'd Jones Elements
00899   virtual void calcAllDiffJones();
00900 
00901   // Calculate one ant/chan's diffJElem w.r.t. each par
00902   virtual void calcOneDiffJones(Matrix<Complex>& mat, const Vector<Complex>& par);
00903 
00904   // Create matrix renderers for dJs
00905   void createDiffJones();
00906 
00907   // Override VJ::setMatByOk in solve context
00908   void setMatByOk() { if (!isSolved()) VisJones::setMatByOk(); };
00909 
00910   // Initialize trivial diff'd Jones
00911   virtual void initTrivDJ();
00912 
00913   virtual void stateSVJ(const Bool& doVC);
00914 
00915   // atomic power normalization calculation
00916   //   SVJ version assumes amp in voltage units
00917   virtual Float calcPowerNorm(Array<Float>& amp, const Array<Bool>& ok);
00918                              
00919 private:
00920 
00921   // Default ctor is private
00922   SolvableVisJones();
00923 
00924   // Jones wrappers for diffJElem_;
00925   Jones *dJ1_;
00926   Jones *dJ2_;
00927 
00928   // Differentiated Jones matrix elements
00929   Array<Complex> diffJElem_;    // (nJME,nPar,nChanMat,nAnt,2)
00930 
00931   // Validity of Jones matrix derivatives
00932   Bool DJValid_;
00933 
00934   // Column widths for listing
00935   uInt wTime_p,  wField_p, wChan_p, wAmp_p, 
00936        wPhase_p, wFlag_p,  wPol_p,  wAntCol_p, 
00937        wTotal_p, wPreAnt_p;
00938 
00939   //for plotting
00940   PlotServerProxy* plotter_;
00941   Vector<dbus::variant> panels_id_;
00942 
00943 };
00944 
00945 // Global methods
00946 
00947 // Discern cal table type from the table itself
00948 String calTableType(const String& tablename);
00949 
00950 } //# NAMESPACE CASA - END
00951 
00952 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1