LCOV - code coverage report
Current view: top level - synthesis/CalTables - CTPatchedInterp.h (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 10 10 100.0 %
Date: 2023-10-25 08:47:59 Functions: 10 10 100.0 %

          Line data    Source code
       1             : //# CTPatchedInterp.h: Definition for Calibration patch panel
       2             : //# Copyright (C) 1996,1997,1998,1999,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: aips2-request@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 CALTABLES_CTPATCHEDINTERP_H
      29             : #define CALTABLES_CTPATCHEDINTERP_H
      30             : 
      31             : #include <synthesis/CalTables/NewCalTable.h>
      32             : #include <synthesis/CalTables/CTTimeInterp1.h>
      33             : #include <synthesis/CalTables/RIorAParray.h>
      34             : #include <synthesis/CalTables/VisCalEnum.h>
      35             : #include <casacore/scimath/Mathematics/InterpolateArray1D.h>
      36             : #include <casacore/casa/Arrays/Array.h>
      37             : #include <casacore/casa/Arrays/Matrix.h>
      38             : #include <casacore/casa/Arrays/Cube.h>
      39             : #include <casacore/ms/MeasurementSets/MeasurementSet.h>
      40             : #include <casacore/ms/MeasurementSets/MSField.h>
      41             : #include <casacore/ms/MeasurementSets/MSColumns.h>
      42             : #include <casacore/casa/aips.h>
      43             : 
      44             : //#include <casa/BasicSL/Constants.h>
      45             : //#include <casa/OS/File.h>
      46             : //#include <casa/Logging/LogMessage.h>
      47             : //#include <casa/Logging/LogSink.h>
      48             : 
      49             : namespace casa { //# NAMESPACE CASA - BEGIN
      50             :     
      51             : class MSMetaInfoForCal;
      52             : 
      53             : class CTPatchedInterp
      54             : {
      55             : public:
      56             :     
      57             :   //msmetadata(const casacore::MeasurementSet * const & s, const float maxcache);
      58             :   // From NewCalTable only 
      59             :   CTPatchedInterp(NewCalTable& ct,
      60             :                   VisCalEnum::MatrixType mtype,
      61             :                   casacore::Int nPar,
      62             :                   const casacore::String& timetype,
      63             :                   const casacore::String& freqtype,
      64             :                   const casacore::String& fieldtype,
      65             :                   casacore::Vector<casacore::Int> spwmap=casacore::Vector<casacore::Int>(),
      66             :                   casacore::Vector<casacore::Int> fldmap=casacore::Vector<casacore::Int>(),
      67             :                   const CTTIFactoryPtr cttifactoryptr=&CTTimeInterp1::factory);
      68             : 
      69             :   // From NewCalTable and casacore::MS 
      70             :   CTPatchedInterp(NewCalTable& ct,
      71             :                   VisCalEnum::MatrixType mtype,
      72             :                   casacore::Int nPar,
      73             :                   const casacore::String& timetype,
      74             :                   const casacore::String& freqtype,
      75             :                   const casacore::String& fieldtype,
      76             :                   const casacore::MeasurementSet& ms,
      77             :           const MSMetaInfoForCal& msmc,
      78             :                   casacore::Vector<casacore::Int> spwmap=casacore::Vector<casacore::Int>(),
      79             :                   const CTTIFactoryPtr cttifactoryptr=&CTTimeInterp1::factory);
      80             : 
      81             :   // From NewCalTable and casacore::MSColumns 
      82             :   CTPatchedInterp(NewCalTable& ct,
      83             :                   VisCalEnum::MatrixType mtype,
      84             :                   casacore::Int nPar,
      85             :                   const casacore::String& timetype,
      86             :                   const casacore::String& freqtype,
      87             :                   const casacore::String& fieldtype,
      88             :                   const casacore::MSColumns& mscol,
      89             :                   casacore::Vector<casacore::Int> spwmap=casacore::Vector<casacore::Int>(),
      90             :                   const CTTIFactoryPtr cttifactoryptr=&CTTimeInterp1::factory);
      91             : 
      92             :   // From NewCalTable and casacore::MS without  metadata
      93             :   CTPatchedInterp(NewCalTable& ct,
      94             :           VisCalEnum::MatrixType mtype,
      95             :           casacore::Int nPar,
      96             :           const casacore::String& timetype,
      97             :           const casacore::String& freqtype,
      98             :           const casacore::String& fieldtype,
      99             :           const casacore::MeasurementSet& ms,
     100             :           casacore::Vector<casacore::Int> spwmap=casacore::Vector<casacore::Int>(),
     101             :           const CTTIFactoryPtr cttifactoryptr=&CTTimeInterp1::factory);
     102             : 
     103             : 
     104             :   // Destructor
     105             :   virtual ~CTPatchedInterp();
     106             : 
     107             :   // Interpolate, given input field, spw, timestamp, & (optionally) freq list
     108             :   //    returns T if new result (anywhere)
     109             :   casacore::Bool interpolate(casacore::Int obs, casacore::Int scan, casacore::Int fld, casacore::Int spw, casacore::Double time, casacore::Double freq=-1.0);
     110             :   casacore::Bool interpolate(casacore::Int obs, casacore::Int scan, casacore::Int fld, casacore::Int spw, casacore::Double time, const casacore::Vector<casacore::Double>& freq);
     111             : 
     112             :   // Access to the result
     113        5222 :   casacore::Array<casacore::Float>& resultF(casacore::Int obs, casacore::Int scan, casacore::Int fld, casacore::Int spw) { return result_(spw,fld,thisTimeSeg(obs,scan)); };
     114       58735 :   casacore::Array<casacore::Complex> resultC(casacore::Int obs, casacore::Int scan, casacore::Int fld, casacore::Int spw) { return RIorAPArray(result_(spw,fld,thisTimeSeg(obs,scan))).c(); };
     115       63957 :   casacore::Array<casacore::Bool>& rflag(casacore::Int obs, casacore::Int scan, casacore::Int fld, casacore::Int spw) { return resFlag_(spw,fld,thisTimeSeg(obs,scan)); };
     116             : 
     117             :   // Temporary public function for testing
     118           7 :   casacore::Array<casacore::Float>& tresultF(casacore::Int obs, casacore::Int scan, casacore::Int fld, casacore::Int spw) { return timeResult_(spw,fld,thisTimeSeg(obs,scan)); };
     119           7 :   casacore::Array<casacore::Bool>& tresultFlag(casacore::Int obs, casacore::Int scan, casacore::Int fld, casacore::Int spw) { return timeResFlag_(spw,fld,thisTimeSeg(obs,scan)); };
     120             : 
     121             :   // spwOK info for users
     122             :   casacore::Bool spwOK(casacore::Int spw) const;
     123             :   casacore::Bool spwInOK(casacore::Int spw) const;
     124             : 
     125             :   // Const access to various state
     126             :   // TBD
     127             : 
     128             :   // Report state
     129             :   void state();
     130             :     
     131             :     // Access to the MSMetaInfoForCal (throws if none)
     132             :   const MSMetaInfoForCal& msmc() const
     133             :   {
     134             :       if (msmc_) return *msmc_;
     135             :       else throw(casacore::AipsError("VisCal::msmc(): No MSMetaInfoForCal object!"));
     136             :   };
     137             : 
     138             : private:
     139             : 
     140             :   // Null ctor does nothing
     141             :   CTPatchedInterp() :
     142             :     mtype_(VisCalEnum::GLOBAL),
     143             :     freqInterpMethod0_(casacore::InterpolateArray1D<casacore::Double,casacore::Float>::nearestNeighbour) {};
     144             :   
     145             :   // Setup methods
     146             :   void sliceTable();
     147             :   void makeInterpolators();
     148             : 
     149      414769 :   casacore::Int thisTimeSeg(casacore::Int obs, casacore::Int scan) { return (byScan_?scan:byObs_?obs:0); };
     150             :     
     151             :   // Methods to set up 1:1 patch-panel maps
     152             :   //  Private for now as not yet ready to control from outside
     153             :   // Field
     154             :   // default: all 0 (no field-dep yet)
     155         231 :   void setDefFldMap() {fldMap_.resize(nMSFld_); fldMap_.set(0);};
     156             :   void setFldMap(const casacore::MSField& msfld);           // via nearest on-sky
     157             :   void setFldMap(const casacore::MSFieldColumns& fcol);  // via nearest on-sky
     158             :   void setFldMap(casacore::Vector<casacore::Int>& fldmap);        // via ordered index list
     159             :   //void setFldMap(casacore::Vector<casacore::String>& field);     // via name matching
     160             :   //void setFldMap(casacore::uInt to, casacore::uInt from);        // via single to/from 
     161             : 
     162             :   // Calculate fldmap redundancy, enabling reuse
     163             :   void calcAltFld();
     164             : 
     165             :   // Spw
     166             :   // default: indgen (index identity)
     167         231 :   void setDefSpwMap() {spwMap_.resize(nMSSpw_); indgen(spwMap_);};
     168             :   void setSpwMap(casacore::Vector<casacore::Int>& spwmap);
     169             :   //void setSpwMap(casacore::Vector<casacore::Double>& refFreqs);  // via refFreq matching
     170             :   //void setSpwMap(casacore::uInt to, casacore::uInt from);        // via single to/from
     171             : 
     172             :   // Antenna
     173             :   // default: indgen (index identity) 
     174         231 :   void setDefAntMap() {antMap_.resize(nMSAnt_); indgen(antMap_);};
     175             :   //void setAntMap(casacore::Vector<casacore::Int>& ant);          // via ordered index list
     176             :   //void setAntMap(casacore::Vector<casacore::String>& ant);       // via name/station matching
     177             :   //void setAntMap(casacore::uInt to, casacore::uInt from);        // via single to/from
     178             : 
     179             :   // Set generic antenna/baseline map
     180             :   void setElemMap();
     181             : 
     182             :   // Resample in frequency
     183             :   void resampleInFreq(casacore::Matrix<casacore::Float>& fres,casacore::Matrix<casacore::Bool>& fflg,const casacore::Vector<casacore::Double>& fout,
     184             :                       casacore::Matrix<casacore::Float>& tres,casacore::Matrix<casacore::Bool>& tflg,const casacore::Vector<casacore::Double>& fin);
     185             :   void resampleFlagsInFreq(casacore::Vector<casacore::Bool>& flgout,const casacore::Vector<casacore::Double>& fout,
     186             :                            casacore::Vector<casacore::Bool>& flgin,const casacore::Vector<casacore::Double>& fin);
     187             : 
     188             :   // Baseline index from antenna indices: (assumes a1<=a2 !!)
     189         408 :   inline casacore::Int blnidx(const casacore::Int& a1, const casacore::Int& a2, const casacore::Int& nAnt) { return  a1*nAnt-a1*(a1+1)/2+a2; };
     190             : 
     191             :   // Translate freq axis interpolation string
     192             :   casacore::InterpolateArray1D<casacore::Double,casacore::Float>::InterpolationMethod ftype(casacore::String& strtype);
     193             : 
     194             : 
     195             :   // PRIVATE DATA:
     196             :   
     197             :   // The Caltable
     198             :   NewCalTable ct_;
     199             : 
     200             :   // The caltable's name (for forming log messages)
     201             :   casacore::String ctname_;
     202             :   
     203             :   // The MSMetaInfoForCal pointer
     204             :   const MSMetaInfoForCal* msmc_;
     205             : 
     206             :   // casacore::Matrix type
     207             :   VisCalEnum::MatrixType mtype_;
     208             : 
     209             :   // Are parameters fundamentally complex?
     210             :   casacore::Bool isCmplx_;
     211             : 
     212             :   // The number of (casacore::Float) parameters (per-chan, per-element)
     213             :   casacore::Int nPar_, nFPar_;
     214             : 
     215             :   // Interpolation modes
     216             :   casacore::String timeType_, freqTypeStr_;
     217             : 
     218             :   // Relative-to-center interpolation
     219             :   casacore::Bool relativeFreq_;
     220             : 
     221             :   // Freq-dep interpolation method (from InterpolateArray1D enum)
     222             : #define INTERPMETHOD casacore::InterpolateArray1D<casacore::Double,casacore::Float>::InterpolationMethod
     223             :   const INTERPMETHOD freqInterpMethod0_;  // user-specified
     224             :   INTERPMETHOD freqInterpMethod_;         // current
     225             :   casacore::Vector<INTERPMETHOD> freqInterpMethodVec_;  // per ms spw
     226             :   
     227             :   // Are we slicing caltable by field?
     228             :   casacore::Bool byObs_,byScan_,byField_;
     229             : 
     230             :   // CalTable freq axis info
     231             :   casacore::Vector<casacore::Int> nChanIn_;
     232             :   casacore::Vector<casacore::Vector<casacore::Double> > freqIn_;
     233             : 
     234             : 
     235             :   // Obs, Field, Spw, Ant _output_ (casacore::MS) sizes 
     236             :   //   calibration required for up to this many
     237             :   casacore::Int nMSTimeSeg_, nMSFld_, nMSSpw_, nMSAnt_, nMSElem_;
     238             : 
     239             :   // Alternate field indices
     240             :   casacore::Vector<casacore::Int> altFld_;
     241             : 
     242             :   // Obs, Field, Spw, Ant _input_ (CalTable) sizes
     243             :   //  patch panels should not violate these (point to larger indices)
     244             :   casacore::Int nCTTimeSeg_, nCTFld_, nCTSpw_, nCTAnt_, nCTElem_;
     245             : 
     246             :   // OK flag
     247             :   casacore::Vector<casacore::Bool> spwInOK_;
     248             : 
     249             :   // The patch panels
     250             :   //   Each has length from casacore::MS, values refer to CT
     251             :   casacore::Vector<casacore::Int> fldMap_, spwMap_, antMap_, elemMap_;
     252             : 
     253             :   // Control conjugation of baseline-based solutions when mapping requires
     254             :   casacore::Vector<casacore::Bool> conjTab_;
     255             : 
     256             :   // Internal result Arrays
     257             :   casacore::Cube<casacore::Cube<casacore::Float> > timeResult_,freqResult_;   // [nMSSpw_,nMSFld_,nMSTimeSeg_][nFpar,nChan,nAnt]
     258             :   casacore::Cube<casacore::Cube<casacore::Bool> >  timeResFlag_,freqResFlag_; // [nMSSpw_,nMSFld_,nMSTimeSeg_][nFpar,nChan,nAnt]
     259             : 
     260             :   // Current interpolation result Arrays
     261             :   //  These will reference time or freq result, depending on context,
     262             :   //  and may be referenced by external code
     263             :   casacore::Cube<casacore::Cube<casacore::Float> > result_;     // [nMSSpw_,nMSFld_,nMSTimeSeg_][nFpar,nChan,nAnt]
     264             :   casacore::Cube<casacore::Cube<casacore::Bool> >  resFlag_;    // [nMSSpw_,nMSFld_,nMSTimeSeg_][nFpar,nChan,nAnt]
     265             : 
     266             :   // The CalTable slices
     267             :   casacore::Array<NewCalTable*> ctSlices_;  // [nCTElem_,nCTSpw_,nCTFld_,nCTObs_]
     268             : 
     269             :   // The pre-patched casacore::Time interpolation engines
     270             :   //   These are populated by the available caltables slices
     271             :   casacore::Array<CTTimeInterp1*> tI_;  // [nMSElem_,nMSSpw_,nMSFld_,nMSTimeSeg_]
     272             :   casacore::Array<casacore::Bool> tIdel_;         // [nMSElem_,nMSSpw_,nMSFld_,nMSTimeSeg_]
     273             :   casacore::Array<casacore::Bool> tIMissingLogged_;         // [nMSElem_,nMSSpw_,nMSFld_,nMSTimeSeg_]
     274             : 
     275             :   casacore::Vector<casacore::Int> lastFld_,lastObs_,lastScan_;
     276             : 
     277             :   // Pointer to the factory to use to create CTTimeInterp1s (or specializations)
     278             :   CTTIFactoryPtr cttifactoryptr_;
     279             : 
     280             : };
     281             : 
     282             : 
     283             : } //# NAMESPACE CASA - END
     284             : 
     285             : #endif

Generated by: LCOV version 1.16