source: trunk/src/SDMemTable.cc@ 344

Last change on this file since 344 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
RevLine 
[2]1//#---------------------------------------------------------------------------
2//# SDMemTable.cc: A MemoryTable container for single dish integrations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
[125]5//# ATNF
[2]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
[206]32#include <map>
33
[125]34#include <casa/aips.h>
[80]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>
[206]42#include <casa/Arrays/Vector.h>
[286]43#include <casa/Quanta/MVAngle.h>
[2]44
[80]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>
[2]50
[80]51#include <tables/Tables/ExprNode.h>
52#include <tables/Tables/TableRecord.h>
53#include <measures/Measures/MFrequency.h>
54#include <measures/Measures/MeasTable.h>
[105]55#include <coordinates/Coordinates/CoordinateUtil.h>
[80]56#include <casa/Quanta/MVTime.h>
[281]57#include <casa/Quanta/MVAngle.h>
[2]58
[215]59#include "SDDefs.h"
[2]60#include "SDMemTable.h"
61#include "SDContainer.h"
62
[206]63
[125]64using namespace casa;
[83]65using namespace asap;
[2]66
[18]67SDMemTable::SDMemTable() :
68 IFSel_(0),
69 beamSel_(0),
[206]70 polSel_(0)
71{
[18]72 setup();
[322]73 attach();
[18]74}
[206]75
[2]76SDMemTable::SDMemTable(const std::string& name) :
77 IFSel_(0),
78 beamSel_(0),
[206]79 polSel_(0)
80{
[50]81 Table tab(name);
[22]82 table_ = tab.copyToMemoryTable("dummy");
[206]83 //cerr << "hello from C SDMemTable @ " << this << endl;
[329]84 attach();
[2]85}
86
[206]87SDMemTable::SDMemTable(const SDMemTable& other, Bool clear)
88{
[148]89 IFSel_= other.IFSel_;
90 beamSel_= other.beamSel_;
91 polSel_= other.polSel_;
92 chanMask_ = other.chanMask_;
93 table_ = other.table_.copyToMemoryTable(String("dummy"));
[2]94 // clear all rows()
[16]95 if (clear) {
[148]96 table_.removeRow(this->table_.rowNumbers());
[16]97 } else {
[148]98 IFSel_ = other.IFSel_;
99 beamSel_ = other.beamSel_;
100 polSel_ = other.polSel_;
[16]101 }
[322]102//
103 attach();
[206]104 //cerr << "hello from CC SDMemTable @ " << this << endl;
[2]105}
106
[80]107SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) :
[2]108 IFSel_(0),
109 beamSel_(0),
[206]110 polSel_(0)
111{
[2]112 Table t = tableCommand(exprs,tab);
[89]113 if (t.nrow() == 0)
114 throw(AipsError("Query unsuccessful."));
[22]115 table_ = t.copyToMemoryTable("dummy");
[329]116 attach();
[2]117}
118
[206]119SDMemTable::~SDMemTable()
120{
[105]121 //cerr << "goodbye from SDMemTable @ " << this << endl;
[2]122}
123
[206]124SDMemTable SDMemTable::getScan(Int scanID) const
125{
[80]126 String cond("SELECT * from $1 WHERE SCANID == ");
127 cond += String::toString(scanID);
128 return SDMemTable(table_, cond);
[2]129}
130
[206]131SDMemTable &SDMemTable::operator=(const SDMemTable& other)
132{
[148]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"));
[322]140 attach();
[206]141 }
142 //cerr << "hello from ASS SDMemTable @ " << this << endl;
[138]143 return *this;
144}
145
[206]146SDMemTable SDMemTable::getSource(const std::string& source) const
147{
[80]148 String cond("SELECT * from $1 WHERE SRCNAME == ");
149 cond += source;
150 return SDMemTable(table_, cond);
151}
152
[206]153void SDMemTable::setup()
154{
[2]155 TableDesc td("", "1", TableDesc::Scratch);
156 td.comment() = "A SDMemTable";
[322]157//
[2]158 td.addColumn(ScalarColumnDesc<Double>("TIME"));
159 td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
160 td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
161 td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
[89]162 td.addColumn(ArrayColumnDesc<Float>("TSYS"));
163 td.addColumn(ScalarColumnDesc<Int>("SCANID"));
164 td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
[39]165 td.addColumn(ArrayColumnDesc<uInt>("FREQID"));
[78]166 td.addColumn(ArrayColumnDesc<Double>("DIRECTION"));
[105]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"));
[206]174 td.addColumn(ArrayColumnDesc<String>("HISTORY"));
[105]175
[2]176 // Now create a new table from the description.
[18]177
[22]178 SetupNewTable aNewTab("dummy", td, Table::New);
[89]179 table_ = Table(aNewTab, Table::Memory, 0);
[2]180}
181
[322]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
[206]204std::string SDMemTable::getSourceName(Int whichRow) const
205{
[2]206 String name;
[322]207 srcnCol_.get(whichRow, name);
[2]208 return name;
209}
210
[281]211std::string SDMemTable::getTime(Int whichRow, Bool showDate) const
[206]212{
[2]213 Double tm;
[281]214 if (whichRow > -1) {
[322]215 timeCol_.get(whichRow, tm);
[281]216 } else {
217 table_.keywordSet().get("UTC",tm);
218 }
[50]219 MVTime mvt(tm);
[281]220 if (showDate)
221 mvt.setFormat(MVTime::YMD);
222 else
223 mvt.setFormat(MVTime::TIME);
[50]224 ostringstream oss;
225 oss << mvt;
[281]226 return String(oss);
[2]227}
[281]228
[206]229double SDMemTable::getInterval(Int whichRow) const
230{
[50]231 Double intval;
[322]232 integrCol_.get(whichRow, intval);
[50]233 return intval;
234}
[2]235
[206]236bool SDMemTable::setIF(Int whichIF)
237{
[50]238 if ( whichIF >= 0 && whichIF < nIF()) {
[2]239 IFSel_ = whichIF;
240 return true;
[50]241 }
242 return false;
[2]243}
[50]244
[206]245bool SDMemTable::setBeam(Int whichBeam)
246{
[50]247 if ( whichBeam >= 0 && whichBeam < nBeam()) {
[2]248 beamSel_ = whichBeam;
249 return true;
[50]250 }
251 return false;
252}
[2]253
[206]254bool SDMemTable::setPol(Int whichPol)
255{
[50]256 if ( whichPol >= 0 && whichPol < nPol()) {
[2]257 polSel_ = whichPol;
258 return true;
[50]259 }
260 return false;
[2]261}
262
[303]263void SDMemTable::resetCursor ()
264{
265 polSel_ = 0;
266 IFSel_ = 0;
267 beamSel_ = 0;
268}
269
[206]270bool SDMemTable::setMask(std::vector<int> whichChans)
271{
[16]272 std::vector<int>::iterator it;
[322]273 uInt n = flagsCol_.shape(0)(3);
[105]274 if (whichChans.empty()) {
275 chanMask_ = std::vector<bool>(n,true);
276 return true;
277 }
[16]278 chanMask_.resize(n,true);
[39]279 for (it = whichChans.begin(); it != whichChans.end(); ++it) {
[105]280 if (*it < n) {
[16]281 chanMask_[*it] = false;
[105]282 }
[16]283 }
[2]284 return true;
285}
286
[16]287std::vector<bool> SDMemTable::getMask(Int whichRow) const {
288 std::vector<bool> mask;
289 Array<uChar> arr;
[322]290 flagsCol_.get(whichRow, arr);
[206]291 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[16]292 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]293 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[16]294 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]295 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[16]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
[206]305 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[16]306 bool out =!static_cast<bool>(*i);
307 if (useUserMask) {
308 out = out && (*miter);
309 miter++;
310 }
311 mask.push_back(out);
[89]312 }
[16]313 return mask;
[2]314}
[206]315std::vector<float> SDMemTable::getSpectrum(Int whichRow) const
316{
[2]317 std::vector<float> spectrum;
318 Array<Float> arr;
[322]319 specCol_.get(whichRow, arr);
[206]320 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[2]321 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]322 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[2]323 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]324 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[16]325 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
[206]326 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[16]327 spectrum.push_back(*i);
[2]328 }
329 return spectrum;
330}
[206]331std::vector<string> SDMemTable::getCoordInfo() const
332{
[105]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);
[263]346 t.keywordSet().get("BASEREFFRAME",rfrm);
347 inf.push_back(rfrm);
[105]348 return inf;
349}
[39]350
[206]351void SDMemTable::setCoordInfo(std::vector<string> theinfo)
352{
[105]353 std::vector<string>::iterator it;
[306]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//
[105]360 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
[306]361//
[105]362 Vector<Double> rstf;
363 t.keywordSet().get("RESTFREQS",rstf);
[306]364//
[105]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);
[275]377//
[105]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 }
[275]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 }
[306]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 }
[105]405}
406
[286]407
[206]408std::vector<double> SDMemTable::getAbcissa(Int whichRow) const
409{
[286]410 std::vector<double> abc(nChan());
[206]411
[286]412// Get header units keyword
[206]413
[286]414 Table t = table_.keywordSet().asTable("FREQUENCIES");
[105]415 String sunit;
416 t.keywordSet().get("UNIT",sunit);
417 if (sunit == "") sunit = "pixel";
418 Unit u(sunit);
[286]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;
[78]431 }
432
[286]433// Continue with km/s or Hz. Get FreqID
434
435 Vector<uInt> v;
[322]436 freqidCol_.get(whichRow, v);
[286]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 }
[39]456 } else if (u == Unit("Hz")) {
[286]457
458// Set world axis units
459
[39]460 Vector<String> wau(1); wau = u.getName();
461 spc.setWorldAxisUnits(wau);
[286]462//
[39]463 std::vector<double>::iterator it;
464 Double tmp;
465 uInt i = 0;
[286]466 for (it = abc.begin(); it != abc.end(); ++it) {
467 spc.toWorld(tmp,pixel[i]);
[39]468 (*it) = tmp;
469 i++;
470 }
471 }
[286]472 return abc;
[39]473}
474
[164]475std::string SDMemTable::getAbcissaString(Int whichRow) const
[105]476{
477 Table t = table_.keywordSet().asTable("FREQUENCIES");
[286]478//
[105]479 String sunit;
480 t.keywordSet().get("UNIT",sunit);
481 if (sunit == "") sunit = "pixel";
482 Unit u(sunit);
[286]483//
[105]484 Vector<uInt> v;
[322]485 freqidCol_.get(whichRow, v);
[105]486 uInt specidx = v(IFSel_);
[286]487
488// Get SpectralCoordinate, with frame, velocity, rest freq state set
489
490 SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow);
[275]491//
[105]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);
[286]498//
499 s = CoordinateUtil::axisLabel(spc,0,True,True,False);
[105]500 }
501 return s;
502}
503
[206]504void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow)
505{
[89]506 Array<Float> arr;
[322]507 specCol_.get(whichRow, arr);
[89]508 if (spectrum.size() != arr.shape()(3)) {
509 throw(AipsError("Attempting to set spectrum with incorrect length."));
510 }
511
[206]512 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[89]513 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]514 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[89]515 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]516 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[89]517 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
518
519 std::vector<float>::iterator it = spectrum.begin();
[206]520 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[89]521 (*i) = Float(*it);
522 it++;
523 }
[322]524 specCol_.put(whichRow, arr);
[89]525}
526
[206]527void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const
528{
[21]529 Array<Float> arr;
[322]530 specCol_.get(whichRow, arr);
[21]531 spectrum.resize(arr.shape()(3));
[206]532 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[21]533 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]534 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[21]535 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]536 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[21]537 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
[2]538
[206]539 ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
540 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[21]541 (*va) = (*i);
542 va++;
543 }
544}
[89]545/*
[68]546void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
[21]547 Array<uChar> arr;
[322]548 flagsCol_.get(whichRow, arr);
[21]549 mask.resize(arr.shape()(3));
550
[206]551 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[21]552 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]553 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[21]554 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]555 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[21]556 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
557
558 Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
[89]559
[206]560 ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask);
[21]561 std::vector<bool> tmp;
562 tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
[89]563 // iterator should work on chanMask_??
[21]564 std::vector<bool>::iterator miter;
565 miter = tmp.begin();
566
[206]567 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[21]568 bool out =!static_cast<bool>(*i);
569 if (useUserMask) {
570 out = out && (*miter);
571 miter++;
572 }
573 (*va) = out;
574 va++;
[89]575 }
[21]576}
[89]577*/
[16]578MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
[164]579 Bool useSelection) const
580{
[2]581 Array<Float> arr;
582 Array<uChar> farr;
[322]583 specCol_.get(whichRow, arr);
584 flagsCol_.get(whichRow, farr);
[2]585 Array<Bool> barr(farr.shape());convertArray(barr, farr);
586 MaskedArray<Float> marr;
[16]587 if (useSelection) {
[206]588 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[16]589 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]590 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[16]591 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]592 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[16]593 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
[89]594
[206]595 ArrayAccessor<Bool, Axis<asap::BeamAxis> > baa0(barr);
[16]596 baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam
[206]597 ArrayAccessor<Bool, Axis<asap::IFAxis> > baa1(baa0);
[16]598 baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF
[206]599 ArrayAccessor<Bool, Axis<asap::PolAxis> > baa2(baa1);
[16]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));
[206]604 ArrayAccessor<Float, Axis<asap::BeamAxis> > a0(a);
605 ArrayAccessor<Bool, Axis<asap::BeamAxis> > b0(b);
[16]606
[206]607 ArrayAccessor<Bool, Axis<asap::ChanAxis> > j(baa2);
608 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2);
609 i != i.end(); ++i) {
[16]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 }
[2]620 return marr;
621}
622
[206]623Float SDMemTable::getTsys(Int whichRow) const
624{
[2]625 Array<Float> arr;
[322]626 tsCol_.get(whichRow, arr);
[2]627 Float out;
628 IPosition ip(arr.shape());
[16]629 ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0;
[2]630 out = arr(ip);
631 return out;
632}
633
[281]634MDirection SDMemTable::getDirection(Int whichRow, Bool refBeam) const
[206]635{
[212]636 MDirection::Types mdr = getDirectionReference();
[206]637 Array<Double> posit;
[322]638 dirCol_.get(whichRow,posit);
[206]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")));
[286]644 return MDirection(lon, lat, mdr);
[206]645}
[39]646
[286]647MEpoch SDMemTable::getEpoch (Int whichRow) const
[206]648{
[286]649 MEpoch::Types met = getTimeReference();
650//
651 Double obstime;
[322]652 timeCol_.get(whichRow,obstime);
[286]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{
[206]668
[39]669 Table t = table_.keywordSet().asTable("FREQUENCIES");
670 if (whichIdx > t.nrow() ) {
[286]671 throw(AipsError("SDMemTable::getSpectralCoordinate - whichIdx out of range"));
[39]672 }
[89]673
[39]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");
[105]679 t.keywordSet().get("BASEREFFRAME",rf);
[89]680
[286]681// Create SpectralCoordinate (units Hz)
682
[39]683 MFrequency::Types mft;
684 if (!MFrequency::getType(mft, rf)) {
685 cerr << "Frequency type unknown assuming TOPO" << endl;
[89]686 mft = MFrequency::TOPO;
687 }
[39]688 rpc.get(whichIdx, rp);
689 rvc.get(whichIdx, rv);
690 incc.get(whichIdx, inc);
[286]691//
[39]692 SpectralCoordinate spec(mft,rv,inc,rp);
[286]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) {
[89]711 spec.setRestFrequencies(vec);
[286]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//
[39]760 return spec;
761}
762
[286]763
[89]764Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
765 uInt whichIdx) {
[50]766 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
767 if (whichIdx > t.nrow() ) {
[89]768 throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
[50]769 }
770 ScalarColumn<Double> rpc(t, "REFPIX");
771 ScalarColumn<Double> rvc(t, "REFVAL");
772 ScalarColumn<Double> incc(t, "INCREMENT");
[89]773
[50]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
[89]781Int SDMemTable::nCoordinates() const
782{
783 return table_.keywordSet().asTable("FREQUENCIES").nrow();
784}
[50]785
[206]786void SDMemTable::setRestFreqs(std::vector<double> freqs,
787 const std::string& theunit)
[89]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
[251]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
[206]807bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft)
808{
[39]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 }
[105]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);
[39]828 aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
[105]829 aTable.rwKeywordSet().define("UNIT", String(""));
830 aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
[89]831 Vector<Double> rfvec;
[206]832 String rfunit;
833 sdft.restFrequencies(rfvec,rfunit);
834 Quantum<Vector<Double> > q(rfvec, rfunit);
835 rfvec.resize();
836 rfvec = q.getValue("Hz");
[89]837 aTable.rwKeywordSet().define("RESTFREQS", rfvec);
[39]838 table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
839 return True;
840}
841
[206]842SDFrequencyTable SDMemTable::getSDFreqTable() const
843{
[251]844 const Table& t = table_.keywordSet().asTable("FREQUENCIES");
[39]845 SDFrequencyTable sdft;
[306]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//
[39]886 return sdft;
887}
888
[206]889bool SDMemTable::putSDContainer(const SDContainer& sdc)
890{
[2]891 uInt rno = table_.nrow();
892 table_.addRow();
[89]893
[322]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());
[89]912
[2]913 return true;
914}
[18]915
[206]916SDContainer SDMemTable::getSDContainer(uInt whichRow) const
917{
[21]918 SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
[322]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);
[105]928 Vector<Float> tc;
[322]929 tcalCol_.get(whichRow, tc);
[105]930 sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
[322]931 tcaltCol_.get(whichRow, sdc.tcaltime);
[21]932 Array<Float> spectrum;
933 Array<Float> tsys;
934 Array<uChar> flagtrum;
[39]935 Vector<uInt> fmap;
[78]936 Array<Double> direction;
[206]937 Vector<String> histo;
[322]938 specCol_.get(whichRow, spectrum);
[21]939 sdc.putSpectrum(spectrum);
[322]940 flagsCol_.get(whichRow, flagtrum);
[21]941 sdc.putFlags(flagtrum);
[322]942 tsCol_.get(whichRow, tsys);
[21]943 sdc.putTsys(tsys);
[322]944 freqidCol_.get(whichRow, fmap);
[39]945 sdc.putFreqMap(fmap);
[322]946 dirCol_.get(whichRow, direction);
[78]947 sdc.putDirection(direction);
[322]948 histCol_.get(whichRow, histo);
[206]949 sdc.putHistory(histo);
[21]950 return sdc;
951}
[78]952
[206]953bool SDMemTable::putSDHeader(const SDHeader& sdh)
954{
[18]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);
[206]969 table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
970 table_.rwKeywordSet().define("Epoch", sdh.epoch);
[18]971 return true;
[50]972}
[21]973
[206]974SDHeader SDMemTable::getSDHeader() const
975{
[21]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);
[206]991 table_.keywordSet().get("FluxUnit", sdh.fluxunit);
992 table_.keywordSet().get("Epoch", sdh.epoch);
[21]993 return sdh;
[18]994}
[206]995void SDMemTable::makePersistent(const std::string& filename)
996{
[2]997 table_.deepCopy(filename,Table::New);
998}
999
[89]1000Int SDMemTable::nScan() const {
[50]1001 Int n = 0;
1002 Int previous = -1;Int current=0;
[322]1003 for (uInt i=0; i< scanCol_.nrow();i++) {
1004 scanCol_.getScalar(i,current);
[50]1005 if (previous != current) {
[89]1006 previous = current;
[50]1007 n++;
1008 }
1009 }
1010 return n;
1011}
1012
[260]1013String SDMemTable::formatSec(Double x) const
[206]1014{
[105]1015 Double xcop = x;
1016 MVTime mvt(xcop/24./3600.); // make days
[281]1017
[105]1018 if (x < 59.95)
[281]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 }
[105]1028};
1029
[281]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
[206]1044std::string SDMemTable::getFluxUnit() const
1045{
1046 String tmp;
1047 table_.keywordSet().get("FluxUnit", tmp);
1048 return tmp;
1049}
1050
[218]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
[275]1062
[236]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
[260]1072std::string SDMemTable::summary() const {
[281]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;
[322]1079 for (uInt i=0; i<scanCol_.nrow();++i) {
1080 while (idx == cIdx && i<scanCol_.nrow()) {
1081 scanCol_.getScalar(++i,cIdx);
[281]1082 ++scount;
1083 }
1084 idx = cIdx;
1085 cycles.push_back(scount);
1086 scount=0;
1087 --i;
1088 }
1089
1090
[89]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;
[281]1105 oss << setw(15) << "Obs Date:" << getTime(-1,True) << endl;
[89]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;
[206]1112 table_.keywordSet().get("FluxUnit", tmp);
1113 oss << setw(15) << "Flux Unit:" << tmp << endl;
[260]1114 Table t = table_.keywordSet().asTable("FREQUENCIES");
[105]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 }
[158]1123 oss << setw(15) << "Abcissa:" << getAbcissaString() << endl;
[105]1124 oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
1125 << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
[89]1126 oss << endl;
[2]1127 uInt count = 0;
1128 String name;
1129 Int previous = -1;Int current=0;
[89]1130 Int integ = 0;
[281]1131 String dirtype ="Position ("+
1132 MDirection::showType(getDirectionReference())+
1133 ")";
[89]1134 oss << setw(6) << "Scan"
[281]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();
[322]1142 for (uInt i=0; i< scanCol_.nrow();i++) {
1143 scanCol_.getScalar(i,current);
[2]1144 if (previous != current) {
[322]1145 srcnCol_.getScalar(i,name);
[50]1146 previous = current;
[105]1147 String t = formatSec(Double(getInterval(i)));
[281]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;
[50]1156 count++;
[281]1157 it++;
[89]1158 } else {
1159 integ++;
[2]1160 }
1161 }
[89]1162 oss << endl;
[321]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;
[325]1170 oss << "FreqID Frame RefFreq(Hz) RefPix Increment(Hz)" << endl;
[328]1171 oss << "-------------------------------------------------------------------------------" << endl;
[321]1172 for (uInt i=0; i<sdft.length(); i++) {
[325]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)
[321]1177 << sdft.increment(i) << endl;
1178 }
1179 oss << "-------------------------------------------------------------------------------" << endl;
[89]1180 return String(oss);
[2]1181}
[18]1182
[206]1183Int SDMemTable::nBeam() const
1184{
[18]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}
[206]1204bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
1205{
1206 Vector<String> history;
[322]1207 histCol_.get(whichRow, history);
[206]1208 history.resize(history.nelements()+1,True);
1209 history[history.nelements()-1] = hist;
[322]1210 histCol_.put(whichRow, history);
[206]1211}
1212
1213std::vector<std::string> SDMemTable::history(int whichRow) const
1214{
1215 Vector<String> history;
[322]1216 histCol_.get(whichRow, history);
[206]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}
[16]1225/*
[18]1226void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
[89]1227
[16]1228 std::vector<int>::iterator it;
[206]1229 ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_);
[16]1230 for (it = whichChans.begin(); it != whichChans.end(); it++) {
1231 j.reset(j.begin(uInt(*it)));
[206]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);
[89]1235 iii != iii.end(); ++iii) {
1236 (*iii) =
1237 }
[16]1238 }
1239 }
1240 }
[89]1241
[16]1242}
1243*/
[206]1244void SDMemTable::flag(int whichRow)
1245{
[89]1246 Array<uChar> arr;
[322]1247 flagsCol_.get(whichRow, arr);
[89]1248
[206]1249 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[89]1250 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]1251 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[89]1252 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]1253 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[89]1254 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
1255
[206]1256 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[89]1257 (*i) = uChar(True);
1258 }
1259
[322]1260 flagsCol_.put(whichRow, arr);
[89]1261}
[212]1262
[281]1263MDirection::Types SDMemTable::getDirectionReference() const
[212]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
[236]1292
1293Instrument SDMemTable::convertInstrument (const String& instrument,
1294 Bool throwIt)
1295{
1296 String t(instrument);
1297 t.upcase();
[293]1298
1299// The strings are what SDReader returns, after cunning interrogation
1300// of station names... :-(
1301
[236]1302 Instrument inst = asap::UNKNOWN;
[293]1303 if (t==String("DSS-43")) {
[236]1304 inst = TIDBINBILLA;
1305 } else if (t==String("ATPKSMB")) {
[292]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;
[236]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.