source: trunk/src/STCalTsys.cpp@ 2746

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

New Development: No

JIRA Issue: Yes CAS-4770

Ready for Test: Yes

Interface Changes: Yes/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...

Defined python interface for calibration that supports both
on-the-fly and interferometry-style (generate caltable and apply)
calibration.

File size: 3.7 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 uInt len = rows.nelements();
75 if (len == 0) {
76 iter.next();
77 continue;
78 }
79
80 uInt nchan = scantable_->nchan(scantable_->getIF(rows[0]));
81 Vector<uChar> flag(nchan);
82 Vector<Bool> bflag(nchan);
83 Vector<Float> spec(nchan);
84
85 Vector<Double> timeSep(len);
86 for (uInt i = 0; i < len-1; i++) {
87 timeSep[i] = timeSec[rows[i+1]] - timeSec[rows[i]] ;
88 }
89 Double tMedian = median(timeSep(IPosition(1,0), IPosition(1,len-2)));
90 timeSep[len-1] = tMedian * 10000.0 ; // any large value
91
92 uInt irow ;
93 uInt jrow ;
94 for (uInt i = 0; i < len; i++) {
95 irow = rows[i];
96 jrow = (i < len-1) ? rows[i+1] : rows[i];
97 // accumulate data
98 flagCol.get(irow, flag);
99 convertArray(bflag, flag);
100 specCol.get(irow, spec);
101 if ( !allEQ(bflag,True) )
102 acc.add( spec, !bflag, tsys, intervalSec[irow], timeSec[irow] ) ;
103 timeCen += timeSec[irow];
104 elCen += elevation[irow];
105 count++;
106
107 // check time gap
108 double gap = 2.0 * timeSep[i] / (intervalSec[jrow] + intervalSec[irow]);
109 if ( gap > 5.0 ) {
110 if ( acc.state() ) {
111 acc.replaceNaN() ;
112// const Vector<Bool> &msk = acc.getMask();
113// convertArray(flag, !msk);
114// for (uInt k = 0; k < nchan; ++k) {
115// uChar userFlag = 1 << 7;
116// if (msk[k]==True) userFlag = 0 << 7;
117// flag(k) = userFlag;
118// }
119 timeCen /= (Double)count * 86400.0; // sec->day
120 elCen /= (Float)count;
121 STCalTsysTable *p = dynamic_cast<STCalTsysTable *>(&(*applytable_));
122 p->appenddata(0, 0, current[2], current[0], current[1],
123 freqidCol(irow), timeCen, elCen, acc.getSpectrum());
124 }
125 acc.reset() ;
126 timeCen = 0.0;
127 elCen = 0.0;
128 count = 0;
129 }
130 }
131
132 iter.next() ;
133 }
134}
135
136}
Note: See TracBrowser for help on using the repository browser.