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<uInt>("NCHAN"));
|
---|
54 | table_.addColumn(ScalarColumnDesc<uInt>("FUNCTION"));
|
---|
55 | table_.addColumn(ScalarColumnDesc<uInt>("ORDER"));
|
---|
56 | table_.addColumn(ScalarColumnDesc<uInt>("CLIP_ITERATION"));
|
---|
57 | table_.addColumn(ScalarColumnDesc<Float>("CLIP_THRESHOLD"));
|
---|
58 | table_.addColumn(ArrayColumnDesc<Float>("SECTION"));
|
---|
59 | table_.addColumn(ArrayColumnDesc<Float>("PARAMETER"));
|
---|
60 | table_.addColumn(ArrayColumnDesc<Float>("MASKLIST"));
|
---|
61 | table_.addColumn(ScalarColumnDesc<Float>("RMS"));
|
---|
62 |
|
---|
63 | table_.rwKeywordSet().define("ApplyType", "BASELINE");
|
---|
64 |
|
---|
65 | attachOptionalColumns();
|
---|
66 | }
|
---|
67 |
|
---|
68 | void STBaselineTable::attachOptionalColumns()
|
---|
69 | {
|
---|
70 | nchanCol_.attach(table_, "NCHAN");
|
---|
71 | funcCol_.attach(table_, "FUNCTION");
|
---|
72 | orderCol_.attach(table_, "ORDER");
|
---|
73 | clipiterCol_.attach(table_, "CLIP_ITERATION");
|
---|
74 | clipthresCol_.attach(table_, "CLIP_THRESHOLD");
|
---|
75 | sectCol_.attach(table_, "SECTION");
|
---|
76 | paramCol_.attach(table_, "PARAMETER");
|
---|
77 | maskCol_.attach(table_, "MASKLIST");
|
---|
78 | rmsCol_.attach(table_, "RMS");
|
---|
79 | }
|
---|
80 |
|
---|
81 | void STBaselineTable::save(const std::string &filename)
|
---|
82 | {
|
---|
83 | String inname(filename);
|
---|
84 | Path path(inname);
|
---|
85 | inname = path.expandedName();
|
---|
86 | table_.deepCopy(inname, Table::New);
|
---|
87 | }
|
---|
88 |
|
---|
89 | void STBaselineTable::setdata(uInt irow, uInt scanno, uInt cycleno,
|
---|
90 | uInt beamno, uInt ifno, uInt polno, uInt freqid,
|
---|
91 | Double time, uInt nchan, STBaselineFunc::FuncName func, uInt order,
|
---|
92 | uInt clipiter, Float clipthres,
|
---|
93 | Vector<Float> sect, Vector<Float> param,
|
---|
94 | Vector<Float> mask, Float rms)
|
---|
95 | {
|
---|
96 | if (irow >= (uInt)nrow()) {
|
---|
97 | throw AipsError("row index out of range");
|
---|
98 | }
|
---|
99 |
|
---|
100 | if (!sel_.empty()) {
|
---|
101 | os_.origin(LogOrigin("STBaselineTable","setdata",WHERE));
|
---|
102 | os_ << LogIO::WARN << "Data selection is effective. Specified row index may be wrong." << LogIO::POST;
|
---|
103 | }
|
---|
104 |
|
---|
105 | setbasedata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time);
|
---|
106 | nchanCol_.put(irow, nchan);
|
---|
107 | funcCol_.put(irow, uInt(func));
|
---|
108 | orderCol_.put(irow, order);
|
---|
109 | clipiterCol_.put(irow, clipiter);
|
---|
110 | clipthresCol_.put(irow, clipthres);
|
---|
111 | sectCol_.put(irow, sect);
|
---|
112 | paramCol_.put(irow, param);
|
---|
113 | maskCol_.put(irow, mask);
|
---|
114 | rmsCol_.put(irow, rms);
|
---|
115 | }
|
---|
116 |
|
---|
117 | void STBaselineTable::appenddata(uInt scanno, uInt cycleno,
|
---|
118 | uInt beamno, uInt ifno, uInt polno, uInt freqid,
|
---|
119 | Double time, uInt nchan, STBaselineFunc::FuncName func, uInt order,
|
---|
120 | uInt clipiter, Float clipthres,
|
---|
121 | Vector<Float> sect, Vector<Float> param,
|
---|
122 | Vector<Float> mask, Float rms)
|
---|
123 | {
|
---|
124 | uInt irow = nrow();
|
---|
125 | table_.addRow(1, True);
|
---|
126 | setdata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time,
|
---|
127 | nchan, func, order, clipiter, clipthres, sect, param, mask, rms);
|
---|
128 | }
|
---|
129 |
|
---|
130 | Vector<STBaselineFunc::FuncName> STBaselineTable::getFunctionAsString()
|
---|
131 | {
|
---|
132 | Vector<uInt> rawBlfuncColumn = funcCol_.getColumn();
|
---|
133 | uInt n = rawBlfuncColumn.nelements();
|
---|
134 | Vector<STBaselineFunc::FuncName> blfuncColumn(n);
|
---|
135 | for (uInt i = 0; i < n; ++i) {
|
---|
136 | blfuncColumn[i] = STBaselineFunc::FuncName(rawBlfuncColumn(i));
|
---|
137 | }
|
---|
138 | return blfuncColumn;
|
---|
139 | }
|
---|
140 |
|
---|
141 | uInt STBaselineTable::nchan(uInt ifno)
|
---|
142 | {
|
---|
143 | STSelector org = sel_;
|
---|
144 | STSelector sel;
|
---|
145 | sel.setIFs(vector<int>(1,(int)ifno));
|
---|
146 | setSelection(sel);
|
---|
147 | uInt n = nchanCol_(0);
|
---|
148 | unsetSelection();
|
---|
149 | if (!org.empty())
|
---|
150 | setSelection(org);
|
---|
151 | return n;
|
---|
152 | }
|
---|
153 | }
|
---|