00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
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
00143
00144
00145 struct IChangeDetector {
00146
00147 virtual Bool changed(const VisBuffer2 &vb, Int row) const = 0;
00148
00149 virtual void update(const VisBuffer2 &vb, Int row) = 0;
00150
00151
00152 virtual void reset() = 0;
00153
00154
00155
00156
00157 Bool changed(const VisBuffer2 &vb) const;
00158
00159
00160
00161 Bool changedBuffer(const VisBuffer2 &vb, Int row1, Int &row2) const;
00162 protected:
00163
00164 virtual ~IChangeDetector();
00165 };
00166
00168
00170
00171
00172
00173
00174 class ParAngleChangeDetector : public IChangeDetector {
00175 Double pa_tolerance_p;
00176
00177 Double last_pa_p;
00178 public:
00179
00180 ParAngleChangeDetector():pa_tolerance_p(0.0) {};
00181
00182
00183 ParAngleChangeDetector(const Quantity &pa_tolerance);
00184
00185 virtual void setTolerance(const Quantity &pa_tolerance);
00186
00187 virtual void reset();
00188
00189
00190 Quantity getParAngleTolerance() const;
00191
00192
00193
00194
00195 virtual Bool changed(const VisBuffer2 &vb, Int row) const;
00196
00197 virtual void update(const VisBuffer2 &vb, Int row);
00198 };
00199
00200
00202
00203 };
00204 };
00205 #endif