source: trunk/src/SDMemTable.cc@ 366

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

rework summary function to handle scan boundary
more straightforardly and to add freqID listing
to each scan

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