[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] | 58 | using namespace casa;
|
---|
[2] | 59 |
|
---|
[805] | 60 | namespace asap {
|
---|
| 61 |
|
---|
| 62 | Scantable::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] | 83 | Scantable::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 |
|
---|
| 103 | Scantable::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] | 117 | Scantable::~Scantable()
|
---|
[206] | 118 | {
|
---|
[805] | 119 | cout << "~Scantable() " << this << endl;
|
---|
[2] | 120 | }
|
---|
| 121 |
|
---|
[805] | 122 | void 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] | 190 | void 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] | 199 | void 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] | 213 | void 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 |
|
---|
[805] | 246 | void Scantable::putSDHeader(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 |
|
---|
[805] | 266 | SDHeader Scantable::getSDHeader() 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 |
|
---|
| 288 | int Scantable::rowToScanIndex( int therow )
|
---|
[745] | 289 | {
|
---|
[805] | 290 | int therealrow = -1;
|
---|
[483] | 291 |
|
---|
[805] | 292 | return therealrow;
|
---|
[2] | 293 | }
|
---|
| 294 |
|
---|
[837] | 295 | int Scantable::nscan() const {
|
---|
[805] | 296 | int n = 0;
|
---|
| 297 | int previous = -1; int current = 0;
|
---|
[322] | 298 | for (uInt i=0; i< scanCol_.nrow();i++) {
|
---|
| 299 | scanCol_.getScalar(i,current);
|
---|
[50] | 300 | if (previous != current) {
|
---|
[89] | 301 | previous = current;
|
---|
[50] | 302 | n++;
|
---|
| 303 | }
|
---|
| 304 | }
|
---|
| 305 | return n;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
[805] | 308 | std::string Scantable::formatSec(Double x) const
|
---|
[206] | 309 | {
|
---|
[105] | 310 | Double xcop = x;
|
---|
| 311 | MVTime mvt(xcop/24./3600.); // make days
|
---|
[365] | 312 |
|
---|
[105] | 313 | if (x < 59.95)
|
---|
[281] | 314 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
|
---|
[745] | 315 | else if (x < 3599.95)
|
---|
[281] | 316 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
|
---|
| 317 | else {
|
---|
| 318 | ostringstream oss;
|
---|
| 319 | oss << setw(2) << std::right << setprecision(1) << mvt.hour();
|
---|
| 320 | oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
|
---|
| 321 | return String(oss);
|
---|
[745] | 322 | }
|
---|
[105] | 323 | };
|
---|
| 324 |
|
---|
[805] | 325 | std::string Scantable::formatDirection(const MDirection& md) const
|
---|
[281] | 326 | {
|
---|
| 327 | Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
|
---|
| 328 | Int prec = 7;
|
---|
| 329 |
|
---|
| 330 | MVAngle mvLon(t[0]);
|
---|
| 331 | String sLon = mvLon.string(MVAngle::TIME,prec);
|
---|
| 332 | MVAngle mvLat(t[1]);
|
---|
| 333 | String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
|
---|
[380] | 334 | return sLon + String(" ") + sLat;
|
---|
[281] | 335 | }
|
---|
| 336 |
|
---|
| 337 |
|
---|
[805] | 338 | std::string Scantable::getFluxUnit() const
|
---|
[206] | 339 | {
|
---|
| 340 | String tmp;
|
---|
| 341 | table_.keywordSet().get("FluxUnit", tmp);
|
---|
| 342 | return tmp;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
[805] | 345 | void Scantable::setFluxUnit(const std::string& unit)
|
---|
[218] | 346 | {
|
---|
| 347 | String tmp(unit);
|
---|
| 348 | Unit tU(tmp);
|
---|
| 349 | if (tU==Unit("K") || tU==Unit("Jy")) {
|
---|
| 350 | table_.rwKeywordSet().define(String("FluxUnit"), tmp);
|
---|
| 351 | } else {
|
---|
| 352 | throw AipsError("Illegal unit - must be compatible with Jy or K");
|
---|
| 353 | }
|
---|
| 354 | }
|
---|
| 355 |
|
---|
[805] | 356 | void Scantable::setInstrument(const std::string& name)
|
---|
[236] | 357 | {
|
---|
[805] | 358 | bool throwIt = true;
|
---|
[476] | 359 | Instrument ins = SDAttr::convertInstrument(name, throwIt);
|
---|
[236] | 360 | String nameU(name);
|
---|
| 361 | nameU.upcase();
|
---|
| 362 | table_.rwKeywordSet().define(String("AntennaName"), nameU);
|
---|
| 363 | }
|
---|
| 364 |
|
---|
[805] | 365 | MPosition Scantable::getAntennaPosition () const
|
---|
| 366 | {
|
---|
| 367 | Vector<Double> antpos;
|
---|
| 368 | table_.keywordSet().get("AntennaPosition", antpos);
|
---|
| 369 | MVPosition mvpos(antpos(0),antpos(1),antpos(2));
|
---|
| 370 | return MPosition(mvpos);
|
---|
| 371 | }
|
---|
[281] | 372 |
|
---|
[805] | 373 | void Scantable::makePersistent(const std::string& filename)
|
---|
| 374 | {
|
---|
| 375 | String inname(filename);
|
---|
| 376 | Path path(inname);
|
---|
| 377 | inname = path.expandedName();
|
---|
| 378 | table_.deepCopy(inname, Table::New);
|
---|
| 379 | }
|
---|
| 380 |
|
---|
[837] | 381 | int Scantable::nbeam( int scanno ) const
|
---|
[805] | 382 | {
|
---|
| 383 | if ( scanno < 0 ) {
|
---|
| 384 | Int n;
|
---|
| 385 | table_.keywordSet().get("nBeam",n);
|
---|
| 386 | return int(n);
|
---|
[105] | 387 | } else {
|
---|
[805] | 388 | // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
|
---|
| 389 | Table tab = table_(table_.col("SCANNO") == scanno
|
---|
| 390 | && table_.col("POLNO") == 0
|
---|
| 391 | && table_.col("IFNO") == 0
|
---|
| 392 | && table_.col("CYCLENO") == 0 );
|
---|
| 393 | ROTableVector<uInt> v(tab, "BEAMNO");
|
---|
| 394 | return int(v.nelements());
|
---|
[105] | 395 | }
|
---|
[805] | 396 | return 0;
|
---|
| 397 | }
|
---|
[455] | 398 |
|
---|
[837] | 399 | int Scantable::nif( int scanno ) const
|
---|
[805] | 400 | {
|
---|
| 401 | if ( scanno < 0 ) {
|
---|
| 402 | Int n;
|
---|
| 403 | table_.keywordSet().get("nIF",n);
|
---|
| 404 | return int(n);
|
---|
| 405 | } else {
|
---|
| 406 | // take the first POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these
|
---|
| 407 | Table tab = table_(table_.col("SCANNO") == scanno
|
---|
| 408 | && table_.col("POLNO") == 0
|
---|
| 409 | && table_.col("BEAMNO") == 0
|
---|
| 410 | && table_.col("CYCLENO") == 0 );
|
---|
| 411 | ROTableVector<uInt> v(tab, "IFNO");
|
---|
| 412 | return int(v.nelements());
|
---|
[2] | 413 | }
|
---|
[805] | 414 | return 0;
|
---|
| 415 | }
|
---|
[321] | 416 |
|
---|
[837] | 417 | int Scantable::npol( int scanno ) const
|
---|
[805] | 418 | {
|
---|
| 419 | if ( scanno < 0 ) {
|
---|
| 420 | Int n;
|
---|
| 421 | table_.keywordSet().get("nPol",n);
|
---|
| 422 | return n;
|
---|
| 423 | } else {
|
---|
| 424 | // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
|
---|
| 425 | Table tab = table_(table_.col("SCANNO") == scanno
|
---|
| 426 | && table_.col("IFNO") == 0
|
---|
| 427 | && table_.col("BEAMNO") == 0
|
---|
| 428 | && table_.col("CYCLENO") == 0 );
|
---|
| 429 | ROTableVector<uInt> v(tab, "POLNO");
|
---|
| 430 | return int(v.nelements());
|
---|
[321] | 431 | }
|
---|
[805] | 432 | return 0;
|
---|
[2] | 433 | }
|
---|
[805] | 434 |
|
---|
[837] | 435 | int Scantable::nrow( int scanno ) const
|
---|
[206] | 436 | {
|
---|
[805] | 437 | if ( scanno < 0 ) {
|
---|
[837] | 438 | Block<String> cols(2);
|
---|
| 439 | cols[0] = "SCANNO";
|
---|
| 440 | cols[1] = "CYCLENO";
|
---|
| 441 | TableIterator it(table_, cols);
|
---|
| 442 | int n = 0;
|
---|
| 443 | while ( !it.pastEnd() ) {
|
---|
| 444 | ++n;
|
---|
| 445 | }
|
---|
| 446 | return n;
|
---|
[805] | 447 | } else {
|
---|
| 448 | // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these
|
---|
| 449 | Table tab = table_(table_.col("SCANNO") == scanno
|
---|
| 450 | && table_.col("BEAMNO") == 0
|
---|
| 451 | && table_.col("IFNO") == 0
|
---|
| 452 | && table_.col("POLNO") == 0 );
|
---|
| 453 | return int(tab.nrow());
|
---|
| 454 | }
|
---|
| 455 | return 0;
|
---|
[18] | 456 | }
|
---|
[455] | 457 |
|
---|
| 458 |
|
---|
[837] | 459 | int Scantable::nchan( int scanno, int ifno ) const
|
---|
[805] | 460 | {
|
---|
[837] | 461 | if ( scanno < 0 || ifno < 0 ) {
|
---|
[805] | 462 | Int n;
|
---|
| 463 | table_.keywordSet().get("nChan",n);
|
---|
| 464 | return int(n);
|
---|
| 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("IFNO") == ifno
|
---|
| 469 | && table_.col("BEAMNO") == 0
|
---|
| 470 | && table_.col("POLNO") == 0
|
---|
| 471 | && table_.col("CYCLENO") == 0 );
|
---|
| 472 | ROArrayColumn<Float> v(tab, "SPECTRA");
|
---|
[837] | 473 | return v(0).nelements();
|
---|
[805] | 474 | }
|
---|
| 475 | return 0;
|
---|
[18] | 476 | }
|
---|
[455] | 477 |
|
---|
[805] | 478 | Table Scantable::getHistoryTable() const
|
---|
[488] | 479 | {
|
---|
| 480 | return table_.keywordSet().asTable("HISTORY");
|
---|
| 481 | }
|
---|
| 482 |
|
---|
[805] | 483 | void Scantable::appendToHistoryTable(const Table& otherHist)
|
---|
[488] | 484 | {
|
---|
| 485 | Table t = table_.rwKeywordSet().asTable("HISTORY");
|
---|
[805] | 486 |
|
---|
| 487 | addHistory(asap::SEPERATOR);
|
---|
[488] | 488 | TableCopy::copyRows(t, otherHist, t.nrow(), 0, otherHist.nrow());
|
---|
[805] | 489 | addHistory(asap::SEPERATOR);
|
---|
[488] | 490 | }
|
---|
| 491 |
|
---|
[805] | 492 | void Scantable::addHistory(const std::string& hist)
|
---|
[206] | 493 | {
|
---|
[483] | 494 | Table t = table_.rwKeywordSet().asTable("HISTORY");
|
---|
[745] | 495 | uInt nrow = t.nrow();
|
---|
[483] | 496 | t.addRow();
|
---|
| 497 | ScalarColumn<String> itemCol(t, "ITEM");
|
---|
| 498 | itemCol.put(nrow, hist);
|
---|
[206] | 499 | }
|
---|
| 500 |
|
---|
[805] | 501 | std::vector<std::string> Scantable::getHistory() const
|
---|
[206] | 502 | {
|
---|
| 503 | Vector<String> history;
|
---|
[483] | 504 | const Table& t = table_.keywordSet().asTable("HISTORY");
|
---|
[745] | 505 | uInt nrow = t.nrow();
|
---|
[483] | 506 | ROScalarColumn<String> itemCol(t, "ITEM");
|
---|
| 507 | std::vector<std::string> stlout;
|
---|
| 508 | String hist;
|
---|
| 509 | for (uInt i=0; i<nrow; ++i) {
|
---|
| 510 | itemCol.get(i, hist);
|
---|
| 511 | stlout.push_back(hist);
|
---|
| 512 | }
|
---|
[206] | 513 | return stlout;
|
---|
| 514 | }
|
---|
[488] | 515 |
|
---|
[805] | 516 | std::string Scantable::formatTime(const MEpoch& me, bool showdate) const
|
---|
| 517 | {
|
---|
| 518 | MVTime mvt(me.getValue());
|
---|
| 519 | if (showdate)
|
---|
| 520 | mvt.setFormat(MVTime::YMD);
|
---|
| 521 | else
|
---|
| 522 | mvt.setFormat(MVTime::TIME);
|
---|
| 523 | ostringstream oss;
|
---|
| 524 | oss << mvt;
|
---|
| 525 | return String(oss);
|
---|
| 526 | }
|
---|
[488] | 527 |
|
---|
[805] | 528 | void Scantable::calculateAZEL()
|
---|
| 529 | {
|
---|
| 530 | MPosition mp = getAntennaPosition();
|
---|
| 531 | MEpoch::ROScalarColumn timeCol(table_, "TIME");
|
---|
| 532 | ostringstream oss;
|
---|
| 533 | oss << "Computed azimuth/elevation using " << endl
|
---|
| 534 | << mp << endl;
|
---|
| 535 | for (uInt i=0; i<nrow(); ++i) {
|
---|
| 536 | MEpoch me = timeCol(i);
|
---|
| 537 | MDirection md = dirCol_(i);
|
---|
| 538 | dirCol_.get(i,md);
|
---|
| 539 | oss << " Time: " << formatTime(me,False) << " Direction: " << formatDirection(md)
|
---|
| 540 | << endl << " => ";
|
---|
| 541 | MeasFrame frame(mp, me);
|
---|
| 542 | Vector<Double> azel =
|
---|
| 543 | MDirection::Convert(md, MDirection::Ref(MDirection::AZEL,
|
---|
| 544 | frame)
|
---|
| 545 | )().getAngle("rad").getValue();
|
---|
| 546 | azCol_.put(i,azel[0]);
|
---|
| 547 | elCol_.put(i,azel[1]);
|
---|
| 548 | oss << "azel: " << azel[0]/C::pi*180.0 << " "
|
---|
| 549 | << azel[1]/C::pi*180.0 << " (deg)" << endl;
|
---|
[16] | 550 | }
|
---|
[805] | 551 | pushLog(String(oss));
|
---|
| 552 | }
|
---|
[89] | 553 |
|
---|
[805] | 554 | double Scantable::getInterval(int whichrow) const
|
---|
| 555 | {
|
---|
| 556 | if (whichrow < 0) return 0.0;
|
---|
| 557 | Double intval;
|
---|
| 558 | integrCol_.get(Int(whichrow), intval);
|
---|
| 559 | return intval;
|
---|
[16] | 560 | }
|
---|
[89] | 561 |
|
---|
[805] | 562 | std::vector<bool> Scantable::getMask(int whichrow) const
|
---|
| 563 | {
|
---|
| 564 | Vector<uChar> flags;
|
---|
| 565 | flagsCol_.get(uInt(whichrow), flags);
|
---|
| 566 | Vector<Bool> bflag(flags.shape());
|
---|
| 567 | convertArray(bflag, flags);
|
---|
| 568 | bflag = !bflag;
|
---|
| 569 | std::vector<bool> mask;
|
---|
| 570 | bflag.tovector(mask);
|
---|
| 571 | return mask;
|
---|
| 572 | }
|
---|
[89] | 573 |
|
---|
[805] | 574 | std::vector<float> Scantable::getSpectrum(int whichrow) const
|
---|
| 575 | {
|
---|
| 576 | Vector<Float> arr;
|
---|
| 577 | specCol_.get(whichrow, arr);
|
---|
| 578 | std::vector<float> out;
|
---|
| 579 | arr.tovector(out);
|
---|
| 580 | return out;
|
---|
[89] | 581 | }
|
---|
[212] | 582 |
|
---|
[805] | 583 | String Scantable::generateName()
|
---|
[745] | 584 | {
|
---|
[805] | 585 | return (File::newUniqueName("./","temp")).baseName();
|
---|
[212] | 586 | }
|
---|
| 587 |
|
---|
[805] | 588 | const casa::Table& Scantable::table( ) const
|
---|
[212] | 589 | {
|
---|
[805] | 590 | return table_;
|
---|
[212] | 591 | }
|
---|
| 592 |
|
---|
[805] | 593 | casa::Table& Scantable::table( )
|
---|
[386] | 594 | {
|
---|
[805] | 595 | return table_;
|
---|
[386] | 596 | }
|
---|
| 597 |
|
---|
[805] | 598 | std::string Scantable::getPolarizationLabel(bool linear, bool stokes,
|
---|
| 599 | bool linpol, int polidx) const
|
---|
[401] | 600 | {
|
---|
[805] | 601 | uInt idx = 0;
|
---|
| 602 | if (polidx >=0) idx = polidx;
|
---|
| 603 | return "";
|
---|
| 604 | //return SDPolUtil::polarizationLabel(idx, linear, stokes, linpol);
|
---|
[401] | 605 | }
|
---|
[386] | 606 |
|
---|
[805] | 607 | void Scantable::unsetSelection()
|
---|
[380] | 608 | {
|
---|
[805] | 609 | table_ = originalTable_;
|
---|
| 610 | selector_.reset();
|
---|
[380] | 611 | }
|
---|
[386] | 612 |
|
---|
[805] | 613 | void Scantable::setSelection( const STSelector& selection )
|
---|
[430] | 614 | {
|
---|
[805] | 615 | Table tab = const_cast<STSelector&>(selection).apply(originalTable_);
|
---|
| 616 | if ( tab.nrow() == 0 ) {
|
---|
| 617 | throw(AipsError("Selection contains no data. Not applying it."));
|
---|
| 618 | }
|
---|
| 619 | table_ = tab;
|
---|
| 620 | selector_ = selection;
|
---|
[430] | 621 | }
|
---|
| 622 |
|
---|
[837] | 623 | std::string Scantable::summary( bool verbose )
|
---|
[447] | 624 | {
|
---|
[805] | 625 | // Format header info
|
---|
| 626 | ostringstream oss;
|
---|
| 627 | oss << endl;
|
---|
| 628 | oss << asap::SEPERATOR << endl;
|
---|
| 629 | oss << " Scan Table Summary" << endl;
|
---|
| 630 | oss << asap::SEPERATOR << endl;
|
---|
| 631 | oss.flags(std::ios_base::left);
|
---|
| 632 | oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl
|
---|
| 633 | << setw(15) << "IFs:" << setw(4) << nif() << endl
|
---|
| 634 | << setw(15) << "Polarisations:" << setw(4) << npol() << endl
|
---|
| 635 | << setw(15) << "Channels:" << setw(4) << nchan() << endl;
|
---|
| 636 | oss << endl;
|
---|
| 637 | String tmp;
|
---|
| 638 | //table_.keywordSet().get("Observer", tmp);
|
---|
| 639 | oss << setw(15) << "Observer:" << table_.keywordSet().asString("Observer") << endl;
|
---|
| 640 | oss << setw(15) << "Obs Date:" << getTime(-1,true) << endl;
|
---|
| 641 | table_.keywordSet().get("Project", tmp);
|
---|
| 642 | oss << setw(15) << "Project:" << tmp << endl;
|
---|
| 643 | table_.keywordSet().get("Obstype", tmp);
|
---|
| 644 | oss << setw(15) << "Obs. Type:" << tmp << endl;
|
---|
| 645 | table_.keywordSet().get("AntennaName", tmp);
|
---|
| 646 | oss << setw(15) << "Antenna Name:" << tmp << endl;
|
---|
| 647 | table_.keywordSet().get("FluxUnit", tmp);
|
---|
| 648 | oss << setw(15) << "Flux Unit:" << tmp << endl;
|
---|
| 649 | Vector<Float> vec;
|
---|
| 650 | oss << setw(15) << "Rest Freqs:";
|
---|
| 651 | if (vec.nelements() > 0) {
|
---|
| 652 | oss << setprecision(10) << vec << " [Hz]" << endl;
|
---|
| 653 | } else {
|
---|
| 654 | oss << "none" << endl;
|
---|
| 655 | }
|
---|
| 656 | oss << setw(15) << "Abcissa:" << "channel" << endl;
|
---|
| 657 | oss << selector_.print() << endl;
|
---|
| 658 | oss << endl;
|
---|
| 659 | // main table
|
---|
| 660 | String dirtype = "Position ("
|
---|
| 661 | + MDirection::showType(dirCol_.getMeasRef().getType())
|
---|
| 662 | + ")";
|
---|
| 663 | oss << setw(5) << "Scan"
|
---|
| 664 | << setw(15) << "Source"
|
---|
| 665 | // << setw(24) << dirtype
|
---|
| 666 | << setw(10) << "Time"
|
---|
| 667 | << setw(18) << "Integration" << endl
|
---|
| 668 | << setw(5) << "" << setw(10) << "Beam" << dirtype << endl
|
---|
| 669 | << setw(15) << "" << setw(5) << "IF"
|
---|
| 670 | << setw(8) << "Frame" << setw(16)
|
---|
| 671 | << "RefVal" << setw(10) << "RefPix" << setw(12) << "Increment" <<endl;
|
---|
| 672 | oss << asap::SEPERATOR << endl;
|
---|
| 673 | TableIterator iter(table_, "SCANNO");
|
---|
| 674 | while (!iter.pastEnd()) {
|
---|
| 675 | Table subt = iter.table();
|
---|
| 676 | ROTableRow row(subt);
|
---|
| 677 | MEpoch::ROScalarColumn timeCol(subt,"TIME");
|
---|
| 678 | const TableRecord& rec = row.get(0);
|
---|
| 679 | oss << setw(4) << std::right << rec.asuInt("SCANNO")
|
---|
| 680 | << std::left << setw(1) << ""
|
---|
| 681 | << setw(15) << rec.asString("SRCNAME")
|
---|
| 682 | << setw(10) << formatTime(timeCol(0), false);
|
---|
| 683 | // count the cycles in the scan
|
---|
| 684 | TableIterator cyciter(subt, "CYCLENO");
|
---|
| 685 | int nint = 0;
|
---|
| 686 | while (!cyciter.pastEnd()) {
|
---|
| 687 | ++nint;
|
---|
| 688 | ++cyciter;
|
---|
| 689 | }
|
---|
| 690 | oss << setw(3) << std::right << nint << setw(3) << " x " << std::left
|
---|
| 691 | << setw(6) << formatSec(rec.asFloat("INTERVAL")) << endl;
|
---|
[447] | 692 |
|
---|
[805] | 693 | TableIterator biter(subt, "BEAMNO");
|
---|
| 694 | while (!biter.pastEnd()) {
|
---|
| 695 | Table bsubt = biter.table();
|
---|
| 696 | ROTableRow brow(bsubt);
|
---|
| 697 | MDirection::ROScalarColumn bdirCol(bsubt,"DIRECTION");
|
---|
| 698 | const TableRecord& brec = brow.get(0);
|
---|
| 699 | oss << setw(6) << "" << setw(10) << brec.asuInt("BEAMNO");
|
---|
| 700 | oss << setw(24) << formatDirection(bdirCol(0)) << endl;
|
---|
| 701 | TableIterator iiter(bsubt, "IFNO");
|
---|
| 702 | while (!iiter.pastEnd()) {
|
---|
| 703 | Table isubt = iiter.table();
|
---|
| 704 | ROTableRow irow(isubt);
|
---|
| 705 | const TableRecord& irec = irow.get(0);
|
---|
| 706 | oss << std::right <<setw(8) << "" << std::left << irec.asuInt("IFNO");
|
---|
| 707 | oss << frequencies().print(irec.asuInt("FREQ_ID"));
|
---|
[447] | 708 |
|
---|
[805] | 709 | ++iiter;
|
---|
| 710 | }
|
---|
| 711 | ++biter;
|
---|
| 712 | }
|
---|
| 713 | ++iter;
|
---|
[447] | 714 | }
|
---|
[805] | 715 | /// @todo implement verbose mode
|
---|
| 716 | return String(oss);
|
---|
[447] | 717 | }
|
---|
| 718 |
|
---|
[805] | 719 | std::string Scantable::getTime(int whichrow, bool showdate) const
|
---|
[777] | 720 | {
|
---|
[805] | 721 | MEpoch::ROScalarColumn timeCol(table_, "TIME");
|
---|
| 722 | MEpoch me;
|
---|
| 723 | if (whichrow > -1) {
|
---|
| 724 | me = timeCol(uInt(whichrow));
|
---|
| 725 | } else {
|
---|
| 726 | Double tm;
|
---|
| 727 | table_.keywordSet().get("UTC",tm);
|
---|
| 728 | me = MEpoch(MVEpoch(tm));
|
---|
[777] | 729 | }
|
---|
[805] | 730 | return formatTime(me, showdate);
|
---|
[777] | 731 | }
|
---|
[805] | 732 |
|
---|
| 733 | }//namespace asap
|
---|