[2703] | 1 | // |
---|
| 2 | // C++ Implementation: STCalTsysTable |
---|
| 3 | // |
---|
| 4 | // Description: |
---|
| 5 | // |
---|
| 6 | // |
---|
| 7 | // Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp> (C) 2012 |
---|
| 8 | // |
---|
| 9 | // Copyright: See COPYING file that comes with this distribution |
---|
| 10 | // |
---|
| 11 | // |
---|
[2724] | 12 | #include <assert.h> |
---|
| 13 | |
---|
[2703] | 14 | #include <casa/Exceptions/Error.h> |
---|
[2756] | 15 | #include <casa/Utilities/Assert.h> |
---|
[2703] | 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> |
---|
[2955] | 21 | #include <tables/Tables/TableIter.h> |
---|
[2703] | 22 | #include <measures/TableMeasures/TableMeasDesc.h> |
---|
| 23 | #include <measures/TableMeasures/TableMeasRefDesc.h> |
---|
| 24 | #include <measures/TableMeasures/TableMeasValueDesc.h> |
---|
| 25 | |
---|
| 26 | #include "Scantable.h" |
---|
| 27 | #include "STCalTsysTable.h" |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | using namespace casa; |
---|
| 31 | |
---|
| 32 | namespace asap { |
---|
| 33 | |
---|
| 34 | const String STCalTsysTable::name_ = "APPLY_TSYS"; |
---|
| 35 | |
---|
| 36 | STCalTsysTable::STCalTsysTable(const Scantable& parent) |
---|
| 37 | : STApplyTable(parent, name_) |
---|
| 38 | { |
---|
| 39 | setup(); |
---|
| 40 | } |
---|
| 41 | |
---|
[2720] | 42 | STCalTsysTable::STCalTsysTable(const String &name) |
---|
| 43 | : STApplyTable(name) |
---|
| 44 | { |
---|
[2955] | 45 | if (!table_.tableDesc().isColumn("FLAGTRA")) { |
---|
| 46 | LogIO os(LogOrigin("STCalTsysTable", "STCalTsysTable", WHERE)); |
---|
| 47 | os << "Adding FLAGTRA column to " << name << " with initial value of 0 (all data valid)." << LogIO::POST; |
---|
| 48 | table_.addColumn(ArrayColumnDesc<uChar>("FLAGTRA")); |
---|
| 49 | TableIterator iter(table_, "IFNO"); |
---|
| 50 | while (!iter.pastEnd()) { |
---|
| 51 | Table t = iter.table(); |
---|
| 52 | ArrayColumn<Float> tsysCol(t, "TSYS"); |
---|
| 53 | IPosition shape(2, tsysCol.shape(0)[0], t.nrow()); |
---|
| 54 | ArrayColumn<uChar> flagtraCol(t, "FLAGTRA"); |
---|
| 55 | Array<uChar> flagtra(shape, (uChar)0); |
---|
| 56 | flagtraCol.putColumn(flagtra); |
---|
| 57 | iter.next(); |
---|
| 58 | } |
---|
| 59 | } |
---|
| 60 | |
---|
[2720] | 61 | attachOptionalColumns(); |
---|
| 62 | } |
---|
| 63 | |
---|
[2703] | 64 | STCalTsysTable::~STCalTsysTable() |
---|
| 65 | { |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | void STCalTsysTable::setup() |
---|
| 69 | { |
---|
| 70 | table_.addColumn(ArrayColumnDesc<Float>("TSYS")); |
---|
[2955] | 71 | table_.addColumn(ArrayColumnDesc<uChar>("FLAGTRA")); |
---|
[2703] | 72 | table_.addColumn(ScalarColumnDesc<Float>("ELEVATION")); |
---|
| 73 | |
---|
[2720] | 74 | table_.rwKeywordSet().define("ApplyType", "CALTSYS"); |
---|
[2703] | 75 | |
---|
| 76 | attachOptionalColumns(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | void STCalTsysTable::attachOptionalColumns() |
---|
| 80 | { |
---|
| 81 | tsysCol_.attach(table_, "TSYS"); |
---|
[2955] | 82 | flagtraCol_.attach(table_, "FLAGTRA"); |
---|
[2703] | 83 | elCol_.attach(table_,"ELEVATION"); |
---|
| 84 | |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | void STCalTsysTable::setdata(uInt irow, uInt scanno, uInt cycleno, |
---|
[2720] | 88 | uInt beamno, uInt ifno, uInt polno, uInt freqid, |
---|
[2955] | 89 | Double time, Float elevation, |
---|
| 90 | const Vector<Float> &tsys, |
---|
| 91 | const Vector<uChar> &flagtra) |
---|
[2703] | 92 | { |
---|
| 93 | if (irow >= (uInt)nrow()) { |
---|
| 94 | throw AipsError("row index out of range"); |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if (!sel_.empty()) { |
---|
| 98 | os_.origin(LogOrigin("STCalTsysTable","setdata",WHERE)); |
---|
| 99 | os_ << LogIO::WARN << "Data selection is effective. Specified row index may be wrong." << LogIO::POST; |
---|
| 100 | } |
---|
| 101 | |
---|
[2720] | 102 | setbasedata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time); |
---|
[2703] | 103 | elCol_.put(irow, elevation); |
---|
| 104 | tsysCol_.put(irow, tsys); |
---|
[2955] | 105 | flagtraCol_.put(irow, flagtra); |
---|
[2703] | 106 | } |
---|
| 107 | |
---|
| 108 | void STCalTsysTable::appenddata(uInt scanno, uInt cycleno, |
---|
[2720] | 109 | uInt beamno, uInt ifno, uInt polno, uInt freqid, |
---|
[2955] | 110 | Double time, Float elevation, |
---|
| 111 | const Vector<Float> &tsys, |
---|
| 112 | const Vector<uChar> &flagtra) |
---|
[2703] | 113 | { |
---|
| 114 | uInt irow = nrow(); |
---|
| 115 | table_.addRow(1, True); |
---|
[2955] | 116 | setdata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time, elevation, |
---|
| 117 | tsys, flagtra); |
---|
[2703] | 118 | } |
---|
[2720] | 119 | |
---|
| 120 | uInt STCalTsysTable::nchan(uInt ifno) |
---|
| 121 | { |
---|
| 122 | STSelector org = sel_; |
---|
| 123 | STSelector sel; |
---|
| 124 | sel.setIFs(vector<int>(1,(int)ifno)); |
---|
| 125 | setSelection(sel); |
---|
| 126 | uInt n = tsysCol_(0).nelements(); |
---|
| 127 | unsetSelection(); |
---|
| 128 | if (!org.empty()) |
---|
| 129 | setSelection(org); |
---|
| 130 | return n; |
---|
[2703] | 131 | } |
---|
[2720] | 132 | |
---|
| 133 | Vector<Double> STCalTsysTable::getBaseFrequency(uInt whichrow) |
---|
| 134 | { |
---|
[2756] | 135 | //assert(whichrow < nrow()); |
---|
| 136 | assert_<AipsError>(whichrow < nrow(), "row index out of range."); |
---|
[2720] | 137 | uInt freqid = freqidCol_(whichrow); |
---|
| 138 | uInt nc = tsysCol_(whichrow).nelements(); |
---|
| 139 | Block<Double> f = getFrequenciesRow(freqid); |
---|
| 140 | Vector<Double> freqs(nc); |
---|
| 141 | indgen(freqs, f[1]-f[0]*f[2], f[2]); |
---|
| 142 | return freqs; |
---|
| 143 | } |
---|
| 144 | } |
---|