LCOV - code coverage report
Current view: top level - synthesis/CalTables - TJonesMBuf.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 0 284 0.0 %
Date: 2023-11-06 10:06:49 Functions: 0 28 0.0 %

          Line data    Source code
       1             : //# TJonesMBuf.cc: Implementation of TJonesMBuf.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/TJonesMBuf.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 : TJonesPolyMBuf::TJonesPolyMBuf() : TJonesMBuf()
      39             : {
      40             : // Null constructor
      41             : // Output to private data:
      42             : //    TJonesMBuf          TJonesMBuf         TJones 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 : TJonesPolyMBuf::TJonesPolyMBuf (const Vector<Int>& calIndices,
      67           0 :                                 const Block<Vector<Int> >& indexValues) : 
      68           0 :   TJonesMBuf (calIndices, indexValues)
      69             : {
      70             : // Construct from a set of cal buffer indices and specified index values
      71             : // Output to private data:
      72             : //    TJonesMBuf       TJonesMBuf         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 : TJonesPolyMBuf::TJonesPolyMBuf (CalIterBase& calIter) : TJonesMBuf (calIter)
      81             : {
      82             : // Construct from a calibration table iterator
      83             : // Input:
      84             : //    calIter             CalIterBase&       Calibration table iterator
      85             : // Output to private data:
      86             : //    TJonesMBuf          TJonesMBuf         TJones 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 TJonesPolyMBuf::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 :   TJonesMBuf::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 TJonesPolyMBuf::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 :   TJonesPolyMCol gjpMainCol(dynamic_cast<TJonesPolyTable&>(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 TJonesPolyMBuf::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 TJonesPolyMBuf::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             :     // Update each matched row
     252           0 :     for (Int i=0; i < nMatch; i++) {
     253           0 :       uInt row = matchingRows(i);
     254           0 :       freqGrpName()(row) = sFreqGrpName;
     255           0 :       polyType()(row) = sPolyType;
     256             : 
     257             :       // Check if the polynomial mode needs to be updated
     258           0 :       String currMode = polyMode()(row);
     259           0 :       if ((currMode.contains("AMP") && sPolyMode.contains("PHAS")) ||
     260           0 :           (currMode.contains("PHAS") && sPolyMode.contains("AMP"))) {
     261           0 :         polyMode()(row) = "A&P";
     262             :       } else {
     263           0 :         polyMode()(row) = sPolyMode;
     264             :       };
     265             : 
     266           0 :       Complex currFactor = scaleFactor()(row);
     267           0 :       scaleFactor()(row) = 
     268           0 :         abs(currFactor) > 0 ? currFactor*sScaleFactor : sScaleFactor;
     269           0 :       nPolyAmp()(row) = sNPolyAmp;
     270           0 :       nPolyPhase()(row) = sNPolyPhase;
     271             : 
     272             :       // Resize the coefficient arrays
     273           0 :       IPosition ampCoeffShape = polyCoeffAmp().shape();
     274           0 :       if (ampCoeffShape(3) != sNPolyAmp) {
     275           0 :         ampCoeffShape(3) = sNPolyAmp;
     276           0 :         polyCoeffAmp().resize(ampCoeffShape);
     277             :       };
     278           0 :       IPosition phaseCoeffShape = polyCoeffPhase().shape();
     279           0 :       if (phaseCoeffShape(3) != sNPolyPhase) {
     280           0 :         IPosition phaseCoeffShape = polyCoeffPhase().shape();
     281           0 :         phaseCoeffShape(3) = sNPolyPhase;
     282           0 :         polyCoeffPhase().resize(phaseCoeffShape);
     283           0 :         polyCoeffPhase() = 0;
     284             :       };
     285             : 
     286             :       // Update all array elements
     287           0 :       for (Int recep=0; recep < ampCoeffShape(0); recep++) {
     288           0 :         for (Int spw=0; spw < ampCoeffShape(1); spw++) {
     289           0 :           for (Int chan=0; chan < ampCoeffShape(2); chan++) {
     290           0 :             IPosition ipos4(4, recep, spw, chan, row);
     291             :             // Compute a phase scale factor if the reference
     292             :             // frequency has changed 
     293           0 :             Double phaseScaleFactor = 0;
     294           0 :             Double refFreqHz = refFreqMeas()(ipos4).get("Hz").getValue();
     295           0 :             Double sRefFreqHz = sRefFreq.get("Hz").getValue();
     296           0 :             if (std::abs(refFreqHz) > 0 && std::abs(sRefFreqHz) > 0) {
     297           0 :               phaseScaleFactor = sRefFreqHz / refFreqHz;
     298             :             };
     299             : 
     300             :             // Reference frequency and antenna
     301           0 :             refFreqMeas()(ipos4) = sRefFreq;
     302           0 :             refAnt()(ipos4) = sRefAnt;
     303             : 
     304             :             // Amplitude polynomial coefficients
     305           0 :             for (Int coeff=0; coeff < sNPolyAmp; coeff++) {
     306           0 :               IPosition ipos5(5, recep, spw, chan, coeff, row);
     307           0 :               polyCoeffAmp()(ipos5) = sPolyCoeffAmp(coeff);
     308             :             };
     309             : 
     310             :             // Phase polynomial coefficients
     311           0 :             for (Int coeff=0; coeff < sNPolyPhase; coeff++) {
     312           0 :               IPosition ipos5(5, recep, spw, chan, coeff, row);
     313             :               // Multiply exisiting coefficients by the phase scale factor
     314           0 :               polyCoeffPhase()(ipos5) *= phaseScaleFactor;
     315           0 :               polyCoeffPhase()(ipos5) += sPolyCoeffPhase(coeff);
     316             :             };
     317             :           };
     318             :         };
     319             :       };
     320             : 
     321             :       // Phase units
     322           0 :       phaseUnits()(row) = sPhaseUnits;
     323             :     };
     324             :   };
     325           0 :   return retval;
     326             : };
     327             : 
     328             : //----------------------------------------------------------------------------
     329             : 
     330           0 : Vector<String>& TJonesPolyMBuf::polyType()
     331             : {
     332             : // POLY_TYPE data field accessor
     333             : // Input from private data:
     334             : //    polyType_p          Vector<String>     Polynomial type
     335             : //    polyTypeOK_p        Bool               Polynomial type cache ok
     336             : //
     337             :   // Fill local cache for this column if cache not valid
     338           0 :   if (connectedToIter()) {
     339           0 :     if (!polyTypeOK_p) {
     340           0 :       calMainCol()->polyType().getColumn (polyType_p);
     341           0 :       polyTypeOK_p = true;
     342             :     };
     343             :   };
     344           0 :   return polyType_p;
     345             : };
     346             : 
     347             : //----------------------------------------------------------------------------
     348             : 
     349           0 : Vector<String>& TJonesPolyMBuf::polyMode()
     350             : {
     351             : // POLY_MODE data field accessor
     352             : // Input from private data:
     353             : //    polyMode_p          Vector<String>     Polynomial mode (e.g. A&P)
     354             : //    polyModeOK_p        Bool               Polynomial mode cache ok
     355             : //
     356             :   // Fill local cache for this column if cache not valid
     357           0 :   if (connectedToIter()) {
     358           0 :     if (!polyModeOK_p) {
     359           0 :       calMainCol()->polyMode().getColumn (polyMode_p);
     360           0 :       polyModeOK_p = true;
     361             :     };
     362             :   };
     363           0 :   return polyMode_p;
     364             : };
     365             : 
     366             : //----------------------------------------------------------------------------
     367             : 
     368           0 : Vector<Complex>& TJonesPolyMBuf::scaleFactor()
     369             : {
     370             : // SCALE_FACTOR data field accessor
     371             : // Input from private data:
     372             : //    scaleFactor_p       Vector<Complex>    Polynomial scale factor
     373             : //    scaleFactorOK_p     Bool               Polynomial scale factor cache ok
     374             : //
     375             :   // Fill local cache for this column if cache not valid
     376           0 :   if (connectedToIter()) {
     377           0 :     if (!scaleFactorOK_p) {
     378           0 :       calMainCol()->scaleFactor().getColumn (scaleFactor_p);
     379           0 :       scaleFactorOK_p = true;
     380             :     };
     381             :   };
     382           0 :   return scaleFactor_p;
     383             : };
     384             : 
     385             : //----------------------------------------------------------------------------
     386             : 
     387           0 : Vector<Int>& TJonesPolyMBuf::nPolyAmp()
     388             : {
     389             : // N_POLY_AMP data field accessor
     390             : // Input from private data:
     391             : //    nPolyAmp_p          Vector<Int>        Polynomial degree (amplitude)
     392             : //    nPolyAmpOK_p        Bool               Poly. degree (amp) cache ok
     393             : //
     394             :   // Fill local cache for this column if cache not valid
     395           0 :   if (connectedToIter()) {
     396           0 :     if (!nPolyAmpOK_p) {
     397           0 :       calMainCol()->nPolyAmp().getColumn (nPolyAmp_p);
     398           0 :       nPolyAmpOK_p = true;
     399             :     };
     400             :   };
     401           0 :   return nPolyAmp_p;
     402             : };
     403             : 
     404             : //----------------------------------------------------------------------------
     405             : 
     406           0 : Vector<Int>& TJonesPolyMBuf::nPolyPhase()
     407             : {
     408             : // N_POLY_PHASE data field accessor
     409             : // Input from private data:
     410             : //    nPolyPhase_p          Vector<Int>        Polynomial degree (phase)
     411             : //    nPolyPhaseOK_p        Bool               Poly. degree (phase) cache ok
     412             : //
     413             :   // Fill local cache for this column if cache not valid
     414           0 :   if (connectedToIter()) {
     415           0 :     if (!nPolyPhaseOK_p) {
     416           0 :       calMainCol()->nPolyPhase().getColumn (nPolyPhase_p);
     417           0 :       nPolyPhaseOK_p = true;
     418             :     };
     419             :   };
     420           0 :   return nPolyPhase_p;
     421             : };
     422             : 
     423             : //----------------------------------------------------------------------------
     424             : 
     425           0 : Array<Double>& TJonesPolyMBuf::polyCoeffAmp()
     426             : {
     427             : // POLY_COEFF_AMP data field accessor
     428             : // Input from private data:
     429             : //    polyCoeffAmp_p      Array<Double>      Polynomial coeff. (amplitude)
     430             : //    polyCoeffAmpOK_p    Bool               Poly. coeff. (amp) cache ok
     431             : //
     432             :   // Fill local cache for this column if cache not valid
     433           0 :   if (connectedToIter()) {
     434           0 :     if (!polyCoeffAmpOK_p) {
     435           0 :       calMainCol()->polyCoeffAmp().getColumn (polyCoeffAmp_p);
     436           0 :       polyCoeffAmpOK_p = true;
     437             :     };
     438             :   };
     439           0 :   return polyCoeffAmp_p;
     440             : };
     441             : 
     442             : //----------------------------------------------------------------------------
     443             : 
     444           0 : Array<Double>& TJonesPolyMBuf::polyCoeffPhase()
     445             : {
     446             : // POLY_COEFF_PHASE data field accessor
     447             : // Input from private data:
     448             : //    polyCoeffPhase_p      Array<Double>      Polynomial coeff. (phase)
     449             : //    polyCoeffPhaseOK_p    Bool               Poly. coeff. (phase) cache ok
     450             : //
     451             :   // Fill local cache for this column if cache not valid
     452           0 :   if (connectedToIter()) {
     453           0 :     if (!polyCoeffPhaseOK_p) {
     454           0 :       calMainCol()->polyCoeffPhase().getColumn (polyCoeffPhase_p);
     455           0 :       polyCoeffPhaseOK_p = true;
     456             :     };
     457             :   };
     458           0 :   return polyCoeffPhase_p;
     459             : };
     460             : 
     461             : //----------------------------------------------------------------------------
     462             : 
     463           0 : Vector<String>& TJonesPolyMBuf::phaseUnits()
     464             : {
     465             : // PHASE_UNITS data field accessor
     466             : // Input from private data:
     467             : //    phaseUnits_p        Vector<String>     Phase units
     468             : //    phaseUnitsOK_p      Bool               Phase units cache ok
     469             : //
     470             :   // Fill local cache for this column if cache not valid
     471           0 :   if (connectedToIter()) {
     472           0 :     if (!phaseUnitsOK_p) {
     473           0 :       calMainCol()->phaseUnits().getColumn (phaseUnits_p);
     474           0 :       phaseUnitsOK_p = true;
     475             :     };
     476             :   };
     477           0 :   return phaseUnits_p;
     478             : };
     479             : 
     480             : //----------------------------------------------------------------------------
     481             : 
     482           0 :   void TJonesPolyMBuf::fillAttributes (const Vector<Int>& /*calIndices*/)
     483             : {
     484             : // Resize all TJonesPoly attribute columns and set to their default values
     485             : // Input:
     486             : //    calIndices         const Vector<Int>&   Vector of cal indices, specified
     487             : //                                            as enums from class MSCalEnums,
     488             : //                                            to exclude
     489             : // Output to private data:
     490             : //    polyType_p          Vector<String>     Polynomial type
     491             : //    polyMode_p          Vector<String>     Polynomial mode (e.g. A&P)
     492             : //    scaleFactor_p       Vector<Complex>    Polynomial scale factor
     493             : //    nPolyAmp_p          Vector<Int>        Polynomial degree (amplitude)
     494             : //    nPolyPhase_p        Vector<Int>        Polynomial degree (phase)
     495             : //    polyCoeffAmp_p      Array<Double>      Polynomial coeff. (amplitude)
     496             : //    polyCoeffPhase_p    Array<Double>      Polynomial coeff. (phase)
     497             : //    phaseUnits_p        Vector<String>     Phase units
     498             : //
     499             :   // Process each TJonesPoly cal buffer column separately
     500             :   //
     501             :   // Use the maximum number of rows currently defined in the cal buffer
     502           0 :   uInt nrow = nRow();
     503             : 
     504             :   // POLY_TYPE
     505           0 :   polyType().resize(nrow);
     506           0 :   polyType() = "";
     507             : 
     508             :   // POLY_MODE
     509           0 :   polyMode().resize(nrow);
     510           0 :   polyMode() = "";
     511             : 
     512             :   // SCALE_FACTOR
     513           0 :   scaleFactor().resize(nrow);
     514           0 :   scaleFactor() = Complex(1,0);
     515             : 
     516             :   // N_POLY_AMP
     517           0 :   nPolyAmp().resize(nrow);
     518           0 :   nPolyAmp() = 0;
     519             : 
     520             :   // NPOLY_PHASE
     521           0 :   nPolyPhase().resize(nrow);
     522           0 :   nPolyPhase() = 0;
     523             : 
     524             :   // Array-based columns POLY_COEFF_AMP and POLY_COEFF_PHASE (set 
     525             :   // to default unit length in each dimension)
     526           0 :   uInt numSpw = 1;
     527           0 :   uInt numChan = 1;
     528           0 :   uInt numReceptors = 1;
     529           0 :   uInt numCoeff = 1;
     530           0 :   IPosition coeffSize(5, numReceptors, numSpw, numChan, numCoeff, nrow);
     531             : 
     532           0 :   polyCoeffAmp().resize(coeffSize);
     533           0 :   polyCoeffAmp() = 0;
     534           0 :   polyCoeffPhase().resize(coeffSize);
     535           0 :   polyCoeffPhase() = 0;
     536             : 
     537             :   // PHASE_UNITS
     538           0 :   phaseUnits().resize(nrow);
     539           0 :   phaseUnits() = "";
     540             : 
     541           0 :   return;
     542             : };
     543             : 
     544             : //----------------------------------------------------------------------------
     545             : 
     546           0 : TJonesSplineMBuf::TJonesSplineMBuf() : TJonesPolyMBuf()
     547             : {
     548             : // Null constructor
     549             : // Output to private data:
     550             : //    TJonesPolyMBuf        TJonesPolyMBuf    TJonesPoly cal main buffer
     551             : //    nKnotsAmp_p           Vector<Int>       No. of amplitude spline knots
     552             : //    nKnotsPhase_p         Vector<Int>       No. of phase spline knots
     553             : //    splineKnotsAmp_p      Array<Double>     Amp. spline knot positions
     554             : //    splineKnotsPhase_p    Array<Double>     Phase spline knot positions
     555             : //    nKnotsAmpOK_p         Bool              No. amp. spline knots cache ok
     556             : //    nKnotsPhaseOK_p       Bool              No. phase spline knots cache ok
     557             : //    splineKnotsAmpOK_p    Bool              Amp. spline knot posn. cache ok
     558             : //    splineKnotsPhaseOK_p  Bool              Phase spline knot posn. cache ok
     559             : //
     560             :   // Invalidate cache
     561           0 :   invalidate();
     562           0 : };
     563             : 
     564             : //----------------------------------------------------------------------------
     565             : 
     566           0 : TJonesSplineMBuf::TJonesSplineMBuf (const Vector<Int>& calIndices,
     567           0 :                                     const Block<Vector<Int> >& indexValues) : 
     568           0 :   TJonesPolyMBuf (calIndices, indexValues)
     569             : {
     570             : // Construct from a set of cal buffer indices and specified index values
     571             : // Output to private data:
     572             : //    TJonesPolyMBuf      TJonesPolyMBuf     Parent class cal main table buffer
     573             : //
     574             :   // Set the local non-index columns to default values
     575           0 :   fillAttributes (calIndices);
     576           0 : };
     577             : 
     578             : //----------------------------------------------------------------------------
     579             : 
     580           0 : TJonesSplineMBuf::TJonesSplineMBuf (CalIterBase& calIter) : 
     581           0 :   TJonesPolyMBuf (calIter)
     582             : {
     583             : // Construct from a calibration table iterator
     584             : // Input:
     585             : //    calIter             CalIterBase&       Calibration table iterator
     586             : // Output to private data:
     587             : //    TJonesPolyMBuf        TJonesPolyMBuf    TJonesPoly cal main buffer
     588             : //    nKnotsAmp_p           Vector<Int>       No. of amplitude spline knots
     589             : //    nKnotsPhase_p         Vector<Int>       No. of phase spline knots
     590             : //    splineKnotsAmp_p      Array<Double>     Amp. spline knot positions
     591             : //    splineKnotsPhase_p    Array<Double>     Phase spline knot positions
     592             : //    nKnotsAmpOK_p         Bool              No. amp. spline knots cache ok
     593             : //    nKnotsPhaseOK_p       Bool              No. phase spline knots cache ok
     594             : //    splineKnotsAmpOK_p    Bool              Amp. spline knot posn. cache ok
     595             : //    splineKnotsPhaseOK_p  Bool              Phase spline knot posn. cache ok
     596             : //
     597             :   // Invalidate cache
     598           0 :   invalidate();
     599           0 : };
     600             : 
     601             : //----------------------------------------------------------------------------
     602             : 
     603           0 : void TJonesSplineMBuf::invalidate()
     604             : {
     605             : // Invalidate the current cache
     606             : // Output to private data:
     607             : //    nKnotsAmpOK_p         Bool              No. amp. spline knots cache ok
     608             : //    nKnotsPhaseOK_p       Bool              No. phase spline knots cache ok
     609             : //    splineKnotsAmpOK_p    Bool              Amp. spline knot posn. cache ok
     610             : //    splineKnotsPhaseOK_p  Bool              Phase spline knot posn. cache ok
     611             : //
     612             :   // Invalidate parent class cache
     613           0 :   TJonesPolyMBuf::invalidate();
     614             : 
     615             :   // Set all cache flags to false
     616           0 :   nKnotsAmpOK_p = false;
     617           0 :   nKnotsPhaseOK_p = false;
     618           0 :   splineKnotsAmpOK_p = false;
     619           0 :   splineKnotsPhaseOK_p = false;
     620           0 : };
     621             : 
     622             : //----------------------------------------------------------------------------
     623             : 
     624           0 : Int TJonesSplineMBuf::append (CalTable& calTable)
     625             : {
     626             : // Append the current calibration buffer to a calibration table
     627             : // Input:
     628             : //    calTable            CalTable&          Calibration table
     629             : //
     630             :   // Extend the inherited parent class method
     631           0 :   Int nAdded = TJonesPolyMBuf::append(calTable);
     632             : 
     633             :   // Compute the row numbers already added by the parent class
     634           0 :   uInt endRow = calTable.nRowMain() - 1;
     635           0 :   uInt startRow = endRow - nAdded + 1;
     636             : 
     637             :   // Attach a calibration table columns accessor
     638           0 :   TJonesSplineMCol gjsMainCol(dynamic_cast<TJonesSplineTable&>(calTable));
     639             : 
     640             :   // Append the current cal buffer main columns
     641           0 :   RefRows refRows(startRow, endRow);
     642           0 :   gjsMainCol.nKnotsAmp().putColumnCells(refRows, nKnotsAmp());
     643           0 :   gjsMainCol.nKnotsPhase().putColumnCells(refRows, nKnotsPhase());
     644           0 :   gjsMainCol.splineKnotsAmp().putColumnCells(refRows, splineKnotsAmp());
     645           0 :   gjsMainCol.splineKnotsPhase().putColumnCells(refRows, splineKnotsPhase());
     646             : 
     647           0 :   return nAdded;
     648             : };
     649             : 
     650             : //----------------------------------------------------------------------------
     651             : 
     652           0 : Int TJonesSplineMBuf::nRow()
     653             : {
     654             : // Return the maximum number of rows in the calibration buffer
     655             : // Input from private data:
     656             : //    nKnotsAmp_p           Vector<Int>       No. of amplitude spline knots
     657             : //    nKnotsPhase_p         Vector<Int>       No. of phase spline knots
     658             : //    splineKnotsAmp_p      Array<Double>     Amp. spline knot positions
     659             : //    splineKnotsPhase_p    Array<Double>     Phase spline knot positions
     660             : //    nKnotsAmpOK_p         Bool              No. amp. spline knots cache ok
     661             : //    nKnotsPhaseOK_p       Bool              No. phase spline knots cache ok
     662             : //    splineKnotsAmpOK_p    Bool              Amp. spline knot posn. cache ok
     663             : //    splineKnotsPhaseOK_p  Bool              Phase spline knot posn. cache ok
     664             : // Output:
     665             : //    nRow                  Int               Maximum number of rows
     666             : //
     667             :   // Extend the inherited parent class method
     668           0 :   Int nRowParent = TJonesPolyMBuf::nRow();
     669             : 
     670             :   // Process each local column individually
     671           0 :   Vector<Int> colLength(5);
     672           0 :   Int n = 0;
     673           0 :   colLength(n++) = nRowParent;
     674           0 :   colLength(n++) = nKnotsAmp().nelements();
     675           0 :   colLength(n++) = nKnotsPhase().nelements();
     676           0 :   colLength(n++) = splineKnotsAmp().shape().nelements() > 0 ?
     677           0 :     splineKnotsAmp().shape().getLast(1)(0) : 0;
     678           0 :   colLength(n++) = splineKnotsPhase().shape().nelements() > 0 ?
     679           0 :     splineKnotsPhase().shape().getLast(1)(0) : 0;
     680             : 
     681           0 :   return max(colLength);
     682             : };
     683             : 
     684             : //----------------------------------------------------------------------------
     685             : 
     686           0 : Bool TJonesSplineMBuf::fillMatchingRows (const Vector<Int>& matchingRows,
     687             :                                          const String& sFreqGrpName,
     688             :                                          const String& sPolyType, 
     689             :                                          const String& sPolyMode,
     690             :                                          const Complex& sScaleFactor,
     691             :                                          const Int& sNPolyAmp, 
     692             :                                          const Int& sNPolyPhase, 
     693             :                                          const Vector<Double>& sPolyCoeffAmp,
     694             :                                          const Vector<Double>& sPolyCoeffPhase,
     695             :                                          const String& sPhaseUnits,
     696             :                                          const Int& sNKnotsAmp,
     697             :                                          const Int& sNKnotsPhase,
     698             :                                          const Vector<Double>& sSplineKnotsAmp,
     699             :                                          const Vector<Double>& 
     700             :                                          sSplineKnotsPhase,
     701             :                                          const MFrequency& sRefFreq,
     702             :                                          const Int& sRefAnt)
     703             : {
     704             : // Update the parametrized solution in each of a set of buffer rows
     705             : // Input:
     706             : //    matchingRows        const Vector<Int>&     Buffer rows to update
     707             : //    sFreqGrpName        const String&          Freq. group name 
     708             : //    sPolyType           const String&          Polynomial type
     709             : //    sPolyMode           const String&          Polynomial mode (e.g. A&P)
     710             : //    sScaleFactor        const Complex&         Polynomial scale factor
     711             : //    sNPolyAmp           const Int&             Poly. degree (amp)
     712             : //    sNPolyPhase         const Int&             Poly. degree (phase)
     713             : //    sPolyCoeffAmp       const Vector<Double>&  Poly. coeff. (amp)
     714             : //    sPolyCoeffPhase     const Vector<Double>&  Poly. coeff. (phase)
     715             : //    sPhaseUnits         const String&          Phase units
     716             : //    sNKnotsAmp          const Int&             No. of amp. spline knots
     717             : //    sNKnotsPhase        const Int&             No. of phase spline knots
     718             : //    sSplineKnotsAmp     const Vector<Double>&  Amp. spline knot positions
     719             : //    sSplineKnotsPhase   const Vector<Double>&  Phase spline knot positions
     720             : //    sRefFreq            const MFrequency&      Reference frequency
     721             : //    sRefAnt             const Int &            Reference antenna id.
     722             : //
     723             :   // Initialization
     724           0 :   Bool retval = false;
     725             : 
     726             :   // Extend parent method
     727           0 :   TJonesPolyMBuf::fillMatchingRows (matchingRows, sFreqGrpName, sPolyType, 
     728             :                                     sPolyMode, sScaleFactor, sNPolyAmp, 
     729             :                                     sNPolyPhase, sPolyCoeffAmp, 
     730             :                                     sPolyCoeffPhase, sPhaseUnits, 
     731             :                                     sRefFreq, sRefAnt);
     732             : 
     733             :   // Add local spline parameters.
     734             :   //
     735           0 :   Int nMatch = matchingRows.nelements();
     736             : 
     737           0 :   if (nMatch > 0) {
     738           0 :     retval = true;
     739             :     // Update each matched row
     740           0 :     for (Int i=0; i < nMatch; i++) {
     741           0 :       uInt row = matchingRows(i);
     742             : 
     743             :       // No of knots in amplitude and phase splines
     744           0 :       nKnotsAmp()(row) = sNKnotsAmp;
     745           0 :       nKnotsPhase()(row) = sNKnotsPhase;
     746             :     
     747             :       // Resize the spline knot arrays in ampltidue and phase
     748           0 :       IPosition splineKnotsAmpShape = splineKnotsAmp().shape();
     749           0 :       if (splineKnotsAmpShape(3) != sNKnotsAmp) {
     750           0 :         splineKnotsAmpShape(3) = sNKnotsAmp;
     751           0 :         splineKnotsAmp().resize(splineKnotsAmpShape);
     752             :       };
     753           0 :       IPosition splineKnotsPhaseShape = splineKnotsPhase().shape();
     754           0 :       if (splineKnotsPhaseShape(3) != sNKnotsPhase) {
     755           0 :         splineKnotsPhaseShape(3) = sNKnotsPhase;
     756           0 :         splineKnotsPhase().resize(splineKnotsPhaseShape);
     757             :       };
     758             : 
     759             :       // Update all array elements
     760           0 :       for (Int recep=0; recep < splineKnotsAmpShape(0); recep++) {
     761           0 :         for (Int spw=0; spw < splineKnotsAmpShape(1); spw++) {
     762           0 :           for (Int chan=0; chan < splineKnotsAmpShape(2); chan++) {
     763             : 
     764             :             // Amplitude spline knot positions
     765           0 :             for (Int coeff=0; coeff < sNKnotsAmp; coeff++) {
     766           0 :               IPosition ipos5(5, recep, spw, chan, coeff, row);
     767           0 :               splineKnotsAmp()(ipos5) = sSplineKnotsAmp(coeff);
     768             :             };
     769             : 
     770             :             // Phase spline knot positions
     771           0 :             for (Int coeff=0; coeff < sNKnotsPhase; coeff++) {
     772           0 :               IPosition ipos5(5, recep, spw, chan, coeff, row);
     773           0 :               splineKnotsPhase()(ipos5) = sSplineKnotsPhase(coeff);
     774             :             };
     775             :           };
     776             :         };
     777             :       };
     778             :     };
     779             :   };
     780           0 :   return retval;
     781             : };
     782             : 
     783             : //----------------------------------------------------------------------------
     784             : 
     785           0 : Vector<Int>& TJonesSplineMBuf::nKnotsAmp()
     786             : {
     787             : // N_KNOTS_AMP data field accessor
     788             : // Input from private data:
     789             : //    nKnotsAmp_p          Vector<Int>       No. of amp. spline knots
     790             : //    nKnotsAmpOK_p        Bool              No. amp. spline knots cache ok
     791             : //
     792             :   // Fill local cache for this column if cache not valid
     793           0 :   if (connectedToIter()) {
     794           0 :     if (!nKnotsAmpOK_p) {
     795           0 :       calMainCol()->nKnotsAmp().getColumn (nKnotsAmp_p);
     796           0 :       nKnotsAmpOK_p = true;
     797             :     };
     798             :   };
     799           0 :   return nKnotsAmp_p;
     800             : };
     801             : 
     802             : //----------------------------------------------------------------------------
     803             : 
     804           0 : Vector<Int>& TJonesSplineMBuf::nKnotsPhase()
     805             : {
     806             : // N_KNOTS_PHASE data field accessor
     807             : // Input from private data:
     808             : //    nKnotsPhase_p          Vector<Int>     No. phase spline knots
     809             : //    nKnotsPhaseOK_p        Bool            No. phase spline knots cache ok
     810             : //
     811             :   // Fill local cache for this column if cache not valid
     812           0 :   if (connectedToIter()) {
     813           0 :     if (!nKnotsPhaseOK_p) {
     814           0 :       calMainCol()->nKnotsPhase().getColumn (nKnotsPhase_p);
     815           0 :       nKnotsPhaseOK_p = true;
     816             :     };
     817             :   };
     818           0 :   return nKnotsPhase_p;
     819             : };
     820             : 
     821             : //----------------------------------------------------------------------------
     822             : 
     823           0 : Array<Double>& TJonesSplineMBuf::splineKnotsAmp()
     824             : {
     825             : // SPLINE_KNOTS_AMP data field accessor
     826             : // Input from private data:
     827             : //    splineKnotsAmp_p      Array<Double>    Amp. spline knot positions
     828             : //    splineKnotsAmpOK_p    Bool             Amp. spline knot posn. cache ok
     829             : //
     830             :   // Fill local cache for this column if cache not valid
     831           0 :   if (connectedToIter()) {
     832           0 :     if (!splineKnotsAmpOK_p) {
     833           0 :       calMainCol()->splineKnotsAmp().getColumn (splineKnotsAmp_p);
     834           0 :       splineKnotsAmpOK_p = true;
     835             :     };
     836             :   };
     837           0 :   return splineKnotsAmp_p;
     838             : };
     839             : 
     840             : //----------------------------------------------------------------------------
     841             : 
     842           0 : Array<Double>& TJonesSplineMBuf::splineKnotsPhase()
     843             : {
     844             : // SPLINE_KNOTS_PHASE data field accessor
     845             : // Input from private data:
     846             : //    splineKnotsPhase_p      Array<Double>   Phase spline knot positions
     847             : //    splineKnotsPhaseOK_p    Bool            Phase spline knot posn. cache ok
     848             : //
     849             :   // Fill local cache for this column if cache not valid
     850           0 :   if (connectedToIter()) {
     851           0 :     if (!splineKnotsPhaseOK_p) {
     852           0 :       calMainCol()->splineKnotsPhase().getColumn (splineKnotsPhase_p);
     853           0 :       splineKnotsPhaseOK_p = true;
     854             :     };
     855             :   };
     856           0 :   return splineKnotsPhase_p;
     857             : };
     858             : 
     859             : //----------------------------------------------------------------------------
     860             : 
     861           0 :   void TJonesSplineMBuf::fillAttributes (const Vector<Int>& /*calIndices*/)
     862             : {
     863             : // Resize all TJonesSpline attribute columns and set to their default values
     864             : // Input:
     865             : //    calIndices         const Vector<Int>&   Vector of cal indices, specified
     866             : //                                            as enums from class MSCalEnums,
     867             : //                                            to exclude
     868             : // Output to private data:
     869             : //    nKnotsAmp_p           Vector<Int>       No. of amplitude spline knots
     870             : //    nKnotsPhase_p         Vector<Int>       No. of phase spline knots
     871             : //    splineKnotsAmp_p      Array<Double>     Amp. spline knot positions
     872             : //    splineKnotsPhase_p    Array<Double>     Phase spline knot positions
     873             : //
     874             :   // Process each TJonesSpline cal buffer column separately
     875             :   //
     876             :   // Use the maximum number of rows currently defined in the cal buffer
     877           0 :   uInt nrow = nRow();
     878             : 
     879             :   // N_KNOTS_AMP
     880           0 :   nKnotsAmp().resize(nrow);
     881           0 :   nKnotsAmp() = 0;
     882             : 
     883             :   // N_KNOTS_PHASE
     884           0 :   nKnotsPhase().resize(nrow);
     885           0 :   nKnotsPhase() = 0;
     886             : 
     887             :   // Array-based columns SPLINE_KNOTS_AMP and SPLINE_KNOTS_PHASE (set 
     888             :   // to default unit length in each dimension)
     889           0 :   uInt numSpw = 1;
     890           0 :   uInt numChan = 1;
     891           0 :   uInt numReceptors = 1;
     892           0 :   uInt numCoeff = 1;
     893           0 :   IPosition knotSize(5, numReceptors, numSpw, numChan, numCoeff, nrow);
     894             : 
     895           0 :   splineKnotsAmp().resize(knotSize);
     896           0 :   splineKnotsAmp() = 0;
     897           0 :   splineKnotsPhase().resize(knotSize);
     898           0 :   splineKnotsPhase() = 0;
     899             : 
     900           0 :   return;
     901             : };
     902             : 
     903             : //----------------------------------------------------------------------------
     904             : 
     905             : 
     906             : } //# NAMESPACE CASA - END
     907             : 

Generated by: LCOV version 1.16