source: trunk/src/Scantable.cpp@ 885

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

added setSpectrum

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