[2696] | 1 | //
|
---|
| 2 | // C++ Implementation: STCalTsys
|
---|
| 3 | //
|
---|
| 4 | // Description:
|
---|
| 5 | //
|
---|
| 6 | //
|
---|
[2703] | 7 | // Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp> (C) 2012
|
---|
[2696] | 8 | //
|
---|
| 9 | // Copyright: See COPYING file that comes with this distribution
|
---|
| 10 | //
|
---|
| 11 | //
|
---|
| 12 |
|
---|
[2703] | 13 | #include <vector>
|
---|
[2786] | 14 |
|
---|
| 15 | #include <casa/Arrays/ArrayMath.h>
|
---|
| 16 | #include <casa/Logging/LogIO.h>
|
---|
[3062] | 17 | #include <tables/Tables/ScalarColumn.h>
|
---|
[2786] | 18 |
|
---|
[2703] | 19 | #include "STSelector.h"
|
---|
[2696] | 20 | #include "STCalTsys.h"
|
---|
[2703] | 21 | #include "STDefs.h"
|
---|
| 22 | #include <atnf/PKSIO/SrcType.h>
|
---|
[2696] | 23 |
|
---|
[2703] | 24 | using namespace std;
|
---|
[2696] | 25 | using namespace casa;
|
---|
| 26 |
|
---|
| 27 | namespace asap {
|
---|
[2923] | 28 | STCalTsys::STCalTsys(CountedPtr<Scantable> &s, vector<int> &iflist)
|
---|
| 29 | : STCalibration(s, "TSYS"),
|
---|
| 30 | iflist_(iflist),
|
---|
| 31 | tsysspw_(),
|
---|
| 32 | do_average_(false)
|
---|
[2696] | 33 | {
|
---|
[2703] | 34 | applytable_ = new STCalTsysTable(*s);
|
---|
[2696] | 35 | }
|
---|
| 36 |
|
---|
[2923] | 37 | STCalTsys::STCalTsys(CountedPtr<Scantable> &s, Record &iflist, bool average)
|
---|
| 38 | : STCalibration(s, "TSYS"),
|
---|
| 39 | iflist_(),
|
---|
| 40 | tsysspw_(iflist),
|
---|
| 41 | do_average_(average)
|
---|
| 42 | {
|
---|
| 43 | iflist_.resize(tsysspw_.nfields());
|
---|
| 44 | for (uInt i = 0; i < tsysspw_.nfields(); ++i) {
|
---|
| 45 | iflist_[i] = std::atoi(tsysspw_.name(i).c_str());
|
---|
| 46 | }
|
---|
| 47 | applytable_ = new STCalTsysTable(*s);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[2786] | 50 | void STCalTsys::setupSelector(const STSelector &sel)
|
---|
[2696] | 51 | {
|
---|
[3062] | 52 | // sel is an selector object that is associated with
|
---|
| 53 | // input Scantable
|
---|
[2786] | 54 | sel_ = sel;
|
---|
[3062] | 55 | //cout << "original: " << endl << sel_.print() << endl;
|
---|
[2786] | 56 | vector<int> ifnos = sel_.getIFs();
|
---|
| 57 | if (ifnos.size() > 0) {
|
---|
| 58 | int nif = 0;
|
---|
| 59 | int nifOrg = iflist_.size();
|
---|
| 60 | vector<int> iflistNew(iflist_);
|
---|
| 61 | for (int i = 0; i < nifOrg; i++) {
|
---|
| 62 | if (find(ifnos.begin(), ifnos.end(), iflist_[i]) != ifnos.end()) {
|
---|
| 63 | iflistNew[nif] = iflist_[i];
|
---|
| 64 | ++nif;
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
| 67 | if (nif == 0) {
|
---|
| 68 | LogIO os(LogOrigin("STCalTsys", "setupSelector", WHERE));
|
---|
| 69 | os << LogIO::SEVERE << "Selection contains no data." << LogIO::EXCEPTION;
|
---|
| 70 | }
|
---|
| 71 | sel_.setIFs(iflistNew);
|
---|
| 72 | }
|
---|
| 73 | else {
|
---|
| 74 | sel_.setIFs(iflist_);
|
---|
| 75 | }
|
---|
[3062] | 76 |
|
---|
| 77 | // intent selection
|
---|
| 78 | ROScalarColumn<Int> srctypeCol(scantable_->table(), "SRCTYPE");
|
---|
| 79 | Vector<Int> srctype = srctypeCol.getColumn();
|
---|
| 80 | uInt calOffCount = 0;
|
---|
| 81 | uInt calOnCount = 0;
|
---|
| 82 | for (size_t i = 0; i < srctype.nelements(); ++i) {
|
---|
| 83 | if (srctype[i] == static_cast<Int>(SrcType::PONCAL)) {
|
---|
| 84 | calOnCount++;
|
---|
| 85 | }
|
---|
| 86 | else if (srctype[i] == static_cast<Int>(SrcType::POFFCAL)) {
|
---|
| 87 | calOffCount++;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | //cout << "srctype = " << srctype << endl;
|
---|
| 91 | //cout << "calOnCount, calOffCount = " << calOnCount << "," << calOffCount << endl;
|
---|
| 92 | if (calOnCount == 0 || calOffCount == 0) {
|
---|
| 93 | LogIO os(LogOrigin("STCalTsys", "setupSelector", WHERE));
|
---|
| 94 | os << LogIO::SEVERE << "Input scantable doesn't have ATMCal intents" << LogIO::EXCEPTION;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | vector<int> intents = sel_.getTypes();
|
---|
| 98 | if (count(intents.begin(), intents.end(), static_cast<Int>(SrcType::POFFCAL)) == 0) {
|
---|
| 99 | intents.push_back(static_cast<Int>(SrcType::POFFCAL));
|
---|
| 100 | sel_.setTypes(intents);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | //cout << "modified: " << endl << sel_.print() << endl;
|
---|
[2696] | 104 | }
|
---|
| 105 |
|
---|
[2915] | 106 | void STCalTsys::appenddata(uInt scanno, uInt cycleno,
|
---|
| 107 | uInt beamno, uInt ifno, uInt polno,
|
---|
| 108 | uInt freqid, Double time, Float elevation,
|
---|
[2955] | 109 | const Vector<Float> &any_data,
|
---|
| 110 | const Vector<uChar> &channel_flag)
|
---|
[2696] | 111 | {
|
---|
[2915] | 112 | STCalTsysTable *p = dynamic_cast<STCalTsysTable *>(&(*applytable_));
|
---|
[2923] | 113 | if (do_average_ && tsysspw_.isDefined(String::toString(ifno))) {
|
---|
| 114 | LogIO os(LogOrigin("STCalTsys", "appenddata", WHERE));
|
---|
| 115 | Vector<Float> averaged_data(any_data.size());
|
---|
[2955] | 116 | Vector<uChar> averaged_flag(any_data.size(), 0);
|
---|
[2923] | 117 | Float averaged_value = 0.0;
|
---|
[2924] | 118 | size_t num_value = 0;
|
---|
[2923] | 119 | Vector<Double> channel_range = tsysspw_.asArrayDouble(String::toString(ifno));
|
---|
| 120 | os << LogIO::DEBUGGING << "do averaging: channel range for IFNO " << ifno << " is " << channel_range << LogIO::POST;
|
---|
| 121 | for (uInt i = 1; i < channel_range.size(); i += 2) {
|
---|
[2924] | 122 | size_t start = (size_t)channel_range[i-1];
|
---|
| 123 | size_t end = std::min((size_t)channel_range[i] + 1, averaged_data.size());
|
---|
[2923] | 124 | os << LogIO::DEBUGGING << "start=" << start << ", end=" << end << LogIO::POST;
|
---|
[2924] | 125 | float sum_per_segment = 0.0;
|
---|
[2958] | 126 | size_t count = 0;
|
---|
[2924] | 127 | for (size_t j = start; j < end; ++j) {
|
---|
[2958] | 128 | if (channel_flag[j] == 0) {
|
---|
| 129 | sum_per_segment += any_data[j];
|
---|
| 130 | count += 1;
|
---|
| 131 | }
|
---|
[2923] | 132 | }
|
---|
[2924] | 133 | averaged_value += sum_per_segment;
|
---|
[2958] | 134 | num_value += count;
|
---|
[2923] | 135 | }
|
---|
| 136 | averaged_value /= (Float)num_value;
|
---|
| 137 | averaged_data = averaged_value;
|
---|
| 138 | os << LogIO::DEBUGGING << "averaged_data = " << averaged_data << LogIO::POST;
|
---|
| 139 | os << LogIO::DEBUGGING << "any_data = " << any_data << LogIO::POST;
|
---|
| 140 | p->appenddata(scanno, cycleno, beamno, ifno, polno,
|
---|
[2955] | 141 | freqid, time, elevation, averaged_data,
|
---|
| 142 | averaged_flag);
|
---|
[2923] | 143 | }
|
---|
| 144 | else {
|
---|
| 145 | p->appenddata(scanno, cycleno, beamno, ifno, polno,
|
---|
[2955] | 146 | freqid, time, elevation, any_data,
|
---|
| 147 | channel_flag);
|
---|
[2923] | 148 | }
|
---|
[2696] | 149 | }
|
---|
| 150 |
|
---|
| 151 | }
|
---|