LCOV - code coverage report
Current view: top level - synthesis/CalTables - GJonesMBuf.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 0 290 0.0 %
Date: 2023-11-02 14:27:30 Functions: 0 28 0.0 %

          Line data    Source code
       1             : //# GJonesMBuf.cc: Implementation of GJonesMBuf.h
       2             : //# Copyright (C) 1996,1997,1998,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 addressed 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             : //# $Id$
      27             : //----------------------------------------------------------------------------
      28             : 
      29             : #include <synthesis/CalTables/GJonesMBuf.h>
      30             : #include <casacore/casa/Arrays/ArrayMath.h>
      31             : #include <casacore/tables/Tables/RefRows.h>
      32             : 
      33             : using namespace casacore;
      34             : namespace casa { //# NAMESPACE CASA - BEGIN
      35             : 
      36             : //----------------------------------------------------------------------------
      37             : 
      38           0 : GJonesPolyMBuf::GJonesPolyMBuf() : GJonesMBuf()
      39             : {
      40             : // Null constructor
      41             : // Output to private data:
      42             : //    GJonesMBuf          GJonesMBuf         GJones cal main buffer
      43             : //    polyType_p          Vector<String>     Polynomial type
      44             : //    polyMode_p          Vector<String>     Polynomial mode (e.g. A&P)
      45             : //    scaleFactor_p       Vector<Complex>    Polynomial scale factor
      46             : //    nPolyAmp_p          Vector<Int>        Polynomial degree (amplitude)
      47             : //    nPolyPhase_p        Vector<Int>        Polynomial degree (phase)
      48             : //    polyCoeffAmp_p      Array<Double>      Polynomial coeff. (amplitude)
      49             : //    polyCoeffPhase_p    Array<Double>      Polynomial coeff. (phase)
      50             : //    phaseUnits_p        Vector<String>     Phase units
      51             : //    polyTypeOK_p        Bool               Polynomial type cache ok
      52             : //    polyModeOK_p        Bool               Polynomial mode cache ok
      53             : //    scaleFactorOK_p     Bool               Scale factor cache ok
      54             : //    nPolyAmpOK_p        Bool               Poly. degree (amp) cache ok
      55             : //    nPolyPhaseOK_p      Bool               Poly. degree (phase) cache ok
      56             : //    polyCoeffAmpOK_p    Bool               Poly. coeff. (amp) cache ok
      57             : //    polyCoeffPhaseOK_p  Bool               Poly. coeff. (phase) cache ok
      58             : //    phaseUnitsOK_p      Bool               Phase units cache ok
      59             : //
      60             :   // Invalidate cache
      61           0 :   invalidate();
      62           0 : };
      63             : 
      64             : //----------------------------------------------------------------------------
      65             : 
      66           0 : GJonesPolyMBuf::GJonesPolyMBuf (const Vector<Int>& calIndices,
      67           0 :                                 const Block<Vector<Int> >& indexValues) : 
      68           0 :   GJonesMBuf (calIndices, indexValues)
      69             : {
      70             : // Construct from a set of cal buffer indices and specified index values
      71             : // Output to private data:
      72             : //    GJonesMBuf       GJonesMBuf         Parent class cal main table buffer
      73             : //
      74             :   // Set the local non-index columns to default values
      75           0 :   fillAttributes (calIndices);
      76           0 : };
      77             : 
      78             : //----------------------------------------------------------------------------
      79             : 
      80           0 : GJonesPolyMBuf::GJonesPolyMBuf (CalIterBase& calIter) : GJonesMBuf (calIter)
      81             : {
      82             : // Construct from a calibration table iterator
      83             : // Input:
      84             : //    calIter             CalIterBase&       Calibration table iterator
      85             : // Output to private data:
      86             : //    GJonesMBuf          GJonesMBuf         GJones cal main buffer
      87             : //    polyType_p          Vector<String>     Polynomial type
      88             : //    polyMode_p          Vector<String>     Polynomial mode (e.g. A&P)
      89             : //    scaleFactor_p       Vector<Complex>    Polynomial scale factor
      90             : //    nPolyAmp_p          Vector<Int>        Polynomial degree (amplitude)
      91             : //    nPolyPhase_p        Vector<Int>        Polynomial degree (phase)
      92             : //    polyCoeffAmp_p      Array<Double>      Polynomial coeff. (amplitude)
      93             : //    polyCoeffPhase_p    Array<Double>      Polynomial coeff. (phase)
      94             : //    phaseUnits_p        Vector<String>     Phase units
      95             : //    polyTypeOK_p        Bool               Polynomial type cache ok
      96             : //    polyModeOK_p        Bool               Polynomial mode cache ok
      97             : //    scaleFactorOK_p     Bool               Scale factor cache ok
      98             : //    nPolyAmpOK_p        Bool               Poly. degree (amp) cache ok
      99             : //    nPolyPhaseOK_p      Bool               Poly. degree (phase) cache ok
     100             : //    polyCoeffAmpOK_p    Bool               Poly. coeff. (amp) cache ok
     101             : //    polyCoeffPhaseOK_p  Bool               Poly. coeff. (phase) cache ok
     102             : //    phaseUnitsOK_p      Bool               Phase units cache ok
     103             : //
     104             :   // Invalidate cache
     105           0 :   invalidate();
     106           0 : };
     107             : 
     108             : //----------------------------------------------------------------------------
     109             : 
     110           0 : void GJonesPolyMBuf::invalidate()
     111             : {
     112             : // Invalidate the current cache
     113             : // Output to private data:
     114             : //    polyTypeOK_p        Bool               Polynomial type cache ok
     115             : //    polyModeOK_p        Bool               Polynomial mode cache ok
     116             : //    scaleFactorOK_p     Bool               Scale factor cache ok
     117             : //    nPolyAmpOK_p        Bool               Poly. degree (amp) cache ok
     118             : //    nPolyPhaseOK_p      Bool               Poly. degree (phase) cache ok
     119             : //    polyCoeffAmpOK_p    Bool               Poly. coeff. (amp) cache ok
     120             : //    polyCoeffPhaseOK_p  Bool               Poly. coeff. (phase) cache ok
     121             : //    phaseUnitsOK_p      Bool               Phase units cache ok
     122             : //
     123             :   // Invalidate parent class cache
     124           0 :   GJonesMBuf::invalidate();
     125             : 
     126             :   // Set all cache flags to false
     127           0 :   polyTypeOK_p = false;
     128           0 :   polyModeOK_p = false;
     129           0 :   scaleFactorOK_p = false;
     130           0 :   nPolyAmpOK_p = false;
     131           0 :   nPolyPhaseOK_p = false;
     132           0 :   polyCoeffAmpOK_p = false;
     133           0 :   polyCoeffPhaseOK_p = false;
     134           0 :   phaseUnitsOK_p = false;
     135           0 : };
     136             : 
     137             : //----------------------------------------------------------------------------
     138             : 
     139           0 : Int GJonesPolyMBuf::append (CalTable& calTable)
     140             : {
     141             : // Append the current calibration buffer to a calibration table
     142             : // Input:
     143             : //    calTable            CalTable&          Calibration table
     144             : //
     145             :   // Extend the inherited parent class method
     146           0 :   Int nAdded = SolvableVisJonesMBuf::append(calTable);
     147             : 
     148             :   // Compute the row numbers already added by the parent class
     149           0 :   uInt endRow = calTable.nRowMain() - 1;
     150           0 :   uInt startRow = endRow - nAdded + 1;
     151             : 
     152             :   // Attach a calibration table columns accessor
     153           0 :   GJonesPolyMCol gjpMainCol(dynamic_cast<GJonesPolyTable&>(calTable));
     154             : 
     155             :   // Append the current cal buffer main columns
     156           0 :   RefRows refRows(startRow, endRow);
     157           0 :   gjpMainCol.polyType().putColumnCells(refRows, polyType());
     158           0 :   gjpMainCol.polyMode().putColumnCells(refRows, polyMode());
     159           0 :   gjpMainCol.scaleFactor().putColumnCells(refRows, scaleFactor());
     160           0 :   gjpMainCol.nPolyAmp().putColumnCells(refRows, nPolyAmp());
     161           0 :   gjpMainCol.nPolyPhase().putColumnCells(refRows, nPolyPhase());
     162           0 :   gjpMainCol.polyCoeffAmp().putColumnCells(refRows, polyCoeffAmp());
     163           0 :   gjpMainCol.polyCoeffPhase().putColumnCells(refRows, polyCoeffPhase());
     164           0 :   gjpMainCol.phaseUnits().putColumnCells(refRows, phaseUnits());
     165             : 
     166           0 :   return nAdded;
     167             : };
     168             : 
     169             : //----------------------------------------------------------------------------
     170             : 
     171           0 : Int GJonesPolyMBuf::nRow()
     172             : {
     173             : // Return the maximum number of rows in the calibration buffer
     174             : // Input from private data:
     175             : //    polyType_p          Vector<String>     Polynomial type
     176             : //    polyMode_p          Vector<String>     Polynomial mode (e.g. A&P)
     177             : //    scaleFactor_p       Vector<Complex>    Polynomial scale factor
     178             : //    nPolyAmp_p          Vector<Int>        Polynomial degree (amplitude)
     179             : //    nPolyPhase_p        Vector<Int>        Polynomial degree (phase)
     180             : //    polyCoeffAmp_p      Array<Double>      Polynomial coeff. (amplitude)
     181             : //    polyCoeffPhase_p    Array<Double>      Polynomial coeff. (phase)
     182             : //    phaseUnits_p        Vector<String>     Phase units
     183             : //    polyTypeOK_p        Bool               Polynomial type cache ok
     184             : //    polyModeOK_p        Bool               Polynomial mode cache ok
     185             : //    scaleFactorOK_p     Bool               Scale factor cache ok
     186             : //    nPolyAmpOK_p        Bool               Poly. degree (amp) cache ok
     187             : //    nPolyPhaseOK_p      Bool               Poly. degree (phase) cache ok
     188             : //    polyCoeffAmpOK_p    Bool               Poly. coeff. (amp) cache ok
     189             : //    polyCoeffPhaseOK_p  Bool               Poly. coeff. (phase) cache ok
     190             : //    phaseUnitsOK_p      Bool               Phase units cache ok
     191             : // Output:
     192             : //    nRow                Int                Maximum number of rows
     193             : //
     194             :   // Extend the inherited parent class method
     195           0 :   Int nRowParent = SolvableVisJonesMBuf::nRow();
     196             : 
     197             :   // Process each local column individually
     198           0 :   Vector<Int> colLength(9);
     199           0 :   Int n = 0;
     200           0 :   colLength(n++) = nRowParent;
     201           0 :   colLength(n++) = polyType().nelements();
     202           0 :   colLength(n++) = polyMode().nelements();
     203           0 :   colLength(n++) = scaleFactor().nelements();
     204           0 :   colLength(n++) = nPolyAmp().nelements();
     205           0 :   colLength(n++) = nPolyPhase().nelements();
     206           0 :   colLength(n++) = polyCoeffAmp().shape().nelements() > 0 ?
     207           0 :     polyCoeffAmp().shape().getLast(1)(0) : 0;
     208           0 :   colLength(n++) = polyCoeffPhase().shape().nelements() > 0 ?
     209           0 :     polyCoeffPhase().shape().getLast(1)(0) : 0;
     210           0 :   colLength(n++) = phaseUnits().nelements();
     211             : 
     212           0 :   return max(colLength);
     213             : };
     214             : 
     215             : //----------------------------------------------------------------------------
     216             : 
     217           0 : Bool GJonesPolyMBuf::fillMatchingRows (const Vector<Int>& matchingRows,
     218             :                                        const String& sFreqGrpName,
     219             :                                        const String& sPolyType, 
     220             :                                        const String& sPolyMode,
     221             :                                        const Complex& sScaleFactor,
     222             :                                        const Int& sNPolyAmp, 
     223             :                                        const Int& sNPolyPhase, 
     224             :                                        const Vector<Double>& sPolyCoeffAmp,
     225             :                                        const Vector<Double>& sPolyCoeffPhase,
     226             :                                        const String& sPhaseUnits,
     227             :                                        const MFrequency& sRefFreq,
     228             :                                        const Int& sRefAnt)
     229             : {
     230             : // Update the parametrized solution in each of a set of buffer rows
     231             : // Input:
     232             : //    matchingRows        const Vec<Int>&        Buffer rows to update
     233             : //    sFreqGrpName        const String&          Freq. group name 
     234             : //    sPolyType           const String&          Polynomial type
     235             : //    sPolyMode           const String&          Polynomial mode (e.g. A&P)
     236             : //    sScaleFactor        const Complex&         Polynomial scale factor
     237             : //    sNPolyAmp           const Int&             Poly. degree (amp)
     238             : //    sNPolyPhase         const Int&             Poly. degree (phase)
     239             : //    sPolyCoeffAmp       const Vector<Double>&  Poly. coeff. (amp)
     240             : //    sPolyCoeffPhase     const Vector<Double>&  Poly. coeff. (phase)
     241             : //    sPhaseUnits         const String&          Phase units
     242             : //    sRefFreq            const MFrequency&      Reference frequency
     243             : //    sRefAnt             const Int &            Reference antenna id.
     244             : //
     245             :   // Initialization
     246           0 :   Bool retval = false;
     247           0 :   Int nMatch = matchingRows.nelements();
     248             : 
     249           0 :   if (nMatch > 0) {
     250           0 :     retval = true;
     251             : 
     252             :     // Resize the coefficient arrays
     253           0 :     IPosition ampCoeffShape = polyCoeffAmp().shape();
     254           0 :     if (sPolyMode.contains("AMP")  && ampCoeffShape(3) != 2*sNPolyAmp) {
     255           0 :       ampCoeffShape(3) = 2*sNPolyAmp;
     256           0 :       polyCoeffAmp().resize(ampCoeffShape);
     257             :     };
     258           0 :     IPosition phaseCoeffShape = polyCoeffPhase().shape();
     259           0 :     if (sPolyMode.contains("PHAS") && phaseCoeffShape(3) != 2*sNPolyPhase) {
     260           0 :       IPosition phaseCoeffShape = polyCoeffPhase().shape();
     261           0 :       phaseCoeffShape(3) = 2*sNPolyPhase;
     262           0 :       polyCoeffPhase().resize(phaseCoeffShape);
     263           0 :       polyCoeffPhase() = 0;
     264             :     };
     265             : 
     266             :     // Update each matched row
     267           0 :     for (Int i=0; i < nMatch; i++) {
     268           0 :       uInt row = matchingRows(i);
     269           0 :       freqGrpName()(row) = sFreqGrpName;
     270           0 :       polyType()(row) = sPolyType;
     271             :       
     272             :       // Check if the polynomial mode needs to be updated
     273           0 :       String currMode = polyMode()(row);
     274           0 :       if ((currMode.contains("AMP") && sPolyMode.contains("PHAS")) ||
     275           0 :           (currMode.contains("PHAS") && sPolyMode.contains("AMP"))) {
     276           0 :         polyMode()(row) = "A&P";
     277             :       } else {
     278           0 :         polyMode()(row) = sPolyMode;
     279             :       };
     280             :       
     281           0 :       if (sPolyMode.contains("PHAS")) {
     282           0 :         Complex currFactor = scaleFactor()(row);
     283           0 :         scaleFactor()(row) = 
     284           0 :           abs(currFactor) > 0 ? currFactor*sScaleFactor : sScaleFactor;
     285           0 :         nPolyPhase()(row) = sNPolyPhase;
     286             : 
     287             :         // Phase units
     288           0 :         phaseUnits()(row) = sPhaseUnits;
     289             :       };
     290             : 
     291           0 :       if (sPolyMode.contains("AMP")) {
     292           0 :         nPolyAmp()(row) = sNPolyAmp;
     293             :       };
     294             : 
     295             :       // Update all array elements
     296           0 :       for (Int recep=0; recep < ampCoeffShape(0); recep++) {
     297           0 :         for (Int spw=0; spw < ampCoeffShape(1); spw++) {
     298           0 :           for (Int chan=0; chan < ampCoeffShape(2); chan++) {
     299           0 :             IPosition ipos4(4, recep, spw, chan, row);
     300             : 
     301             : 
     302           0 :             if (sPolyMode.contains("PHAS")) {
     303             :               // Compute a phase scale factor if the reference
     304             :               // frequency has changed 
     305           0 :               Double phaseScaleFactor = 0;
     306           0 :               Double refFreqHz = refFreqMeas()(ipos4).get("Hz").getValue();
     307           0 :               Double sRefFreqHz = sRefFreq.get("Hz").getValue();
     308           0 :               if (abs(refFreqHz) > 0 && abs(sRefFreqHz) > 0) {
     309           0 :                 phaseScaleFactor = sRefFreqHz / refFreqHz;
     310             :               };
     311             :               // Reference frequency and antenna
     312           0 :               refFreqMeas()(ipos4) = sRefFreq;
     313           0 :               refAnt()(ipos4) = sRefAnt;
     314             :               
     315             :               // Phase polynomial coefficients
     316           0 :               for (Int coeff=0; coeff < 2*sNPolyPhase; coeff++) {
     317           0 :                 IPosition ipos5(5, recep, spw, chan, coeff, row);
     318             :                 // Multiply exisiting coefficients by the phase scale factor
     319           0 :                 polyCoeffPhase()(ipos5) *= phaseScaleFactor;
     320           0 :                 polyCoeffPhase()(ipos5) += sPolyCoeffPhase(coeff);
     321             :               };
     322             :             }
     323             : 
     324           0 :             if (sPolyMode.contains("AMP")) {
     325             :               // Amplitude polynomial coefficients
     326           0 :               for (Int coeff=0; coeff < 2*sNPolyAmp; coeff++) {
     327           0 :                 IPosition ipos5(5, recep, spw, chan, coeff, row);
     328           0 :                 polyCoeffAmp()(ipos5) = sPolyCoeffAmp(coeff);
     329             :               };
     330             :             };
     331             : 
     332             :           };
     333             :         };
     334             :       };
     335             : 
     336             :     };
     337             :   };
     338           0 :   return retval;
     339             : };
     340             : 
     341             : //----------------------------------------------------------------------------
     342             : 
     343           0 : Vector<String>& GJonesPolyMBuf::polyType()
     344             : {
     345             : // POLY_TYPE data field accessor
     346             : // Input from private data:
     347             : //    polyType_p          Vector<String>     Polynomial type
     348             : //    polyTypeOK_p        Bool               Polynomial type cache ok
     349             : //
     350             :   // Fill local cache for this column if cache not valid
     351           0 :   if (connectedToIter()) {
     352           0 :     if (!polyTypeOK_p) {
     353           0 :       calMainCol()->polyType().getColumn (polyType_p);
     354           0 :       polyTypeOK_p = true;
     355             :     };
     356             :   };
     357           0 :   return polyType_p;
     358             : };
     359             : 
     360             : //----------------------------------------------------------------------------
     361             : 
     362           0 : Vector<String>& GJonesPolyMBuf::polyMode()
     363             : {
     364             : // POLY_MODE data field accessor
     365             : // Input from private data:
     366             : //    polyMode_p          Vector<String>     Polynomial mode (e.g. A&P)
     367             : //    polyModeOK_p        Bool               Polynomial mode cache ok
     368             : //
     369             :   // Fill local cache for this column if cache not valid
     370           0 :   if (connectedToIter()) {
     371           0 :     if (!polyModeOK_p) {
     372           0 :       calMainCol()->polyMode().getColumn (polyMode_p);
     373           0 :       polyModeOK_p = true;
     374             :     };
     375             :   };
     376           0 :   return polyMode_p;
     377             : };
     378             : 
     379             : //----------------------------------------------------------------------------
     380             : 
     381           0 : Vector<Complex>& GJonesPolyMBuf::scaleFactor()
     382             : {
     383             : // SCALE_FACTOR data field accessor
     384             : // Input from private data:
     385             : //    scaleFactor_p       Vector<Complex>    Polynomial scale factor
     386             : //    scaleFactorOK_p     Bool               Polynomial scale factor cache ok
     387             : //
     388             :   // Fill local cache for this column if cache not valid
     389           0 :   if (connectedToIter()) {
     390           0 :     if (!scaleFactorOK_p) {
     391           0 :       calMainCol()->scaleFactor().getColumn (scaleFactor_p);
     392           0 :       scaleFactorOK_p = true;
     393             :     };
     394             :   };
     395           0 :   return scaleFactor_p;
     396             : };
     397             : 
     398             : //----------------------------------------------------------------------------
     399             : 
     400           0 : Vector<Int>& GJonesPolyMBuf::nPolyAmp()
     401             : {
     402             : // N_POLY_AMP data field accessor
     403             : // Input from private data:
     404             : //    nPolyAmp_p          Vector<Int>        Polynomial degree (amplitude)
     405             : //    nPolyAmpOK_p        Bool               Poly. degree (amp) cache ok
     406             : //
     407             :   // Fill local cache for this column if cache not valid
     408           0 :   if (connectedToIter()) {
     409           0 :     if (!nPolyAmpOK_p) {
     410           0 :       calMainCol()->nPolyAmp().getColumn (nPolyAmp_p);
     411           0 :       nPolyAmpOK_p = true;
     412             :     };
     413             :   };
     414           0 :   return nPolyAmp_p;
     415             : };
     416             : 
     417             : //----------------------------------------------------------------------------
     418             : 
     419           0 : Vector<Int>& GJonesPolyMBuf::nPolyPhase()
     420             : {
     421             : // N_POLY_PHASE data field accessor
     422             : // Input from private data:
     423             : //    nPolyPhase_p          Vector<Int>        Polynomial degree (phase)
     424             : //    nPolyPhaseOK_p        Bool               Poly. degree (phase) cache ok
     425             : //
     426             :   // Fill local cache for this column if cache not valid
     427           0 :   if (connectedToIter()) {
     428           0 :     if (!nPolyPhaseOK_p) {
     429           0 :       calMainCol()->nPolyPhase().getColumn (nPolyPhase_p);
     430           0 :       nPolyPhaseOK_p = true;
     431             :     };
     432             :   };
     433           0 :   return nPolyPhase_p;
     434             : };
     435             : 
     436             : //----------------------------------------------------------------------------
     437             : 
     438           0 : Array<Double>& GJonesPolyMBuf::polyCoeffAmp()
     439             : {
     440             : // POLY_COEFF_AMP data field accessor
     441             : // Input from private data:
     442             : //    polyCoeffAmp_p      Array<Double>      Polynomial coeff. (amplitude)
     443             : //    polyCoeffAmpOK_p    Bool               Poly. coeff. (amp) cache ok
     444             : //
     445             :   // Fill local cache for this column if cache not valid
     446           0 :   if (connectedToIter()) {
     447           0 :     if (!polyCoeffAmpOK_p) {
     448           0 :       calMainCol()->polyCoeffAmp().getColumn (polyCoeffAmp_p);
     449           0 :       polyCoeffAmpOK_p = true;
     450             :     };
     451             :   };
     452           0 :   return polyCoeffAmp_p;
     453             : };
     454             : 
     455             : //----------------------------------------------------------------------------
     456             : 
     457           0 : Array<Double>& GJonesPolyMBuf::polyCoeffPhase()
     458             : {
     459             : // POLY_COEFF_PHASE data field accessor
     460             : // Input from private data:
     461             : //    polyCoeffPhase_p      Array<Double>      Polynomial coeff. (phase)
     462             : //    polyCoeffPhaseOK_p    Bool               Poly. coeff. (phase) cache ok
     463             : //
     464             :   // Fill local cache for this column if cache not valid
     465           0 :   if (connectedToIter()) {
     466           0 :     if (!polyCoeffPhaseOK_p) {
     467           0 :       calMainCol()->polyCoeffPhase().getColumn (polyCoeffPhase_p);
     468           0 :       polyCoeffPhaseOK_p = true;
     469             :     };
     470             :   };
     471           0 :   return polyCoeffPhase_p;
     472             : };
     473             : 
     474             : //----------------------------------------------------------------------------
     475             : 
     476           0 : Vector<String>& GJonesPolyMBuf::phaseUnits()
     477             : {
     478             : // PHASE_UNITS data field accessor
     479             : // Input from private data:
     480             : //    phaseUnits_p        Vector<String>     Phase units
     481             : //    phaseUnitsOK_p      Bool               Phase units cache ok
     482             : //
     483             :   // Fill local cache for this column if cache not valid
     484           0 :   if (connectedToIter()) {
     485           0 :     if (!phaseUnitsOK_p) {
     486           0 :       calMainCol()->phaseUnits().getColumn (phaseUnits_p);
     487           0 :       phaseUnitsOK_p = true;
     488             :     };
     489             :   };
     490           0 :   return phaseUnits_p;
     491             : };
     492             : 
     493             : //----------------------------------------------------------------------------
     494             : 
     495           0 :   void GJonesPolyMBuf::fillAttributes (const Vector<Int>& /*calIndices*/)
     496             : {
     497             : // Resize all GJonesPoly attribute columns and set to their default values
     498             : // Input:
     499             : //    calIndices         const Vector<Int>&   Vector of cal indices, specified
     500             : //                                            as enums from class MSCalEnums,
     501             : //                                            to exclude
     502             : // Output to private data:
     503             : //    polyType_p          Vector<String>     Polynomial type
     504             : //    polyMode_p          Vector<String>     Polynomial mode (e.g. A&P)
     505             : //    scaleFactor_p       Vector<Complex>    Polynomial scale factor
     506             : //    nPolyAmp_p          Vector<Int>        Polynomial degree (amplitude)
     507             : //    nPolyPhase_p        Vector<Int>        Polynomial degree (phase)
     508             : //    polyCoeffAmp_p      Array<Double>      Polynomial coeff. (amplitude)
     509             : //    polyCoeffPhase_p    Array<Double>      Polynomial coeff. (phase)
     510             : //    phaseUnits_p        Vector<String>     Phase units
     511             : //
     512             :   // Process each GJonesPoly cal buffer column separately
     513             :   //
     514             :   // Use the maximum number of rows currently defined in the cal buffer
     515           0 :   uInt nrow = nRow();
     516             : 
     517             :   // POLY_TYPE
     518           0 :   polyType().resize(nrow);
     519           0 :   polyType() = "";
     520             : 
     521             :   // POLY_MODE
     522           0 :   polyMode().resize(nrow);
     523           0 :   polyMode() = "";
     524             : 
     525             :   // SCALE_FACTOR
     526           0 :   scaleFactor().resize(nrow);
     527           0 :   scaleFactor() = Complex(1,0);
     528             : 
     529             :   // N_POLY_AMP
     530           0 :   nPolyAmp().resize(nrow);
     531           0 :   nPolyAmp() = 0;
     532             : 
     533             :   // NPOLY_PHASE
     534           0 :   nPolyPhase().resize(nrow);
     535           0 :   nPolyPhase() = 0;
     536             : 
     537             :   // Array-based columns POLY_COEFF_AMP and POLY_COEFF_PHASE (set 
     538             :   // to default unit length in each dimension)
     539           0 :   uInt numSpw = 1;
     540           0 :   uInt numChan = 1;
     541           0 :   uInt numReceptors = 1;
     542           0 :   uInt numCoeff = 1;
     543           0 :   IPosition coeffSize(5, numReceptors, numSpw, numChan, numCoeff, nrow);
     544             : 
     545           0 :   polyCoeffAmp().resize(coeffSize);
     546           0 :   polyCoeffAmp() = 0;
     547           0 :   polyCoeffPhase().resize(coeffSize);
     548           0 :   polyCoeffPhase() = 0;
     549             : 
     550             :   // PHASE_UNITS
     551           0 :   phaseUnits().resize(nrow);
     552           0 :   phaseUnits() = "";
     553             : 
     554           0 :   return;
     555             : };
     556             : 
     557             : //----------------------------------------------------------------------------
     558             : 
     559           0 : GJonesSplineMBuf::GJonesSplineMBuf() : GJonesPolyMBuf()
     560             : {
     561             : // Null constructor
     562             : // Output to private data:
     563             : //    GJonesPolyMBuf        GJonesPolyMBuf    GJonesPoly cal main buffer
     564             : //    nKnotsAmp_p           Vector<Int>       No. of amplitude spline knots
     565             : //    nKnotsPhase_p         Vector<Int>       No. of phase spline knots
     566             : //    splineKnotsAmp_p      Array<Double>     Amp. spline knot positions
     567             : //    splineKnotsPhase_p    Array<Double>     Phase spline knot positions
     568             : //    nKnotsAmpOK_p         Bool              No. amp. spline knots cache ok
     569             : //    nKnotsPhaseOK_p       Bool              No. phase spline knots cache ok
     570             : //    splineKnotsAmpOK_p    Bool              Amp. spline knot posn. cache ok
     571             : //    splineKnotsPhaseOK_p  Bool              Phase spline knot posn. cache ok
     572             : //
     573             :   // Invalidate cache
     574           0 :   invalidate();
     575           0 : };
     576             : 
     577             : //----------------------------------------------------------------------------
     578             : 
     579           0 : GJonesSplineMBuf::GJonesSplineMBuf (const Vector<Int>& calIndices,
     580           0 :                                     const Block<Vector<Int> >& indexValues) : 
     581           0 :   GJonesPolyMBuf (calIndices, indexValues)
     582             : {
     583             : // Construct from a set of cal buffer indices and specified index values
     584             : // Output to private data:
     585             : //    GJonesPolyMBuf      GJonesPolyMBuf     Parent class cal main table buffer
     586             : //
     587             :   // Set the local non-index columns to default values
     588           0 :   fillAttributes (calIndices);
     589             : 
     590           0 : };
     591             : 
     592             : //----------------------------------------------------------------------------
     593             : 
     594           0 : GJonesSplineMBuf::GJonesSplineMBuf (CalIterBase& calIter) : 
     595           0 :   GJonesPolyMBuf (calIter)
     596             : {
     597             : // Construct from a calibration table iterator
     598             : // Input:
     599             : //    calIter             CalIterBase&       Calibration table iterator
     600             : // Output to private data:
     601             : //    GJonesPolyMBuf        GJonesPolyMBuf    GJonesPoly cal main buffer
     602             : //    nKnotsAmp_p           Vector<Int>       No. of amplitude spline knots
     603             : //    nKnotsPhase_p         Vector<Int>       No. of phase spline knots
     604             : //    splineKnotsAmp_p      Array<Double>     Amp. spline knot positions
     605             : //    splineKnotsPhase_p    Array<Double>     Phase spline knot positions
     606             : //    nKnotsAmpOK_p         Bool              No. amp. spline knots cache ok
     607             : //    nKnotsPhaseOK_p       Bool              No. phase spline knots cache ok
     608             : //    splineKnotsAmpOK_p    Bool              Amp. spline knot posn. cache ok
     609             : //    splineKnotsPhaseOK_p  Bool              Phase spline knot posn. cache ok
     610             : //
     611             :   // Invalidate cache
     612           0 :   invalidate();
     613           0 : };
     614             : 
     615             : //----------------------------------------------------------------------------
     616             : 
     617           0 : void GJonesSplineMBuf::invalidate()
     618             : {
     619             : // Invalidate the current cache
     620             : // Output to private data:
     621             : //    nKnotsAmpOK_p         Bool              No. amp. spline knots cache ok
     622             : //    nKnotsPhaseOK_p       Bool              No. phase spline knots cache ok
     623             : //    splineKnotsAmpOK_p    Bool              Amp. spline knot posn. cache ok
     624             : //    splineKnotsPhaseOK_p  Bool              Phase spline knot posn. cache ok
     625             : //
     626             :   // Invalidate parent class cache
     627           0 :   GJonesPolyMBuf::invalidate();
     628             : 
     629             :   // Set all cache flags to false
     630           0 :   nKnotsAmpOK_p = false;
     631           0 :   nKnotsPhaseOK_p = false;
     632           0 :   splineKnotsAmpOK_p = false;
     633           0 :   splineKnotsPhaseOK_p = false;
     634           0 : };
     635             : 
     636             : //----------------------------------------------------------------------------
     637             : 
     638           0 : Int GJonesSplineMBuf::append (CalTable& calTable)
     639             : {
     640             : // Append the current calibration buffer to a calibration table
     641             : // Input:
     642             : //    calTable            CalTable&          Calibration table
     643             : //
     644             :   // Extend the inherited parent class method
     645           0 :   Int nAdded = GJonesPolyMBuf::append(calTable);
     646             : 
     647             :   // Compute the row numbers already added by the parent class
     648           0 :   uInt endRow = calTable.nRowMain() - 1;
     649           0 :   uInt startRow = endRow - nAdded + 1;
     650             : 
     651             :   // Attach a calibration table columns accessor
     652           0 :   GJonesSplineMCol gjsMainCol(dynamic_cast<GJonesSplineTable&>(calTable));
     653             : 
     654             :   // Append the current cal buffer main columns
     655           0 :   RefRows refRows(startRow, endRow);
     656           0 :   gjsMainCol.nKnotsAmp().putColumnCells(refRows, nKnotsAmp());
     657           0 :   gjsMainCol.nKnotsPhase().putColumnCells(refRows, nKnotsPhase());
     658           0 :   gjsMainCol.splineKnotsAmp().putColumnCells(refRows, splineKnotsAmp());
     659           0 :   gjsMainCol.splineKnotsPhase().putColumnCells(refRows, splineKnotsPhase());
     660             : 
     661           0 :   return nAdded;
     662             : };
     663             : 
     664             : //----------------------------------------------------------------------------
     665             : 
     666           0 : Int GJonesSplineMBuf::nRow()
     667             : {
     668             : // Return the maximum number of rows in the calibration buffer
     669             : // Input from private data:
     670             : //    nKnotsAmp_p           Vector<Int>       No. of amplitude spline knots
     671             : //    nKnotsPhase_p         Vector<Int>       No. of phase spline knots
     672             : //    splineKnotsAmp_p      Array<Double>     Amp. spline knot positions
     673             : //    splineKnotsPhase_p    Array<Double>     Phase spline knot positions
     674             : //    nKnotsAmpOK_p         Bool              No. amp. spline knots cache ok
     675             : //    nKnotsPhaseOK_p       Bool              No. phase spline knots cache ok
     676             : //    splineKnotsAmpOK_p    Bool              Amp. spline knot posn. cache ok
     677             : //    splineKnotsPhaseOK_p  Bool              Phase spline knot posn. cache ok
     678             : // Output:
     679             : //    nRow                  Int               Maximum number of rows
     680             : //
     681             :   // Extend the inherited parent class method
     682           0 :   Int nRowParent = GJonesPolyMBuf::nRow();
     683             : 
     684             :   // Process each local column individually
     685           0 :   Vector<Int> colLength(5);
     686           0 :   Int n = 0;
     687           0 :   colLength(n++) = nRowParent;
     688           0 :   colLength(n++) = nKnotsAmp().nelements();
     689           0 :   colLength(n++) = nKnotsPhase().nelements();
     690           0 :   colLength(n++) = splineKnotsAmp().shape().nelements() > 0 ?
     691           0 :     splineKnotsAmp().shape().getLast(1)(0) : 0;
     692           0 :   colLength(n++) = splineKnotsPhase().shape().nelements() > 0 ?
     693           0 :     splineKnotsPhase().shape().getLast(1)(0) : 0;
     694             : 
     695           0 :   return max(colLength);
     696             : };
     697             : 
     698             : //----------------------------------------------------------------------------
     699             : 
     700           0 : Bool GJonesSplineMBuf::fillMatchingRows (const Vector<Int>& matchingRows,
     701             :                                          const String& sFreqGrpName,
     702             :                                          const String& sPolyType, 
     703             :                                          const String& sPolyMode,
     704             :                                          const Complex& sScaleFactor,
     705             :                                          const Int& sNPolyAmp, 
     706             :                                          const Int& sNPolyPhase, 
     707             :                                          const Vector<Double>& sPolyCoeffAmp,
     708             :                                          const Vector<Double>& sPolyCoeffPhase,
     709             :                                          const String& sPhaseUnits,
     710             :                                          const Int& sNKnotsAmp,
     711             :                                          const Int& sNKnotsPhase,
     712             :                                          const Vector<Double>& sSplineKnotsAmp,
     713             :                                          const Vector<Double>& 
     714             :                                          sSplineKnotsPhase,
     715             :                                          const MFrequency& sRefFreq,
     716             :                                          const Int& sRefAnt)
     717             : {
     718             : // Update the parametrized solution in each of a set of buffer rows
     719             : // Input:
     720             : //    matchingRows        const Vector<Int>&     Buffer rows to update
     721             : //    sFreqGrpName        const String&          Freq. group name 
     722             : //    sPolyType           const String&          Polynomial type
     723             : //    sPolyMode           const String&          Polynomial mode (e.g. A&P)
     724             : //    sScaleFactor        const Complex&         Polynomial scale factor
     725             : //    sNPolyAmp           const Int&             Poly. degree (amp)
     726             : //    sNPolyPhase         const Int&             Poly. degree (phase)
     727             : //    sPolyCoeffAmp       const Vector<Double>&  Poly. coeff. (amp)
     728             : //    sPolyCoeffPhase     const Vector<Double>&  Poly. coeff. (phase)
     729             : //    sPhaseUnits         const String&          Phase units
     730             : //    sNKnotsAmp          const Int&             No. of amp. spline knots
     731             : //    sNKnotsPhase        const Int&             No. of phase spline knots
     732             : //    sSplineKnotsAmp     const Vector<Double>&  Amp. spline knot positions
     733             : //    sSplineKnotsPhase   const Vector<Double>&  Phase spline knot positions
     734             : //    sRefFreq            const MFrequency&      Reference frequency
     735             : //    sRefAnt             const Int &            Reference antenna id.
     736             : //
     737             :   // Initialization
     738           0 :   Bool retval = false;
     739             : 
     740             :   // Extend parent method
     741           0 :   GJonesPolyMBuf::fillMatchingRows (matchingRows, sFreqGrpName, sPolyType, 
     742             :                                     sPolyMode, sScaleFactor, sNPolyAmp, 
     743             :                                     sNPolyPhase, sPolyCoeffAmp, 
     744             :                                     sPolyCoeffPhase, sPhaseUnits, 
     745             :                                     sRefFreq, sRefAnt);
     746             : 
     747             :   // Add local spline parameters.
     748             :   //
     749           0 :   Int nMatch = matchingRows.nelements();
     750             : 
     751           0 :   if (nMatch > 0) {
     752           0 :     retval = true;
     753             : 
     754             : 
     755             :     // Resize the spline knot arrays in ampltidue and phase
     756           0 :     IPosition splineKnotsAmpShape = splineKnotsAmp().shape();
     757           0 :     if (sPolyMode.contains("AMP") && splineKnotsAmpShape(3) != sNKnotsAmp) {
     758           0 :       splineKnotsAmpShape(3) = sNKnotsAmp;
     759           0 :       splineKnotsAmp().resize(splineKnotsAmpShape);
     760             :     };
     761           0 :     IPosition splineKnotsPhaseShape = splineKnotsPhase().shape();
     762           0 :     if (sPolyMode.contains("PHAS") && splineKnotsPhaseShape(3) != sNKnotsPhase) {
     763           0 :       splineKnotsPhaseShape(3) = sNKnotsPhase;
     764           0 :       splineKnotsPhase().resize(splineKnotsPhaseShape);
     765             :     };
     766             : 
     767             :     // Update each matched row
     768           0 :     for (Int i=0; i < nMatch; i++) {
     769           0 :       uInt row = matchingRows(i);
     770             : 
     771             :       // No of knots in amplitude and phase splines
     772           0 :       if (sPolyMode.contains("AMP"))  nKnotsAmp()(row)   = sNKnotsAmp;
     773           0 :       if (sPolyMode.contains("PHAS")) nKnotsPhase()(row) = sNKnotsPhase;
     774             :     
     775             :       // Update all array elements
     776           0 :       for (Int recep=0; recep < splineKnotsAmpShape(0); recep++) {
     777           0 :         for (Int spw=0; spw < splineKnotsAmpShape(1); spw++) {
     778           0 :           for (Int chan=0; chan < splineKnotsAmpShape(2); chan++) {
     779             : 
     780             :             // Amplitude spline knot positions
     781           0 :             if (sPolyMode.contains("AMP")) {
     782           0 :               for (Int coeff=0; coeff < sNKnotsAmp; coeff++) {
     783           0 :                 IPosition ipos5(5, recep, spw, chan, coeff, row);
     784           0 :                 splineKnotsAmp()(ipos5) = sSplineKnotsAmp(coeff);
     785             :               };
     786             :             };
     787             : 
     788             :             // Phase spline knot positions
     789           0 :             if (sPolyMode.contains("PHAS")) {
     790           0 :               for (Int coeff=0; coeff < sNKnotsPhase; coeff++) {
     791           0 :                 IPosition ipos5(5, recep, spw, chan, coeff, row);
     792           0 :                 splineKnotsPhase()(ipos5) = sSplineKnotsPhase(coeff);
     793             :               };
     794             :             };
     795             :           };
     796             :         };
     797             :       };
     798             :     };
     799             :   };
     800           0 :   return retval;
     801             : };
     802             : 
     803             : //----------------------------------------------------------------------------
     804             : 
     805           0 : Vector<Int>& GJonesSplineMBuf::nKnotsAmp()
     806             : {
     807             : // N_KNOTS_AMP data field accessor
     808             : // Input from private data:
     809             : //    nKnotsAmp_p          Vector<Int>       No. of amp. spline knots
     810             : //    nKnotsAmpOK_p        Bool              No. amp. spline knots cache ok
     811             : //
     812             :   // Fill local cache for this column if cache not valid
     813           0 :   if (connectedToIter()) {
     814           0 :     if (!nKnotsAmpOK_p) {
     815           0 :       calMainCol()->nKnotsAmp().getColumn (nKnotsAmp_p);
     816           0 :       nKnotsAmpOK_p = true;
     817             :     };
     818             :   };
     819           0 :   return nKnotsAmp_p;
     820             : };
     821             : 
     822             : //----------------------------------------------------------------------------
     823             : 
     824           0 : Vector<Int>& GJonesSplineMBuf::nKnotsPhase()
     825             : {
     826             : // N_KNOTS_PHASE data field accessor
     827             : // Input from private data:
     828             : //    nKnotsPhase_p          Vector<Int>     No. phase spline knots
     829             : //    nKnotsPhaseOK_p        Bool            No. phase spline knots cache ok
     830             : //
     831             :   // Fill local cache for this column if cache not valid
     832           0 :   if (connectedToIter()) {
     833           0 :     if (!nKnotsPhaseOK_p) {
     834           0 :       calMainCol()->nKnotsPhase().getColumn (nKnotsPhase_p);
     835           0 :       nKnotsPhaseOK_p = true;
     836             :     };
     837             :   };
     838           0 :   return nKnotsPhase_p;
     839             : };
     840             : 
     841             : //----------------------------------------------------------------------------
     842             : 
     843           0 : Array<Double>& GJonesSplineMBuf::splineKnotsAmp()
     844             : {
     845             : // SPLINE_KNOTS_AMP data field accessor
     846             : // Input from private data:
     847             : //    splineKnotsAmp_p      Array<Double>    Amp. spline knot positions
     848             : //    splineKnotsAmpOK_p    Bool             Amp. spline knot posn. cache ok
     849             : //
     850             :   // Fill local cache for this column if cache not valid
     851           0 :   if (connectedToIter()) {
     852           0 :     if (!splineKnotsAmpOK_p) {
     853           0 :       calMainCol()->splineKnotsAmp().getColumn (splineKnotsAmp_p);
     854           0 :       splineKnotsAmpOK_p = true;
     855             :     };
     856             :   };
     857           0 :   return splineKnotsAmp_p;
     858             : };
     859             : 
     860             : //----------------------------------------------------------------------------
     861             : 
     862           0 : Array<Double>& GJonesSplineMBuf::splineKnotsPhase()
     863             : {
     864             : // SPLINE_KNOTS_PHASE data field accessor
     865             : // Input from private data:
     866             : //    splineKnotsPhase_p      Array<Double>   Phase spline knot positions
     867             : //    splineKnotsPhaseOK_p    Bool            Phase spline knot posn. cache ok
     868             : //
     869             :   // Fill local cache for this column if cache not valid
     870           0 :   if (connectedToIter()) {
     871           0 :     if (!splineKnotsPhaseOK_p) {
     872           0 :       calMainCol()->splineKnotsPhase().getColumn (splineKnotsPhase_p);
     873           0 :       splineKnotsPhaseOK_p = true;
     874             :     };
     875             :   };
     876           0 :   return splineKnotsPhase_p;
     877             : };
     878             : 
     879             : //----------------------------------------------------------------------------
     880             : 
     881           0 :   void GJonesSplineMBuf::fillAttributes (const Vector<Int>& /*calIndices*/)
     882             : {
     883             : // Resize all GJonesSpline attribute columns and set to their default values
     884             : // Input:
     885             : //    calIndices         const Vector<Int>&   Vector of cal indices, specified
     886             : //                                            as enums from class MSCalEnums,
     887             : //                                            to exclude
     888             : // Output to private data:
     889             : //    nKnotsAmp_p           Vector<Int>       No. of amplitude spline knots
     890             : //    nKnotsPhase_p         Vector<Int>       No. of phase spline knots
     891             : //    splineKnotsAmp_p      Array<Double>     Amp. spline knot positions
     892             : //    splineKnotsPhase_p    Array<Double>     Phase spline knot positions
     893             : //
     894             :   // Process each GJonesSpline cal buffer column separately
     895             :   //
     896             :   // Use the maximum number of rows currently defined in the cal buffer
     897           0 :   uInt nrow = nRow();
     898             : 
     899             :   // N_KNOTS_AMP
     900           0 :   nKnotsAmp().resize(nrow);
     901           0 :   nKnotsAmp() = 0;
     902             : 
     903             :   // N_KNOTS_PHASE
     904           0 :   nKnotsPhase().resize(nrow);
     905           0 :   nKnotsPhase() = 0;
     906             : 
     907             :   // Array-based columns SPLINE_KNOTS_AMP and SPLINE_KNOTS_PHASE (set 
     908             :   // to default unit length in each dimension)
     909           0 :   uInt numSpw = 1;
     910           0 :   uInt numChan = 1;
     911           0 :   uInt numReceptors = 1;
     912           0 :   uInt numCoeff = 1;
     913           0 :   IPosition knotSize(5, numReceptors, numSpw, numChan, numCoeff, nrow);
     914             : 
     915           0 :   splineKnotsAmp().resize(knotSize);
     916           0 :   splineKnotsAmp() = 0;
     917           0 :   splineKnotsPhase().resize(knotSize);
     918           0 :   splineKnotsPhase() = 0;
     919             : 
     920           0 :   return;
     921             : };
     922             : 
     923             : //----------------------------------------------------------------------------
     924             : 
     925             : 
     926             : } //# NAMESPACE CASA - END
     927             : 

Generated by: LCOV version 1.16