1 | //
|
---|
2 | // C++ Implementation: STCalSkyPSAlma
|
---|
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 | //
|
---|
12 |
|
---|
13 | #include <vector>
|
---|
14 | #include "STSelector.h"
|
---|
15 | #include "STCalSkyPSAlma.h"
|
---|
16 | #include "RowAccumulator.h"
|
---|
17 | #include "STIdxIter.h"
|
---|
18 | #include "STDefs.h"
|
---|
19 | #include <atnf/PKSIO/SrcType.h>
|
---|
20 |
|
---|
21 | using namespace std;
|
---|
22 | using namespace casa;
|
---|
23 |
|
---|
24 | namespace asap {
|
---|
25 | STCalSkyPSAlma::STCalSkyPSAlma(CountedPtr<Scantable> &s)
|
---|
26 | : STCalibration(s)
|
---|
27 | {
|
---|
28 | applytable_ = new STCalSkyTable(*s, "PS");
|
---|
29 | }
|
---|
30 |
|
---|
31 | void STCalSkyPSAlma::calibrate()
|
---|
32 | {
|
---|
33 | vector<int> types(1,SrcType::PSOFF);
|
---|
34 | STSelector selOrg = scantable_->getSelection();
|
---|
35 | STSelector sel;
|
---|
36 | sel.setTypes(types);
|
---|
37 | scantable_->setSelection(sel);
|
---|
38 |
|
---|
39 | fillCalTable();
|
---|
40 |
|
---|
41 | scantable_->setSelection(selOrg);
|
---|
42 | }
|
---|
43 |
|
---|
44 | void STCalSkyPSAlma::fillCalTable()
|
---|
45 | {
|
---|
46 | RowAccumulator acc(W_TINT);
|
---|
47 |
|
---|
48 | vector<string> cols(3);
|
---|
49 | cols[0] = "IFNO";
|
---|
50 | cols[1] = "POLNO";
|
---|
51 | cols[2] = "BEAMNO";
|
---|
52 | STIdxIterAcc iter(scantable_, cols);
|
---|
53 |
|
---|
54 | ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(scantable_->table(), "TIME");
|
---|
55 | Vector<Double> timeSec = tcol->getColumn() * 86400.0;
|
---|
56 | tcol->attach(scantable_->table(), "INTERVAL");
|
---|
57 | Vector<Double> intervalSec = tcol->getColumn();
|
---|
58 | delete tcol;
|
---|
59 | ROScalarColumn<Float> *ecol = new ROScalarColumn<Float>(scantable_->table(), "ELEVATION");
|
---|
60 | Vector<Float> elevation = ecol->getColumn();
|
---|
61 | delete ecol;
|
---|
62 |
|
---|
63 | ROArrayColumn<Float> specCol(scantable_->table(), "SPECTRA");
|
---|
64 | ROArrayColumn<uChar> flagCol(scantable_->table(), "FLAGTRA");
|
---|
65 |
|
---|
66 | // dummy Tsys: the following process doesn't need Tsys but RowAccumulator
|
---|
67 | // requires to set it with spectral data
|
---|
68 | Vector<Float> tsys(1, 1.0);
|
---|
69 |
|
---|
70 | Double timeCen = 0.0;
|
---|
71 | Float elCen = 0.0;
|
---|
72 | uInt count = 0;
|
---|
73 |
|
---|
74 | while(!iter.pastEnd()) {
|
---|
75 | Vector<uInt> rows = iter.getRows(SHARE);
|
---|
76 | Vector<uInt> current = iter.current();
|
---|
77 | uInt len = rows.nelements();
|
---|
78 | if (len == 0) {
|
---|
79 | iter.next();
|
---|
80 | continue;
|
---|
81 | }
|
---|
82 |
|
---|
83 | uInt nchan = scantable_->nchan(scantable_->getIF(rows[0]));
|
---|
84 | Vector<uChar> flag(nchan);
|
---|
85 | Vector<Bool> bflag(nchan);
|
---|
86 | Vector<Float> spec(nchan);
|
---|
87 |
|
---|
88 | Vector<Double> timeSep(len);
|
---|
89 | for (uInt i = 0; i < len-1; i++) {
|
---|
90 | timeSep[i] = timeSec[rows[i+1]] - timeSec[rows[i]] ;
|
---|
91 | }
|
---|
92 | Double tMedian = median(timeSep(IPosition(1,0), IPosition(1,len-2)));
|
---|
93 | timeSep[len-1] = tMedian * 10000.0 ; // any large value
|
---|
94 |
|
---|
95 | uInt irow ;
|
---|
96 | uInt jrow ;
|
---|
97 | for (uInt i = 0; i < len; i++) {
|
---|
98 | irow = rows[i];
|
---|
99 | jrow = (i < len-1) ? rows[i+1] : rows[i];
|
---|
100 | // accumulate data
|
---|
101 | flagCol.get(irow, flag);
|
---|
102 | convertArray(bflag, flag);
|
---|
103 | specCol.get(irow, spec);
|
---|
104 | if ( !allEQ(bflag,True) )
|
---|
105 | acc.add( spec, !bflag, tsys, intervalSec[irow], timeSec[irow] ) ;
|
---|
106 | timeCen += timeSec[irow];
|
---|
107 | elCen += elevation[irow];
|
---|
108 | count++;
|
---|
109 |
|
---|
110 | // check time gap
|
---|
111 | double gap = 2.0 * timeSep[i] / (intervalSec[jrow] + intervalSec[irow]);
|
---|
112 | if ( gap > 1.1 ) {
|
---|
113 | if ( acc.state() ) {
|
---|
114 | acc.replaceNaN() ;
|
---|
115 | // const Vector<Bool> &msk = acc.getMask();
|
---|
116 | // convertArray(flag, !msk);
|
---|
117 | // for (uInt k = 0; k < nchan; ++k) {
|
---|
118 | // uChar userFlag = 1 << 7;
|
---|
119 | // if (msk[k]==True) userFlag = 0 << 7;
|
---|
120 | // flag(k) = userFlag;
|
---|
121 | // }
|
---|
122 | timeCen /= (Double)count * 86400.0; // sec->day
|
---|
123 | elCen /= (Float)count;
|
---|
124 | STCalSkyTable *p = dynamic_cast<STCalSkyTable *>(&(*applytable_));
|
---|
125 | p->appenddata(0, 0, current[2], current[0], current[1],
|
---|
126 | timeCen, elCen, acc.getSpectrum());
|
---|
127 | }
|
---|
128 | acc.reset() ;
|
---|
129 | timeCen = 0.0;
|
---|
130 | elCen = 0.0;
|
---|
131 | count = 0;
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | iter.next() ;
|
---|
136 | }
|
---|
137 | }
|
---|
138 |
|
---|
139 | }
|
---|