source: trunk/src/Scantable.cpp@ 862

Last change on this file since 862 was 860, checked in by mar637, 19 years ago

reworked history table
added STHistory class

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.8 KB
Line 
1//
2// C++ Implementation: Scantable
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2005
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#include <map>
13
14#include <casa/aips.h>
15#include <casa/iostream.h>
16#include <casa/iomanip.h>
17#include <casa/OS/Path.h>
18#include <casa/OS/File.h>
19#include <casa/Arrays/Array.h>
20#include <casa/Arrays/ArrayMath.h>
21#include <casa/Arrays/MaskArrMath.h>
22#include <casa/Arrays/ArrayLogical.h>
23#include <casa/Arrays/ArrayAccessor.h>
24#include <casa/Arrays/VectorSTLIterator.h>
25#include <casa/Arrays/Vector.h>
26#include <casa/BasicMath/Math.h>
27#include <casa/BasicSL/Constants.h>
28#include <casa/Quanta/MVAngle.h>
29#include <casa/Containers/RecordField.h>
30
31#include <tables/Tables/TableParse.h>
32#include <tables/Tables/TableDesc.h>
33#include <tables/Tables/TableCopy.h>
34#include <tables/Tables/SetupNewTab.h>
35#include <tables/Tables/ScaColDesc.h>
36#include <tables/Tables/ArrColDesc.h>
37#include <tables/Tables/TableRow.h>
38#include <tables/Tables/TableVector.h>
39#include <tables/Tables/TableIter.h>
40
41#include <tables/Tables/ExprNode.h>
42#include <tables/Tables/TableRecord.h>
43#include <measures/Measures/MFrequency.h>
44#include <measures/Measures/MEpoch.h>
45#include <measures/Measures/MeasTable.h>
46#include <measures/Measures/MeasRef.h>
47#include <measures/TableMeasures/TableMeasRefDesc.h>
48#include <measures/TableMeasures/TableMeasValueDesc.h>
49#include <measures/TableMeasures/TableMeasDesc.h>
50#include <measures/TableMeasures/ScalarMeasColumn.h>
51#include <coordinates/Coordinates/CoordinateUtil.h>
52#include <casa/Quanta/MVTime.h>
53#include <casa/Quanta/MVAngle.h>
54
55#include "Scantable.h"
56#include "SDAttr.h"
57
58using namespace casa;
59
60namespace asap {
61
62Scantable::Scantable(Table::TableType ttype) :
63 type_(ttype)
64{
65 setupMainTable();
66 freqTable_ = STFrequencies(*this);
67 table_.rwKeywordSet().defineTable("FREQUENCIES", freqTable_.table());
68 weatherTable_ = STWeather(*this);
69 table_.rwKeywordSet().defineTable("WEATHER", weatherTable_.table());
70 focusTable_ = STFocus(*this);
71 table_.rwKeywordSet().defineTable("FOCUS", focusTable_.table());
72 tcalTable_ = STTcal(*this);
73 table_.rwKeywordSet().defineTable("TCAL", tcalTable_.table());
74 moleculeTable_ = STMolecules(*this);
75 table_.rwKeywordSet().defineTable("MOLECULES", moleculeTable_.table());
76 historyTable_ = STHistory(*this);
77 table_.rwKeywordSet().defineTable("HISTORY", historyTable_.table());
78 setupFitTable();
79 fitTable_ = table_.keywordSet().asTable("FITS");
80 originalTable_ = table_;
81 attach();
82}
83
84Scantable::Scantable(const std::string& name, Table::TableType ttype) :
85 type_(ttype)
86{
87 Table tab(name);
88 Int version;
89 tab.keywordSet().get("VERSION", version);
90 if (version != version_) {
91 throw(AipsError("Unsupported version of ASAP file."));
92 }
93 if ( type_ == Table::Memory )
94 table_ = tab.copyToMemoryTable(generateName());
95 else
96 table_ = tab;
97 attachSubtables();
98 originalTable_ = table_;
99 attach();
100}
101
102Scantable::Scantable( const Scantable& other, bool clear )
103{
104 // with or without data
105 String newname = String(generateName());
106 if ( other.table_.tableType() == Table::Memory ) {
107 if ( clear ) {
108 cout << "copy ctor memory clear" << endl;
109 table_ = TableCopy::makeEmptyMemoryTable(newname,
110 other.table_, True);
111 } else
112 table_ = other.table_.copyToMemoryTable(newname);
113 } else {
114 if ( clear ) {
115 cout << "copy ctor clear" << endl;
116 other.table_.deepCopy(newname, Table::New);
117 cout << "reading table" << endl;
118 table_ = Table(newname, Table::Scratch);
119 cout << "removing rows" << endl;
120 table_.removeRow(table_.rowNumbers());
121
122 } else {
123 cout << "copy ctor no clear" << endl;
124 other.table_.deepCopy(newname, Table::Scratch);
125 table_ = Table(newname, Table::Scratch);
126 }
127 }
128 //table_.rwKeywordSet().renameTables(newname, table_.tableName());
129 //cout << table_.keywordSet().asTable("TCAL").tableName() << endl;
130 attachSubtables();
131 originalTable_ = table_;
132 attach();
133}
134
135void Scantable::attachSubtables()
136{
137 freqTable_ = STFrequencies(table_);
138 focusTable_ = STFocus(table_);
139 weatherTable_ = STWeather(table_);
140 tcalTable_ = STTcal(table_);
141 moleculeTable_ = STMolecules(table_);
142 historyTable_ = STHistory(table_);
143}
144
145Scantable::~Scantable()
146{
147 cout << "~Scantable() " << this << endl;
148}
149
150void Scantable::setupMainTable()
151{
152 TableDesc td("", "1", TableDesc::Scratch);
153 td.comment() = "An ASAP Scantable";
154 td.rwKeywordSet().define("VERSION", Int(version_));
155
156 // n Cycles
157 td.addColumn(ScalarColumnDesc<uInt>("SCANNO"));
158 // new index every nBeam x nIF x nPol
159 td.addColumn(ScalarColumnDesc<uInt>("CYCLENO"));
160
161 td.addColumn(ScalarColumnDesc<uInt>("BEAMNO"));
162 td.addColumn(ScalarColumnDesc<uInt>("IFNO"));
163 td.rwKeywordSet().define("POLTYPE", String("linear"));
164 td.addColumn(ScalarColumnDesc<uInt>("POLNO"));
165
166 td.addColumn(ScalarColumnDesc<uInt>("FREQ_ID"));
167 td.addColumn(ScalarColumnDesc<uInt>("MOLECULE_ID"));
168 // linear, circular, stokes [I Q U V], stokes1 [I Plinear Pangle V]
169 td.addColumn(ScalarColumnDesc<Int>("REFBEAMNO"));
170
171 td.addColumn(ScalarColumnDesc<Double>("TIME"));
172 TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default
173 TableMeasValueDesc measVal(td, "TIME");
174 TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
175 mepochCol.write(td);
176
177 td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
178
179 td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
180 // Type of source (on=0, off=1, other=-1)
181 td.addColumn(ScalarColumnDesc<Int>("SRCTYPE", Int(-1)));
182 td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
183
184 //The actual Data Vectors
185 td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
186 td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
187 td.addColumn(ArrayColumnDesc<Float>("TSYS"));
188
189 td.addColumn(ArrayColumnDesc<Double>("DIRECTION",
190 IPosition(1,2),
191 ColumnDesc::Direct));
192 TableMeasRefDesc mdirRef(MDirection::J2000); // default
193 TableMeasValueDesc tmvdMDir(td, "DIRECTION");
194 // the TableMeasDesc gives the column a type
195 TableMeasDesc<MDirection> mdirCol(tmvdMDir, mdirRef);
196 // writing create the measure column
197 mdirCol.write(td);
198 td.addColumn(ScalarColumnDesc<Double>("AZIMUTH"));
199 td.addColumn(ScalarColumnDesc<Double>("ELEVATION"));
200 td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
201
202 td.addColumn(ScalarColumnDesc<uInt>("TCAL_ID"));
203 td.addColumn(ScalarColumnDesc<uInt>("FIT_ID"));
204
205 td.addColumn(ScalarColumnDesc<uInt>("FOCUS_ID"));
206 td.addColumn(ScalarColumnDesc<uInt>("WEATHER_ID"));
207
208 td.rwKeywordSet().define("OBSMODE", String(""));
209
210 // Now create Table SetUp from the description.
211 SetupNewTable aNewTab(generateName(), td, Table::Scratch);
212 table_ = Table(aNewTab, type_, 0);
213 originalTable_ = table_;
214
215}
216
217void Scantable::setupFitTable()
218{
219 TableDesc td("", "1", TableDesc::Scratch);
220 td.addColumn(ScalarColumnDesc<uInt>("FIT_ID"));
221 td.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
222 td.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
223 td.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
224 td.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
225 td.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
226 SetupNewTable aNewTab("fits", td, Table::Scratch);
227 Table aTable(aNewTab, Table::Memory);
228 table_.rwKeywordSet().defineTable("FITS", aTable);
229}
230
231void Scantable::attach()
232{
233 timeCol_.attach(table_, "TIME");
234 srcnCol_.attach(table_, "SRCNAME");
235 specCol_.attach(table_, "SPECTRA");
236 flagsCol_.attach(table_, "FLAGTRA");
237 tsCol_.attach(table_, "TSYS");
238 cycleCol_.attach(table_,"CYCLENO");
239 scanCol_.attach(table_, "SCANNO");
240 beamCol_.attach(table_, "BEAMNO");
241 ifCol_.attach(table_, "IFNO");
242 polCol_.attach(table_, "POLNO");
243 integrCol_.attach(table_, "INTERVAL");
244 azCol_.attach(table_, "AZIMUTH");
245 elCol_.attach(table_, "ELEVATION");
246 dirCol_.attach(table_, "DIRECTION");
247 paraCol_.attach(table_, "PARANGLE");
248 fldnCol_.attach(table_, "FIELDNAME");
249 rbeamCol_.attach(table_, "REFBEAMNO");
250
251 mfitidCol_.attach(table_,"FIT_ID");
252 //fitidCol_.attach(fitTable_,"FIT_ID");
253
254 mfreqidCol_.attach(table_, "FREQ_ID");
255
256 mtcalidCol_.attach(table_, "TCAL_ID");
257
258 mfocusidCol_.attach(table_, "FOCUS_ID");
259
260 mmolidCol_.attach(table_, "MOLECULE_ID");
261}
262
263void Scantable::setHeader(const SDHeader& sdh)
264{
265 table_.rwKeywordSet().define("nIF", sdh.nif);
266 table_.rwKeywordSet().define("nBeam", sdh.nbeam);
267 table_.rwKeywordSet().define("nPol", sdh.npol);
268 table_.rwKeywordSet().define("nChan", sdh.nchan);
269 table_.rwKeywordSet().define("Observer", sdh.observer);
270 table_.rwKeywordSet().define("Project", sdh.project);
271 table_.rwKeywordSet().define("Obstype", sdh.obstype);
272 table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
273 table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
274 table_.rwKeywordSet().define("Equinox", sdh.equinox);
275 table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
276 table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
277 table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
278 table_.rwKeywordSet().define("UTC", sdh.utc);
279 table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
280 table_.rwKeywordSet().define("Epoch", sdh.epoch);
281}
282
283SDHeader Scantable::getHeader() const
284{
285 SDHeader sdh;
286 table_.keywordSet().get("nBeam",sdh.nbeam);
287 table_.keywordSet().get("nIF",sdh.nif);
288 table_.keywordSet().get("nPol",sdh.npol);
289 table_.keywordSet().get("nChan",sdh.nchan);
290 table_.keywordSet().get("Observer", sdh.observer);
291 table_.keywordSet().get("Project", sdh.project);
292 table_.keywordSet().get("Obstype", sdh.obstype);
293 table_.keywordSet().get("AntennaName", sdh.antennaname);
294 table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
295 table_.keywordSet().get("Equinox", sdh.equinox);
296 table_.keywordSet().get("FreqRefFrame", sdh.freqref);
297 table_.keywordSet().get("FreqRefVal", sdh.reffreq);
298 table_.keywordSet().get("Bandwidth", sdh.bandwidth);
299 table_.keywordSet().get("UTC", sdh.utc);
300 table_.keywordSet().get("FluxUnit", sdh.fluxunit);
301 table_.keywordSet().get("Epoch", sdh.epoch);
302 return sdh;
303}
304
305bool Scantable::conformant( const Scantable& other )
306{
307 return this->getHeader().conformant(other.getHeader());
308}
309
310
311int Scantable::nscan() const {
312 int n = 0;
313 int previous = -1; int current = 0;
314 for (uInt i=0; i< scanCol_.nrow();i++) {
315 scanCol_.getScalar(i,current);
316 if (previous != current) {
317 previous = current;
318 n++;
319 }
320 }
321 return n;
322}
323
324std::string Scantable::formatSec(Double x) const
325{
326 Double xcop = x;
327 MVTime mvt(xcop/24./3600.); // make days
328
329 if (x < 59.95)
330 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
331 else if (x < 3599.95)
332 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
333 else {
334 ostringstream oss;
335 oss << setw(2) << std::right << setprecision(1) << mvt.hour();
336 oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
337 return String(oss);
338 }
339};
340
341std::string Scantable::formatDirection(const MDirection& md) const
342{
343 Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
344 Int prec = 7;
345
346 MVAngle mvLon(t[0]);
347 String sLon = mvLon.string(MVAngle::TIME,prec);
348 MVAngle mvLat(t[1]);
349 String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
350 return sLon + String(" ") + sLat;
351}
352
353
354std::string Scantable::getFluxUnit() const
355{
356 return table_.keywordSet().asString("FluxUnit");
357}
358
359void Scantable::setFluxUnit(const std::string& unit)
360{
361 String tmp(unit);
362 Unit tU(tmp);
363 if (tU==Unit("K") || tU==Unit("Jy")) {
364 table_.rwKeywordSet().define(String("FluxUnit"), tmp);
365 } else {
366 throw AipsError("Illegal unit - must be compatible with Jy or K");
367 }
368}
369
370void Scantable::setInstrument(const std::string& name)
371{
372 bool throwIt = true;
373 Instrument ins = SDAttr::convertInstrument(name, throwIt);
374 String nameU(name);
375 nameU.upcase();
376 table_.rwKeywordSet().define(String("AntennaName"), nameU);
377}
378
379MPosition Scantable::getAntennaPosition () const
380{
381 Vector<Double> antpos;
382 table_.keywordSet().get("AntennaPosition", antpos);
383 MVPosition mvpos(antpos(0),antpos(1),antpos(2));
384 return MPosition(mvpos);
385}
386
387void Scantable::makePersistent(const std::string& filename)
388{
389 String inname(filename);
390 Path path(inname);
391 inname = path.expandedName();
392 //cout << table_.tableName() << endl;
393 //cout << freqTable_.table().tableName() << endl;
394 table_.deepCopy(inname, Table::New);
395 //Table t = Table(inname, Table::Update);
396 //cout << t.keywordSet().asTable("FREQUENCIES").tableName() << endl;
397}
398
399int Scantable::nbeam( int scanno ) const
400{
401 if ( scanno < 0 ) {
402 Int n;
403 table_.keywordSet().get("nBeam",n);
404 return int(n);
405 } else {
406 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
407 Table tab = table_(table_.col("SCANNO") == scanno
408 && table_.col("POLNO") == 0
409 && table_.col("IFNO") == 0
410 && table_.col("CYCLENO") == 0 );
411 ROTableVector<uInt> v(tab, "BEAMNO");
412 return int(v.nelements());
413 }
414 return 0;
415}
416
417int Scantable::nif( int scanno ) const
418{
419 if ( scanno < 0 ) {
420 Int n;
421 table_.keywordSet().get("nIF",n);
422 return int(n);
423 } else {
424 // take the first POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these
425 Table tab = table_(table_.col("SCANNO") == scanno
426 && table_.col("POLNO") == 0
427 && table_.col("BEAMNO") == 0
428 && table_.col("CYCLENO") == 0 );
429 ROTableVector<uInt> v(tab, "IFNO");
430 return int(v.nelements());
431 }
432 return 0;
433}
434
435int Scantable::npol( int scanno ) const
436{
437 if ( scanno < 0 ) {
438 Int n;
439 table_.keywordSet().get("nPol",n);
440 return n;
441 } else {
442 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
443 Table tab = table_(table_.col("SCANNO") == scanno
444 && table_.col("IFNO") == 0
445 && table_.col("BEAMNO") == 0
446 && table_.col("CYCLENO") == 0 );
447 ROTableVector<uInt> v(tab, "POLNO");
448 return int(v.nelements());
449 }
450 return 0;
451}
452
453int Scantable::ncycle( int scanno ) const
454{
455 if ( scanno < 0 ) {
456 Block<String> cols(2);
457 cols[0] = "SCANNO";
458 cols[1] = "CYCLENO";
459 TableIterator it(table_, cols);
460 int n = 0;
461 while ( !it.pastEnd() ) {
462 ++n;
463 }
464 return n;
465 } else {
466 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
467 Table tab = table_(table_.col("SCANNO") == scanno
468 && table_.col("BEAMNO") == 0
469 && table_.col("IFNO") == 0
470 && table_.col("POLNO") == 0 );
471 return int(tab.nrow());
472 }
473 return 0;
474}
475
476
477int Scantable::nrow( int scanno ) const
478{
479 return int(table_.nrow());
480}
481
482int Scantable::nchan( int ifno ) const
483{
484 if ( ifno < 0 ) {
485 Int n;
486 table_.keywordSet().get("nChan",n);
487 return int(n);
488 } else {
489 // take the first SCANNO,POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these
490 Table tab = table_(table_.col("SCANNO") == 0
491 && table_.col("IFNO") == ifno
492 && table_.col("BEAMNO") == 0
493 && table_.col("POLNO") == 0
494 && table_.col("CYCLENO") == 0 );
495 ROArrayColumn<Float> v(tab, "SPECTRA");
496 return v(0).nelements();
497 }
498 return 0;
499}
500
501
502int Scantable::getBeam(int whichrow) const
503{
504 return beamCol_(whichrow);
505}
506
507int Scantable::getIF(int whichrow) const
508{
509 return ifCol_(whichrow);
510}
511
512int Scantable::getPol(int whichrow) const
513{
514 return polCol_(whichrow);
515}
516
517std::string Scantable::formatTime(const MEpoch& me, bool showdate) const
518{
519 MVTime mvt(me.getValue());
520 if (showdate)
521 mvt.setFormat(MVTime::YMD);
522 else
523 mvt.setFormat(MVTime::TIME);
524 ostringstream oss;
525 oss << mvt;
526 return String(oss);
527}
528
529void Scantable::calculateAZEL()
530{
531 MPosition mp = getAntennaPosition();
532 MEpoch::ROScalarColumn timeCol(table_, "TIME");
533 ostringstream oss;
534 oss << "Computed azimuth/elevation using " << endl
535 << mp << endl;
536 for (uInt i=0; i<nrow(); ++i) {
537 MEpoch me = timeCol(i);
538 MDirection md = dirCol_(i);
539 dirCol_.get(i,md);
540 oss << " Time: " << formatTime(me,False) << " Direction: " << formatDirection(md)
541 << endl << " => ";
542 MeasFrame frame(mp, me);
543 Vector<Double> azel =
544 MDirection::Convert(md, MDirection::Ref(MDirection::AZEL,
545 frame)
546 )().getAngle("rad").getValue();
547 azCol_.put(i,azel[0]);
548 elCol_.put(i,azel[1]);
549 oss << "azel: " << azel[0]/C::pi*180.0 << " "
550 << azel[1]/C::pi*180.0 << " (deg)" << endl;
551 }
552 pushLog(String(oss));
553}
554
555std::vector<bool> Scantable::getMask(int whichrow) const
556{
557 Vector<uChar> flags;
558 flagsCol_.get(uInt(whichrow), flags);
559 Vector<Bool> bflag(flags.shape());
560 convertArray(bflag, flags);
561 bflag = !bflag;
562 std::vector<bool> mask;
563 bflag.tovector(mask);
564 return mask;
565}
566
567std::vector<float> Scantable::getSpectrum(int whichrow) const
568{
569 Vector<Float> arr;
570 specCol_.get(whichrow, arr);
571 std::vector<float> out;
572 arr.tovector(out);
573 return out;
574}
575
576String Scantable::generateName()
577{
578 return (File::newUniqueName("./","temp")).baseName();
579}
580
581const casa::Table& Scantable::table( ) const
582{
583 return table_;
584}
585
586casa::Table& Scantable::table( )
587{
588 return table_;
589}
590
591std::string Scantable::getPolarizationLabel(bool linear, bool stokes,
592 bool linpol, int polidx) const
593{
594 uInt idx = 0;
595 if (polidx >=0) idx = polidx;
596 return "";
597 //return SDPolUtil::polarizationLabel(idx, linear, stokes, linpol);
598}
599
600void Scantable::unsetSelection()
601{
602 table_ = originalTable_;
603 attach();
604 selector_.reset();
605}
606
607void Scantable::setSelection( const STSelector& selection )
608{
609 Table tab = const_cast<STSelector&>(selection).apply(originalTable_);
610 if ( tab.nrow() == 0 ) {
611 throw(AipsError("Selection contains no data. Not applying it."));
612 }
613 table_ = tab;
614 attach();
615 selector_ = selection;
616}
617
618std::string Scantable::summary( bool verbose )
619{
620 // Format header info
621 ostringstream oss;
622 oss << endl;
623 oss << asap::SEPERATOR << endl;
624 oss << " Scan Table Summary" << endl;
625 oss << asap::SEPERATOR << endl;
626 oss.flags(std::ios_base::left);
627 oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl
628 << setw(15) << "IFs:" << setw(4) << nif() << endl
629 << setw(15) << "Polarisations:" << setw(4) << npol() << endl
630 << setw(15) << "Channels:" << setw(4) << nchan() << endl;
631 oss << endl;
632 String tmp;
633 oss << setw(15) << "Observer:"
634 << table_.keywordSet().asString("Observer") << endl;
635 oss << setw(15) << "Obs Date:" << getTime(-1,true) << endl;
636 table_.keywordSet().get("Project", tmp);
637 oss << setw(15) << "Project:" << tmp << endl;
638 table_.keywordSet().get("Obstype", tmp);
639 oss << setw(15) << "Obs. Type:" << tmp << endl;
640 table_.keywordSet().get("AntennaName", tmp);
641 oss << setw(15) << "Antenna Name:" << tmp << endl;
642 table_.keywordSet().get("FluxUnit", tmp);
643 oss << setw(15) << "Flux Unit:" << tmp << endl;
644 Vector<Float> vec;
645 oss << setw(15) << "Rest Freqs:";
646 if (vec.nelements() > 0) {
647 oss << setprecision(10) << vec << " [Hz]" << endl;
648 } else {
649 oss << "none" << endl;
650 }
651 oss << setw(15) << "Abcissa:" << "channel" << endl;
652 oss << selector_.print() << endl;
653 oss << endl;
654 // main table
655 String dirtype = "Position ("
656 + MDirection::showType(dirCol_.getMeasRef().getType())
657 + ")";
658 oss << setw(5) << "Scan"
659 << setw(15) << "Source"
660// << setw(24) << dirtype
661 << setw(10) << "Time"
662 << setw(18) << "Integration" << endl
663 << setw(5) << "" << setw(10) << "Beam" << dirtype << endl
664 << setw(15) << "" << setw(5) << "IF"
665 << setw(8) << "Frame" << setw(16)
666 << "RefVal" << setw(10) << "RefPix" << setw(12) << "Increment" <<endl;
667 oss << asap::SEPERATOR << endl;
668 TableIterator iter(table_, "SCANNO");
669 while (!iter.pastEnd()) {
670 Table subt = iter.table();
671 ROTableRow row(subt);
672 MEpoch::ROScalarColumn timeCol(subt,"TIME");
673 const TableRecord& rec = row.get(0);
674 oss << setw(4) << std::right << rec.asuInt("SCANNO")
675 << std::left << setw(1) << ""
676 << setw(15) << rec.asString("SRCNAME")
677 << setw(10) << formatTime(timeCol(0), false);
678 // count the cycles in the scan
679 TableIterator cyciter(subt, "CYCLENO");
680 int nint = 0;
681 while (!cyciter.pastEnd()) {
682 ++nint;
683 ++cyciter;
684 }
685 oss << setw(3) << std::right << nint << setw(3) << " x " << std::left
686 << setw(6) << formatSec(rec.asFloat("INTERVAL")) << endl;
687
688 TableIterator biter(subt, "BEAMNO");
689 while (!biter.pastEnd()) {
690 Table bsubt = biter.table();
691 ROTableRow brow(bsubt);
692 MDirection::ROScalarColumn bdirCol(bsubt,"DIRECTION");
693 const TableRecord& brec = brow.get(0);
694 oss << setw(6) << "" << setw(10) << brec.asuInt("BEAMNO");
695 oss << setw(24) << formatDirection(bdirCol(0)) << endl;
696 TableIterator iiter(bsubt, "IFNO");
697 while (!iiter.pastEnd()) {
698 Table isubt = iiter.table();
699 ROTableRow irow(isubt);
700 const TableRecord& irec = irow.get(0);
701 oss << std::right <<setw(8) << "" << std::left << irec.asuInt("IFNO");
702 oss << frequencies().print(irec.asuInt("FREQ_ID"));
703
704 ++iiter;
705 }
706 ++biter;
707 }
708 ++iter;
709 }
710 /// @todo implement verbose mode
711 return String(oss);
712}
713
714std::string Scantable::getTime(int whichrow, bool showdate) const
715{
716 MEpoch::ROScalarColumn timeCol(table_, "TIME");
717 MEpoch me;
718 if (whichrow > -1) {
719 me = timeCol(uInt(whichrow));
720 } else {
721 Double tm;
722 table_.keywordSet().get("UTC",tm);
723 me = MEpoch(MVEpoch(tm));
724 }
725 return formatTime(me, showdate);
726}
727
728std::string Scantable::getAbcissaLabel( int whichrow ) const
729{
730 if ( whichrow > table_.nrow() ) throw(AipsError("Illegal ro number"));
731 const MPosition& mp = getAntennaPosition();
732 const MDirection& md = dirCol_(whichrow);
733 const MEpoch& me = timeCol_(whichrow);
734 const Double& rf = mmolidCol_(whichrow);
735 SpectralCoordinate spc =
736 freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow));
737
738 String s = "Channel";
739 Unit u = Unit(freqTable_.getUnitString());
740 if (u == Unit("km/s")) {
741 s = CoordinateUtil::axisLabel(spc,0,True,True,True);
742 } else if (u == Unit("Hz")) {
743 Vector<String> wau(1);wau = u.getName();
744 spc.setWorldAxisUnits(wau);
745
746 s = CoordinateUtil::axisLabel(spc,0,True,True,False);
747 }
748 return s;
749
750}
751
752void asap::Scantable::setRestFrequencies( double rf, const std::string& unit )
753{
754 ///@todo lookup in line table
755 Unit u(unit);
756 Quantum<Double> urf(rf, u);
757 uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), "", "");
758 TableVector<uInt> tabvec(table_, "MOLECULE_ID");
759 tabvec = id;
760}
761
762void asap::Scantable::setRestFrequencies( const std::string& name )
763{
764 throw(AipsError("setRestFrequencies( const std::string& name ) NYI"));
765 ///@todo implement
766}
767
768std::vector< unsigned int > asap::Scantable::rownumbers( ) const
769{
770 std::vector<unsigned int> stlout;
771 Vector<uInt> vec = table_.rowNumbers();
772 vec.tovector(stlout);
773 return stlout;
774}
775
776}//namespace asap
Note: See TracBrowser for help on using the repository browser.