LCOV - code coverage report
Current view: top level - synthesis/MeasurementComponents - VisCal.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 96 0.0 %
Date: 2024-10-29 13:38:20 Functions: 0 78 0.0 %

          Line data    Source code
       1             : //# VisCal.h: Definitions of interface for VisCal 
       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             : //# $Id: VisCal.h,v 1.10 2006/02/06 19:23:11 gmoellen Exp $
      28             : 
      29             : #ifndef SYNTHESIS_VISCAL_H
      30             : #define SYNTHESIS_VISCAL_H
      31             : 
      32             : #include <casacore/casa/aips.h>
      33             : #include <casacore/casa/Containers/Record.h>
      34             : #include <casacore/casa/BasicSL/Complex.h>
      35             : #include <casacore/casa/BasicSL/Constants.h>
      36             : #include <synthesis/MeasurementComponents/Mueller.h>
      37             : #include <synthesis/MeasurementComponents/Jones.h>
      38             : #include <synthesis/CalTables/VisCalEnum.h>
      39             : #include <synthesis/MeasurementComponents/VisVector.h>
      40             : #include <msvis/MSVis/VisSet.h>
      41             : #include <msvis/MSVis/VisBuffer2.h>
      42             : 
      43             : #include <msvis/MSVis/VisBuffGroupAcc.h>
      44             : 
      45             : namespace casa { //# NAMESPACE CASA - BEGIN
      46             : 
      47             : class MSMetaInfoForCal;
      48             : 
      49             : // **********************************************************
      50             : //  VisCal
      51             : //
      52             : 
      53             : class VisCal {
      54             : 
      55             :   friend class SolvableVisJones;
      56             : 
      57             : public:
      58             :  
      59             :   // Allowed types of VisCal matrices - 'correct' order
      60             :   //  enum Type{UVMOD,Mf,M,K,B,G,D,C,E,P,T,EP,F};
      61             :   //  enum Type{Test=0,ANoise,M,KAntPos,K,B,G,J,D,X,C,P,E,T,F,A,ALL};
      62             :   enum Type{Test=0,ANoise,M,KAntPos,B,K,G,J,D,X,C,P,E,T,F,A,ALL};
      63             : 
      64             :   // Enumeration of parameter types (casacore::Complex, Real, or Both)
      65             :   enum ParType{Co,Re,CoRe};
      66             : 
      67           0 :   static casacore::String nameOfType(Type type) {
      68           0 :     switch (type) {
      69           0 :     case ANoise: return "ANoise";
      70           0 :     case M: return "M";
      71           0 :     case K: return "K";
      72           0 :     case B: return "B";
      73           0 :     case J: return "J";
      74           0 :     case D: return "D";
      75           0 :     case X: return "X";
      76           0 :     case C: return "C";
      77           0 :     case P: return "P";
      78           0 :     case E: return "E";
      79           0 :     case T: return "T";
      80           0 :     case F: return "F";
      81           0 :     case A: return "A";
      82           0 :     default: return "0";
      83             :     }
      84             :   }
      85             : 
      86             :   VisCal(VisSet& vs);
      87             :   
      88             :   VisCal(casacore::String msname,casacore::Int MSnAnt,casacore::Int MSnSpw);
      89             : 
      90             :   VisCal(const MSMetaInfoForCal& msmc);
      91             :   
      92             :   VisCal(const casacore::Int& nAnt);
      93             :   
      94             :   virtual ~VisCal();
      95             : 
      96             :   // Return the type of this calibration matrix (actual type of derived class).
      97             :   //    (Must be implemented in specializations!)
      98             :   virtual Type type()=0;
      99             : 
     100             :   // Return type name as string
     101           0 :   virtual casacore::String typeName()     { return "Unknown VisCal"; };
     102           0 :   virtual casacore::String longTypeName() { return "Unknown VisCal"; };
     103             : 
     104             :   // Return casacore::Matrix type
     105           0 :   virtual VisCalEnum::MatrixType matrixType() { return VisCalEnum::GLOBAL; };
     106             : 
     107             :   // Return the parameter type (nominally complex)
     108           0 :   virtual VisCalEnum::VCParType parType() { return VisCalEnum::COMPLEX; };
     109             : 
     110             :   // Number of pars per ant/bln
     111             :   //    (Must be implemented in specializations!)
     112             :   virtual casacore::Int nPar()=0;
     113             : 
     114             :   // Report calibration availability per spw
     115             :   //  (always true for non-tabular?)
     116           0 :   virtual casacore::Vector<casacore::Bool> spwOK() { return casacore::Vector<casacore::Bool>(nSpw(),true); };
     117           0 :   virtual casacore::Bool spwOK(casacore::Int) { return true; };
     118             : 
     119             :   // Calibration available?
     120             :   //  (always true for non-tabular)
     121           0 :   virtual casacore::Bool calAvailable(vi::VisBuffer2&) { return true;};
     122             : 
     123             :   // Calibration expected AND available? 
     124             :   //  (always assume true for non-tabular)
     125           0 :   virtual casacore::Bool VBOKforCalApply(vi::VisBuffer2&) { return true;};
     126             : 
     127             :   // Frequency-dependent Parameters?  Nominally not.
     128           0 :   virtual casacore::Bool freqDepPar() { return false; };
     129             : 
     130             :   // Number of par channels in current spw
     131           0 :   inline const casacore::Int& nChanPar() const { return nChanPar_[currSpw_]; };
     132             :   
     133             :   // Frequency-dependent Matrices?  Nominally same as freqDepPar.
     134           0 :   virtual casacore::Bool freqDepMat() { return freqDepPar(); };
     135             : 
     136             :   // Freq-dep Weight scaling?  // almost always false
     137           0 :   virtual casacore::Bool freqDepCalWt() { return false; };
     138             : 
     139             :   // Matrices time-dependent per parameter set (nominally no)
     140           0 :   virtual casacore::Bool timeDepMat() { return false; };
     141             : 
     142             :   // Is this calibration matrix to be applied?
     143           0 :   inline casacore::Bool isApplied() {return applied_;};
     144             : 
     145             :   // Is this solveable? (never via this interface)
     146           0 :   virtual casacore::Bool isSolvable() {return false;};
     147             : 
     148             :   // Return the time interval over which this calibration is constant
     149           0 :   inline virtual casacore::Double& interval() {return interval_;}
     150             : 
     151             :   // Set the application parameters
     152             :   virtual void setApply();
     153             :   virtual void setApply(const casacore::Record& apply);
     154             :   virtual void setCallib(const casacore::Record& callib,const casacore::MeasurementSet& selms);
     155             : 
     156             :   // Apply info/params, suitable for logging
     157             :   virtual casacore::String applyinfo();
     158             : 
     159             :   // simulation params - for a VC, sim is apply; for a SVC this will get 
     160             :   // overriden
     161           0 :   inline virtual casacore::String siminfo() { return applyinfo(); };
     162             : 
     163             :   // Trigger calibration of weights
     164           0 :   inline casacore::Bool& calWt() { return calWt_; };
     165             : 
     166             :   // Apply calibration to data in VisBuffer (correct casacore::Data or corrupt Model)
     167             :   //  (in-place versions)
     168             :   virtual void correct(VisBuffer& vb, casacore::Bool trial=false);
     169             :   virtual void correct2(vi::VisBuffer2& vb, casacore::Bool trial=false, 
     170             :                         casacore::Bool doWtSp=false, casacore::Bool dosync=true);
     171             :   virtual void corrupt(VisBuffer& vb);
     172             :   virtual void corrupt2(vi::VisBuffer2& vb);
     173             : 
     174             :   // Apply calibration to data in VisBuffer; 
     175             :   //  (alternate output versions)
     176             :   virtual void correct(VisBuffer& vb, casacore::Cube<casacore::Complex>& Vout,casacore::Bool trial=false);
     177             :   virtual void corrupt(VisBuffer& vb, casacore::Cube<casacore::Complex>& Mout);
     178             :   virtual void corrupt2(vi::VisBuffer2& vb, casacore::Cube<casacore::Complex>& Mout);
     179             : 
     180             :   // Flag counting
     181             :   virtual void initCalFlagCount();
     182             :   virtual casacore::Record actionRec();
     183             : 
     184             :   // Report the state
     185             :   virtual void state();
     186             : 
     187             :   virtual void currMetaNote();
     188             : 
     189             :   // Set the print level
     190           0 :   inline void setPrtlev(const casacore::Int& prtlev) { prtlev_=prtlev; };
     191             : 
     192             :   // Baseline index from antenna indices: (assumes a1<=a2 !!)
     193           0 :   inline casacore::Int blnidx(const casacore::Int& a1, 
     194           0 :                     const casacore::Int& a2) { return  a1*nAnt() - a1*(a1+1)/2 + a2; };
     195             : 
     196           0 :   inline casacore::String& extraTag() { return extratag_; };
     197             : 
     198             :  
     199             :   // VI2-related refactor--------------------------------------
     200             : 
     201             :   // Set "current" meta info, so internals can be registered
     202             :   virtual void setMeta(int obs, int scan, double time,
     203             :                        int spw, const casacore::Vector<double>& freq,
     204             :                        int fld);
     205             : 
     206             :   // Reshape solvePar* arrays for the currSpw()  
     207             :   //  (sensitive to freqDepPar())
     208             :   virtual void sizeApplyParCurrSpw(int nVisChan);
     209             : 
     210             :   // Set parameters to def values in the currSpw(), 
     211             :   //   and optionally sync everything
     212             :   virtual void setDefApplyParCurrSpw(bool sync=false, bool doInv=false);
     213             : 
     214             :   // Set parameters to specified values in the currSpw(),
     215             :   //   and optionally sync matrices
     216             :   virtual void setApplyParCurrSpw(const casacore::Cube<casacore::Complex> cpar,
     217             :                                   bool sync=false, bool doInv=false);
     218             : 
     219             :   virtual void setApplyParCurrSpw(const casacore::Cube<float> rpar,
     220             :                                   bool sync=false, bool doInv=false);
     221             : 
     222             :   // Access (public) to current solution parameters and matrices
     223           0 :   inline virtual casacore::Cube<casacore::Complex>& currCPar()  {return (*currCPar_[currSpw()]);};
     224           0 :   inline virtual casacore::Cube<casacore::Float>&   currRPar()  {return (*currRPar_[currSpw()]);};
     225           0 :   inline virtual casacore::Cube<casacore::Bool>&    currParOK() {return (*currParOK_[currSpw()]);};
     226             : 
     227             : 
     228             : protected:
     229             : 
     230             :   // Set applied state flag
     231           0 :   inline void setApplied(const casacore::Bool& flag) {applied_=flag;};
     232             : 
     233           0 :   inline casacore::String& msName() { return msName_; };
     234             : 
     235             :   // General Shape Info 
     236           0 :   inline casacore::Int& nSpw() { return nSpw_; };
     237           0 :   inline casacore::Int& nAnt() { return nAnt_; };
     238           0 :   inline casacore::Int& nBln() { return nBln_; };
     239             : 
     240             :   // The number of sets of parameters under consideration
     241             :   virtual casacore::Int& nElem()=0;
     242             : 
     243             :   // Number of Calibration matrices on ant/bln axis
     244             :   virtual casacore::Int nCalMat()=0;
     245             : 
     246             :   // Current in-focus spw
     247           0 :   inline casacore::Int& currSpw() { return currSpw_; };
     248             : 
     249             :   // Current coords
     250           0 :   inline casacore::Double& lastTime()                { return lastTime_(currSpw()); };
     251           0 :   inline casacore::Double& currTime()                { return currTime_(currSpw()); };
     252           0 :   inline casacore::Int&    currScan()                { return currScan_(currSpw()); };
     253           0 :   inline casacore::Int&    currObs()                 { return currObs_(currSpw()); };
     254           0 :   inline casacore::Int&    currField()               { return currField_(currSpw()); };
     255           0 :   inline casacore::Int&    currIntent()              { return currIntent_(currSpw()); };
     256           0 :   inline casacore::Vector<casacore::Double>& currFreq()        { return currFreq_; };
     257             : 
     258           0 :   inline casacore::Double& refTime()                 { return refTime_; };
     259           0 :   inline casacore::Double& refFreq()                 { return refFreq_; };
     260             : 
     261             :   // Current spectral shapes
     262           0 :   inline casacore::Int& nChanPar()              { return nChanPar_[currSpw_]; };
     263           0 :   inline casacore::Int& nChanMat()              { return nChanMat_[currSpw_]; };
     264           0 :   inline casacore::Int& startChan()             { return startChan_[currSpw_];};
     265           0 :   inline casacore::Vector<casacore::Int>& nChanParList()  { return nChanPar_; };
     266           0 :   inline casacore::Vector<casacore::Int>& nChanMatList()  { return nChanMat_; };
     267           0 :   inline casacore::Vector<casacore::Int>& startChanList() { return startChan_;};
     268             : 
     269             :   // Access to matrix renderings of Visibilities
     270           0 :   inline VisVector& V() { return (*V_[currSpw()]); };
     271             : 
     272             :   // Validation of calibration parameters
     273           0 :   inline void invalidateP() {PValid_(currSpw())=false;};
     274           0 :   inline void validateP()   {PValid_(currSpw())=true;};
     275           0 :   inline casacore::Bool PValid()      {return PValid_(currSpw());};
     276             : 
     277             :   // Invalidate cal matrices generically 
     278             :   virtual void invalidateCalMat()=0;
     279             : 
     280             :   // Access to weight-scaling factors
     281           0 :   inline casacore::Cube<casacore::Float>& currWtScale() { return (*currWtScale_[currSpw()]); };
     282             : 
     283             :   // Flag counting
     284             :   virtual void countInFlag(const VisBuffer& vb);
     285             :   virtual void countInFlag2(const vi::VisBuffer2& vb);
     286             :   virtual void countOutFlag(const VisBuffer& vb);
     287             :   virtual void countOutFlag2(const vi::VisBuffer2& vb);
     288             : 
     289             :   // Row-by-row apply to a casacore::Cube<casacore::Complex> (generic)
     290             :   virtual void applyCal(VisBuffer& vb, casacore::Cube<casacore::Complex>& Vout,casacore::Bool trial=false)=0;
     291             :   virtual void applyCal2(vi::VisBuffer2& vb, 
     292             :                          casacore::Cube<casacore::Complex>& Vout,casacore::Cube<casacore::Float>& Wout,
     293             :                          casacore::Bool trial=false)=0;
     294             : 
     295             :   // Synchronize "gains" with a VisBuffer or another VisCal
     296             :   virtual void syncCal(const VisBuffer& vb,
     297             :                        const casacore::Bool& doInv=false);
     298             :   virtual void syncCal2(const vi::VisBuffer2& vb,
     299             :                        const casacore::Bool& doInv=false);
     300             :   virtual void syncCal(VisCal& vc);
     301             : 
     302             :   // Set internal meta data from a VisBuffer or another VisCal
     303             :   virtual void syncMeta(const VisBuffer& vb);
     304             :   virtual void syncMeta2(const vi::VisBuffer2& vb);
     305             :   void syncMeta(VisCal& vc);
     306             : 
     307             :   void syncMeta(const casacore::Int& spw,
     308             :                 const casacore::Double& time,
     309             :                 const casacore::Int& field,
     310             :                 const casacore::Vector<casacore::Double>& freq,
     311             :                 const casacore::Int& nchan);
     312             : 
     313             :   // Set the calibration matrix channelization
     314             :   void setCalChannelization(const casacore::Int& nChanDat);
     315             : 
     316             :   // Test for need of new calibration
     317             :   void checkCurrCal();
     318             : 
     319             :   // Synchronize "gains" with current meta-data
     320             :   virtual void syncCal(const casacore::Bool& doInv=false);
     321             : 
     322             :   // Sync parameters for current meta data
     323             :   virtual void syncPar();
     324             : 
     325             :   // Calculate Mueller parameters by some means 
     326             :   virtual void calcPar();
     327             : 
     328             :   // Sync matrices generically for current meta data 
     329             :   virtual void syncCalMat(const casacore::Bool& doInv=false)=0;
     330             : 
     331             :   // Return print (cout) level
     332           0 :   inline casacore::Int& prtlev() { return prtlev_; };
     333             : 
     334             :   // set current field index vector to given field id
     335             :   void setCurrField(const casacore::Int& ifld);
     336             : 
     337             :   // Access to the MSMetaInfoForCal (throws if none)
     338           0 :   const MSMetaInfoForCal& msmc() const
     339             :   {
     340           0 :       if (msmc_) return *msmc_;
     341           0 :       else throw(casacore::AipsError("VisCal::msmc(): No MSMetaInfoForCal object!"));
     342             :   };
     343             : 
     344             : private:
     345             : 
     346             :   // Defalt ctor is private
     347             :   VisCal();
     348             : 
     349             :   // Initialize pointers, etc.
     350             :   void initVisCal();
     351             : 
     352             :   // Delete pointers
     353             :   void deleteVisCal();
     354             : 
     355             :   // Associated casacore::MS name
     356             :   casacore::String msName_;
     357             : 
     358             :   // The MSMetaInfoForCal pointer
     359             :   const MSMetaInfoForCal* msmc_;
     360             :   const bool delmsmc_;  // must delete _only_ if locally formed
     361             : 
     362             :   // Number of Spectral windows
     363             :   casacore::Int nSpw_;
     364             : 
     365             :   // Number of antennas
     366             :   casacore::Int nAnt_;
     367             : 
     368             :   // Number of baselines
     369             :   casacore::Int nBln_;
     370             : 
     371             :   // Current synchronized spw
     372             :   casacore::Int currSpw_;
     373             : 
     374             :   // Current indices
     375             :   casacore::Vector<casacore::Double> currTime_;
     376             :   casacore::Vector<casacore::Int> currScan_;
     377             :   casacore::Vector<casacore::Int> currObs_;
     378             :   casacore::Vector<casacore::Int> currField_;
     379             :   casacore::Vector<casacore::Int> currIntent_;
     380             :   casacore::Vector<casacore::Double> currFreq_;
     381             :   casacore::Vector<casacore::Double> lastTime_;
     382             :   casacore::Double refTime_;
     383             :   casacore::Double refFreq_;
     384             : 
     385             :   // Channel counts
     386             :   casacore::Vector<casacore::Int> nChanPar_, nChanMat_;
     387             :   casacore::Vector<casacore::Int> startChan_;
     388             : 
     389             :   // Solution timescale (context-dependent)
     390             :   casacore::Double interval_;
     391             : 
     392             :   // Application flag
     393             :   casacore::Bool applied_;
     394             : 
     395             :   // In-focus channel for single-chan solves on multi-chan data
     396             :   casacore::Int focusChan_;
     397             : 
     398             :   // VisVector wrapper (per Spw)
     399             :   casacore::PtrBlock<VisVector*> V_;
     400             : 
     401             :   // Current parameters
     402             :   casacore::PtrBlock<casacore::Cube<casacore::Complex>*>  currCPar_;   // [nSpw](nPar,nChanPar,nElm)
     403             :   casacore::PtrBlock<casacore::Cube<casacore::Float>*>    currRPar_;   // [nSpw](nPar,nChanPar,nElm)
     404             :   casacore::PtrBlock<casacore::Cube<casacore::Bool>*>     currParOK_;  // [nSpw](nPar,nChanPar,nElm)
     405             : 
     406             :   // Paremeter validity
     407             :   casacore::Vector<casacore::Bool> PValid_;
     408             : 
     409             :   // Trigger calibration of weights
     410             :   casacore::Bool calWt_;
     411             : 
     412             :   // Weight scale factors
     413             :   casacore::PtrBlock<casacore::Cube<casacore::Float>*> currWtScale_;  // [nSpw](nPar,nChan,nElm)
     414             : 
     415             :   // Flag counting
     416             :   casacore::Int64 ndataIn_, nflagIn_, nflagOut_;
     417             : 
     418             :   // Print level
     419             :   casacore::Int prtlev_;
     420             : 
     421             :   casacore::String extratag_;  // e.g. to tag as noise scale
     422             : 
     423             : 
     424             : };
     425             : 
     426             : 
     427             : // **********************************************************
     428             : //  VisMueller
     429             : //
     430             : 
     431             : class VisMueller : virtual public VisCal {
     432             : 
     433             : public:
     434             : 
     435             :   // Constructor
     436             :   VisMueller(VisSet& vs);
     437             : 
     438             :   VisMueller(casacore::String msname,casacore::Int MSnAnt,casacore::Int MSnSpw);
     439             : 
     440             :   VisMueller(const MSMetaInfoForCal& msmc);
     441             : 
     442             :   VisMueller(const casacore::Int& nAnt);
     443             : 
     444             :   virtual ~VisMueller();
     445             : 
     446             :   // Return casacore::Matrix type
     447           0 :   virtual VisCalEnum::MatrixType matrixType() { return VisCalEnum::MUELLER; };
     448             : 
     449             :   // Mueller matrix type (must be implemented in Mueller specializations!)
     450             :   virtual Mueller::MuellerType muellerType()=0;  
     451             : 
     452             :   // Report the state
     453             :   virtual void state();
     454             : 
     455             : protected:
     456             : 
     457             :   // Total number of parameter sets required
     458           0 :   virtual casacore::Int& nElem() { return nBln(); };
     459             : 
     460             :   // Number of Cal Matrices to form on baseline axis
     461             :   //  (Mueller, apply context: nBln())
     462           0 :   virtual casacore::Int nCalMat() { return nBln(); };
     463             : 
     464             :   // Are the parameters the matrix elements? 
     465             :   //   (or is a non-trivial calculation required?)
     466             :   //    (Must be implemented in specializations!)
     467             :   virtual casacore::Bool trivialMuellerElem()=0;
     468             : 
     469             :   // Are we applying via Mueller multiplication?
     470             :   //   (necessarily true for native Muellers)
     471           0 :   virtual casacore::Bool applyByMueller() { return true; };
     472             : 
     473             :   // Access to matrix renderings of Muellers
     474           0 :   inline Mueller& M()   { return (*M_[currSpw()]); };
     475             : 
     476             :   // Access to current matrices
     477           0 :   inline casacore::Cube<casacore::Complex>& currMElem()   {return (*currMElem_[currSpw()]);};
     478           0 :   inline casacore::Cube<casacore::Bool>&    currMElemOK() {return (*currMElemOK_[currSpw()]);};
     479             : 
     480             :   // Invalidate cal matrices generically (at this level, just Mueller)
     481           0 :   inline virtual void invalidateCalMat() { invalidateM(); };
     482             : 
     483             :   // Validation of Mueller matrices (for currSpw)
     484           0 :   inline void invalidateM() {MValid_(currSpw())=false;};
     485           0 :   inline void validateM()   {MValid_(currSpw())=true;};
     486           0 :   inline casacore::Bool MValid()      {return MValid_(currSpw());};
     487             : 
     488             :   // Row-by-row apply to a casacore::Cube<casacore::Complex> (applyByMueller override)
     489             :   virtual void applyCal(VisBuffer& vb, casacore::Cube<casacore::Complex>& Vout,casacore::Bool trial=false);
     490             :   virtual void applyCal2(vi::VisBuffer2& vb, 
     491             :                          casacore::Cube<casacore::Complex>& Vout,casacore::Cube<casacore::Float>& Wout,
     492             :                          casacore::Bool trial=false);
     493             :   //  { throw(casacore::AipsError("VisMueller::applyCal2 NYI!!!!!!!!!!!!!")); };
     494             : 
     495             :   // Sync matrices for current meta data (Mueller override)
     496             :   virtual void syncCalMat(const casacore::Bool& doInv=false);
     497             : 
     498             :   // Sync Mueller matrix elements for current parameters
     499             :   virtual void syncMueller(const casacore::Bool& doInv=false);
     500             : 
     501             :   // Calculate an ensemble of Mueller matrices (all baselines, channels)
     502             :   virtual void calcAllMueller();
     503             : 
     504             :   // Calculate a single Mueller matrix by some means
     505             :   virtual void calcOneMueller(casacore::Vector<casacore::Complex>& mat, casacore::Vector<casacore::Bool>& mOk,
     506             :                               const casacore::Vector<casacore::Complex>& par, const casacore::Vector<casacore::Bool>& pOk);
     507             : 
     508             :   // Invert Mueller matrices
     509             :   virtual void invMueller();
     510             : 
     511             :   // Set matrix elements according to their ok flags
     512             :   //  (e.g., makes a unit matrix if everything flagged,
     513             :   //   so we don't have to make atomic ok checks in apply)
     514             :   virtual void setMatByOk();
     515             : 
     516             :   // Create Mueller matrix algebra interface
     517             :   void createMueller();
     518             :  
     519             :   // Synchronize weight scale factors
     520             :   virtual void syncWtScale();
     521             : 
     522             :   // Perform weight scale calculation (specializable)
     523             :   virtual void calcWtScale();
     524             : 
     525             :   // Update the wt vector for a baseline
     526             :   virtual void updateWt(casacore::Vector<casacore::Float>& wt,const casacore::Int& a1,const casacore::Int& a2);
     527             : 
     528             : 
     529             : private:
     530             : 
     531             :   // Default ctor is private
     532             :   VisMueller();
     533             : 
     534             :   // Init VisMueller pointers, etc.
     535             :   void initVisMueller();
     536             : 
     537             :   // Delete the this* caches
     538             :   void deleteVisMueller();
     539             : 
     540             :   // Mueller algebra wrapper (per Spw)
     541             :   casacore::PtrBlock<Mueller*> M_;                
     542             : 
     543             :   // Current Mueller matrix elements
     544             :   casacore::PtrBlock<casacore::Cube<casacore::Complex>*> currMElem_;    // [nSpw]([1,2,4,16],nChanMat,nBln)
     545             :   casacore::PtrBlock<casacore::Cube<casacore::Bool>*>    currMElemOK_;  // [nSpw]([1,2,4,16],nChanMat,nBln)
     546             : 
     547             :   // Mueller validity
     548             :   casacore::Vector<casacore::Bool> MValid_;
     549             : 
     550             : };
     551             : 
     552             : 
     553             : // **********************************************************
     554             : //  VisJones
     555             : //
     556             : 
     557             : class VisJones : virtual public VisMueller {
     558             : 
     559             :   friend class SolvableVisJones;
     560             : 
     561             : public:
     562             : 
     563             :   // Constructor
     564             :   VisJones(VisSet& vs);
     565             : 
     566             :   VisJones(casacore::String msname,casacore::Int MSnAnt,casacore::Int MSnSpw);
     567             : 
     568             :   VisJones(const MSMetaInfoForCal& msmc);
     569             : 
     570             :   VisJones(const casacore::Int& nAnt);
     571             : 
     572             :   virtual ~VisJones();
     573             : 
     574             :   // Return casacore::Matrix type
     575           0 :   virtual VisCalEnum::MatrixType matrixType() { return VisCalEnum::JONES; };
     576             : 
     577             :   // What kind of Mueller matrices should we use?  
     578             :   //   (A function of the jonesType and target data shape)
     579             :   virtual Mueller::MuellerType muellerType();
     580             : 
     581             :   // What kind of Jones matrix are we?  
     582             :   //    (Must be implemented in specializations!)
     583             :   virtual Jones::JonesType jonesType()=0; 
     584             : 
     585             :   // Report the state
     586             :   virtual void state();
     587             : 
     588             : protected:
     589             : 
     590             :   // Number of parameter sets is number of antennas
     591           0 :   inline virtual casacore::Int& nElem() { return nAnt(); };
     592             : 
     593             :   // Number of Cal Matrices to form on antenna axis
     594             :   //  (Jones, apply context: nAnt())
     595           0 :   virtual casacore::Int nCalMat() { return nAnt(); };
     596             : 
     597             :   // Jones matrices can never be trivial Muellers!
     598           0 :   virtual casacore::Bool trivialMuellerElem() { return false; };
     599             : 
     600             :   // Are the parameters the Jones matrix elements?
     601             :   //   (or is a non-trivial calculation required?)
     602             :   //    (Must be implemented in specializations!)
     603             :   virtual casacore::Bool trivialJonesElem()=0;
     604             : 
     605             :   // Are we applying via Mueller or Jones multiplication?
     606             :   //   (probably by Jones for native Jones?)
     607           0 :   virtual casacore::Bool applyByMueller() { return false; };
     608           0 :   virtual casacore::Bool applyByJones()   { return true; };
     609             : 
     610             :   // Access to matrix renderings of Jones matrices
     611           0 :   inline Jones& J1() { return *J1_[currSpw()]; };
     612           0 :   inline Jones& J2() { return *J2_[currSpw()]; };
     613             : 
     614             :   // Access to Jones matrix element array
     615           0 :   inline casacore::Cube<casacore::Complex>& currJElem() {return (*currJElem_[currSpw()]);};
     616           0 :   inline casacore::Cube<casacore::Bool>& currJElemOK()  {return (*currJElemOK_[currSpw()]);};
     617             : 
     618             :   // Invalidate cal matrices generically (at this level, both Mueller and Jones)
     619           0 :   inline virtual void invalidateCalMat() { invalidateM(); invalidateJ(); };
     620             : 
     621             :   // Validation of Jones matrices
     622           0 :   inline void invalidateJ() {JValid_(currSpw())=false;};
     623           0 :   inline void validateJ()   {JValid_(currSpw())=true;};
     624           0 :   inline casacore::Bool JValid()      {return JValid_(currSpw());};
     625             : 
     626             :   // Row-by-row apply to a casacore::Cube<casacore::Complex> (applyByJones override)
     627             :   virtual void applyCal(VisBuffer& vb, casacore::Cube<casacore::Complex>& Vout,casacore::Bool trial=false);
     628             :   virtual void applyCal2(vi::VisBuffer2& vb, 
     629             :                          casacore::Cube<casacore::Complex>& Vout,casacore::Cube<casacore::Float>& Wout,
     630             :                          casacore::Bool trial=false);
     631             : 
     632             :   // Sync matrices for current meta data (VisJones override)
     633             :   virtual void syncCalMat(const casacore::Bool& doInv=false);
     634             : 
     635             :   // Calculate an ensemble of Mueller matrices (all baselines, channels)
     636             :   //  (only meaningful if applyByMueller()=T)
     637             :   virtual void calcAllMueller();
     638             : 
     639             :   // Synchronize current Jones matrices
     640             :   virtual void syncJones(const casacore::Bool& doInv=false);
     641             : 
     642             :   // Calculate an ensemble of Jones matrices (all antennas, channels)
     643             :   virtual void calcAllJones();
     644             : 
     645             :   // Calculate a single Jones matrix by some means from parameters
     646             :   virtual void calcOneJones(casacore::Vector<casacore::Complex>& mat, casacore::Vector<casacore::Bool>& mOk, 
     647             :                             const casacore::Vector<casacore::Complex>& par, const casacore::Vector<casacore::Bool>& pOk );
     648             : 
     649             :   // Invert Jones matrices
     650             :   virtual void invJones();
     651             : 
     652             :   // Set matrix elements according to their ok flags
     653             :   //  (e.g., makes a unit matrix if everything flagged,
     654             :   //   so we don't have to make atomic ok checks in apply)
     655             :   virtual void setMatByOk();
     656             : 
     657             :   // Create Jones interface
     658             :   void createJones();
     659             : 
     660             :   // Synchronize weight scale factors
     661             :   virtual void syncWtScale();
     662             : 
     663             :   // Perform weight scale calculation (specializable)
     664             :   virtual void calcWtScale();
     665             : 
     666             :   // Update the wt vector for a baseline
     667             :   virtual void updateWt(casacore::Vector<casacore::Float>& wt,const casacore::Int& a1,const casacore::Int& a2);
     668             :   virtual void updateWt2(casacore::Matrix<casacore::Float>& wt,const casacore::Int& a1,const casacore::Int& a2);
     669             : 
     670             : private:
     671             : 
     672             :   // Default ctor is private
     673             :   VisJones();
     674             : 
     675             :   // Init VisJones pointers
     676             :   void initVisJones();
     677             : 
     678             :   // Delete the this* caches
     679             :   void deleteVisJones();
     680             : 
     681             :   // Jones algebra wrapper (per Spw)
     682             :   casacore::PtrBlock<Jones*> J1_;
     683             :   casacore::PtrBlock<Jones*> J2_;
     684             : 
     685             :   // Current Jones matrix-element arrays
     686             :   casacore::PtrBlock<casacore::Cube<casacore::Complex>*> currJElem_;    // [nSpw](nJElem,nChanMat,nAnt)
     687             :   casacore::PtrBlock<casacore::Cube<casacore::Bool>*>    currJElemOK_;  // [nSpw](nJElem,nChanMat,nAnt)
     688             : 
     689             :   // Jones validity, per spw
     690             :   casacore::Vector<casacore::Bool> JValid_;
     691             : 
     692             : 
     693             : };
     694             : 
     695             : } //# NAMESPACE CASA - END
     696             : 
     697             : #endif

Generated by: LCOV version 1.16