source: trunk/src/STBaselineTable.cpp @ 2767

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

New Development: Yes

JIRA Issue: Yes CAS-4794

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sd

Description: functions to apply/write STBaselineTable in which baseline parameters stored.


File size: 6.4 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  }
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
139void STBaselineTable::appenddata(uInt scanno, uInt cycleno,
140                                 uInt beamno, uInt ifno, uInt polno,
141                                 uInt freqid, Double time,
142                                 Bool apply,
143                                 STBaselineFunc::FuncName ftype,
144                                 Vector<Int> fpar,
145                                 Vector<Float> ffpar,
146                                 Vector<uInt> mask,
147                                 Vector<Float> res,
148                                 Float rms,
149                                 uInt nchan,
150                                 Float cthres,
151                                 uInt citer,
152                                 Float lfthres,
153                                 uInt lfavg,
154                                 Vector<uInt> lfedge)
155{
156  uInt irow = nrow();
157  table_.addRow(1, True);
158  setdata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time,
159          apply, ftype, fpar, ffpar, mask, res, rms,
160          nchan, cthres, citer, lfthres, lfavg, lfedge);
161}
162
163void STBaselineTable::appendbasedata(int scanno, int cycleno,
164                                     int beamno, int ifno, int polno,
165                                     int freqid, Double time)
166{
167  uInt irow = nrow();
168  table_.addRow(1, True);
169  setbasedata(irow, uInt(scanno), uInt(cycleno), uInt(beamno), uInt(ifno), uInt(polno), uInt(freqid), time);
170}
171
172void STBaselineTable::setresult(casa::uInt irow,
173                                casa::Vector<casa::Float> res,
174                                casa::Float rms)
175{
176  resCol_.put(irow, res);
177  rmsCol_.put(irow, rms);
178}
179
180bool STBaselineTable::getApply(int irow)
181{
182  return (bool)applyCol_.get(irow);
183}
184
185void STBaselineTable::setApply(int irow, bool apply)
186{
187  applyCol_.put(uInt(irow), Bool(apply));
188}
189
190Vector<STBaselineFunc::FuncName> STBaselineTable::getFunctionNames()
191{
192  Vector<uInt> rawBlfuncColumn = ftypeCol_.getColumn();
193  uInt n = rawBlfuncColumn.nelements();
194  Vector<STBaselineFunc::FuncName> blfuncColumn(n);
195  for (uInt i = 0; i < n; ++i) {
196    blfuncColumn[i] = STBaselineFunc::FuncName(rawBlfuncColumn(i));
197  }
198  return blfuncColumn;
199}
200
201STBaselineFunc::FuncName STBaselineTable::getFunctionName(int irow)
202{
203  return STBaselineFunc::FuncName(ftypeCol_.get(irow));
204}
205
206std::vector<int> STBaselineTable::getFuncParam(int irow)
207{
208  Vector<Int> uiparam = fparCol_.get(irow);
209  std::vector<int> res(uiparam.size());
210  for (uInt i = 0; i < res.size(); ++i) {
211    res[i] = (int)uiparam[i];
212  }
213  return res;
214}
215
216std::vector<bool> STBaselineTable::getMask(int irow)
217{
218  uInt nchan = getNChan(irow);
219  Vector<uInt> masklist = maskCol_.get(irow);
220  std::vector<int> masklist1(masklist.size());
221  for (uInt i = 0; i < masklist1.size(); ++i) {
222    masklist1[i] = (int)masklist[i];
223  }
224  return Scantable::getMaskFromMaskList(nchan, masklist1);
225}
226
227uInt STBaselineTable::getNChan(int irow)
228{
229  return nchanCol_.get(irow);
230}
231
232uInt STBaselineTable::nchan(uInt ifno)
233{
234  STSelector org = sel_;
235  STSelector sel;
236  sel.setIFs(vector<int>(1,(int)ifno));
237  setSelection(sel);
238  uInt n = nchanCol_(0);
239  unsetSelection();
240  if (!org.empty())
241    setSelection(org);
242  return n;
243}
244}
Note: See TracBrowser for help on using the repository browser.