1 | //#---------------------------------------------------------------------------
|
---|
2 | //# SDMemTable.cc: A MemoryTable container for single dish integrations
|
---|
3 | //#---------------------------------------------------------------------------
|
---|
4 | //# Copyright (C) 2004
|
---|
5 | //# ATNF
|
---|
6 | //#
|
---|
7 | //# This program is free software; you can redistribute it and/or modify it
|
---|
8 | //# under the terms of the GNU General Public License as published by the Free
|
---|
9 | //# Software Foundation; either version 2 of the License, or (at your option)
|
---|
10 | //# any later version.
|
---|
11 | //#
|
---|
12 | //# This program is distributed in the hope that it will be useful, but
|
---|
13 | //# WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
---|
15 | //# Public License for more details.
|
---|
16 | //#
|
---|
17 | //# You should have received a copy of the GNU General Public License along
|
---|
18 | //# with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
19 | //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
|
---|
20 | //#
|
---|
21 | //# Correspondence concerning this software should be addressed as follows:
|
---|
22 | //# Internet email: Malte.Marquarding@csiro.au
|
---|
23 | //# Postal address: Malte Marquarding,
|
---|
24 | //# Australia Telescope National Facility,
|
---|
25 | //# P.O. Box 76,
|
---|
26 | //# Epping, NSW, 2121,
|
---|
27 | //# AUSTRALIA
|
---|
28 | //#
|
---|
29 | //# $Id:
|
---|
30 | //#---------------------------------------------------------------------------
|
---|
31 |
|
---|
32 | #include <map>
|
---|
33 |
|
---|
34 | #include <casa/aips.h>
|
---|
35 | #include <casa/iostream.h>
|
---|
36 | #include <casa/iomanip.h>
|
---|
37 | #include <casa/Arrays/Array.h>
|
---|
38 | #include <casa/Arrays/ArrayMath.h>
|
---|
39 | #include <casa/Arrays/MaskArrMath.h>
|
---|
40 | #include <casa/Arrays/ArrayLogical.h>
|
---|
41 | #include <casa/Arrays/ArrayAccessor.h>
|
---|
42 | #include <casa/Arrays/Vector.h>
|
---|
43 |
|
---|
44 | #include <tables/Tables/TableParse.h>
|
---|
45 | #include <tables/Tables/TableDesc.h>
|
---|
46 | #include <tables/Tables/SetupNewTab.h>
|
---|
47 | #include <tables/Tables/ScaColDesc.h>
|
---|
48 | #include <tables/Tables/ArrColDesc.h>
|
---|
49 |
|
---|
50 | #include <tables/Tables/ExprNode.h>
|
---|
51 | #include <tables/Tables/ScalarColumn.h>
|
---|
52 | #include <tables/Tables/ArrayColumn.h>
|
---|
53 | #include <tables/Tables/TableRecord.h>
|
---|
54 | #include <measures/Measures/MFrequency.h>
|
---|
55 | #include <measures/Measures/MeasTable.h>
|
---|
56 | #include <coordinates/Coordinates/CoordinateUtil.h>
|
---|
57 | #include <casa/Quanta/MVTime.h>
|
---|
58 |
|
---|
59 | #include "SDDefs.h"
|
---|
60 | #include "SDMemTable.h"
|
---|
61 | #include "SDContainer.h"
|
---|
62 |
|
---|
63 |
|
---|
64 | using namespace casa;
|
---|
65 | using namespace asap;
|
---|
66 |
|
---|
67 | SDMemTable::SDMemTable() :
|
---|
68 | IFSel_(0),
|
---|
69 | beamSel_(0),
|
---|
70 | polSel_(0)
|
---|
71 | {
|
---|
72 | setup();
|
---|
73 | }
|
---|
74 |
|
---|
75 | SDMemTable::SDMemTable(const std::string& name) :
|
---|
76 | IFSel_(0),
|
---|
77 | beamSel_(0),
|
---|
78 | polSel_(0)
|
---|
79 | {
|
---|
80 | Table tab(name);
|
---|
81 | table_ = tab.copyToMemoryTable("dummy");
|
---|
82 | //cerr << "hello from C SDMemTable @ " << this << endl;
|
---|
83 | }
|
---|
84 |
|
---|
85 | SDMemTable::SDMemTable(const SDMemTable& other, Bool clear)
|
---|
86 | {
|
---|
87 | IFSel_= other.IFSel_;
|
---|
88 | beamSel_= other.beamSel_;
|
---|
89 | polSel_= other.polSel_;
|
---|
90 | chanMask_ = other.chanMask_;
|
---|
91 | table_ = other.table_.copyToMemoryTable(String("dummy"));
|
---|
92 | // clear all rows()
|
---|
93 | if (clear) {
|
---|
94 | table_.removeRow(this->table_.rowNumbers());
|
---|
95 | } else {
|
---|
96 | IFSel_ = other.IFSel_;
|
---|
97 | beamSel_ = other.beamSel_;
|
---|
98 | polSel_ = other.polSel_;
|
---|
99 | }
|
---|
100 | //cerr << "hello from CC SDMemTable @ " << this << endl;
|
---|
101 | }
|
---|
102 |
|
---|
103 | SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) :
|
---|
104 | IFSel_(0),
|
---|
105 | beamSel_(0),
|
---|
106 | polSel_(0)
|
---|
107 | {
|
---|
108 | Table t = tableCommand(exprs,tab);
|
---|
109 | if (t.nrow() == 0)
|
---|
110 | throw(AipsError("Query unsuccessful."));
|
---|
111 | table_ = t.copyToMemoryTable("dummy");
|
---|
112 | }
|
---|
113 |
|
---|
114 | SDMemTable::~SDMemTable()
|
---|
115 | {
|
---|
116 | //cerr << "goodbye from SDMemTable @ " << this << endl;
|
---|
117 | }
|
---|
118 |
|
---|
119 | SDMemTable SDMemTable::getScan(Int scanID) const
|
---|
120 | {
|
---|
121 | String cond("SELECT * from $1 WHERE SCANID == ");
|
---|
122 | cond += String::toString(scanID);
|
---|
123 | return SDMemTable(table_, cond);
|
---|
124 | }
|
---|
125 |
|
---|
126 | SDMemTable &SDMemTable::operator=(const SDMemTable& other)
|
---|
127 | {
|
---|
128 | if (this != &other) {
|
---|
129 | IFSel_= other.IFSel_;
|
---|
130 | beamSel_= other.beamSel_;
|
---|
131 | polSel_= other.polSel_;
|
---|
132 | chanMask_.resize(0);
|
---|
133 | chanMask_ = other.chanMask_;
|
---|
134 | table_ = other.table_.copyToMemoryTable(String("dummy"));
|
---|
135 | }
|
---|
136 | //cerr << "hello from ASS SDMemTable @ " << this << endl;
|
---|
137 | return *this;
|
---|
138 | }
|
---|
139 |
|
---|
140 | SDMemTable SDMemTable::getSource(const std::string& source) const
|
---|
141 | {
|
---|
142 | String cond("SELECT * from $1 WHERE SRCNAME == ");
|
---|
143 | cond += source;
|
---|
144 | return SDMemTable(table_, cond);
|
---|
145 | }
|
---|
146 |
|
---|
147 | void SDMemTable::setup()
|
---|
148 | {
|
---|
149 | TableDesc td("", "1", TableDesc::Scratch);
|
---|
150 | td.comment() = "A SDMemTable";
|
---|
151 | td.addColumn(ScalarColumnDesc<Double>("TIME"));
|
---|
152 | td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
|
---|
153 | td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
|
---|
154 | td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
|
---|
155 | td.addColumn(ArrayColumnDesc<Float>("TSYS"));
|
---|
156 | td.addColumn(ScalarColumnDesc<Int>("SCANID"));
|
---|
157 | td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
|
---|
158 | td.addColumn(ArrayColumnDesc<uInt>("FREQID"));
|
---|
159 | td.addColumn(ArrayColumnDesc<Double>("DIRECTION"));
|
---|
160 | td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
|
---|
161 | td.addColumn(ScalarColumnDesc<String>("TCALTIME"));
|
---|
162 | td.addColumn(ArrayColumnDesc<Float>("TCAL"));
|
---|
163 | td.addColumn(ScalarColumnDesc<Float>("AZIMUTH"));
|
---|
164 | td.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
|
---|
165 | td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
|
---|
166 | td.addColumn(ScalarColumnDesc<Int>("REFBEAM"));
|
---|
167 | td.addColumn(ArrayColumnDesc<String>("HISTORY"));
|
---|
168 |
|
---|
169 | // Now create a new table from the description.
|
---|
170 |
|
---|
171 | SetupNewTable aNewTab("dummy", td, Table::New);
|
---|
172 | table_ = Table(aNewTab, Table::Memory, 0);
|
---|
173 | }
|
---|
174 |
|
---|
175 | std::string SDMemTable::getSourceName(Int whichRow) const
|
---|
176 | {
|
---|
177 | ROScalarColumn<String> src(table_, "SRCNAME");
|
---|
178 | String name;
|
---|
179 | src.get(whichRow, name);
|
---|
180 | return name;
|
---|
181 | }
|
---|
182 |
|
---|
183 | std::string SDMemTable::getTime(Int whichRow) const
|
---|
184 | {
|
---|
185 | ROScalarColumn<Double> src(table_, "TIME");
|
---|
186 | Double tm;
|
---|
187 | src.get(whichRow, tm);
|
---|
188 | MVTime mvt(tm);
|
---|
189 | mvt.setFormat(MVTime::TIME);
|
---|
190 | ostringstream oss;
|
---|
191 | oss << mvt;
|
---|
192 | String str(oss);
|
---|
193 | return str;
|
---|
194 | }
|
---|
195 | double SDMemTable::getInterval(Int whichRow) const
|
---|
196 | {
|
---|
197 | ROScalarColumn<Double> src(table_, "INTERVAL");
|
---|
198 | Double intval;
|
---|
199 | src.get(whichRow, intval);
|
---|
200 | return intval;
|
---|
201 | }
|
---|
202 |
|
---|
203 | bool SDMemTable::setIF(Int whichIF)
|
---|
204 | {
|
---|
205 | if ( whichIF >= 0 && whichIF < nIF()) {
|
---|
206 | IFSel_ = whichIF;
|
---|
207 | return true;
|
---|
208 | }
|
---|
209 | return false;
|
---|
210 | }
|
---|
211 |
|
---|
212 | bool SDMemTable::setBeam(Int whichBeam)
|
---|
213 | {
|
---|
214 | if ( whichBeam >= 0 && whichBeam < nBeam()) {
|
---|
215 | beamSel_ = whichBeam;
|
---|
216 | return true;
|
---|
217 | }
|
---|
218 | return false;
|
---|
219 | }
|
---|
220 |
|
---|
221 | bool SDMemTable::setPol(Int whichPol)
|
---|
222 | {
|
---|
223 | if ( whichPol >= 0 && whichPol < nPol()) {
|
---|
224 | polSel_ = whichPol;
|
---|
225 | return true;
|
---|
226 | }
|
---|
227 | return false;
|
---|
228 | }
|
---|
229 |
|
---|
230 | bool SDMemTable::setMask(std::vector<int> whichChans)
|
---|
231 | {
|
---|
232 | ROArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
233 | std::vector<int>::iterator it;
|
---|
234 | uInt n = spec.shape(0)(3);
|
---|
235 | if (whichChans.empty()) {
|
---|
236 | chanMask_ = std::vector<bool>(n,true);
|
---|
237 | return true;
|
---|
238 | }
|
---|
239 | chanMask_.resize(n,true);
|
---|
240 | for (it = whichChans.begin(); it != whichChans.end(); ++it) {
|
---|
241 | if (*it < n) {
|
---|
242 | chanMask_[*it] = false;
|
---|
243 | }
|
---|
244 | }
|
---|
245 | return true;
|
---|
246 | }
|
---|
247 |
|
---|
248 | std::vector<bool> SDMemTable::getMask(Int whichRow) const {
|
---|
249 | std::vector<bool> mask;
|
---|
250 | ROArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
251 | Array<uChar> arr;
|
---|
252 | spec.get(whichRow, arr);
|
---|
253 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
|
---|
254 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
255 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
|
---|
256 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
257 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
|
---|
258 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
259 |
|
---|
260 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
|
---|
261 |
|
---|
262 | std::vector<bool> tmp;
|
---|
263 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here
|
---|
264 | std::vector<bool>::iterator miter;
|
---|
265 | miter = tmp.begin();
|
---|
266 |
|
---|
267 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
268 | bool out =!static_cast<bool>(*i);
|
---|
269 | if (useUserMask) {
|
---|
270 | out = out && (*miter);
|
---|
271 | miter++;
|
---|
272 | }
|
---|
273 | mask.push_back(out);
|
---|
274 | }
|
---|
275 | return mask;
|
---|
276 | }
|
---|
277 | std::vector<float> SDMemTable::getSpectrum(Int whichRow) const
|
---|
278 | {
|
---|
279 | std::vector<float> spectrum;
|
---|
280 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
281 | Array<Float> arr;
|
---|
282 | spec.get(whichRow, arr);
|
---|
283 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
|
---|
284 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
285 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
|
---|
286 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
287 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
|
---|
288 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
289 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
290 | spectrum.push_back(*i);
|
---|
291 | }
|
---|
292 | return spectrum;
|
---|
293 | }
|
---|
294 | std::vector<string> SDMemTable::getCoordInfo() const
|
---|
295 | {
|
---|
296 | String un;
|
---|
297 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
298 | String sunit;
|
---|
299 | t.keywordSet().get("UNIT",sunit);
|
---|
300 | String dpl;
|
---|
301 | t.keywordSet().get("DOPPLER",dpl);
|
---|
302 | if (dpl == "") dpl = "RADIO";
|
---|
303 | String rfrm;
|
---|
304 | t.keywordSet().get("REFFRAME",rfrm);
|
---|
305 | std::vector<string> inf;
|
---|
306 | inf.push_back(sunit);
|
---|
307 | inf.push_back(rfrm);
|
---|
308 | inf.push_back(dpl);
|
---|
309 | return inf;
|
---|
310 | }
|
---|
311 |
|
---|
312 | void SDMemTable::setCoordInfo(std::vector<string> theinfo)
|
---|
313 | {
|
---|
314 | std::vector<string>::iterator it;
|
---|
315 | String un,rfrm,dpl;
|
---|
316 | un = theinfo[0];
|
---|
317 | rfrm = theinfo[1];
|
---|
318 | dpl = theinfo[2];
|
---|
319 |
|
---|
320 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
|
---|
321 | Vector<Double> rstf;
|
---|
322 | t.keywordSet().get("RESTFREQS",rstf);
|
---|
323 | Bool canDo = True;
|
---|
324 | Unit u1("km/s");Unit u2("Hz");
|
---|
325 | if (Unit(un) == u1) {
|
---|
326 | Vector<Double> rstf;
|
---|
327 | t.keywordSet().get("RESTFREQS",rstf);
|
---|
328 | if (rstf.nelements() == 0) {
|
---|
329 | throw(AipsError("Can't set unit to km/s if no restfrequencies are specified"));
|
---|
330 | }
|
---|
331 | } else if (Unit(un) != u2 && un != "") {
|
---|
332 | throw(AipsError("Unit not conformant with Spectral Coordinates"));
|
---|
333 | }
|
---|
334 | t.rwKeywordSet().define("UNIT", un);
|
---|
335 |
|
---|
336 | MFrequency::Types mdr;
|
---|
337 | if (!MFrequency::getType(mdr, rfrm)) {
|
---|
338 |
|
---|
339 | Int a,b;const uInt* c;
|
---|
340 | const String* valid = MFrequency::allMyTypes(a, b, c);
|
---|
341 | String pfix = "Please specify a legal frame type. Types are\n";
|
---|
342 | throw(AipsError(pfix+(*valid)));
|
---|
343 | } else {
|
---|
344 | t.rwKeywordSet().define("REFFRAME",rfrm);
|
---|
345 | }
|
---|
346 |
|
---|
347 | }
|
---|
348 |
|
---|
349 | std::vector<double> SDMemTable::getAbcissa(Int whichRow) const
|
---|
350 | {
|
---|
351 | std::vector<double> absc(nChan());
|
---|
352 | Vector<Double> absc1(nChan());
|
---|
353 | indgen(absc1);
|
---|
354 | ROArrayColumn<uInt> fid(table_, "FREQID");
|
---|
355 | Vector<uInt> v;
|
---|
356 | fid.get(whichRow, v);
|
---|
357 | uInt specidx = v(IFSel_);
|
---|
358 | SpectralCoordinate spc = getCoordinate(specidx);
|
---|
359 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
360 |
|
---|
361 | MDirection direct = getDirection(whichRow);
|
---|
362 |
|
---|
363 | ROScalarColumn<Double> tme(table_, "TIME");
|
---|
364 | Double obstime;
|
---|
365 | tme.get(whichRow,obstime);
|
---|
366 | MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
|
---|
367 | MEpoch::Types met = getTimeReference();
|
---|
368 | MEpoch epoch(tm2, met);
|
---|
369 |
|
---|
370 | Vector<Double> antpos;
|
---|
371 | table_.keywordSet().get("AntennaPosition", antpos);
|
---|
372 | MVPosition mvpos(antpos(0),antpos(1),antpos(2));
|
---|
373 | MPosition pos(mvpos);
|
---|
374 | String sunit;
|
---|
375 | t.keywordSet().get("UNIT",sunit);
|
---|
376 | if (sunit == "") sunit = "pixel";
|
---|
377 | Unit u(sunit);
|
---|
378 | String frm;
|
---|
379 | t.keywordSet().get("REFFRAME",frm);
|
---|
380 | if (frm == "") frm = "TOPO";
|
---|
381 | String dpl;
|
---|
382 | t.keywordSet().get("DOPPLER",dpl);
|
---|
383 | if (dpl == "") dpl = "RADIO";
|
---|
384 | MFrequency::Types mtype;
|
---|
385 | if (!MFrequency::getType(mtype, frm)) {
|
---|
386 | cout << "Frequency type unknown assuming TOPO" << endl;
|
---|
387 | mtype = MFrequency::TOPO;
|
---|
388 | }
|
---|
389 |
|
---|
390 | if (!spc.setReferenceConversion(mtype,epoch,pos,direct)) {
|
---|
391 | throw(AipsError("Couldn't convert frequency frame."));
|
---|
392 | }
|
---|
393 |
|
---|
394 | if ( u == Unit("km/s") ) {
|
---|
395 | Vector<Double> rstf;
|
---|
396 | t.keywordSet().get("RESTFREQS",rstf);
|
---|
397 | if (rstf.nelements() > 0) {
|
---|
398 | if (rstf.nelements() >= nIF())
|
---|
399 | spc.selectRestFrequency(uInt(IFSel_));
|
---|
400 | spc.setVelocity(u.getName());
|
---|
401 | Vector<Double> wrld;
|
---|
402 | spc.pixelToVelocity(wrld,absc1);
|
---|
403 | std::vector<double>::iterator it;
|
---|
404 | uInt i = 0;
|
---|
405 | for (it = absc.begin(); it != absc.end(); ++it) {
|
---|
406 | (*it) = wrld[i];
|
---|
407 | i++;
|
---|
408 | }
|
---|
409 | }
|
---|
410 | } else if (u == Unit("Hz")) {
|
---|
411 | Vector<String> wau(1); wau = u.getName();
|
---|
412 | spc.setWorldAxisUnits(wau);
|
---|
413 | std::vector<double>::iterator it;
|
---|
414 | Double tmp;
|
---|
415 | uInt i = 0;
|
---|
416 | for (it = absc.begin(); it != absc.end(); ++it) {
|
---|
417 | spc.toWorld(tmp,absc1[i]);
|
---|
418 | (*it) = tmp;
|
---|
419 | i++;
|
---|
420 | }
|
---|
421 |
|
---|
422 | } else {
|
---|
423 | // assume channels/pixels
|
---|
424 | std::vector<double>::iterator it;
|
---|
425 | uInt i=0;
|
---|
426 | for (it = absc.begin(); it != absc.end(); ++it) {
|
---|
427 | (*it) = Double(i++);
|
---|
428 | }
|
---|
429 | }
|
---|
430 | return absc;
|
---|
431 | }
|
---|
432 |
|
---|
433 | std::string SDMemTable::getAbcissaString(Int whichRow) const
|
---|
434 | {
|
---|
435 | ROArrayColumn<uInt> fid(table_, "FREQID");
|
---|
436 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
437 | String sunit;
|
---|
438 | t.keywordSet().get("UNIT",sunit);
|
---|
439 | if (sunit == "") sunit = "pixel";
|
---|
440 | Unit u(sunit);
|
---|
441 | Vector<uInt> v;
|
---|
442 | fid.get(whichRow, v);
|
---|
443 | uInt specidx = v(IFSel_);
|
---|
444 | SpectralCoordinate spc = getCoordinate(specidx);
|
---|
445 | String frm;
|
---|
446 | t.keywordSet().get("REFFRAME",frm);
|
---|
447 | MFrequency::Types mtype;
|
---|
448 | if (!MFrequency::getType(mtype, frm)) {
|
---|
449 | cout << "Frequency type unknown assuming TOPO" << endl;
|
---|
450 | mtype = MFrequency::TOPO;
|
---|
451 | }
|
---|
452 | spc.setFrequencySystem(mtype);
|
---|
453 | String s = "Channel";
|
---|
454 | if (u == Unit("km/s")) {
|
---|
455 | spc.setVelocity(u.getName());
|
---|
456 | s = CoordinateUtil::axisLabel(spc,0,True,True,True);
|
---|
457 | } else if (u == Unit("Hz")) {
|
---|
458 | Vector<String> wau(1);wau = u.getName();
|
---|
459 | spc.setWorldAxisUnits(wau);
|
---|
460 | s = CoordinateUtil::axisLabel(spc);
|
---|
461 | }
|
---|
462 | return s;
|
---|
463 | }
|
---|
464 |
|
---|
465 | void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow)
|
---|
466 | {
|
---|
467 | ArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
468 | Array<Float> arr;
|
---|
469 | spec.get(whichRow, arr);
|
---|
470 | if (spectrum.size() != arr.shape()(3)) {
|
---|
471 | throw(AipsError("Attempting to set spectrum with incorrect length."));
|
---|
472 | }
|
---|
473 |
|
---|
474 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
|
---|
475 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
476 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
|
---|
477 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
478 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
|
---|
479 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
480 |
|
---|
481 | std::vector<float>::iterator it = spectrum.begin();
|
---|
482 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
483 | (*i) = Float(*it);
|
---|
484 | it++;
|
---|
485 | }
|
---|
486 | spec.put(whichRow, arr);
|
---|
487 | }
|
---|
488 |
|
---|
489 | void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const
|
---|
490 | {
|
---|
491 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
492 | Array<Float> arr;
|
---|
493 | spec.get(whichRow, arr);
|
---|
494 | spectrum.resize(arr.shape()(3));
|
---|
495 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
|
---|
496 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
497 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
|
---|
498 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
499 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
|
---|
500 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
501 |
|
---|
502 | ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
|
---|
503 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
504 | (*va) = (*i);
|
---|
505 | va++;
|
---|
506 | }
|
---|
507 | }
|
---|
508 | /*
|
---|
509 | void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
|
---|
510 | ROArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
511 | Array<uChar> arr;
|
---|
512 | spec.get(whichRow, arr);
|
---|
513 | mask.resize(arr.shape()(3));
|
---|
514 |
|
---|
515 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
|
---|
516 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
517 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
|
---|
518 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
519 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
|
---|
520 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
521 |
|
---|
522 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
|
---|
523 |
|
---|
524 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask);
|
---|
525 | std::vector<bool> tmp;
|
---|
526 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
|
---|
527 | // iterator should work on chanMask_??
|
---|
528 | std::vector<bool>::iterator miter;
|
---|
529 | miter = tmp.begin();
|
---|
530 |
|
---|
531 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
532 | bool out =!static_cast<bool>(*i);
|
---|
533 | if (useUserMask) {
|
---|
534 | out = out && (*miter);
|
---|
535 | miter++;
|
---|
536 | }
|
---|
537 | (*va) = out;
|
---|
538 | va++;
|
---|
539 | }
|
---|
540 | }
|
---|
541 | */
|
---|
542 | MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
|
---|
543 | Bool useSelection) const
|
---|
544 | {
|
---|
545 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
546 | Array<Float> arr;
|
---|
547 | ROArrayColumn<uChar> flag(table_, "FLAGTRA");
|
---|
548 | Array<uChar> farr;
|
---|
549 | spec.get(whichRow, arr);
|
---|
550 | flag.get(whichRow, farr);
|
---|
551 | Array<Bool> barr(farr.shape());convertArray(barr, farr);
|
---|
552 | MaskedArray<Float> marr;
|
---|
553 | if (useSelection) {
|
---|
554 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
|
---|
555 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
556 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
|
---|
557 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
558 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
|
---|
559 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
560 |
|
---|
561 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > baa0(barr);
|
---|
562 | baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam
|
---|
563 | ArrayAccessor<Bool, Axis<asap::IFAxis> > baa1(baa0);
|
---|
564 | baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF
|
---|
565 | ArrayAccessor<Bool, Axis<asap::PolAxis> > baa2(baa1);
|
---|
566 | baa2.reset(baa2.begin(uInt(polSel_)));// go to pol
|
---|
567 |
|
---|
568 | Vector<Float> a(arr.shape()(3));
|
---|
569 | Vector<Bool> b(barr.shape()(3));
|
---|
570 | ArrayAccessor<Float, Axis<asap::BeamAxis> > a0(a);
|
---|
571 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > b0(b);
|
---|
572 |
|
---|
573 | ArrayAccessor<Bool, Axis<asap::ChanAxis> > j(baa2);
|
---|
574 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2);
|
---|
575 | i != i.end(); ++i) {
|
---|
576 | (*a0) = (*i);
|
---|
577 | (*b0) = !(*j);
|
---|
578 | j++;
|
---|
579 | a0++;
|
---|
580 | b0++;
|
---|
581 | }
|
---|
582 | marr.setData(a,b);
|
---|
583 | } else {
|
---|
584 | marr.setData(arr,!barr);
|
---|
585 | }
|
---|
586 | return marr;
|
---|
587 | }
|
---|
588 |
|
---|
589 | Float SDMemTable::getTsys(Int whichRow) const
|
---|
590 | {
|
---|
591 | ROArrayColumn<Float> ts(table_, "TSYS");
|
---|
592 | Array<Float> arr;
|
---|
593 | ts.get(whichRow, arr);
|
---|
594 | Float out;
|
---|
595 | IPosition ip(arr.shape());
|
---|
596 | ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0;
|
---|
597 | out = arr(ip);
|
---|
598 | return out;
|
---|
599 | }
|
---|
600 |
|
---|
601 | MDirection SDMemTable::getDirection(Int whichRow) const
|
---|
602 | {
|
---|
603 | MDirection::Types mdr = getDirectionReference();
|
---|
604 | ROArrayColumn<Double> dir(table_, "DIRECTION");
|
---|
605 | Array<Double> posit;
|
---|
606 | dir.get(whichRow,posit);
|
---|
607 | Vector<Double> wpos(2);
|
---|
608 | wpos[0] = posit(IPosition(2,beamSel_,0));
|
---|
609 | wpos[1] = posit(IPosition(2,beamSel_,1));
|
---|
610 | Quantum<Double> lon(wpos[0],Unit(String("rad")));
|
---|
611 | Quantum<Double> lat(wpos[1],Unit(String("rad")));
|
---|
612 | MDirection direct(lon, lat, mdr);
|
---|
613 | return direct;
|
---|
614 | }
|
---|
615 |
|
---|
616 | SpectralCoordinate SDMemTable::getCoordinate(uInt whichIdx) const
|
---|
617 | {
|
---|
618 |
|
---|
619 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
620 | if (whichIdx > t.nrow() ) {
|
---|
621 | throw(AipsError("SDMemTable::getCoordinate - whichIdx out of range"));
|
---|
622 | }
|
---|
623 |
|
---|
624 | Double rp,rv,inc;
|
---|
625 | String rf;
|
---|
626 | Vector<Double> vec;
|
---|
627 | ROScalarColumn<Double> rpc(t, "REFPIX");
|
---|
628 | ROScalarColumn<Double> rvc(t, "REFVAL");
|
---|
629 | ROScalarColumn<Double> incc(t, "INCREMENT");
|
---|
630 | t.keywordSet().get("RESTFREQS",vec);
|
---|
631 | t.keywordSet().get("BASEREFFRAME",rf);
|
---|
632 |
|
---|
633 | MFrequency::Types mft;
|
---|
634 | if (!MFrequency::getType(mft, rf)) {
|
---|
635 | cerr << "Frequency type unknown assuming TOPO" << endl;
|
---|
636 | mft = MFrequency::TOPO;
|
---|
637 | }
|
---|
638 | rpc.get(whichIdx, rp);
|
---|
639 | rvc.get(whichIdx, rv);
|
---|
640 | incc.get(whichIdx, inc);
|
---|
641 | SpectralCoordinate spec(mft,rv,inc,rp);
|
---|
642 | if (vec.nelements() > 0)
|
---|
643 | spec.setRestFrequencies(vec);
|
---|
644 | return spec;
|
---|
645 | }
|
---|
646 |
|
---|
647 | Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
|
---|
648 | uInt whichIdx) {
|
---|
649 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
|
---|
650 | if (whichIdx > t.nrow() ) {
|
---|
651 | throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
|
---|
652 | }
|
---|
653 | ScalarColumn<Double> rpc(t, "REFPIX");
|
---|
654 | ScalarColumn<Double> rvc(t, "REFVAL");
|
---|
655 | ScalarColumn<Double> incc(t, "INCREMENT");
|
---|
656 |
|
---|
657 | rpc.put(whichIdx, speccord.referencePixel()[0]);
|
---|
658 | rvc.put(whichIdx, speccord.referenceValue()[0]);
|
---|
659 | incc.put(whichIdx, speccord.increment()[0]);
|
---|
660 |
|
---|
661 | return True;
|
---|
662 | }
|
---|
663 |
|
---|
664 | Int SDMemTable::nCoordinates() const
|
---|
665 | {
|
---|
666 | return table_.keywordSet().asTable("FREQUENCIES").nrow();
|
---|
667 | }
|
---|
668 |
|
---|
669 | void SDMemTable::setRestFreqs(std::vector<double> freqs,
|
---|
670 | const std::string& theunit)
|
---|
671 | {
|
---|
672 | Vector<Double> tvec(freqs);
|
---|
673 | Quantum<Vector<Double> > q(tvec, String(theunit));
|
---|
674 | tvec.resize();
|
---|
675 | tvec = q.getValue("Hz");
|
---|
676 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
677 | t.rwKeywordSet().define("RESTFREQS",tvec);
|
---|
678 | }
|
---|
679 |
|
---|
680 | std::vector<double> SDMemTable::getRestFreqs() const
|
---|
681 | {
|
---|
682 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
683 | Vector<Double> tvec;
|
---|
684 | t.keywordSet().get("RESTFREQS",tvec);
|
---|
685 | std::vector<double> stlout;
|
---|
686 | tvec.tovector(stlout);
|
---|
687 | return stlout;
|
---|
688 | }
|
---|
689 |
|
---|
690 | bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft)
|
---|
691 | {
|
---|
692 | TableDesc td("", "1", TableDesc::Scratch);
|
---|
693 | td.addColumn(ScalarColumnDesc<Double>("REFPIX"));
|
---|
694 | td.addColumn(ScalarColumnDesc<Double>("REFVAL"));
|
---|
695 | td.addColumn(ScalarColumnDesc<Double>("INCREMENT"));
|
---|
696 | SetupNewTable aNewTab("freqs", td, Table::New);
|
---|
697 | Table aTable (aNewTab, Table::Memory, sdft.length());
|
---|
698 | ScalarColumn<Double> sc0(aTable, "REFPIX");
|
---|
699 | ScalarColumn<Double> sc1(aTable, "REFVAL");
|
---|
700 | ScalarColumn<Double> sc2(aTable, "INCREMENT");
|
---|
701 | for (uInt i=0; i < sdft.length(); ++i) {
|
---|
702 | sc0.put(i,sdft.referencePixel(i));
|
---|
703 | sc1.put(i,sdft.referenceValue(i));
|
---|
704 | sc2.put(i,sdft.increment(i));
|
---|
705 | }
|
---|
706 | String rf = sdft.refFrame();
|
---|
707 | if (rf.contains("TOPO")) rf = "TOPO";
|
---|
708 |
|
---|
709 | aTable.rwKeywordSet().define("BASEREFFRAME", rf);
|
---|
710 | aTable.rwKeywordSet().define("REFFRAME", rf);
|
---|
711 | aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
|
---|
712 | aTable.rwKeywordSet().define("UNIT", String(""));
|
---|
713 | aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
|
---|
714 | Vector<Double> rfvec;
|
---|
715 | String rfunit;
|
---|
716 | sdft.restFrequencies(rfvec,rfunit);
|
---|
717 | Quantum<Vector<Double> > q(rfvec, rfunit);
|
---|
718 | rfvec.resize();
|
---|
719 | rfvec = q.getValue("Hz");
|
---|
720 | aTable.rwKeywordSet().define("RESTFREQS", rfvec);
|
---|
721 | table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
|
---|
722 | return True;
|
---|
723 | }
|
---|
724 |
|
---|
725 | SDFrequencyTable SDMemTable::getSDFreqTable() const
|
---|
726 | {
|
---|
727 | // TODO !!!!! implement this properly USE with care
|
---|
728 | const Table& t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
729 | SDFrequencyTable sdft;
|
---|
730 | sdft.setLength(t.nrow());
|
---|
731 | return sdft;
|
---|
732 | }
|
---|
733 |
|
---|
734 | bool SDMemTable::putSDContainer(const SDContainer& sdc)
|
---|
735 | {
|
---|
736 | ScalarColumn<Double> mjd(table_, "TIME");
|
---|
737 | ScalarColumn<String> srcn(table_, "SRCNAME");
|
---|
738 | ScalarColumn<String> fldn(table_, "FIELDNAME");
|
---|
739 | ArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
740 | ArrayColumn<uChar> flags(table_, "FLAGTRA");
|
---|
741 | ArrayColumn<Float> ts(table_, "TSYS");
|
---|
742 | ScalarColumn<Int> scan(table_, "SCANID");
|
---|
743 | ScalarColumn<Double> integr(table_, "INTERVAL");
|
---|
744 | ArrayColumn<uInt> freqid(table_, "FREQID");
|
---|
745 | ArrayColumn<Double> dir(table_, "DIRECTION");
|
---|
746 | ScalarColumn<Int> rbeam(table_, "REFBEAM");
|
---|
747 | ArrayColumn<Float> tcal(table_, "TCAL");
|
---|
748 | ScalarColumn<String> tcalt(table_, "TCALTIME");
|
---|
749 | ScalarColumn<Float> az(table_, "AZIMUTH");
|
---|
750 | ScalarColumn<Float> el(table_, "ELEVATION");
|
---|
751 | ScalarColumn<Float> para(table_, "PARANGLE");
|
---|
752 | ArrayColumn<String> hist(table_, "HISTORY");
|
---|
753 |
|
---|
754 | uInt rno = table_.nrow();
|
---|
755 | table_.addRow();
|
---|
756 |
|
---|
757 | mjd.put(rno, sdc.timestamp);
|
---|
758 | srcn.put(rno, sdc.sourcename);
|
---|
759 | fldn.put(rno, sdc.fieldname);
|
---|
760 | spec.put(rno, sdc.getSpectrum());
|
---|
761 | flags.put(rno, sdc.getFlags());
|
---|
762 | ts.put(rno, sdc.getTsys());
|
---|
763 | scan.put(rno, sdc.scanid);
|
---|
764 | integr.put(rno, sdc.interval);
|
---|
765 | freqid.put(rno, sdc.getFreqMap());
|
---|
766 | dir.put(rno, sdc.getDirection());
|
---|
767 | rbeam.put(rno, sdc.refbeam);
|
---|
768 | tcal.put(rno, sdc.tcal);
|
---|
769 | tcalt.put(rno, sdc.tcaltime);
|
---|
770 | az.put(rno, sdc.azimuth);
|
---|
771 | el.put(rno, sdc.elevation);
|
---|
772 | para.put(rno, sdc.parangle);
|
---|
773 | hist.put(rno, sdc.getHistory());
|
---|
774 |
|
---|
775 | return true;
|
---|
776 | }
|
---|
777 |
|
---|
778 | SDContainer SDMemTable::getSDContainer(uInt whichRow) const
|
---|
779 | {
|
---|
780 | ROScalarColumn<Double> mjd(table_, "TIME");
|
---|
781 | ROScalarColumn<String> srcn(table_, "SRCNAME");
|
---|
782 | ROScalarColumn<String> fldn(table_, "FIELDNAME");
|
---|
783 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
784 | ROArrayColumn<uChar> flags(table_, "FLAGTRA");
|
---|
785 | ROArrayColumn<Float> ts(table_, "TSYS");
|
---|
786 | ROScalarColumn<Int> scan(table_, "SCANID");
|
---|
787 | ROScalarColumn<Double> integr(table_, "INTERVAL");
|
---|
788 | ROArrayColumn<uInt> freqid(table_, "FREQID");
|
---|
789 | ROArrayColumn<Double> dir(table_, "DIRECTION");
|
---|
790 | ROScalarColumn<Int> rbeam(table_, "REFBEAM");
|
---|
791 | ROArrayColumn<Float> tcal(table_, "TCAL");
|
---|
792 | ROScalarColumn<String> tcalt(table_, "TCALTIME");
|
---|
793 | ROScalarColumn<Float> az(table_, "AZIMUTH");
|
---|
794 | ROScalarColumn<Float> el(table_, "ELEVATION");
|
---|
795 | ROScalarColumn<Float> para(table_, "PARANGLE");
|
---|
796 | ROArrayColumn<String> hist(table_, "HISTORY");
|
---|
797 |
|
---|
798 | SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
|
---|
799 | mjd.get(whichRow, sdc.timestamp);
|
---|
800 | srcn.get(whichRow, sdc.sourcename);
|
---|
801 | integr.get(whichRow, sdc.interval);
|
---|
802 | scan.get(whichRow, sdc.scanid);
|
---|
803 | fldn.get(whichRow, sdc.fieldname);
|
---|
804 | rbeam.get(whichRow, sdc.refbeam);
|
---|
805 | az.get(whichRow, sdc.azimuth);
|
---|
806 | el.get(whichRow, sdc.elevation);
|
---|
807 | para.get(whichRow, sdc.parangle);
|
---|
808 | Vector<Float> tc;
|
---|
809 | tcal.get(whichRow, tc);
|
---|
810 | sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
|
---|
811 | tcalt.get(whichRow, sdc.tcaltime);
|
---|
812 | Array<Float> spectrum;
|
---|
813 | Array<Float> tsys;
|
---|
814 | Array<uChar> flagtrum;
|
---|
815 | Vector<uInt> fmap;
|
---|
816 | Array<Double> direction;
|
---|
817 | Vector<String> histo;
|
---|
818 | spec.get(whichRow, spectrum);
|
---|
819 | sdc.putSpectrum(spectrum);
|
---|
820 | flags.get(whichRow, flagtrum);
|
---|
821 | sdc.putFlags(flagtrum);
|
---|
822 | ts.get(whichRow, tsys);
|
---|
823 | sdc.putTsys(tsys);
|
---|
824 | freqid.get(whichRow, fmap);
|
---|
825 | sdc.putFreqMap(fmap);
|
---|
826 | dir.get(whichRow, direction);
|
---|
827 | sdc.putDirection(direction);
|
---|
828 | hist.get(whichRow, histo);
|
---|
829 | sdc.putHistory(histo);
|
---|
830 | return sdc;
|
---|
831 | }
|
---|
832 |
|
---|
833 | bool SDMemTable::putSDHeader(const SDHeader& sdh)
|
---|
834 | {
|
---|
835 | table_.rwKeywordSet().define("nIF", sdh.nif);
|
---|
836 | table_.rwKeywordSet().define("nBeam", sdh.nbeam);
|
---|
837 | table_.rwKeywordSet().define("nPol", sdh.npol);
|
---|
838 | table_.rwKeywordSet().define("nChan", sdh.nchan);
|
---|
839 | table_.rwKeywordSet().define("Observer", sdh.observer);
|
---|
840 | table_.rwKeywordSet().define("Project", sdh.project);
|
---|
841 | table_.rwKeywordSet().define("Obstype", sdh.obstype);
|
---|
842 | table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
|
---|
843 | table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
|
---|
844 | table_.rwKeywordSet().define("Equinox", sdh.equinox);
|
---|
845 | table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
|
---|
846 | table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
|
---|
847 | table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
|
---|
848 | table_.rwKeywordSet().define("UTC", sdh.utc);
|
---|
849 | table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
|
---|
850 | table_.rwKeywordSet().define("Epoch", sdh.epoch);
|
---|
851 | return true;
|
---|
852 | }
|
---|
853 |
|
---|
854 | SDHeader SDMemTable::getSDHeader() const
|
---|
855 | {
|
---|
856 | SDHeader sdh;
|
---|
857 | table_.keywordSet().get("nBeam",sdh.nbeam);
|
---|
858 | table_.keywordSet().get("nIF",sdh.nif);
|
---|
859 | table_.keywordSet().get("nPol",sdh.npol);
|
---|
860 | table_.keywordSet().get("nChan",sdh.nchan);
|
---|
861 | table_.keywordSet().get("Observer", sdh.observer);
|
---|
862 | table_.keywordSet().get("Project", sdh.project);
|
---|
863 | table_.keywordSet().get("Obstype", sdh.obstype);
|
---|
864 | table_.keywordSet().get("AntennaName", sdh.antennaname);
|
---|
865 | table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
|
---|
866 | table_.keywordSet().get("Equinox", sdh.equinox);
|
---|
867 | table_.keywordSet().get("FreqRefFrame", sdh.freqref);
|
---|
868 | table_.keywordSet().get("FreqRefVal", sdh.reffreq);
|
---|
869 | table_.keywordSet().get("Bandwidth", sdh.bandwidth);
|
---|
870 | table_.keywordSet().get("UTC", sdh.utc);
|
---|
871 | table_.keywordSet().get("FluxUnit", sdh.fluxunit);
|
---|
872 | table_.keywordSet().get("Epoch", sdh.epoch);
|
---|
873 | return sdh;
|
---|
874 | }
|
---|
875 | void SDMemTable::makePersistent(const std::string& filename)
|
---|
876 | {
|
---|
877 | table_.deepCopy(filename,Table::New);
|
---|
878 | }
|
---|
879 |
|
---|
880 | Int SDMemTable::nScan() const {
|
---|
881 | Int n = 0;
|
---|
882 | ROScalarColumn<Int> scans(table_, "SCANID");
|
---|
883 | Int previous = -1;Int current=0;
|
---|
884 | for (uInt i=0; i< scans.nrow();i++) {
|
---|
885 | scans.getScalar(i,current);
|
---|
886 | if (previous != current) {
|
---|
887 | previous = current;
|
---|
888 | n++;
|
---|
889 | }
|
---|
890 | }
|
---|
891 | return n;
|
---|
892 | }
|
---|
893 |
|
---|
894 | String SDMemTable::formatSec(Double x)
|
---|
895 | {
|
---|
896 | Double xcop = x;
|
---|
897 | MVTime mvt(xcop/24./3600.); // make days
|
---|
898 | if (x < 59.95)
|
---|
899 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
|
---|
900 | return mvt.string(MVTime::TIME_CLEAN_NO_H, 7)+" ";
|
---|
901 | };
|
---|
902 |
|
---|
903 | std::string SDMemTable::getFluxUnit() const
|
---|
904 | {
|
---|
905 | String tmp;
|
---|
906 | table_.keywordSet().get("FluxUnit", tmp);
|
---|
907 | return tmp;
|
---|
908 | }
|
---|
909 |
|
---|
910 | void SDMemTable::setFluxUnit(const std::string& unit)
|
---|
911 | {
|
---|
912 | String tmp(unit);
|
---|
913 | Unit tU(tmp);
|
---|
914 | if (tU==Unit("K") || tU==Unit("Jy")) {
|
---|
915 | table_.rwKeywordSet().define(String("FluxUnit"), tmp);
|
---|
916 | } else {
|
---|
917 | throw AipsError("Illegal unit - must be compatible with Jy or K");
|
---|
918 | }
|
---|
919 | }
|
---|
920 |
|
---|
921 | void SDMemTable::setInstrument(const std::string& name)
|
---|
922 | {
|
---|
923 | Bool throwIt = True;
|
---|
924 | Instrument ins = convertInstrument (name, throwIt);
|
---|
925 | String nameU(name);
|
---|
926 | nameU.upcase();
|
---|
927 | table_.rwKeywordSet().define(String("AntennaName"), nameU);
|
---|
928 | }
|
---|
929 |
|
---|
930 | std::string SDMemTable::summary() {
|
---|
931 | ROScalarColumn<Int> scans(table_, "SCANID");
|
---|
932 | ROScalarColumn<String> srcs(table_, "SRCNAME");
|
---|
933 | ostringstream oss;
|
---|
934 | oss << endl;
|
---|
935 | oss << "--------------------------------------------------" << endl;
|
---|
936 | oss << " Scan Table Summary" << endl;
|
---|
937 | oss << "--------------------------------------------------" << endl;
|
---|
938 | oss.flags(std::ios_base::left);
|
---|
939 | oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
|
---|
940 | << setw(15) << "IFs:" << setw(4) << nIF() << endl
|
---|
941 | << setw(15) << "Polarisations:" << setw(4) << nPol() << endl
|
---|
942 | << setw(15) << "Channels:" << setw(4) << nChan() << endl;
|
---|
943 | oss << endl;
|
---|
944 | String tmp;
|
---|
945 | table_.keywordSet().get("Observer", tmp);
|
---|
946 | oss << setw(15) << "Observer:" << tmp << endl;
|
---|
947 | table_.keywordSet().get("Project", tmp);
|
---|
948 | oss << setw(15) << "Project:" << tmp << endl;
|
---|
949 | table_.keywordSet().get("Obstype", tmp);
|
---|
950 | oss << setw(15) << "Obs. Type:" << tmp << endl;
|
---|
951 | table_.keywordSet().get("AntennaName", tmp);
|
---|
952 | oss << setw(15) << "Antenna Name:" << tmp << endl;
|
---|
953 | table_.keywordSet().get("FluxUnit", tmp);
|
---|
954 | oss << setw(15) << "Flux Unit:" << tmp << endl;
|
---|
955 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
|
---|
956 | Vector<Double> vec;
|
---|
957 | t.keywordSet().get("RESTFREQS",vec);
|
---|
958 | oss << setw(15) << "Rest Freqs:";
|
---|
959 | if (vec.nelements() > 0) {
|
---|
960 | oss << setprecision(0) << vec << " [Hz]" << endl;
|
---|
961 | } else {
|
---|
962 | oss << "None set" << endl;
|
---|
963 | }
|
---|
964 | oss << setw(15) << "Abcissa:" << getAbcissaString() << endl;
|
---|
965 | oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
|
---|
966 | << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
|
---|
967 | oss << endl;
|
---|
968 | uInt count = 0;
|
---|
969 | String name;
|
---|
970 | Int previous = -1;Int current=0;
|
---|
971 | Int integ = 0;
|
---|
972 | oss << setw(6) << "Scan"
|
---|
973 | << setw(12) << "Source"
|
---|
974 | << setw(21) << "Time"
|
---|
975 | << setw(11) << "Integration" << endl;
|
---|
976 | oss << "--------------------------------------------------" << endl;
|
---|
977 | for (uInt i=0; i< scans.nrow();i++) {
|
---|
978 | scans.getScalar(i,current);
|
---|
979 | if (previous != current) {
|
---|
980 | srcs.getScalar(i,name);
|
---|
981 | previous = current;
|
---|
982 | String t = formatSec(Double(getInterval(i)));
|
---|
983 | oss << setw(6) << count << setw(12) << name << setw(21) << getTime(i)
|
---|
984 | << setw(2) << setprecision(1)
|
---|
985 | << t << endl;
|
---|
986 | count++;
|
---|
987 | } else {
|
---|
988 | integ++;
|
---|
989 | }
|
---|
990 | }
|
---|
991 | oss << endl;
|
---|
992 | oss << "Table contains " << table_.nrow() << " integration(s)." << endl;
|
---|
993 | oss << "in " << count << " scan(s)." << endl;
|
---|
994 | oss << "--------------------------------------------------";
|
---|
995 | return String(oss);
|
---|
996 | }
|
---|
997 |
|
---|
998 | Int SDMemTable::nBeam() const
|
---|
999 | {
|
---|
1000 | Int n;
|
---|
1001 | table_.keywordSet().get("nBeam",n);
|
---|
1002 | return n;
|
---|
1003 | }
|
---|
1004 | Int SDMemTable::nIF() const {
|
---|
1005 | Int n;
|
---|
1006 | table_.keywordSet().get("nIF",n);
|
---|
1007 | return n;
|
---|
1008 | }
|
---|
1009 | Int SDMemTable::nPol() const {
|
---|
1010 | Int n;
|
---|
1011 | table_.keywordSet().get("nPol",n);
|
---|
1012 | return n;
|
---|
1013 | }
|
---|
1014 | Int SDMemTable::nChan() const {
|
---|
1015 | Int n;
|
---|
1016 | table_.keywordSet().get("nChan",n);
|
---|
1017 | return n;
|
---|
1018 | }
|
---|
1019 | bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
|
---|
1020 | {
|
---|
1021 | ArrayColumn<String> histo(table_, "HISTORY");
|
---|
1022 | Vector<String> history;
|
---|
1023 | histo.get(whichRow, history);
|
---|
1024 | history.resize(history.nelements()+1,True);
|
---|
1025 | history[history.nelements()-1] = hist;
|
---|
1026 | histo.put(whichRow, history);
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | std::vector<std::string> SDMemTable::history(int whichRow) const
|
---|
1030 | {
|
---|
1031 | ROArrayColumn<String> hist(table_, "HISTORY");
|
---|
1032 | Vector<String> history;
|
---|
1033 | hist.get(whichRow, history);
|
---|
1034 | std::vector<std::string> stlout;
|
---|
1035 | // there is no Array<String>.tovector(std::vector<std::string>), so
|
---|
1036 | // do it by hand
|
---|
1037 | for (uInt i=0; i<history.nelements(); ++i) {
|
---|
1038 | stlout.push_back(history[i]);
|
---|
1039 | }
|
---|
1040 | return stlout;
|
---|
1041 | }
|
---|
1042 | /*
|
---|
1043 | void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
|
---|
1044 |
|
---|
1045 | std::vector<int>::iterator it;
|
---|
1046 | ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_);
|
---|
1047 | for (it = whichChans.begin(); it != whichChans.end(); it++) {
|
---|
1048 | j.reset(j.begin(uInt(*it)));
|
---|
1049 | for (ArrayAccessor<uChar, Axis<asap::BeamAxis> > i(j); i != i.end(); ++i) {
|
---|
1050 | for (ArrayAccessor<uChar, Axis<asap::IFAxis> > ii(i); ii != ii.end(); ++ii) {
|
---|
1051 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > iii(ii);
|
---|
1052 | iii != iii.end(); ++iii) {
|
---|
1053 | (*iii) =
|
---|
1054 | }
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 | }
|
---|
1058 |
|
---|
1059 | }
|
---|
1060 | */
|
---|
1061 | void SDMemTable::flag(int whichRow)
|
---|
1062 | {
|
---|
1063 | ArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
1064 | Array<uChar> arr;
|
---|
1065 | spec.get(whichRow, arr);
|
---|
1066 |
|
---|
1067 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
|
---|
1068 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
1069 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
|
---|
1070 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
1071 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
|
---|
1072 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
1073 |
|
---|
1074 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
1075 | (*i) = uChar(True);
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | spec.put(whichRow, arr);
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 | MDirection::Types SDMemTable::getDirectionReference () const
|
---|
1082 | {
|
---|
1083 | Float eq;
|
---|
1084 | table_.keywordSet().get("Equinox",eq);
|
---|
1085 | std::map<float,string> mp;
|
---|
1086 | mp[2000.0] = "J2000";
|
---|
1087 | mp[1950.0] = "B1950";
|
---|
1088 | MDirection::Types mdr;
|
---|
1089 | if (!MDirection::getType(mdr, mp[eq])) {
|
---|
1090 | mdr = MDirection::J2000;
|
---|
1091 | cerr << "Unknown equinox using J2000" << endl;
|
---|
1092 | }
|
---|
1093 | //
|
---|
1094 | return mdr;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | MEpoch::Types SDMemTable::getTimeReference () const
|
---|
1098 | {
|
---|
1099 | MEpoch::Types met;
|
---|
1100 | String ep;
|
---|
1101 | table_.keywordSet().get("Epoch",ep);
|
---|
1102 | if (!MEpoch::getType(met, ep)) {
|
---|
1103 | cerr << "Epoch type uknown - using UTC" << endl;
|
---|
1104 | met = MEpoch::UTC;
|
---|
1105 | }
|
---|
1106 | //
|
---|
1107 | return met;
|
---|
1108 | }
|
---|
1109 |
|
---|
1110 |
|
---|
1111 | Instrument SDMemTable::convertInstrument (const String& instrument,
|
---|
1112 | Bool throwIt)
|
---|
1113 | {
|
---|
1114 | String t(instrument);
|
---|
1115 | t.upcase();
|
---|
1116 | //
|
---|
1117 | Instrument inst = asap::UNKNOWN;
|
---|
1118 | if (t==String("TID")) {
|
---|
1119 | inst = TIDBINBILLA;
|
---|
1120 | } else if (t==String("ATPKSMB")) {
|
---|
1121 | inst = PKSMULTIBEAM;
|
---|
1122 | } else if (t==String("ATPKSSB")) {
|
---|
1123 | inst = PKSSINGLEBEAM;
|
---|
1124 | } else if (t==String("MOPRA")) {
|
---|
1125 | inst = MOPRA;
|
---|
1126 | } else {
|
---|
1127 | if (throwIt) {
|
---|
1128 | throw AipsError("Unrecognized instrument - use function scan.set_instrument to set");
|
---|
1129 | }
|
---|
1130 | }
|
---|
1131 | return inst;
|
---|
1132 | }
|
---|
1133 |
|
---|