[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> |
---|
[902] | 30 | #include <casa/Utilities/GenSort.h> |
---|
[2] | 31 | |
---|
[80] | 32 | #include <tables/Tables/TableParse.h> |
---|
| 33 | #include <tables/Tables/TableDesc.h> |
---|
[488] | 34 | #include <tables/Tables/TableCopy.h> |
---|
[80] | 35 | #include <tables/Tables/SetupNewTab.h> |
---|
| 36 | #include <tables/Tables/ScaColDesc.h> |
---|
| 37 | #include <tables/Tables/ArrColDesc.h> |
---|
[805] | 38 | #include <tables/Tables/TableRow.h> |
---|
| 39 | #include <tables/Tables/TableVector.h> |
---|
| 40 | #include <tables/Tables/TableIter.h> |
---|
[2] | 41 | |
---|
[80] | 42 | #include <tables/Tables/ExprNode.h> |
---|
| 43 | #include <tables/Tables/TableRecord.h> |
---|
| 44 | #include <measures/Measures/MFrequency.h> |
---|
[805] | 45 | #include <measures/Measures/MEpoch.h> |
---|
[80] | 46 | #include <measures/Measures/MeasTable.h> |
---|
[805] | 47 | #include <measures/Measures/MeasRef.h> |
---|
| 48 | #include <measures/TableMeasures/TableMeasRefDesc.h> |
---|
| 49 | #include <measures/TableMeasures/TableMeasValueDesc.h> |
---|
| 50 | #include <measures/TableMeasures/TableMeasDesc.h> |
---|
| 51 | #include <measures/TableMeasures/ScalarMeasColumn.h> |
---|
[105] | 52 | #include <coordinates/Coordinates/CoordinateUtil.h> |
---|
[80] | 53 | #include <casa/Quanta/MVTime.h> |
---|
[281] | 54 | #include <casa/Quanta/MVAngle.h> |
---|
[2] | 55 | |
---|
[805] | 56 | #include "Scantable.h" |
---|
[896] | 57 | #include "STPolLinear.h" |
---|
[913] | 58 | #include "STPolStokes.h" |
---|
[878] | 59 | #include "STAttr.h" |
---|
[902] | 60 | #include "MathUtils.h" |
---|
[2] | 61 | |
---|
[125] | 62 | using namespace casa; |
---|
[2] | 63 | |
---|
[805] | 64 | namespace asap { |
---|
| 65 | |
---|
[896] | 66 | std::map<std::string, STPol::STPolFactory *> Scantable::factories_; |
---|
| 67 | |
---|
| 68 | void Scantable::initFactories() { |
---|
| 69 | if ( factories_.empty() ) { |
---|
| 70 | Scantable::factories_["linear"] = &STPolLinear::myFactory; |
---|
[913] | 71 | Scantable::factories_["stokes"] = &STPolStokes::myFactory; |
---|
[896] | 72 | } |
---|
| 73 | } |
---|
| 74 | |
---|
[805] | 75 | Scantable::Scantable(Table::TableType ttype) : |
---|
[852] | 76 | type_(ttype) |
---|
[206] | 77 | { |
---|
[896] | 78 | initFactories(); |
---|
[805] | 79 | setupMainTable(); |
---|
[852] | 80 | freqTable_ = STFrequencies(*this); |
---|
[805] | 81 | table_.rwKeywordSet().defineTable("FREQUENCIES", freqTable_.table()); |
---|
[852] | 82 | weatherTable_ = STWeather(*this); |
---|
[805] | 83 | table_.rwKeywordSet().defineTable("WEATHER", weatherTable_.table()); |
---|
[852] | 84 | focusTable_ = STFocus(*this); |
---|
[805] | 85 | table_.rwKeywordSet().defineTable("FOCUS", focusTable_.table()); |
---|
[852] | 86 | tcalTable_ = STTcal(*this); |
---|
[805] | 87 | table_.rwKeywordSet().defineTable("TCAL", tcalTable_.table()); |
---|
[852] | 88 | moleculeTable_ = STMolecules(*this); |
---|
[805] | 89 | table_.rwKeywordSet().defineTable("MOLECULES", moleculeTable_.table()); |
---|
[860] | 90 | historyTable_ = STHistory(*this); |
---|
| 91 | table_.rwKeywordSet().defineTable("HISTORY", historyTable_.table()); |
---|
[959] | 92 | fitTable_ = STFit(*this); |
---|
| 93 | table_.rwKeywordSet().defineTable("FIT", fitTable_.table()); |
---|
[805] | 94 | originalTable_ = table_; |
---|
[322] | 95 | attach(); |
---|
[18] | 96 | } |
---|
[206] | 97 | |
---|
[805] | 98 | Scantable::Scantable(const std::string& name, Table::TableType ttype) : |
---|
[852] | 99 | type_(ttype) |
---|
[206] | 100 | { |
---|
[896] | 101 | initFactories(); |
---|
[865] | 102 | Table tab(name, Table::Update); |
---|
[1009] | 103 | uInt version = tab.keywordSet().asuInt("VERSION"); |
---|
[483] | 104 | if (version != version_) { |
---|
| 105 | throw(AipsError("Unsupported version of ASAP file.")); |
---|
| 106 | } |
---|
[1009] | 107 | if ( type_ == Table::Memory ) { |
---|
[852] | 108 | table_ = tab.copyToMemoryTable(generateName()); |
---|
[1009] | 109 | } else { |
---|
[805] | 110 | table_ = tab; |
---|
[1009] | 111 | } |
---|
| 112 | |
---|
[859] | 113 | attachSubtables(); |
---|
[805] | 114 | originalTable_ = table_; |
---|
[329] | 115 | attach(); |
---|
[2] | 116 | } |
---|
| 117 | |
---|
[805] | 118 | Scantable::Scantable( const Scantable& other, bool clear ) |
---|
[206] | 119 | { |
---|
[805] | 120 | // with or without data |
---|
[859] | 121 | String newname = String(generateName()); |
---|
[865] | 122 | type_ = other.table_.tableType(); |
---|
[859] | 123 | if ( other.table_.tableType() == Table::Memory ) { |
---|
| 124 | if ( clear ) { |
---|
| 125 | table_ = TableCopy::makeEmptyMemoryTable(newname, |
---|
| 126 | other.table_, True); |
---|
| 127 | } else |
---|
| 128 | table_ = other.table_.copyToMemoryTable(newname); |
---|
[16] | 129 | } else { |
---|
[915] | 130 | other.table_.deepCopy(newname, Table::New, False, |
---|
| 131 | other.table_.endianFormat(), |
---|
[865] | 132 | Bool(clear)); |
---|
| 133 | table_ = Table(newname, Table::Update); |
---|
| 134 | table_.markForDelete(); |
---|
| 135 | } |
---|
[859] | 136 | |
---|
[915] | 137 | if ( clear ) copySubtables(other); |
---|
[859] | 138 | attachSubtables(); |
---|
[805] | 139 | originalTable_ = table_; |
---|
[322] | 140 | attach(); |
---|
[2] | 141 | } |
---|
| 142 | |
---|
[865] | 143 | void Scantable::copySubtables(const Scantable& other) { |
---|
| 144 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); |
---|
| 145 | TableCopy::copyRows(t, other.freqTable_.table()); |
---|
| 146 | t = table_.rwKeywordSet().asTable("FOCUS"); |
---|
| 147 | TableCopy::copyRows(t, other.focusTable_.table()); |
---|
| 148 | t = table_.rwKeywordSet().asTable("WEATHER"); |
---|
| 149 | TableCopy::copyRows(t, other.weatherTable_.table()); |
---|
| 150 | t = table_.rwKeywordSet().asTable("TCAL"); |
---|
| 151 | TableCopy::copyRows(t, other.tcalTable_.table()); |
---|
| 152 | t = table_.rwKeywordSet().asTable("MOLECULES"); |
---|
| 153 | TableCopy::copyRows(t, other.moleculeTable_.table()); |
---|
| 154 | t = table_.rwKeywordSet().asTable("HISTORY"); |
---|
| 155 | TableCopy::copyRows(t, other.historyTable_.table()); |
---|
[972] | 156 | t = table_.rwKeywordSet().asTable("FIT"); |
---|
| 157 | TableCopy::copyRows(t, other.fitTable_.table()); |
---|
[865] | 158 | } |
---|
| 159 | |
---|
[859] | 160 | void Scantable::attachSubtables() |
---|
| 161 | { |
---|
| 162 | freqTable_ = STFrequencies(table_); |
---|
| 163 | focusTable_ = STFocus(table_); |
---|
| 164 | weatherTable_ = STWeather(table_); |
---|
| 165 | tcalTable_ = STTcal(table_); |
---|
| 166 | moleculeTable_ = STMolecules(table_); |
---|
[860] | 167 | historyTable_ = STHistory(table_); |
---|
[972] | 168 | fitTable_ = STFit(table_); |
---|
[859] | 169 | } |
---|
| 170 | |
---|
[805] | 171 | Scantable::~Scantable() |
---|
[206] | 172 | { |
---|
[941] | 173 | //cout << "~Scantable() " << this << endl; |
---|
[2] | 174 | } |
---|
| 175 | |
---|
[805] | 176 | void Scantable::setupMainTable() |
---|
[206] | 177 | { |
---|
[805] | 178 | TableDesc td("", "1", TableDesc::Scratch); |
---|
| 179 | td.comment() = "An ASAP Scantable"; |
---|
[1009] | 180 | td.rwKeywordSet().define("VERSION", uInt(version_)); |
---|
[2] | 181 | |
---|
[805] | 182 | // n Cycles |
---|
| 183 | td.addColumn(ScalarColumnDesc<uInt>("SCANNO")); |
---|
| 184 | // new index every nBeam x nIF x nPol |
---|
| 185 | td.addColumn(ScalarColumnDesc<uInt>("CYCLENO")); |
---|
[2] | 186 | |
---|
[805] | 187 | td.addColumn(ScalarColumnDesc<uInt>("BEAMNO")); |
---|
| 188 | td.addColumn(ScalarColumnDesc<uInt>("IFNO")); |
---|
[972] | 189 | // linear, circular, stokes |
---|
[805] | 190 | td.rwKeywordSet().define("POLTYPE", String("linear")); |
---|
| 191 | td.addColumn(ScalarColumnDesc<uInt>("POLNO")); |
---|
[138] | 192 | |
---|
[805] | 193 | td.addColumn(ScalarColumnDesc<uInt>("FREQ_ID")); |
---|
| 194 | td.addColumn(ScalarColumnDesc<uInt>("MOLECULE_ID")); |
---|
| 195 | td.addColumn(ScalarColumnDesc<Int>("REFBEAMNO")); |
---|
[80] | 196 | |
---|
[805] | 197 | td.addColumn(ScalarColumnDesc<Double>("TIME")); |
---|
| 198 | TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default |
---|
| 199 | TableMeasValueDesc measVal(td, "TIME"); |
---|
| 200 | TableMeasDesc<MEpoch> mepochCol(measVal, measRef); |
---|
| 201 | mepochCol.write(td); |
---|
[483] | 202 | |
---|
[805] | 203 | td.addColumn(ScalarColumnDesc<Double>("INTERVAL")); |
---|
| 204 | |
---|
[2] | 205 | td.addColumn(ScalarColumnDesc<String>("SRCNAME")); |
---|
[805] | 206 | // Type of source (on=0, off=1, other=-1) |
---|
| 207 | td.addColumn(ScalarColumnDesc<Int>("SRCTYPE", Int(-1))); |
---|
| 208 | td.addColumn(ScalarColumnDesc<String>("FIELDNAME")); |
---|
| 209 | |
---|
| 210 | //The actual Data Vectors |
---|
[2] | 211 | td.addColumn(ArrayColumnDesc<Float>("SPECTRA")); |
---|
| 212 | td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA")); |
---|
[89] | 213 | td.addColumn(ArrayColumnDesc<Float>("TSYS")); |
---|
[805] | 214 | |
---|
| 215 | td.addColumn(ArrayColumnDesc<Double>("DIRECTION", |
---|
| 216 | IPosition(1,2), |
---|
| 217 | ColumnDesc::Direct)); |
---|
| 218 | TableMeasRefDesc mdirRef(MDirection::J2000); // default |
---|
| 219 | TableMeasValueDesc tmvdMDir(td, "DIRECTION"); |
---|
| 220 | // the TableMeasDesc gives the column a type |
---|
| 221 | TableMeasDesc<MDirection> mdirCol(tmvdMDir, mdirRef); |
---|
[987] | 222 | // a uder set table type e.g. GALCTIC, B1950 ... |
---|
| 223 | td.rwKeywordSet().define("DIRECTIONREF", String("J2000")); |
---|
[805] | 224 | // writing create the measure column |
---|
| 225 | mdirCol.write(td); |
---|
[923] | 226 | td.addColumn(ScalarColumnDesc<Float>("AZIMUTH")); |
---|
| 227 | td.addColumn(ScalarColumnDesc<Float>("ELEVATION")); |
---|
[105] | 228 | td.addColumn(ScalarColumnDesc<Float>("PARANGLE")); |
---|
[1048] | 229 | td.addColumn(ScalarColumnDesc<Float>("OPACITY")); |
---|
[105] | 230 | |
---|
[805] | 231 | td.addColumn(ScalarColumnDesc<uInt>("TCAL_ID")); |
---|
[972] | 232 | ScalarColumnDesc<Int> fitColumn("FIT_ID"); |
---|
[973] | 233 | fitColumn.setDefault(Int(-1)); |
---|
[972] | 234 | td.addColumn(fitColumn); |
---|
[805] | 235 | |
---|
| 236 | td.addColumn(ScalarColumnDesc<uInt>("FOCUS_ID")); |
---|
| 237 | td.addColumn(ScalarColumnDesc<uInt>("WEATHER_ID")); |
---|
| 238 | |
---|
[999] | 239 | // columns which just get dragged along, as they aren't used in asap |
---|
| 240 | td.addColumn(ScalarColumnDesc<Double>("SRCVELOCITY")); |
---|
| 241 | td.addColumn(ArrayColumnDesc<Double>("SRCPROPERMOTION")); |
---|
| 242 | td.addColumn(ArrayColumnDesc<Double>("SRCDIRECTION")); |
---|
| 243 | td.addColumn(ArrayColumnDesc<Double>("SCANRATE")); |
---|
| 244 | |
---|
[805] | 245 | td.rwKeywordSet().define("OBSMODE", String("")); |
---|
| 246 | |
---|
[418] | 247 | // Now create Table SetUp from the description. |
---|
[859] | 248 | SetupNewTable aNewTab(generateName(), td, Table::Scratch); |
---|
[852] | 249 | table_ = Table(aNewTab, type_, 0); |
---|
[805] | 250 | originalTable_ = table_; |
---|
| 251 | } |
---|
[418] | 252 | |
---|
[455] | 253 | |
---|
[805] | 254 | void Scantable::attach() |
---|
[455] | 255 | { |
---|
[805] | 256 | timeCol_.attach(table_, "TIME"); |
---|
| 257 | srcnCol_.attach(table_, "SRCNAME"); |
---|
| 258 | specCol_.attach(table_, "SPECTRA"); |
---|
| 259 | flagsCol_.attach(table_, "FLAGTRA"); |
---|
[865] | 260 | tsysCol_.attach(table_, "TSYS"); |
---|
[805] | 261 | cycleCol_.attach(table_,"CYCLENO"); |
---|
| 262 | scanCol_.attach(table_, "SCANNO"); |
---|
| 263 | beamCol_.attach(table_, "BEAMNO"); |
---|
[847] | 264 | ifCol_.attach(table_, "IFNO"); |
---|
| 265 | polCol_.attach(table_, "POLNO"); |
---|
[805] | 266 | integrCol_.attach(table_, "INTERVAL"); |
---|
| 267 | azCol_.attach(table_, "AZIMUTH"); |
---|
| 268 | elCol_.attach(table_, "ELEVATION"); |
---|
| 269 | dirCol_.attach(table_, "DIRECTION"); |
---|
| 270 | paraCol_.attach(table_, "PARANGLE"); |
---|
| 271 | fldnCol_.attach(table_, "FIELDNAME"); |
---|
| 272 | rbeamCol_.attach(table_, "REFBEAMNO"); |
---|
[455] | 273 | |
---|
[805] | 274 | mfitidCol_.attach(table_,"FIT_ID"); |
---|
| 275 | mfreqidCol_.attach(table_, "FREQ_ID"); |
---|
| 276 | mtcalidCol_.attach(table_, "TCAL_ID"); |
---|
| 277 | mfocusidCol_.attach(table_, "FOCUS_ID"); |
---|
| 278 | mmolidCol_.attach(table_, "MOLECULE_ID"); |
---|
[455] | 279 | } |
---|
| 280 | |
---|
[901] | 281 | void Scantable::setHeader(const STHeader& sdh) |
---|
[206] | 282 | { |
---|
[18] | 283 | table_.rwKeywordSet().define("nIF", sdh.nif); |
---|
| 284 | table_.rwKeywordSet().define("nBeam", sdh.nbeam); |
---|
| 285 | table_.rwKeywordSet().define("nPol", sdh.npol); |
---|
| 286 | table_.rwKeywordSet().define("nChan", sdh.nchan); |
---|
| 287 | table_.rwKeywordSet().define("Observer", sdh.observer); |
---|
| 288 | table_.rwKeywordSet().define("Project", sdh.project); |
---|
| 289 | table_.rwKeywordSet().define("Obstype", sdh.obstype); |
---|
| 290 | table_.rwKeywordSet().define("AntennaName", sdh.antennaname); |
---|
| 291 | table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition); |
---|
| 292 | table_.rwKeywordSet().define("Equinox", sdh.equinox); |
---|
| 293 | table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref); |
---|
| 294 | table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq); |
---|
| 295 | table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth); |
---|
| 296 | table_.rwKeywordSet().define("UTC", sdh.utc); |
---|
[206] | 297 | table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit); |
---|
| 298 | table_.rwKeywordSet().define("Epoch", sdh.epoch); |
---|
[905] | 299 | table_.rwKeywordSet().define("POLTYPE", sdh.poltype); |
---|
[50] | 300 | } |
---|
[21] | 301 | |
---|
[901] | 302 | STHeader Scantable::getHeader() const |
---|
[206] | 303 | { |
---|
[901] | 304 | STHeader sdh; |
---|
[21] | 305 | table_.keywordSet().get("nBeam",sdh.nbeam); |
---|
| 306 | table_.keywordSet().get("nIF",sdh.nif); |
---|
| 307 | table_.keywordSet().get("nPol",sdh.npol); |
---|
| 308 | table_.keywordSet().get("nChan",sdh.nchan); |
---|
| 309 | table_.keywordSet().get("Observer", sdh.observer); |
---|
| 310 | table_.keywordSet().get("Project", sdh.project); |
---|
| 311 | table_.keywordSet().get("Obstype", sdh.obstype); |
---|
| 312 | table_.keywordSet().get("AntennaName", sdh.antennaname); |
---|
| 313 | table_.keywordSet().get("AntennaPosition", sdh.antennaposition); |
---|
| 314 | table_.keywordSet().get("Equinox", sdh.equinox); |
---|
| 315 | table_.keywordSet().get("FreqRefFrame", sdh.freqref); |
---|
| 316 | table_.keywordSet().get("FreqRefVal", sdh.reffreq); |
---|
| 317 | table_.keywordSet().get("Bandwidth", sdh.bandwidth); |
---|
| 318 | table_.keywordSet().get("UTC", sdh.utc); |
---|
[206] | 319 | table_.keywordSet().get("FluxUnit", sdh.fluxunit); |
---|
| 320 | table_.keywordSet().get("Epoch", sdh.epoch); |
---|
[905] | 321 | table_.keywordSet().get("POLTYPE", sdh.poltype); |
---|
[21] | 322 | return sdh; |
---|
[18] | 323 | } |
---|
[805] | 324 | |
---|
[845] | 325 | bool Scantable::conformant( const Scantable& other ) |
---|
| 326 | { |
---|
| 327 | return this->getHeader().conformant(other.getHeader()); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | |
---|
[837] | 331 | int Scantable::nscan() const { |
---|
[902] | 332 | Vector<uInt> scannos(scanCol_.getColumn()); |
---|
| 333 | uInt nout = GenSort<uInt>::sort( scannos, Sort::Ascending, |
---|
| 334 | Sort::QuickSort|Sort::NoDuplicates ); |
---|
| 335 | return int(nout); |
---|
[50] | 336 | } |
---|
| 337 | |
---|
[805] | 338 | std::string Scantable::formatSec(Double x) const |
---|
[206] | 339 | { |
---|
[105] | 340 | Double xcop = x; |
---|
| 341 | MVTime mvt(xcop/24./3600.); // make days |
---|
[365] | 342 | |
---|
[105] | 343 | if (x < 59.95) |
---|
[281] | 344 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s"; |
---|
[745] | 345 | else if (x < 3599.95) |
---|
[281] | 346 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" "; |
---|
| 347 | else { |
---|
| 348 | ostringstream oss; |
---|
| 349 | oss << setw(2) << std::right << setprecision(1) << mvt.hour(); |
---|
| 350 | oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " "; |
---|
| 351 | return String(oss); |
---|
[745] | 352 | } |
---|
[105] | 353 | }; |
---|
| 354 | |
---|
[805] | 355 | std::string Scantable::formatDirection(const MDirection& md) const |
---|
[281] | 356 | { |
---|
| 357 | Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue(); |
---|
| 358 | Int prec = 7; |
---|
| 359 | |
---|
| 360 | MVAngle mvLon(t[0]); |
---|
| 361 | String sLon = mvLon.string(MVAngle::TIME,prec); |
---|
[987] | 362 | uInt tp = md.getRef().getType(); |
---|
| 363 | if (tp == MDirection::GALACTIC || |
---|
| 364 | tp == MDirection::SUPERGAL ) { |
---|
| 365 | sLon = mvLon(0.0).string(MVAngle::ANGLE_CLEAN,prec); |
---|
| 366 | } |
---|
[281] | 367 | MVAngle mvLat(t[1]); |
---|
| 368 | String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec); |
---|
[380] | 369 | return sLon + String(" ") + sLat; |
---|
[281] | 370 | } |
---|
| 371 | |
---|
| 372 | |
---|
[805] | 373 | std::string Scantable::getFluxUnit() const |
---|
[206] | 374 | { |
---|
[847] | 375 | return table_.keywordSet().asString("FluxUnit"); |
---|
[206] | 376 | } |
---|
| 377 | |
---|
[805] | 378 | void Scantable::setFluxUnit(const std::string& unit) |
---|
[218] | 379 | { |
---|
| 380 | String tmp(unit); |
---|
| 381 | Unit tU(tmp); |
---|
| 382 | if (tU==Unit("K") || tU==Unit("Jy")) { |
---|
| 383 | table_.rwKeywordSet().define(String("FluxUnit"), tmp); |
---|
| 384 | } else { |
---|
| 385 | throw AipsError("Illegal unit - must be compatible with Jy or K"); |
---|
| 386 | } |
---|
| 387 | } |
---|
| 388 | |
---|
[805] | 389 | void Scantable::setInstrument(const std::string& name) |
---|
[236] | 390 | { |
---|
[805] | 391 | bool throwIt = true; |
---|
[996] | 392 | // create an Instrument to see if this is valid |
---|
| 393 | STAttr::convertInstrument(name, throwIt); |
---|
[236] | 394 | String nameU(name); |
---|
| 395 | nameU.upcase(); |
---|
| 396 | table_.rwKeywordSet().define(String("AntennaName"), nameU); |
---|
| 397 | } |
---|
| 398 | |
---|
[805] | 399 | MPosition Scantable::getAntennaPosition () const |
---|
| 400 | { |
---|
| 401 | Vector<Double> antpos; |
---|
| 402 | table_.keywordSet().get("AntennaPosition", antpos); |
---|
| 403 | MVPosition mvpos(antpos(0),antpos(1),antpos(2)); |
---|
| 404 | return MPosition(mvpos); |
---|
| 405 | } |
---|
[281] | 406 | |
---|
[805] | 407 | void Scantable::makePersistent(const std::string& filename) |
---|
| 408 | { |
---|
| 409 | String inname(filename); |
---|
| 410 | Path path(inname); |
---|
| 411 | inname = path.expandedName(); |
---|
| 412 | table_.deepCopy(inname, Table::New); |
---|
| 413 | } |
---|
| 414 | |
---|
[837] | 415 | int Scantable::nbeam( int scanno ) const |
---|
[805] | 416 | { |
---|
| 417 | if ( scanno < 0 ) { |
---|
| 418 | Int n; |
---|
| 419 | table_.keywordSet().get("nBeam",n); |
---|
| 420 | return int(n); |
---|
[105] | 421 | } else { |
---|
[805] | 422 | // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these |
---|
[888] | 423 | Table t = table_(table_.col("SCANNO") == scanno); |
---|
| 424 | ROTableRow row(t); |
---|
| 425 | const TableRecord& rec = row.get(0); |
---|
| 426 | Table subt = t( t.col("IFNO") == Int(rec.asuInt("IFNO")) |
---|
| 427 | && t.col("POLNO") == Int(rec.asuInt("POLNO")) |
---|
| 428 | && t.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) ); |
---|
| 429 | ROTableVector<uInt> v(subt, "BEAMNO"); |
---|
[805] | 430 | return int(v.nelements()); |
---|
[105] | 431 | } |
---|
[805] | 432 | return 0; |
---|
| 433 | } |
---|
[455] | 434 | |
---|
[837] | 435 | int Scantable::nif( int scanno ) const |
---|
[805] | 436 | { |
---|
| 437 | if ( scanno < 0 ) { |
---|
| 438 | Int n; |
---|
| 439 | table_.keywordSet().get("nIF",n); |
---|
| 440 | return int(n); |
---|
| 441 | } else { |
---|
| 442 | // take the first POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these |
---|
[888] | 443 | Table t = table_(table_.col("SCANNO") == scanno); |
---|
| 444 | ROTableRow row(t); |
---|
| 445 | const TableRecord& rec = row.get(0); |
---|
| 446 | Table subt = t( t.col("BEAMNO") == Int(rec.asuInt("BEAMNO")) |
---|
| 447 | && t.col("POLNO") == Int(rec.asuInt("POLNO")) |
---|
| 448 | && t.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) ); |
---|
| 449 | if ( subt.nrow() == 0 ) return 0; |
---|
| 450 | ROTableVector<uInt> v(subt, "IFNO"); |
---|
[805] | 451 | return int(v.nelements()); |
---|
[2] | 452 | } |
---|
[805] | 453 | return 0; |
---|
| 454 | } |
---|
[321] | 455 | |
---|
[837] | 456 | int Scantable::npol( int scanno ) const |
---|
[805] | 457 | { |
---|
| 458 | if ( scanno < 0 ) { |
---|
| 459 | Int n; |
---|
| 460 | table_.keywordSet().get("nPol",n); |
---|
| 461 | return n; |
---|
| 462 | } else { |
---|
| 463 | // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these |
---|
[888] | 464 | Table t = table_(table_.col("SCANNO") == scanno); |
---|
| 465 | ROTableRow row(t); |
---|
| 466 | const TableRecord& rec = row.get(0); |
---|
| 467 | Table subt = t( t.col("BEAMNO") == Int(rec.asuInt("BEAMNO")) |
---|
| 468 | && t.col("IFNO") == Int(rec.asuInt("IFNO")) |
---|
| 469 | && t.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) ); |
---|
| 470 | if ( subt.nrow() == 0 ) return 0; |
---|
| 471 | ROTableVector<uInt> v(subt, "POLNO"); |
---|
[805] | 472 | return int(v.nelements()); |
---|
[321] | 473 | } |
---|
[805] | 474 | return 0; |
---|
[2] | 475 | } |
---|
[805] | 476 | |
---|
[845] | 477 | int Scantable::ncycle( int scanno ) const |
---|
[206] | 478 | { |
---|
[805] | 479 | if ( scanno < 0 ) { |
---|
[837] | 480 | Block<String> cols(2); |
---|
| 481 | cols[0] = "SCANNO"; |
---|
| 482 | cols[1] = "CYCLENO"; |
---|
| 483 | TableIterator it(table_, cols); |
---|
| 484 | int n = 0; |
---|
| 485 | while ( !it.pastEnd() ) { |
---|
| 486 | ++n; |
---|
[902] | 487 | ++it; |
---|
[837] | 488 | } |
---|
| 489 | return n; |
---|
[805] | 490 | } else { |
---|
[888] | 491 | Table t = table_(table_.col("SCANNO") == scanno); |
---|
| 492 | ROTableRow row(t); |
---|
| 493 | const TableRecord& rec = row.get(0); |
---|
| 494 | Table subt = t( t.col("BEAMNO") == Int(rec.asuInt("BEAMNO")) |
---|
| 495 | && t.col("POLNO") == Int(rec.asuInt("POLNO")) |
---|
| 496 | && t.col("IFNO") == Int(rec.asuInt("IFNO")) ); |
---|
| 497 | if ( subt.nrow() == 0 ) return 0; |
---|
| 498 | return int(subt.nrow()); |
---|
[805] | 499 | } |
---|
| 500 | return 0; |
---|
[18] | 501 | } |
---|
[455] | 502 | |
---|
| 503 | |
---|
[845] | 504 | int Scantable::nrow( int scanno ) const |
---|
[805] | 505 | { |
---|
[845] | 506 | return int(table_.nrow()); |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | int Scantable::nchan( int ifno ) const |
---|
| 510 | { |
---|
| 511 | if ( ifno < 0 ) { |
---|
[805] | 512 | Int n; |
---|
| 513 | table_.keywordSet().get("nChan",n); |
---|
| 514 | return int(n); |
---|
| 515 | } else { |
---|
[845] | 516 | // take the first SCANNO,POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these |
---|
[888] | 517 | Table t = table_(table_.col("IFNO") == ifno); |
---|
| 518 | if ( t.nrow() == 0 ) return 0; |
---|
| 519 | ROArrayColumn<Float> v(t, "SPECTRA"); |
---|
[923] | 520 | return v.shape(0)(0); |
---|
[805] | 521 | } |
---|
| 522 | return 0; |
---|
[18] | 523 | } |
---|
[455] | 524 | |
---|
[923] | 525 | int Scantable::getChannels(int whichrow) const |
---|
| 526 | { |
---|
| 527 | return specCol_.shape(whichrow)(0); |
---|
| 528 | } |
---|
[847] | 529 | |
---|
| 530 | int Scantable::getBeam(int whichrow) const |
---|
| 531 | { |
---|
| 532 | return beamCol_(whichrow); |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | int Scantable::getIF(int whichrow) const |
---|
| 536 | { |
---|
| 537 | return ifCol_(whichrow); |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | int Scantable::getPol(int whichrow) const |
---|
| 541 | { |
---|
| 542 | return polCol_(whichrow); |
---|
| 543 | } |
---|
| 544 | |
---|
[805] | 545 | std::string Scantable::formatTime(const MEpoch& me, bool showdate) const |
---|
| 546 | { |
---|
| 547 | MVTime mvt(me.getValue()); |
---|
| 548 | if (showdate) |
---|
| 549 | mvt.setFormat(MVTime::YMD); |
---|
| 550 | else |
---|
| 551 | mvt.setFormat(MVTime::TIME); |
---|
| 552 | ostringstream oss; |
---|
| 553 | oss << mvt; |
---|
| 554 | return String(oss); |
---|
| 555 | } |
---|
[488] | 556 | |
---|
[805] | 557 | void Scantable::calculateAZEL() |
---|
| 558 | { |
---|
| 559 | MPosition mp = getAntennaPosition(); |
---|
| 560 | MEpoch::ROScalarColumn timeCol(table_, "TIME"); |
---|
| 561 | ostringstream oss; |
---|
| 562 | oss << "Computed azimuth/elevation using " << endl |
---|
| 563 | << mp << endl; |
---|
[996] | 564 | for (Int i=0; i<nrow(); ++i) { |
---|
[805] | 565 | MEpoch me = timeCol(i); |
---|
[987] | 566 | MDirection md = getDirection(i); |
---|
[805] | 567 | oss << " Time: " << formatTime(me,False) << " Direction: " << formatDirection(md) |
---|
| 568 | << endl << " => "; |
---|
| 569 | MeasFrame frame(mp, me); |
---|
| 570 | Vector<Double> azel = |
---|
| 571 | MDirection::Convert(md, MDirection::Ref(MDirection::AZEL, |
---|
| 572 | frame) |
---|
| 573 | )().getAngle("rad").getValue(); |
---|
[923] | 574 | azCol_.put(i,Float(azel[0])); |
---|
| 575 | elCol_.put(i,Float(azel[1])); |
---|
[805] | 576 | oss << "azel: " << azel[0]/C::pi*180.0 << " " |
---|
| 577 | << azel[1]/C::pi*180.0 << " (deg)" << endl; |
---|
[16] | 578 | } |
---|
[805] | 579 | pushLog(String(oss)); |
---|
| 580 | } |
---|
[89] | 581 | |
---|
[1000] | 582 | void Scantable::flag(const std::vector<bool>& msk) |
---|
[865] | 583 | { |
---|
[1026] | 584 | if ( selector_.empty() && msk.size() == 0 ) |
---|
[1000] | 585 | throw(AipsError("Trying to flag whole scantable.")); |
---|
| 586 | if ( msk.size() == 0 ) { |
---|
| 587 | uChar userflag = 1 << 7; |
---|
| 588 | for ( uInt i=0; i<table_.nrow(); ++i) { |
---|
| 589 | Vector<uChar> flgs = flagsCol_(i); |
---|
| 590 | flgs = userflag; |
---|
| 591 | flagsCol_.put(i, flgs); |
---|
| 592 | } |
---|
| 593 | return; |
---|
| 594 | } |
---|
| 595 | if ( int(msk.size()) != nchan() ) { |
---|
| 596 | throw(AipsError("Mask has incorrect number of channels.")); |
---|
| 597 | } |
---|
| 598 | for ( uInt i=0; i<table_.nrow(); ++i) { |
---|
| 599 | Vector<uChar> flgs = flagsCol_(i); |
---|
| 600 | if ( flgs.nelements() != msk.size() ) { |
---|
| 601 | throw(AipsError("Mask has incorrect number of channels." |
---|
| 602 | " Probably varying with IF. Please flag per IF")); |
---|
| 603 | } |
---|
| 604 | std::vector<bool>::const_iterator it; |
---|
| 605 | uInt j = 0; |
---|
| 606 | uChar userflag = 1 << 7; |
---|
| 607 | for (it = msk.begin(); it != msk.end(); ++it) { |
---|
| 608 | if ( *it ) { |
---|
| 609 | flgs(j) = userflag; |
---|
| 610 | } |
---|
| 611 | ++j; |
---|
| 612 | } |
---|
| 613 | flagsCol_.put(i, flgs); |
---|
| 614 | } |
---|
[865] | 615 | } |
---|
| 616 | |
---|
[805] | 617 | std::vector<bool> Scantable::getMask(int whichrow) const |
---|
| 618 | { |
---|
| 619 | Vector<uChar> flags; |
---|
| 620 | flagsCol_.get(uInt(whichrow), flags); |
---|
| 621 | Vector<Bool> bflag(flags.shape()); |
---|
| 622 | convertArray(bflag, flags); |
---|
| 623 | bflag = !bflag; |
---|
| 624 | std::vector<bool> mask; |
---|
| 625 | bflag.tovector(mask); |
---|
| 626 | return mask; |
---|
| 627 | } |
---|
[89] | 628 | |
---|
[896] | 629 | std::vector<float> Scantable::getSpectrum( int whichrow, |
---|
[902] | 630 | const std::string& poltype ) const |
---|
[805] | 631 | { |
---|
[905] | 632 | String ptype = poltype; |
---|
| 633 | if (poltype == "" ) ptype = getPolType(); |
---|
[902] | 634 | if ( whichrow < 0 || whichrow >= nrow() ) |
---|
| 635 | throw(AipsError("Illegal row number.")); |
---|
[896] | 636 | std::vector<float> out; |
---|
[805] | 637 | Vector<Float> arr; |
---|
[896] | 638 | uInt requestedpol = polCol_(whichrow); |
---|
| 639 | String basetype = getPolType(); |
---|
[905] | 640 | if ( ptype == basetype ) { |
---|
[896] | 641 | specCol_.get(whichrow, arr); |
---|
| 642 | } else { |
---|
| 643 | STPol* stpol = 0; |
---|
| 644 | stpol =STPol::getPolClass(Scantable::factories_, basetype); |
---|
| 645 | try { |
---|
| 646 | uInt row = uInt(whichrow); |
---|
| 647 | stpol->setSpectra(getPolMatrix(row)); |
---|
[959] | 648 | Float fang,fhand,parang; |
---|
| 649 | fang = focusTable_.getTotalFeedAngle(mfocusidCol_(row)); |
---|
| 650 | fhand = focusTable_.getFeedHand(mfocusidCol_(row)); |
---|
| 651 | parang = paraCol_(row); |
---|
| 652 | /// @todo re-enable this |
---|
| 653 | // disable total feed angle to support paralactifying Caswell style |
---|
| 654 | stpol->setPhaseCorrections(parang, -parang, fhand); |
---|
[905] | 655 | arr = stpol->getSpectrum(requestedpol, ptype); |
---|
[896] | 656 | delete stpol; |
---|
| 657 | } catch (AipsError& e) { |
---|
| 658 | delete stpol; |
---|
| 659 | throw(e); |
---|
| 660 | } |
---|
| 661 | } |
---|
[902] | 662 | if ( arr.nelements() == 0 ) |
---|
| 663 | pushLog("Not enough polarisations present to do the conversion."); |
---|
[805] | 664 | arr.tovector(out); |
---|
| 665 | return out; |
---|
[89] | 666 | } |
---|
[212] | 667 | |
---|
[884] | 668 | void asap::Scantable::setSpectrum( const std::vector<float>& spec, |
---|
| 669 | int whichrow ) |
---|
| 670 | { |
---|
| 671 | Vector<Float> spectrum(spec); |
---|
| 672 | Vector<Float> arr; |
---|
| 673 | specCol_.get(whichrow, arr); |
---|
| 674 | if ( spectrum.nelements() != arr.nelements() ) |
---|
[896] | 675 | throw AipsError("The spectrum has incorrect number of channels."); |
---|
[884] | 676 | specCol_.put(whichrow, spectrum); |
---|
| 677 | } |
---|
| 678 | |
---|
| 679 | |
---|
[805] | 680 | String Scantable::generateName() |
---|
[745] | 681 | { |
---|
[805] | 682 | return (File::newUniqueName("./","temp")).baseName(); |
---|
[212] | 683 | } |
---|
| 684 | |
---|
[805] | 685 | const casa::Table& Scantable::table( ) const |
---|
[212] | 686 | { |
---|
[805] | 687 | return table_; |
---|
[212] | 688 | } |
---|
| 689 | |
---|
[805] | 690 | casa::Table& Scantable::table( ) |
---|
[386] | 691 | { |
---|
[805] | 692 | return table_; |
---|
[386] | 693 | } |
---|
| 694 | |
---|
[896] | 695 | std::string Scantable::getPolType() const |
---|
| 696 | { |
---|
| 697 | return table_.keywordSet().asString("POLTYPE"); |
---|
| 698 | } |
---|
| 699 | |
---|
[805] | 700 | void Scantable::unsetSelection() |
---|
[380] | 701 | { |
---|
[805] | 702 | table_ = originalTable_; |
---|
[847] | 703 | attach(); |
---|
[805] | 704 | selector_.reset(); |
---|
[380] | 705 | } |
---|
[386] | 706 | |
---|
[805] | 707 | void Scantable::setSelection( const STSelector& selection ) |
---|
[430] | 708 | { |
---|
[805] | 709 | Table tab = const_cast<STSelector&>(selection).apply(originalTable_); |
---|
| 710 | if ( tab.nrow() == 0 ) { |
---|
| 711 | throw(AipsError("Selection contains no data. Not applying it.")); |
---|
| 712 | } |
---|
| 713 | table_ = tab; |
---|
[847] | 714 | attach(); |
---|
[805] | 715 | selector_ = selection; |
---|
[430] | 716 | } |
---|
| 717 | |
---|
[837] | 718 | std::string Scantable::summary( bool verbose ) |
---|
[447] | 719 | { |
---|
[805] | 720 | // Format header info |
---|
| 721 | ostringstream oss; |
---|
| 722 | oss << endl; |
---|
| 723 | oss << asap::SEPERATOR << endl; |
---|
| 724 | oss << " Scan Table Summary" << endl; |
---|
| 725 | oss << asap::SEPERATOR << endl; |
---|
| 726 | oss.flags(std::ios_base::left); |
---|
| 727 | oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl |
---|
| 728 | << setw(15) << "IFs:" << setw(4) << nif() << endl |
---|
[896] | 729 | << setw(15) << "Polarisations:" << setw(4) << npol() |
---|
| 730 | << "(" << getPolType() << ")" << endl |
---|
[805] | 731 | << setw(15) << "Channels:" << setw(4) << nchan() << endl; |
---|
| 732 | oss << endl; |
---|
| 733 | String tmp; |
---|
[860] | 734 | oss << setw(15) << "Observer:" |
---|
| 735 | << table_.keywordSet().asString("Observer") << endl; |
---|
[805] | 736 | oss << setw(15) << "Obs Date:" << getTime(-1,true) << endl; |
---|
| 737 | table_.keywordSet().get("Project", tmp); |
---|
| 738 | oss << setw(15) << "Project:" << tmp << endl; |
---|
| 739 | table_.keywordSet().get("Obstype", tmp); |
---|
| 740 | oss << setw(15) << "Obs. Type:" << tmp << endl; |
---|
| 741 | table_.keywordSet().get("AntennaName", tmp); |
---|
| 742 | oss << setw(15) << "Antenna Name:" << tmp << endl; |
---|
| 743 | table_.keywordSet().get("FluxUnit", tmp); |
---|
| 744 | oss << setw(15) << "Flux Unit:" << tmp << endl; |
---|
[941] | 745 | Vector<Double> vec(moleculeTable_.getRestFrequencies()); |
---|
[805] | 746 | oss << setw(15) << "Rest Freqs:"; |
---|
| 747 | if (vec.nelements() > 0) { |
---|
| 748 | oss << setprecision(10) << vec << " [Hz]" << endl; |
---|
| 749 | } else { |
---|
| 750 | oss << "none" << endl; |
---|
| 751 | } |
---|
[941] | 752 | |
---|
| 753 | oss << setw(15) << "Abcissa:" << getAbcissaLabel(0) << endl; |
---|
[805] | 754 | oss << selector_.print() << endl; |
---|
| 755 | oss << endl; |
---|
| 756 | // main table |
---|
| 757 | String dirtype = "Position (" |
---|
[987] | 758 | + getDirectionRefString() |
---|
[805] | 759 | + ")"; |
---|
[941] | 760 | oss << setw(5) << "Scan" << setw(15) << "Source" |
---|
| 761 | << setw(10) << "Time" << setw(18) << "Integration" << endl; |
---|
| 762 | oss << setw(5) << "" << setw(5) << "Beam" << setw(3) << "" << dirtype << endl; |
---|
| 763 | oss << setw(10) << "" << setw(3) << "IF" << setw(6) << "" |
---|
[805] | 764 | << setw(8) << "Frame" << setw(16) |
---|
| 765 | << "RefVal" << setw(10) << "RefPix" << setw(12) << "Increment" <<endl; |
---|
| 766 | oss << asap::SEPERATOR << endl; |
---|
| 767 | TableIterator iter(table_, "SCANNO"); |
---|
| 768 | while (!iter.pastEnd()) { |
---|
| 769 | Table subt = iter.table(); |
---|
| 770 | ROTableRow row(subt); |
---|
| 771 | MEpoch::ROScalarColumn timeCol(subt,"TIME"); |
---|
| 772 | const TableRecord& rec = row.get(0); |
---|
| 773 | oss << setw(4) << std::right << rec.asuInt("SCANNO") |
---|
| 774 | << std::left << setw(1) << "" |
---|
| 775 | << setw(15) << rec.asString("SRCNAME") |
---|
| 776 | << setw(10) << formatTime(timeCol(0), false); |
---|
| 777 | // count the cycles in the scan |
---|
| 778 | TableIterator cyciter(subt, "CYCLENO"); |
---|
| 779 | int nint = 0; |
---|
| 780 | while (!cyciter.pastEnd()) { |
---|
| 781 | ++nint; |
---|
| 782 | ++cyciter; |
---|
| 783 | } |
---|
| 784 | oss << setw(3) << std::right << nint << setw(3) << " x " << std::left |
---|
| 785 | << setw(6) << formatSec(rec.asFloat("INTERVAL")) << endl; |
---|
[447] | 786 | |
---|
[805] | 787 | TableIterator biter(subt, "BEAMNO"); |
---|
| 788 | while (!biter.pastEnd()) { |
---|
| 789 | Table bsubt = biter.table(); |
---|
| 790 | ROTableRow brow(bsubt); |
---|
| 791 | const TableRecord& brec = brow.get(0); |
---|
[1000] | 792 | uInt row0 = bsubt.rowNumbers(table_)[0]; |
---|
[941] | 793 | oss << setw(5) << "" << setw(4) << std::right << brec.asuInt("BEAMNO")<< std::left; |
---|
[987] | 794 | oss << setw(4) << "" << formatDirection(getDirection(row0)) << endl; |
---|
[805] | 795 | TableIterator iiter(bsubt, "IFNO"); |
---|
| 796 | while (!iiter.pastEnd()) { |
---|
| 797 | Table isubt = iiter.table(); |
---|
| 798 | ROTableRow irow(isubt); |
---|
| 799 | const TableRecord& irec = irow.get(0); |
---|
[941] | 800 | oss << setw(10) << ""; |
---|
| 801 | oss << setw(3) << std::right << irec.asuInt("IFNO") << std::left |
---|
| 802 | << setw(2) << "" << frequencies().print(irec.asuInt("FREQ_ID")); |
---|
[447] | 803 | |
---|
[805] | 804 | ++iiter; |
---|
| 805 | } |
---|
| 806 | ++biter; |
---|
| 807 | } |
---|
| 808 | ++iter; |
---|
[447] | 809 | } |
---|
[805] | 810 | /// @todo implement verbose mode |
---|
| 811 | return String(oss); |
---|
[447] | 812 | } |
---|
| 813 | |
---|
[805] | 814 | std::string Scantable::getTime(int whichrow, bool showdate) const |
---|
[777] | 815 | { |
---|
[805] | 816 | MEpoch::ROScalarColumn timeCol(table_, "TIME"); |
---|
| 817 | MEpoch me; |
---|
| 818 | if (whichrow > -1) { |
---|
| 819 | me = timeCol(uInt(whichrow)); |
---|
| 820 | } else { |
---|
| 821 | Double tm; |
---|
| 822 | table_.keywordSet().get("UTC",tm); |
---|
| 823 | me = MEpoch(MVEpoch(tm)); |
---|
[777] | 824 | } |
---|
[805] | 825 | return formatTime(me, showdate); |
---|
[777] | 826 | } |
---|
[805] | 827 | |
---|
[865] | 828 | std::vector< double > asap::Scantable::getAbcissa( int whichrow ) const |
---|
| 829 | { |
---|
[996] | 830 | if ( whichrow > int(table_.nrow()) ) throw(AipsError("Illegal ro number")); |
---|
[865] | 831 | std::vector<double> stlout; |
---|
| 832 | int nchan = specCol_(whichrow).nelements(); |
---|
| 833 | String us = freqTable_.getUnitString(); |
---|
| 834 | if ( us == "" || us == "pixel" || us == "channel" ) { |
---|
| 835 | for (int i=0; i<nchan; ++i) { |
---|
| 836 | stlout.push_back(double(i)); |
---|
| 837 | } |
---|
| 838 | return stlout; |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | const MPosition& mp = getAntennaPosition(); |
---|
[987] | 842 | const MDirection& md = getDirection(whichrow); |
---|
[865] | 843 | const MEpoch& me = timeCol_(whichrow); |
---|
| 844 | Double rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow)); |
---|
| 845 | SpectralCoordinate spc = |
---|
| 846 | freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow)); |
---|
| 847 | Vector<Double> pixel(nchan); |
---|
| 848 | Vector<Double> world; |
---|
| 849 | indgen(pixel); |
---|
| 850 | if ( Unit(us) == Unit("Hz") ) { |
---|
| 851 | for ( int i=0; i < nchan; ++i) { |
---|
| 852 | Double world; |
---|
| 853 | spc.toWorld(world, pixel[i]); |
---|
| 854 | stlout.push_back(double(world)); |
---|
| 855 | } |
---|
| 856 | } else if ( Unit(us) == Unit("km/s") ) { |
---|
| 857 | Vector<Double> world; |
---|
| 858 | spc.pixelToVelocity(world, pixel); |
---|
| 859 | world.tovector(stlout); |
---|
| 860 | } |
---|
| 861 | return stlout; |
---|
| 862 | } |
---|
[987] | 863 | void asap::Scantable::setDirectionRefString( const std::string & refstr ) |
---|
| 864 | { |
---|
| 865 | MDirection::Types mdt; |
---|
| 866 | if (refstr != "" && !MDirection::getType(mdt, refstr)) { |
---|
| 867 | throw(AipsError("Illegal Direction frame.")); |
---|
| 868 | } |
---|
| 869 | if ( refstr == "" ) { |
---|
| 870 | String defaultstr = MDirection::showType(dirCol_.getMeasRef().getType()); |
---|
| 871 | table_.rwKeywordSet().define("DIRECTIONREF", defaultstr); |
---|
| 872 | } else { |
---|
| 873 | table_.rwKeywordSet().define("DIRECTIONREF", String(refstr)); |
---|
| 874 | } |
---|
| 875 | } |
---|
[865] | 876 | |
---|
[987] | 877 | std::string asap::Scantable::getDirectionRefString( ) const |
---|
| 878 | { |
---|
| 879 | return table_.keywordSet().asString("DIRECTIONREF"); |
---|
| 880 | } |
---|
| 881 | |
---|
| 882 | MDirection Scantable::getDirection(int whichrow ) const |
---|
| 883 | { |
---|
| 884 | String usertype = table_.keywordSet().asString("DIRECTIONREF"); |
---|
| 885 | String type = MDirection::showType(dirCol_.getMeasRef().getType()); |
---|
| 886 | if ( usertype != type ) { |
---|
| 887 | MDirection::Types mdt; |
---|
| 888 | if (!MDirection::getType(mdt, usertype)) { |
---|
| 889 | throw(AipsError("Illegal Direction frame.")); |
---|
| 890 | } |
---|
| 891 | return dirCol_.convert(uInt(whichrow), mdt); |
---|
| 892 | } else { |
---|
| 893 | return dirCol_(uInt(whichrow)); |
---|
| 894 | } |
---|
| 895 | } |
---|
| 896 | |
---|
[847] | 897 | std::string Scantable::getAbcissaLabel( int whichrow ) const |
---|
| 898 | { |
---|
[996] | 899 | if ( whichrow > int(table_.nrow()) ) throw(AipsError("Illegal ro number")); |
---|
[847] | 900 | const MPosition& mp = getAntennaPosition(); |
---|
[987] | 901 | const MDirection& md = getDirection(whichrow); |
---|
[847] | 902 | const MEpoch& me = timeCol_(whichrow); |
---|
| 903 | const Double& rf = mmolidCol_(whichrow); |
---|
| 904 | SpectralCoordinate spc = |
---|
| 905 | freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow)); |
---|
| 906 | |
---|
| 907 | String s = "Channel"; |
---|
| 908 | Unit u = Unit(freqTable_.getUnitString()); |
---|
| 909 | if (u == Unit("km/s")) { |
---|
| 910 | s = CoordinateUtil::axisLabel(spc,0,True,True,True); |
---|
| 911 | } else if (u == Unit("Hz")) { |
---|
| 912 | Vector<String> wau(1);wau = u.getName(); |
---|
| 913 | spc.setWorldAxisUnits(wau); |
---|
| 914 | s = CoordinateUtil::axisLabel(spc,0,True,True,False); |
---|
| 915 | } |
---|
| 916 | return s; |
---|
| 917 | |
---|
| 918 | } |
---|
| 919 | |
---|
| 920 | void asap::Scantable::setRestFrequencies( double rf, const std::string& unit ) |
---|
| 921 | { |
---|
[923] | 922 | ///@todo lookup in line table to fill in name and formattedname |
---|
[847] | 923 | Unit u(unit); |
---|
| 924 | Quantum<Double> urf(rf, u); |
---|
| 925 | uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), "", ""); |
---|
| 926 | TableVector<uInt> tabvec(table_, "MOLECULE_ID"); |
---|
| 927 | tabvec = id; |
---|
| 928 | } |
---|
| 929 | |
---|
| 930 | void asap::Scantable::setRestFrequencies( const std::string& name ) |
---|
| 931 | { |
---|
| 932 | throw(AipsError("setRestFrequencies( const std::string& name ) NYI")); |
---|
| 933 | ///@todo implement |
---|
| 934 | } |
---|
| 935 | |
---|
[852] | 936 | std::vector< unsigned int > asap::Scantable::rownumbers( ) const |
---|
| 937 | { |
---|
| 938 | std::vector<unsigned int> stlout; |
---|
| 939 | Vector<uInt> vec = table_.rowNumbers(); |
---|
| 940 | vec.tovector(stlout); |
---|
| 941 | return stlout; |
---|
| 942 | } |
---|
| 943 | |
---|
[865] | 944 | |
---|
[896] | 945 | Matrix<Float> asap::Scantable::getPolMatrix( uInt whichrow ) const |
---|
| 946 | { |
---|
| 947 | ROTableRow row(table_); |
---|
| 948 | const TableRecord& rec = row.get(whichrow); |
---|
| 949 | Table t = |
---|
| 950 | originalTable_( originalTable_.col("SCANNO") == Int(rec.asuInt("SCANNO")) |
---|
| 951 | && originalTable_.col("BEAMNO") == Int(rec.asuInt("BEAMNO")) |
---|
| 952 | && originalTable_.col("IFNO") == Int(rec.asuInt("IFNO")) |
---|
| 953 | && originalTable_.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) ); |
---|
| 954 | ROArrayColumn<Float> speccol(t, "SPECTRA"); |
---|
| 955 | return speccol.getColumn(); |
---|
| 956 | } |
---|
[865] | 957 | |
---|
[902] | 958 | std::vector< std::string > asap::Scantable::columnNames( ) const |
---|
| 959 | { |
---|
| 960 | Vector<String> vec = table_.tableDesc().columnNames(); |
---|
| 961 | return mathutil::tovectorstring(vec); |
---|
| 962 | } |
---|
[896] | 963 | |
---|
[915] | 964 | casa::MEpoch::Types asap::Scantable::getTimeReference( ) const |
---|
| 965 | { |
---|
| 966 | return MEpoch::castType(timeCol_.getMeasRef().getType()); |
---|
[972] | 967 | } |
---|
[915] | 968 | |
---|
[972] | 969 | void asap::Scantable::addFit( const STFitEntry & fit, int row ) |
---|
| 970 | { |
---|
| 971 | cout << mfitidCol_(uInt(row)) << endl; |
---|
| 972 | uInt id = fitTable_.addEntry(fit, mfitidCol_(uInt(row))); |
---|
| 973 | mfitidCol_.put(uInt(row), id); |
---|
| 974 | } |
---|
[915] | 975 | |
---|
[987] | 976 | |
---|
| 977 | } |
---|
| 978 | //namespace asap |
---|