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