LCOV - code coverage report
Current view: top level - synthesis/MeasurementComponents - SolvableVisCal.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 136 0.0 %
Date: 2024-10-10 19:51:30 Functions: 0 120 0.0 %

          Line data    Source code
       1             : //# SolvableVisCal.h: Definitions of interface for SolvableVisCal 
       2             : //# Copyright (C) 1996,1997,2000,2001,2002,2003
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be adressed as follows:
      20             : //#        Internet email: casa-feedback@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //#
      27             : 
      28             : #ifndef SYNTHESIS_SOLVABLEVISCAL_H
      29             : #define SYNTHESIS_SOLVABLEVISCAL_H
      30             : 
      31             : #include <casacore/casa/aips.h>
      32             : #include <casacore/casa/Containers/Record.h>
      33             : #include <casacore/casa/BasicSL/Complex.h>
      34             : #include <casacore/casa/BasicSL/Constants.h>
      35             : #include <synthesis/MeasurementComponents/VisCal.h>
      36             : #include <synthesis/MeasurementComponents/CalCorruptor.h>
      37             : #include <synthesis/MeasurementComponents/Mueller.h>
      38             : #include <synthesis/MeasurementComponents/Jones.h>
      39             : #include <synthesis/MeasurementComponents/VisVector.h>
      40             : #include <synthesis/TransformMachines/SynthesisError.h>
      41             : #include <synthesis/CalTables/NewCalTable.h>
      42             : #include <synthesis/CalTables/CLPatchPanel.h>
      43             : #include <synthesis/CalTables/CTPatchedInterp.h>
      44             : #include <synthesis/CalTables/CalSetMetaInfo.h>
      45             : #include <synthesis/CalTables/VisCalEnum.h>
      46             : #include <msvis/MSVis/VisSet.h>
      47             : #include <msvis/MSVis/CalVisBuffer.h>
      48             : #include <msvis/MSVis/VisBuffGroupAcc.h>
      49             : 
      50             : #include <casacore/casa/Logging/LogMessage.h>
      51             : #include <casacore/casa/Logging/LogSink.h>
      52             : #include <casacore/casa/Logging/LogIO.h>
      53             : #include <casacore/casa/OS/Timer.h>
      54             : 
      55             : #include <iostream>
      56             : #include <fstream>
      57             : 
      58             : namespace casa { //# NAMESPACE CASA - BEGIN
      59             : 
      60             : 
      61             : // **********************************************************
      62             : //  SolvableVisCal
      63             : //
      64             : 
      65             : // Forward
      66             : class VisEquation;
      67             : class SolveDataBuffer;
      68             : class SDBList;
      69             : 
      70             : class SolNorm {
      71             : 
      72             : public:
      73             : 
      74             :   enum Type { MEAN, MEDIAN, UNKNOWN };
      75             : 
      76             :   SolNorm(casacore::Bool donorm=false, casacore::String normtype=casacore::String("mean"));
      77             :   SolNorm(const SolNorm& other);
      78             : 
      79           0 :   inline casacore::Bool donorm() const { return donorm_; };
      80           0 :   inline Type normtype() const { return normtype_; };
      81           0 :   inline casacore::String normtypeString() const { return normTypeAsString(normtype_); };
      82             : 
      83             :   void report();
      84             : 
      85             : private:
      86             : 
      87             :   // data 
      88             :   casacore::Bool donorm_;
      89             :   Type normtype_;
      90             : 
      91             :   static Type normTypeFromString(casacore::String name);
      92             :   static casacore::String normTypeAsString(Type type);
      93             : 
      94             :   
      95             : };
      96             : 
      97             : 
      98             : 
      99             : class FreqMetaData {
     100             : 
     101             : public:
     102             : 
     103             :   FreqMetaData();
     104             : 
     105             :   // Calculate appropriately decimated freq meta info from supplied info
     106             :   void calcFreqMeta(const casacore::Vector< casacore::Vector<casacore::Double> >& msfreq,
     107             :                     const casacore::Vector< casacore::Vector<casacore::Double> >& mswidth,
     108             :                     const casacore::Vector<casacore::uInt>& selspw,
     109             :                     casacore::Bool freqdep,casacore::Bool combspw,
     110             :                     const casacore::Vector<casacore::Int>& spwfanin);
     111             : 
     112             :   // Public access to freq meta info
     113             :   const casacore::Vector<casacore::Double>& freq(casacore::Int spw) const;
     114             :   const casacore::Vector<casacore::Double>& width(casacore::Int spw) const;
     115             :   const casacore::Vector<casacore::Double>& effBW(casacore::Int spw) const;
     116             : 
     117             :   // Public access to spw fan-in
     118             :   casacore::Int fannedInSpw(casacore::Int spw) const;
     119             : 
     120             :   // Has freq meta data been calculated?
     121             :   casacore::Bool ok() const;
     122             : 
     123             :   // Return list of valid spws
     124             :   const casacore::Vector<casacore::Int>& validSpws() const;
     125             : 
     126             : private:
     127             : 
     128             :   // true if we have run calcFreqMeta (indicates valid freq info contained herein
     129             :   casacore::Bool ok_;
     130             : 
     131             :   // List of valid spws (calc'd in calcFreqMeta)
     132             :   casacore::Vector<casacore::Int> validspws_;
     133             : 
     134             :   // The freq meta data arrays  [nSpw][nChan]
     135             :   casacore::Vector< casacore::Vector<casacore::Double> > freq_, width_, effBW_;
     136             : 
     137             :   // When combspw=true, store spw fan-in 
     138             :   casacore::Vector<casacore::Int> spwfanin_;
     139             : 
     140             : };
     141             : 
     142             : 
     143             :  
     144             : class SolvableVisCal : virtual public VisCal {
     145             : public:
     146             : 
     147             :   typedef struct fluxScaleStruct {
     148             :     casacore::Matrix<casacore::Double> fd;
     149             :     casacore::Matrix<casacore::Double> fderr;
     150             :     casacore::Matrix<casacore::Int> numSol;
     151             :     casacore::Vector<casacore::Double> freq;
     152             :     casacore::Matrix<casacore::Double> spidx;
     153             :     casacore::Matrix<casacore::Double> spidxerr;
     154             :     casacore::Vector<casacore::Double> fitfd;
     155             :     casacore::Vector<casacore::Double> fitfderr;
     156             :     casacore::Vector<casacore::Double> fitreffreq;
     157             :     //casacore::Matrix<casacore::Double> covarmat;
     158             :     //casacore::PtrBlock<casacore::Matrix<casacore::Double>* >  covarmat;
     159             :     casacore::Vector<casacore::Matrix<casacore::Double> >  covarmat;
     160             :   } fluxScaleStruct;
     161             : 
     162             : 
     163             :   SolvableVisCal(VisSet& vs);
     164             :   
     165             :   SolvableVisCal(casacore::String msname,casacore::Int MSnAnt,casacore::Int MSnSpw);
     166             : 
     167             :   SolvableVisCal(const MSMetaInfoForCal& msmc);
     168             : 
     169             :   SolvableVisCal(const casacore::Int& nAnt);
     170             : 
     171             :   virtual ~SolvableVisCal();
     172             : 
     173             :   // Access to user-supplied parameters
     174           0 :   inline casacore::String&      calTableName()   { return calTableName_; };
     175           0 :   inline casacore::String&      calTableSelect() { return calTableSelect_; };
     176           0 :   inline casacore::Bool&        append()         { return append_; };
     177           0 :   inline casacore::String&      tInterpType()    { return tInterpType_; };
     178           0 :   inline casacore::String&      fInterpType()    { return fInterpType_; };
     179           0 :   inline casacore::Vector<casacore::Int>& spwMap()         { return spwMap_; };
     180           0 :   inline casacore::String&      refantmode()     { return refantmode_; };
     181           0 :   inline casacore::Int&         refant()         { return refantlist()(0); };
     182           0 :   inline casacore::Vector<casacore::Int>& refantlist()     { return urefantlist_; };
     183           0 :   inline casacore::Int&         minblperant()    { return minblperant_; };
     184           0 :   inline casacore::String&      apmode()         { return apmode_; };
     185           0 :   inline casacore::String&      solmode()        { return solmode_; };
     186           0 :   inline casacore::Vector<casacore::Float>& rmsthresh()      { return rmsthresh_; };
     187           0 :   inline casacore::String&      solint()         { return solint_; };
     188           0 :   inline casacore::String&      fsolint()        { return fsolint_; };
     189           0 :   inline casacore::Double&      preavg()         { return preavg_; };
     190           0 :   inline casacore::String&      corrcomb()       { return corrcomb_; };
     191           0 :   inline const SolNorm&         solNorm()        { return solnorm_;};
     192           0 :   inline casacore::Bool         solnorm()        { return solnorm_.donorm();};
     193           0 :   inline casacore::Float&       minSNR()         { return minSNR_; };
     194             : 
     195           0 :   inline casacore::String&      combine()        { return combine_; };
     196           0 :   inline casacore::Bool         combspw()        { return upcase(combine_).contains("SPW"); };
     197           0 :   inline casacore::Bool         combfld()        { return upcase(combine_).contains("FIELD"); };
     198           0 :   inline casacore::Bool         combscan()       { return upcase(combine_).contains("SCAN"); };
     199           0 :   inline casacore::Bool         combobs()        { return upcase(combine_).contains("OBS"); };
     200             : 
     201             :   // Total number of (complex) parameters per solve
     202             :   //  (specialize to jive with ant- or bln-basedness, etc.)
     203             :   virtual casacore::Int nTotalPar()=0;
     204             : 
     205             :   // Report if calibration available for specified spw
     206             :   //  (if no CalInterp available, assume true)
     207             : 
     208             :   // Use generic data gathering mechanism for solve
     209           0 :   virtual casacore::Bool useGenericGatherForSolve() { return true; };
     210             : 
     211             :   // Use generic solution engine for a single solve
     212             :   //  (usually inside the generic gathering mechanism)
     213           0 :   virtual casacore::Bool useGenericSolveOne() { return useGenericGatherForSolve(); };
     214             : 
     215             :   // Solve for point-source X or Q,U?
     216             :   //  nominally no (0)
     217           0 :   virtual casacore::Int solvePol() { return 0; };
     218             : 
     219             :   // Does normalization by MODEL_DATA commute with this VisCal?
     220             :   //   (if so, permits pre-solve time-averaging)
     221             :   virtual casacore::Bool normalizable()=0;
     222             : 
     223             :   // Should data and model be divided by Stokes I model  before average+solve?
     224             :   //   (Nominally false, for now)
     225           0 :   virtual casacore::Bool divideByStokesIModelForSolve() { return false; };
     226             : 
     227             :   // Is this type capable of accumulation?  (nominally no)
     228           0 :   virtual casacore::Bool accumulatable() { return false; };
     229             : 
     230             :   // Is this type capable of smoothing?  (nominally no)
     231           0 :   virtual casacore::Bool smoothable() { return false; };
     232             : 
     233             :   // Should only parallel-hands be used in solving?
     234             :   //  (generally no (default=false), but GJones and related
     235             :   //   will override, and eventually this will be a user-set-able
     236             :   //   parameter)
     237           0 :   virtual casacore::Bool phandonly() { return false; }
     238             : 
     239             :   // Access to focus channel
     240           0 :   inline casacore::Int&         focusChan()      { return focusChan_; };
     241             : 
     242             :   // Is this ready to solve?
     243           0 :   inline casacore::Bool isSolved() {return solved_;};
     244             : 
     245             :   // Is this solveable? (via this interface, nominally yes)
     246           0 :   virtual casacore::Bool isSolvable() {return true;};
     247             : 
     248             :   // Set the application parameters 
     249             :   virtual void setApply();
     250             :   virtual void setApply(const casacore::Record& apply);
     251             :   virtual void setCallib(const casacore::Record& callib,const casacore::MeasurementSet& selms);
     252             : 
     253           0 :   virtual void setModel(const casacore::String& )
     254           0 :   {throw(SynthesisError("Internal error: setModel() not yet supported for non EPJones type."));};
     255             : 
     256             :   // Report apply info/params, e.g. for logging
     257             :   virtual casacore::String applyinfo();
     258             : 
     259             :   // Set the solving parameters
     260             :   virtual void setSolve();
     261             :   virtual void setSolve(const casacore::Record& solve);
     262             : 
     263             :   // Report solve info/params, e.g., for logging
     264             :   virtual casacore::String solveinfo();
     265             : 
     266             :   // Arrange for accumulation
     267             :   virtual void setAccumulate(VisSet& vs,
     268             :                              const casacore::String& table,
     269             :                              const casacore::String& select,
     270             :                              const casacore::Double& t,
     271             :                              const casacore::Int& refAnt=-1);
     272             : 
     273             :   // Default value for parameters
     274           0 :   virtual casacore::Complex defaultPar() { return casacore::Complex(1.0); };
     275           0 :   virtual casacore::Float defaultRPar() { return casacore::Float(0.0); };
     276           0 :   virtual casacore::Complex defaultCPar() { return casacore::Complex(1.0); };
     277             : 
     278             :   // Arrange to build a cal table from specified values
     279             :   virtual void setSpecify(const casacore::Record& specify);
     280             : 
     281             :   // Fill a caltable with specified values
     282             :   virtual void specify(const casacore::Record& specify);
     283             : 
     284             :   // Size up the solving arrays, etc.  (supports combine)
     285             :   virtual casacore::Int sizeUpSolve(VisSet& vs, casacore::Vector<casacore::Int>& nChunkPerSol);
     286             : 
     287             :   // These inflate methods soon to deprecate (gmoellen, 20121212)
     288             :   // Inflate the pristine CalSet (from VisSet info)
     289             :   void inflate(VisSet& vs, const casacore::Bool& fillMeta=false);
     290             :   // Inflate the pristine CalSet (generically)
     291             :   virtual void inflate(const casacore::Vector<casacore::Int>& nChanDat,
     292             :                        const casacore::Vector<casacore::Int>& startChanDat,
     293             :                        const casacore::Vector<casacore::Int>& nSlot);
     294             : 
     295             : 
     296             :   // Hazard a guess at the parameters (solveCPar) given the data
     297             :   virtual void guessPar(VisBuffer& vb)=0;
     298           0 :   virtual void guessPar(SDBList&,const casacore::Bool&) { throw(casacore::AipsError("SVC::guessPar(SDBList&) NYI!!")); };  // VI2
     299             : 
     300             :   // Time-dep solution interval  (VI2)
     301           0 :   inline double solTimeInterval() const { return solTimeInterval_; };
     302             : 
     303             :   // Freq-dep solint values (const?!)
     304           0 :   inline casacore::Double& fintervalHz() { return fintervalHz_; };
     305           0 :   inline casacore::Double& fintervalCh() { return fintervalCh_(currSpw()); };  // for current Spw
     306           0 :   const inline casacore::Vector<casacore::Double>& fintervalChV() { return fintervalCh_; };  // all spws
     307           0 :   casacore::Matrix<casacore::Int> chanAveBounds()  { return chanAveBounds_(currSpw()); }; // for current Spw
     308           0 :   casacore::Matrix<casacore::Int> chanAveBounds(casacore::Int spw)  { return chanAveBounds_(spw); }; 
     309             : 
     310             :   // Access to current solution parameters and matrices
     311           0 :   inline virtual casacore::Cube<casacore::Complex>& solveCPar()   {return (*solveCPar_[currSpw()]);};
     312           0 :   inline virtual casacore::Cube<casacore::Float>&   solveRPar()   {return (*solveRPar_[currSpw()]);};
     313           0 :   inline virtual casacore::Cube<casacore::Bool>&    solveParOK()  {return (*solveParOK_[currSpw()]);};
     314           0 :   inline virtual casacore::Cube<casacore::Float> &  solveParErr() {return (*solveParErr_[currSpw()]);};
     315           0 :   inline virtual casacore::Cube<casacore::Float> &  solveParSNR() {return (*solveParSNR_[currSpw()]);};
     316             : 
     317           0 :   inline virtual casacore::Cube<casacore::Complex>& solveAllCPar()   {return (*solveAllCPar_[currSpw()]);};
     318           0 :   inline virtual casacore::Cube<casacore::Float>&   solveAllRPar()   {return (*solveAllRPar_[currSpw()]);};
     319           0 :   inline virtual casacore::Cube<casacore::Bool>&    solveAllParOK()  {return (*solveAllParOK_[currSpw()]);};
     320           0 :   inline virtual casacore::Cube<casacore::Float> &  solveAllParErr() {return (*solveAllParErr_[currSpw()]);};
     321           0 :   inline virtual casacore::Cube<casacore::Float> &  solveAllParSNR() {return (*solveAllParSNR_[currSpw()]);};
     322             : 
     323             :   // Access to per-spw solution parameters and matrices
     324           0 :   inline virtual void solveAllCPar(casacore::Int spw, casacore::Cube<casacore::Complex>& cparSpw)
     325           0 :         { if (spw<nSpw()) cparSpw = (*solveAllCPar_[spw]);}
     326           0 :   inline virtual void solveAllRPar(casacore::Int spw, casacore::Cube<casacore::Float>& rparSpw)
     327           0 :     { if (spw<nSpw()) rparSpw = (*solveAllRPar_[spw]);}
     328           0 :   inline virtual void solveAllParOK(casacore::Int spw, casacore::Cube<casacore::Bool>& parokSpw)
     329           0 :     { if (spw<nSpw()) parokSpw = (*solveAllParOK_[spw]);}
     330           0 :   inline virtual void solveAllParErr(casacore::Int spw, casacore::Cube<casacore::Float>& parerrSpw) 
     331           0 :     { if (spw<nSpw()) parerrSpw = (*solveAllParErr_[spw]);}
     332           0 :   inline virtual void solveAllParSNR(casacore::Int spw, casacore::Cube<casacore::Float>& parsnrSpw) 
     333           0 :     { if (spw<nSpw()) parsnrSpw = (*solveAllParSNR_[spw]);}
     334             : 
     335             :   // Access to source pol parameters
     336           0 :   inline casacore::Vector<casacore::Complex>& srcPolPar() { return srcPolPar_; };
     337             :     
     338             :   // get antenna map
     339           0 :   virtual std::map<casacore::Int, std::map<casacore::String, casacore::Vector<casacore::Int>>> getAntennaMap() {return antennaMap_;};
     340             :   // get refant map
     341           0 :   virtual std::map<casacore::Int, std::map<casacore::Int, casacore::Int>> getRefantMap() {return refantMap_;};
     342             :     
     343             : 
     344             :   // Synchronize the meta data with a solvable VisBuffer
     345             :   //   (returns false if VisBuffer has no valid data)
     346             :   casacore::Bool syncSolveMeta(VisBuffer& vb, const casacore::Int& fieldId);
     347             :   casacore::Bool syncSolveMeta(VisBuffGroupAcc& vbga);
     348             :   void syncSolveMeta(SDBList& sdbs);  // VI2   (valid data now checked elsewhere)
     349             :   // Provide for override of currScan and currObs
     350             :   void overrideObsScan(casacore::Int obs, casacore::Int scan);
     351             : 
     352             :   // If apmode() is "A", convert vb's visibilities to amp + 0i.
     353             :   // If it is "P", convert them to phase + 0i.
     354             :   // Otherwise (i.e. "AP"), leave them alone.
     355             :   virtual void enforceAPonData(VisBuffer& vb);
     356             :     
     357             :   // Fill expected and data_unflagged
     358             :   virtual void expectedUnflagged(SDBList& sdbs);
     359             :   // Clear antennaMap values
     360             :   void clearMap();
     361             :   void clearRefantMap();
     362             : 
     363             :   // Verify VisBuffer data sufficient for solving (wts, etc.)
     364             :   virtual casacore::Bool verifyConstraints(VisBuffGroupAcc& vbag);
     365             :   virtual casacore::Bool verifyConstraints(SDBList& sdbs);  // VI2 
     366             :   virtual casacore::Bool verifyForSolve(VisBuffer& vb);
     367             :   
     368             :   // Self- gather and/or solve prototypes
     369             :   //  (triggered by useGenericGatherForSolve=F or useGenericSolveOne=F; 
     370             :   //   must be overridden in derived specializations)
     371             :   virtual void selfGatherAndSolve(VisSet& vs, VisEquation& ve);
     372             :   virtual void selfSolveOne(VisBuffGroupAcc& vs);
     373           0 :   virtual void selfSolveOne(SDBList&) { throw(casacore::AipsError("selfSolveOne for VI2/SDB usage NYI for "+typeName())); };
     374             : 
     375             :   // Set up data and model for pol solve
     376             :   void setUpForPolSolve(VisBuffer& vb);
     377             :   // A VB2-specific version which depends on local specialization
     378             :   //   (this may be further refined later)
     379           0 :   virtual void setUpForPolSolve(vi::VisBuffer2&) {
     380           0 :     throw(casacore::AipsError("setUpForPolSolve(VB2) not specialized in "+typeName()+" as required.")); };
     381             : 
     382             :   // Differentiate VB model w.r.t. Cal  parameters (no 2nd derivative yet)
     383             :   virtual void differentiate(CalVisBuffer& cvb)=0;
     384           0 :   virtual void differentiate(SolveDataBuffer&) { throw(casacore::AipsError("SVC::differentiate(SDB)  NYI!")); };  // VI2
     385             :   virtual void differentiate(VisBuffer& vb,        
     386             :                              casacore::Cube<casacore::Complex>& V,     
     387             :                              casacore::Array<casacore::Complex>& dV,
     388             :                              casacore::Matrix<casacore::Bool>& Vflg)=0;
     389           0 :   virtual void differentiate(VisBuffer& ,          // vb.visCube() has the obs. data.  vb.modelVisCube() will receive the residuals
     390             :                              VisBuffer&   ,       // 1st. Derivative w.r.t. first parameter
     391             :                              VisBuffer& ,         // 1st. Derivative w.r.t. second parameter
     392           0 :                              casacore::Matrix<casacore::Bool>& ){ throw(casacore::AipsError("Invalid use of differentiate(vb,dV0,dv1)")); };
     393             : 
     394             : 
     395             :   // Differentiate VB model w.r.t. Source parameters
     396             :   virtual void diffSrc(VisBuffer& vb,        
     397             :                        casacore::Array<casacore::Complex>& dV)=0;
     398             : 
     399             :   // Update solve parameters incrementally (additive)
     400             :   virtual void updatePar(const casacore::Vector<casacore::Complex> dCalPar,const casacore::Vector<casacore::Complex> dSrcPar);
     401             :   virtual void updatePar(const casacore::Vector<casacore::Complex> dCalPar);  //  (VI2)
     402             : 
     403             :   // Form solution SNR
     404             :   virtual void formSolveSNR();
     405             : 
     406             :   // Apply SNR threshold
     407             :   virtual void applySNRThreshold();
     408             : 
     409             :   // Apply refant (implemented in SVJ)
     410             :   virtual void reReference()=0;
     411             : 
     412             :   // Retrieve the cal flag info as a record
     413             :   virtual casacore::Record actionRec();
     414             : 
     415             :   // Retrieve solve-related info via Record
     416             :   virtual casacore::Record solveActionRec();
     417             : 
     418             :   // Accumulate another VisCal onto this one
     419             :   virtual void accumulate(SolvableVisCal* incr,
     420             :                           const casacore::Vector<casacore::Int>& fields)=0;
     421             : 
     422             :   virtual void smooth(casacore::Vector<casacore::Int>& fields,
     423             :                       const casacore::String& smtype,
     424             :                       const casacore::Double& smtime);
     425             : 
     426             :   // Report solved-for QU
     427             :   virtual void reportSolvedQU();
     428             : 
     429             : 
     430             :   // New CalTable handling
     431             :   virtual void createMemCalTable();
     432             :   virtual void keep1(casacore::Int ichan);
     433             :   virtual void keepNCT();
     434             :   virtual void storeNCT();
     435             :   void storeNCT(const casacore::String& tableName,const casacore::Bool& append);
     436             : 
     437             :   virtual void loadMemCalTable(casacore::String ctname,casacore::String field="");
     438             : 
     439             :   // New spwOK
     440             :   virtual casacore::Bool spwOK(casacore::Int ispw);
     441             : 
     442             :   //Is VB OK for calibration? 
     443             :   virtual casacore::Bool VBOKforCalApply(vi::VisBuffer2& vb);
     444             : 
     445             :   // Calibration available?
     446             :   virtual casacore::Bool calAvailable(vi::VisBuffer2&);
     447             : 
     448             :   // Post solve tinkering (generic version)
     449             :   virtual void globalPostSolveTinker();
     450             : 
     451             :   // Divide all solutions by their amplitudes
     452             :   virtual void enforceAPonSoln();
     453             : 
     454             :   // Normalize a solution (generic implementation)
     455             :   virtual void normalize();
     456             : 
     457             :   // Determine and apply flux density scaling
     458             :   virtual void fluxscale(const casacore::String& outfile,
     459             :                          const casacore::Vector<casacore::Int>& refFieldIn,
     460             :                          const casacore::Vector<casacore::Int>& tranFieldIn,
     461             :                          const casacore::Vector<casacore::Int>& inRefSpwMap,
     462             :                          const casacore::Vector<casacore::String>& fldNames,
     463             :                          const casacore::Float& inGainThres,
     464             :                          const casacore::String& antSel,
     465             :                          const casacore::String& timerangeSel,
     466             :                          const casacore::String& scanSel,
     467             :                          fluxScaleStruct& oFluxScaleStruct,
     468             :                          const casacore::String& oListFile,
     469             :                          const casacore::Bool& incremental,
     470             :                          const casacore::Int& fitorder,
     471             :                          const casacore::Bool& display)=0;
     472             : 
     473             :   // Report state:
     474           0 :   inline virtual void state() { stateSVC(true); };
     475             : 
     476           0 :   virtual VisCalEnum::VCParType setParType(VisCalEnum::VCParType type) 
     477           0 :   {parType_ = type;return (VisCalEnum::VCParType)parType_;};
     478             :   virtual void currMetaNote();
     479             : 
     480             :   virtual void listCal(const casacore::Vector<casacore::Int> ufldids, const casacore::Vector<casacore::Int> uantids,
     481             :                        const casacore::Matrix<casacore::Int> uchanids,  //const casacore::Int& spw, const casacore::Int& chan,
     482             :                        const casacore::String& listfile="",const casacore::Int& pagerows=50)=0;
     483             : 
     484             :   // Handle external channel mask
     485           0 :   inline void setChanMask(casacore::PtrBlock<casacore::Vector<casacore::Bool>*>& chanmask) { chanmask_=&chanmask; };
     486           0 :   inline void clearChanMask() { chanmask_=NULL; };
     487             :   void applyChanMask(VisBuffer& vb);
     488             :   // Log periodic solver activity
     489             :   virtual void printActivity(const casacore::Int nSlots, const casacore::Int slotNo, 
     490             :                              const casacore::Int fieldId, const casacore::Int spw, 
     491             :                              const casacore::Int nSolutions);
     492           0 :   virtual void markTimer() {timer_p.mark();};
     493             : 
     494             : 
     495             :   // -------------
     496             :   // Set the simulation parameters
     497             :   virtual void setSimulate(VisSet& vs, casacore::Record& simpar, casacore::Vector<casacore::Double>& solTimes);
     498             : 
     499             :   // make a corruptor in a VC-specific way
     500             :   virtual void createCorruptor(const VisIter& vi,const casacore::Record& simpar, const int nSim);
     501             : 
     502             :   // access to simulation variables that are general to all VisCals
     503           0 :   inline casacore::String& simint() { return simint_; };
     504             : 
     505             :   // Simulation info/params, suitable for logging
     506             :   virtual casacore::String siminfo();
     507             : 
     508             :   // Is this calibration simulated?
     509           0 :   inline casacore::Bool isSimulated() {return simulated_;};
     510             : 
     511             :   // object that can simulate the corruption terms
     512             :   CalCorruptor *corruptor_p;
     513             : 
     514             :   // calculate # required slots to simulate this SVC
     515             :   casacore::Int sizeUpSim(VisSet& vs, casacore::Vector<casacore::Int>& nChunkPerSol, casacore::Vector<casacore::Double>& solTimes);
     516             : 
     517             : 
     518             :   // VI2-related refactor--------------------------------------
     519             : 
     520             :   // Set "current" meta info, so internals are registered
     521             :   //  (VI2: replaces meta-inf part of syncSolveMeta; 
     522             :   //   NB: does _NOT_ check sum(wt)>0 older syncSolveMeta!)
     523             :   virtual void setMeta(int obs, int scan, double time,
     524             :                        int spw, const casacore::Vector<double>& freq,
     525             :                        int fld);
     526             : 
     527             :   // Reshape solvePar* arrays for the currSpw()  
     528             :   //  (ensitive to freqDepPar())
     529             :   //  (VI2: replaces initSolvePar part of sizeUpSolve)
     530             :   virtual int sizeSolveParCurrSpw(int nVisChan);
     531             : 
     532             :   // Set parameters to def values in the currSpw(), 
     533             :   //   and optionally sync everything
     534             :   virtual void setDefSolveParCurrSpw(bool sync=false);
     535             : 
     536             :   // Parse solint in VI2 context
     537             :   void reParseSolintForVI2();
     538             : 
     539             :   // Generate the in-memory caltable (empty)
     540             :   //  NB: no subtable revisions
     541             :   virtual void createMemCalTable2();
     542             : 
     543             :   // Set (or verify) freq info in output cal table for specified spw
     544             :   virtual void setOrVerifyCTFrequencies(int spw);
     545             : 
     546             : 
     547             : 
     548             :   // Discern frequency meta info for solutions (solve context)
     549             :   virtual void discernAndSetSolnFrequencies(const casa::vi::VisibilityIterator2& vi,
     550             :                                             const casacore::Vector<casacore::uInt>& selspws);
     551             : 
     552             :   // Set frequencies in the Caltable (according to discernAndSetSolnFrequencies)
     553             :   virtual void setCTFrequencies(casacore::Int netspw);
     554             : 
     555             :   
     556             : 
     557             : protected:
     558             : 
     559             :   // Set to-be-solved-for flag
     560           0 :   inline void setSolved(const casacore::Bool& flag) {solved_=flag;};
     561             : 
     562             :   // Initialize solve parameters (shape)
     563             :   virtual void initSolvePar()=0;
     564             : 
     565             :   // Invalidate diff cal matrices generically 
     566             :   inline virtual void invalidateDiffCalMat()=0;
     567             : 
     568             :   // Explicitly synchronize pars with a CalSet slot
     569             :   using VisCal::syncPar;
     570             : 
     571             :   // Set matrix channelization according to a VisSet
     572             :   virtual void setSolveChannelization(VisSet& vs);
     573             : 
     574             :   // Convert Hz to Ch in fsolint
     575             :   virtual void convertHzToCh();
     576             : 
     577             :   // Calculate chan averaging bounds
     578             :   virtual void setFracChanAve();
     579             : 
     580             :   // Inflate an NCT w/ meta-data according to a VisSet 
     581             :   //   (for accum)
     582             :   void inflateNCTwithMetaData(VisSet& vs);
     583             : 
     584             :   // Synchronize calibration for solve context
     585             :   void syncSolveCal();
     586             : 
     587             :   // Synchronize parameters for solve context
     588             :   void syncSolvePar();
     589             : 
     590             :   // Calculate parameters by some means (e.g., interpolation from a CalSet)
     591             :   virtual void calcPar();
     592             :   virtual void calcParByCLPP();
     593             : 
     594             :   // Synchronize the differentiated calibration 
     595             :   virtual void syncDiffMat()=0;
     596             : 
     597             :   // Report the SVC-specific state, w/ option for VC::state()
     598             :   virtual void stateSVC(const casacore::Bool& doVC);
     599             : 
     600             :   // Normalize a (complex) solution array (generic)
     601             :   casacore::Complex normSolnArray(casacore::Array<casacore::Complex>& sol,
     602             :                                   const casacore::Array<casacore::Bool>& solOK,
     603             :                                   const casacore::Bool doPhase=false);
     604             : 
     605             :   virtual casacore::Float calcPowerNorm(casacore::Array<casacore::Float>& amp, const casacore::Array<casacore::Bool>& ok)=0;
     606             : 
     607             :   // Logger
     608           0 :   casacore::LogIO& logSink() { return logsink_p; };
     609             : 
     610             :   // Check if a cal table is appropriate
     611             :   void verifyCalTable(const casacore::String& caltablename);
     612             : 
     613             :   void sortVisSet(VisSet& vs, const casacore::Bool verbose=false);
     614             : 
     615             :   casacore::Int parType_;
     616             : 
     617             :   // New CalTable 
     618             :   NewCalTable *ct_;
     619             :   CTPatchedInterp *ci_;
     620             :   CLPatchPanel *cpp_;
     621             :   casacore::Vector<casacore::Bool> spwOK_;
     622             : 
     623             :   casacore::Double maxTimePerSolution_p, minTimePerSolution_p, avgTimePerSolution_p;
     624             :   casacore::Float userPrintActivityInterval_p, userPrintActivityFraction_p;
     625             :   casacore::uInt caiRC_p, cafRC_p;
     626             :   casacore::Timer timer_p;
     627             :   // Map for refant information SPW || ANT || VAL
     628             :   std::map<casacore::Int, std::map<casacore::Int, casacore::Int>> refantMap_;
     629             : 
     630             :   // Set state flag to simulate cal terms
     631           0 :   inline void setSimulated(const casacore::Bool& flag) {simulated_=flag;};
     632             : 
     633             :   // RI todo implement calcOneJones like calcAllMueller
     634             :   // calculate terms during apply, or up front during setSim?
     635           0 :   inline casacore::Bool& simOnTheFly() { 
     636             :     //    cout << "simOTF=" << onthefly_ << endl;
     637           0 :     return onthefly_; };
     638             :     
     639             :   // Frequency meta data for solutions (for CalTable labels...)
     640             :   FreqMetaData freqMetaData_;
     641             : 
     642             : 
     643             : private:
     644             : 
     645             :   // Default ctor is private
     646             :   SolvableVisCal();
     647             : 
     648             :   // Initialize pointers, etc.
     649             :   void initSVC();
     650             : 
     651             :   // Delete pointers
     652             :   void deleteSVC();
     653             : 
     654             :   // Pointer to CTTimeInterp1 factory method (generic)
     655             :   // SVC specializations may choose to specialize CTTimeInterp1, as needed,
     656             :   //   and override this method accordingly (e.g., see FringeJones.h)
     657           0 :   virtual CTTIFactoryPtr cttifactoryptr() { return &CTTimeInterp1::factory; };
     658             : 
     659             :   // Cal table name
     660             :   casacore::String calTableName_;
     661             :   casacore::String calTableSelect_;
     662             :   casacore::Bool append_;
     663             : 
     664             :   // Interpolation types
     665             :   casacore::String tInterpType_;
     666             :   casacore::String fInterpType_;
     667             : 
     668             :   // Spw mapping
     669             :   casacore::Vector<casacore::Int> spwMap_;
     670             : 
     671             :   // Refant mode
     672             :   casacore::String refantmode_;
     673             : 
     674             :   // Refant
     675             :   casacore::Vector<casacore::Int> urefantlist_;
     676             : 
     677             :   // Min baselines per ant for solve
     678             :   casacore::Int minblperant_;
     679             : 
     680             :   // Solved-for flag
     681             :   casacore::Bool solved_;
     682             : 
     683             :   // Signal apply by callib
     684             :   casacore::Bool byCallib_;
     685             : 
     686             :   // Solving mode
     687             :   casacore::String apmode_;
     688             : 
     689             :   // Solver iteration mode
     690             :   casacore::String solmode_;
     691             :   casacore::Vector<casacore::Float> rmsthresh_;
     692             : 
     693             :   // User-specified full solint string
     694             :   casacore::String usolint_;
     695             : 
     696             :   // User-specified time-dep solint (string)
     697             :   casacore::String solint_;
     698             : 
     699             :   // Derived time-dep solution interval (s) (VI2)
     700             :   double solTimeInterval_;
     701             : 
     702             :   // User-specified freq-dep solint info
     703             :   casacore::String fsolint_;
     704             : 
     705             :   // Derived frequency intervals
     706             :   casacore::Double fintervalHz_;
     707             :   casacore::Vector<casacore::Double> fintervalCh_;   // (nSpw)
     708             : 
     709             : 
     710             :   // Channel averaging bounds
     711             :   casacore::Vector<casacore::Matrix<casacore::Int> > chanAveBounds_;  // (nSpw)(2,nOutChan)
     712             : 
     713             :   // Preavering interval
     714             :   casacore::Double preavg_;
     715             : 
     716             :   // Combine polarizations
     717             :   casacore::String corrcomb_;
     718             :   
     719             :   // Do solution normalization after a solve
     720             :   SolNorm solnorm_;
     721             : 
     722             :   // SNR threshold
     723             :   casacore::Float minSNR_;
     724             : 
     725             :   // axes to combine for solve
     726             :   casacore::String combine_;
     727             : 
     728             :   // In-focus channel for single-chan solves on multi-chan data
     729             :   casacore::Int focusChan_;
     730             : 
     731             :   // Solving meta-data
     732             :   casacore::Double dataInterval_;
     733             :   casacore::Double fitWt_;
     734             :   casacore::Double fit_;
     735             : 
     736             :   // Current parameters
     737             :   casacore::PtrBlock<casacore::Cube<casacore::Complex>*> solveCPar_;  // [nSpw](nPar,1,{1|nElem})
     738             :   casacore::PtrBlock<casacore::Cube<casacore::Float>*>   solveRPar_;  // [nSpw](nPar,1,{1|nElem})
     739             :   casacore::PtrBlock<casacore::Cube<casacore::Bool>*>    solveParOK_; // [nSpw](nPar,1,{1|nElm})
     740             :   casacore::PtrBlock<casacore::Cube<casacore::Float>*>   solveParErr_; // [nSpw](nPar,1,{1|nElm})
     741             :   casacore::PtrBlock<casacore::Cube<casacore::Float>*>   solveParSNR_; // [nSpw](nPar,1,{1|nElm})
     742             : 
     743             :   casacore::PtrBlock<casacore::Cube<casacore::Complex>*> solveAllCPar_;   // [nSpw](nPar,nChan,{1|nElem})
     744             :   casacore::PtrBlock<casacore::Cube<casacore::Float>*>   solveAllRPar_;   // [nSpw](nPar,nChan,{1|nElem})
     745             :   casacore::PtrBlock<casacore::Cube<casacore::Bool>*>    solveAllParOK_;  // [nSpw](nPar,nChan,{1|nElm})
     746             :   casacore::PtrBlock<casacore::Cube<casacore::Float>*>   solveAllParErr_; // [nSpw](nPar,nChan,{1|nElm})
     747             :   casacore::PtrBlock<casacore::Cube<casacore::Float>*>   solveAllParSNR_; // [nSpw](nPar,nChan,{1|nElm})
     748             : 
     749             :   casacore::Vector<casacore::Complex> srcPolPar_;
     750             :     
     751             :   // Map for antenna information
     752             :   std::map<casacore::Int, std::map<casacore::String, casacore::Vector<casacore::Int>>> antennaMap_;
     753             :   // Map for refant information SPW || ANT || VAL
     754             :   // std::map<casacore::Int, std::map<casacore::Int, casacore::Int>> refantMap_;
     755             : 
     756             :   // A _pointer_ to the external channel mask
     757             :   casacore::PtrBlock<casacore::Vector<casacore::Bool>*> *chanmask_;
     758             : 
     759             :   // LogIO
     760             :   casacore::LogIO logsink_p;
     761             : 
     762             :   // Simulation flag
     763             :   casacore::Bool simulated_;
     764             : 
     765             :   // simulation interval
     766             :   casacore::String simint_;
     767             : 
     768             :   casacore::Bool onthefly_;  
     769             : 
     770             : };
     771             : 
     772             : 
     773             : 
     774             : // **********************************************************
     775             : //  SolvableVisMueller
     776             : //
     777             : 
     778             : class SolvableVisMueller : public SolvableVisCal, virtual public VisMueller
     779             : {
     780             : 
     781             : public:
     782             : 
     783             :   SolvableVisMueller(VisSet& vs);
     784             : 
     785             :   SolvableVisMueller(casacore::String msname,casacore::Int MSnAnt,casacore::Int MSnSpw);
     786             : 
     787             :   SolvableVisMueller(const MSMetaInfoForCal& msmc);
     788             : 
     789             :   SolvableVisMueller(const casacore::Int& nAnt);
     790             : 
     791             :   virtual ~SolvableVisMueller();
     792             : 
     793             :   // Total number of (complex) parameters per solve
     794             :   //  Mueller version:  just return number of per-Bln parameters
     795           0 :   virtual casacore::Int nTotalPar() { return nPar(); };
     796             : 
     797             :   // Does normalization by MODEL_DATA commute with this VisCal?
     798           0 :   virtual casacore::Bool normalizable() { return (this->muellerType() < Mueller::General); };
     799             : 
     800             :   // Hazard a guess at the parameters (solvePar) given the data
     801           0 :   virtual void guessPar(VisBuffer& ) { throw(casacore::AipsError("NYI")); };
     802             : 
     803             :   // Differentiate VB model w.r.t. Mueller parameters (no 2nd derivative yet)
     804           0 :   virtual void differentiate(CalVisBuffer& ) {throw(casacore::AipsError("SVM::differentiate(CVB): NYI")); };
     805           0 :   virtual void differentiate(SolveDataBuffer& ) {throw(casacore::AipsError("SVM::differentiate(SDB): NYI")); };  // VI2
     806           0 :   virtual void differentiate(VisBuffer& ,          // input data
     807             :                              casacore::Cube<casacore::Complex>& ,       // trial apply (nCorr,nChan,nRow)
     808             :                              casacore::Array<casacore::Complex>& ,     // 1st deriv   (nCorr,nPar,nChan,nRow)
     809           0 :                              casacore::Matrix<casacore::Bool>& ) { throw(casacore::AipsError("NYI")); };
     810             :   using SolvableVisCal::differentiate;
     811             : 
     812             :   // Differentiate VB model w.r.t. Source parameters
     813           0 :   virtual void diffSrc(VisBuffer& ,
     814           0 :                        casacore::Array<casacore::Complex>& ) {throw(casacore::AipsError("NYI")); };
     815             : 
     816             :   // Apply refant (no-op for Muellers)
     817           0 :   virtual void reReference() {};
     818             : 
     819             :   // Accumulate another VisCal onto this one
     820           0 :   virtual void accumulate(SolvableVisCal* ,
     821           0 :                           const casacore::Vector<casacore::Int>& ) { throw(casacore::AipsError("NYI")); };
     822             : 
     823             :   // Scale solutions
     824           0 :   virtual void fluxscale(const casacore::String&,
     825             :                          const casacore::Vector<casacore::Int>& ,
     826             :                          const casacore::Vector<casacore::Int>& ,
     827             :                          const casacore::Vector<casacore::Int>& ,
     828             :                          const casacore::Vector<casacore::String>& ,
     829             :                          const casacore::Float& ,
     830             :                          const casacore::String& ,
     831             :                          const casacore::String& ,
     832             :                          const casacore::String& ,
     833             :                          SolvableVisCal::fluxScaleStruct&,
     834             :                          const casacore::String&,
     835             :                          const casacore::Bool&,
     836             :                          const casacore::Int&,
     837             :                          const casacore::Bool&)
     838           0 :         { throw(casacore::AipsError("NYI")); };
     839             : 
     840             :   // SVM-specific write to caltable
     841             :   virtual void keepNCT();
     842             : 
     843             :   // Report state:
     844           0 :   inline virtual void state() { stateSVM(true); };
     845             : 
     846             :   // casacore::List calibration solutions in tabular form.
     847           0 :   virtual void listCal(const casacore::Vector<casacore::Int> ,
     848             :                        const casacore::Vector<casacore::Int> ,
     849             :                        const casacore::Matrix<casacore::Int> ,
     850             :                                const casacore::String& ,
     851             :                        const casacore::Int& )
     852           0 :   { throw(casacore::AipsError(casacore::String("Calibration listing not supported for "+typeName()))); };
     853             : 
     854             : protected:
     855             : 
     856             :   // Number of Cal Matrices to form on baseline axis
     857             :   //  (Mueller, solve context: 1)
     858           0 :   virtual casacore::Int nCalMat() { return isSolved() ? 1 : nBln(); };
     859             : 
     860             :   // Are differentiated M matrices constant in chan & bln?
     861           0 :   virtual casacore::Bool trivialDM() { return false; };
     862             : 
     863             :   // Initialize solve parameter shape
     864             :   //  Mueller version:  (nPar(),1,1)   (one chan, one baseline)
     865             :   virtual void initSolvePar();
     866             : 
     867             :   // Access to matrix rendering of dM (per par)
     868           0 :   inline Mueller& dM() { return *dM_; };
     869             : 
     870             :   // Access to differentiated Mueller elements
     871           0 :   inline casacore::Array<casacore::Complex>& diffMElem() {return diffMElem_;};
     872             : 
     873             :   // Invalidate diff cal matrices generically (at this level, just M, dM)
     874           0 :   inline virtual void invalidateDiffCalMat() { invalidateM(); invalidateDM(); };
     875             : 
     876             :   // Validation of diffMueller matrices
     877           0 :   inline void invalidateDM() {DMValid_=false;};
     878           0 :   inline void validateDM()   {DMValid_=true;};
     879           0 :   inline casacore::Bool DMValid()      {return DMValid_;};
     880             : 
     881             :   // Synchronize the differentiated calibration (specialization for Mueller);
     882             :   virtual void syncDiffMat();
     883             : 
     884             :   // Synchronize the Muellers AND diffMuellers
     885             :   virtual void syncDiffMueller();
     886             : 
     887             :   // Calculate the ensemble of diff'd Mueller Elements
     888             :   virtual void calcAllDiffMueller();
     889             : 
     890             :   // Calculate one diffMElem 
     891             :   virtual void calcOneDiffMueller(casacore::Matrix<casacore::Complex>& mat, const casacore::Vector<casacore::Complex>& par);
     892             : 
     893             :   // Create matrix renderers for dMs
     894             :   void createDiffMueller();
     895             : 
     896             :   // Override VM::setMatByOk in solve context
     897           0 :   void setMatByOk() { if (!isSolved()) VisMueller::setMatByOk(); };
     898             : 
     899             :   // Initialize trivial diff'd Muellers
     900             :   virtual void initTrivDM();
     901             : 
     902             :   // SVM-specific state
     903             :   virtual void stateSVM(const casacore::Bool& doVC);
     904             : 
     905             :   // atomic power normalization calculation
     906             :   //   Mueller version assumes amp in power units
     907             :   virtual casacore::Float calcPowerNorm(casacore::Array<casacore::Float>& amp, const casacore::Array<casacore::Bool>& ok);
     908             : 
     909             : private:
     910             : 
     911             :   // Default ctor is private
     912             :   SolvableVisMueller();
     913             : 
     914             :   // Mueller wrapper for diffMElem_;
     915             :   Mueller *dM_;
     916             : 
     917             :   // Differentiated Mueller matrix elements
     918             :   casacore::Array<casacore::Complex> diffMElem_;    // (nDMEl,nPar,nChanMat,nBln)
     919             : 
     920             :   // diffMueller validation
     921             :   casacore::Bool DMValid_;
     922             : 
     923             : 
     924             : };
     925             : 
     926             : // **********************************************************
     927             : //  SolvableVisJones
     928             : //
     929             : 
     930             : class SolvableVisJones : public SolvableVisMueller, public VisJones {
     931             : 
     932             : public:
     933             : 
     934             :   SolvableVisJones(VisSet& vs);
     935             : 
     936             :   SolvableVisJones(casacore::String msname,casacore::Int MSnAnt,casacore::Int MSnSpw);
     937             : 
     938             :   SolvableVisJones(const casacore::Int& nAnt);
     939             : 
     940             :   SolvableVisJones(const MSMetaInfoForCal& msmc);
     941             : 
     942             :   virtual ~SolvableVisJones();
     943             : 
     944             :   // Total number of (complex) parameters per solve
     945             :   //  Jones version:  nPar()*nAnt()
     946           0 :   virtual casacore::Int nTotalPar() { return nPar()*nAnt(); };
     947             : 
     948             :   // Does normalization by MODEL_DATA commute with this VisCal?
     949           0 :   virtual casacore::Bool normalizable() { return (this->jonesType() < Jones::GenLinear); };
     950             : 
     951             :   // Differentiate VB model w.r.t. Jones parameters
     952             :   virtual void differentiate(CalVisBuffer& cvb);
     953             :   virtual void differentiate(SolveDataBuffer& sdb);  // VI2
     954             :   virtual void differentiate(VisBuffer& vb,          // input data
     955             :                              casacore::Cube<casacore::Complex>& V,       // trial apply (nCorr,nChan,nRow)
     956             :                              casacore::Array<casacore::Complex>& dV,     // 1st deriv   (nCorr,nPar,nChan,nRow,2)
     957             :                              casacore::Matrix<casacore::Bool>& Vflg);
     958             :   using SolvableVisMueller::differentiate;
     959             : 
     960             :   // Differentiate VB model w.r.t. Source parameters
     961             :   virtual void diffSrc(VisBuffer& vb,        
     962             :                        casacore::Array<casacore::Complex>& dV);
     963             : 
     964             :   // Apply refant
     965             :   virtual void reReference();
     966             : 
     967             :   // Accumulate another VisCal onto this one
     968             :   virtual void accumulate(SolvableVisCal* incr,
     969             :                           const casacore::Vector<casacore::Int>& fields);
     970             : 
     971             :   // Post solve tinkering (Jones version: includes refant application)
     972             :   virtual void globalPostSolveTinker();
     973             : 
     974             :   // Apply reference antenna (generic Jones version)
     975             :   virtual void applyRefAnt();
     976             : 
     977             :   // Fluxscale is implemented here
     978             :   void fluxscale(const casacore::String& outfile,
     979             :                  const casacore::Vector<casacore::Int>& refFieldIn,
     980             :                  const casacore::Vector<casacore::Int>& tranFieldIn,
     981             :                  const casacore::Vector<casacore::Int>& inRefSpwMap,
     982             :                  const casacore::Vector<casacore::String>& fldNames,
     983             :                  const casacore::Float& inGainThres,
     984             :                  const casacore::String& antSel,
     985             :                  const casacore::String& timerangeSel,
     986             :                  const casacore::String& scanSel,
     987             :                  SolvableVisCal::fluxScaleStruct& oFluxScaleStruct,
     988             :                  const casacore::String& oListFile,
     989             :                  const casacore::Bool& incremental=false,
     990             :                  const casacore::Int& fitorder=1,
     991             :                  const casacore::Bool& display=false);
     992             : 
     993             :   // SVJ-specific write to caltable
     994             :   virtual void keepNCT();
     995             : 
     996             :   // Report state:
     997           0 :   inline virtual void state() { stateSVJ(true); };
     998             : 
     999             :   // Write calibration solutions to the terminal
    1000             :   virtual void listCal(const casacore::Vector<casacore::Int> ufldids, const casacore::Vector<casacore::Int> uantids,
    1001             :                        const casacore::Matrix<casacore::Int> uchanids,
    1002             :                        const casacore::String& listfile="",const casacore::Int& pagerows=50);
    1003             : 
    1004             :   // Write header for listCal output
    1005             :   int writeHeader(const casacore::uInt numAntCols, 
    1006             :                   const casacore::uInt numAnts,
    1007             :                   const casacore::uInt iElem);
    1008             : 
    1009           0 :   virtual void nearest(const casacore::Double , casacore::Array<casacore::Float>& ) {};
    1010           0 :   virtual void nearest(const casacore::Double , casacore::Array<casacore::Complex>& ) {};
    1011             : 
    1012             :   //plotting historgram
    1013             :   void setupPlotter();
    1014             :   void plotHistogram(const casacore::String& title, const casacore::Int index,
    1015             :                      const casacore::Vector<casacore::Double>& data, const casacore::Int nbin);
    1016             : 
    1017             : protected:
    1018             :  
    1019             :   // Number of Cal Matrices to form on baseline axis
    1020             :   //  (Jones, all contexts: nAnt())
    1021           0 :   virtual casacore::Int nCalMat() { return nAnt(); };
    1022             : 
    1023             :   // DM never trivial for SVJ
    1024           0 :   virtual casacore::Bool trivialDM() { return false; };
    1025             : 
    1026             :   // Are differentiated J matrices constant in chan & ant?
    1027           0 :   inline virtual casacore::Bool trivialDJ() { return false; };
    1028             : 
    1029             :   // Initialize solve parameter shape
    1030             :   //  Jones version:  (nPar(),1,nAnt())   (one chan, all antennas)
    1031             :   virtual void initSolvePar();
    1032             : 
    1033             :   // Access to matrix rendering of dJ1, dJ2
    1034           0 :   inline Jones& dJ1() { return *dJ1_; };
    1035           0 :   inline Jones& dJ2() { return *dJ2_; };
    1036             : 
    1037             :   // Access to differentiated Joness
    1038           0 :   casacore::Array<casacore::Complex>& diffJElem() { return diffJElem_; };
    1039             : 
    1040             :   // Invalidate diff cal matrices generically (at this level, M, dM, J, dJ)
    1041           0 :   inline virtual void invalidateDiffCalMat() { 
    1042           0 :     SolvableVisMueller::invalidateDiffCalMat(); invalidateJ(); invalidateDJ(); };
    1043             : 
    1044             :   // Validation of Jones matrix derivatives
    1045           0 :   inline void invalidateDJ() {DJValid_=false;};
    1046           0 :   inline void validateDJ()   {DJValid_=true;};
    1047           0 :   inline casacore::Bool DJValid()      {return DJValid_;};
    1048             : 
    1049             :   // Synchronize the differentiated calibration (specialization for Jones)
    1050             :   virtual void syncDiffMat();
    1051             : 
    1052             :   // Synchronize the Jones AND diffJones matrices
    1053             :   virtual void syncDiffJones();
    1054             : 
    1055             :   // Calculate the ensemble of diff'd Jones Elements
    1056             :   virtual void calcAllDiffJones();
    1057             : 
    1058             :   // Calculate one ant/chan's diffJElem w.r.t. each par
    1059             :   virtual void calcOneDiffJones(casacore::Matrix<casacore::Complex>& mat, const casacore::Vector<casacore::Complex>& par);
    1060             : 
    1061             :   // Create matrix renderers for dJs
    1062             :   void createDiffJones();
    1063             : 
    1064             :   // Override VJ::setMatByOk in solve context
    1065           0 :   void setMatByOk() { if (!isSolved()) VisJones::setMatByOk(); };
    1066             : 
    1067             :   // Initialize trivial diff'd Jones
    1068             :   virtual void initTrivDJ();
    1069             : 
    1070             :   virtual void stateSVJ(const casacore::Bool& doVC);
    1071             : 
    1072             :   // atomic power normalization calculation
    1073             :   //   SVJ version assumes amp in voltage units
    1074             :   virtual casacore::Float calcPowerNorm(casacore::Array<casacore::Float>& amp, const casacore::Array<casacore::Bool>& ok);
    1075             :                              
    1076             : private:
    1077             : 
    1078             :   // Default ctor is private
    1079             :   SolvableVisJones();
    1080             : 
    1081             :   // Jones wrappers for diffJElem_;
    1082             :   Jones *dJ1_;
    1083             :   Jones *dJ2_;
    1084             : 
    1085             :   // Differentiated Jones matrix elements
    1086             :   casacore::Array<casacore::Complex> diffJElem_;    // (nJME,nPar,nChanMat,nAnt,2)
    1087             : 
    1088             :   // Validity of Jones matrix derivatives
    1089             :   casacore::Bool DJValid_;
    1090             : 
    1091             :   // Column widths for listing
    1092             :   casacore::uInt wTime_p,  wField_p, wChan_p, wAmp_p, 
    1093             :        wPhase_p, wFlag_p,  wPol_p,  wAntCol_p, 
    1094             :        wTotal_p, wPreAnt_p;
    1095             : 
    1096             : };
    1097             : 
    1098             : // Global methods
    1099             : 
    1100             : // Discern cal table type from the table itself
    1101             : casacore::String calTableType(const casacore::String& tablename);
    1102             : 
    1103             : } //# NAMESPACE CASA - END
    1104             : 
    1105             : #endif

Generated by: LCOV version 1.16