LCOV - code coverage report
Current view: top level - mstransform/TVI - FreqAxisTVI.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 84 0.0 %
Date: 2024-10-04 16:51:10 Functions: 0 15 0.0 %

          Line data    Source code
       1             : //# FreqAxisTVI.h: This file contains the implementation of the FreqAxisTVI class.
       2             : //#
       3             : //#  CASA - Common Astronomy Software Applications (http://casa.nrao.edu/)
       4             : //#  Copyright (C) Associated Universities, Inc. Washington DC, USA 2011, All rights reserved.
       5             : //#  Copyright (C) European Southern Observatory, 2011, All rights reserved.
       6             : //#
       7             : //#  This library is free software; you can redistribute it and/or
       8             : //#  modify it under the terms of the GNU Lesser General Public
       9             : //#  License as published by the Free software Foundation; either
      10             : //#  version 2.1 of the License, or (at your option) any later version.
      11             : //#
      12             : //#  This library is distributed in the hope that it will be useful,
      13             : //#  but WITHOUT ANY WARRANTY, without even the implied warranty of
      14             : //#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             : //#  Lesser General Public License for more details.
      16             : //#
      17             : //#  You should have received a copy of the GNU Lesser General Public
      18             : //#  License along with this library; if not, write to the Free Software
      19             : //#  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      20             : //#  MA 02111-1307  USA
      21             : //# $Id: $
      22             : 
      23             : #include <mstransform/TVI/FreqAxisTVI.h>
      24             : 
      25             : using namespace casacore;
      26             : namespace casa { //# NAMESPACE CASA - BEGIN
      27             : 
      28             : namespace vi { //# NAMESPACE VI - BEGIN
      29             : 
      30             : //////////////////////////////////////////////////////////////////////////
      31             : // FreqAxisTVI class
      32             : //////////////////////////////////////////////////////////////////////////
      33             : 
      34             : // -----------------------------------------------------------------------
      35             : //
      36             : // -----------------------------------------------------------------------
      37           0 : FreqAxisTVI::FreqAxisTVI(       ViImplementation2 * inputVii) :
      38           0 :                                                         TransformingVi2 (inputVii)
      39             : {
      40           0 :         initialize();
      41             : 
      42             :         // Initialize attached VisBuffer
      43           0 :         setVisBuffer(createAttachedVisBuffer (VbRekeyable));
      44             : 
      45           0 :         return;
      46           0 : }
      47             : 
      48             : // -----------------------------------------------------------------------
      49             : //
      50             : // -----------------------------------------------------------------------
      51           0 : FreqAxisTVI::~FreqAxisTVI()
      52             : {
      53             :         // The parent class destructor (~TransformingVi2) deletes the inner
      54             :         // ViImplementation2 object. However if it might have been already
      55             :         // deleted at the top level context
      56             :         // 2/8/2016 (jagonzal): As per request from George M. (via CAS-8220)
      57             :         // I allow TransformingVi2 destructor to delete its inner input VI;
      58             :         // This relies on the application layer that produces the inner VI not
      59             :         // deleting it which can be guaranteed when using the Factory pattern.
      60             :         // inputVii_p = NULL;
      61             : 
      62           0 :         return;
      63           0 : }
      64             : 
      65             : 
      66             : // -----------------------------------------------------------------------
      67             : //
      68             : // -----------------------------------------------------------------------
      69           0 : void FreqAxisTVI::initialize()
      70             : {
      71             : 
      72           0 :     if (inputVii_p == nullptr)
      73           0 :         return;
      74             : 
      75             :     //Create a map with the input SPWs and their channels.
      76             :     //Note that this access directly the information provided by the previous
      77             :     //layer and it is no longer based on the original MS selection, which
      78             :     //for this particular layer might not make any sense (see CAS-9679).
      79           0 :     formChanMap();
      80           0 :     return;
      81             : }
      82             : 
      83             : // -----------------------------------------------------------------------
      84             : //
      85             : // -----------------------------------------------------------------------
      86           0 : void FreqAxisTVI::formChanMap()
      87             : {
      88             :     // This triggers realization of the channel selection
      89           0 :     inputVii_p->originChunks();
      90             : 
      91             :     // Refresh map
      92           0 :     spwInpChanIdxMap_p.clear();
      93             : 
      94           0 :     for (Int ispw = 0; ispw < inputVii_p->nSpectralWindows(); ++ispw)
      95             :     {
      96             :         // TBD trap unselected spws with a continue
      97             : 
      98           0 :         Vector<Int> chansV;
      99           0 :         chansV.reference(inputVii_p->getChannels(0.0, -1, ispw, 0));
     100             : 
     101           0 :         Int nChan = chansV.nelements();
     102           0 :         if (nChan > 0)
     103             :         {
     104           0 :             spwInpChanIdxMap_p[ispw].clear(); // creates ispw's map
     105           0 :             for (Int ich = 0; ich < nChan; ++ich)
     106             :             {
     107           0 :                 spwInpChanIdxMap_p[ispw].push_back(chansV[ich]); // accum into map
     108             :             }
     109             :         }
     110           0 :     } // ispw
     111             : 
     112           0 :     return;
     113             : }
     114             : 
     115             : // -----------------------------------------------------------------------
     116             : //
     117             : // -----------------------------------------------------------------------
     118           0 : void FreqAxisTVI::origin()
     119             : {
     120             :     // Drive underlying ViImplementation2
     121           0 :     getVii()->origin();
     122             : 
     123           0 :     configureShapes();
     124             : 
     125             :     // Synchronize own VisBuffer
     126           0 :     configureNewSubchunk();
     127             : 
     128           0 :     return;
     129             : }
     130             : 
     131             : // -----------------------------------------------------------------------
     132             : //
     133             : // -----------------------------------------------------------------------
     134           0 : void FreqAxisTVI::next()
     135             : {
     136             :     // Drive underlying ViImplementation2
     137           0 :     getVii()->next();
     138             : 
     139           0 :     configureShapes();
     140             : 
     141             :     // Synchronize own VisBuffer
     142           0 :     configureNewSubchunk();
     143             : 
     144           0 :     return;
     145             : }
     146             : 
     147           0 : void FreqAxisTVI::configureShapes()
     148             : {
     149           0 :     Vector<Int> spws;
     150           0 :     spectralWindows(spws);
     151           0 :     Vector<Int> channels = getChannels (0, 0, spws (0) , msId());
     152           0 :     nChannPerShape_ = casacore::Vector<casacore::Int> (1, channels.nelements());
     153           0 : }
     154             : 
     155             : // -----------------------------------------------------------------------
     156             : //
     157             : // -----------------------------------------------------------------------
     158           0 : Bool FreqAxisTVI::existsColumn (VisBufferComponent2 id) const
     159             : {
     160             : 
     161             :         Bool ret;
     162           0 :         switch (id)
     163             :         {
     164           0 :                 case VisBufferComponent2::WeightSpectrum:
     165             :                 {
     166           0 :                         ret = true;
     167           0 :                         break;
     168             :                 }
     169           0 :                 case VisBufferComponent2::SigmaSpectrum:
     170             :                 {
     171           0 :                         ret = true;
     172           0 :                         break;
     173             :                 }
     174           0 :                 default:
     175             :                 {
     176           0 :                         ret = getVii()->existsColumn(id);
     177           0 :                         break;
     178             :                 }
     179             :         }
     180             : 
     181           0 :         return ret;
     182             : }
     183             : 
     184             : // -----------------------------------------------------------------------
     185             : //
     186             : // -----------------------------------------------------------------------
     187           0 : Vector<Int> FreqAxisTVI::getChannels (Double,Int,Int spectralWindowId,Int) const
     188             : {
     189           0 :         Vector<Int> ret(spwOutChanNumMap_p[spectralWindowId]);
     190             : 
     191           0 :         for (uInt chanIdx = 0; chanIdx<spwOutChanNumMap_p[spectralWindowId];chanIdx++)
     192             :         {
     193           0 :                 ret(chanIdx) = chanIdx;
     194             :         }
     195             : 
     196           0 :         return ret;
     197           0 : }
     198             : 
     199             : const casacore::Vector<casacore::Int>&
     200           0 : FreqAxisTVI::nChannelsPerShape () const
     201             : {
     202           0 :     return nChannPerShape_;
     203             : }
     204             : 
     205             : 
     206             : // -----------------------------------------------------------------------
     207             : //
     208             : // -----------------------------------------------------------------------
     209           0 : void FreqAxisTVI::writeFlagRow (const Vector<Bool> & flag)
     210             : {
     211           0 :         getVii()->writeFlagRow(flag);
     212           0 : }
     213             : 
     214             : // -----------------------------------------------------------------------
     215             : //
     216             : // -----------------------------------------------------------------------
     217           0 : void FreqAxisTVI::flagRow (Vector<Bool> & flagRow) const
     218             : {
     219             :         // Get flagCube from own VisBuffer
     220           0 :         const Cube<Bool> &flagCube = getVisBuffer()->flagCube();
     221             : 
     222             :         // Calculate output flagRow
     223           0 :         accumulateFlagCube(flagCube,flagRow);
     224           0 : }
     225             : 
     226             : // -----------------------------------------------------------------------
     227             : //
     228             : // -----------------------------------------------------------------------
     229           0 : void FreqAxisTVI::weight (Matrix<Float> & weight) const
     230             : {
     231           0 :         if (weightSpectrumExists()) // Defined by each derived class or inner TVI
     232             :         {
     233             :                 // Get flags and weightSpectrum from own VisBuffer
     234           0 :                 const Cube<Bool> &flags = getVisBuffer()->flagCube();
     235           0 :                 const Cube<Float> &weightSpectrum = getVisBuffer()->weightSpectrum();
     236             : 
     237             :                 // Calculate output weight
     238           0 :                 accumulateWeightCube(weightSpectrum,flags,weight);
     239             :         }
     240             :         else
     241             :         {
     242           0 :                 getVii()->weight (weight);
     243             :         }
     244             : 
     245           0 :         return;
     246             : }
     247             : 
     248             : // -----------------------------------------------------------------------
     249             : //
     250             : // -----------------------------------------------------------------------
     251           0 : void FreqAxisTVI::sigma (Matrix<Float> & sigma) const
     252             : {
     253           0 :         if (sigmaSpectrumExists())
     254             :         {
     255             :                 // Get flags and sigmaSpectrum from own VisBuffer
     256           0 :                 const Cube<Bool> &flags = getVisBuffer()->flagCube();
     257           0 :                 const Cube<Float> &sigmaSpectrum = getVisBuffer()->sigmaSpectrum();
     258             : 
     259             :                 // Calculate output sigma
     260           0 :                 accumulateWeightCube(sigmaSpectrum,flags,sigma);
     261             :         }
     262             :         else
     263             :         {
     264           0 :                 getVii()->sigma (sigma);
     265             :         }
     266             : 
     267           0 :         return;
     268             : }
     269             : 
     270             : } //# NAMESPACE VI - END
     271             : 
     272             : } //# NAMESPACE CASA - END
     273             : 
     274             : 

Generated by: LCOV version 1.16