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 #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
00138
00139
00140 struct IChangeDetector {
00141
00142 virtual Bool changed(const VisBuffer &vb, Int row) const = 0;
00143
00144 virtual void update(const VisBuffer &vb, Int row) = 0;
00145
00146
00147 virtual void reset() = 0;
00148
00149
00150
00151
00152 Bool changed(const VisBuffer &vb) const;
00153
00154
00155
00156 Bool changedBuffer(const VisBuffer &vb, Int row1, Int &row2) const;
00157 protected:
00158
00159 virtual ~IChangeDetector();
00160 };
00161
00163
00165
00166
00167
00168
00169 class ParAngleChangeDetector : public IChangeDetector {
00170 Double pa_tolerance_p;
00171
00172 Double last_pa_p;
00173 public:
00174
00175 ParAngleChangeDetector():pa_tolerance_p(0.0) {};
00176
00177
00178 ParAngleChangeDetector(const Quantity &pa_tolerance);
00179
00180 virtual void setTolerance(const Quantity &pa_tolerance);
00181
00182 virtual void reset();
00183
00184
00185 Quantity getParAngleTolerance() const;
00186
00187
00188
00189
00190 virtual Bool changed(const VisBuffer &vb, Int row) const;
00191
00192 virtual void update(const VisBuffer &vb, Int row);
00193 };
00194
00195
00197
00198 }
00199 #endif