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 |
|
---|
15 | #include <casa/Arrays/ArrayMath.h>
|
---|
16 | #include <casa/Logging/LogIO.h>
|
---|
17 |
|
---|
18 | #include "STSelector.h"
|
---|
19 | #include "STCalTsys.h"
|
---|
20 | #include "STDefs.h"
|
---|
21 | #include <atnf/PKSIO/SrcType.h>
|
---|
22 |
|
---|
23 | using namespace std;
|
---|
24 | using namespace casa;
|
---|
25 |
|
---|
26 | namespace asap {
|
---|
27 | STCalTsys::STCalTsys(CountedPtr<Scantable> &s, vector<int> &iflist)
|
---|
28 | : STCalibration(s, "TSYS"),
|
---|
29 | iflist_(iflist),
|
---|
30 | tsysspw_(),
|
---|
31 | do_average_(false)
|
---|
32 | {
|
---|
33 | applytable_ = new STCalTsysTable(*s);
|
---|
34 | }
|
---|
35 |
|
---|
36 | STCalTsys::STCalTsys(CountedPtr<Scantable> &s, Record &iflist, bool average)
|
---|
37 | : STCalibration(s, "TSYS"),
|
---|
38 | iflist_(),
|
---|
39 | tsysspw_(iflist),
|
---|
40 | do_average_(average)
|
---|
41 | {
|
---|
42 | iflist_.resize(tsysspw_.nfields());
|
---|
43 | for (uInt i = 0; i < tsysspw_.nfields(); ++i) {
|
---|
44 | iflist_[i] = std::atoi(tsysspw_.name(i).c_str());
|
---|
45 | }
|
---|
46 | applytable_ = new STCalTsysTable(*s);
|
---|
47 | }
|
---|
48 |
|
---|
49 | void STCalTsys::setupSelector(const STSelector &sel)
|
---|
50 | {
|
---|
51 | sel_ = sel;
|
---|
52 | vector<int> ifnos = sel_.getIFs();
|
---|
53 | if (ifnos.size() > 0) {
|
---|
54 | int nif = 0;
|
---|
55 | int nifOrg = iflist_.size();
|
---|
56 | vector<int> iflistNew(iflist_);
|
---|
57 | for (int i = 0; i < nifOrg; i++) {
|
---|
58 | if (find(ifnos.begin(), ifnos.end(), iflist_[i]) != ifnos.end()) {
|
---|
59 | iflistNew[nif] = iflist_[i];
|
---|
60 | ++nif;
|
---|
61 | }
|
---|
62 | }
|
---|
63 | if (nif == 0) {
|
---|
64 | LogIO os(LogOrigin("STCalTsys", "setupSelector", WHERE));
|
---|
65 | os << LogIO::SEVERE << "Selection contains no data." << LogIO::EXCEPTION;
|
---|
66 | }
|
---|
67 | sel_.setIFs(iflistNew);
|
---|
68 | }
|
---|
69 | else {
|
---|
70 | sel_.setIFs(iflist_);
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | void STCalTsys::appenddata(uInt scanno, uInt cycleno,
|
---|
75 | uInt beamno, uInt ifno, uInt polno,
|
---|
76 | uInt freqid, Double time, Float elevation,
|
---|
77 | Vector<Float> any_data)
|
---|
78 | {
|
---|
79 | STCalTsysTable *p = dynamic_cast<STCalTsysTable *>(&(*applytable_));
|
---|
80 | if (do_average_ && tsysspw_.isDefined(String::toString(ifno))) {
|
---|
81 | LogIO os(LogOrigin("STCalTsys", "appenddata", WHERE));
|
---|
82 | Vector<Float> averaged_data(any_data.size());
|
---|
83 | Float averaged_value = 0.0;
|
---|
84 | size_t num_value = 0;
|
---|
85 | Vector<Double> channel_range = tsysspw_.asArrayDouble(String::toString(ifno));
|
---|
86 | os << LogIO::DEBUGGING << "do averaging: channel range for IFNO " << ifno << " is " << channel_range << LogIO::POST;
|
---|
87 | for (uInt i = 1; i < channel_range.size(); i += 2) {
|
---|
88 | size_t start = (size_t)channel_range[i-1];
|
---|
89 | size_t end = std::min((size_t)channel_range[i] + 1, averaged_data.size());
|
---|
90 | os << LogIO::DEBUGGING << "start=" << start << ", end=" << end << LogIO::POST;
|
---|
91 | //Vector<Float> segment = any_data(Slice(start, end - 1, 1, False));
|
---|
92 | //averaged_value += sum(segment);
|
---|
93 | //num_value += segment.size();
|
---|
94 | float sum_per_segment = 0.0;
|
---|
95 | for (size_t j = start; j < end; ++j) {
|
---|
96 | sum_per_segment += any_data[j];
|
---|
97 | }
|
---|
98 | averaged_value += sum_per_segment;
|
---|
99 | num_value += end - start;
|
---|
100 | }
|
---|
101 | averaged_value /= (Float)num_value;
|
---|
102 | averaged_data = averaged_value;
|
---|
103 | os << LogIO::DEBUGGING << "averaged_data = " << averaged_data << LogIO::POST;
|
---|
104 | os << LogIO::DEBUGGING << "any_data = " << any_data << LogIO::POST;
|
---|
105 | p->appenddata(scanno, cycleno, beamno, ifno, polno,
|
---|
106 | freqid, time, elevation, averaged_data);
|
---|
107 | }
|
---|
108 | else {
|
---|
109 | p->appenddata(scanno, cycleno, beamno, ifno, polno,
|
---|
110 | freqid, time, elevation, any_data);
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | }
|
---|