source: trunk/src/CalibrationManager.cpp@ 2747

Last change on this file since 2747 was 2747, 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...

Changed implementation not to use friend.


File size: 7.8 KB
Line 
1//
2// C++ Implementation: CalibrationManager
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#include <assert.h>
13
14#include <casa/Arrays/Vector.h>
15#include <casa/Exceptions/Error.h>
16#include <casa/Utilities/Regex.h>
17#include <casa/BasicSL/String.h>
18#include <tables/Tables/Table.h>
19#include <tables/Tables/ScalarColumn.h>
20#include <measures/TableMeasures/ScalarMeasColumn.h>
21
22
23#include "CalibrationManager.h"
24#include "Scantable.h"
25#include "STCalTsys.h"
26#include "STCalSkyPSAlma.h"
27
28using namespace casa;
29using namespace std;
30
31namespace asap {
32
33CalibrationManager::CalibrationManager()
34 : target_(0),
35 calmode_(""),
36 spwlist_(0)
37{
38 applicator_ = new STApplyCal();
39}
40
41CalibrationManager::~CalibrationManager()
42{
43}
44
45void CalibrationManager::setScantable(ScantableWrapper &s)
46{
47 os_.origin(LogOrigin("CalibrationManager","setScantable",WHERE));
48 os_ << LogIO::DEBUGGING << "set scantable object." << LogIO::POST;
49 target_ = s.getCP();
50}
51
52void CalibrationManager::setScantableByName(const string &s)
53{
54 os_.origin(LogOrigin("CalibrationManager","setScantableAsName",WHERE));
55 os_ << LogIO::DEBUGGING << "set scantable " << s << "." << LogIO::POST;
56 // always plain table
57 target_ = new Scantable(s, Table::Plain);
58}
59
60void CalibrationManager::addSkyTable(const string &c)
61{
62 os_.origin(LogOrigin("CalibrationManager","addSkyTable",WHERE));
63 os_ << LogIO::DEBUGGING << "add STCalSkyTable " << c << "." << LogIO::POST;
64 skytables_.push_back(new STCalSkyTable(c));
65}
66
67void CalibrationManager::addTsysTable(const string &c)
68{
69 os_.origin(LogOrigin("CalibrationManager","addTsysTable",WHERE));
70 os_ << LogIO::DEBUGGING << "add STCalTsysTable " << c << "." << LogIO::POST;
71 tsystables_.push_back(new STCalTsysTable(c));
72}
73
74void CalibrationManager::setMode(const string &mode)
75{
76 os_.origin(LogOrigin("CalibrationManager","setMode",WHERE));
77 os_ << LogIO::DEBUGGING << "set calibration mode to " << mode << "." << LogIO::POST;
78 calmode_ = mode;
79 calmode_.upcase();
80}
81
82void CalibrationManager::setTimeInterpolation(const string &interp, int order)
83{
84 os_.origin(LogOrigin("CalibrationManager","setTimeInterpolation",WHERE));
85 os_ << LogIO::DEBUGGING << "set interpolation method for time axis to " << interp << "." << LogIO::POST;
86 applicator_->setTimeInterpolation(stringToInterpolationEnum(interp),
87 order);
88}
89
90void CalibrationManager::setFrequencyInterpolation(const string &interp, int order)
91{
92 os_.origin(LogOrigin("CalibrationManager","setFrequencyInterpolation",WHERE));
93 os_ << LogIO::DEBUGGING << "set interpolation method for frequency axis to " << interp << "." << LogIO::POST;
94 applicator_->setFrequencyInterpolation(stringToInterpolationEnum(interp),
95 order);
96}
97
98void CalibrationManager::setTsysTransfer(unsigned int from,
99 const vector<unsigned int> &to)
100{
101 os_.origin(LogOrigin("CalibrationManager","setTsysTransfer",WHERE));
102 os_ << LogIO::DEBUGGING << "associate Tsys IFNO " << from << " with science IFNO [";
103 for (size_t i = 0; i < to.size() ; i++) {
104 os_ << to[i];
105 if (i == to.size() - 1)
106 os_ << "].";
107 else
108 os_ << ", ";
109 }
110 os_ << LogIO::POST;
111 Vector<uInt> v(to);
112 applicator_->setTsysTransfer(from, v);
113}
114
115void CalibrationManager::setTsysSpw(const vector<int> &spwlist)
116{
117 os_.origin(LogOrigin("CalibrationManager","setTsysSpw",WHERE));
118 os_ << LogIO::DEBUGGING << "set IFNO for Tsys calibration to [";
119 for (size_t i = 0; i < spwlist.size() ; i++) {
120 os_ << spwlist[i];
121 if (i == spwlist.size() - 1)
122 os_ << "].";
123 else
124 os_ << ", ";
125 }
126 os_ << LogIO::POST;
127 spwlist_ = spwlist;
128}
129
130void CalibrationManager::resetCalSetup()
131{
132 os_.origin(LogOrigin("CalibrationManager","resetCalSetup",WHERE));
133 os_ << LogIO::DEBUGGING << "reset all calibration settings except target data ." << LogIO::POST;
134 applicator_->reset();
135 calmode_ = "";
136 spwlist_.clear();
137}
138
139void CalibrationManager::reset()
140{
141 os_.origin(LogOrigin("CalibrationManager","reset",WHERE));
142 os_ << LogIO::DEBUGGING << "reset all calibration settings." << LogIO::POST;
143 applicator_->completeReset();
144 calmode_ = "";
145 spwlist_.clear();
146}
147
148void CalibrationManager::calibrate()
149{
150 os_.origin(LogOrigin("CalibrationManager","calibrate",WHERE));
151 os_ << LogIO::DEBUGGING << "start calibration with mode " << calmode_ << "." << LogIO::POST;
152 assert(!target_.null());
153 if (calmode_ == "TSYS") {
154 assert(spwlist_.size() > 0);
155 STCalTsys cal(target_, spwlist_);
156 cal.calibrate();
157 tsystables_.push_back(cal.applytable());
158 }
159 else if (calmode_ == "PS") {
160 // will match DV01-25, DA41-65, PM01-04, CM01-12
161 Regex reant("^(DV(0[1-9]|1[0-9]|2[0-5])|DA(4[1-9]|5[0-9]|6[0-5])|PM0[1-4]|CM(0[1-9]|1[1,2]))$");
162 const String antname = target_->getAntennaName();
163 if (reant.match(antname.c_str(), antname.size()) != String::npos) {
164 os_ << LogIO::DEBUGGING << "ALMA specific position-switch calibration." << LogIO::POST;
165 STCalSkyPSAlma cal(target_);
166 cal.calibrate();
167 skytables_.push_back(cal.applytable());
168 }
169 else {
170 String msg = "Calibration type " + calmode_ + " for antenna " + antname + " is not supported.";
171 os_.origin(LogOrigin("CalibrationManager","calibrate",WHERE));
172 os_ << LogIO::SEVERE << msg << LogIO::POST;
173 throw AipsError(msg);
174 }
175 }
176 else {
177 String msg = "Calibration type " + calmode_ + " is not supported.";
178 os_.origin(LogOrigin("CalibrationManager","calibrate",WHERE));
179 os_ << LogIO::SEVERE << msg << LogIO::POST;
180 throw AipsError(msg);
181 }
182}
183
184void CalibrationManager::apply()
185{
186 os_.origin(LogOrigin("CalibrationManager","apply",WHERE));
187 os_ << LogIO::DEBUGGING << "apply calibration to the data." << LogIO::POST;
188 applicator_->setTarget(target_);
189 for (size_t i = 0; i < tsystables_.size() ; i++)
190 applicator_->push(dynamic_cast<STCalTsysTable*>(&(*tsystables_[i])));
191 for (size_t i = 0; i < skytables_.size(); i++)
192 applicator_->push(dynamic_cast<STCalSkyTable*>(&(*skytables_[i])));
193 applicator_->apply(false);
194}
195
196void CalibrationManager::saveCaltable(const string &name)
197{
198 os_.origin(LogOrigin("CalibrationManager","saveCaltable",WHERE));
199 if (calmode_ == "TSYS") {
200 os_ << LogIO::DEBUGGING << "save latest STCalTsysTable as " << name << "." << LogIO::POST;
201 tsystables_[tsystables_.size()-1]->save(name);
202 }
203 else {
204 os_ << LogIO::DEBUGGING << "save latest STCalSkyTable as " << name << "." << LogIO::POST;
205 skytables_[skytables_.size()-1]->save(name);
206 }
207}
208
209void CalibrationManager::split(const string &name)
210{
211 os_.origin(LogOrigin("CalibrationManager","split",WHERE));
212 os_ << LogIO::DEBUGGING << "split science data and save them to " << name << "." << LogIO::POST;
213 applicator_->save(name);
214}
215
216STCalEnum::InterpolationType CalibrationManager::stringToInterpolationEnum(const string &s)
217{
218 String itype(s);
219 itype.upcase();
220 const Char *c = itype.c_str();
221 String::size_type len = itype.size();
222 Regex nearest("^NEAREST(NEIGHBOR)?$");
223 Regex linear("^LINEAR$");
224 Regex spline("^(C(UBIC)?)?SPLINE$");
225 Regex poly("^POLY(NOMIAL)?$");
226 if (nearest.match(c, len) != String::npos) {
227 return STCalEnum::NearestInterpolation;
228 }
229 else if (linear.match(c, len) != String::npos) {
230 return STCalEnum::LinearInterpolation;
231 }
232 else if (spline.match(c, len) != String::npos) {
233 return STCalEnum::CubicSplineInterpolation;
234 }
235 else if (poly.match(c, len) != String::npos) {
236 return STCalEnum::PolynomialInterpolation;
237 }
238
239 os_.origin(LogOrigin("CalibrationManager","stringToInterpolationEnum",WHERE));
240 os_ << LogIO::WARN << "Interpolation type " << s << " is not available. Use default interpolation method." << LogIO::POST;
241 return STCalEnum::DefaultInterpolation;
242}
243
244}
Note: See TracBrowser for help on using the repository browser.