source: trunk/src/STApplyTable.cpp@ 2727

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

New Development: Yes

JIRA Issue: Yes CAS-4770 and its sub-tickets

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...

First version of applycal for single dish calibration.
Added new classes for the operation (STApplyCal, Calibrator, PSAlmaCalibrator,
Locator, BisectionLocator, Interpolator1D, NearestInterpolator1D).
Also, modified existing classes to fit with implementation of applycal.


File size: 4.5 KB
Line 
1//
2// C++ Implementation: STApplyTable
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 <casa/Exceptions/Error.h>
13#include <tables/Tables/TableDesc.h>
14#include <tables/Tables/SetupNewTab.h>
15#include <tables/Tables/ScaColDesc.h>
16#include <tables/Tables/TableRecord.h>
17#include <tables/Tables/Table.h>
18#include <tables/Tables/ExprNode.h>
19#include <measures/TableMeasures/TableMeasDesc.h>
20#include <measures/TableMeasures/TableMeasRefDesc.h>
21#include <measures/TableMeasures/TableMeasValueDesc.h>
22
23#include "Scantable.h"
24#include "STApplyTable.h"
25
26
27using namespace casa;
28
29namespace asap {
30
31STApplyTable::STApplyTable( const Scantable& parent, const casa::String& name )
32{
33 TableDesc td("", "1", TableDesc::Scratch);
34 td.addColumn(ScalarColumnDesc<uInt>("SCANNO"));
35 td.addColumn(ScalarColumnDesc<uInt>("CYCLENO"));
36 td.addColumn(ScalarColumnDesc<uInt>("BEAMNO"));
37 td.addColumn(ScalarColumnDesc<uInt>("IFNO"));
38 td.addColumn(ScalarColumnDesc<uInt>("POLNO"));
39 td.addColumn(ScalarColumnDesc<uInt>("FREQ_ID"));
40 td.addColumn(ScalarColumnDesc<Double>("TIME"));
41 TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default
42 TableMeasValueDesc measVal(td, "TIME");
43 TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
44 mepochCol.write(td);
45 String tabname = parent.table().tableName()+"/"+name;
46 SetupNewTable aNewTab(tabname, td, Table::Scratch);
47 //table_ = Table(aNewTab, parent.table().tableType());
48 table_ = Table(aNewTab, Table::Memory);
49 attachBaseColumns();
50
51 table_.rwKeywordSet().define("VERSION", 1);
52 table_.rwKeywordSet().define("ScantableName", parent.table().tableName());
53 table_.rwKeywordSet().define("ApplyType", "NONE");
54 table_.rwKeywordSet().defineTable("FREQUENCIES", parent.frequencies().table());
55
56 table_.tableInfo().setType("ApplyTable");
57
58 originaltable_ = table_;
59}
60
61STApplyTable::STApplyTable(const String &name)
62{
63 table_ = Table(name, Table::Update);
64 attachBaseColumns();
65 originaltable_ = table_;
66}
67
68
69STApplyTable::~STApplyTable()
70{
71}
72
73void STApplyTable::attach()
74{
75 attachBaseColumns();
76 attachOptionalColumns();
77}
78
79void STApplyTable::attachBaseColumns()
80{
81 scanCol_.attach(table_, "SCANNO");
82 cycleCol_.attach(table_, "CYCLENO");
83 beamCol_.attach(table_, "BEAMNO");
84 ifCol_.attach(table_, "IFNO");
85 polCol_.attach(table_, "POLNO");
86 timeCol_.attach(table_, "TIME");
87 timeMeasCol_.attach(table_, "TIME");
88 freqidCol_.attach(table_, "FREQ_ID");
89}
90
91void STApplyTable::setSelection(STSelector &sel, bool sortByTime)
92{
93 table_ = sel.apply(originaltable_);
94 if (sortByTime)
95 table_.sort("TIME", Sort::Descending);
96 attach();
97 sel_ = sel;
98}
99
100void STApplyTable::unsetSelection()
101{
102 table_ = originaltable_;
103 attach();
104 sel_.reset();
105}
106
107void STApplyTable::setbasedata(uInt irow, uInt scanno, uInt cycleno,
108 uInt beamno, uInt ifno, uInt polno,
109 uInt freqid, Double time)
110{
111 scanCol_.put(irow, scanno);
112 cycleCol_.put(irow, cycleno);
113 beamCol_.put(irow, beamno);
114 ifCol_.put(irow, ifno);
115 polCol_.put(irow, polno);
116 timeCol_.put(irow, time);
117 freqidCol_.put(irow, freqid);
118}
119
120void STApplyTable::save(const String &name)
121{
122 table_.deepCopy(name, Table::New);
123}
124
125String STApplyTable::caltype()
126{
127 if (table_.keywordSet().isDefined("ApplyType")) {
128 return table_.keywordSet().asString("ApplyType");
129 }
130 else
131 return "NONE";
132}
133
134STCalEnum::CalType STApplyTable::getCalType(const String &name)
135{
136 Table t(name, Table::Old);
137 return stringToType(t.keywordSet().asString("ApplyType"));
138}
139
140STCalEnum::CalType STApplyTable::getCalType(CountedPtr<STApplyTable> tab)
141{
142 return stringToType(tab->caltype());
143}
144
145STCalEnum::CalType STApplyTable::getCalType(STApplyTable *tab)
146{
147 return stringToType(tab->caltype());
148}
149
150STCalEnum::CalType STApplyTable::stringToType(const String &caltype)
151{
152 if (caltype == "CALSKY_PSALMA")
153 return STCalEnum::CalPSAlma;
154 else if (caltype == "CALTSYS")
155 return STCalEnum::CalTsys;
156 else
157 return STCalEnum::NoType;
158}
159
160Block<Double> STApplyTable::getFrequenciesRow(uInt id)
161{
162 const TableRecord &rec = table_.keywordSet();
163 rec.print(os_.output());
164 os_ << LogIO::POST;
165 Table ftab = rec.asTable("FREQUENCIES");
166 Table t = ftab(ftab.col("ID") == id);
167 ROTableColumn col(t, "REFPIX");
168 Block<Double> r(3);
169 r[0] = col.asdouble(0);
170 col.attach(t, "REFVAL");
171 r[1] = col.asdouble(0);
172 col.attach(t, "INCREMENT");
173 r[2] = col.asdouble(0);
174 return r;
175}
176}
Note: See TracBrowser for help on using the repository browser.