1 | // C++ Interface: STSideBandSep |
---|
2 | // |
---|
3 | // Description: |
---|
4 | // A class to invoke sideband separation of Scantable |
---|
5 | // |
---|
6 | // Author: Kanako Sugimoto <kana.sugi@nao.ac.jp>, (C) 2012 |
---|
7 | // |
---|
8 | // Copyright: See COPYING file that comes with this distribution |
---|
9 | // |
---|
10 | // |
---|
11 | #ifndef ASAPSIDEBANDSEP_H |
---|
12 | #define ASAPSIDEBANDSEP_H |
---|
13 | |
---|
14 | // STL |
---|
15 | #include <iostream> |
---|
16 | #include <string> |
---|
17 | #include <vector> |
---|
18 | // casacore |
---|
19 | #include <casa/aips.h> |
---|
20 | #include <casa/Utilities/CountedPtr.h> |
---|
21 | #include <casa/Arrays/Vector.h> |
---|
22 | #include <measures/Measures/MDirection.h> |
---|
23 | #include <coordinates/Coordinates/DirectionCoordinate.h> |
---|
24 | #include <coordinates/Coordinates/SpectralCoordinate.h> |
---|
25 | #include <scimath/Mathematics/FFTServer.h> |
---|
26 | // asap |
---|
27 | #include "ScantableWrapper.h" |
---|
28 | #include "Scantable.h" |
---|
29 | |
---|
30 | namespace asap { |
---|
31 | |
---|
32 | class STSideBandSep { |
---|
33 | public: |
---|
34 | /** |
---|
35 | * constructors and a destructor |
---|
36 | **/ |
---|
37 | STSideBandSep() { throw( casacore::AipsError("No data set to process") ); }; |
---|
38 | explicit STSideBandSep(const std::vector<std::string> &names); |
---|
39 | explicit STSideBandSep(const std::vector<ScantableWrapper> &tables); |
---|
40 | virtual ~STSideBandSep(); |
---|
41 | |
---|
42 | |
---|
43 | /** |
---|
44 | * Separate side bands |
---|
45 | **/ |
---|
46 | void separate(std::string outname); |
---|
47 | |
---|
48 | /** |
---|
49 | * Set IFNO and frequency tolerance to select data to process |
---|
50 | **/ |
---|
51 | void setFrequency(const int ifno, const std::string freqtol, |
---|
52 | const std::string frame=""); |
---|
53 | |
---|
54 | /** |
---|
55 | * Set direction tolerance to group spectra. |
---|
56 | * The spectra within this range will be averaged before procesing. |
---|
57 | **/ |
---|
58 | void setDirTolerance(const std::vector<std::string> dirtol); |
---|
59 | |
---|
60 | /** |
---|
61 | * Set the number of channels shifted in image side band |
---|
62 | * of each of scantable. |
---|
63 | **/ |
---|
64 | void setShift(const std::vector<double> &shift); |
---|
65 | |
---|
66 | /** |
---|
67 | * Set rejection limit of solution. |
---|
68 | **/ |
---|
69 | void setThreshold(const double limit); |
---|
70 | |
---|
71 | /** |
---|
72 | * Resolve both image and signal sideband when true is set. |
---|
73 | **/ |
---|
74 | void solveBoth(const bool flag) { doboth_ = flag; }; |
---|
75 | |
---|
76 | /** |
---|
77 | * Obtain spectra by subtracting the solution of the other sideband. |
---|
78 | **/ |
---|
79 | void solvefromOther(const bool flag) { otherside_ = flag; }; |
---|
80 | |
---|
81 | /** |
---|
82 | * Set scantable to fill frequencies of image sideband (temporal) |
---|
83 | **/ |
---|
84 | void setImageTable(const ScantableWrapper &s); |
---|
85 | void setScanTb0(const ScantableWrapper &s); |
---|
86 | |
---|
87 | /** |
---|
88 | * Set additional information to fill frequencies of image sideband |
---|
89 | **/ |
---|
90 | void setLO1(const std::string lo1, const std::string frame="TOPO", |
---|
91 | const double reftime=-1, std::string refdir=""); |
---|
92 | void setLO1Root(const std::string name); |
---|
93 | |
---|
94 | private: |
---|
95 | /** Initialize member variables **/ |
---|
96 | void init(); |
---|
97 | void initshift(); |
---|
98 | |
---|
99 | /** Return if the path exists (optionally, check file type) **/ |
---|
100 | casacore::Bool checkFile(const std::string name, std::string type=""); |
---|
101 | |
---|
102 | /** **/ |
---|
103 | unsigned int setupShift(); |
---|
104 | bool getFreqInfo(const casacore::CountedPtr<Scantable> &stab, const unsigned int &ifno, |
---|
105 | double &freq0, double &incr, unsigned int &nchan); |
---|
106 | |
---|
107 | /** Grid scantable **/ |
---|
108 | ScantableWrapper gridTable(); |
---|
109 | void mapExtent(std::vector< casacore::CountedPtr<Scantable> > &tablist, |
---|
110 | casacore::Double &xmin, casacore::Double &xmax, |
---|
111 | casacore::Double &ymin, casacore::Double &ymax); |
---|
112 | |
---|
113 | /** |
---|
114 | * Shift TIME in gridded scantable for future imaging |
---|
115 | * |
---|
116 | * STGrid sets the identical time for all rows in scantable |
---|
117 | * which is reasonable thing to do in position based averaging. |
---|
118 | * However, this prevents CASA from finding proper pointing |
---|
119 | * per spectra once the gridded scantable is converted to |
---|
120 | * measurement set (MS). It is because MS does not |
---|
121 | * have ability to store per spectra pointing information. |
---|
122 | * MS stores pointing information in a subtable, POINTING, |
---|
123 | * with corresponding TIME when an antenna pointed the direction. |
---|
124 | * The pointing direction corresponding to a spectra is resolved |
---|
125 | * in MS by interpolating DIRECTION in POINTING subtable in TIME |
---|
126 | * the spectra is observed. If there are multiple match, |
---|
127 | * the first match is adopted. Therefore, gridded table (whose TIME |
---|
128 | * is set to a single value) is misunderstood in MS that all data |
---|
129 | * come from a single pointing. |
---|
130 | * The function workarounds this defect by artificially shifting |
---|
131 | * TIME by INTERVAL in each row. |
---|
132 | **/ |
---|
133 | void shiftTimeInGriddedST(const casacore::CountedPtr<Scantable> &stab); |
---|
134 | /** |
---|
135 | * Actual calculation of frequencies of image sideband |
---|
136 | **/ |
---|
137 | void solveImageFrequency(); |
---|
138 | |
---|
139 | /** |
---|
140 | * Get LO1 frequency to solve the frequencies of image side band |
---|
141 | **/ |
---|
142 | bool getLo1FromAsdm(const std::string asdmname, |
---|
143 | const double refval, const double refpix, |
---|
144 | const double increment, const int nChan); |
---|
145 | bool getLo1FromAsisTab(const std::string msname, |
---|
146 | const double refval, const double refpix, |
---|
147 | const double increment, const int nChan); |
---|
148 | bool getLo1FromScanTab(casacore::CountedPtr< Scantable > &scantab, |
---|
149 | const double refval, const double refpix, |
---|
150 | const double increment, const int nChan); |
---|
151 | // bool getSpectraToSolve(const int polId, const int beamId, |
---|
152 | // const double dirX, const double dirY, |
---|
153 | // Matrix<float> &specmat, std::vector<casacore::uInt> &tabIdvec); |
---|
154 | bool getSpectraToSolve(const int polId, const int beamId, |
---|
155 | const double dirX, const double dirY, |
---|
156 | casacore::Matrix<float> &specMat, casacore::Matrix<bool> &flagMat, |
---|
157 | std::vector<casacore::uInt> &tabIdvec); |
---|
158 | |
---|
159 | std::vector<float> solve(const casacore::Matrix<float> &specMat, |
---|
160 | const std::vector<casacore::uInt> &tabIdvec, |
---|
161 | const bool signal = true); |
---|
162 | |
---|
163 | casacore::Vector<bool> collapseFlag(const casacore::Matrix<bool> &flagMat, |
---|
164 | const std::vector<casacore::uInt> &tabIdvec, |
---|
165 | const bool signal = true); |
---|
166 | |
---|
167 | void shiftSpectrum(const casacore::Vector<float> &invec, double shift, |
---|
168 | casacore::Vector<float> &outvec); |
---|
169 | |
---|
170 | void shiftFlag(const casacore::Vector<bool> &invec, double shift, |
---|
171 | casacore::Vector<bool> &outvec); |
---|
172 | |
---|
173 | void deconvolve(casacore::Matrix<float> &specmat, const std::vector<double> shiftvec, |
---|
174 | const double threshold, casacore::Matrix<float> &outmat); |
---|
175 | |
---|
176 | void aggregateMat(casacore::Matrix<float> &inmat, std::vector<float> &outvec); |
---|
177 | |
---|
178 | void subtractFromOther(const casacore::Matrix<float> &shiftmat, |
---|
179 | const std::vector<float> &invec, |
---|
180 | const std::vector<double> &shift, |
---|
181 | std::vector<float> &outvec); |
---|
182 | |
---|
183 | |
---|
184 | |
---|
185 | /** Member variables **/ |
---|
186 | // input tables |
---|
187 | std::vector<std::string> infileList_; |
---|
188 | std::vector< casacore::CountedPtr<Scantable> > intabList_; |
---|
189 | unsigned int ntable_; |
---|
190 | // frequency and direction setup to select data. |
---|
191 | int sigIfno_; |
---|
192 | casacore::Quantum<casacore::Double> ftol_; |
---|
193 | casacore::MFrequency::Types solFrame_; |
---|
194 | std::vector<double> sigShift_, imgShift_; |
---|
195 | unsigned int nshift_, nchan_; |
---|
196 | std::vector< casacore::CountedPtr<Scantable> > tableList_; |
---|
197 | casacore::Double xtol_, ytol_; |
---|
198 | // solution parameters |
---|
199 | bool otherside_, doboth_; |
---|
200 | double rejlimit_; |
---|
201 | // LO1 |
---|
202 | double lo1Freq_; // in Hz |
---|
203 | casacore::MFrequency::Types loFrame_; |
---|
204 | double loTime_; |
---|
205 | std::string loDir_; |
---|
206 | std::string asdmName_, asisName_; |
---|
207 | |
---|
208 | //CountedPtr<Scantable> imgTab_p, sigTab_p; |
---|
209 | casacore::CountedPtr<Scantable> imgTab_p, sigTab_p; |
---|
210 | casacore::Table::TableType tp_; |
---|
211 | casacore::FFTServer<casacore::Float, casacore::Complex> fftsf, fftsi; |
---|
212 | |
---|
213 | }; // class |
---|
214 | |
---|
215 | } // namespace |
---|
216 | |
---|
217 | #endif |
---|