source: trunk/src/Scantable.cpp@ 859

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

reworked subtable handling
fixed bug in casa::Table construction, where Table::New was used instead of Table::Scratch

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 24.0 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 setupHistoryTable();
77 setupFitTable();
78 historyTable_ = table_.keywordSet().asTable("HISTORY");
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
102
103Scantable::Scantable( const Scantable& other, bool clear )
104{
105 // with or without data
106 String newname = String(generateName());
107 if ( other.table_.tableType() == Table::Memory ) {
108 if ( clear ) {
109 cout << "copy ctor memory clear" << endl;
110 table_ = TableCopy::makeEmptyMemoryTable(newname,
111 other.table_, True);
112 } else
113 table_ = other.table_.copyToMemoryTable(newname);
114 } else {
115 if ( clear ) {
116 cout << "copy ctor clear" << endl;
117 other.table_.deepCopy(newname, Table::New);
118 cout << "reading table" << endl;
119 table_ = Table(newname, Table::Scratch);
120 cout << "removing rows" << endl;
121 table_.removeRow(table_.rowNumbers());
122
123 } else {
124 cout << "copy ctor no clear" << endl;
125 other.table_.deepCopy(newname, Table::Scratch);
126 table_ = Table(newname, Table::Scratch);
127 }
128 }
129 //table_.rwKeywordSet().renameTables(newname, table_.tableName());
130 //cout << table_.keywordSet().asTable("TCAL").tableName() << endl;
131 attachSubtables();
132 originalTable_ = table_;
133 attach();
134}
135
136void Scantable::attachSubtables()
137{
138 freqTable_ = STFrequencies(table_);
139 focusTable_ = STFocus(table_);
140 weatherTable_ = STWeather(table_);
141 tcalTable_ = STTcal(table_);
142 moleculeTable_ = STMolecules(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::setupHistoryTable( )
218{
219 TableDesc tdh("", "1", TableDesc::Scratch);
220 tdh.addColumn(ScalarColumnDesc<String>("ITEM"));
221 SetupNewTable histtab("history", tdh, Table::Scratch);
222 Table histTable(histtab, Table::Memory);
223 table_.rwKeywordSet().defineTable("HISTORY", histTable);
224}
225
226void Scantable::setupFitTable()
227{
228 TableDesc td("", "1", TableDesc::Scratch);
229 td.addColumn(ScalarColumnDesc<uInt>("FIT_ID"));
230 td.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
231 td.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
232 td.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
233 td.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
234 td.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
235 SetupNewTable aNewTab("fits", td, Table::Scratch);
236 Table aTable(aNewTab, Table::Memory);
237 table_.rwKeywordSet().defineTable("FITS", aTable);
238}
239
240void Scantable::attach()
241{
242 timeCol_.attach(table_, "TIME");
243 srcnCol_.attach(table_, "SRCNAME");
244 specCol_.attach(table_, "SPECTRA");
245 flagsCol_.attach(table_, "FLAGTRA");
246 tsCol_.attach(table_, "TSYS");
247 cycleCol_.attach(table_,"CYCLENO");
248 scanCol_.attach(table_, "SCANNO");
249 beamCol_.attach(table_, "BEAMNO");
250 ifCol_.attach(table_, "IFNO");
251 polCol_.attach(table_, "POLNO");
252 integrCol_.attach(table_, "INTERVAL");
253 azCol_.attach(table_, "AZIMUTH");
254 elCol_.attach(table_, "ELEVATION");
255 dirCol_.attach(table_, "DIRECTION");
256 paraCol_.attach(table_, "PARANGLE");
257 fldnCol_.attach(table_, "FIELDNAME");
258 rbeamCol_.attach(table_, "REFBEAMNO");
259
260 mfitidCol_.attach(table_,"FIT_ID");
261 //fitidCol_.attach(fitTable_,"FIT_ID");
262
263 mfreqidCol_.attach(table_, "FREQ_ID");
264
265 mtcalidCol_.attach(table_, "TCAL_ID");
266
267 mfocusidCol_.attach(table_, "FOCUS_ID");
268
269 mmolidCol_.attach(table_, "MOLECULE_ID");
270}
271
272void Scantable::setHeader(const SDHeader& sdh)
273{
274 table_.rwKeywordSet().define("nIF", sdh.nif);
275 table_.rwKeywordSet().define("nBeam", sdh.nbeam);
276 table_.rwKeywordSet().define("nPol", sdh.npol);
277 table_.rwKeywordSet().define("nChan", sdh.nchan);
278 table_.rwKeywordSet().define("Observer", sdh.observer);
279 table_.rwKeywordSet().define("Project", sdh.project);
280 table_.rwKeywordSet().define("Obstype", sdh.obstype);
281 table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
282 table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
283 table_.rwKeywordSet().define("Equinox", sdh.equinox);
284 table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
285 table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
286 table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
287 table_.rwKeywordSet().define("UTC", sdh.utc);
288 table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
289 table_.rwKeywordSet().define("Epoch", sdh.epoch);
290}
291
292SDHeader Scantable::getHeader() const
293{
294 SDHeader sdh;
295 table_.keywordSet().get("nBeam",sdh.nbeam);
296 table_.keywordSet().get("nIF",sdh.nif);
297 table_.keywordSet().get("nPol",sdh.npol);
298 table_.keywordSet().get("nChan",sdh.nchan);
299 table_.keywordSet().get("Observer", sdh.observer);
300 table_.keywordSet().get("Project", sdh.project);
301 table_.keywordSet().get("Obstype", sdh.obstype);
302 table_.keywordSet().get("AntennaName", sdh.antennaname);
303 table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
304 table_.keywordSet().get("Equinox", sdh.equinox);
305 table_.keywordSet().get("FreqRefFrame", sdh.freqref);
306 table_.keywordSet().get("FreqRefVal", sdh.reffreq);
307 table_.keywordSet().get("Bandwidth", sdh.bandwidth);
308 table_.keywordSet().get("UTC", sdh.utc);
309 table_.keywordSet().get("FluxUnit", sdh.fluxunit);
310 table_.keywordSet().get("Epoch", sdh.epoch);
311 return sdh;
312}
313
314bool Scantable::conformant( const Scantable& other )
315{
316 return this->getHeader().conformant(other.getHeader());
317}
318
319
320int Scantable::nscan() const {
321 int n = 0;
322 int previous = -1; int current = 0;
323 for (uInt i=0; i< scanCol_.nrow();i++) {
324 scanCol_.getScalar(i,current);
325 if (previous != current) {
326 previous = current;
327 n++;
328 }
329 }
330 return n;
331}
332
333std::string Scantable::formatSec(Double x) const
334{
335 Double xcop = x;
336 MVTime mvt(xcop/24./3600.); // make days
337
338 if (x < 59.95)
339 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
340 else if (x < 3599.95)
341 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
342 else {
343 ostringstream oss;
344 oss << setw(2) << std::right << setprecision(1) << mvt.hour();
345 oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
346 return String(oss);
347 }
348};
349
350std::string Scantable::formatDirection(const MDirection& md) const
351{
352 Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
353 Int prec = 7;
354
355 MVAngle mvLon(t[0]);
356 String sLon = mvLon.string(MVAngle::TIME,prec);
357 MVAngle mvLat(t[1]);
358 String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
359 return sLon + String(" ") + sLat;
360}
361
362
363std::string Scantable::getFluxUnit() const
364{
365 return table_.keywordSet().asString("FluxUnit");
366}
367
368void Scantable::setFluxUnit(const std::string& unit)
369{
370 String tmp(unit);
371 Unit tU(tmp);
372 if (tU==Unit("K") || tU==Unit("Jy")) {
373 table_.rwKeywordSet().define(String("FluxUnit"), tmp);
374 } else {
375 throw AipsError("Illegal unit - must be compatible with Jy or K");
376 }
377}
378
379void Scantable::setInstrument(const std::string& name)
380{
381 bool throwIt = true;
382 Instrument ins = SDAttr::convertInstrument(name, throwIt);
383 String nameU(name);
384 nameU.upcase();
385 table_.rwKeywordSet().define(String("AntennaName"), nameU);
386}
387
388MPosition Scantable::getAntennaPosition () const
389{
390 Vector<Double> antpos;
391 table_.keywordSet().get("AntennaPosition", antpos);
392 MVPosition mvpos(antpos(0),antpos(1),antpos(2));
393 return MPosition(mvpos);
394}
395
396void Scantable::makePersistent(const std::string& filename)
397{
398 String inname(filename);
399 Path path(inname);
400 inname = path.expandedName();
401 //cout << table_.tableName() << endl;
402 //cout << freqTable_.table().tableName() << endl;
403 table_.deepCopy(inname, Table::New);
404 //Table t = Table(inname, Table::Update);
405 //cout << t.keywordSet().asTable("FREQUENCIES").tableName() << endl;
406}
407
408int Scantable::nbeam( int scanno ) const
409{
410 if ( scanno < 0 ) {
411 Int n;
412 table_.keywordSet().get("nBeam",n);
413 return int(n);
414 } else {
415 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
416 Table tab = table_(table_.col("SCANNO") == scanno
417 && table_.col("POLNO") == 0
418 && table_.col("IFNO") == 0
419 && table_.col("CYCLENO") == 0 );
420 ROTableVector<uInt> v(tab, "BEAMNO");
421 return int(v.nelements());
422 }
423 return 0;
424}
425
426int Scantable::nif( int scanno ) const
427{
428 if ( scanno < 0 ) {
429 Int n;
430 table_.keywordSet().get("nIF",n);
431 return int(n);
432 } else {
433 // take the first POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these
434 Table tab = table_(table_.col("SCANNO") == scanno
435 && table_.col("POLNO") == 0
436 && table_.col("BEAMNO") == 0
437 && table_.col("CYCLENO") == 0 );
438 ROTableVector<uInt> v(tab, "IFNO");
439 return int(v.nelements());
440 }
441 return 0;
442}
443
444int Scantable::npol( int scanno ) const
445{
446 if ( scanno < 0 ) {
447 Int n;
448 table_.keywordSet().get("nPol",n);
449 return n;
450 } else {
451 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
452 Table tab = table_(table_.col("SCANNO") == scanno
453 && table_.col("IFNO") == 0
454 && table_.col("BEAMNO") == 0
455 && table_.col("CYCLENO") == 0 );
456 ROTableVector<uInt> v(tab, "POLNO");
457 return int(v.nelements());
458 }
459 return 0;
460}
461
462int Scantable::ncycle( int scanno ) const
463{
464 if ( scanno < 0 ) {
465 Block<String> cols(2);
466 cols[0] = "SCANNO";
467 cols[1] = "CYCLENO";
468 TableIterator it(table_, cols);
469 int n = 0;
470 while ( !it.pastEnd() ) {
471 ++n;
472 }
473 return n;
474 } else {
475 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
476 Table tab = table_(table_.col("SCANNO") == scanno
477 && table_.col("BEAMNO") == 0
478 && table_.col("IFNO") == 0
479 && table_.col("POLNO") == 0 );
480 return int(tab.nrow());
481 }
482 return 0;
483}
484
485
486int Scantable::nrow( int scanno ) const
487{
488 return int(table_.nrow());
489}
490
491int Scantable::nchan( int ifno ) const
492{
493 if ( ifno < 0 ) {
494 Int n;
495 table_.keywordSet().get("nChan",n);
496 return int(n);
497 } else {
498 // take the first SCANNO,POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these
499 Table tab = table_(table_.col("SCANNO") == 0
500 && table_.col("IFNO") == ifno
501 && table_.col("BEAMNO") == 0
502 && table_.col("POLNO") == 0
503 && table_.col("CYCLENO") == 0 );
504 ROArrayColumn<Float> v(tab, "SPECTRA");
505 return v(0).nelements();
506 }
507 return 0;
508}
509
510
511int Scantable::getBeam(int whichrow) const
512{
513 return beamCol_(whichrow);
514}
515
516int Scantable::getIF(int whichrow) const
517{
518 return ifCol_(whichrow);
519}
520
521int Scantable::getPol(int whichrow) const
522{
523 return polCol_(whichrow);
524}
525
526Table Scantable::getHistoryTable() const
527{
528 return table_.keywordSet().asTable("HISTORY");
529}
530
531void Scantable::appendToHistoryTable(const Table& otherHist)
532{
533 Table t = table_.rwKeywordSet().asTable("HISTORY");
534
535 addHistory(asap::SEPERATOR);
536 TableCopy::copyRows(t, otherHist, t.nrow(), 0, otherHist.nrow());
537 addHistory(asap::SEPERATOR);
538}
539
540void Scantable::addHistory(const std::string& hist)
541{
542 Table t = table_.rwKeywordSet().asTable("HISTORY");
543 uInt nrow = t.nrow();
544 t.addRow();
545 ScalarColumn<String> itemCol(t, "ITEM");
546 itemCol.put(nrow, hist);
547}
548
549std::vector<std::string> Scantable::getHistory() const
550{
551 Vector<String> history;
552 const Table& t = table_.keywordSet().asTable("HISTORY");
553 uInt nrow = t.nrow();
554 ROScalarColumn<String> itemCol(t, "ITEM");
555 std::vector<std::string> stlout;
556 String hist;
557 for (uInt i=0; i<nrow; ++i) {
558 itemCol.get(i, hist);
559 stlout.push_back(hist);
560 }
561 return stlout;
562}
563
564std::string Scantable::formatTime(const MEpoch& me, bool showdate) const
565{
566 MVTime mvt(me.getValue());
567 if (showdate)
568 mvt.setFormat(MVTime::YMD);
569 else
570 mvt.setFormat(MVTime::TIME);
571 ostringstream oss;
572 oss << mvt;
573 return String(oss);
574}
575
576void Scantable::calculateAZEL()
577{
578 MPosition mp = getAntennaPosition();
579 MEpoch::ROScalarColumn timeCol(table_, "TIME");
580 ostringstream oss;
581 oss << "Computed azimuth/elevation using " << endl
582 << mp << endl;
583 for (uInt i=0; i<nrow(); ++i) {
584 MEpoch me = timeCol(i);
585 MDirection md = dirCol_(i);
586 dirCol_.get(i,md);
587 oss << " Time: " << formatTime(me,False) << " Direction: " << formatDirection(md)
588 << endl << " => ";
589 MeasFrame frame(mp, me);
590 Vector<Double> azel =
591 MDirection::Convert(md, MDirection::Ref(MDirection::AZEL,
592 frame)
593 )().getAngle("rad").getValue();
594 azCol_.put(i,azel[0]);
595 elCol_.put(i,azel[1]);
596 oss << "azel: " << azel[0]/C::pi*180.0 << " "
597 << azel[1]/C::pi*180.0 << " (deg)" << endl;
598 }
599 pushLog(String(oss));
600}
601
602std::vector<bool> Scantable::getMask(int whichrow) const
603{
604 Vector<uChar> flags;
605 flagsCol_.get(uInt(whichrow), flags);
606 Vector<Bool> bflag(flags.shape());
607 convertArray(bflag, flags);
608 bflag = !bflag;
609 std::vector<bool> mask;
610 bflag.tovector(mask);
611 return mask;
612}
613
614std::vector<float> Scantable::getSpectrum(int whichrow) const
615{
616 Vector<Float> arr;
617 specCol_.get(whichrow, arr);
618 std::vector<float> out;
619 arr.tovector(out);
620 return out;
621}
622
623String Scantable::generateName()
624{
625 return (File::newUniqueName("./","temp")).baseName();
626}
627
628const casa::Table& Scantable::table( ) const
629{
630 return table_;
631}
632
633casa::Table& Scantable::table( )
634{
635 return table_;
636}
637
638std::string Scantable::getPolarizationLabel(bool linear, bool stokes,
639 bool linpol, int polidx) const
640{
641 uInt idx = 0;
642 if (polidx >=0) idx = polidx;
643 return "";
644 //return SDPolUtil::polarizationLabel(idx, linear, stokes, linpol);
645}
646
647void Scantable::unsetSelection()
648{
649 table_ = originalTable_;
650 attach();
651 selector_.reset();
652}
653
654void Scantable::setSelection( const STSelector& selection )
655{
656 Table tab = const_cast<STSelector&>(selection).apply(originalTable_);
657 if ( tab.nrow() == 0 ) {
658 throw(AipsError("Selection contains no data. Not applying it."));
659 }
660 table_ = tab;
661 attach();
662 selector_ = selection;
663}
664
665std::string Scantable::summary( bool verbose )
666{
667 // Format header info
668 ostringstream oss;
669 oss << endl;
670 oss << asap::SEPERATOR << endl;
671 oss << " Scan Table Summary" << endl;
672 oss << asap::SEPERATOR << endl;
673 oss.flags(std::ios_base::left);
674 oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl
675 << setw(15) << "IFs:" << setw(4) << nif() << endl
676 << setw(15) << "Polarisations:" << setw(4) << npol() << endl
677 << setw(15) << "Channels:" << setw(4) << nchan() << endl;
678 oss << endl;
679 String tmp;
680 //table_.keywordSet().get("Observer", tmp);
681 oss << setw(15) << "Observer:" << table_.keywordSet().asString("Observer") << endl;
682 oss << setw(15) << "Obs Date:" << getTime(-1,true) << endl;
683 table_.keywordSet().get("Project", tmp);
684 oss << setw(15) << "Project:" << tmp << endl;
685 table_.keywordSet().get("Obstype", tmp);
686 oss << setw(15) << "Obs. Type:" << tmp << endl;
687 table_.keywordSet().get("AntennaName", tmp);
688 oss << setw(15) << "Antenna Name:" << tmp << endl;
689 table_.keywordSet().get("FluxUnit", tmp);
690 oss << setw(15) << "Flux Unit:" << tmp << endl;
691 Vector<Float> vec;
692 oss << setw(15) << "Rest Freqs:";
693 if (vec.nelements() > 0) {
694 oss << setprecision(10) << vec << " [Hz]" << endl;
695 } else {
696 oss << "none" << endl;
697 }
698 oss << setw(15) << "Abcissa:" << "channel" << endl;
699 oss << selector_.print() << endl;
700 oss << endl;
701 // main table
702 String dirtype = "Position ("
703 + MDirection::showType(dirCol_.getMeasRef().getType())
704 + ")";
705 oss << setw(5) << "Scan"
706 << setw(15) << "Source"
707// << setw(24) << dirtype
708 << setw(10) << "Time"
709 << setw(18) << "Integration" << endl
710 << setw(5) << "" << setw(10) << "Beam" << dirtype << endl
711 << setw(15) << "" << setw(5) << "IF"
712 << setw(8) << "Frame" << setw(16)
713 << "RefVal" << setw(10) << "RefPix" << setw(12) << "Increment" <<endl;
714 oss << asap::SEPERATOR << endl;
715 TableIterator iter(table_, "SCANNO");
716 while (!iter.pastEnd()) {
717 Table subt = iter.table();
718 ROTableRow row(subt);
719 MEpoch::ROScalarColumn timeCol(subt,"TIME");
720 const TableRecord& rec = row.get(0);
721 oss << setw(4) << std::right << rec.asuInt("SCANNO")
722 << std::left << setw(1) << ""
723 << setw(15) << rec.asString("SRCNAME")
724 << setw(10) << formatTime(timeCol(0), false);
725 // count the cycles in the scan
726 TableIterator cyciter(subt, "CYCLENO");
727 int nint = 0;
728 while (!cyciter.pastEnd()) {
729 ++nint;
730 ++cyciter;
731 }
732 oss << setw(3) << std::right << nint << setw(3) << " x " << std::left
733 << setw(6) << formatSec(rec.asFloat("INTERVAL")) << endl;
734
735 TableIterator biter(subt, "BEAMNO");
736 while (!biter.pastEnd()) {
737 Table bsubt = biter.table();
738 ROTableRow brow(bsubt);
739 MDirection::ROScalarColumn bdirCol(bsubt,"DIRECTION");
740 const TableRecord& brec = brow.get(0);
741 oss << setw(6) << "" << setw(10) << brec.asuInt("BEAMNO");
742 oss << setw(24) << formatDirection(bdirCol(0)) << endl;
743 TableIterator iiter(bsubt, "IFNO");
744 while (!iiter.pastEnd()) {
745 Table isubt = iiter.table();
746 ROTableRow irow(isubt);
747 const TableRecord& irec = irow.get(0);
748 oss << std::right <<setw(8) << "" << std::left << irec.asuInt("IFNO");
749 oss << frequencies().print(irec.asuInt("FREQ_ID"));
750
751 ++iiter;
752 }
753 ++biter;
754 }
755 ++iter;
756 }
757 /// @todo implement verbose mode
758 return String(oss);
759}
760
761std::string Scantable::getTime(int whichrow, bool showdate) const
762{
763 MEpoch::ROScalarColumn timeCol(table_, "TIME");
764 MEpoch me;
765 if (whichrow > -1) {
766 me = timeCol(uInt(whichrow));
767 } else {
768 Double tm;
769 table_.keywordSet().get("UTC",tm);
770 me = MEpoch(MVEpoch(tm));
771 }
772 return formatTime(me, showdate);
773}
774
775std::string Scantable::getAbcissaLabel( int whichrow ) const
776{
777 if ( whichrow > table_.nrow() ) throw(AipsError("Illegal ro number"));
778 const MPosition& mp = getAntennaPosition();
779 const MDirection& md = dirCol_(whichrow);
780 const MEpoch& me = timeCol_(whichrow);
781 const Double& rf = mmolidCol_(whichrow);
782 SpectralCoordinate spc =
783 freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow));
784
785 String s = "Channel";
786 Unit u = Unit(freqTable_.getUnitString());
787 if (u == Unit("km/s")) {
788 s = CoordinateUtil::axisLabel(spc,0,True,True,True);
789 } else if (u == Unit("Hz")) {
790 Vector<String> wau(1);wau = u.getName();
791 spc.setWorldAxisUnits(wau);
792
793 s = CoordinateUtil::axisLabel(spc,0,True,True,False);
794 }
795 return s;
796
797}
798
799void asap::Scantable::setRestFrequencies( double rf, const std::string& unit )
800{
801 ///@todo lookup in line table
802 Unit u(unit);
803 Quantum<Double> urf(rf, u);
804 uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), "", "");
805 TableVector<uInt> tabvec(table_, "MOLECULE_ID");
806 tabvec = id;
807}
808
809void asap::Scantable::setRestFrequencies( const std::string& name )
810{
811 throw(AipsError("setRestFrequencies( const std::string& name ) NYI"));
812 ///@todo implement
813}
814
815std::vector< unsigned int > asap::Scantable::rownumbers( ) const
816{
817 std::vector<unsigned int> stlout;
818 Vector<uInt> vec = table_.rowNumbers();
819 vec.tovector(stlout);
820 return stlout;
821}
822
823}//namespace asap
Note: See TracBrowser for help on using the repository browser.