source: trunk/src/Scantable.cpp@ 846

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

changed getSDHeader -> getHeader
changed nrow interface
added ncycle()

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