1 | // |
---|
2 | // C++ Implementation: STBaselineTable |
---|
3 | // |
---|
4 | // Description: |
---|
5 | // |
---|
6 | // |
---|
7 | // Author: Wataru Kawasaki <wataru.kawasaki@nao.ac.jp> (C) 2013 |
---|
8 | // |
---|
9 | // Copyright: See COPYING file that comes with this distribution |
---|
10 | // |
---|
11 | // |
---|
12 | #include <assert.h> |
---|
13 | |
---|
14 | #include <casa/Exceptions/Error.h> |
---|
15 | #include <casa/OS/Path.h> |
---|
16 | #include <tables/Tables/TableDesc.h> |
---|
17 | #include <tables/Tables/SetupNewTab.h> |
---|
18 | #include <tables/Tables/ArrColDesc.h> |
---|
19 | #include <tables/Tables/ScaColDesc.h> |
---|
20 | #include <tables/Tables/TableRecord.h> |
---|
21 | #include <measures/TableMeasures/TableMeasDesc.h> |
---|
22 | #include <measures/TableMeasures/TableMeasRefDesc.h> |
---|
23 | #include <measures/TableMeasures/TableMeasValueDesc.h> |
---|
24 | |
---|
25 | #include "Scantable.h" |
---|
26 | #include "STBaselineTable.h" |
---|
27 | |
---|
28 | |
---|
29 | using namespace casa; |
---|
30 | |
---|
31 | namespace asap { |
---|
32 | |
---|
33 | const String STBaselineTable::name_ = "APPLY_BASELINE"; |
---|
34 | |
---|
35 | STBaselineTable::STBaselineTable(const Scantable& parent) |
---|
36 | : STApplyTable(parent, name_) |
---|
37 | { |
---|
38 | setup(); |
---|
39 | } |
---|
40 | |
---|
41 | STBaselineTable::STBaselineTable(const String &name) |
---|
42 | : STApplyTable(name) |
---|
43 | { |
---|
44 | attachOptionalColumns(); |
---|
45 | } |
---|
46 | |
---|
47 | STBaselineTable::~STBaselineTable() |
---|
48 | { |
---|
49 | } |
---|
50 | |
---|
51 | void STBaselineTable::setup() |
---|
52 | { |
---|
53 | table_.addColumn(ScalarColumnDesc<Bool>("APPLY")); |
---|
54 | table_.addColumn(ScalarColumnDesc<uInt>("FUNC_TYPE")); |
---|
55 | table_.addColumn(ArrayColumnDesc<Int>("FUNC_PARAM")); |
---|
56 | table_.addColumn(ArrayColumnDesc<Float>("FUNC_FPARAM")); |
---|
57 | table_.addColumn(ArrayColumnDesc<uInt>("MASKLIST")); |
---|
58 | table_.addColumn(ArrayColumnDesc<Float>("RESULT")); |
---|
59 | table_.addColumn(ScalarColumnDesc<Float>("RMS")); |
---|
60 | table_.addColumn(ScalarColumnDesc<uInt>("NCHAN")); |
---|
61 | table_.addColumn(ScalarColumnDesc<Float>("CLIP_THRESHOLD")); |
---|
62 | table_.addColumn(ScalarColumnDesc<uInt>("CLIP_ITERATION")); |
---|
63 | table_.addColumn(ScalarColumnDesc<Float>("LF_THRESHOLD")); |
---|
64 | table_.addColumn(ScalarColumnDesc<uInt>("LF_AVERAGE")); |
---|
65 | table_.addColumn(ArrayColumnDesc<uInt>("LF_EDGE")); |
---|
66 | |
---|
67 | table_.rwKeywordSet().define("ApplyType", "BASELINE"); |
---|
68 | |
---|
69 | attachOptionalColumns(); |
---|
70 | } |
---|
71 | |
---|
72 | void STBaselineTable::attachOptionalColumns() |
---|
73 | { |
---|
74 | applyCol_.attach(table_, "APPLY"); |
---|
75 | ftypeCol_.attach(table_, "FUNC_TYPE"); |
---|
76 | fparCol_.attach(table_, "FUNC_PARAM"); |
---|
77 | ffparCol_.attach(table_, "FUNC_FPARAM"); |
---|
78 | maskCol_.attach(table_, "MASKLIST"); |
---|
79 | resCol_.attach(table_, "RESULT"); |
---|
80 | rmsCol_.attach(table_, "RMS"); |
---|
81 | nchanCol_.attach(table_, "NCHAN"); |
---|
82 | cthresCol_.attach(table_, "CLIP_THRESHOLD"); |
---|
83 | citerCol_.attach(table_, "CLIP_ITERATION"); |
---|
84 | lfthresCol_.attach(table_, "LF_THRESHOLD"); |
---|
85 | lfavgCol_.attach(table_, "LF_AVERAGE"); |
---|
86 | lfedgeCol_.attach(table_, "LF_EDGE"); |
---|
87 | } |
---|
88 | |
---|
89 | void STBaselineTable::save(const std::string &filename) |
---|
90 | { |
---|
91 | String inname(filename); |
---|
92 | Path path(inname); |
---|
93 | inname = path.expandedName(); |
---|
94 | table_.deepCopy(inname, Table::New); |
---|
95 | } |
---|
96 | |
---|
97 | void STBaselineTable::setdata(uInt irow, uInt scanno, uInt cycleno, |
---|
98 | uInt beamno, uInt ifno, uInt polno, |
---|
99 | uInt freqid, Double time, |
---|
100 | Bool apply, |
---|
101 | STBaselineFunc::FuncName ftype, |
---|
102 | Vector<Int> fpar, |
---|
103 | Vector<Float> ffpar, |
---|
104 | Vector<uInt> mask, |
---|
105 | Vector<Float> res, |
---|
106 | Float rms, |
---|
107 | uInt nchan, |
---|
108 | Float cthres, |
---|
109 | uInt citer, |
---|
110 | Float lfthres, |
---|
111 | uInt lfavg, |
---|
112 | Vector<uInt> lfedge) |
---|
113 | { |
---|
114 | if (irow >= (uInt)nrow()) { |
---|
115 | throw AipsError("row index out of range"); |
---|
116 | } |
---|
117 | |
---|
118 | if (!sel_.empty()) { |
---|
119 | os_.origin(LogOrigin("STBaselineTable","setdata",WHERE)); |
---|
120 | os_ << LogIO::WARN << "Data selection is effective. Specified row index may be wrong." << LogIO::POST; |
---|
121 | } |
---|
122 | |
---|
123 | setbasedata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time); |
---|
124 | applyCol_.put(irow, apply); |
---|
125 | ftypeCol_.put(irow, uInt(ftype)); |
---|
126 | fparCol_.put(irow, fpar); |
---|
127 | ffparCol_.put(irow, ffpar); |
---|
128 | maskCol_.put(irow, mask); |
---|
129 | resCol_.put(irow, res); |
---|
130 | rmsCol_.put(irow, rms); |
---|
131 | nchanCol_.put(irow, nchan); |
---|
132 | cthresCol_.put(irow, cthres); |
---|
133 | citerCol_.put(irow, citer); |
---|
134 | lfthresCol_.put(irow, lfthres); |
---|
135 | lfavgCol_.put(irow, lfavg); |
---|
136 | lfedgeCol_.put(irow, lfedge); |
---|
137 | } |
---|
138 | |
---|
139 | void STBaselineTable::appenddata(int scanno, int cycleno, |
---|
140 | int beamno, int ifno, int polno, |
---|
141 | int freqid, Double time, |
---|
142 | bool apply, |
---|
143 | STBaselineFunc::FuncName ftype, |
---|
144 | int fpar, |
---|
145 | vector<float> ffpar, |
---|
146 | Vector<uInt> mask, |
---|
147 | vector<float> res, |
---|
148 | float rms, |
---|
149 | int nchan, |
---|
150 | float cthres, |
---|
151 | int citer, |
---|
152 | float lfthres, |
---|
153 | int lfavg, |
---|
154 | vector<int> lfedge) |
---|
155 | { |
---|
156 | vector<int> fparam(1); |
---|
157 | fparam[0] = fpar; |
---|
158 | |
---|
159 | appenddata(scanno, cycleno, beamno, ifno, polno, freqid, time, |
---|
160 | apply, ftype, fparam, ffpar, mask, res, rms, nchan, |
---|
161 | cthres, citer, lfthres, lfavg, lfedge); |
---|
162 | } |
---|
163 | |
---|
164 | void STBaselineTable::appenddata(int scanno, int cycleno, |
---|
165 | int beamno, int ifno, int polno, |
---|
166 | int freqid, Double time, |
---|
167 | bool apply, |
---|
168 | STBaselineFunc::FuncName ftype, |
---|
169 | vector<int> fpar, |
---|
170 | vector<float> ffpar, |
---|
171 | Vector<uInt> mask, |
---|
172 | vector<float> res, |
---|
173 | float rms, |
---|
174 | int nchan, |
---|
175 | float cthres, |
---|
176 | int citer, |
---|
177 | float lfthres, |
---|
178 | int lfavg, |
---|
179 | vector<int> lfedge) |
---|
180 | { |
---|
181 | Vector<Int> fparam(fpar.size()); |
---|
182 | for (uInt i = 0; i < fpar.size(); ++i) { |
---|
183 | fparam[i] = fpar[i]; |
---|
184 | } |
---|
185 | Vector<uInt> edge(lfedge.size()); |
---|
186 | for (uInt i = 0; i < lfedge.size(); ++i) { |
---|
187 | edge[i] = lfedge[i]; |
---|
188 | } |
---|
189 | appenddata(uInt(scanno), uInt(cycleno), uInt(beamno), |
---|
190 | uInt(ifno), uInt(polno), uInt(freqid), time, |
---|
191 | Bool(apply), ftype, fparam, Vector<Float>(ffpar), |
---|
192 | mask, Vector<Float>(res), Float(rms), uInt(nchan), |
---|
193 | Float(cthres), uInt(citer), |
---|
194 | Float(lfthres), uInt(lfavg), edge); |
---|
195 | } |
---|
196 | |
---|
197 | void STBaselineTable::appenddata(uInt scanno, uInt cycleno, |
---|
198 | uInt beamno, uInt ifno, uInt polno, |
---|
199 | uInt freqid, Double time, |
---|
200 | Bool apply, |
---|
201 | STBaselineFunc::FuncName ftype, |
---|
202 | Vector<Int> fpar, |
---|
203 | Vector<Float> ffpar, |
---|
204 | Vector<uInt> mask, |
---|
205 | Vector<Float> res, |
---|
206 | Float rms, |
---|
207 | uInt nchan, |
---|
208 | Float cthres, |
---|
209 | uInt citer, |
---|
210 | Float lfthres, |
---|
211 | uInt lfavg, |
---|
212 | Vector<uInt> lfedge) |
---|
213 | { |
---|
214 | uInt irow = nrow(); |
---|
215 | table_.addRow(1, True); |
---|
216 | setdata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time, |
---|
217 | apply, ftype, fpar, ffpar, mask, res, rms, |
---|
218 | nchan, cthres, citer, lfthres, lfavg, lfedge); |
---|
219 | } |
---|
220 | |
---|
221 | void STBaselineTable::appendbasedata(int scanno, int cycleno, |
---|
222 | int beamno, int ifno, int polno, |
---|
223 | int freqid, Double time) |
---|
224 | { |
---|
225 | uInt irow = nrow(); |
---|
226 | table_.addRow(1, True); |
---|
227 | setbasedata(irow, uInt(scanno), uInt(cycleno), uInt(beamno), uInt(ifno), uInt(polno), uInt(freqid), time); |
---|
228 | } |
---|
229 | |
---|
230 | void STBaselineTable::setresult(casa::uInt irow, |
---|
231 | casa::Vector<casa::Float> res, |
---|
232 | casa::Float rms) |
---|
233 | { |
---|
234 | resCol_.put(irow, res); |
---|
235 | rmsCol_.put(irow, rms); |
---|
236 | } |
---|
237 | |
---|
238 | bool STBaselineTable::getApply(int irow) |
---|
239 | { |
---|
240 | return (bool)applyCol_.get(irow); |
---|
241 | } |
---|
242 | |
---|
243 | void STBaselineTable::setApply(int irow, bool apply) |
---|
244 | { |
---|
245 | applyCol_.put(uInt(irow), Bool(apply)); |
---|
246 | } |
---|
247 | |
---|
248 | Vector<STBaselineFunc::FuncName> STBaselineTable::getFunctionNames() |
---|
249 | { |
---|
250 | Vector<uInt> rawBlfuncColumn = ftypeCol_.getColumn(); |
---|
251 | uInt n = rawBlfuncColumn.nelements(); |
---|
252 | Vector<STBaselineFunc::FuncName> blfuncColumn(n); |
---|
253 | for (uInt i = 0; i < n; ++i) { |
---|
254 | blfuncColumn[i] = STBaselineFunc::FuncName(rawBlfuncColumn(i)); |
---|
255 | } |
---|
256 | return blfuncColumn; |
---|
257 | } |
---|
258 | |
---|
259 | STBaselineFunc::FuncName STBaselineTable::getFunctionName(int irow) |
---|
260 | { |
---|
261 | return STBaselineFunc::FuncName(ftypeCol_.get(irow)); |
---|
262 | } |
---|
263 | |
---|
264 | std::vector<int> STBaselineTable::getFuncParam(int irow) |
---|
265 | { |
---|
266 | Vector<Int> uiparam = fparCol_.get(irow); |
---|
267 | std::vector<int> res(uiparam.size()); |
---|
268 | for (uInt i = 0; i < res.size(); ++i) { |
---|
269 | res[i] = (int)uiparam[i]; |
---|
270 | } |
---|
271 | return res; |
---|
272 | } |
---|
273 | |
---|
274 | std::vector<bool> STBaselineTable::getMask(int irow) |
---|
275 | { |
---|
276 | uInt nchan = getNChan(irow); |
---|
277 | Vector<uInt> masklist = maskCol_.get(irow); |
---|
278 | std::vector<int> masklist1(masklist.size()); |
---|
279 | for (uInt i = 0; i < masklist1.size(); ++i) { |
---|
280 | masklist1[i] = (int)masklist[i]; |
---|
281 | } |
---|
282 | return Scantable::getMaskFromMaskList(nchan, masklist1); |
---|
283 | } |
---|
284 | |
---|
285 | uInt STBaselineTable::getNChan(int irow) |
---|
286 | { |
---|
287 | return nchanCol_.get(irow); |
---|
288 | } |
---|
289 | |
---|
290 | uInt STBaselineTable::nchan(uInt ifno) |
---|
291 | { |
---|
292 | STSelector org = sel_; |
---|
293 | STSelector sel; |
---|
294 | sel.setIFs(vector<int>(1,(int)ifno)); |
---|
295 | setSelection(sel); |
---|
296 | uInt n = nchanCol_(0); |
---|
297 | unsetSelection(); |
---|
298 | if (!org.empty()) |
---|
299 | setSelection(org); |
---|
300 | return n; |
---|
301 | } |
---|
302 | } |
---|