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
RevLine 
[805]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//
[206]12#include <map>
13
[125]14#include <casa/aips.h>
[80]15#include <casa/iostream.h>
16#include <casa/iomanip.h>
[805]17#include <casa/OS/Path.h>
18#include <casa/OS/File.h>
[80]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>
[455]24#include <casa/Arrays/VectorSTLIterator.h>
[206]25#include <casa/Arrays/Vector.h>
[418]26#include <casa/BasicMath/Math.h>
[504]27#include <casa/BasicSL/Constants.h>
[286]28#include <casa/Quanta/MVAngle.h>
[805]29#include <casa/Containers/RecordField.h>
[2]30
[80]31#include <tables/Tables/TableParse.h>
32#include <tables/Tables/TableDesc.h>
[488]33#include <tables/Tables/TableCopy.h>
[80]34#include <tables/Tables/SetupNewTab.h>
35#include <tables/Tables/ScaColDesc.h>
36#include <tables/Tables/ArrColDesc.h>
[805]37#include <tables/Tables/TableRow.h>
38#include <tables/Tables/TableVector.h>
39#include <tables/Tables/TableIter.h>
[2]40
[80]41#include <tables/Tables/ExprNode.h>
42#include <tables/Tables/TableRecord.h>
43#include <measures/Measures/MFrequency.h>
[805]44#include <measures/Measures/MEpoch.h>
[80]45#include <measures/Measures/MeasTable.h>
[805]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>
[105]51#include <coordinates/Coordinates/CoordinateUtil.h>
[80]52#include <casa/Quanta/MVTime.h>
[281]53#include <casa/Quanta/MVAngle.h>
[2]54
[805]55#include "Scantable.h"
[476]56#include "SDAttr.h"
[2]57
[125]58using namespace casa;
[2]59
[805]60namespace asap {
61
62Scantable::Scantable(Table::TableType ttype) :
[852]63 type_(ttype)
[206]64{
[805]65 setupMainTable();
[852]66 freqTable_ = STFrequencies(*this);
[805]67 table_.rwKeywordSet().defineTable("FREQUENCIES", freqTable_.table());
[852]68 weatherTable_ = STWeather(*this);
[805]69 table_.rwKeywordSet().defineTable("WEATHER", weatherTable_.table());
[852]70 focusTable_ = STFocus(*this);
[805]71 table_.rwKeywordSet().defineTable("FOCUS", focusTable_.table());
[852]72 tcalTable_ = STTcal(*this);
[805]73 table_.rwKeywordSet().defineTable("TCAL", tcalTable_.table());
[852]74 moleculeTable_ = STMolecules(*this);
[805]75 table_.rwKeywordSet().defineTable("MOLECULES", moleculeTable_.table());
[860]76 historyTable_ = STHistory(*this);
77 table_.rwKeywordSet().defineTable("HISTORY", historyTable_.table());
[805]78 setupFitTable();
[852]79 fitTable_ = table_.keywordSet().asTable("FITS");
[805]80 originalTable_ = table_;
[322]81 attach();
[18]82}
[206]83
[805]84Scantable::Scantable(const std::string& name, Table::TableType ttype) :
[852]85 type_(ttype)
[206]86{
[50]87 Table tab(name);
[499]88 Int version;
[483]89 tab.keywordSet().get("VERSION", version);
90 if (version != version_) {
91 throw(AipsError("Unsupported version of ASAP file."));
92 }
[805]93 if ( type_ == Table::Memory )
[852]94 table_ = tab.copyToMemoryTable(generateName());
[805]95 else
96 table_ = tab;
[859]97 attachSubtables();
[805]98 originalTable_ = table_;
[329]99 attach();
[2]100}
101
[805]102Scantable::Scantable( const Scantable& other, bool clear )
[206]103{
[805]104 // with or without data
[859]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);
[16]113 } else {
[859]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 }
[16]127 }
[859]128 //table_.rwKeywordSet().renameTables(newname, table_.tableName());
129 //cout << table_.keywordSet().asTable("TCAL").tableName() << endl;
130 attachSubtables();
[805]131 originalTable_ = table_;
[322]132 attach();
[2]133}
134
[859]135void Scantable::attachSubtables()
136{
137 freqTable_ = STFrequencies(table_);
138 focusTable_ = STFocus(table_);
139 weatherTable_ = STWeather(table_);
140 tcalTable_ = STTcal(table_);
141 moleculeTable_ = STMolecules(table_);
[860]142 historyTable_ = STHistory(table_);
[859]143}
144
[805]145Scantable::~Scantable()
[206]146{
[805]147 cout << "~Scantable() " << this << endl;
[2]148}
149
[805]150void Scantable::setupMainTable()
[206]151{
[805]152 TableDesc td("", "1", TableDesc::Scratch);
153 td.comment() = "An ASAP Scantable";
154 td.rwKeywordSet().define("VERSION", Int(version_));
[2]155
[805]156 // n Cycles
157 td.addColumn(ScalarColumnDesc<uInt>("SCANNO"));
158 // new index every nBeam x nIF x nPol
159 td.addColumn(ScalarColumnDesc<uInt>("CYCLENO"));
[2]160
[805]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"));
[138]165
[805]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"));
[80]170
[805]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);
[483]176
[805]177 td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
178
[2]179 td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
[805]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
[2]185 td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
186 td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
[89]187 td.addColumn(ArrayColumnDesc<Float>("TSYS"));
[805]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"));
[105]200 td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
201
[805]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
[418]210 // Now create Table SetUp from the description.
[859]211 SetupNewTable aNewTab(generateName(), td, Table::Scratch);
[852]212 table_ = Table(aNewTab, type_, 0);
[805]213 originalTable_ = table_;
[745]214
[805]215}
[418]216
[805]217void Scantable::setupFitTable()
[322]218{
[39]219 TableDesc td("", "1", TableDesc::Scratch);
[805]220 td.addColumn(ScalarColumnDesc<uInt>("FIT_ID"));
[455]221 td.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
222 td.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
223 td.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
224 td.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
[465]225 td.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
[859]226 SetupNewTable aNewTab("fits", td, Table::Scratch);
[455]227 Table aTable(aNewTab, Table::Memory);
228 table_.rwKeywordSet().defineTable("FITS", aTable);
229}
230
[805]231void Scantable::attach()
[455]232{
[805]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");
[847]241 ifCol_.attach(table_, "IFNO");
242 polCol_.attach(table_, "POLNO");
[805]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");
[455]250
[805]251 mfitidCol_.attach(table_,"FIT_ID");
[859]252 //fitidCol_.attach(fitTable_,"FIT_ID");
[465]253
[805]254 mfreqidCol_.attach(table_, "FREQ_ID");
[465]255
[805]256 mtcalidCol_.attach(table_, "TCAL_ID");
[465]257
[805]258 mfocusidCol_.attach(table_, "FOCUS_ID");
[455]259
[805]260 mmolidCol_.attach(table_, "MOLECULE_ID");
[455]261}
262
[845]263void Scantable::setHeader(const SDHeader& sdh)
[206]264{
[18]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);
[206]279 table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
280 table_.rwKeywordSet().define("Epoch", sdh.epoch);
[50]281}
[21]282
[845]283SDHeader Scantable::getHeader() const
[206]284{
[21]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);
[206]300 table_.keywordSet().get("FluxUnit", sdh.fluxunit);
301 table_.keywordSet().get("Epoch", sdh.epoch);
[21]302 return sdh;
[18]303}
[805]304
[845]305bool Scantable::conformant( const Scantable& other )
306{
307 return this->getHeader().conformant(other.getHeader());
308}
309
310
[837]311int Scantable::nscan() const {
[805]312 int n = 0;
313 int previous = -1; int current = 0;
[322]314 for (uInt i=0; i< scanCol_.nrow();i++) {
315 scanCol_.getScalar(i,current);
[50]316 if (previous != current) {
[89]317 previous = current;
[50]318 n++;
319 }
320 }
321 return n;
322}
323
[805]324std::string Scantable::formatSec(Double x) const
[206]325{
[105]326 Double xcop = x;
327 MVTime mvt(xcop/24./3600.); // make days
[365]328
[105]329 if (x < 59.95)
[281]330 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
[745]331 else if (x < 3599.95)
[281]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);
[745]338 }
[105]339};
340
[805]341std::string Scantable::formatDirection(const MDirection& md) const
[281]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);
[380]350 return sLon + String(" ") + sLat;
[281]351}
352
353
[805]354std::string Scantable::getFluxUnit() const
[206]355{
[847]356 return table_.keywordSet().asString("FluxUnit");
[206]357}
358
[805]359void Scantable::setFluxUnit(const std::string& unit)
[218]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
[805]370void Scantable::setInstrument(const std::string& name)
[236]371{
[805]372 bool throwIt = true;
[476]373 Instrument ins = SDAttr::convertInstrument(name, throwIt);
[236]374 String nameU(name);
375 nameU.upcase();
376 table_.rwKeywordSet().define(String("AntennaName"), nameU);
377}
378
[805]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}
[281]386
[805]387void Scantable::makePersistent(const std::string& filename)
388{
389 String inname(filename);
390 Path path(inname);
391 inname = path.expandedName();
[859]392 //cout << table_.tableName() << endl;
393 //cout << freqTable_.table().tableName() << endl;
[805]394 table_.deepCopy(inname, Table::New);
[859]395 //Table t = Table(inname, Table::Update);
396 //cout << t.keywordSet().asTable("FREQUENCIES").tableName() << endl;
[805]397}
398
[837]399int Scantable::nbeam( int scanno ) const
[805]400{
401 if ( scanno < 0 ) {
402 Int n;
403 table_.keywordSet().get("nBeam",n);
404 return int(n);
[105]405 } else {
[805]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());
[105]413 }
[805]414 return 0;
415}
[455]416
[837]417int Scantable::nif( int scanno ) const
[805]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());
[2]431 }
[805]432 return 0;
433}
[321]434
[837]435int Scantable::npol( int scanno ) const
[805]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());
[321]449 }
[805]450 return 0;
[2]451}
[805]452
[845]453int Scantable::ncycle( int scanno ) const
[206]454{
[805]455 if ( scanno < 0 ) {
[837]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;
[805]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;
[18]474}
[455]475
476
[845]477int Scantable::nrow( int scanno ) const
[805]478{
[845]479 return int(table_.nrow());
480}
481
482int Scantable::nchan( int ifno ) const
483{
484 if ( ifno < 0 ) {
[805]485 Int n;
486 table_.keywordSet().get("nChan",n);
487 return int(n);
488 } else {
[845]489 // take the first SCANNO,POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these
490 Table tab = table_(table_.col("SCANNO") == 0
[805]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");
[837]496 return v(0).nelements();
[805]497 }
498 return 0;
[18]499}
[455]500
[847]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
[805]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}
[488]528
[805]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;
[16]551 }
[805]552 pushLog(String(oss));
553}
[89]554
[805]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}
[89]566
[805]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;
[89]574}
[212]575
[805]576String Scantable::generateName()
[745]577{
[805]578 return (File::newUniqueName("./","temp")).baseName();
[212]579}
580
[805]581const casa::Table& Scantable::table( ) const
[212]582{
[805]583 return table_;
[212]584}
585
[805]586casa::Table& Scantable::table( )
[386]587{
[805]588 return table_;
[386]589}
590
[805]591std::string Scantable::getPolarizationLabel(bool linear, bool stokes,
592 bool linpol, int polidx) const
[401]593{
[805]594 uInt idx = 0;
595 if (polidx >=0) idx = polidx;
596 return "";
597 //return SDPolUtil::polarizationLabel(idx, linear, stokes, linpol);
[401]598}
[386]599
[805]600void Scantable::unsetSelection()
[380]601{
[805]602 table_ = originalTable_;
[847]603 attach();
[805]604 selector_.reset();
[380]605}
[386]606
[805]607void Scantable::setSelection( const STSelector& selection )
[430]608{
[805]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;
[847]614 attach();
[805]615 selector_ = selection;
[430]616}
617
[837]618std::string Scantable::summary( bool verbose )
[447]619{
[805]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;
[860]633 oss << setw(15) << "Observer:"
634 << table_.keywordSet().asString("Observer") << endl;
[805]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;
[447]687
[805]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"));
[447]703
[805]704 ++iiter;
705 }
706 ++biter;
707 }
708 ++iter;
[447]709 }
[805]710 /// @todo implement verbose mode
711 return String(oss);
[447]712}
713
[805]714std::string Scantable::getTime(int whichrow, bool showdate) const
[777]715{
[805]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));
[777]724 }
[805]725 return formatTime(me, showdate);
[777]726}
[805]727
[847]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
[852]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
[805]776}//namespace asap
Note: See TracBrowser for help on using the repository browser.