LCOV - code coverage report
Current view: top level - synthesis/TransformMachines - NewMultiTermFT.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 25 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 15 0.0 %

          Line data    Source code
       1             : //# NewMultiTermFT.h: Definition for NewMultiTermFT
       2             : //# Copyright (C) 1996,1997,1998,1999,2000,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 adressed 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             : //#
      27             : //# $Id$
      28             : 
      29             : #ifndef SYNTHESIS_NEWMULTITERMFT_H
      30             : #define SYNTHESIS_NEWMULTITERMFT_H
      31             : 
      32             : #include <synthesis/TransformMachines/FTMachine.h>
      33             : #include <casacore/casa/Arrays/Matrix.h>
      34             : #include <casacore/scimath/Mathematics/FFTServer.h>
      35             : #include <msvis/MSVis/VisBuffer.h>
      36             : #include <casacore/images/Images/ImageInterface.h>
      37             : #include <casacore/images/Images/ImageInterface.h>
      38             : #include <casacore/casa/Containers/Block.h>
      39             : #include <casacore/casa/Arrays/Array.h>
      40             : #include <casacore/casa/Arrays/Vector.h>
      41             : #include <casacore/casa/Arrays/Matrix.h>
      42             : #include <casacore/scimath/Mathematics/ConvolveGridder.h>
      43             : #include <casacore/lattices/Lattices/LatticeCache.h>
      44             : #include <casacore/lattices/Lattices/ArrayLattice.h>
      45             : //#include <synthesis/MeasurementComponents/SynthesisPeek.h>
      46             : #include <casacore/casa/OS/Timer.h>
      47             : 
      48             : namespace casacore{
      49             : 
      50             : class UVWMachine;
      51             : }
      52             : 
      53             : namespace casa { //# NAMESPACE CASA - BEGIN
      54             : 
      55             : 
      56             : class NewMultiTermFT : public FTMachine {
      57             : public:
      58             : 
      59             :   // Construct using an existing FT-Machine 
      60             :   NewMultiTermFT(FTMachine *subftm, casacore::Int nterms=1, casacore::Double reffreq=0.0);
      61             : 
      62             :   // Construct from a casacore::Record containing the NewMultiTermFT state
      63             :   NewMultiTermFT(const casacore::RecordInterface& stateRec);
      64             : 
      65             :   // Copy constructor. 
      66             :   // This first calls the default "=" operator, and then instantiates objects for member pointers.
      67             :   NewMultiTermFT(const NewMultiTermFT &other);
      68             : 
      69             :   // Assignment operator --- leave it as the default
      70             :   NewMultiTermFT &operator=(const NewMultiTermFT &other);
      71             : 
      72             :   // Destructor
      73             :   ~NewMultiTermFT();
      74             : 
      75             :   // Called at the start of de-gridding : subftm->initializeToVis()
      76             :   // Note : Pre-de-gridding model-image divisions by PBs will go here.
      77           0 :   void initializeToVis(casacore::ImageInterface<casacore::Complex>& /*image*/, 
      78             :                        const VisBuffer& /*vb*/)
      79           0 :   {throw(casacore::AipsError("NewMultiTermFT::initializeToVis called without vectors !"));};
      80             : 
      81             :    // Vectorized InitializeToVis
      82             :   void initializeToVis(casacore::Block<casacore::CountedPtr<casacore::ImageInterface<casacore::Complex> > > & compImageVec,casacore::PtrBlock<casacore::SubImage<casacore::Float> *> & modelImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *>& weightImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *>& fluxScaleVec, casacore::Block<casacore::Matrix<casacore::Float> >& weightsVec, const VisBuffer& vb);
      83             : 
      84             :   // Called at the end of de-gridding : subftm->finalizeToVis()
      85             :   void finalizeToVis();
      86             : 
      87             :   // Called at the start of gridding : subftm->initializeToSky()
      88           0 :   void initializeToSky(casacore::ImageInterface<casacore::Complex>& /*image*/,  
      89             :                        casacore::Matrix<casacore::Float>& /*weight*/, const VisBuffer& /*vb*/) 
      90           0 :    {throw(casacore::AipsError("NewMultiTermFT::initializeToSky() called without vectors!"));};
      91             : 
      92             :   void initializeToSky(casacore::Block<casacore::CountedPtr<casacore::ImageInterface<casacore::Complex> > > & compImageVec, casacore::Block<casacore::Matrix<casacore::Float> >& weightsVec, const VisBuffer& vb, const casacore::Bool dopsf);
      93             : 
      94             : 
      95             :   // Called at the end of gridding : subftm->finalizeToSky()
      96           0 :   void finalizeToSky(){throw(casacore::AipsError("NewMultiTermFT::finalizeToSky() called without arguments!"));};
      97             : 
      98             :   void finalizeToSky(casacore::Block<casacore::CountedPtr<casacore::ImageInterface<casacore::Complex> > > & compImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *> & resImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *>& weightImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *>& fluxScaleVec, casacore::Bool dopsf, casacore::Block<casacore::Matrix<casacore::Float> >& weightsVec, const VisBuffer& vb);
      99             : 
     100             :   //  void normalizeToSky(casacore::ImageInterface<casacore::Complex>& compImage, casacore::ImageInterface<casacore::Float>& resImage, casacore::ImageInterface<casacore::Float>& weightImage, casacore::Bool dopsf, casacore::Matrix<casacore::Float>& weights)
     101             :   // {throw(casacore::AipsError("NewMultiTermFT::normalizeToSky should not get called !"));};
     102             : 
     103             : 
     104             :   // Do the degridding via subftm->get() and modify model-visibilities by Taylor-weights
     105             :   void get(VisBuffer& vb, casacore::Int row=-1);
     106             : 
     107             :   // Modify imaging weights with Taylor-weights and do gridding via subftm->put()
     108             :   void put(VisBuffer& vb, casacore::Int row=-1, casacore::Bool dopsf=false,
     109             :            FTMachine::Type type=FTMachine::OBSERVED);
     110             : 
     111             :   // Have a const version for compatibility with other FTMs.. Throw an exception if called.
     112           0 :   void put(const VisBuffer& /*vb*/, casacore::Int /*row*/=-1, casacore::Bool /*dopsf*/=false,
     113             :            FTMachine::Type /*type*/=FTMachine::OBSERVED)
     114           0 :   {throw(casacore::AipsError("NewMultiTermFT::put called with a const vb. This FTM needs to modify the vb."));};
     115             : 
     116             :   // Calculate residual visibilities if possible.
     117             :   // The purpose is to allow rGridFT to make this multi-threaded
     118             :   virtual void ComputeResiduals(VisBuffer&vb, casacore::Bool useCorrected); 
     119             : 
     120             :   // Make an image : subftm->makeImage()
     121             :   void makeImage(FTMachine::Type type,
     122             :                  VisSet& vs,
     123             :                  casacore::ImageInterface<casacore::Complex>& image,
     124             :                  casacore::Matrix<casacore::Float>& weight);
     125             :   
     126             :   // Get the final image: do the Fourier transform grid-correct, then 
     127             :   // optionally normalize by the summed weights
     128             :   // Note : Post-gridding residual-image divisions by PBs will go here.
     129             :   //           For now, it just calls subftm->getImage()
     130             :   //  casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& weights, casacore::Bool normalize=true)
     131             :   //{return getImage(weights,normalize,0);};
     132             :   //casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& weights, casacore::Bool normalize=true, 
     133             :   //                                                         const casacore::Int taylorindex=0);
     134           0 :   casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& /*weights*/, casacore::Bool /*normalize*/=true)
     135           0 :   {throw(casacore::AipsError("NewMultiTermFT::getImage() should not be called"));}
     136             :  
     137             : 
     138             :   // Place-holder for possible use with AWProject and AWProjectWB FTMs
     139             :   /*
     140             :   virtual void normalizeImage(casacore::Lattice<casacore::Complex>& skyImage,
     141             :                               const casacore::Matrix<casacore::Double>& sumOfWts,
     142             :                               casacore::Lattice<casacore::Float>& sensitivityImage,
     143             :                               casacore::Bool fftNorm)
     144             :     {throw(casacore::AipsError("NewMultiTermFT::normalizeImage() is not implemented"));}
     145             :   */
     146             :   // Get the final weights image - this will hold PB2
     147             :   //void getWeightImage(casacore::ImageInterface<casacore::Float>& weightImage, casacore::Matrix<casacore::Float>& weights)
     148             :   //{getWeightImage(weightImage, weights, 0);};
     149             :   //void getWeightImage(casacore::ImageInterface<casacore::Float>& weightImage, casacore::Matrix<casacore::Float>& weights, 
     150             :   //                                const casacore::Int taylorindex);
     151           0 :   void getWeightImage(casacore::ImageInterface<casacore::Float>& weightImage, casacore::Matrix<casacore::Float>& weights)
     152           0 :   {subftms_p[0]->getWeightImage(weightImage, weights);}
     153             :   //  {throw(casacore::AipsError("NewMultiTermFT::getWeightImage() should not be called"));}
     154             : 
     155             :   // Save and restore the NewMultiTermFT to and from a record
     156             :   virtual casacore::Bool toRecord(casacore::String& error, casacore::RecordInterface& outRec, casacore::Bool withImage=false,
     157             :                         const casacore::String diskimage="");
     158             :   virtual casacore::Bool fromRecord(casacore::String& error, const casacore::RecordInterface& inRec);
     159             : 
     160             :   // Various small inline functions
     161           0 :   virtual casacore::Bool isFourier() {return true;}
     162           0 :   virtual void setNoPadding(casacore::Bool nopad){subftms_p[0]->setNoPadding(nopad);};
     163           0 :   virtual casacore::String name()const {return machineName_p;};
     164           0 :   virtual void setMiscInfo(const casacore::Int qualifier){(void)qualifier;};
     165             : 
     166           0 :   void printFTTypes()
     167             :   {
     168           0 :     cout << "** Number of FTs : " << subftms_p.nelements() << " -- " ;
     169           0 :     for(casacore::uInt tix=0; tix<(subftms_p).nelements(); tix++)
     170           0 :       cout << tix << " : " << (subftms_p[tix])->name() << "   " ;
     171           0 :     cout << endl;
     172           0 :   };
     173             : 
     174           0 :   virtual void setDOPBCorrection(casacore::Bool doit=true) {doWideBandPBCorrection_p=doit;};
     175           0 :   virtual casacore::Bool getDOPBCorrection() {return doWideBandPBCorrection_p;};
     176           0 :   virtual void setConjBeams(casacore::Bool useit=true) {useConjBeams_p=useit;};
     177           0 :   virtual casacore::Bool getConjBeams() {return useConjBeams_p;};
     178             : 
     179             : 
     180             : protected:
     181             : 
     182             :   // Instantiate a new sub FTM
     183             :   FTMachine* getNewFTM(const FTMachine *ftm);
     184             : 
     185             :   // Multiply Imaging weights by Taylor-function weights - during "put"
     186             :   casacore::Bool modifyVisWeights(VisBuffer& vb, casacore::uInt thisterm);
     187             :   // Multiply model visibilities by Taylor-function weights - during "get"
     188             :   casacore::Bool modifyModelVis(VisBuffer &vb, casacore::uInt thisterm);
     189             :   // Restore vb.imagingweights to the original
     190             :   void restoreImagingWeights(VisBuffer &vb);
     191             : 
     192             :   // Use sumwts to make a Hessian, invert it, apply to weight images, fill in pbcoeffs_p
     193             :   void normAvgPBs(casacore::PtrBlock<casacore::SubImage<casacore::Float> *> & weightImageVec);
     194             :   void calculateTaylorPBs(casacore::PtrBlock<casacore::SubImage<casacore::Float> *> & weightImageVec);
     195             :   // Make pixel-by-pixel matrices from pbcoeffs, invert, apply to residuals
     196             :   //  void normalizeWideBandPB2(casacore::PtrBlock<casacore::SubImage<casacore::Float> *> & resImageVec);
     197             :   //  void normalizeWideBandPB(casacore::PtrBlock<casacore::SubImage<casacore::Float> *> & resImageVec, casacore::PtrBlock<casacore::SubImage<casacore::Float> *>& scratchImageVec);
     198             :   void applyWideBandPB(casacore::String action, casacore::PtrBlock<casacore::SubImage<casacore::Float> *> & imageVec);
     199             : 
     200             :   void multiplyHMatrix( casacore::Matrix<casacore::Double> &hmat, casacore::PtrBlock<casacore::SubImage<casacore::Float>* > &invec,
     201             :                         casacore::PtrBlock<casacore::SubImage<casacore::Float>* > &outvec, casacore::String saveImagePrefix );
     202             : 
     203             :   // Helper function to write ImageInterfaces to disk
     204             :   casacore::Bool storeAsImg(casacore::String fileName, casacore::ImageInterface<casacore::Float> & theImg);
     205             : 
     206             : 
     207             :   casacore::Cube<casacore::Complex> modviscube_p;
     208             : 
     209             :   //// New MTFT specific internal parameters and functions
     210             :   casacore::uInt nterms_p;
     211             :   casacore::Bool donePSF_p, doingPSF_p;
     212             :   casacore::Double reffreq_p;
     213             :   casacore::Matrix<casacore::Float> imweights_p;
     214             :   casacore::String machineName_p;
     215             :   casacore::Float pblimit_p;
     216             :   casacore::Bool doWideBandPBCorrection_p;
     217             :   casacore::String cacheDir_p;
     218             :   casacore::Bool donePBTaylor_p;
     219             :   casacore::Bool useConjBeams_p;
     220             : 
     221             :   casacore::Block< casacore::CountedPtr<FTMachine> > subftms_p;
     222             :   casacore::Block<casacore::Matrix<casacore::Float> > sumweights_p;
     223             : 
     224             :   casacore::Double sumwt_p;
     225             :   casacore::Matrix<casacore::Double> hess_p, invhess_p; // casacore::Block is for the pol axis
     226             : 
     227             :   casacore::Block<casacore::CountedPtr<casacore::ImageInterface<casacore::Float> > > sensitivitymaps_p;
     228             :   casacore::PtrBlock<casacore::SubImage<casacore::Float>* > pbcoeffs_p;
     229             : 
     230             :   casacore::Bool dbg_p,dotime_p;
     231             :   casacore::Timer tmr_p;
     232             :   casacore::Double time_get, time_put, time_res;
     233             : };
     234             : 
     235             : } //# NAMESPACE CASA - END
     236             : 
     237             : #endif

Generated by: LCOV version 1.16