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