source: trunk/src/SDMemTable.cc@ 339

Last change on this file since 339 was 329, checked in by kil064, 20 years ago

make sure call attach() function in all constructors

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 37.0 KB
Line 
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#include <casa/Quanta/MVAngle.h>
44
45#include <tables/Tables/TableParse.h>
46#include <tables/Tables/TableDesc.h>
47#include <tables/Tables/SetupNewTab.h>
48#include <tables/Tables/ScaColDesc.h>
49#include <tables/Tables/ArrColDesc.h>
50
51#include <tables/Tables/ExprNode.h>
52#include <tables/Tables/TableRecord.h>
53#include <measures/Measures/MFrequency.h>
54#include <measures/Measures/MeasTable.h>
55#include <coordinates/Coordinates/CoordinateUtil.h>
56#include <casa/Quanta/MVTime.h>
57#include <casa/Quanta/MVAngle.h>
58
59#include "SDDefs.h"
60#include "SDMemTable.h"
61#include "SDContainer.h"
62
63
64using namespace casa;
65using namespace asap;
66
67SDMemTable::SDMemTable() :
68 IFSel_(0),
69 beamSel_(0),
70 polSel_(0)
71{
72 setup();
73 attach();
74}
75
76SDMemTable::SDMemTable(const std::string& name) :
77 IFSel_(0),
78 beamSel_(0),
79 polSel_(0)
80{
81 Table tab(name);
82 table_ = tab.copyToMemoryTable("dummy");
83 //cerr << "hello from C SDMemTable @ " << this << endl;
84 attach();
85}
86
87SDMemTable::SDMemTable(const SDMemTable& other, Bool clear)
88{
89 IFSel_= other.IFSel_;
90 beamSel_= other.beamSel_;
91 polSel_= other.polSel_;
92 chanMask_ = other.chanMask_;
93 table_ = other.table_.copyToMemoryTable(String("dummy"));
94 // clear all rows()
95 if (clear) {
96 table_.removeRow(this->table_.rowNumbers());
97 } else {
98 IFSel_ = other.IFSel_;
99 beamSel_ = other.beamSel_;
100 polSel_ = other.polSel_;
101 }
102//
103 attach();
104 //cerr << "hello from CC SDMemTable @ " << this << endl;
105}
106
107SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) :
108 IFSel_(0),
109 beamSel_(0),
110 polSel_(0)
111{
112 Table t = tableCommand(exprs,tab);
113 if (t.nrow() == 0)
114 throw(AipsError("Query unsuccessful."));
115 table_ = t.copyToMemoryTable("dummy");
116 attach();
117}
118
119SDMemTable::~SDMemTable()
120{
121 //cerr << "goodbye from SDMemTable @ " << this << endl;
122}
123
124SDMemTable SDMemTable::getScan(Int scanID) const
125{
126 String cond("SELECT * from $1 WHERE SCANID == ");
127 cond += String::toString(scanID);
128 return SDMemTable(table_, cond);
129}
130
131SDMemTable &SDMemTable::operator=(const SDMemTable& other)
132{
133 if (this != &other) {
134 IFSel_= other.IFSel_;
135 beamSel_= other.beamSel_;
136 polSel_= other.polSel_;
137 chanMask_.resize(0);
138 chanMask_ = other.chanMask_;
139 table_ = other.table_.copyToMemoryTable(String("dummy"));
140 attach();
141 }
142 //cerr << "hello from ASS SDMemTable @ " << this << endl;
143 return *this;
144}
145
146SDMemTable SDMemTable::getSource(const std::string& source) const
147{
148 String cond("SELECT * from $1 WHERE SRCNAME == ");
149 cond += source;
150 return SDMemTable(table_, cond);
151}
152
153void SDMemTable::setup()
154{
155 TableDesc td("", "1", TableDesc::Scratch);
156 td.comment() = "A SDMemTable";
157//
158 td.addColumn(ScalarColumnDesc<Double>("TIME"));
159 td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
160 td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
161 td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
162 td.addColumn(ArrayColumnDesc<Float>("TSYS"));
163 td.addColumn(ScalarColumnDesc<Int>("SCANID"));
164 td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
165 td.addColumn(ArrayColumnDesc<uInt>("FREQID"));
166 td.addColumn(ArrayColumnDesc<Double>("DIRECTION"));
167 td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
168 td.addColumn(ScalarColumnDesc<String>("TCALTIME"));
169 td.addColumn(ArrayColumnDesc<Float>("TCAL"));
170 td.addColumn(ScalarColumnDesc<Float>("AZIMUTH"));
171 td.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
172 td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
173 td.addColumn(ScalarColumnDesc<Int>("REFBEAM"));
174 td.addColumn(ArrayColumnDesc<String>("HISTORY"));
175
176 // Now create a new table from the description.
177
178 SetupNewTable aNewTab("dummy", td, Table::New);
179 table_ = Table(aNewTab, Table::Memory, 0);
180}
181
182void SDMemTable::attach ()
183{
184 timeCol_.attach(table_, "TIME");
185 srcnCol_.attach(table_, "SRCNAME");
186 specCol_.attach(table_, "SPECTRA");
187 flagsCol_.attach(table_, "FLAGTRA");
188 tsCol_.attach(table_, "TSYS");
189 scanCol_.attach(table_, "SCANID");
190 integrCol_.attach(table_, "INTERVAL");
191 freqidCol_.attach(table_, "FREQID");
192 dirCol_.attach(table_, "DIRECTION");
193 fldnCol_.attach(table_, "FIELDNAME");
194 tcaltCol_.attach(table_, "TCALTIME");
195 tcalCol_.attach(table_, "TCAL");
196 azCol_.attach(table_, "AZIMUTH");
197 elCol_.attach(table_, "ELEVATION");
198 paraCol_.attach(table_, "PARANGLE");
199 rbeamCol_.attach(table_, "REFBEAM");
200 histCol_.attach(table_, "HISTORY");
201}
202
203
204std::string SDMemTable::getSourceName(Int whichRow) const
205{
206 String name;
207 srcnCol_.get(whichRow, name);
208 return name;
209}
210
211std::string SDMemTable::getTime(Int whichRow, Bool showDate) const
212{
213 Double tm;
214 if (whichRow > -1) {
215 timeCol_.get(whichRow, tm);
216 } else {
217 table_.keywordSet().get("UTC",tm);
218 }
219 MVTime mvt(tm);
220 if (showDate)
221 mvt.setFormat(MVTime::YMD);
222 else
223 mvt.setFormat(MVTime::TIME);
224 ostringstream oss;
225 oss << mvt;
226 return String(oss);
227}
228
229double SDMemTable::getInterval(Int whichRow) const
230{
231 Double intval;
232 integrCol_.get(whichRow, intval);
233 return intval;
234}
235
236bool SDMemTable::setIF(Int whichIF)
237{
238 if ( whichIF >= 0 && whichIF < nIF()) {
239 IFSel_ = whichIF;
240 return true;
241 }
242 return false;
243}
244
245bool SDMemTable::setBeam(Int whichBeam)
246{
247 if ( whichBeam >= 0 && whichBeam < nBeam()) {
248 beamSel_ = whichBeam;
249 return true;
250 }
251 return false;
252}
253
254bool SDMemTable::setPol(Int whichPol)
255{
256 if ( whichPol >= 0 && whichPol < nPol()) {
257 polSel_ = whichPol;
258 return true;
259 }
260 return false;
261}
262
263void SDMemTable::resetCursor ()
264{
265 polSel_ = 0;
266 IFSel_ = 0;
267 beamSel_ = 0;
268}
269
270bool SDMemTable::setMask(std::vector<int> whichChans)
271{
272 std::vector<int>::iterator it;
273 uInt n = flagsCol_.shape(0)(3);
274 if (whichChans.empty()) {
275 chanMask_ = std::vector<bool>(n,true);
276 return true;
277 }
278 chanMask_.resize(n,true);
279 for (it = whichChans.begin(); it != whichChans.end(); ++it) {
280 if (*it < n) {
281 chanMask_[*it] = false;
282 }
283 }
284 return true;
285}
286
287std::vector<bool> SDMemTable::getMask(Int whichRow) const {
288 std::vector<bool> mask;
289 Array<uChar> arr;
290 flagsCol_.get(whichRow, arr);
291 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
292 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
293 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
294 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
295 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
296 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
297
298 Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
299
300 std::vector<bool> tmp;
301 tmp = chanMask_; // WHY the fxxx do I have to make a copy here
302 std::vector<bool>::iterator miter;
303 miter = tmp.begin();
304
305 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
306 bool out =!static_cast<bool>(*i);
307 if (useUserMask) {
308 out = out && (*miter);
309 miter++;
310 }
311 mask.push_back(out);
312 }
313 return mask;
314}
315std::vector<float> SDMemTable::getSpectrum(Int whichRow) const
316{
317 std::vector<float> spectrum;
318 Array<Float> arr;
319 specCol_.get(whichRow, arr);
320 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
321 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
322 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
323 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
324 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
325 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
326 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
327 spectrum.push_back(*i);
328 }
329 return spectrum;
330}
331std::vector<string> SDMemTable::getCoordInfo() const
332{
333 String un;
334 Table t = table_.keywordSet().asTable("FREQUENCIES");
335 String sunit;
336 t.keywordSet().get("UNIT",sunit);
337 String dpl;
338 t.keywordSet().get("DOPPLER",dpl);
339 if (dpl == "") dpl = "RADIO";
340 String rfrm;
341 t.keywordSet().get("REFFRAME",rfrm);
342 std::vector<string> inf;
343 inf.push_back(sunit);
344 inf.push_back(rfrm);
345 inf.push_back(dpl);
346 t.keywordSet().get("BASEREFFRAME",rfrm);
347 inf.push_back(rfrm);
348 return inf;
349}
350
351void SDMemTable::setCoordInfo(std::vector<string> theinfo)
352{
353 std::vector<string>::iterator it;
354 String un,rfrm, brfrm,dpl;
355 un = theinfo[0]; // Abcissa unit
356 rfrm = theinfo[1]; // Active (or conversion) frame
357 dpl = theinfo[2]; // Doppler
358 brfrm = theinfo[3]; // Base frame
359//
360 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
361//
362 Vector<Double> rstf;
363 t.keywordSet().get("RESTFREQS",rstf);
364//
365 Bool canDo = True;
366 Unit u1("km/s");Unit u2("Hz");
367 if (Unit(un) == u1) {
368 Vector<Double> rstf;
369 t.keywordSet().get("RESTFREQS",rstf);
370 if (rstf.nelements() == 0) {
371 throw(AipsError("Can't set unit to km/s if no restfrequencies are specified"));
372 }
373 } else if (Unit(un) != u2 && un != "") {
374 throw(AipsError("Unit not conformant with Spectral Coordinates"));
375 }
376 t.rwKeywordSet().define("UNIT", un);
377//
378 MFrequency::Types mdr;
379 if (!MFrequency::getType(mdr, rfrm)) {
380
381 Int a,b;const uInt* c;
382 const String* valid = MFrequency::allMyTypes(a, b, c);
383 String pfix = "Please specify a legal frame type. Types are\n";
384 throw(AipsError(pfix+(*valid)));
385 } else {
386 t.rwKeywordSet().define("REFFRAME",rfrm);
387 }
388//
389 MDoppler::Types dtype;
390 dpl.upcase();
391 if (!MDoppler::getType(dtype, dpl)) {
392 throw(AipsError("Doppler type unknown"));
393 } else {
394 t.rwKeywordSet().define("DOPPLER",dpl);
395 }
396//
397 if (!MFrequency::getType(mdr, brfrm)) {
398 Int a,b;const uInt* c;
399 const String* valid = MFrequency::allMyTypes(a, b, c);
400 String pfix = "Please specify a legal frame type. Types are\n";
401 throw(AipsError(pfix+(*valid)));
402 } else {
403 t.rwKeywordSet().define("BASEREFFRAME",brfrm);
404 }
405}
406
407
408std::vector<double> SDMemTable::getAbcissa(Int whichRow) const
409{
410 std::vector<double> abc(nChan());
411
412// Get header units keyword
413
414 Table t = table_.keywordSet().asTable("FREQUENCIES");
415 String sunit;
416 t.keywordSet().get("UNIT",sunit);
417 if (sunit == "") sunit = "pixel";
418 Unit u(sunit);
419
420// Easy if just wanting pixels
421
422 if (sunit==String("pixel")) {
423 // assume channels/pixels
424 std::vector<double>::iterator it;
425 uInt i=0;
426 for (it = abc.begin(); it != abc.end(); ++it) {
427 (*it) = Double(i++);
428 }
429//
430 return abc;
431 }
432
433// Continue with km/s or Hz. Get FreqID
434
435 Vector<uInt> v;
436 freqidCol_.get(whichRow, v);
437 uInt specidx = v(IFSel_);
438
439// Get SpectralCoordinate, set reference frame conversion,
440// velocity conversion, and rest freq state
441
442 SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow);
443//
444 Vector<Double> pixel(nChan());
445 indgen(pixel);
446//
447 if (u == Unit("km/s")) {
448 Vector<Double> world;
449 spc.pixelToVelocity(world,pixel);
450 std::vector<double>::iterator it;
451 uInt i = 0;
452 for (it = abc.begin(); it != abc.end(); ++it) {
453 (*it) = world[i];
454 i++;
455 }
456 } else if (u == Unit("Hz")) {
457
458// Set world axis units
459
460 Vector<String> wau(1); wau = u.getName();
461 spc.setWorldAxisUnits(wau);
462//
463 std::vector<double>::iterator it;
464 Double tmp;
465 uInt i = 0;
466 for (it = abc.begin(); it != abc.end(); ++it) {
467 spc.toWorld(tmp,pixel[i]);
468 (*it) = tmp;
469 i++;
470 }
471 }
472 return abc;
473}
474
475std::string SDMemTable::getAbcissaString(Int whichRow) const
476{
477 Table t = table_.keywordSet().asTable("FREQUENCIES");
478//
479 String sunit;
480 t.keywordSet().get("UNIT",sunit);
481 if (sunit == "") sunit = "pixel";
482 Unit u(sunit);
483//
484 Vector<uInt> v;
485 freqidCol_.get(whichRow, v);
486 uInt specidx = v(IFSel_);
487
488// Get SpectralCoordinate, with frame, velocity, rest freq state set
489
490 SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow);
491//
492 String s = "Channel";
493 if (u == Unit("km/s")) {
494 s = CoordinateUtil::axisLabel(spc,0,True,True,True);
495 } else if (u == Unit("Hz")) {
496 Vector<String> wau(1);wau = u.getName();
497 spc.setWorldAxisUnits(wau);
498//
499 s = CoordinateUtil::axisLabel(spc,0,True,True,False);
500 }
501 return s;
502}
503
504void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow)
505{
506 Array<Float> arr;
507 specCol_.get(whichRow, arr);
508 if (spectrum.size() != arr.shape()(3)) {
509 throw(AipsError("Attempting to set spectrum with incorrect length."));
510 }
511
512 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
513 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
514 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
515 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
516 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
517 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
518
519 std::vector<float>::iterator it = spectrum.begin();
520 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
521 (*i) = Float(*it);
522 it++;
523 }
524 specCol_.put(whichRow, arr);
525}
526
527void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const
528{
529 Array<Float> arr;
530 specCol_.get(whichRow, arr);
531 spectrum.resize(arr.shape()(3));
532 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
533 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
534 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
535 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
536 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
537 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
538
539 ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
540 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
541 (*va) = (*i);
542 va++;
543 }
544}
545/*
546void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
547 Array<uChar> arr;
548 flagsCol_.get(whichRow, arr);
549 mask.resize(arr.shape()(3));
550
551 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
552 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
553 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
554 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
555 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
556 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
557
558 Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
559
560 ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask);
561 std::vector<bool> tmp;
562 tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
563 // iterator should work on chanMask_??
564 std::vector<bool>::iterator miter;
565 miter = tmp.begin();
566
567 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
568 bool out =!static_cast<bool>(*i);
569 if (useUserMask) {
570 out = out && (*miter);
571 miter++;
572 }
573 (*va) = out;
574 va++;
575 }
576}
577*/
578MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
579 Bool useSelection) const
580{
581 Array<Float> arr;
582 Array<uChar> farr;
583 specCol_.get(whichRow, arr);
584 flagsCol_.get(whichRow, farr);
585 Array<Bool> barr(farr.shape());convertArray(barr, farr);
586 MaskedArray<Float> marr;
587 if (useSelection) {
588 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
589 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
590 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
591 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
592 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
593 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
594
595 ArrayAccessor<Bool, Axis<asap::BeamAxis> > baa0(barr);
596 baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam
597 ArrayAccessor<Bool, Axis<asap::IFAxis> > baa1(baa0);
598 baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF
599 ArrayAccessor<Bool, Axis<asap::PolAxis> > baa2(baa1);
600 baa2.reset(baa2.begin(uInt(polSel_)));// go to pol
601
602 Vector<Float> a(arr.shape()(3));
603 Vector<Bool> b(barr.shape()(3));
604 ArrayAccessor<Float, Axis<asap::BeamAxis> > a0(a);
605 ArrayAccessor<Bool, Axis<asap::BeamAxis> > b0(b);
606
607 ArrayAccessor<Bool, Axis<asap::ChanAxis> > j(baa2);
608 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2);
609 i != i.end(); ++i) {
610 (*a0) = (*i);
611 (*b0) = !(*j);
612 j++;
613 a0++;
614 b0++;
615 }
616 marr.setData(a,b);
617 } else {
618 marr.setData(arr,!barr);
619 }
620 return marr;
621}
622
623Float SDMemTable::getTsys(Int whichRow) const
624{
625 Array<Float> arr;
626 tsCol_.get(whichRow, arr);
627 Float out;
628 IPosition ip(arr.shape());
629 ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0;
630 out = arr(ip);
631 return out;
632}
633
634MDirection SDMemTable::getDirection(Int whichRow, Bool refBeam) const
635{
636 MDirection::Types mdr = getDirectionReference();
637 Array<Double> posit;
638 dirCol_.get(whichRow,posit);
639 Vector<Double> wpos(2);
640 wpos[0] = posit(IPosition(2,beamSel_,0));
641 wpos[1] = posit(IPosition(2,beamSel_,1));
642 Quantum<Double> lon(wpos[0],Unit(String("rad")));
643 Quantum<Double> lat(wpos[1],Unit(String("rad")));
644 return MDirection(lon, lat, mdr);
645}
646
647MEpoch SDMemTable::getEpoch (Int whichRow) const
648{
649 MEpoch::Types met = getTimeReference();
650//
651 Double obstime;
652 timeCol_.get(whichRow,obstime);
653 MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
654 return MEpoch(tm2, met);
655}
656
657MPosition SDMemTable::getAntennaPosition () const
658{
659 Vector<Double> antpos;
660 table_.keywordSet().get("AntennaPosition", antpos);
661 MVPosition mvpos(antpos(0),antpos(1),antpos(2));
662 return MPosition(mvpos);
663}
664
665
666SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx) const
667{
668
669 Table t = table_.keywordSet().asTable("FREQUENCIES");
670 if (whichIdx > t.nrow() ) {
671 throw(AipsError("SDMemTable::getSpectralCoordinate - whichIdx out of range"));
672 }
673
674 Double rp,rv,inc;
675 String rf;
676 ROScalarColumn<Double> rpc(t, "REFPIX");
677 ROScalarColumn<Double> rvc(t, "REFVAL");
678 ROScalarColumn<Double> incc(t, "INCREMENT");
679 t.keywordSet().get("BASEREFFRAME",rf);
680
681// Create SpectralCoordinate (units Hz)
682
683 MFrequency::Types mft;
684 if (!MFrequency::getType(mft, rf)) {
685 cerr << "Frequency type unknown assuming TOPO" << endl;
686 mft = MFrequency::TOPO;
687 }
688 rpc.get(whichIdx, rp);
689 rvc.get(whichIdx, rv);
690 incc.get(whichIdx, inc);
691//
692 SpectralCoordinate spec(mft,rv,inc,rp);
693//
694 return spec;
695}
696
697
698SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx, uInt whichRow) const
699{
700// Create basic SC
701
702 SpectralCoordinate spec = getSpectralCoordinate (whichIdx);
703//
704 Table t = table_.keywordSet().asTable("FREQUENCIES");
705
706// Set rest frequencies
707
708 Vector<Double> vec;
709 t.keywordSet().get("RESTFREQS",vec);
710 if (vec.nelements() > 0) {
711 spec.setRestFrequencies(vec);
712
713// Select rest freq
714
715 if (vec.nelements() >= nIF()) {
716 spec.selectRestFrequency(uInt(IFSel_));
717 }
718 }
719
720// Set up frame conversion layer
721
722 String frm;
723 t.keywordSet().get("REFFRAME",frm);
724 if (frm == "") frm = "TOPO";
725 MFrequency::Types mtype;
726 if (!MFrequency::getType(mtype, frm)) {
727 cout << "Frequency type unknown assuming TOPO" << endl; // SHould never happen
728 mtype = MFrequency::TOPO;
729 }
730
731// Set reference frame conversion (requires row)
732
733 MDirection direct = getDirection(whichRow);
734 MEpoch epoch = getEpoch(whichRow);
735 MPosition pos = getAntennaPosition();
736 if (!spec.setReferenceConversion(mtype,epoch,pos,direct)) {
737 throw(AipsError("Couldn't convert frequency frame."));
738 }
739
740// Now velocity conversion if appropriate
741
742 String unitStr;
743 t.keywordSet().get("UNIT",unitStr);
744//
745 String dpl;
746 t.keywordSet().get("DOPPLER",dpl);
747 MDoppler::Types dtype;
748 MDoppler::getType(dtype, dpl);
749
750// Only set velocity unit if non-blank and non-Hz
751
752 if (!unitStr.empty()) {
753 Unit unitU(unitStr);
754 if (unitU==Unit("Hz")) {
755 } else {
756 spec.setVelocity(unitStr, dtype);
757 }
758 }
759//
760 return spec;
761}
762
763
764Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
765 uInt whichIdx) {
766 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
767 if (whichIdx > t.nrow() ) {
768 throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
769 }
770 ScalarColumn<Double> rpc(t, "REFPIX");
771 ScalarColumn<Double> rvc(t, "REFVAL");
772 ScalarColumn<Double> incc(t, "INCREMENT");
773
774 rpc.put(whichIdx, speccord.referencePixel()[0]);
775 rvc.put(whichIdx, speccord.referenceValue()[0]);
776 incc.put(whichIdx, speccord.increment()[0]);
777
778 return True;
779}
780
781Int SDMemTable::nCoordinates() const
782{
783 return table_.keywordSet().asTable("FREQUENCIES").nrow();
784}
785
786void SDMemTable::setRestFreqs(std::vector<double> freqs,
787 const std::string& theunit)
788{
789 Vector<Double> tvec(freqs);
790 Quantum<Vector<Double> > q(tvec, String(theunit));
791 tvec.resize();
792 tvec = q.getValue("Hz");
793 Table t = table_.keywordSet().asTable("FREQUENCIES");
794 t.rwKeywordSet().define("RESTFREQS",tvec);
795}
796
797std::vector<double> SDMemTable::getRestFreqs() const
798{
799 Table t = table_.keywordSet().asTable("FREQUENCIES");
800 Vector<Double> tvec;
801 t.keywordSet().get("RESTFREQS",tvec);
802 std::vector<double> stlout;
803 tvec.tovector(stlout);
804 return stlout;
805}
806
807bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft)
808{
809 TableDesc td("", "1", TableDesc::Scratch);
810 td.addColumn(ScalarColumnDesc<Double>("REFPIX"));
811 td.addColumn(ScalarColumnDesc<Double>("REFVAL"));
812 td.addColumn(ScalarColumnDesc<Double>("INCREMENT"));
813 SetupNewTable aNewTab("freqs", td, Table::New);
814 Table aTable (aNewTab, Table::Memory, sdft.length());
815 ScalarColumn<Double> sc0(aTable, "REFPIX");
816 ScalarColumn<Double> sc1(aTable, "REFVAL");
817 ScalarColumn<Double> sc2(aTable, "INCREMENT");
818 for (uInt i=0; i < sdft.length(); ++i) {
819 sc0.put(i,sdft.referencePixel(i));
820 sc1.put(i,sdft.referenceValue(i));
821 sc2.put(i,sdft.increment(i));
822 }
823 String rf = sdft.refFrame();
824 if (rf.contains("TOPO")) rf = "TOPO";
825
826 aTable.rwKeywordSet().define("BASEREFFRAME", rf);
827 aTable.rwKeywordSet().define("REFFRAME", rf);
828 aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
829 aTable.rwKeywordSet().define("UNIT", String(""));
830 aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
831 Vector<Double> rfvec;
832 String rfunit;
833 sdft.restFrequencies(rfvec,rfunit);
834 Quantum<Vector<Double> > q(rfvec, rfunit);
835 rfvec.resize();
836 rfvec = q.getValue("Hz");
837 aTable.rwKeywordSet().define("RESTFREQS", rfvec);
838 table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
839 return True;
840}
841
842SDFrequencyTable SDMemTable::getSDFreqTable() const
843{
844 const Table& t = table_.keywordSet().asTable("FREQUENCIES");
845 SDFrequencyTable sdft;
846
847// Add refpix/refval/incr. What are the units ? Hz I suppose
848// but it's nowhere described...
849
850 Vector<Double> refPix, refVal, incr;
851 ScalarColumn<Double> refPixCol(t, "REFPIX");
852 ScalarColumn<Double> refValCol(t, "REFVAL");
853 ScalarColumn<Double> incrCol(t, "INCREMENT");
854 refPix = refPixCol.getColumn();
855 refVal = refValCol.getColumn();
856 incr = incrCol.getColumn();
857//
858 uInt n = refPix.nelements();
859 for (uInt i=0; i<n; i++) {
860 sdft.addFrequency(refPix[i], refVal[i], incr[i]);
861 }
862
863// Frequency reference frame. I don't know if this
864// is the correct frame. It might be 'REFFRAME'
865// rather than 'BASEREFFRAME' ?
866
867 String baseFrame;
868 t.keywordSet().get("BASEREFFRAME",baseFrame);
869 sdft.setRefFrame(baseFrame);
870
871// Equinox
872
873 Float equinox;
874 t.keywordSet().get("EQUINOX", equinox);
875 sdft.setEquinox(equinox);
876
877// Rest Frequency
878
879 Vector<Double> restFreqs;
880 t.keywordSet().get("RESTFREQS", restFreqs);
881 for (uInt i=0; i<restFreqs.nelements(); i++) {
882 sdft.addRestFrequency(restFreqs[i]);
883 }
884 sdft.setRestFrequencyUnit(String("Hz"));
885//
886 return sdft;
887}
888
889bool SDMemTable::putSDContainer(const SDContainer& sdc)
890{
891 uInt rno = table_.nrow();
892 table_.addRow();
893
894// mjd.put(rno, sdc.timestamp);
895 timeCol_.put(rno, sdc.timestamp);
896 srcnCol_.put(rno, sdc.sourcename);
897 fldnCol_.put(rno, sdc.fieldname);
898 specCol_.put(rno, sdc.getSpectrum());
899 flagsCol_.put(rno, sdc.getFlags());
900 tsCol_.put(rno, sdc.getTsys());
901 scanCol_.put(rno, sdc.scanid);
902 integrCol_.put(rno, sdc.interval);
903 freqidCol_.put(rno, sdc.getFreqMap());
904 dirCol_.put(rno, sdc.getDirection());
905 rbeamCol_.put(rno, sdc.refbeam);
906 tcalCol_.put(rno, sdc.tcal);
907 tcaltCol_.put(rno, sdc.tcaltime);
908 azCol_.put(rno, sdc.azimuth);
909 elCol_.put(rno, sdc.elevation);
910 paraCol_.put(rno, sdc.parangle);
911 histCol_.put(rno, sdc.getHistory());
912
913 return true;
914}
915
916SDContainer SDMemTable::getSDContainer(uInt whichRow) const
917{
918 SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
919 timeCol_.get(whichRow, sdc.timestamp);
920 srcnCol_.get(whichRow, sdc.sourcename);
921 integrCol_.get(whichRow, sdc.interval);
922 scanCol_.get(whichRow, sdc.scanid);
923 fldnCol_.get(whichRow, sdc.fieldname);
924 rbeamCol_.get(whichRow, sdc.refbeam);
925 azCol_.get(whichRow, sdc.azimuth);
926 elCol_.get(whichRow, sdc.elevation);
927 paraCol_.get(whichRow, sdc.parangle);
928 Vector<Float> tc;
929 tcalCol_.get(whichRow, tc);
930 sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
931 tcaltCol_.get(whichRow, sdc.tcaltime);
932 Array<Float> spectrum;
933 Array<Float> tsys;
934 Array<uChar> flagtrum;
935 Vector<uInt> fmap;
936 Array<Double> direction;
937 Vector<String> histo;
938 specCol_.get(whichRow, spectrum);
939 sdc.putSpectrum(spectrum);
940 flagsCol_.get(whichRow, flagtrum);
941 sdc.putFlags(flagtrum);
942 tsCol_.get(whichRow, tsys);
943 sdc.putTsys(tsys);
944 freqidCol_.get(whichRow, fmap);
945 sdc.putFreqMap(fmap);
946 dirCol_.get(whichRow, direction);
947 sdc.putDirection(direction);
948 histCol_.get(whichRow, histo);
949 sdc.putHistory(histo);
950 return sdc;
951}
952
953bool SDMemTable::putSDHeader(const SDHeader& sdh)
954{
955 table_.rwKeywordSet().define("nIF", sdh.nif);
956 table_.rwKeywordSet().define("nBeam", sdh.nbeam);
957 table_.rwKeywordSet().define("nPol", sdh.npol);
958 table_.rwKeywordSet().define("nChan", sdh.nchan);
959 table_.rwKeywordSet().define("Observer", sdh.observer);
960 table_.rwKeywordSet().define("Project", sdh.project);
961 table_.rwKeywordSet().define("Obstype", sdh.obstype);
962 table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
963 table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
964 table_.rwKeywordSet().define("Equinox", sdh.equinox);
965 table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
966 table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
967 table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
968 table_.rwKeywordSet().define("UTC", sdh.utc);
969 table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
970 table_.rwKeywordSet().define("Epoch", sdh.epoch);
971 return true;
972}
973
974SDHeader SDMemTable::getSDHeader() const
975{
976 SDHeader sdh;
977 table_.keywordSet().get("nBeam",sdh.nbeam);
978 table_.keywordSet().get("nIF",sdh.nif);
979 table_.keywordSet().get("nPol",sdh.npol);
980 table_.keywordSet().get("nChan",sdh.nchan);
981 table_.keywordSet().get("Observer", sdh.observer);
982 table_.keywordSet().get("Project", sdh.project);
983 table_.keywordSet().get("Obstype", sdh.obstype);
984 table_.keywordSet().get("AntennaName", sdh.antennaname);
985 table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
986 table_.keywordSet().get("Equinox", sdh.equinox);
987 table_.keywordSet().get("FreqRefFrame", sdh.freqref);
988 table_.keywordSet().get("FreqRefVal", sdh.reffreq);
989 table_.keywordSet().get("Bandwidth", sdh.bandwidth);
990 table_.keywordSet().get("UTC", sdh.utc);
991 table_.keywordSet().get("FluxUnit", sdh.fluxunit);
992 table_.keywordSet().get("Epoch", sdh.epoch);
993 return sdh;
994}
995void SDMemTable::makePersistent(const std::string& filename)
996{
997 table_.deepCopy(filename,Table::New);
998}
999
1000Int SDMemTable::nScan() const {
1001 Int n = 0;
1002 Int previous = -1;Int current=0;
1003 for (uInt i=0; i< scanCol_.nrow();i++) {
1004 scanCol_.getScalar(i,current);
1005 if (previous != current) {
1006 previous = current;
1007 n++;
1008 }
1009 }
1010 return n;
1011}
1012
1013String SDMemTable::formatSec(Double x) const
1014{
1015 Double xcop = x;
1016 MVTime mvt(xcop/24./3600.); // make days
1017
1018 if (x < 59.95)
1019 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
1020 else if (x < 3599.95)
1021 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
1022 else {
1023 ostringstream oss;
1024 oss << setw(2) << std::right << setprecision(1) << mvt.hour();
1025 oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
1026 return String(oss);
1027 }
1028};
1029
1030String SDMemTable::formatDirection(const MDirection& md) const
1031{
1032 Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
1033 Int prec = 7;
1034
1035 MVAngle mvLon(t[0]);
1036 String sLon = mvLon.string(MVAngle::TIME,prec);
1037 MVAngle mvLat(t[1]);
1038 String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
1039
1040 return sLon + String(" ") + sLat;
1041}
1042
1043
1044std::string SDMemTable::getFluxUnit() const
1045{
1046 String tmp;
1047 table_.keywordSet().get("FluxUnit", tmp);
1048 return tmp;
1049}
1050
1051void SDMemTable::setFluxUnit(const std::string& unit)
1052{
1053 String tmp(unit);
1054 Unit tU(tmp);
1055 if (tU==Unit("K") || tU==Unit("Jy")) {
1056 table_.rwKeywordSet().define(String("FluxUnit"), tmp);
1057 } else {
1058 throw AipsError("Illegal unit - must be compatible with Jy or K");
1059 }
1060}
1061
1062
1063void SDMemTable::setInstrument(const std::string& name)
1064{
1065 Bool throwIt = True;
1066 Instrument ins = convertInstrument (name, throwIt);
1067 String nameU(name);
1068 nameU.upcase();
1069 table_.rwKeywordSet().define(String("AntennaName"), nameU);
1070}
1071
1072std::string SDMemTable::summary() const {
1073
1074 // get number of integrations per scan
1075 int cIdx = 0;
1076 int idx = 0;
1077 int scount = 0;
1078 std::vector<int> cycles;
1079 for (uInt i=0; i<scanCol_.nrow();++i) {
1080 while (idx == cIdx && i<scanCol_.nrow()) {
1081 scanCol_.getScalar(++i,cIdx);
1082 ++scount;
1083 }
1084 idx = cIdx;
1085 cycles.push_back(scount);
1086 scount=0;
1087 --i;
1088 }
1089
1090
1091 ostringstream oss;
1092 oss << endl;
1093 oss << "--------------------------------------------------" << endl;
1094 oss << " Scan Table Summary" << endl;
1095 oss << "--------------------------------------------------" << endl;
1096 oss.flags(std::ios_base::left);
1097 oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
1098 << setw(15) << "IFs:" << setw(4) << nIF() << endl
1099 << setw(15) << "Polarisations:" << setw(4) << nPol() << endl
1100 << setw(15) << "Channels:" << setw(4) << nChan() << endl;
1101 oss << endl;
1102 String tmp;
1103 table_.keywordSet().get("Observer", tmp);
1104 oss << setw(15) << "Observer:" << tmp << endl;
1105 oss << setw(15) << "Obs Date:" << getTime(-1,True) << endl;
1106 table_.keywordSet().get("Project", tmp);
1107 oss << setw(15) << "Project:" << tmp << endl;
1108 table_.keywordSet().get("Obstype", tmp);
1109 oss << setw(15) << "Obs. Type:" << tmp << endl;
1110 table_.keywordSet().get("AntennaName", tmp);
1111 oss << setw(15) << "Antenna Name:" << tmp << endl;
1112 table_.keywordSet().get("FluxUnit", tmp);
1113 oss << setw(15) << "Flux Unit:" << tmp << endl;
1114 Table t = table_.keywordSet().asTable("FREQUENCIES");
1115 Vector<Double> vec;
1116 t.keywordSet().get("RESTFREQS",vec);
1117 oss << setw(15) << "Rest Freqs:";
1118 if (vec.nelements() > 0) {
1119 oss << setprecision(0) << vec << " [Hz]" << endl;
1120 } else {
1121 oss << "None set" << endl;
1122 }
1123 oss << setw(15) << "Abcissa:" << getAbcissaString() << endl;
1124 oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
1125 << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
1126 oss << endl;
1127 uInt count = 0;
1128 String name;
1129 Int previous = -1;Int current=0;
1130 Int integ = 0;
1131 String dirtype ="Position ("+
1132 MDirection::showType(getDirectionReference())+
1133 ")";
1134 oss << setw(6) << "Scan"
1135 << setw(15) << "Source"
1136 << setw(26) << dirtype
1137 << setw(10) << "Time"
1138 << setw(13) << "Integration" << endl;
1139 oss << "-------------------------------------------------------------------------------" << endl;
1140
1141 std::vector<int>::iterator it = cycles.begin();
1142 for (uInt i=0; i< scanCol_.nrow();i++) {
1143 scanCol_.getScalar(i,current);
1144 if (previous != current) {
1145 srcnCol_.getScalar(i,name);
1146 previous = current;
1147 String t = formatSec(Double(getInterval(i)));
1148 String posit = formatDirection(getDirection(i,True));
1149 oss << setw(6) << count
1150 << setw(15) << name
1151 << setw(26) << posit
1152 << setw(10) << getTime(i,False)
1153 << setw(3) << std::right << *it << " x "
1154 << setw(10)
1155 << t << std::left << endl;
1156 count++;
1157 it++;
1158 } else {
1159 integ++;
1160 }
1161 }
1162 oss << endl;
1163 oss << "Table contains " << table_.nrow() << " integration(s) in " << count << " scan(s)." << endl;
1164
1165// Frequency Table
1166
1167 std::vector<string> info = getCoordInfo();
1168 SDFrequencyTable sdft = getSDFreqTable();
1169 oss << endl << endl;
1170 oss << "FreqID Frame RefFreq(Hz) RefPix Increment(Hz)" << endl;
1171 oss << "-------------------------------------------------------------------------------" << endl;
1172 for (uInt i=0; i<sdft.length(); i++) {
1173 oss << setw(8) << i << setw(8)
1174 << info[3] << setw(16) << setprecision (8)
1175 << sdft.referenceValue(i) << setw(10)
1176 << sdft.referencePixel(i) << setw(12)
1177 << sdft.increment(i) << endl;
1178 }
1179 oss << "-------------------------------------------------------------------------------" << endl;
1180 return String(oss);
1181}
1182
1183Int SDMemTable::nBeam() const
1184{
1185 Int n;
1186 table_.keywordSet().get("nBeam",n);
1187 return n;
1188}
1189Int SDMemTable::nIF() const {
1190 Int n;
1191 table_.keywordSet().get("nIF",n);
1192 return n;
1193}
1194Int SDMemTable::nPol() const {
1195 Int n;
1196 table_.keywordSet().get("nPol",n);
1197 return n;
1198}
1199Int SDMemTable::nChan() const {
1200 Int n;
1201 table_.keywordSet().get("nChan",n);
1202 return n;
1203}
1204bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
1205{
1206 Vector<String> history;
1207 histCol_.get(whichRow, history);
1208 history.resize(history.nelements()+1,True);
1209 history[history.nelements()-1] = hist;
1210 histCol_.put(whichRow, history);
1211}
1212
1213std::vector<std::string> SDMemTable::history(int whichRow) const
1214{
1215 Vector<String> history;
1216 histCol_.get(whichRow, history);
1217 std::vector<std::string> stlout;
1218 // there is no Array<String>.tovector(std::vector<std::string>), so
1219 // do it by hand
1220 for (uInt i=0; i<history.nelements(); ++i) {
1221 stlout.push_back(history[i]);
1222 }
1223 return stlout;
1224}
1225/*
1226void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
1227
1228 std::vector<int>::iterator it;
1229 ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_);
1230 for (it = whichChans.begin(); it != whichChans.end(); it++) {
1231 j.reset(j.begin(uInt(*it)));
1232 for (ArrayAccessor<uChar, Axis<asap::BeamAxis> > i(j); i != i.end(); ++i) {
1233 for (ArrayAccessor<uChar, Axis<asap::IFAxis> > ii(i); ii != ii.end(); ++ii) {
1234 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > iii(ii);
1235 iii != iii.end(); ++iii) {
1236 (*iii) =
1237 }
1238 }
1239 }
1240 }
1241
1242}
1243*/
1244void SDMemTable::flag(int whichRow)
1245{
1246 Array<uChar> arr;
1247 flagsCol_.get(whichRow, arr);
1248
1249 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
1250 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
1251 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
1252 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
1253 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
1254 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
1255
1256 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
1257 (*i) = uChar(True);
1258 }
1259
1260 flagsCol_.put(whichRow, arr);
1261}
1262
1263MDirection::Types SDMemTable::getDirectionReference() const
1264{
1265 Float eq;
1266 table_.keywordSet().get("Equinox",eq);
1267 std::map<float,string> mp;
1268 mp[2000.0] = "J2000";
1269 mp[1950.0] = "B1950";
1270 MDirection::Types mdr;
1271 if (!MDirection::getType(mdr, mp[eq])) {
1272 mdr = MDirection::J2000;
1273 cerr << "Unknown equinox using J2000" << endl;
1274 }
1275//
1276 return mdr;
1277}
1278
1279MEpoch::Types SDMemTable::getTimeReference () const
1280{
1281 MEpoch::Types met;
1282 String ep;
1283 table_.keywordSet().get("Epoch",ep);
1284 if (!MEpoch::getType(met, ep)) {
1285 cerr << "Epoch type uknown - using UTC" << endl;
1286 met = MEpoch::UTC;
1287 }
1288//
1289 return met;
1290}
1291
1292
1293Instrument SDMemTable::convertInstrument (const String& instrument,
1294 Bool throwIt)
1295{
1296 String t(instrument);
1297 t.upcase();
1298
1299// The strings are what SDReader returns, after cunning interrogation
1300// of station names... :-(
1301
1302 Instrument inst = asap::UNKNOWN;
1303 if (t==String("DSS-43")) {
1304 inst = TIDBINBILLA;
1305 } else if (t==String("ATPKSMB")) {
1306 inst = ATPKSMB;
1307 } else if (t==String("ATPKSHOH")) {
1308 inst = ATPKSHOH;
1309 } else if (t==String("ATMOPRA")) {
1310 inst = ATMOPRA;
1311 } else if (t==String("CEDUNA")) {
1312 inst = CEDUNA;
1313 } else if (t==String("HOBART")) {
1314 inst = HOBART;
1315 } else {
1316 if (throwIt) {
1317 throw AipsError("Unrecognized instrument - use function scan.set_instrument to set");
1318 }
1319 }
1320 return inst;
1321}
1322
Note: See TracBrowser for help on using the repository browser.