[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 | |
---|
| 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 | { |
---|
[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 | |
---|
| 72 | void 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 | |
---|
| 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, |
---|
[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()) { |
---|
[2883] | 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()); |
---|
[2738] | 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); |
---|
[2767] | 127 | applyCol_.put(irow, apply); |
---|
[2740] | 128 | ftypeCol_.put(irow, uInt(ftype)); |
---|
| 129 | fparCol_.put(irow, fpar); |
---|
| 130 | ffparCol_.put(irow, ffpar); |
---|
[2738] | 131 | maskCol_.put(irow, mask); |
---|
[2740] | 132 | resCol_.put(irow, res); |
---|
[2738] | 133 | rmsCol_.put(irow, rms); |
---|
[2767] | 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); |
---|
[2738] | 140 | } |
---|
| 141 | |
---|
[2773] | 142 | void 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 | |
---|
| 167 | void 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 | |
---|
[2738] | 200 | void STBaselineTable::appenddata(uInt scanno, uInt cycleno, |
---|
[2740] | 201 | uInt beamno, uInt ifno, uInt polno, |
---|
| 202 | uInt freqid, Double time, |
---|
[2767] | 203 | Bool apply, |
---|
[2740] | 204 | STBaselineFunc::FuncName ftype, |
---|
[2767] | 205 | Vector<Int> fpar, |
---|
[2740] | 206 | Vector<Float> ffpar, |
---|
| 207 | Vector<uInt> mask, |
---|
| 208 | Vector<Float> res, |
---|
[2767] | 209 | Float rms, |
---|
| 210 | uInt nchan, |
---|
| 211 | Float cthres, |
---|
| 212 | uInt citer, |
---|
| 213 | Float lfthres, |
---|
| 214 | uInt lfavg, |
---|
| 215 | Vector<uInt> lfedge) |
---|
[2738] | 216 | { |
---|
| 217 | uInt irow = nrow(); |
---|
| 218 | table_.addRow(1, True); |
---|
| 219 | setdata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time, |
---|
[2767] | 220 | apply, ftype, fpar, ffpar, mask, res, rms, |
---|
| 221 | nchan, cthres, citer, lfthres, lfavg, lfedge); |
---|
[2738] | 222 | } |
---|
| 223 | |
---|
[2767] | 224 | void STBaselineTable::appendbasedata(int scanno, int cycleno, |
---|
| 225 | int beamno, int ifno, int polno, |
---|
| 226 | int freqid, Double time) |
---|
[2738] | 227 | { |
---|
[2767] | 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 | |
---|
| 233 | void 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 | |
---|
| 241 | bool STBaselineTable::getApply(int irow) |
---|
| 242 | { |
---|
| 243 | return (bool)applyCol_.get(irow); |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | void STBaselineTable::setApply(int irow, bool apply) |
---|
| 247 | { |
---|
| 248 | applyCol_.put(uInt(irow), Bool(apply)); |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | Vector<STBaselineFunc::FuncName> STBaselineTable::getFunctionNames() |
---|
| 252 | { |
---|
[2740] | 253 | Vector<uInt> rawBlfuncColumn = ftypeCol_.getColumn(); |
---|
[2738] | 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 | |
---|
[2767] | 262 | STBaselineFunc::FuncName STBaselineTable::getFunctionName(int irow) |
---|
| 263 | { |
---|
| 264 | return STBaselineFunc::FuncName(ftypeCol_.get(irow)); |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | std::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 | |
---|
| 277 | std::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 | |
---|
| 288 | uInt STBaselineTable::getNChan(int irow) |
---|
| 289 | { |
---|
| 290 | return nchanCol_.get(irow); |
---|
| 291 | } |
---|
| 292 | |
---|
[2738] | 293 | uInt 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 | } |
---|