source: trunk/src/SDMemTable.cc@ 327

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

more preciion for ref val in freq table summary

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