LCOV - code coverage report
Current view: top level - synthesis/MeasurementComponents - PredictAlgorithm.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 6 77 7.8 %
Date: 2024-11-06 17:42:47 Functions: 4 9 44.4 %

          Line data    Source code
       1             : //# PredictAlgorithm.cc:  class providing for parallelized predict methods
       2             : //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002
       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: casa-feedback@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             : #include <casacore/casa/Utilities/Assert.h>
      29             : #include <msvis/MSVis/VisSet.h>
      30             : #include <msvis/MSVis/VisSetUtil.h>
      31             : #include <msvis/MSVis/VisibilityIterator.h>
      32             : #include <msvis/MSVis/VisBuffer.h>
      33             : #include <casacore/casa/Arrays/ArrayMath.h>
      34             : #include <casacore/casa/Arrays/MatrixMath.h>
      35             : #include <casacore/casa/Logging/LogMessage.h>
      36             : #include <casacore/casa/Logging/LogIO.h>
      37             : #include <casacore/casa/Logging/LogSink.h>
      38             : #include <casacore/ms/MeasurementSets/MeasurementSet.h>
      39             : #include <casacore/ms/MeasurementSets/MSColumns.h>
      40             : #include <synthesis/MeasurementComponents/PredictAlgorithm.h>
      41             : #include <casacore/casa/OS/Time.h>
      42             : #include <casacore/images/Images/ImageInterface.h>
      43             : #include <casacore/images/Images/PagedImage.h>
      44             : #include <casacore/images/Images/TempImage.h>
      45             : #include <synthesis/TransformMachines/StokesImageUtil.h>
      46             : #include <casacore/casa/System/ProgressMeter.h>
      47             : #include <synthesis/Parallel/Applicator.h>
      48             : #include <unistd.h>
      49             : #include <casacore/lattices/LRegions/LCBox.h>
      50             : #include <casacore/lattices/Lattices/SubLattice.h>   
      51             : #include <casacore/lattices/Lattices/TiledShape.h>  
      52             : 
      53             : using namespace casacore;
      54             : namespace casa { //# NAMESPACE CASA - BEGIN
      55             : 
      56             : extern Applicator applicator;
      57             : 
      58           1 : PredictAlgorithm::PredictAlgorithm() : myName_p("PredictAlgorithm")
      59             : {
      60           1 : };
      61             : 
      62           2 : PredictAlgorithm::~PredictAlgorithm()
      63             : {
      64           2 : };
      65             : 
      66           0 : void PredictAlgorithm::get(){
      67             : 
      68             :   // Receive data from the controller process
      69             :   
      70           0 :   applicator.get(model_p);
      71           0 :   applicator.get(msName_p);
      72           0 :   applicator.get(incremental_p);
      73             :  
      74             :   // Receiving image parameters 
      75           0 :   Record container_image;
      76           0 :   String errorString;
      77           0 :   applicator.get(container_image);
      78           0 :   cImage_p= new TempImage<Complex>();
      79           0 :   cImage_p->fromRecord(errorString, container_image);
      80             : 
      81             :   // Receiving and making FT machine 
      82           0 :   Record container_ft;
      83           0 :   applicator.get(container_ft);
      84           0 :   ft_p=new GridFT(container_ft);
      85           0 : };
      86             : 
      87           0 : void PredictAlgorithm::put(){
      88             : 
      89             :   // Send data back to the controller process
      90           0 :   applicator.put(model_p);
      91             : 
      92             :   // Sending FT machine parameters
      93           0 :   String errorString;
      94           0 :   Record container_ft;
      95           0 :   ft_p->toRecord(errorString, container_ft);
      96           0 :   applicator.put(container_ft);
      97           0 :   delete ft_p;
      98           0 :   delete cImage_p;
      99             : 
     100           0 : };
     101             : 
     102           1 : String& PredictAlgorithm::name(){
     103             : 
     104             :   // Return the algorithm name
     105           1 :   return myName_p;
     106             : 
     107             : };
     108             : 
     109           0 : void PredictAlgorithm::task(){
     110             :   
     111             :   // Predict the model visibilities in parallel
     112           0 :   ms_p= new MeasurementSet(msName_p, TableLock(TableLock::UserNoReadLocking),
     113           0 :                            Table::Update);
     114             :         
     115           0 :   Block<Int> sort(0);
     116           0 :   Matrix<Int> noselection;
     117           0 :   noselection=MeasurementSet::ANTENNA1;
     118           0 :   Double interval=0; 
     119           0 :   ms_p->unlock(); 
     120             : 
     121             :   // Construct the VisibilityIterator
     122           0 :   VisSet vs(*ms_p, sort, noselection, interval);
     123           0 :   VisIter& vi(vs.iter());
     124             :   // Row blocking defines the memory used
     125           0 :   vi.setRowBlocking(200000); 
     126           0 :   VisBuffer vb(vi);
     127             :       
     128             :   // Change the model polarization frame
     129           0 :   if(vb.polFrame()==MSIter::Linear) {
     130           0 :     StokesImageUtil::changeCStokesRep(*cImage_p,
     131             :                                       StokesImageUtil::LINEAR);
     132             :   }
     133             :   else {
     134           0 :     StokesImageUtil::changeCStokesRep(*cImage_p,
     135             :                                       StokesImageUtil::CIRCULAR);
     136             :   }
     137             :       
     138             : 
     139             :   // Initialize get (i.e. Transform from Sky)
     140           0 :   vi.originChunks();
     141           0 :   vi.origin();      
     142           0 :   initializeGet(vi, 0, model_p, incremental_p);
     143             : 
     144             : 
     145           0 :   Int chunkNo=0;
     146           0 :   Int intraChunk=0;
     147             :   // Iterate through the visibility data
     148             : 
     149           0 :   for (vi.originChunks();vi.moreChunks();vi.nextChunk()) {
     150           0 :     chunkNo++;
     151           0 :     for (vi.origin(); vi.more(); vi++) {  
     152           0 :       intraChunk++;     
     153           0 :       if(!incremental_p && model_p==0){ 
     154           0 :         vb.setModelVisCube(Complex(0.0,0.0));
     155           0 :         ms_p->lock();
     156           0 :         vi.setVis(vb.modelVisCube(),VisibilityIterator::Model);
     157           0 :         ms_p->unlock();
     158             :       }
     159           0 :       getModelVis(vb,model_p,incremental_p);
     160             :         
     161           0 :       vi.setVis(vb.modelVisCube(),VisibilityIterator::Model);
     162           0 :       ms_p->flush(true);
     163           0 :       ms_p->unlock(); // this is the unlock for the lock in getModelVis
     164             : 
     165             :     }
     166             :         
     167             :   }
     168             :       
     169           0 :   ms_p->unlock();
     170           0 :   delete ms_p; 
     171             : 
     172           0 : };
     173             : 
     174           0 : void PredictAlgorithm::initializeGet(const VisBuffer& vb, Int /*row*/, Int /*model*/,
     175             :                                      Bool /*incremental*/) {
     176             : 
     177             :   // Need to add support for varying SkyJones
     178           0 :   ft_p->initializeToVis(*cImage_p, vb);
     179           0 : }
     180             : 
     181           0 : VisBuffer& PredictAlgorithm::getModelVis(VisBuffer& result, Int /*model*/,
     182             :                                          Bool /*incremental*/) {
     183             :   
     184             :   // Need to add support for varying SkyJones
     185             : 
     186             :   //UNUSED: Int nRow=result.nRow();
     187           0 :   result.modelVisCube(); // get the visibility so vb will have it
     188           0 :   VisBuffer vb(result);
     189             : 
     190           0 :   ft_p->get(vb);
     191           0 :   ms_p->lock(FileLocker::Write);
     192           0 :   result.invalidate();// reget it in case it has changed in the mean time
     193             :   // important as other processors might have changed the values
     194           0 :   result.modelVisCube();
     195           0 :   result.modelVisCube()+=vb.modelVisCube();   
     196           0 :   return result;
     197           0 : }
     198             : 
     199             : 
     200             : 
     201             : 
     202             : 
     203             : 
     204             : 
     205             : 
     206             : 
     207             : } //# NAMESPACE CASA - END
     208             : 

Generated by: LCOV version 1.16