[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());
|
---|
[805] | 92 | setupFitTable();
|
---|
[852] | 93 | fitTable_ = table_.keywordSet().asTable("FITS");
|
---|
[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);
|
---|
[499] | 103 | Int version;
|
---|
[483] | 104 | tab.keywordSet().get("VERSION", version);
|
---|
| 105 | if (version != version_) {
|
---|
| 106 | throw(AipsError("Unsupported version of ASAP file."));
|
---|
| 107 | }
|
---|
[805] | 108 | if ( type_ == Table::Memory )
|
---|
[852] | 109 | table_ = tab.copyToMemoryTable(generateName());
|
---|
[805] | 110 | else
|
---|
| 111 | table_ = tab;
|
---|
[859] | 112 | attachSubtables();
|
---|
[805] | 113 | originalTable_ = table_;
|
---|
[329] | 114 | attach();
|
---|
[2] | 115 | }
|
---|
| 116 |
|
---|
[805] | 117 | Scantable::Scantable( const Scantable& other, bool clear )
|
---|
[206] | 118 | {
|
---|
[805] | 119 | // with or without data
|
---|
[859] | 120 | String newname = String(generateName());
|
---|
[865] | 121 | type_ = other.table_.tableType();
|
---|
[859] | 122 | if ( other.table_.tableType() == Table::Memory ) {
|
---|
| 123 | if ( clear ) {
|
---|
| 124 | table_ = TableCopy::makeEmptyMemoryTable(newname,
|
---|
| 125 | other.table_, True);
|
---|
| 126 | } else
|
---|
| 127 | table_ = other.table_.copyToMemoryTable(newname);
|
---|
[16] | 128 | } else {
|
---|
[915] | 129 | other.table_.deepCopy(newname, Table::New, False,
|
---|
| 130 | other.table_.endianFormat(),
|
---|
[865] | 131 | Bool(clear));
|
---|
| 132 | table_ = Table(newname, Table::Update);
|
---|
| 133 | table_.markForDelete();
|
---|
| 134 | }
|
---|
[859] | 135 |
|
---|
[915] | 136 | if ( clear ) copySubtables(other);
|
---|
[859] | 137 | attachSubtables();
|
---|
[805] | 138 | originalTable_ = table_;
|
---|
[322] | 139 | attach();
|
---|
[2] | 140 | }
|
---|
| 141 |
|
---|
[865] | 142 | void Scantable::copySubtables(const Scantable& other) {
|
---|
| 143 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
|
---|
| 144 | TableCopy::copyRows(t, other.freqTable_.table());
|
---|
| 145 | t = table_.rwKeywordSet().asTable("FOCUS");
|
---|
| 146 | TableCopy::copyRows(t, other.focusTable_.table());
|
---|
| 147 | t = table_.rwKeywordSet().asTable("WEATHER");
|
---|
| 148 | TableCopy::copyRows(t, other.weatherTable_.table());
|
---|
| 149 | t = table_.rwKeywordSet().asTable("TCAL");
|
---|
| 150 | TableCopy::copyRows(t, other.tcalTable_.table());
|
---|
| 151 | t = table_.rwKeywordSet().asTable("MOLECULES");
|
---|
| 152 | TableCopy::copyRows(t, other.moleculeTable_.table());
|
---|
| 153 | t = table_.rwKeywordSet().asTable("HISTORY");
|
---|
| 154 | TableCopy::copyRows(t, other.historyTable_.table());
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[859] | 157 | void Scantable::attachSubtables()
|
---|
| 158 | {
|
---|
| 159 | freqTable_ = STFrequencies(table_);
|
---|
| 160 | focusTable_ = STFocus(table_);
|
---|
| 161 | weatherTable_ = STWeather(table_);
|
---|
| 162 | tcalTable_ = STTcal(table_);
|
---|
| 163 | moleculeTable_ = STMolecules(table_);
|
---|
[860] | 164 | historyTable_ = STHistory(table_);
|
---|
[859] | 165 | }
|
---|
| 166 |
|
---|
[805] | 167 | Scantable::~Scantable()
|
---|
[206] | 168 | {
|
---|
[941] | 169 | //cout << "~Scantable() " << this << endl;
|
---|
[2] | 170 | }
|
---|
| 171 |
|
---|
[805] | 172 | void Scantable::setupMainTable()
|
---|
[206] | 173 | {
|
---|
[805] | 174 | TableDesc td("", "1", TableDesc::Scratch);
|
---|
| 175 | td.comment() = "An ASAP Scantable";
|
---|
| 176 | td.rwKeywordSet().define("VERSION", Int(version_));
|
---|
[2] | 177 |
|
---|
[805] | 178 | // n Cycles
|
---|
| 179 | td.addColumn(ScalarColumnDesc<uInt>("SCANNO"));
|
---|
| 180 | // new index every nBeam x nIF x nPol
|
---|
| 181 | td.addColumn(ScalarColumnDesc<uInt>("CYCLENO"));
|
---|
[2] | 182 |
|
---|
[805] | 183 | td.addColumn(ScalarColumnDesc<uInt>("BEAMNO"));
|
---|
| 184 | td.addColumn(ScalarColumnDesc<uInt>("IFNO"));
|
---|
| 185 | td.rwKeywordSet().define("POLTYPE", String("linear"));
|
---|
| 186 | td.addColumn(ScalarColumnDesc<uInt>("POLNO"));
|
---|
[138] | 187 |
|
---|
[805] | 188 | td.addColumn(ScalarColumnDesc<uInt>("FREQ_ID"));
|
---|
| 189 | td.addColumn(ScalarColumnDesc<uInt>("MOLECULE_ID"));
|
---|
| 190 | // linear, circular, stokes [I Q U V], stokes1 [I Plinear Pangle V]
|
---|
| 191 | td.addColumn(ScalarColumnDesc<Int>("REFBEAMNO"));
|
---|
[80] | 192 |
|
---|
[805] | 193 | td.addColumn(ScalarColumnDesc<Double>("TIME"));
|
---|
| 194 | TableMeasRefDesc measRef(MEpoch::UTC); // UTC as default
|
---|
| 195 | TableMeasValueDesc measVal(td, "TIME");
|
---|
| 196 | TableMeasDesc<MEpoch> mepochCol(measVal, measRef);
|
---|
| 197 | mepochCol.write(td);
|
---|
[483] | 198 |
|
---|
[805] | 199 | td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
|
---|
| 200 |
|
---|
[2] | 201 | td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
|
---|
[805] | 202 | // Type of source (on=0, off=1, other=-1)
|
---|
| 203 | td.addColumn(ScalarColumnDesc<Int>("SRCTYPE", Int(-1)));
|
---|
| 204 | td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
|
---|
| 205 |
|
---|
| 206 | //The actual Data Vectors
|
---|
[2] | 207 | td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
|
---|
| 208 | td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
|
---|
[89] | 209 | td.addColumn(ArrayColumnDesc<Float>("TSYS"));
|
---|
[805] | 210 |
|
---|
| 211 | td.addColumn(ArrayColumnDesc<Double>("DIRECTION",
|
---|
| 212 | IPosition(1,2),
|
---|
| 213 | ColumnDesc::Direct));
|
---|
| 214 | TableMeasRefDesc mdirRef(MDirection::J2000); // default
|
---|
| 215 | TableMeasValueDesc tmvdMDir(td, "DIRECTION");
|
---|
| 216 | // the TableMeasDesc gives the column a type
|
---|
| 217 | TableMeasDesc<MDirection> mdirCol(tmvdMDir, mdirRef);
|
---|
| 218 | // writing create the measure column
|
---|
| 219 | mdirCol.write(td);
|
---|
[923] | 220 | td.addColumn(ScalarColumnDesc<Float>("AZIMUTH"));
|
---|
| 221 | td.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
|
---|
[105] | 222 | td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
|
---|
| 223 |
|
---|
[805] | 224 | td.addColumn(ScalarColumnDesc<uInt>("TCAL_ID"));
|
---|
| 225 | td.addColumn(ScalarColumnDesc<uInt>("FIT_ID"));
|
---|
| 226 |
|
---|
| 227 | td.addColumn(ScalarColumnDesc<uInt>("FOCUS_ID"));
|
---|
| 228 | td.addColumn(ScalarColumnDesc<uInt>("WEATHER_ID"));
|
---|
| 229 |
|
---|
| 230 | td.rwKeywordSet().define("OBSMODE", String(""));
|
---|
| 231 |
|
---|
[418] | 232 | // Now create Table SetUp from the description.
|
---|
[859] | 233 | SetupNewTable aNewTab(generateName(), td, Table::Scratch);
|
---|
[852] | 234 | table_ = Table(aNewTab, type_, 0);
|
---|
[805] | 235 | originalTable_ = table_;
|
---|
[745] | 236 |
|
---|
[805] | 237 | }
|
---|
[418] | 238 |
|
---|
[805] | 239 | void Scantable::setupFitTable()
|
---|
[322] | 240 | {
|
---|
[39] | 241 | TableDesc td("", "1", TableDesc::Scratch);
|
---|
[805] | 242 | td.addColumn(ScalarColumnDesc<uInt>("FIT_ID"));
|
---|
[455] | 243 | td.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
|
---|
| 244 | td.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
|
---|
| 245 | td.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
|
---|
| 246 | td.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
|
---|
[465] | 247 | td.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
|
---|
[859] | 248 | SetupNewTable aNewTab("fits", td, Table::Scratch);
|
---|
[455] | 249 | Table aTable(aNewTab, Table::Memory);
|
---|
| 250 | table_.rwKeywordSet().defineTable("FITS", aTable);
|
---|
| 251 | }
|
---|
| 252 |
|
---|
[805] | 253 | void Scantable::attach()
|
---|
[455] | 254 | {
|
---|
[805] | 255 | timeCol_.attach(table_, "TIME");
|
---|
| 256 | srcnCol_.attach(table_, "SRCNAME");
|
---|
| 257 | specCol_.attach(table_, "SPECTRA");
|
---|
| 258 | flagsCol_.attach(table_, "FLAGTRA");
|
---|
[865] | 259 | tsysCol_.attach(table_, "TSYS");
|
---|
[805] | 260 | cycleCol_.attach(table_,"CYCLENO");
|
---|
| 261 | scanCol_.attach(table_, "SCANNO");
|
---|
| 262 | beamCol_.attach(table_, "BEAMNO");
|
---|
[847] | 263 | ifCol_.attach(table_, "IFNO");
|
---|
| 264 | polCol_.attach(table_, "POLNO");
|
---|
[805] | 265 | integrCol_.attach(table_, "INTERVAL");
|
---|
| 266 | azCol_.attach(table_, "AZIMUTH");
|
---|
| 267 | elCol_.attach(table_, "ELEVATION");
|
---|
| 268 | dirCol_.attach(table_, "DIRECTION");
|
---|
| 269 | paraCol_.attach(table_, "PARANGLE");
|
---|
| 270 | fldnCol_.attach(table_, "FIELDNAME");
|
---|
| 271 | rbeamCol_.attach(table_, "REFBEAMNO");
|
---|
[455] | 272 |
|
---|
[805] | 273 | mfitidCol_.attach(table_,"FIT_ID");
|
---|
[859] | 274 | //fitidCol_.attach(fitTable_,"FIT_ID");
|
---|
[465] | 275 |
|
---|
[805] | 276 | mfreqidCol_.attach(table_, "FREQ_ID");
|
---|
[465] | 277 |
|
---|
[805] | 278 | mtcalidCol_.attach(table_, "TCAL_ID");
|
---|
[465] | 279 |
|
---|
[805] | 280 | mfocusidCol_.attach(table_, "FOCUS_ID");
|
---|
[455] | 281 |
|
---|
[805] | 282 | mmolidCol_.attach(table_, "MOLECULE_ID");
|
---|
[455] | 283 | }
|
---|
| 284 |
|
---|
[901] | 285 | void Scantable::setHeader(const STHeader& sdh)
|
---|
[206] | 286 | {
|
---|
[18] | 287 | table_.rwKeywordSet().define("nIF", sdh.nif);
|
---|
| 288 | table_.rwKeywordSet().define("nBeam", sdh.nbeam);
|
---|
| 289 | table_.rwKeywordSet().define("nPol", sdh.npol);
|
---|
| 290 | table_.rwKeywordSet().define("nChan", sdh.nchan);
|
---|
| 291 | table_.rwKeywordSet().define("Observer", sdh.observer);
|
---|
| 292 | table_.rwKeywordSet().define("Project", sdh.project);
|
---|
| 293 | table_.rwKeywordSet().define("Obstype", sdh.obstype);
|
---|
| 294 | table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
|
---|
| 295 | table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
|
---|
| 296 | table_.rwKeywordSet().define("Equinox", sdh.equinox);
|
---|
| 297 | table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
|
---|
| 298 | table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
|
---|
| 299 | table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
|
---|
| 300 | table_.rwKeywordSet().define("UTC", sdh.utc);
|
---|
[206] | 301 | table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
|
---|
| 302 | table_.rwKeywordSet().define("Epoch", sdh.epoch);
|
---|
[905] | 303 | table_.rwKeywordSet().define("POLTYPE", sdh.poltype);
|
---|
[50] | 304 | }
|
---|
[21] | 305 |
|
---|
[901] | 306 | STHeader Scantable::getHeader() const
|
---|
[206] | 307 | {
|
---|
[901] | 308 | STHeader sdh;
|
---|
[21] | 309 | table_.keywordSet().get("nBeam",sdh.nbeam);
|
---|
| 310 | table_.keywordSet().get("nIF",sdh.nif);
|
---|
| 311 | table_.keywordSet().get("nPol",sdh.npol);
|
---|
| 312 | table_.keywordSet().get("nChan",sdh.nchan);
|
---|
| 313 | table_.keywordSet().get("Observer", sdh.observer);
|
---|
| 314 | table_.keywordSet().get("Project", sdh.project);
|
---|
| 315 | table_.keywordSet().get("Obstype", sdh.obstype);
|
---|
| 316 | table_.keywordSet().get("AntennaName", sdh.antennaname);
|
---|
| 317 | table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
|
---|
| 318 | table_.keywordSet().get("Equinox", sdh.equinox);
|
---|
| 319 | table_.keywordSet().get("FreqRefFrame", sdh.freqref);
|
---|
| 320 | table_.keywordSet().get("FreqRefVal", sdh.reffreq);
|
---|
| 321 | table_.keywordSet().get("Bandwidth", sdh.bandwidth);
|
---|
| 322 | table_.keywordSet().get("UTC", sdh.utc);
|
---|
[206] | 323 | table_.keywordSet().get("FluxUnit", sdh.fluxunit);
|
---|
| 324 | table_.keywordSet().get("Epoch", sdh.epoch);
|
---|
[905] | 325 | table_.keywordSet().get("POLTYPE", sdh.poltype);
|
---|
[21] | 326 | return sdh;
|
---|
[18] | 327 | }
|
---|
[805] | 328 |
|
---|
[845] | 329 | bool Scantable::conformant( const Scantable& other )
|
---|
| 330 | {
|
---|
| 331 | return this->getHeader().conformant(other.getHeader());
|
---|
| 332 | }
|
---|
| 333 |
|
---|
| 334 |
|
---|
[837] | 335 | int Scantable::nscan() const {
|
---|
[805] | 336 | int n = 0;
|
---|
[902] | 337 | Int previous = -1; Int current = 0;
|
---|
| 338 | Vector<uInt> scannos(scanCol_.getColumn());
|
---|
| 339 | uInt nout = GenSort<uInt>::sort( scannos, Sort::Ascending,
|
---|
| 340 | Sort::QuickSort|Sort::NoDuplicates );
|
---|
| 341 | return int(nout);
|
---|
[50] | 342 | }
|
---|
| 343 |
|
---|
[805] | 344 | std::string Scantable::formatSec(Double x) const
|
---|
[206] | 345 | {
|
---|
[105] | 346 | Double xcop = x;
|
---|
| 347 | MVTime mvt(xcop/24./3600.); // make days
|
---|
[365] | 348 |
|
---|
[105] | 349 | if (x < 59.95)
|
---|
[281] | 350 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
|
---|
[745] | 351 | else if (x < 3599.95)
|
---|
[281] | 352 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
|
---|
| 353 | else {
|
---|
| 354 | ostringstream oss;
|
---|
| 355 | oss << setw(2) << std::right << setprecision(1) << mvt.hour();
|
---|
| 356 | oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
|
---|
| 357 | return String(oss);
|
---|
[745] | 358 | }
|
---|
[105] | 359 | };
|
---|
| 360 |
|
---|
[805] | 361 | std::string Scantable::formatDirection(const MDirection& md) const
|
---|
[281] | 362 | {
|
---|
| 363 | Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
|
---|
| 364 | Int prec = 7;
|
---|
| 365 |
|
---|
| 366 | MVAngle mvLon(t[0]);
|
---|
| 367 | String sLon = mvLon.string(MVAngle::TIME,prec);
|
---|
| 368 | MVAngle mvLat(t[1]);
|
---|
| 369 | String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
|
---|
[380] | 370 | return sLon + String(" ") + sLat;
|
---|
[281] | 371 | }
|
---|
| 372 |
|
---|
| 373 |
|
---|
[805] | 374 | std::string Scantable::getFluxUnit() const
|
---|
[206] | 375 | {
|
---|
[847] | 376 | return table_.keywordSet().asString("FluxUnit");
|
---|
[206] | 377 | }
|
---|
| 378 |
|
---|
[805] | 379 | void Scantable::setFluxUnit(const std::string& unit)
|
---|
[218] | 380 | {
|
---|
| 381 | String tmp(unit);
|
---|
| 382 | Unit tU(tmp);
|
---|
| 383 | if (tU==Unit("K") || tU==Unit("Jy")) {
|
---|
| 384 | table_.rwKeywordSet().define(String("FluxUnit"), tmp);
|
---|
| 385 | } else {
|
---|
| 386 | throw AipsError("Illegal unit - must be compatible with Jy or K");
|
---|
| 387 | }
|
---|
| 388 | }
|
---|
| 389 |
|
---|
[805] | 390 | void Scantable::setInstrument(const std::string& name)
|
---|
[236] | 391 | {
|
---|
[805] | 392 | bool throwIt = true;
|
---|
[878] | 393 | Instrument ins = 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;
|
---|
| 564 | for (uInt i=0; i<nrow(); ++i) {
|
---|
| 565 | MEpoch me = timeCol(i);
|
---|
| 566 | MDirection md = dirCol_(i);
|
---|
| 567 | dirCol_.get(i,md);
|
---|
| 568 | oss << " Time: " << formatTime(me,False) << " Direction: " << formatDirection(md)
|
---|
| 569 | << endl << " => ";
|
---|
| 570 | MeasFrame frame(mp, me);
|
---|
| 571 | Vector<Double> azel =
|
---|
| 572 | MDirection::Convert(md, MDirection::Ref(MDirection::AZEL,
|
---|
| 573 | frame)
|
---|
| 574 | )().getAngle("rad").getValue();
|
---|
[923] | 575 | azCol_.put(i,Float(azel[0]));
|
---|
| 576 | elCol_.put(i,Float(azel[1]));
|
---|
[805] | 577 | oss << "azel: " << azel[0]/C::pi*180.0 << " "
|
---|
| 578 | << azel[1]/C::pi*180.0 << " (deg)" << endl;
|
---|
[16] | 579 | }
|
---|
[805] | 580 | pushLog(String(oss));
|
---|
| 581 | }
|
---|
[89] | 582 |
|
---|
[865] | 583 | void Scantable::flag()
|
---|
| 584 | {
|
---|
| 585 | if ( selector_.empty() )
|
---|
| 586 | throw(AipsError("Trying to flag whole scantable. Aborted."));
|
---|
[896] | 587 | TableVector<uChar> tvec(table_, "FLAGTRA");
|
---|
| 588 | uChar userflag = 1 << 7;
|
---|
| 589 | tvec = userflag;
|
---|
[865] | 590 | }
|
---|
| 591 |
|
---|
[805] | 592 | std::vector<bool> Scantable::getMask(int whichrow) const
|
---|
| 593 | {
|
---|
| 594 | Vector<uChar> flags;
|
---|
| 595 | flagsCol_.get(uInt(whichrow), flags);
|
---|
| 596 | Vector<Bool> bflag(flags.shape());
|
---|
| 597 | convertArray(bflag, flags);
|
---|
| 598 | bflag = !bflag;
|
---|
| 599 | std::vector<bool> mask;
|
---|
| 600 | bflag.tovector(mask);
|
---|
| 601 | return mask;
|
---|
| 602 | }
|
---|
[89] | 603 |
|
---|
[896] | 604 | std::vector<float> Scantable::getSpectrum( int whichrow,
|
---|
[902] | 605 | const std::string& poltype ) const
|
---|
[805] | 606 | {
|
---|
[905] | 607 | String ptype = poltype;
|
---|
| 608 | if (poltype == "" ) ptype = getPolType();
|
---|
[902] | 609 | if ( whichrow < 0 || whichrow >= nrow() )
|
---|
| 610 | throw(AipsError("Illegal row number."));
|
---|
[896] | 611 | std::vector<float> out;
|
---|
[805] | 612 | Vector<Float> arr;
|
---|
[896] | 613 | uInt requestedpol = polCol_(whichrow);
|
---|
| 614 | String basetype = getPolType();
|
---|
[905] | 615 | if ( ptype == basetype ) {
|
---|
[896] | 616 | specCol_.get(whichrow, arr);
|
---|
| 617 | } else {
|
---|
| 618 | STPol* stpol = 0;
|
---|
| 619 | stpol =STPol::getPolClass(Scantable::factories_, basetype);
|
---|
| 620 | try {
|
---|
| 621 | uInt row = uInt(whichrow);
|
---|
| 622 | stpol->setSpectra(getPolMatrix(row));
|
---|
| 623 | Float frot,fang,ftan;
|
---|
[902] | 624 | focusTable_.getEntry(frot, fang, ftan, mfocusidCol_(row));
|
---|
[896] | 625 | stpol->setPhaseCorrections(frot, fang, ftan);
|
---|
[905] | 626 | arr = stpol->getSpectrum(requestedpol, ptype);
|
---|
[896] | 627 | delete stpol;
|
---|
| 628 | } catch (AipsError& e) {
|
---|
| 629 | delete stpol;
|
---|
| 630 | throw(e);
|
---|
| 631 | }
|
---|
| 632 | }
|
---|
[902] | 633 | if ( arr.nelements() == 0 )
|
---|
| 634 | pushLog("Not enough polarisations present to do the conversion.");
|
---|
[805] | 635 | arr.tovector(out);
|
---|
| 636 | return out;
|
---|
[89] | 637 | }
|
---|
[212] | 638 |
|
---|
[884] | 639 | void asap::Scantable::setSpectrum( const std::vector<float>& spec,
|
---|
| 640 | int whichrow )
|
---|
| 641 | {
|
---|
| 642 | Vector<Float> spectrum(spec);
|
---|
| 643 | Vector<Float> arr;
|
---|
| 644 | specCol_.get(whichrow, arr);
|
---|
| 645 | if ( spectrum.nelements() != arr.nelements() )
|
---|
[896] | 646 | throw AipsError("The spectrum has incorrect number of channels.");
|
---|
[884] | 647 | specCol_.put(whichrow, spectrum);
|
---|
| 648 | }
|
---|
| 649 |
|
---|
| 650 |
|
---|
[805] | 651 | String Scantable::generateName()
|
---|
[745] | 652 | {
|
---|
[805] | 653 | return (File::newUniqueName("./","temp")).baseName();
|
---|
[212] | 654 | }
|
---|
| 655 |
|
---|
[805] | 656 | const casa::Table& Scantable::table( ) const
|
---|
[212] | 657 | {
|
---|
[805] | 658 | return table_;
|
---|
[212] | 659 | }
|
---|
| 660 |
|
---|
[805] | 661 | casa::Table& Scantable::table( )
|
---|
[386] | 662 | {
|
---|
[805] | 663 | return table_;
|
---|
[386] | 664 | }
|
---|
| 665 |
|
---|
[896] | 666 | std::string Scantable::getPolType() const
|
---|
| 667 | {
|
---|
| 668 | return table_.keywordSet().asString("POLTYPE");
|
---|
| 669 | }
|
---|
| 670 |
|
---|
[805] | 671 | void Scantable::unsetSelection()
|
---|
[380] | 672 | {
|
---|
[805] | 673 | table_ = originalTable_;
|
---|
[847] | 674 | attach();
|
---|
[805] | 675 | selector_.reset();
|
---|
[380] | 676 | }
|
---|
[386] | 677 |
|
---|
[805] | 678 | void Scantable::setSelection( const STSelector& selection )
|
---|
[430] | 679 | {
|
---|
[805] | 680 | Table tab = const_cast<STSelector&>(selection).apply(originalTable_);
|
---|
| 681 | if ( tab.nrow() == 0 ) {
|
---|
| 682 | throw(AipsError("Selection contains no data. Not applying it."));
|
---|
| 683 | }
|
---|
| 684 | table_ = tab;
|
---|
[847] | 685 | attach();
|
---|
[805] | 686 | selector_ = selection;
|
---|
[430] | 687 | }
|
---|
| 688 |
|
---|
[837] | 689 | std::string Scantable::summary( bool verbose )
|
---|
[447] | 690 | {
|
---|
[805] | 691 | // Format header info
|
---|
| 692 | ostringstream oss;
|
---|
| 693 | oss << endl;
|
---|
| 694 | oss << asap::SEPERATOR << endl;
|
---|
| 695 | oss << " Scan Table Summary" << endl;
|
---|
| 696 | oss << asap::SEPERATOR << endl;
|
---|
| 697 | oss.flags(std::ios_base::left);
|
---|
| 698 | oss << setw(15) << "Beams:" << setw(4) << nbeam() << endl
|
---|
| 699 | << setw(15) << "IFs:" << setw(4) << nif() << endl
|
---|
[896] | 700 | << setw(15) << "Polarisations:" << setw(4) << npol()
|
---|
| 701 | << "(" << getPolType() << ")" << endl
|
---|
[805] | 702 | << setw(15) << "Channels:" << setw(4) << nchan() << endl;
|
---|
| 703 | oss << endl;
|
---|
| 704 | String tmp;
|
---|
[860] | 705 | oss << setw(15) << "Observer:"
|
---|
| 706 | << table_.keywordSet().asString("Observer") << endl;
|
---|
[805] | 707 | oss << setw(15) << "Obs Date:" << getTime(-1,true) << endl;
|
---|
| 708 | table_.keywordSet().get("Project", tmp);
|
---|
| 709 | oss << setw(15) << "Project:" << tmp << endl;
|
---|
| 710 | table_.keywordSet().get("Obstype", tmp);
|
---|
| 711 | oss << setw(15) << "Obs. Type:" << tmp << endl;
|
---|
| 712 | table_.keywordSet().get("AntennaName", tmp);
|
---|
| 713 | oss << setw(15) << "Antenna Name:" << tmp << endl;
|
---|
| 714 | table_.keywordSet().get("FluxUnit", tmp);
|
---|
| 715 | oss << setw(15) << "Flux Unit:" << tmp << endl;
|
---|
[941] | 716 | Vector<Double> vec(moleculeTable_.getRestFrequencies());
|
---|
[805] | 717 | oss << setw(15) << "Rest Freqs:";
|
---|
| 718 | if (vec.nelements() > 0) {
|
---|
| 719 | oss << setprecision(10) << vec << " [Hz]" << endl;
|
---|
| 720 | } else {
|
---|
| 721 | oss << "none" << endl;
|
---|
| 722 | }
|
---|
[941] | 723 |
|
---|
| 724 | oss << setw(15) << "Abcissa:" << getAbcissaLabel(0) << endl;
|
---|
[805] | 725 | oss << selector_.print() << endl;
|
---|
| 726 | oss << endl;
|
---|
| 727 | // main table
|
---|
| 728 | String dirtype = "Position ("
|
---|
| 729 | + MDirection::showType(dirCol_.getMeasRef().getType())
|
---|
| 730 | + ")";
|
---|
[941] | 731 | oss << setw(5) << "Scan" << setw(15) << "Source"
|
---|
| 732 | << setw(10) << "Time" << setw(18) << "Integration" << endl;
|
---|
| 733 | oss << setw(5) << "" << setw(5) << "Beam" << setw(3) << "" << dirtype << endl;
|
---|
| 734 | oss << setw(10) << "" << setw(3) << "IF" << setw(6) << ""
|
---|
[805] | 735 | << setw(8) << "Frame" << setw(16)
|
---|
| 736 | << "RefVal" << setw(10) << "RefPix" << setw(12) << "Increment" <<endl;
|
---|
| 737 | oss << asap::SEPERATOR << endl;
|
---|
| 738 | TableIterator iter(table_, "SCANNO");
|
---|
| 739 | while (!iter.pastEnd()) {
|
---|
| 740 | Table subt = iter.table();
|
---|
| 741 | ROTableRow row(subt);
|
---|
| 742 | MEpoch::ROScalarColumn timeCol(subt,"TIME");
|
---|
| 743 | const TableRecord& rec = row.get(0);
|
---|
| 744 | oss << setw(4) << std::right << rec.asuInt("SCANNO")
|
---|
| 745 | << std::left << setw(1) << ""
|
---|
| 746 | << setw(15) << rec.asString("SRCNAME")
|
---|
| 747 | << setw(10) << formatTime(timeCol(0), false);
|
---|
| 748 | // count the cycles in the scan
|
---|
| 749 | TableIterator cyciter(subt, "CYCLENO");
|
---|
| 750 | int nint = 0;
|
---|
| 751 | while (!cyciter.pastEnd()) {
|
---|
| 752 | ++nint;
|
---|
| 753 | ++cyciter;
|
---|
| 754 | }
|
---|
| 755 | oss << setw(3) << std::right << nint << setw(3) << " x " << std::left
|
---|
| 756 | << setw(6) << formatSec(rec.asFloat("INTERVAL")) << endl;
|
---|
[447] | 757 |
|
---|
[805] | 758 | TableIterator biter(subt, "BEAMNO");
|
---|
| 759 | while (!biter.pastEnd()) {
|
---|
| 760 | Table bsubt = biter.table();
|
---|
| 761 | ROTableRow brow(bsubt);
|
---|
| 762 | MDirection::ROScalarColumn bdirCol(bsubt,"DIRECTION");
|
---|
| 763 | const TableRecord& brec = brow.get(0);
|
---|
[941] | 764 | oss << setw(5) << "" << setw(4) << std::right << brec.asuInt("BEAMNO")<< std::left;
|
---|
| 765 | oss << setw(4) << "" << formatDirection(bdirCol(0)) << endl;
|
---|
[805] | 766 | TableIterator iiter(bsubt, "IFNO");
|
---|
| 767 | while (!iiter.pastEnd()) {
|
---|
| 768 | Table isubt = iiter.table();
|
---|
| 769 | ROTableRow irow(isubt);
|
---|
| 770 | const TableRecord& irec = irow.get(0);
|
---|
[941] | 771 | oss << setw(10) << "";
|
---|
| 772 | oss << setw(3) << std::right << irec.asuInt("IFNO") << std::left
|
---|
| 773 | << setw(2) << "" << frequencies().print(irec.asuInt("FREQ_ID"));
|
---|
[447] | 774 |
|
---|
[805] | 775 | ++iiter;
|
---|
| 776 | }
|
---|
| 777 | ++biter;
|
---|
| 778 | }
|
---|
| 779 | ++iter;
|
---|
[447] | 780 | }
|
---|
[805] | 781 | /// @todo implement verbose mode
|
---|
| 782 | return String(oss);
|
---|
[447] | 783 | }
|
---|
| 784 |
|
---|
[805] | 785 | std::string Scantable::getTime(int whichrow, bool showdate) const
|
---|
[777] | 786 | {
|
---|
[805] | 787 | MEpoch::ROScalarColumn timeCol(table_, "TIME");
|
---|
| 788 | MEpoch me;
|
---|
| 789 | if (whichrow > -1) {
|
---|
| 790 | me = timeCol(uInt(whichrow));
|
---|
| 791 | } else {
|
---|
| 792 | Double tm;
|
---|
| 793 | table_.keywordSet().get("UTC",tm);
|
---|
| 794 | me = MEpoch(MVEpoch(tm));
|
---|
[777] | 795 | }
|
---|
[805] | 796 | return formatTime(me, showdate);
|
---|
[777] | 797 | }
|
---|
[805] | 798 |
|
---|
[865] | 799 | std::vector< double > asap::Scantable::getAbcissa( int whichrow ) const
|
---|
| 800 | {
|
---|
| 801 | if ( whichrow > table_.nrow() ) throw(AipsError("Illegal ro number"));
|
---|
| 802 | std::vector<double> stlout;
|
---|
| 803 | int nchan = specCol_(whichrow).nelements();
|
---|
| 804 | String us = freqTable_.getUnitString();
|
---|
| 805 | if ( us == "" || us == "pixel" || us == "channel" ) {
|
---|
| 806 | for (int i=0; i<nchan; ++i) {
|
---|
| 807 | stlout.push_back(double(i));
|
---|
| 808 | }
|
---|
| 809 | return stlout;
|
---|
| 810 | }
|
---|
| 811 |
|
---|
| 812 | const MPosition& mp = getAntennaPosition();
|
---|
| 813 | const MDirection& md = dirCol_(whichrow);
|
---|
| 814 | const MEpoch& me = timeCol_(whichrow);
|
---|
| 815 | Double rf = moleculeTable_.getRestFrequency(mmolidCol_(whichrow));
|
---|
| 816 | SpectralCoordinate spc =
|
---|
| 817 | freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow));
|
---|
| 818 | Vector<Double> pixel(nchan);
|
---|
| 819 | Vector<Double> world;
|
---|
| 820 | indgen(pixel);
|
---|
| 821 | if ( Unit(us) == Unit("Hz") ) {
|
---|
| 822 | for ( int i=0; i < nchan; ++i) {
|
---|
| 823 | Double world;
|
---|
| 824 | spc.toWorld(world, pixel[i]);
|
---|
| 825 | stlout.push_back(double(world));
|
---|
| 826 | }
|
---|
| 827 | } else if ( Unit(us) == Unit("km/s") ) {
|
---|
| 828 | Vector<Double> world;
|
---|
| 829 | spc.pixelToVelocity(world, pixel);
|
---|
| 830 | world.tovector(stlout);
|
---|
| 831 | }
|
---|
| 832 | return stlout;
|
---|
| 833 | }
|
---|
| 834 |
|
---|
[847] | 835 | std::string Scantable::getAbcissaLabel( int whichrow ) const
|
---|
| 836 | {
|
---|
| 837 | if ( whichrow > table_.nrow() ) throw(AipsError("Illegal ro number"));
|
---|
| 838 | const MPosition& mp = getAntennaPosition();
|
---|
| 839 | const MDirection& md = dirCol_(whichrow);
|
---|
| 840 | const MEpoch& me = timeCol_(whichrow);
|
---|
| 841 | const Double& rf = mmolidCol_(whichrow);
|
---|
| 842 | SpectralCoordinate spc =
|
---|
| 843 | freqTable_.getSpectralCoordinate(md, mp, me, rf, mfreqidCol_(whichrow));
|
---|
| 844 |
|
---|
| 845 | String s = "Channel";
|
---|
| 846 | Unit u = Unit(freqTable_.getUnitString());
|
---|
| 847 | if (u == Unit("km/s")) {
|
---|
| 848 | s = CoordinateUtil::axisLabel(spc,0,True,True,True);
|
---|
| 849 | } else if (u == Unit("Hz")) {
|
---|
| 850 | Vector<String> wau(1);wau = u.getName();
|
---|
| 851 | spc.setWorldAxisUnits(wau);
|
---|
| 852 |
|
---|
| 853 | s = CoordinateUtil::axisLabel(spc,0,True,True,False);
|
---|
| 854 | }
|
---|
| 855 | return s;
|
---|
| 856 |
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | void asap::Scantable::setRestFrequencies( double rf, const std::string& unit )
|
---|
| 860 | {
|
---|
[923] | 861 | ///@todo lookup in line table to fill in name and formattedname
|
---|
[847] | 862 | Unit u(unit);
|
---|
| 863 | Quantum<Double> urf(rf, u);
|
---|
| 864 | uInt id = moleculeTable_.addEntry(urf.getValue("Hz"), "", "");
|
---|
| 865 | TableVector<uInt> tabvec(table_, "MOLECULE_ID");
|
---|
| 866 | tabvec = id;
|
---|
| 867 | }
|
---|
| 868 |
|
---|
| 869 | void asap::Scantable::setRestFrequencies( const std::string& name )
|
---|
| 870 | {
|
---|
| 871 | throw(AipsError("setRestFrequencies( const std::string& name ) NYI"));
|
---|
| 872 | ///@todo implement
|
---|
| 873 | }
|
---|
| 874 |
|
---|
[852] | 875 | std::vector< unsigned int > asap::Scantable::rownumbers( ) const
|
---|
| 876 | {
|
---|
| 877 | std::vector<unsigned int> stlout;
|
---|
| 878 | Vector<uInt> vec = table_.rowNumbers();
|
---|
| 879 | vec.tovector(stlout);
|
---|
| 880 | return stlout;
|
---|
| 881 | }
|
---|
| 882 |
|
---|
[865] | 883 |
|
---|
[896] | 884 | Matrix<Float> asap::Scantable::getPolMatrix( uInt whichrow ) const
|
---|
| 885 | {
|
---|
| 886 | ROTableRow row(table_);
|
---|
| 887 | const TableRecord& rec = row.get(whichrow);
|
---|
| 888 | Table t =
|
---|
| 889 | originalTable_( originalTable_.col("SCANNO") == Int(rec.asuInt("SCANNO"))
|
---|
| 890 | && originalTable_.col("BEAMNO") == Int(rec.asuInt("BEAMNO"))
|
---|
| 891 | && originalTable_.col("IFNO") == Int(rec.asuInt("IFNO"))
|
---|
| 892 | && originalTable_.col("CYCLENO") == Int(rec.asuInt("CYCLENO")) );
|
---|
| 893 | ROArrayColumn<Float> speccol(t, "SPECTRA");
|
---|
| 894 | return speccol.getColumn();
|
---|
| 895 | }
|
---|
[865] | 896 |
|
---|
[902] | 897 | std::vector< std::string > asap::Scantable::columnNames( ) const
|
---|
| 898 | {
|
---|
| 899 | Vector<String> vec = table_.tableDesc().columnNames();
|
---|
| 900 | return mathutil::tovectorstring(vec);
|
---|
| 901 | }
|
---|
[896] | 902 |
|
---|
[915] | 903 | casa::MEpoch::Types asap::Scantable::getTimeReference( ) const
|
---|
| 904 | {
|
---|
| 905 | return MEpoch::castType(timeCol_.getMeasRef().getType());
|
---|
| 906 | }
|
---|
| 907 |
|
---|
| 908 |
|
---|
[902] | 909 | } //namespace asap
|
---|