source: trunk/src/SDMemTable.cc@ 293

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

better documentation for a couple of functions

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