source: trunk/src/Scantable.cpp@ 849

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

numerous changes before move to new svn repository sourcecode.atnf.csiro.au

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