LCOV - code coverage report
Current view: top level - synthesis/TransformMachines2 - MultiTermFTNew.h (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 3 27 11.1 %
Date: 2023-10-25 08:47:59 Functions: 2 16 12.5 %

          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: 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             : //#
      27             : //# $Id$
      28             : 
      29             : #ifndef SYNTHESIS_TRANSFORM2_MULTITERMFTNEW_H
      30             : #define SYNTHESIS_TRANSFORM2_MULTITERMFTNEW_H
      31             : 
      32             : #include <synthesis/TransformMachines2/FTMachine.h>
      33             : #include <casacore/casa/Arrays/Matrix.h>
      34             : #include <casacore/scimath/Mathematics/FFTServer.h>
      35             : #include <msvis/MSVis/VisBuffer2.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             : namespace vi{
      56             :                           class VisibilityIterator2;
      57             :                         }
      58             : 
      59             : namespace refim { //# namespace refactor imaginging
      60             : class MultiTermFTNew : public FTMachine {
      61             : public:
      62             : 
      63             :   // Construct using an existing FT-Machine 
      64             :   MultiTermFTNew(casacore::CountedPtr<FTMachine>& subftm, casacore::Int nterms=1, casacore::Bool forward=false);
      65             : 
      66             :   // Construct from a casacore::Record containing the MultiTermFTNew state
      67             :   MultiTermFTNew(const casacore::RecordInterface& stateRec);
      68             : 
      69             :   // Copy constructor. 
      70             :   // This first calls the default "=" operator, and then instantiates objects for member pointers.
      71             :   MultiTermFTNew(const MultiTermFTNew &other);
      72             : 
      73             :   // Assignment operator --- leave it as the default
      74             :   MultiTermFTNew &operator=(const MultiTermFTNew &other);
      75             : 
      76             :   // Destructor
      77             :   ~MultiTermFTNew();
      78             : 
      79             :   // Called at the start of de-gridding : subftm->initializeToVis()
      80             :   // Note : Pre-de-gridding model-image divisions by PBs will go here.
      81             : 
      82           0 :   void initializeToVis(casacore::ImageInterface<casacore::Complex>& /*image*/,
      83           0 :                          const vi::VisBuffer2& /*vb*/){throw(casacore::AipsError("not implemented"));};
      84             :    // Vectorized InitializeToVis
      85             :   //  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);
      86             : 
      87             :   virtual void initializeToVisNew(const vi::VisBuffer2& vb,
      88             :                                              casacore::CountedPtr<SIImageStore> imstore);
      89             : 
      90             :   // Called at the end of de-gridding : subftm->finalizeToVis()
      91             :   void finalizeToVis();
      92             : 
      93             :   // Called at the start of gridding : subftm->initializeToSky()
      94           0 :   void initializeToSky(casacore::ImageInterface<casacore::Complex>& /*image*/,
      95           0 :                          casacore::Matrix<casacore::Float>& /*weight*/, const vi::VisBuffer2& /*vb*/){throw(casacore::AipsError("not implemented"));};
      96             :   //  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);
      97             : 
      98             :   virtual void initializeToSkyNew(const casacore::Bool dopsf,
      99             :                                   const vi::VisBuffer2& vb,
     100             :                                   casacore::CountedPtr<SIImageStore> imstore);
     101             : 
     102             :   virtual void initBriggsWeightor(vi::VisibilityIterator2& vi);
     103             :   // Called at the end of gridding : subftm->finalizeToSky()
     104           0 :   void finalizeToSky(){throw(casacore::AipsError("MultiTermFTNew::finalizeToSky() called without arguments!"));};
     105             : 
     106             :   //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);
     107             : 
     108             :   virtual void finalizeToSkyNew(casacore::Bool dopsf, 
     109             :                                            const vi::VisBuffer2& vb,
     110             :                                            casacore::CountedPtr<SIImageStore> imstore  );
     111             : 
     112             :   //  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)
     113             :   // {throw(casacore::AipsError("MultiTermFTNew::normalizeToSky should not get called !"));};
     114             : 
     115             : 
     116             :   // Do the degridding via subftm->get() and modify model-visibilities by Taylor-weights
     117             :   void get(vi::VisBuffer2& vb, casacore::Int row=-1);
     118             :   // Modify imaging weights with Taylor-weights and do gridding via subftm->put()
     119             :   void put(vi::VisBuffer2& vb, casacore::Int row=-1, casacore::Bool dopsf=false,
     120             :            refim::FTMachine::Type type=refim::FTMachine::OBSERVED);
     121             :   // Have a const version for compatibility with other FTMs.. Throw an exception if called.
     122           0 :   void put(const vi::VisBuffer2& /*vb*/, casacore::Int /*row=-1*/, casacore::Bool /*dopsf=false*/,
     123             :            refim::FTMachine::Type /*type=FTMachine::OBSERVED*/)
     124           0 :   {throw(casacore::AipsError("Internal error: called MultiTermFTNew::put(const VB2)"));};
     125             :   // Calculate residual visibilities if possible.
     126             :   // The purpose is to allow rGridFT to make this multi-threaded
     127             :   virtual void ComputeResiduals(vi::VisBuffer2& vb, casacore::Bool useCorrected);
     128             : 
     129             :   // Make an image : subftm->makeImage()
     130             :   void makeImage(refim::FTMachine::Type type,
     131             :                  vi::VisibilityIterator2& vs,
     132             :                  casacore::ImageInterface<casacore::Complex>& image,
     133             :                  casacore::Matrix<casacore::Float>& weight);
     134             :   ////Make the multi term images
     135             :   ////caller make sure vector is the size of nterms or npsfterms required 
     136             :   void makeMTImages(refim::FTMachine::Type type,
     137             :                  vi::VisibilityIterator2& vi,
     138             :                     casacore::Vector<casacore::CountedPtr<casacore::ImageInterface<casacore::Complex> > >& image,
     139             :                     casacore::Vector<casacore::CountedPtr<casacore::Matrix<casacore::Float> > >& weight);
     140             :   // Get the final image: do the Fourier transform grid-correct, then 
     141             :   // optionally normalize by the summed weights
     142             :   // Note : Post-gridding residual-image divisions by PBs will go here.
     143             :   //           For now, it just calls subftm->getImage()
     144             :   //  casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& weights, casacore::Bool normalize=true)
     145             :   //{return getImage(weights,normalize,0);};
     146             :   //casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& weights, casacore::Bool normalize=true, 
     147             :   //                                                         const casacore::Int taylorindex=0);
     148           0 :   casacore::ImageInterface<casacore::Complex>& getImage(casacore::Matrix<casacore::Float>& /*weights*/, casacore::Bool /*normalize*/=true)
     149           0 :   {throw(casacore::AipsError("MultiTermFTNew::getImage() should not be called"));}
     150             :  
     151         119 :   virtual casacore::Bool useWeightImage()
     152         119 :   {AlwaysAssert(subftms_p.nelements()>0,casacore::AipsError); return subftms_p[0]->useWeightImage(); };
     153             : 
     154           0 :   void getWeightImage(casacore::ImageInterface<casacore::Float>& weightImage, casacore::Matrix<casacore::Float>& weights)
     155           0 :   {AlwaysAssert(subftms_p.nelements()>0,casacore::AipsError); 
     156           0 :     subftms_p[0]->getWeightImage(weightImage, weights);}
     157             :   //  {throw(casacore::AipsError("MultiTermFTNew::getWeightImage() should not be called"));}
     158             : 
     159             :   // Save and restore the MultiTermFTNew to and from a record
     160             :   virtual casacore::Bool toRecord(casacore::String& error, casacore::RecordInterface& outRec, casacore::Bool withImage=false,
     161             :                         const casacore::String diskimage="");
     162             :   virtual casacore::Bool fromRecord(casacore::String& error, const casacore::RecordInterface& inRec);
     163             : 
     164             :   // Various small inline functions
     165           0 :   virtual casacore::Bool isFourier() {return true;}
     166           0 :   virtual void setNoPadding(casacore::Bool nopad){subftms_p[0]->setNoPadding(nopad);};
     167         506 :   virtual casacore::String name()const {return machineName_p;};
     168           0 :   virtual void setMiscInfo(const casacore::Int qualifier){(void)qualifier;};
     169             : 
     170             :   void printFTTypes()
     171             :   {
     172             :     cout << "** Number of FTs : " << subftms_p.nelements() << " -- " ;
     173             :     for(casacore::uInt tix=0; tix<(subftms_p).nelements(); tix++)
     174             :       cout << tix << " : " << (subftms_p[tix])->name() << "   " ;
     175             :     cout << endl;
     176             :   };
     177             : 
     178             :   FTMachine* cloneFTM();
     179           0 :   virtual void setDryRun(casacore::Bool val) 
     180             :   {
     181           0 :     isDryRun=val;
     182             :     //cerr << "MTFTMN: " << isDryRun << endl;
     183           0 :     for (casacore::uInt i=0;i<subftms_p.nelements();i++)
     184           0 :       subftms_p[i]->setDryRun(val);
     185           0 :   };
     186           0 :   virtual casacore::Bool isUsingCFCache() {casacore::Bool v=false; if (subftms_p.nelements() > 0) v=subftms_p[0]->isUsingCFCache(); return v;};
     187           0 :   virtual const casacore::CountedPtr<refim::FTMachine>& getFTM2(const casacore::Bool ) {return subftms_p[0];}
     188             :   virtual void setCFCache(casacore::CountedPtr<CFCache>& cfc, const casacore::Bool resetCFC=true);
     189             : 
     190             : 
     191             :   ///return number of terms
     192             : 
     193           0 :   virtual casacore::Int nTerms(){ return nterms_p;};
     194           0 :   virtual casacore::Int psfNTerms(){ return psfnterms_p;};
     195             : 
     196             :   // set a moving source aka planets or comets =>  adjust phase center
     197             :   // on the fly for gridding 
     198             :   virtual void setMovingSource(const casacore::String& sourcename, const casacore::String& ephemtable="");
     199             :   virtual void setMovingSource(const casacore::MDirection& mdir);
     200             :   // set and get the location used for frame 
     201             :   virtual void setLocation(const casacore::MPosition& loc);
     202             :    ///estimate of memory necessary in kB
     203             :    virtual casacore::Long estimateRAM(const casacore::CountedPtr<SIImageStore>& imstore);
     204             : protected:
     205             :   // have to call the initmaps of subftm
     206             :   virtual void initMaps(const vi::VisBuffer2& vb);
     207             :   // Instantiate a new sub FTM
     208             :   casacore::CountedPtr<FTMachine> getNewFTM(const casacore::CountedPtr<FTMachine>& ftm);
     209             : 
     210             :   // Multiply Imaging weights by Taylor-function weights - during "put"
     211             :   casacore::Bool modifyVisWeights(vi::VisBuffer2& vb, casacore::uInt thisterm);
     212             :   // Multiply model visibilities by Taylor-function weights - during "get"
     213             :   casacore::Bool modifyModelVis(vi::VisBuffer2 &vb, casacore::uInt thisterm);
     214             :   // Restore vb.imagingweights to the original
     215             :   void restoreImagingWeights(vi::VisBuffer2 &vb);
     216             : 
     217             :   // Helper function to write ImageInterfaces to disk
     218             :   casacore::Bool storeAsImg(casacore::String fileName, casacore::ImageInterface<casacore::Float> & theImg);
     219             : 
     220             : 
     221             :   casacore::Cube<casacore::Complex> modviscube_p;
     222             : 
     223             :   //// New MTFT specific internal parameters and functions
     224             :   casacore::uInt nterms_p, psfnterms_p;
     225             :   casacore::Double reffreq_p;
     226             :   casacore::Matrix<casacore::Float> imweights_p;
     227             :   casacore::String machineName_p;
     228             : 
     229             :   //  casacore::Bool donePSF_p;
     230             : 
     231             :   casacore::Block< casacore::CountedPtr<FTMachine> > subftms_p;
     232             : 
     233             : };
     234             : 
     235             : } //end namespace refim
     236             : } //# NAMESPACE CASA - END
     237             : 
     238             : #endif

Generated by: LCOV version 1.16