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