LCOV - code coverage report
Current view: top level - mstransform/TVI - SPWCombinationTVI.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 35 0.0 %
Date: 2024-10-10 15:00:01 Functions: 0 5 0.0 %

          Line data    Source code
       1             : //# SPWCombinationTVI.h: This file contains the interface definition of the MSTransformManager 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             : #ifndef SPWCombinationTVI_H_
      24             : #define SPWCombinationTVI_H_
      25             : 
      26             : // Base class
      27             : #include <mstransform/TVI/FreqAxisTVI.h>
      28             : #include <msvis/MSVis/VisibilityIterator2.h>
      29             : 
      30             : 
      31             : namespace casa { //# NAMESPACE CASA - BEGIN
      32             : 
      33             : namespace vi { //# NAMESPACE VI - BEGIN
      34             : 
      35             : //////////////////////////////////////////////////////////////////////////
      36             : // SPWCombinationTVI class
      37             : //////////////////////////////////////////////////////////////////////////
      38             : 
      39             : class SPWCombinationTVI : public FreqAxisTVI
      40             : {
      41             : 
      42             : public:
      43             : 
      44             :     // Constructor
      45             :     SPWCombinationTVI(ViImplementation2 * inputVii);
      46             : 
      47             :     // Report the the ViImplementation type
      48           0 :     virtual casacore::String ViiType() const override { return casacore::String("SPWCombination( ")+getVii()->ViiType()+" )"; };
      49             : 
      50             :     void origin() override;
      51             : 
      52             :     void next() override;
      53             : 
      54             :     // Structural changes
      55             :     casacore::rownr_t nShapes() const override;
      56             :     const casacore::Vector<casacore::rownr_t>& nRowsPerShape() const override;
      57             :     const casacore::Vector<casacore::Int>& nChannelsPerShape() const override;
      58             :     void spectralWindows(casacore::Vector<casacore::Int>& spws) const override;
      59             :     casacore::Vector<double> getFrequencies(double time, casacore::Int frameOfReference,
      60             :                                             casacore::Int spectralWindowId,
      61             :                                             casacore::Int msId) const override;
      62             : 
      63             :     // Transformation of the flags
      64             :     void flag(casacore::Cube<casacore::Bool>& flagCube) const override;
      65             :     void flag(casacore::Vector<casacore::Cube<casacore::Bool>>& flagCubes) const override;
      66             : 
      67             :     // Transformation of float data
      68             :     void floatData(casacore::Cube<casacore::Float> & vis) const override;
      69             :     void floatData(casacore::Vector<casacore::Cube<casacore::Float>> & vis) const override;
      70             : 
      71             :     // Transformation of observed visibilities
      72             :     void visibilityObserved(casacore::Cube<casacore::Complex> & vis) const override;
      73             :     void visibilityObserved(casacore::Vector<casacore::Cube<casacore::Complex>> & vis) const override;
      74             : 
      75             :     // Transformation of corrected visibilities
      76             :     void visibilityCorrected(casacore::Cube<casacore::Complex> & vis) const override;
      77             :     void visibilityCorrected(casacore::Vector<casacore::Cube<casacore::Complex>> & vis) const override;
      78             : 
      79             :     // Transformation of model
      80             :     void visibilityModel(casacore::Cube<casacore::Complex> & vis) const override;
      81             :     void visibilityModel(casacore::Vector<casacore::Cube<casacore::Complex>> & vis) const override;
      82             : 
      83             :     // Transformation of weight 
      84             :     void weight(casacore::Matrix<casacore::Float> &weight) const override;
      85             :     void weight(casacore::Vector<casacore::Matrix<casacore::Float>> &weight) const override;
      86             :     void weightSpectrum(casacore::Cube<casacore::Float> &weightSp) const override;
      87             :     void weightSpectrum(casacore::Vector<casacore::Cube<casacore::Float>> &weightSp) const override;
      88             : 
      89             :     // Transformation of sigma
      90             :     void sigma(casacore::Matrix<casacore::Float> &sigma) const override;
      91             :     void sigma(casacore::Vector<casacore::Matrix<casacore::Float>> &sigma) const override;
      92             :     void sigmaSpectrum(casacore::Cube<casacore::Float> &sigmaSp) const override;
      93             :     void sigmaSpectrum(casacore::Vector<casacore::Cube<casacore::Float>> &sigmaSp) const override;
      94             : 
      95             :     // Transformation of several scalar quantities
      96             :     void antenna1(casacore::Vector<casacore::Int> & ant1) const override;
      97             :     void antenna2(casacore::Vector<casacore::Int> & ant2) const override;
      98             :     void arrayIds (casacore::Vector<casacore::Int>& arrayIds) const override;
      99             :     void exposure(casacore::Vector<double> & exp) const override;
     100             :     void feed1 (casacore::Vector<casacore::Int> & fd1) const override;
     101             :     void feed2 (casacore::Vector<casacore::Int> & fd2) const override;
     102             :     void fieldIds (casacore::Vector<casacore::Int>& fieldId) const override;
     103             :     void observationId (casacore::Vector<casacore::Int> & obsids) const override;
     104             :     void processorId (casacore::Vector<casacore::Int> & procids) const override;
     105             :     void stateId (casacore::Vector<casacore::Int> & stateids) const override;
     106             :     void time(casacore::Vector<double> & t) const override;
     107             :     void timeCentroid(casacore::Vector<double> & t) const override;
     108             :     void timeInterval(casacore::Vector<double> & t) const override;
     109             : 
     110             : protected:
     111             : 
     112             :     void initialize();
     113             : 
     114             :     void setUpCurrentSubchunkStructure();
     115             : 
     116             :     double checkEqualWidth() const;
     117             : 
     118             :     double getChannelNominalFreq(size_t spw, size_t channel) const;
     119             : 
     120             :     double freqWidthChan_p;
     121             : 
     122             :     std::map<int, double> spwOutFirstFreq_p;
     123             : 
     124             :     // Variables that depend on the subchunk we are in
     125             :     casacore::Vector<casacore::rownr_t> nRowsPerShape_p;
     126             : 
     127             :     casacore::Vector<casacore::Int> nChannelsPerShape_p;
     128             : 
     129             :     casacore::Vector<casacore::Int> currentSubchunkSpwIds_p;
     130             : 
     131             :     casacore::Vector<casacore::Int> currentSubchunkInnerPolIds_p;
     132             : 
     133             :     casacore::Vector<casacore::Int> currentSubchunkInnerSpwIds_p;
     134             : 
     135             :     // map[outSpwStartIdx_p... outSpwStartIdx_p+nSpW] map[key:inpSpwId] vector-> inp chann idx, same as spwInpChanIdxMap, value: outputChannel
     136             :     std::map<int, std::map<int, std::vector<int>>> spwInpChanOutMap_p;
     137             :     // map[outSpwStartIdx_p... outSpwStartIdx_p+nSpW] map[key:inpSpwId] vector-> inp chann idx, same as spwInpChanIdxMap, value: outputChannel freq
     138             :     std::map<int, std::map<int, std::vector<double>>> spwInpChanOutFreqMap_p;
     139             :     // Start of te output SPW indexes.
     140             :     // This assumes that there is no reindexing performed by this TVI, i.e., the output
     141             :     // SPW is added to the list of input SPWs. With reindexing this would have been 0.
     142             :     casacore::Int outSpwStartIdx_p;
     143             : 
     144             :     template <class T>
     145           0 :     void transformCubesVector(const casacore::Vector<casacore::Cube<T>> & inCubesVector,
     146             :                               casacore::Vector<casacore::Cube<T>> & outCubesVector) const
     147             :     {
     148             :         // Resize cube vector
     149           0 :         outCubesVector.resize(nShapes());
     150             : 
     151           0 :         size_t iShape = 0;
     152             :         // It is assumed that the VisBuffer contains unique metadata and timestamp except for DDId.
     153             :         // See checkSortingInner().
     154           0 :         for(auto& outCube : outCubesVector)
     155             :         {
     156           0 :             casacore::IPosition cubeShape(3, nCorrelationsPerShape()[iShape],
     157             :                                 nChannelsPerShape_p[iShape], nRowsPerShape_p[iShape]);
     158           0 :             outCube.resize(cubeShape);
     159           0 :             ++iShape;
     160             :         }
     161           0 :         casacore::rownr_t inputRowsProcessed = 0;
     162           0 :         for(auto& inputCube : inCubesVector)
     163             :         {
     164             :             // It is assumed that each input cube corresponds to
     165             :             // an unique DDiD.
     166             :             // The case in which several DDiDs which have the same
     167             :             // number of channels and polarizations have been merged in a single
     168             :             // cube with equal shape is not supported yet.
     169             :             // By construction of the rest of VB2 (VisibilityIteratorImpl2,
     170             :             // SimpleSimVI2, rest of TVIs) this doesn't happen yet anyway.
     171           0 :             casacore::Int thisCubePolId = currentSubchunkInnerPolIds_p[inputRowsProcessed];
     172           0 :             auto thisSpw = currentSubchunkInnerSpwIds_p[inputRowsProcessed];
     173           0 :             auto thisOutputSpw = thisCubePolId + outSpwStartIdx_p;
     174             : 
     175           0 :             auto outputChannel = spwInpChanOutMap_p.at(thisOutputSpw).at(thisSpw)[0];
     176           0 :             casacore::IPosition blcOutput(3, 0, outputChannel, 0);
     177           0 :             casacore::IPosition trcOutput(3, inputCube.shape()(0)-1, outputChannel + inputCube.shape()(1)-1, inputCube.shape()(2)-1);
     178           0 :             outCubesVector[thisCubePolId](blcOutput, trcOutput) = inputCube;
     179           0 :             inputRowsProcessed+=inputCube.shape()(2);
     180             :         }
     181           0 :     }
     182             : 
     183             :     template <class T>
     184           0 :     void transformMatricesVector(const casacore::Vector<casacore::Matrix<T>> & inMatricesVector,
     185             :                                  casacore::Vector<casacore::Matrix<T>> & outMatricesVector) const
     186             :     {
     187             :         // Resize cube vector
     188           0 :         outMatricesVector.resize(nShapes());
     189             : 
     190           0 :         size_t iShape = 0;
     191             :         // It is assumed that the VisBuffer contains unique metadata and timestamp except for DDId.
     192             :         // See checkSortingInner().
     193           0 :         for(auto& outMat : outMatricesVector)
     194             :         {
     195           0 :             casacore::IPosition matShape(2, nCorrelationsPerShape()[iShape],
     196             :                                 nRowsPerShape_p[iShape]);
     197           0 :             outMat.resize(matShape);
     198           0 :             outMat = 0;
     199           0 :             ++iShape;
     200             :         }
     201           0 :         casacore::rownr_t inputRowsProcessed = 0;
     202           0 :         for(auto& inputMat : inMatricesVector)
     203             :         {
     204             :             // It is assumed that each input cube corresponds to
     205             :             // an unique DDiD.
     206             :             // The case in which several DDiDs which have the same
     207             :             // number of channels and polarizations have been merged in a single
     208             :             // cube with equal shape is not supported yet.
     209             :             // By construction of the rest of VB2 (VisibilityIteratorImpl2,
     210             :             // SimpleSimVI2, rest of TVIs) this doesn't happen yet anyway.
     211           0 :             casacore::Int thisMatrixPolId = currentSubchunkInnerPolIds_p[inputRowsProcessed];
     212             : 
     213           0 :             casacore::IPosition blcOutput(2, 0, 0);
     214           0 :             casacore::IPosition trcOutput(2, inputMat.shape()(0)-1, inputMat.shape()(1)-1);
     215           0 :             outMatricesVector[thisMatrixPolId](blcOutput, trcOutput) = inputMat;
     216           0 :             inputRowsProcessed+=inputMat.shape()(1);
     217             :         }
     218           0 :     }
     219             : 
     220             : };
     221             : 
     222             : /*
     223             :  * Factory that allows the creation of SPWCombinationTVI classes.
     224             :  * This factory doesn't have any parameter to configure
     225             :  */
     226             : class SPWCombinationTVIFactory : public ViFactory
     227             : {
     228             : 
     229             : public:
     230             : 
     231             :     SPWCombinationTVIFactory(ViImplementation2 *inputVII);
     232             : 
     233             :     ~SPWCombinationTVIFactory();
     234             : 
     235             : protected:
     236             : 
     237             :     virtual vi::ViImplementation2 * createVi () const;
     238             : 
     239             : private:
     240             : 
     241             :     ViImplementation2 *inputVii_p;;
     242             : };
     243             : 
     244             : /*
     245             :  * Factory that allows the creation of SPWCombinationTVI classes
     246             :  * which act upon an underlying VI2
     247             :  * This factory doesn't have any parameter to configure
     248             :  */
     249             : class SPWCombinationTVILayerFactory : public ViiLayerFactory
     250             : {
     251             : 
     252             : public:
     253             : 
     254             :     SPWCombinationTVILayerFactory();
     255             : 
     256             :     virtual ~SPWCombinationTVILayerFactory();
     257             : 
     258             : protected:
     259             :   
     260             :     virtual ViImplementation2 * createInstance(ViImplementation2* vii0) const;
     261             : };
     262             : 
     263             : 
     264             : } //# NAMESPACE VI - END
     265             : 
     266             : } //# NAMESPACE CASA - END
     267             : 
     268             : #endif /* SPWCombinationTVI_H_ */

Generated by: LCOV version 1.16