source: branches/casa-release-4_3-test02/src/STBaselineTable.cpp@ 3066

Last change on this file since 3066 was 2883, checked in by WataruKawasaki, 11 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sd

Description: fixed two bugs in Scantable::subBaseline() reported by Kana: (1) RuntimeError "too many channels masked..." occurs when clipniter>0 and (2) RuntimeError "row index is out of range" occurs when outbltable exists.


File size: 8.1 KB
Line 
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{
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
72void 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
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,
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 stringstream ss;
117 ss << "row index out of range[irow=" << irow << "][nrow=" << nrow() << "]";
118 throw AipsError(ss.str());
119 }
120
121 if (!sel_.empty()) {
122 os_.origin(LogOrigin("STBaselineTable","setdata",WHERE));
123 os_ << LogIO::WARN << "Data selection is effective. Specified row index may be wrong." << LogIO::POST;
124 }
125
126 setbasedata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time);
127 applyCol_.put(irow, apply);
128 ftypeCol_.put(irow, uInt(ftype));
129 fparCol_.put(irow, fpar);
130 ffparCol_.put(irow, ffpar);
131 maskCol_.put(irow, mask);
132 resCol_.put(irow, res);
133 rmsCol_.put(irow, rms);
134 nchanCol_.put(irow, nchan);
135 cthresCol_.put(irow, cthres);
136 citerCol_.put(irow, citer);
137 lfthresCol_.put(irow, lfthres);
138 lfavgCol_.put(irow, lfavg);
139 lfedgeCol_.put(irow, lfedge);
140}
141
142void STBaselineTable::appenddata(int scanno, int cycleno,
143 int beamno, int ifno, int polno,
144 int freqid, Double time,
145 bool apply,
146 STBaselineFunc::FuncName ftype,
147 int fpar,
148 vector<float> ffpar,
149 Vector<uInt> mask,
150 vector<float> res,
151 float rms,
152 int nchan,
153 float cthres,
154 int citer,
155 float lfthres,
156 int lfavg,
157 vector<int> lfedge)
158{
159 vector<int> fparam(1);
160 fparam[0] = fpar;
161
162 appenddata(scanno, cycleno, beamno, ifno, polno, freqid, time,
163 apply, ftype, fparam, ffpar, mask, res, rms, nchan,
164 cthres, citer, lfthres, lfavg, lfedge);
165}
166
167void STBaselineTable::appenddata(int scanno, int cycleno,
168 int beamno, int ifno, int polno,
169 int freqid, Double time,
170 bool apply,
171 STBaselineFunc::FuncName ftype,
172 vector<int> fpar,
173 vector<float> ffpar,
174 Vector<uInt> mask,
175 vector<float> res,
176 float rms,
177 int nchan,
178 float cthres,
179 int citer,
180 float lfthres,
181 int lfavg,
182 vector<int> lfedge)
183{
184 Vector<Int> fparam(fpar.size());
185 for (uInt i = 0; i < fpar.size(); ++i) {
186 fparam[i] = fpar[i];
187 }
188 Vector<uInt> edge(lfedge.size());
189 for (uInt i = 0; i < lfedge.size(); ++i) {
190 edge[i] = lfedge[i];
191 }
192 appenddata(uInt(scanno), uInt(cycleno), uInt(beamno),
193 uInt(ifno), uInt(polno), uInt(freqid), time,
194 Bool(apply), ftype, fparam, Vector<Float>(ffpar),
195 mask, Vector<Float>(res), Float(rms), uInt(nchan),
196 Float(cthres), uInt(citer),
197 Float(lfthres), uInt(lfavg), edge);
198}
199
200void STBaselineTable::appenddata(uInt scanno, uInt cycleno,
201 uInt beamno, uInt ifno, uInt polno,
202 uInt freqid, Double time,
203 Bool apply,
204 STBaselineFunc::FuncName ftype,
205 Vector<Int> fpar,
206 Vector<Float> ffpar,
207 Vector<uInt> mask,
208 Vector<Float> res,
209 Float rms,
210 uInt nchan,
211 Float cthres,
212 uInt citer,
213 Float lfthres,
214 uInt lfavg,
215 Vector<uInt> lfedge)
216{
217 uInt irow = nrow();
218 table_.addRow(1, True);
219 setdata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time,
220 apply, ftype, fpar, ffpar, mask, res, rms,
221 nchan, cthres, citer, lfthres, lfavg, lfedge);
222}
223
224void STBaselineTable::appendbasedata(int scanno, int cycleno,
225 int beamno, int ifno, int polno,
226 int freqid, Double time)
227{
228 uInt irow = nrow();
229 table_.addRow(1, True);
230 setbasedata(irow, uInt(scanno), uInt(cycleno), uInt(beamno), uInt(ifno), uInt(polno), uInt(freqid), time);
231}
232
233void STBaselineTable::setresult(casa::uInt irow,
234 casa::Vector<casa::Float> res,
235 casa::Float rms)
236{
237 resCol_.put(irow, res);
238 rmsCol_.put(irow, rms);
239}
240
241bool STBaselineTable::getApply(int irow)
242{
243 return (bool)applyCol_.get(irow);
244}
245
246void STBaselineTable::setApply(int irow, bool apply)
247{
248 applyCol_.put(uInt(irow), Bool(apply));
249}
250
251Vector<STBaselineFunc::FuncName> STBaselineTable::getFunctionNames()
252{
253 Vector<uInt> rawBlfuncColumn = ftypeCol_.getColumn();
254 uInt n = rawBlfuncColumn.nelements();
255 Vector<STBaselineFunc::FuncName> blfuncColumn(n);
256 for (uInt i = 0; i < n; ++i) {
257 blfuncColumn[i] = STBaselineFunc::FuncName(rawBlfuncColumn(i));
258 }
259 return blfuncColumn;
260}
261
262STBaselineFunc::FuncName STBaselineTable::getFunctionName(int irow)
263{
264 return STBaselineFunc::FuncName(ftypeCol_.get(irow));
265}
266
267std::vector<int> STBaselineTable::getFuncParam(int irow)
268{
269 Vector<Int> uiparam = fparCol_.get(irow);
270 std::vector<int> res(uiparam.size());
271 for (uInt i = 0; i < res.size(); ++i) {
272 res[i] = (int)uiparam[i];
273 }
274 return res;
275}
276
277std::vector<bool> STBaselineTable::getMask(int irow)
278{
279 uInt nchan = getNChan(irow);
280 Vector<uInt> masklist = maskCol_.get(irow);
281 std::vector<int> masklist1(masklist.size());
282 for (uInt i = 0; i < masklist1.size(); ++i) {
283 masklist1[i] = (int)masklist[i];
284 }
285 return Scantable::getMaskFromMaskList(nchan, masklist1);
286}
287
288uInt STBaselineTable::getNChan(int irow)
289{
290 return nchanCol_.get(irow);
291}
292
293uInt STBaselineTable::nchan(uInt ifno)
294{
295 STSelector org = sel_;
296 STSelector sel;
297 sel.setIFs(vector<int>(1,(int)ifno));
298 setSelection(sel);
299 uInt n = nchanCol_(0);
300 unsetSelection();
301 if (!org.empty())
302 setSelection(org);
303 return n;
304}
305}
Note: See TracBrowser for help on using the repository browser.