source: trunk/src/STBaselineTable.cpp@ 2782

Last change on this file since 2782 was 2773, checked in by WataruKawasaki, 12 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: Yes

Module(s): sd

Description: optimisation/refactoring the baselining functions for scantable.


File size: 7.9 KB
RevLine 
[2738]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
29using namespace casa;
30
31namespace asap {
32
33const String STBaselineTable::name_ = "APPLY_BASELINE";
34
35STBaselineTable::STBaselineTable(const Scantable& parent)
36 : STApplyTable(parent, name_)
37{
38 setup();
39}
40
41STBaselineTable::STBaselineTable(const String &name)
42 : STApplyTable(name)
43{
44 attachOptionalColumns();
45}
46
47STBaselineTable::~STBaselineTable()
48{
49}
50
51void STBaselineTable::setup()
52{
[2767]53 table_.addColumn(ScalarColumnDesc<Bool>("APPLY"));
[2740]54 table_.addColumn(ScalarColumnDesc<uInt>("FUNC_TYPE"));
[2767]55 table_.addColumn(ArrayColumnDesc<Int>("FUNC_PARAM"));
[2740]56 table_.addColumn(ArrayColumnDesc<Float>("FUNC_FPARAM"));
57 table_.addColumn(ArrayColumnDesc<uInt>("MASKLIST"));
58 table_.addColumn(ArrayColumnDesc<Float>("RESULT"));
[2738]59 table_.addColumn(ScalarColumnDesc<Float>("RMS"));
[2767]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"));
[2738]66
67 table_.rwKeywordSet().define("ApplyType", "BASELINE");
68
69 attachOptionalColumns();
70}
71
72void STBaselineTable::attachOptionalColumns()
73{
[2767]74 applyCol_.attach(table_, "APPLY");
[2740]75 ftypeCol_.attach(table_, "FUNC_TYPE");
76 fparCol_.attach(table_, "FUNC_PARAM");
77 ffparCol_.attach(table_, "FUNC_FPARAM");
[2738]78 maskCol_.attach(table_, "MASKLIST");
[2740]79 resCol_.attach(table_, "RESULT");
[2738]80 rmsCol_.attach(table_, "RMS");
[2767]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");
[2738]87}
88
89void 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
97void STBaselineTable::setdata(uInt irow, uInt scanno, uInt cycleno,
[2740]98 uInt beamno, uInt ifno, uInt polno,
99 uInt freqid, Double time,
[2767]100 Bool apply,
[2740]101 STBaselineFunc::FuncName ftype,
[2767]102 Vector<Int> fpar,
[2740]103 Vector<Float> ffpar,
104 Vector<uInt> mask,
105 Vector<Float> res,
[2767]106 Float rms,
107 uInt nchan,
108 Float cthres,
109 uInt citer,
110 Float lfthres,
111 uInt lfavg,
112 Vector<uInt> lfedge)
[2738]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);
[2767]124 applyCol_.put(irow, apply);
[2740]125 ftypeCol_.put(irow, uInt(ftype));
126 fparCol_.put(irow, fpar);
127 ffparCol_.put(irow, ffpar);
[2738]128 maskCol_.put(irow, mask);
[2740]129 resCol_.put(irow, res);
[2738]130 rmsCol_.put(irow, rms);
[2767]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);
[2738]137}
138
[2773]139void 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
164void 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
[2738]197void STBaselineTable::appenddata(uInt scanno, uInt cycleno,
[2740]198 uInt beamno, uInt ifno, uInt polno,
199 uInt freqid, Double time,
[2767]200 Bool apply,
[2740]201 STBaselineFunc::FuncName ftype,
[2767]202 Vector<Int> fpar,
[2740]203 Vector<Float> ffpar,
204 Vector<uInt> mask,
205 Vector<Float> res,
[2767]206 Float rms,
207 uInt nchan,
208 Float cthres,
209 uInt citer,
210 Float lfthres,
211 uInt lfavg,
212 Vector<uInt> lfedge)
[2738]213{
214 uInt irow = nrow();
215 table_.addRow(1, True);
216 setdata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time,
[2767]217 apply, ftype, fpar, ffpar, mask, res, rms,
218 nchan, cthres, citer, lfthres, lfavg, lfedge);
[2738]219}
220
[2767]221void STBaselineTable::appendbasedata(int scanno, int cycleno,
222 int beamno, int ifno, int polno,
223 int freqid, Double time)
[2738]224{
[2767]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
230void 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
238bool STBaselineTable::getApply(int irow)
239{
240 return (bool)applyCol_.get(irow);
241}
242
243void STBaselineTable::setApply(int irow, bool apply)
244{
245 applyCol_.put(uInt(irow), Bool(apply));
246}
247
248Vector<STBaselineFunc::FuncName> STBaselineTable::getFunctionNames()
249{
[2740]250 Vector<uInt> rawBlfuncColumn = ftypeCol_.getColumn();
[2738]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
[2767]259STBaselineFunc::FuncName STBaselineTable::getFunctionName(int irow)
260{
261 return STBaselineFunc::FuncName(ftypeCol_.get(irow));
262}
263
264std::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
274std::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
285uInt STBaselineTable::getNChan(int irow)
286{
287 return nchanCol_.get(irow);
288}
289
[2738]290uInt 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}
Note: See TracBrowser for help on using the repository browser.