source: trunk/src/SDMemTable.cc@ 383

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