source: trunk/src/SDMemTable.cc@ 304

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

add function resetCursor

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