LCOV - code coverage report
Current view: top level - synthesis/TransformMachines - Utils.h (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 1 9 11.1 %
Date: 2024-12-11 20:54:31 Functions: 1 8 12.5 %

          Line data    Source code
       1             : // -*- C++ -*-
       2             : //# Utils.h: Definition of global functions in Utils.cc
       3             : //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
       4             : //# Associated Universities, Inc. Washington DC, USA.
       5             : //#
       6             : //# This library is free software; you can redistribute it and/or modify it
       7             : //# under the terms of the GNU Library General Public License as published by
       8             : //# the Free Software Foundation; either version 2 of the License, or (at your
       9             : //# option) any later version.
      10             : //#
      11             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      12             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      14             : //# License for more details.
      15             : //#
      16             : //# You should have received a copy of the GNU Library General Public License
      17             : //# along with this library; if not, write to the Free Software Foundation,
      18             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      19             : //#
      20             : //# Correspondence concerning AIPS++ should be addressed as follows:
      21             : //#        Internet email: casa-feedback@nrao.edu.
      22             : //#        Postal address: AIPS++ Project Office
      23             : //#                        National Radio Astronomy Observatory
      24             : //#                        520 Edgemont Road
      25             : //#                        Charlottesville, VA 22903-2475 USA
      26             : //#
      27             : //# $Id$
      28             : #include <casacore/casa/aips.h>
      29             : #include <casacore/casa/Exceptions/Error.h>
      30             : #include <msvis/MSVis/VisBuffer.h>
      31             : #include <casacore/casa/Quanta/Quantum.h>
      32             : #include <casacore/ms/MeasurementSets/MSColumns.h>
      33             : #include <casacore/ms/MeasurementSets/MSRange.h>
      34             : #include <casacore/images/Images/ImageInterface.h>
      35             : #include <casacore/ms/MeasurementSets/MeasurementSet.h>
      36             : #include <casacore/casa/Arrays/Array.h>
      37             : #include <casacore/casa/Logging/LogIO.h>
      38             : #include <synthesis/TransformMachines/CFCell.h>
      39             : #include <iostream>
      40             : 
      41             : #ifndef SYNTHESIS_UTILS_H
      42             : #define SYNTHESIS_UTILS_H
      43             : 
      44             : namespace casa
      45             : {
      46             :   casacore::Int getPhaseCenter(casacore::MeasurementSet& ms, casacore::MDirection& dir0, casacore::Int whichField=-1);
      47             :   casacore::Bool findMaxAbsLattice(const casacore::ImageInterface<casacore::Float>& lattice,
      48             :                          casacore::Float& maxAbs,casacore::IPosition& posMaxAbs);
      49             :   casacore::Bool findMaxAbsLattice(const casacore::ImageInterface<casacore::Float>& masklat,
      50             :                          const casacore::Lattice<casacore::Float>& lattice,
      51             :                          casacore::Float& maxAbs,casacore::IPosition& posMaxAbs, 
      52             :                          casacore::Bool flip=false);
      53             :   casacore::Double getCurrentTimeStamp(const VisBuffer& vb);
      54             :   void makeStokesAxis(casacore::Int npol_p, casacore::Vector<casacore::String>& polType, casacore::Vector<casacore::Int>& whichStokes);
      55             :   casacore::Double getPA(const VisBuffer& vb);
      56             :   void storeImg(casacore::String fileName,casacore::ImageInterface<casacore::Complex>& theImg, casacore::Bool writeReIm=false);
      57             :   void storeImg(casacore::String fileName,casacore::ImageInterface<casacore::Float>& theImg);
      58             :   void storeArrayAsImage(casacore::String fileName, const casacore::CoordinateSystem& coords, const casacore::Array<casacore::Complex>& cf);
      59             :   void storeArrayAsImage(casacore::String fileName, const casacore::CoordinateSystem& coords, const casacore::Array<casacore::DComplex>& cf);
      60             :   void storeArrayAsImage(casacore::String fileName, const casacore::CoordinateSystem& coords, const casacore::Array<casacore::Float>& cf);
      61             :                          
      62             :   casacore::Bool isVBNaN(const VisBuffer& vb, casacore::String& mesg);
      63             :   namespace SynthesisUtils
      64             :   {
      65             :     void rotateComplexArray(casacore::LogIO& logIO, casacore::Array<casacore::Complex>& inArray, 
      66             :                             casacore::CoordinateSystem& inCS,
      67             :                             casacore::Array<casacore::Complex>& outArray, 
      68             :                             casacore::Double dAngleRad, 
      69             :                             casacore::String interpMathod=casacore::String("CUBIC"),
      70             :                             casacore::Bool modifyInCS=true);
      71             :     void findLatticeMax(const casacore::Array<casacore::Complex>& lattice,
      72             :                         casacore::Vector<casacore::Float>& maxAbs,
      73             :                         casacore::Vector<casacore::IPosition>& posMaxAbs) ;
      74             :     void findLatticeMax(const casacore::ImageInterface<casacore::Complex>& lattice,
      75             :                         casacore::Vector<casacore::Float>& maxAbs,
      76             :                         casacore::Vector<casacore::IPosition>& posMaxAbs) ;
      77             :     void findLatticeMax(const casacore::ImageInterface<casacore::Float>& lattice,
      78             :                         casacore::Vector<casacore::Float>& maxAbs,
      79             :                         casacore::Vector<casacore::IPosition>& posMaxAbs) ;
      80         286 :     inline  casacore::Int nint(const casacore::Double& v) {return (casacore::Int)std::floor(v+0.5);}
      81           0 :     inline  casacore::Int nint(const casacore::Float& v) {return (casacore::Int)std::floor(v+0.5);}
      82             :     inline  casacore::Bool near(const casacore::Double& d1, const casacore::Double& d2, 
      83             :                       const casacore::Double EPS=1E-6) 
      84             :     {
      85             :       casacore::Bool b1=(fabs(d1-d2) < EPS);
      86             :       return b1;
      87             :     }
      88             :     template <class T>
      89           0 :     inline void SETVEC(casacore::Vector<T>& lhs, const casacore::Vector<T>& rhs)
      90           0 :     {lhs.resize(rhs.shape()); lhs = rhs;};
      91             :     template <class T>
      92           0 :     inline void SETVEC(casacore::Array<T>& lhs, const casacore::Array<T>& rhs)
      93           0 :     {lhs.resize(rhs.shape()); lhs = rhs;};
      94             : 
      95             :     template <class T>
      96             :     T getenv(const char *name, const T defaultVal);
      97             :     casacore::Float libreSpheroidal(casacore::Float nu);
      98             :     casacore::Double getRefFreq(const VisBuffer& vb);
      99             :     void makeFTCoordSys(const casacore::CoordinateSystem& coords,
     100             :                         const casacore::Int& convSize,
     101             :                         const casacore::Vector<casacore::Double>& ftRef,
     102             :                         casacore::CoordinateSystem& ftCoords);
     103             : 
     104             :     void expandFreqSelection(const casacore::Matrix<casacore::Double>& freqSelection,
     105             :                              casacore::Matrix<casacore::Double>& expandedFreqList,
     106             :                              casacore::Matrix<casacore::Double>& expandedConjFreqList);
     107             : 
     108             :     template <class T>
     109             :     void libreConvolver(casacore::Array<T>& c1, const casacore::Array<T>& c2);
     110           0 :     inline casacore::Double conjFreq(const casacore::Double& freq, const casacore::Double& refFreq) 
     111           0 :     {return sqrt(2*refFreq*refFreq - freq*freq);};
     112             : 
     113             :     casacore::Double nearestValue(const casacore::Vector<casacore::Double>& list, const casacore::Double& val, casacore::Int& index);
     114             : 
     115             :     template <class T>
     116             :     T stdNearestValue(const std::vector<T>& list, const T& val, casacore::Int& index);
     117             : 
     118             :     casacore::CoordinateSystem makeUVCoords(casacore::CoordinateSystem& imageCoordSys,
     119             :                                   casacore::IPosition& shape);
     120             : 
     121             :     casacore::Vector<casacore::Int> mapSpwIDToDDID(const VisBuffer& vb, const casacore::Int& spwID);
     122             :     casacore::Vector<casacore::Int> mapSpwIDToPolID(const VisBuffer& vb, const casacore::Int& spwID);
     123             :     void calcIntersection(const casacore::Int blc1[2], const casacore::Int trc1[2], const casacore::Float blc2[2], const casacore::Float trc2[2],
     124             :                           casacore::Float blc[2], casacore::Float trc[2]);
     125             :     casacore::Bool checkIntersection(const casacore::Int blc1[2], const casacore::Int trc1[2], const casacore::Float blc2[2], const casacore::Float trc2[2]);
     126             : 
     127             :     casacore::String mjdToString(casacore::Time& mjd);
     128             : 
     129             :     template<class Iterator>
     130             :     Iterator Unique(Iterator first, Iterator last);
     131             :                           
     132             :     void showCS(const casacore::CoordinateSystem& cs, std::ostream& os, const casacore::String& msg=casacore::String());
     133             :     const casacore::Array<casacore::Complex> getCFPixels(const casacore::String& Dir, const casacore::String& fileName);
     134             : 
     135             :     void rotate2(const double& actualPA, CFCell& baseCFC, CFCell& cfc, const double& rotAngleIncr);
     136             : 
     137             :     casacore::TableRecord getCFParams(const casacore::String& dirName,const casacore::String& fileName,
     138             :                                       casacore::Array<casacore::Complex>& pixelBuffer,
     139             :                                       casacore::CoordinateSystem& coordSys, 
     140             :                                       casacore::Double& sampling,
     141             :                                       casacore::Double& paVal,
     142             :                                       casacore::Int& xSupport, casacore::Int& ySupport,
     143             :                                       casacore::Double& fVal, casacore::Double& wVal, casacore::Int& mVal,
     144             :                                       casacore::Double& conjFreq, casacore::Int& conjPoln,
     145             :                                       casacore::Bool loadPixels,
     146             :                                       casacore::Bool loadMiscInfo=true);
     147             :   }
     148             : 
     149             :   void getHADec(casacore::MeasurementSet& ms, const VisBuffer& vb, casacore::Double &HA, casacore::Double& RA, casacore::Double& Dec);
     150             :   /////////////////////////////////////////////////////////////////////////////
     151             :   // 
     152             :   // An interface class to detect changes in the VisBuffer
     153             :   // Exact meaning of the "change" is defined in the derived classes
     154             :   //
     155             :   struct IChangeDetector {
     156             :      // return true if a change occurs in the given row since the last call of update
     157             :      virtual casacore::Bool changed(const VisBuffer &vb, casacore::Int row) const = 0;
     158             :      // start looking for a change from the given row of the VisBuffer
     159             :      virtual void update(const VisBuffer &vb, casacore::Int row) = 0;
     160             :      
     161             :      // reset to the state which exists just after construction
     162             :      virtual void reset() = 0;
     163             : 
     164             :      // some derived methods, which use the abstract virtual function changed(vb,row)
     165             :      
     166             :      // return true if a change occurs somewhere in the buffer
     167             :      casacore::Bool changed(const VisBuffer &vb) const;
     168             :      // return true if a change occurs somewhere in the buffer starting from row1
     169             :      // up to row2 (row2=-1 means up to the end of the buffer). The row number, 
     170             :      // where the change occurs is returned in the row2 parameter
     171             :      casacore::Bool changedBuffer(const VisBuffer &vb, casacore::Int row1, casacore::Int &row2) const;
     172             :   protected:
     173             :      // a virtual destructor to make the compiler happy
     174             :      virtual ~IChangeDetector();
     175             :   };
     176             :   //
     177             :   //////////////////////////////////////////////////////////////////////////////
     178             : 
     179             :   //////////////////////////////////////////////////////////////////////////////
     180             :   //
     181             :   // ParAngleChangeDetector - a class to detect a change in the parallactic 
     182             :   //                          angle. 
     183             :   //
     184             :   class ParAngleChangeDetector : public IChangeDetector {
     185             :      casacore::Double pa_tolerance_p;   // a parallactic angle tolerance. If exeeded, 
     186             :                               // the angle is considered to be changed.
     187             :      casacore::Double last_pa_p;        // last value of the parallactic angle
     188             :   public:
     189             :      // The default constructor
     190           0 :      ParAngleChangeDetector():pa_tolerance_p(0.0) {};
     191             :      // set up the tolerance, which determines how much the position angle should
     192             :      // change to report the change by this class
     193             :      ParAngleChangeDetector(const casacore::Quantity &pa_tolerance);
     194             : 
     195             :      virtual void setTolerance(const casacore::Quantity &pa_tolerance);
     196             :      // reset to the state which exists just after construction
     197             :      virtual void reset();
     198             : 
     199             :      // return parallactic angle tolerance
     200             :      casacore::Quantity getParAngleTolerance() const;
     201             :       
     202             :      // implementation of the base class' virtual functions
     203             :      
     204             :      // return true if a change occurs in the given row since the last call of update
     205             :      virtual casacore::Bool changed(const VisBuffer &vb, casacore::Int row) const;
     206             :      // start looking for a change from the given row of the VisBuffer
     207             :      virtual void update(const VisBuffer &vb, casacore::Int row);
     208             :   };
     209             : 
     210             :   //
     211             :   /////////////////////////////////////////////////////////////////////////////
     212             : 
     213             : }
     214             : #endif

Generated by: LCOV version 1.16