Utils.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //# Utils.h: Definition of global functions in Utils.cc
00003 //# Copyright (C) 1997,1998,1999,2000,2001,2002,2003
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //# $Id$
00028 #include <casa/aips.h>
00029 #include <casa/Exceptions/Error.h>
00030 #include <msvis/MSVis/VisBuffer.h>
00031 #include <casa/Quanta/Quantum.h>
00032 #include <ms/MeasurementSets/MSColumns.h>
00033 #include <ms/MeasurementSets/MSRange.h>
00034 #include <images/Images/ImageInterface.h>
00035 #include <ms/MeasurementSets/MeasurementSet.h>
00036 #include <casa/Arrays/Array.h>
00037 #include <casa/Logging/LogIO.h>
00038 #include <casa/iostream.h>
00039 
00040 #ifndef SYNTHESIS_UTILS_H
00041 #define SYNTHESIS_UTILS_H
00042 
00043 namespace casa
00044 {
00045   Int getPhaseCenter(MeasurementSet& ms, MDirection& dir0, Int whichField=-1);
00046   Bool findMaxAbsLattice(const ImageInterface<Float>& lattice,
00047                          Float& maxAbs,IPosition& posMaxAbs);
00048   Bool findMaxAbsLattice(const ImageInterface<Float>& masklat,
00049                          const Lattice<Float>& lattice,
00050                          Float& maxAbs,IPosition& posMaxAbs, 
00051                          Bool flip=False);
00052   Double getCurrentTimeStamp(const VisBuffer& vb);
00053   void makeStokesAxis(Int npol_p, Vector<String>& polType, Vector<Int>& whichStokes);
00054   Double getPA(const VisBuffer& vb);
00055   void storeImg(String fileName,ImageInterface<Complex>& theImg, Bool writeReIm=False);
00056   void storeImg(String fileName,ImageInterface<Float>& theImg);
00057   void storeArrayAsImage(String fileName, const CoordinateSystem& coords, const Array<Complex>& cf);
00058   void storeArrayAsImage(String fileName, const CoordinateSystem& coords, const Array<DComplex>& cf);
00059   void storeArrayAsImage(String fileName, const CoordinateSystem& coords, const Array<Float>& cf);
00060                          
00061   Bool isVBNaN(const VisBuffer& vb, String& mesg);
00062   namespace SynthesisUtils
00063   {
00064     void rotateComplexArray(LogIO& logIO, Array<Complex>& inArray, 
00065                             CoordinateSystem& inCS,
00066                             Array<Complex>& outArray, 
00067                             Double dAngleRad, 
00068                             String interpMathod=String("CUBIC"),
00069                             Bool modifyInCS=True);
00070     void findLatticeMax(const Array<Complex>& lattice,
00071                         Vector<Float>& maxAbs,
00072                         Vector<IPosition>& posMaxAbs) ;
00073     void findLatticeMax(const ImageInterface<Complex>& lattice,
00074                         Vector<Float>& maxAbs,
00075                         Vector<IPosition>& posMaxAbs) ;
00076     void findLatticeMax(const ImageInterface<Float>& lattice,
00077                         Vector<Float>& maxAbs,
00078                         Vector<IPosition>& posMaxAbs) ;
00079     inline  Int nint(const Double& v) {return (Int)std::floor(v+0.5);}
00080     inline  Int nint(const Float& v) {return (Int)std::floor(v+0.5);}
00081     inline  Bool near(const Double& d1, const Double& d2, 
00082                       const Double EPS=1E-6) 
00083     {
00084       Bool b1=(fabs(d1-d2) < EPS)?True:False;
00085       return b1;
00086     }
00087     template <class T>
00088     inline void SETVEC(Vector<T>& lhs, const Vector<T>& rhs)
00089     {lhs.resize(rhs.shape()); lhs = rhs;};
00090     template <class T>
00091     inline void SETVEC(Array<T>& lhs, const Array<T>& rhs)
00092     {lhs.resize(rhs.shape()); lhs = rhs;};
00093 
00094     template <class T>
00095     T getenv(const char *name, const T defaultVal);
00096     Float libreSpheroidal(Float nu);
00097     Double getRefFreq(const VisBuffer& vb);
00098     void makeFTCoordSys(const CoordinateSystem& coords,
00099                         const Int& convSize,
00100                         const Vector<Double>& ftRef,
00101                         CoordinateSystem& ftCoords);
00102 
00103     void expandFreqSelection(const Matrix<Double>& freqSelection,
00104                              Matrix<Double>& expandedFreqList,
00105                              Matrix<Double>& expandedConjFreqList);
00106 
00107     template <class T>
00108     void libreConvolver(Array<T>& c1, const Array<T>& c2);
00109     inline Double conjFreq(const Double& freq, const Double& refFreq) 
00110     {return sqrt(2*refFreq*refFreq - freq*freq);};
00111 
00112     Double nearestValue(const Vector<Double>& list, const Double& val, Int& index);
00113 
00114     template <class T>
00115     T stdNearestValue(const vector<T>& list, const T& val, Int& index);
00116 
00117     CoordinateSystem makeUVCoords(CoordinateSystem& imageCoordSys,
00118                                   IPosition& shape);
00119 
00120     Vector<Int> mapSpwIDToDDID(const VisBuffer& vb, const Int& spwID);
00121     Vector<Int> mapSpwIDToPolID(const VisBuffer& vb, const Int& spwID);
00122     void calcIntersection(const Int blc1[2], const Int trc1[2], const Float blc2[2], const Float trc2[2],
00123                           Float blc[2], Float trc[2]);
00124     Bool checkIntersection(const Int blc1[2], const Int trc1[2], const Float blc2[2], const Float trc2[2]);
00125 
00126     String mjdToString(Time& mjd);
00127 
00128     template<class Iterator>
00129     Iterator Unique(Iterator first, Iterator last);
00130                           
00131     void showCS(const CoordinateSystem& cs, ostream& os, const String& msg=String());
00132   }
00133 
00134   void getHADec(MeasurementSet& ms, const VisBuffer& vb, Double &HA, Double& RA, Double& Dec);
00136   // 
00137   // An interface class to detect changes in the VisBuffer
00138   // Exact meaning of the "change" is defined in the derived classes
00139   //
00140   struct IChangeDetector {
00141      // return True if a change occurs in the given row since the last call of update
00142      virtual Bool changed(const VisBuffer &vb, Int row) const = 0;
00143      // start looking for a change from the given row of the VisBuffer
00144      virtual void update(const VisBuffer &vb, Int row) = 0;
00145      
00146      // reset to the state which exists just after construction
00147      virtual void reset() = 0;
00148 
00149      // some derived methods, which use the abstract virtual function changed(vb,row)
00150      
00151      // return True if a change occurs somewhere in the buffer
00152      Bool changed(const VisBuffer &vb) const;
00153      // return True if a change occurs somewhere in the buffer starting from row1
00154      // up to row2 (row2=-1 means up to the end of the buffer). The row number, 
00155      // where the change occurs is returned in the row2 parameter
00156      Bool changedBuffer(const VisBuffer &vb, Int row1, Int &row2) const;
00157   protected:
00158      // a virtual destructor to make the compiler happy
00159      virtual ~IChangeDetector();
00160   };
00161   //
00163 
00165   //
00166   // ParAngleChangeDetector - a class to detect a change in the parallactic 
00167   //                          angle. 
00168   //
00169   class ParAngleChangeDetector : public IChangeDetector {
00170      Double pa_tolerance_p;   // a parallactic angle tolerance. If exeeded, 
00171                               // the angle is considered to be changed.
00172      Double last_pa_p;        // last value of the parallactic angle
00173   public:
00174      // The default constructor
00175      ParAngleChangeDetector():pa_tolerance_p(0.0) {};
00176      // set up the tolerance, which determines how much the position angle should
00177      // change to report the change by this class
00178      ParAngleChangeDetector(const Quantity &pa_tolerance);
00179 
00180      virtual void setTolerance(const Quantity &pa_tolerance);
00181      // reset to the state which exists just after construction
00182      virtual void reset();
00183 
00184      // return parallactic angle tolerance
00185      Quantity getParAngleTolerance() const;
00186       
00187      // implementation of the base class' virtual functions
00188      
00189      // return True if a change occurs in the given row since the last call of update
00190      virtual Bool changed(const VisBuffer &vb, Int row) const;
00191      // start looking for a change from the given row of the VisBuffer
00192      virtual void update(const VisBuffer &vb, Int row);
00193   };
00194 
00195   //
00197 
00198 }
00199 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1