source: trunk/src/STCalTsys.cpp@ 2756

Last change on this file since 2756 was 2749, checked in by Takeshi Nakazato, 12 years ago

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...

Bug fix for the case when only one row is selected in a certain iteration
loop.


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