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 #ifndef SYNTHESIS_TRANSFORM2_UTILS_H
00029 #define SYNTHESIS_TRANSFORM2_UTILS_H
00030 
00031 
00032 #include <casa/aips.h>
00033 #include <casa/Exceptions/Error.h>
00034 #include <msvis/MSVis/VisBuffer2.h>
00035 #include <casa/Quanta/Quantum.h>
00036 #include <images/Images/ImageInterface.h>
00037 //#include <ms/MeasurementSets/MeasurementSet.h>
00038 #include <msvis/MSVis/VisibilityIterator2.h>
00039 #include <ms/MeasurementSets/MSColumns.h>
00040 #include <casa/Arrays/Array.h>
00041 #include <casa/Logging/LogIO.h>
00042 #include <casa/iostream.h>
00043 
00044 namespace casa
00045 {
00046   using namespace vi;
00047   namespace refim {
00048     Int getPhaseCenter(MeasurementSet& ms, MDirection& dir0, Int whichField=-1);
00049     Bool findMaxAbsLattice(const ImageInterface<Float>& lattice,
00050                            Float& maxAbs,IPosition& posMaxAbs);
00051     Bool findMaxAbsLattice(const ImageInterface<Float>& masklat,
00052                            const Lattice<Float>& lattice,
00053                            Float& maxAbs,IPosition& posMaxAbs, 
00054                            Bool flip=False);
00055     Double getCurrentTimeStamp(const VisBuffer2& vb);
00056     void makeStokesAxis(Int npol_p, Vector<String>& polType, Vector<Int>& whichStokes);
00057     Double getPA(const vi::VisBuffer2& vb);
00058     void storeImg(String fileName,ImageInterface<Complex>& theImg, Bool writeReIm=False);
00059     void storeImg(String fileName,ImageInterface<Float>& theImg);
00060     void storeArrayAsImage(String fileName, const CoordinateSystem& coords, const Array<Complex>& cf);
00061     void storeArrayAsImage(String fileName, const CoordinateSystem& coords, const Array<DComplex>& cf);
00062     void storeArrayAsImage(String fileName, const CoordinateSystem& coords, const Array<Float>& cf);
00063     
00064     Bool isVBNaN(const VisBuffer2& vb, String& mesg);
00065     namespace SynthesisUtils
00066     {
00067       //using namespace vi;
00068       void rotateComplexArray(LogIO& logIO, Array<Complex>& inArray, 
00069                               CoordinateSystem& inCS,
00070                               Array<Complex>& outArray, 
00071                               Double dAngleRad, 
00072                               String interpMathod=String("CUBIC"),
00073                               Bool modifyInCS=True);
00074       void findLatticeMax(const Array<Complex>& lattice,
00075                           Vector<Float>& maxAbs,
00076                           Vector<IPosition>& posMaxAbs) ;
00077       void findLatticeMax(const ImageInterface<Complex>& lattice,
00078                           Vector<Float>& maxAbs,
00079                           Vector<IPosition>& posMaxAbs) ;
00080       void findLatticeMax(const ImageInterface<Float>& lattice,
00081                           Vector<Float>& maxAbs,
00082                           Vector<IPosition>& posMaxAbs) ;
00083       inline  Int nint(const Double& v) {return (Int)std::floor(v+0.5);}
00084       inline  Int nint(const Float& v) {return (Int)std::floor(v+0.5);}
00085       inline  Bool near(const Double& d1, const Double& d2, 
00086                         const Double EPS=1E-6) 
00087       {
00088         Bool b1=(fabs(d1-d2) < EPS)?True:False;
00089         return b1;
00090       }
00091       template <class T>
00092       inline void SETVEC(Vector<T>& lhs, const Vector<T>& rhs)
00093       {lhs.resize(rhs.shape()); lhs = rhs;};
00094       template <class T>
00095       inline void SETVEC(Array<T>& lhs, const Array<T>& rhs)
00096       {lhs.resize(rhs.shape()); lhs = rhs;};
00097       
00098       template <class T>
00099       T getenv(const char *name, const T defaultVal);
00100       Float libreSpheroidal(Float nu);
00101       Double getRefFreq(const VisBuffer2& vb);
00102       void makeFTCoordSys(const CoordinateSystem& coords,
00103                           const Int& convSize,
00104                           const Vector<Double>& ftRef,
00105                           CoordinateSystem& ftCoords);
00106       
00107       void expandFreqSelection(const Matrix<Double>& freqSelection,
00108                                Matrix<Double>& expandedFreqList,
00109                                Matrix<Double>& expandedConjFreqList);
00110       
00111       template <class T>
00112       void libreConvolver(Array<T>& c1, const Array<T>& c2);
00113       inline Double conjFreq(const Double& freq, const Double& refFreq) 
00114       {return sqrt(2*refFreq*refFreq - freq*freq);};
00115       
00116       Double nearestValue(const Vector<Double>& list, const Double& val, Int& index);
00117       
00118       template <class T>
00119       T stdNearestValue(const vector<T>& list, const T& val, Int& index);
00120       
00121       CoordinateSystem makeUVCoords(CoordinateSystem& imageCoordSys,
00122                                     IPosition& shape);
00123       
00124       Vector<Int> mapSpwIDToDDID(const VisBuffer2& vb, const Int& spwID);
00125       Vector<Int> mapSpwIDToPolID(const VisBuffer2& vb, const Int& spwID);
00126       void calcIntersection(const Int blc1[2], const Int trc1[2], const Float blc2[2], const Float trc2[2],
00127                             Float blc[2], Float trc[2]);
00128       Bool checkIntersection(const Int blc1[2], const Int trc1[2], const Float blc2[2], const Float trc2[2]);
00129       
00130       String mjdToString(casa::Time& mjd);
00131       
00132       template<class Iterator>
00133       Iterator Unique(Iterator first, Iterator last);
00134       
00135       void showCS(const CoordinateSystem& cs, ostream& os, const String& msg=String());
00136     }
00137     
00138     void getHADec(MeasurementSet& ms, const VisBuffer2& vb, Double &HA, Double& RA, Double& Dec);
00139 
00141     // 
00142     // An interface class to detect changes in the VisBuffer
00143     // Exact meaning of the "change" is defined in the derived classes
00144     //
00145     struct IChangeDetector {
00146       // return True if a change occurs in the given row since the last call of update
00147       virtual Bool changed(const VisBuffer2 &vb, Int row) const = 0;
00148       // start looking for a change from the given row of the VisBuffer
00149       virtual void update(const VisBuffer2 &vb, Int row) = 0;
00150       
00151       // reset to the state which exists just after construction
00152       virtual void reset() = 0;
00153       
00154       // some derived methods, which use the abstract virtual function changed(vb,row)
00155       
00156       // return True if a change occurs somewhere in the buffer
00157       Bool changed(const VisBuffer2 &vb) const;
00158       // return True if a change occurs somewhere in the buffer starting from row1
00159       // up to row2 (row2=-1 means up to the end of the buffer). The row number, 
00160       // where the change occurs is returned in the row2 parameter
00161       Bool changedBuffer(const VisBuffer2 &vb, Int row1, Int &row2) const;
00162     protected:
00163       // a virtual destructor to make the compiler happy
00164       virtual ~IChangeDetector();
00165     };
00166     //
00168     
00170     //
00171     // ParAngleChangeDetector - a class to detect a change in the parallactic 
00172     //                          angle. 
00173     //
00174     class ParAngleChangeDetector : public IChangeDetector {
00175       Double pa_tolerance_p;   // a parallactic angle tolerance. If exeeded, 
00176       // the angle is considered to be changed.
00177       Double last_pa_p;        // last value of the parallactic angle
00178     public:
00179       // The default constructor
00180       ParAngleChangeDetector():pa_tolerance_p(0.0) {};
00181       // set up the tolerance, which determines how much the position angle should
00182       // change to report the change by this class
00183       ParAngleChangeDetector(const Quantity &pa_tolerance);
00184       
00185       virtual void setTolerance(const Quantity &pa_tolerance);
00186       // reset to the state which exists just after construction
00187       virtual void reset();
00188       
00189       // return parallactic angle tolerance
00190       Quantity getParAngleTolerance() const;
00191       
00192       // implementation of the base class' virtual functions
00193       
00194       // return True if a change occurs in the given row since the last call of update
00195       virtual Bool changed(const VisBuffer2 &vb, Int row) const;
00196       // start looking for a change from the given row of the VisBuffer
00197       virtual void update(const VisBuffer2 &vb, Int row);
00198     };
00199     
00200     //
00202     
00203   };
00204 };
00205 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1