source: trunk/src/SDMemTable.cc@ 313

Last change on this file since 313 was 306, checked in by kil064, 20 years ago

implement function getSDFreqTable which was empty before

  • 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/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;
[306]333 String un,rfrm, brfrm,dpl;
334 un = theinfo[0]; // Abcissa unit
335 rfrm = theinfo[1]; // Active (or conversion) frame
336 dpl = theinfo[2]; // Doppler
337 brfrm = theinfo[3]; // Base frame
338//
[105]339 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
[306]340//
[105]341 Vector<Double> rstf;
342 t.keywordSet().get("RESTFREQS",rstf);
[306]343//
[105]344 Bool canDo = True;
345 Unit u1("km/s");Unit u2("Hz");
346 if (Unit(un) == u1) {
347 Vector<Double> rstf;
348 t.keywordSet().get("RESTFREQS",rstf);
349 if (rstf.nelements() == 0) {
350 throw(AipsError("Can't set unit to km/s if no restfrequencies are specified"));
351 }
352 } else if (Unit(un) != u2 && un != "") {
353 throw(AipsError("Unit not conformant with Spectral Coordinates"));
354 }
355 t.rwKeywordSet().define("UNIT", un);
[275]356//
[105]357 MFrequency::Types mdr;
358 if (!MFrequency::getType(mdr, rfrm)) {
359
360 Int a,b;const uInt* c;
361 const String* valid = MFrequency::allMyTypes(a, b, c);
362 String pfix = "Please specify a legal frame type. Types are\n";
363 throw(AipsError(pfix+(*valid)));
364 } else {
365 t.rwKeywordSet().define("REFFRAME",rfrm);
366 }
[275]367//
368 MDoppler::Types dtype;
369 dpl.upcase();
370 if (!MDoppler::getType(dtype, dpl)) {
371 throw(AipsError("Doppler type unknown"));
372 } else {
373 t.rwKeywordSet().define("DOPPLER",dpl);
374 }
[306]375//
376 if (!MFrequency::getType(mdr, brfrm)) {
377 Int a,b;const uInt* c;
378 const String* valid = MFrequency::allMyTypes(a, b, c);
379 String pfix = "Please specify a legal frame type. Types are\n";
380 throw(AipsError(pfix+(*valid)));
381 } else {
382 t.rwKeywordSet().define("BASEREFFRAME",brfrm);
383 }
[105]384}
385
[286]386
[206]387std::vector<double> SDMemTable::getAbcissa(Int whichRow) const
388{
[286]389 std::vector<double> abc(nChan());
[206]390
[286]391// Get header units keyword
[206]392
[286]393 Table t = table_.keywordSet().asTable("FREQUENCIES");
[105]394 String sunit;
395 t.keywordSet().get("UNIT",sunit);
396 if (sunit == "") sunit = "pixel";
397 Unit u(sunit);
[286]398
399// Easy if just wanting pixels
400
401 if (sunit==String("pixel")) {
402 // assume channels/pixels
403 std::vector<double>::iterator it;
404 uInt i=0;
405 for (it = abc.begin(); it != abc.end(); ++it) {
406 (*it) = Double(i++);
407 }
408//
409 return abc;
[78]410 }
411
[286]412// Continue with km/s or Hz. Get FreqID
413
414 ROArrayColumn<uInt> fid(table_, "FREQID");
415 Vector<uInt> v;
416 fid.get(whichRow, v);
417 uInt specidx = v(IFSel_);
418
419// Get SpectralCoordinate, set reference frame conversion,
420// velocity conversion, and rest freq state
421
422 SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow);
423//
424 Vector<Double> pixel(nChan());
425 indgen(pixel);
426//
427 if (u == Unit("km/s")) {
428 Vector<Double> world;
429 spc.pixelToVelocity(world,pixel);
430 std::vector<double>::iterator it;
431 uInt i = 0;
432 for (it = abc.begin(); it != abc.end(); ++it) {
433 (*it) = world[i];
434 i++;
435 }
[39]436 } else if (u == Unit("Hz")) {
[286]437
438// Set world axis units
439
[39]440 Vector<String> wau(1); wau = u.getName();
441 spc.setWorldAxisUnits(wau);
[286]442//
[39]443 std::vector<double>::iterator it;
444 Double tmp;
445 uInt i = 0;
[286]446 for (it = abc.begin(); it != abc.end(); ++it) {
447 spc.toWorld(tmp,pixel[i]);
[39]448 (*it) = tmp;
449 i++;
450 }
451 }
[286]452 return abc;
[39]453}
454
[164]455std::string SDMemTable::getAbcissaString(Int whichRow) const
[105]456{
457 ROArrayColumn<uInt> fid(table_, "FREQID");
458 Table t = table_.keywordSet().asTable("FREQUENCIES");
[286]459//
[105]460 String sunit;
461 t.keywordSet().get("UNIT",sunit);
462 if (sunit == "") sunit = "pixel";
463 Unit u(sunit);
[286]464//
[105]465 Vector<uInt> v;
466 fid.get(whichRow, v);
467 uInt specidx = v(IFSel_);
[286]468
469// Get SpectralCoordinate, with frame, velocity, rest freq state set
470
471 SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow);
[275]472//
[105]473 String s = "Channel";
474 if (u == Unit("km/s")) {
475 s = CoordinateUtil::axisLabel(spc,0,True,True,True);
476 } else if (u == Unit("Hz")) {
477 Vector<String> wau(1);wau = u.getName();
478 spc.setWorldAxisUnits(wau);
[286]479//
480 s = CoordinateUtil::axisLabel(spc,0,True,True,False);
[105]481 }
482 return s;
483}
484
[206]485void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow)
486{
[89]487 ArrayColumn<Float> spec(table_, "SPECTRA");
488 Array<Float> arr;
489 spec.get(whichRow, arr);
490 if (spectrum.size() != arr.shape()(3)) {
491 throw(AipsError("Attempting to set spectrum with incorrect length."));
492 }
493
[206]494 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[89]495 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]496 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[89]497 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]498 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[89]499 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
500
501 std::vector<float>::iterator it = spectrum.begin();
[206]502 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[89]503 (*i) = Float(*it);
504 it++;
505 }
506 spec.put(whichRow, arr);
507}
508
[206]509void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const
510{
[21]511 ROArrayColumn<Float> spec(table_, "SPECTRA");
512 Array<Float> arr;
513 spec.get(whichRow, arr);
514 spectrum.resize(arr.shape()(3));
[206]515 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[21]516 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]517 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[21]518 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]519 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[21]520 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
[2]521
[206]522 ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
523 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[21]524 (*va) = (*i);
525 va++;
526 }
527}
[89]528/*
[68]529void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
[21]530 ROArrayColumn<uChar> spec(table_, "FLAGTRA");
531 Array<uChar> arr;
532 spec.get(whichRow, arr);
533 mask.resize(arr.shape()(3));
534
[206]535 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[21]536 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]537 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[21]538 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]539 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[21]540 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
541
542 Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
[89]543
[206]544 ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask);
[21]545 std::vector<bool> tmp;
546 tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
[89]547 // iterator should work on chanMask_??
[21]548 std::vector<bool>::iterator miter;
549 miter = tmp.begin();
550
[206]551 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[21]552 bool out =!static_cast<bool>(*i);
553 if (useUserMask) {
554 out = out && (*miter);
555 miter++;
556 }
557 (*va) = out;
558 va++;
[89]559 }
[21]560}
[89]561*/
[16]562MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
[164]563 Bool useSelection) const
564{
[2]565 ROArrayColumn<Float> spec(table_, "SPECTRA");
566 Array<Float> arr;
567 ROArrayColumn<uChar> flag(table_, "FLAGTRA");
568 Array<uChar> farr;
569 spec.get(whichRow, arr);
570 flag.get(whichRow, farr);
571 Array<Bool> barr(farr.shape());convertArray(barr, farr);
572 MaskedArray<Float> marr;
[16]573 if (useSelection) {
[206]574 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[16]575 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]576 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[16]577 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]578 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[16]579 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
[89]580
[206]581 ArrayAccessor<Bool, Axis<asap::BeamAxis> > baa0(barr);
[16]582 baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam
[206]583 ArrayAccessor<Bool, Axis<asap::IFAxis> > baa1(baa0);
[16]584 baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF
[206]585 ArrayAccessor<Bool, Axis<asap::PolAxis> > baa2(baa1);
[16]586 baa2.reset(baa2.begin(uInt(polSel_)));// go to pol
587
588 Vector<Float> a(arr.shape()(3));
589 Vector<Bool> b(barr.shape()(3));
[206]590 ArrayAccessor<Float, Axis<asap::BeamAxis> > a0(a);
591 ArrayAccessor<Bool, Axis<asap::BeamAxis> > b0(b);
[16]592
[206]593 ArrayAccessor<Bool, Axis<asap::ChanAxis> > j(baa2);
594 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2);
595 i != i.end(); ++i) {
[16]596 (*a0) = (*i);
597 (*b0) = !(*j);
598 j++;
599 a0++;
600 b0++;
601 }
602 marr.setData(a,b);
603 } else {
604 marr.setData(arr,!barr);
605 }
[2]606 return marr;
607}
608
[206]609Float SDMemTable::getTsys(Int whichRow) const
610{
[2]611 ROArrayColumn<Float> ts(table_, "TSYS");
612 Array<Float> arr;
613 ts.get(whichRow, arr);
614 Float out;
615 IPosition ip(arr.shape());
[16]616 ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0;
[2]617 out = arr(ip);
618 return out;
619}
620
[281]621MDirection SDMemTable::getDirection(Int whichRow, Bool refBeam) const
[206]622{
[212]623 MDirection::Types mdr = getDirectionReference();
[206]624 ROArrayColumn<Double> dir(table_, "DIRECTION");
625 Array<Double> posit;
626 dir.get(whichRow,posit);
627 Vector<Double> wpos(2);
628 wpos[0] = posit(IPosition(2,beamSel_,0));
629 wpos[1] = posit(IPosition(2,beamSel_,1));
630 Quantum<Double> lon(wpos[0],Unit(String("rad")));
631 Quantum<Double> lat(wpos[1],Unit(String("rad")));
[286]632 return MDirection(lon, lat, mdr);
[206]633}
[39]634
[286]635MEpoch SDMemTable::getEpoch (Int whichRow) const
[206]636{
[286]637 MEpoch::Types met = getTimeReference();
638//
639 ROScalarColumn<Double> tme(table_, "TIME");
640 Double obstime;
641 tme.get(whichRow,obstime);
642 MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
643 return MEpoch(tm2, met);
644}
645
646MPosition SDMemTable::getAntennaPosition () const
647{
648 Vector<Double> antpos;
649 table_.keywordSet().get("AntennaPosition", antpos);
650 MVPosition mvpos(antpos(0),antpos(1),antpos(2));
651 return MPosition(mvpos);
652}
653
654
655SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx) const
656{
[206]657
[39]658 Table t = table_.keywordSet().asTable("FREQUENCIES");
659 if (whichIdx > t.nrow() ) {
[286]660 throw(AipsError("SDMemTable::getSpectralCoordinate - whichIdx out of range"));
[39]661 }
[89]662
[39]663 Double rp,rv,inc;
664 String rf;
665 ROScalarColumn<Double> rpc(t, "REFPIX");
666 ROScalarColumn<Double> rvc(t, "REFVAL");
667 ROScalarColumn<Double> incc(t, "INCREMENT");
[105]668 t.keywordSet().get("BASEREFFRAME",rf);
[89]669
[286]670// Create SpectralCoordinate (units Hz)
671
[39]672 MFrequency::Types mft;
673 if (!MFrequency::getType(mft, rf)) {
674 cerr << "Frequency type unknown assuming TOPO" << endl;
[89]675 mft = MFrequency::TOPO;
676 }
[39]677 rpc.get(whichIdx, rp);
678 rvc.get(whichIdx, rv);
679 incc.get(whichIdx, inc);
[286]680//
[39]681 SpectralCoordinate spec(mft,rv,inc,rp);
[286]682//
683 return spec;
684}
685
686
687SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx, uInt whichRow) const
688{
689// Create basic SC
690
691 SpectralCoordinate spec = getSpectralCoordinate (whichIdx);
692//
693 Table t = table_.keywordSet().asTable("FREQUENCIES");
694
695// Set rest frequencies
696
697 Vector<Double> vec;
698 t.keywordSet().get("RESTFREQS",vec);
699 if (vec.nelements() > 0) {
[89]700 spec.setRestFrequencies(vec);
[286]701
702// Select rest freq
703
704 if (vec.nelements() >= nIF()) {
705 spec.selectRestFrequency(uInt(IFSel_));
706 }
707 }
708
709// Set up frame conversion layer
710
711 String frm;
712 t.keywordSet().get("REFFRAME",frm);
713 if (frm == "") frm = "TOPO";
714 MFrequency::Types mtype;
715 if (!MFrequency::getType(mtype, frm)) {
716 cout << "Frequency type unknown assuming TOPO" << endl; // SHould never happen
717 mtype = MFrequency::TOPO;
718 }
719
720// Set reference frame conversion (requires row)
721
722 MDirection direct = getDirection(whichRow);
723 MEpoch epoch = getEpoch(whichRow);
724 MPosition pos = getAntennaPosition();
725 if (!spec.setReferenceConversion(mtype,epoch,pos,direct)) {
726 throw(AipsError("Couldn't convert frequency frame."));
727 }
728
729// Now velocity conversion if appropriate
730
731 String unitStr;
732 t.keywordSet().get("UNIT",unitStr);
733//
734 String dpl;
735 t.keywordSet().get("DOPPLER",dpl);
736 MDoppler::Types dtype;
737 MDoppler::getType(dtype, dpl);
738
739// Only set velocity unit if non-blank and non-Hz
740
741 if (!unitStr.empty()) {
742 Unit unitU(unitStr);
743 if (unitU==Unit("Hz")) {
744 } else {
745 spec.setVelocity(unitStr, dtype);
746 }
747 }
748//
[39]749 return spec;
750}
751
[286]752
[89]753Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
754 uInt whichIdx) {
[50]755 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
756 if (whichIdx > t.nrow() ) {
[89]757 throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
[50]758 }
759 ScalarColumn<Double> rpc(t, "REFPIX");
760 ScalarColumn<Double> rvc(t, "REFVAL");
761 ScalarColumn<Double> incc(t, "INCREMENT");
[89]762
[50]763 rpc.put(whichIdx, speccord.referencePixel()[0]);
764 rvc.put(whichIdx, speccord.referenceValue()[0]);
765 incc.put(whichIdx, speccord.increment()[0]);
766
767 return True;
768}
769
[89]770Int SDMemTable::nCoordinates() const
771{
772 return table_.keywordSet().asTable("FREQUENCIES").nrow();
773}
[50]774
[206]775void SDMemTable::setRestFreqs(std::vector<double> freqs,
776 const std::string& theunit)
[89]777{
778 Vector<Double> tvec(freqs);
779 Quantum<Vector<Double> > q(tvec, String(theunit));
780 tvec.resize();
781 tvec = q.getValue("Hz");
782 Table t = table_.keywordSet().asTable("FREQUENCIES");
783 t.rwKeywordSet().define("RESTFREQS",tvec);
784}
785
[251]786std::vector<double> SDMemTable::getRestFreqs() const
787{
788 Table t = table_.keywordSet().asTable("FREQUENCIES");
789 Vector<Double> tvec;
790 t.keywordSet().get("RESTFREQS",tvec);
791 std::vector<double> stlout;
792 tvec.tovector(stlout);
793 return stlout;
794}
795
[206]796bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft)
797{
[39]798 TableDesc td("", "1", TableDesc::Scratch);
799 td.addColumn(ScalarColumnDesc<Double>("REFPIX"));
800 td.addColumn(ScalarColumnDesc<Double>("REFVAL"));
801 td.addColumn(ScalarColumnDesc<Double>("INCREMENT"));
802 SetupNewTable aNewTab("freqs", td, Table::New);
803 Table aTable (aNewTab, Table::Memory, sdft.length());
804 ScalarColumn<Double> sc0(aTable, "REFPIX");
805 ScalarColumn<Double> sc1(aTable, "REFVAL");
806 ScalarColumn<Double> sc2(aTable, "INCREMENT");
807 for (uInt i=0; i < sdft.length(); ++i) {
808 sc0.put(i,sdft.referencePixel(i));
809 sc1.put(i,sdft.referenceValue(i));
810 sc2.put(i,sdft.increment(i));
811 }
[105]812 String rf = sdft.refFrame();
813 if (rf.contains("TOPO")) rf = "TOPO";
814
815 aTable.rwKeywordSet().define("BASEREFFRAME", rf);
816 aTable.rwKeywordSet().define("REFFRAME", rf);
[39]817 aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
[105]818 aTable.rwKeywordSet().define("UNIT", String(""));
819 aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
[89]820 Vector<Double> rfvec;
[206]821 String rfunit;
822 sdft.restFrequencies(rfvec,rfunit);
823 Quantum<Vector<Double> > q(rfvec, rfunit);
824 rfvec.resize();
825 rfvec = q.getValue("Hz");
[89]826 aTable.rwKeywordSet().define("RESTFREQS", rfvec);
[39]827 table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
828 return True;
829}
830
[206]831SDFrequencyTable SDMemTable::getSDFreqTable() const
832{
[251]833 const Table& t = table_.keywordSet().asTable("FREQUENCIES");
[39]834 SDFrequencyTable sdft;
[306]835
836// Add refpix/refval/incr. What are the units ? Hz I suppose
837// but it's nowhere described...
838
839 Vector<Double> refPix, refVal, incr;
840 ScalarColumn<Double> refPixCol(t, "REFPIX");
841 ScalarColumn<Double> refValCol(t, "REFVAL");
842 ScalarColumn<Double> incrCol(t, "INCREMENT");
843 refPix = refPixCol.getColumn();
844 refVal = refValCol.getColumn();
845 incr = incrCol.getColumn();
846//
847 uInt n = refPix.nelements();
848 for (uInt i=0; i<n; i++) {
849 sdft.addFrequency(refPix[i], refVal[i], incr[i]);
850 }
851
852// Frequency reference frame. I don't know if this
853// is the correct frame. It might be 'REFFRAME'
854// rather than 'BASEREFFRAME' ?
855
856 String baseFrame;
857 t.keywordSet().get("BASEREFFRAME",baseFrame);
858 sdft.setRefFrame(baseFrame);
859
860// Equinox
861
862 Float equinox;
863 t.keywordSet().get("EQUINOX", equinox);
864 sdft.setEquinox(equinox);
865
866// Rest Frequency
867
868 Vector<Double> restFreqs;
869 t.keywordSet().get("RESTFREQS", restFreqs);
870 for (uInt i=0; i<restFreqs.nelements(); i++) {
871 sdft.addRestFrequency(restFreqs[i]);
872 }
873 sdft.setRestFrequencyUnit(String("Hz"));
874//
[39]875 return sdft;
876}
877
[206]878bool SDMemTable::putSDContainer(const SDContainer& sdc)
879{
[2]880 ScalarColumn<Double> mjd(table_, "TIME");
881 ScalarColumn<String> srcn(table_, "SRCNAME");
[105]882 ScalarColumn<String> fldn(table_, "FIELDNAME");
[2]883 ArrayColumn<Float> spec(table_, "SPECTRA");
884 ArrayColumn<uChar> flags(table_, "FLAGTRA");
885 ArrayColumn<Float> ts(table_, "TSYS");
886 ScalarColumn<Int> scan(table_, "SCANID");
[16]887 ScalarColumn<Double> integr(table_, "INTERVAL");
[39]888 ArrayColumn<uInt> freqid(table_, "FREQID");
[78]889 ArrayColumn<Double> dir(table_, "DIRECTION");
[105]890 ScalarColumn<Int> rbeam(table_, "REFBEAM");
891 ArrayColumn<Float> tcal(table_, "TCAL");
892 ScalarColumn<String> tcalt(table_, "TCALTIME");
893 ScalarColumn<Float> az(table_, "AZIMUTH");
894 ScalarColumn<Float> el(table_, "ELEVATION");
895 ScalarColumn<Float> para(table_, "PARANGLE");
[206]896 ArrayColumn<String> hist(table_, "HISTORY");
[2]897
898 uInt rno = table_.nrow();
899 table_.addRow();
[89]900
[2]901 mjd.put(rno, sdc.timestamp);
902 srcn.put(rno, sdc.sourcename);
[105]903 fldn.put(rno, sdc.fieldname);
[2]904 spec.put(rno, sdc.getSpectrum());
905 flags.put(rno, sdc.getFlags());
906 ts.put(rno, sdc.getTsys());
907 scan.put(rno, sdc.scanid);
[16]908 integr.put(rno, sdc.interval);
[39]909 freqid.put(rno, sdc.getFreqMap());
[78]910 dir.put(rno, sdc.getDirection());
[105]911 rbeam.put(rno, sdc.refbeam);
912 tcal.put(rno, sdc.tcal);
913 tcalt.put(rno, sdc.tcaltime);
914 az.put(rno, sdc.azimuth);
915 el.put(rno, sdc.elevation);
916 para.put(rno, sdc.parangle);
[206]917 hist.put(rno, sdc.getHistory());
[89]918
[2]919 return true;
920}
[18]921
[206]922SDContainer SDMemTable::getSDContainer(uInt whichRow) const
923{
[21]924 ROScalarColumn<Double> mjd(table_, "TIME");
925 ROScalarColumn<String> srcn(table_, "SRCNAME");
[105]926 ROScalarColumn<String> fldn(table_, "FIELDNAME");
[21]927 ROArrayColumn<Float> spec(table_, "SPECTRA");
928 ROArrayColumn<uChar> flags(table_, "FLAGTRA");
929 ROArrayColumn<Float> ts(table_, "TSYS");
930 ROScalarColumn<Int> scan(table_, "SCANID");
931 ROScalarColumn<Double> integr(table_, "INTERVAL");
[39]932 ROArrayColumn<uInt> freqid(table_, "FREQID");
[78]933 ROArrayColumn<Double> dir(table_, "DIRECTION");
[105]934 ROScalarColumn<Int> rbeam(table_, "REFBEAM");
935 ROArrayColumn<Float> tcal(table_, "TCAL");
936 ROScalarColumn<String> tcalt(table_, "TCALTIME");
937 ROScalarColumn<Float> az(table_, "AZIMUTH");
938 ROScalarColumn<Float> el(table_, "ELEVATION");
939 ROScalarColumn<Float> para(table_, "PARANGLE");
[206]940 ROArrayColumn<String> hist(table_, "HISTORY");
[21]941
942 SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
943 mjd.get(whichRow, sdc.timestamp);
944 srcn.get(whichRow, sdc.sourcename);
945 integr.get(whichRow, sdc.interval);
946 scan.get(whichRow, sdc.scanid);
[105]947 fldn.get(whichRow, sdc.fieldname);
948 rbeam.get(whichRow, sdc.refbeam);
949 az.get(whichRow, sdc.azimuth);
950 el.get(whichRow, sdc.elevation);
951 para.get(whichRow, sdc.parangle);
952 Vector<Float> tc;
953 tcal.get(whichRow, tc);
954 sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
955 tcalt.get(whichRow, sdc.tcaltime);
[21]956 Array<Float> spectrum;
957 Array<Float> tsys;
958 Array<uChar> flagtrum;
[39]959 Vector<uInt> fmap;
[78]960 Array<Double> direction;
[206]961 Vector<String> histo;
[21]962 spec.get(whichRow, spectrum);
963 sdc.putSpectrum(spectrum);
964 flags.get(whichRow, flagtrum);
965 sdc.putFlags(flagtrum);
966 ts.get(whichRow, tsys);
967 sdc.putTsys(tsys);
[39]968 freqid.get(whichRow, fmap);
969 sdc.putFreqMap(fmap);
[78]970 dir.get(whichRow, direction);
971 sdc.putDirection(direction);
[206]972 hist.get(whichRow, histo);
973 sdc.putHistory(histo);
[21]974 return sdc;
975}
[78]976
[206]977bool SDMemTable::putSDHeader(const SDHeader& sdh)
978{
[18]979 table_.rwKeywordSet().define("nIF", sdh.nif);
980 table_.rwKeywordSet().define("nBeam", sdh.nbeam);
981 table_.rwKeywordSet().define("nPol", sdh.npol);
982 table_.rwKeywordSet().define("nChan", sdh.nchan);
983 table_.rwKeywordSet().define("Observer", sdh.observer);
984 table_.rwKeywordSet().define("Project", sdh.project);
985 table_.rwKeywordSet().define("Obstype", sdh.obstype);
986 table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
987 table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
988 table_.rwKeywordSet().define("Equinox", sdh.equinox);
989 table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
990 table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
991 table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
992 table_.rwKeywordSet().define("UTC", sdh.utc);
[206]993 table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
994 table_.rwKeywordSet().define("Epoch", sdh.epoch);
[18]995 return true;
[50]996}
[21]997
[206]998SDHeader SDMemTable::getSDHeader() const
999{
[21]1000 SDHeader sdh;
1001 table_.keywordSet().get("nBeam",sdh.nbeam);
1002 table_.keywordSet().get("nIF",sdh.nif);
1003 table_.keywordSet().get("nPol",sdh.npol);
1004 table_.keywordSet().get("nChan",sdh.nchan);
1005 table_.keywordSet().get("Observer", sdh.observer);
1006 table_.keywordSet().get("Project", sdh.project);
1007 table_.keywordSet().get("Obstype", sdh.obstype);
1008 table_.keywordSet().get("AntennaName", sdh.antennaname);
1009 table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
1010 table_.keywordSet().get("Equinox", sdh.equinox);
1011 table_.keywordSet().get("FreqRefFrame", sdh.freqref);
1012 table_.keywordSet().get("FreqRefVal", sdh.reffreq);
1013 table_.keywordSet().get("Bandwidth", sdh.bandwidth);
1014 table_.keywordSet().get("UTC", sdh.utc);
[206]1015 table_.keywordSet().get("FluxUnit", sdh.fluxunit);
1016 table_.keywordSet().get("Epoch", sdh.epoch);
[21]1017 return sdh;
[18]1018}
[206]1019void SDMemTable::makePersistent(const std::string& filename)
1020{
[2]1021 table_.deepCopy(filename,Table::New);
1022}
1023
[89]1024Int SDMemTable::nScan() const {
[50]1025 Int n = 0;
1026 ROScalarColumn<Int> scans(table_, "SCANID");
1027 Int previous = -1;Int current=0;
1028 for (uInt i=0; i< scans.nrow();i++) {
1029 scans.getScalar(i,current);
1030 if (previous != current) {
[89]1031 previous = current;
[50]1032 n++;
1033 }
1034 }
1035 return n;
1036}
1037
[260]1038String SDMemTable::formatSec(Double x) const
[206]1039{
[105]1040 Double xcop = x;
1041 MVTime mvt(xcop/24./3600.); // make days
[281]1042
[105]1043 if (x < 59.95)
[281]1044 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
1045 else if (x < 3599.95)
1046 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
1047 else {
1048 ostringstream oss;
1049 oss << setw(2) << std::right << setprecision(1) << mvt.hour();
1050 oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
1051 return String(oss);
1052 }
[105]1053};
1054
[281]1055String SDMemTable::formatDirection(const MDirection& md) const
1056{
1057 Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
1058 Int prec = 7;
1059
1060 MVAngle mvLon(t[0]);
1061 String sLon = mvLon.string(MVAngle::TIME,prec);
1062 MVAngle mvLat(t[1]);
1063 String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
1064
1065 return sLon + String(" ") + sLat;
1066}
1067
1068
[206]1069std::string SDMemTable::getFluxUnit() const
1070{
1071 String tmp;
1072 table_.keywordSet().get("FluxUnit", tmp);
1073 return tmp;
1074}
1075
[218]1076void SDMemTable::setFluxUnit(const std::string& unit)
1077{
1078 String tmp(unit);
1079 Unit tU(tmp);
1080 if (tU==Unit("K") || tU==Unit("Jy")) {
1081 table_.rwKeywordSet().define(String("FluxUnit"), tmp);
1082 } else {
1083 throw AipsError("Illegal unit - must be compatible with Jy or K");
1084 }
1085}
1086
[275]1087
[236]1088void SDMemTable::setInstrument(const std::string& name)
1089{
1090 Bool throwIt = True;
1091 Instrument ins = convertInstrument (name, throwIt);
1092 String nameU(name);
1093 nameU.upcase();
1094 table_.rwKeywordSet().define(String("AntennaName"), nameU);
1095}
1096
[260]1097std::string SDMemTable::summary() const {
[2]1098 ROScalarColumn<Int> scans(table_, "SCANID");
1099 ROScalarColumn<String> srcs(table_, "SRCNAME");
[281]1100
1101 // get number of integrations per scan
1102 int cIdx = 0;
1103 int idx = 0;
1104 int scount = 0;
1105 std::vector<int> cycles;
1106 for (uInt i=0; i<scans.nrow();++i) {
1107 while (idx == cIdx && i<scans.nrow()) {
1108 scans.getScalar(++i,cIdx);
1109 ++scount;
1110 }
1111 idx = cIdx;
1112 cycles.push_back(scount);
1113 scount=0;
1114 --i;
1115 }
1116
1117
[89]1118 ostringstream oss;
1119 oss << endl;
1120 oss << "--------------------------------------------------" << endl;
1121 oss << " Scan Table Summary" << endl;
1122 oss << "--------------------------------------------------" << endl;
1123 oss.flags(std::ios_base::left);
1124 oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
1125 << setw(15) << "IFs:" << setw(4) << nIF() << endl
1126 << setw(15) << "Polarisations:" << setw(4) << nPol() << endl
1127 << setw(15) << "Channels:" << setw(4) << nChan() << endl;
1128 oss << endl;
1129 String tmp;
1130 table_.keywordSet().get("Observer", tmp);
1131 oss << setw(15) << "Observer:" << tmp << endl;
[281]1132 oss << setw(15) << "Obs Date:" << getTime(-1,True) << endl;
[89]1133 table_.keywordSet().get("Project", tmp);
1134 oss << setw(15) << "Project:" << tmp << endl;
1135 table_.keywordSet().get("Obstype", tmp);
1136 oss << setw(15) << "Obs. Type:" << tmp << endl;
1137 table_.keywordSet().get("AntennaName", tmp);
1138 oss << setw(15) << "Antenna Name:" << tmp << endl;
[206]1139 table_.keywordSet().get("FluxUnit", tmp);
1140 oss << setw(15) << "Flux Unit:" << tmp << endl;
[260]1141 Table t = table_.keywordSet().asTable("FREQUENCIES");
[105]1142 Vector<Double> vec;
1143 t.keywordSet().get("RESTFREQS",vec);
1144 oss << setw(15) << "Rest Freqs:";
1145 if (vec.nelements() > 0) {
1146 oss << setprecision(0) << vec << " [Hz]" << endl;
1147 } else {
1148 oss << "None set" << endl;
1149 }
[158]1150 oss << setw(15) << "Abcissa:" << getAbcissaString() << endl;
[105]1151 oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
1152 << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
[89]1153 oss << endl;
[2]1154 uInt count = 0;
1155 String name;
1156 Int previous = -1;Int current=0;
[89]1157 Int integ = 0;
[281]1158 String dirtype ="Position ("+
1159 MDirection::showType(getDirectionReference())+
1160 ")";
[89]1161 oss << setw(6) << "Scan"
[281]1162 << setw(15) << "Source"
1163 << setw(26) << dirtype
1164 << setw(10) << "Time"
1165 << setw(13) << "Integration" << endl;
1166 oss << "-------------------------------------------------------------------------------" << endl;
1167
1168 std::vector<int>::iterator it = cycles.begin();
[2]1169 for (uInt i=0; i< scans.nrow();i++) {
1170 scans.getScalar(i,current);
1171 if (previous != current) {
1172 srcs.getScalar(i,name);
[50]1173 previous = current;
[105]1174 String t = formatSec(Double(getInterval(i)));
[281]1175 String posit = formatDirection(getDirection(i,True));
1176 oss << setw(6) << count
1177 << setw(15) << name
1178 << setw(26) << posit
1179 << setw(10) << getTime(i,False)
1180 << setw(3) << std::right << *it << " x "
1181 << setw(10)
1182 << t << std::left << endl;
[50]1183 count++;
[281]1184 it++;
[89]1185 } else {
1186 integ++;
[2]1187 }
1188 }
[89]1189 oss << endl;
1190 oss << "Table contains " << table_.nrow() << " integration(s)." << endl;
1191 oss << "in " << count << " scan(s)." << endl;
[281]1192 oss << "-------------------------------------------------------------------------------";
[89]1193 return String(oss);
[2]1194}
[18]1195
[206]1196Int SDMemTable::nBeam() const
1197{
[18]1198 Int n;
1199 table_.keywordSet().get("nBeam",n);
1200 return n;
1201}
1202Int SDMemTable::nIF() const {
1203 Int n;
1204 table_.keywordSet().get("nIF",n);
1205 return n;
1206}
1207Int SDMemTable::nPol() const {
1208 Int n;
1209 table_.keywordSet().get("nPol",n);
1210 return n;
1211}
1212Int SDMemTable::nChan() const {
1213 Int n;
1214 table_.keywordSet().get("nChan",n);
1215 return n;
1216}
[206]1217bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
1218{
1219 ArrayColumn<String> histo(table_, "HISTORY");
1220 Vector<String> history;
1221 histo.get(whichRow, history);
1222 history.resize(history.nelements()+1,True);
1223 history[history.nelements()-1] = hist;
1224 histo.put(whichRow, history);
1225}
1226
1227std::vector<std::string> SDMemTable::history(int whichRow) const
1228{
1229 ROArrayColumn<String> hist(table_, "HISTORY");
1230 Vector<String> history;
1231 hist.get(whichRow, history);
1232 std::vector<std::string> stlout;
1233 // there is no Array<String>.tovector(std::vector<std::string>), so
1234 // do it by hand
1235 for (uInt i=0; i<history.nelements(); ++i) {
1236 stlout.push_back(history[i]);
1237 }
1238 return stlout;
1239}
[16]1240/*
[18]1241void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
[89]1242
[16]1243 std::vector<int>::iterator it;
[206]1244 ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_);
[16]1245 for (it = whichChans.begin(); it != whichChans.end(); it++) {
1246 j.reset(j.begin(uInt(*it)));
[206]1247 for (ArrayAccessor<uChar, Axis<asap::BeamAxis> > i(j); i != i.end(); ++i) {
1248 for (ArrayAccessor<uChar, Axis<asap::IFAxis> > ii(i); ii != ii.end(); ++ii) {
1249 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > iii(ii);
[89]1250 iii != iii.end(); ++iii) {
1251 (*iii) =
1252 }
[16]1253 }
1254 }
1255 }
[89]1256
[16]1257}
1258*/
[206]1259void SDMemTable::flag(int whichRow)
1260{
[89]1261 ArrayColumn<uChar> spec(table_, "FLAGTRA");
1262 Array<uChar> arr;
1263 spec.get(whichRow, arr);
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
1276 spec.put(whichRow, arr);
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
1295MEpoch::Types SDMemTable::getTimeReference () const
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
1309Instrument SDMemTable::convertInstrument (const String& instrument,
1310 Bool throwIt)
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 {
1332 if (throwIt) {
1333 throw AipsError("Unrecognized instrument - use function scan.set_instrument to set");
1334 }
1335 }
1336 return inst;
1337}
1338
Note: See TracBrowser for help on using the repository browser.