[2] | 1 | //#--------------------------------------------------------------------------- |
---|
| 2 | //# SDMemTable.cc: A MemoryTable container for single dish integrations |
---|
| 3 | //#--------------------------------------------------------------------------- |
---|
| 4 | //# Copyright (C) 2004 |
---|
[125] | 5 | //# ATNF |
---|
[2] | 6 | //# |
---|
| 7 | //# This program is free software; you can redistribute it and/or modify it |
---|
| 8 | //# under the terms of the GNU General Public License as published by the Free |
---|
| 9 | //# Software Foundation; either version 2 of the License, or (at your option) |
---|
| 10 | //# any later version. |
---|
| 11 | //# |
---|
| 12 | //# This program is distributed in the hope that it will be useful, but |
---|
| 13 | //# WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
| 15 | //# Public License for more details. |
---|
| 16 | //# |
---|
| 17 | //# You should have received a copy of the GNU General Public License along |
---|
| 18 | //# with this program; if not, write to the Free Software Foundation, Inc., |
---|
| 19 | //# 675 Massachusetts Ave, Cambridge, MA 02139, USA. |
---|
| 20 | //# |
---|
| 21 | //# Correspondence concerning this software should be addressed as follows: |
---|
| 22 | //# Internet email: Malte.Marquarding@csiro.au |
---|
| 23 | //# Postal address: Malte Marquarding, |
---|
| 24 | //# Australia Telescope National Facility, |
---|
| 25 | //# P.O. Box 76, |
---|
| 26 | //# Epping, NSW, 2121, |
---|
| 27 | //# AUSTRALIA |
---|
| 28 | //# |
---|
| 29 | //# $Id: |
---|
| 30 | //#--------------------------------------------------------------------------- |
---|
| 31 | |
---|
[206] | 32 | #include <map> |
---|
| 33 | |
---|
[125] | 34 | #include <casa/aips.h> |
---|
[80] | 35 | #include <casa/iostream.h> |
---|
| 36 | #include <casa/iomanip.h> |
---|
| 37 | #include <casa/Arrays/Array.h> |
---|
| 38 | #include <casa/Arrays/ArrayMath.h> |
---|
| 39 | #include <casa/Arrays/MaskArrMath.h> |
---|
| 40 | #include <casa/Arrays/ArrayLogical.h> |
---|
| 41 | #include <casa/Arrays/ArrayAccessor.h> |
---|
[206] | 42 | #include <casa/Arrays/Vector.h> |
---|
[286] | 43 | #include <casa/Quanta/MVAngle.h> |
---|
[2] | 44 | |
---|
[80] | 45 | #include <tables/Tables/TableParse.h> |
---|
| 46 | #include <tables/Tables/TableDesc.h> |
---|
| 47 | #include <tables/Tables/SetupNewTab.h> |
---|
| 48 | #include <tables/Tables/ScaColDesc.h> |
---|
| 49 | #include <tables/Tables/ArrColDesc.h> |
---|
[2] | 50 | |
---|
[80] | 51 | #include <tables/Tables/ExprNode.h> |
---|
| 52 | #include <tables/Tables/TableRecord.h> |
---|
| 53 | #include <measures/Measures/MFrequency.h> |
---|
| 54 | #include <measures/Measures/MeasTable.h> |
---|
[105] | 55 | #include <coordinates/Coordinates/CoordinateUtil.h> |
---|
[80] | 56 | #include <casa/Quanta/MVTime.h> |
---|
[281] | 57 | #include <casa/Quanta/MVAngle.h> |
---|
[2] | 58 | |
---|
[215] | 59 | #include "SDDefs.h" |
---|
[2] | 60 | #include "SDMemTable.h" |
---|
| 61 | #include "SDContainer.h" |
---|
| 62 | |
---|
[206] | 63 | |
---|
[125] | 64 | using namespace casa; |
---|
[83] | 65 | using namespace asap; |
---|
[2] | 66 | |
---|
[18] | 67 | SDMemTable::SDMemTable() : |
---|
| 68 | IFSel_(0), |
---|
| 69 | beamSel_(0), |
---|
[206] | 70 | polSel_(0) |
---|
| 71 | { |
---|
[18] | 72 | setup(); |
---|
[322] | 73 | cerr << "Call SDMemTable::attach" << endl; |
---|
| 74 | attach(); |
---|
[18] | 75 | } |
---|
[206] | 76 | |
---|
[2] | 77 | SDMemTable::SDMemTable(const std::string& name) : |
---|
| 78 | IFSel_(0), |
---|
| 79 | beamSel_(0), |
---|
[206] | 80 | polSel_(0) |
---|
| 81 | { |
---|
[50] | 82 | Table tab(name); |
---|
[22] | 83 | table_ = tab.copyToMemoryTable("dummy"); |
---|
[206] | 84 | //cerr << "hello from C SDMemTable @ " << this << endl; |
---|
[2] | 85 | } |
---|
| 86 | |
---|
[206] | 87 | SDMemTable::SDMemTable(const SDMemTable& other, Bool clear) |
---|
| 88 | { |
---|
[148] | 89 | IFSel_= other.IFSel_; |
---|
| 90 | beamSel_= other.beamSel_; |
---|
| 91 | polSel_= other.polSel_; |
---|
| 92 | chanMask_ = other.chanMask_; |
---|
| 93 | table_ = other.table_.copyToMemoryTable(String("dummy")); |
---|
[2] | 94 | // clear all rows() |
---|
[16] | 95 | if (clear) { |
---|
[148] | 96 | table_.removeRow(this->table_.rowNumbers()); |
---|
[16] | 97 | } else { |
---|
[148] | 98 | IFSel_ = other.IFSel_; |
---|
| 99 | beamSel_ = other.beamSel_; |
---|
| 100 | polSel_ = other.polSel_; |
---|
[16] | 101 | } |
---|
[322] | 102 | // |
---|
| 103 | attach(); |
---|
[206] | 104 | //cerr << "hello from CC SDMemTable @ " << this << endl; |
---|
[2] | 105 | } |
---|
| 106 | |
---|
[80] | 107 | SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) : |
---|
[2] | 108 | IFSel_(0), |
---|
| 109 | beamSel_(0), |
---|
[206] | 110 | polSel_(0) |
---|
| 111 | { |
---|
[2] | 112 | Table t = tableCommand(exprs,tab); |
---|
[89] | 113 | if (t.nrow() == 0) |
---|
| 114 | throw(AipsError("Query unsuccessful.")); |
---|
[22] | 115 | table_ = t.copyToMemoryTable("dummy"); |
---|
[2] | 116 | } |
---|
| 117 | |
---|
[206] | 118 | SDMemTable::~SDMemTable() |
---|
| 119 | { |
---|
[105] | 120 | //cerr << "goodbye from SDMemTable @ " << this << endl; |
---|
[2] | 121 | } |
---|
| 122 | |
---|
[206] | 123 | SDMemTable SDMemTable::getScan(Int scanID) const |
---|
| 124 | { |
---|
[80] | 125 | String cond("SELECT * from $1 WHERE SCANID == "); |
---|
| 126 | cond += String::toString(scanID); |
---|
| 127 | return SDMemTable(table_, cond); |
---|
[2] | 128 | } |
---|
| 129 | |
---|
[206] | 130 | SDMemTable &SDMemTable::operator=(const SDMemTable& other) |
---|
| 131 | { |
---|
[148] | 132 | if (this != &other) { |
---|
| 133 | IFSel_= other.IFSel_; |
---|
| 134 | beamSel_= other.beamSel_; |
---|
| 135 | polSel_= other.polSel_; |
---|
| 136 | chanMask_.resize(0); |
---|
| 137 | chanMask_ = other.chanMask_; |
---|
| 138 | table_ = other.table_.copyToMemoryTable(String("dummy")); |
---|
[322] | 139 | attach(); |
---|
[206] | 140 | } |
---|
| 141 | //cerr << "hello from ASS SDMemTable @ " << this << endl; |
---|
[138] | 142 | return *this; |
---|
| 143 | } |
---|
| 144 | |
---|
[206] | 145 | SDMemTable SDMemTable::getSource(const std::string& source) const |
---|
| 146 | { |
---|
[80] | 147 | String cond("SELECT * from $1 WHERE SRCNAME == "); |
---|
| 148 | cond += source; |
---|
| 149 | return SDMemTable(table_, cond); |
---|
| 150 | } |
---|
| 151 | |
---|
[206] | 152 | void SDMemTable::setup() |
---|
| 153 | { |
---|
[2] | 154 | TableDesc td("", "1", TableDesc::Scratch); |
---|
| 155 | td.comment() = "A SDMemTable"; |
---|
[322] | 156 | // |
---|
[2] | 157 | td.addColumn(ScalarColumnDesc<Double>("TIME")); |
---|
| 158 | td.addColumn(ScalarColumnDesc<String>("SRCNAME")); |
---|
| 159 | td.addColumn(ArrayColumnDesc<Float>("SPECTRA")); |
---|
| 160 | td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA")); |
---|
[89] | 161 | td.addColumn(ArrayColumnDesc<Float>("TSYS")); |
---|
| 162 | td.addColumn(ScalarColumnDesc<Int>("SCANID")); |
---|
| 163 | td.addColumn(ScalarColumnDesc<Double>("INTERVAL")); |
---|
[39] | 164 | td.addColumn(ArrayColumnDesc<uInt>("FREQID")); |
---|
[78] | 165 | td.addColumn(ArrayColumnDesc<Double>("DIRECTION")); |
---|
[105] | 166 | td.addColumn(ScalarColumnDesc<String>("FIELDNAME")); |
---|
| 167 | td.addColumn(ScalarColumnDesc<String>("TCALTIME")); |
---|
| 168 | td.addColumn(ArrayColumnDesc<Float>("TCAL")); |
---|
| 169 | td.addColumn(ScalarColumnDesc<Float>("AZIMUTH")); |
---|
| 170 | td.addColumn(ScalarColumnDesc<Float>("ELEVATION")); |
---|
| 171 | td.addColumn(ScalarColumnDesc<Float>("PARANGLE")); |
---|
| 172 | td.addColumn(ScalarColumnDesc<Int>("REFBEAM")); |
---|
[206] | 173 | td.addColumn(ArrayColumnDesc<String>("HISTORY")); |
---|
[105] | 174 | |
---|
[2] | 175 | // Now create a new table from the description. |
---|
[18] | 176 | |
---|
[22] | 177 | SetupNewTable aNewTab("dummy", td, Table::New); |
---|
[89] | 178 | table_ = Table(aNewTab, Table::Memory, 0); |
---|
[2] | 179 | } |
---|
| 180 | |
---|
[322] | 181 | void SDMemTable::attach () |
---|
| 182 | { |
---|
| 183 | timeCol_.attach(table_, "TIME"); |
---|
| 184 | srcnCol_.attach(table_, "SRCNAME"); |
---|
| 185 | specCol_.attach(table_, "SPECTRA"); |
---|
| 186 | flagsCol_.attach(table_, "FLAGTRA"); |
---|
| 187 | tsCol_.attach(table_, "TSYS"); |
---|
| 188 | scanCol_.attach(table_, "SCANID"); |
---|
| 189 | integrCol_.attach(table_, "INTERVAL"); |
---|
| 190 | freqidCol_.attach(table_, "FREQID"); |
---|
| 191 | dirCol_.attach(table_, "DIRECTION"); |
---|
| 192 | fldnCol_.attach(table_, "FIELDNAME"); |
---|
| 193 | tcaltCol_.attach(table_, "TCALTIME"); |
---|
| 194 | tcalCol_.attach(table_, "TCAL"); |
---|
| 195 | azCol_.attach(table_, "AZIMUTH"); |
---|
| 196 | elCol_.attach(table_, "ELEVATION"); |
---|
| 197 | paraCol_.attach(table_, "PARANGLE"); |
---|
| 198 | rbeamCol_.attach(table_, "REFBEAM"); |
---|
| 199 | histCol_.attach(table_, "HISTORY"); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | |
---|
[206] | 203 | std::string SDMemTable::getSourceName(Int whichRow) const |
---|
| 204 | { |
---|
[2] | 205 | String name; |
---|
[322] | 206 | srcnCol_.get(whichRow, name); |
---|
[2] | 207 | return name; |
---|
| 208 | } |
---|
| 209 | |
---|
[281] | 210 | std::string SDMemTable::getTime(Int whichRow, Bool showDate) const |
---|
[206] | 211 | { |
---|
[2] | 212 | Double tm; |
---|
[281] | 213 | if (whichRow > -1) { |
---|
[322] | 214 | timeCol_.get(whichRow, tm); |
---|
[281] | 215 | } else { |
---|
| 216 | table_.keywordSet().get("UTC",tm); |
---|
| 217 | } |
---|
[50] | 218 | MVTime mvt(tm); |
---|
[281] | 219 | if (showDate) |
---|
| 220 | mvt.setFormat(MVTime::YMD); |
---|
| 221 | else |
---|
| 222 | mvt.setFormat(MVTime::TIME); |
---|
[50] | 223 | ostringstream oss; |
---|
| 224 | oss << mvt; |
---|
[281] | 225 | return String(oss); |
---|
[2] | 226 | } |
---|
[281] | 227 | |
---|
[206] | 228 | double SDMemTable::getInterval(Int whichRow) const |
---|
| 229 | { |
---|
[50] | 230 | Double intval; |
---|
[322] | 231 | integrCol_.get(whichRow, intval); |
---|
[50] | 232 | return intval; |
---|
| 233 | } |
---|
[2] | 234 | |
---|
[206] | 235 | bool SDMemTable::setIF(Int whichIF) |
---|
| 236 | { |
---|
[50] | 237 | if ( whichIF >= 0 && whichIF < nIF()) { |
---|
[2] | 238 | IFSel_ = whichIF; |
---|
| 239 | return true; |
---|
[50] | 240 | } |
---|
| 241 | return false; |
---|
[2] | 242 | } |
---|
[50] | 243 | |
---|
[206] | 244 | bool SDMemTable::setBeam(Int whichBeam) |
---|
| 245 | { |
---|
[50] | 246 | if ( whichBeam >= 0 && whichBeam < nBeam()) { |
---|
[2] | 247 | beamSel_ = whichBeam; |
---|
| 248 | return true; |
---|
[50] | 249 | } |
---|
| 250 | return false; |
---|
| 251 | } |
---|
[2] | 252 | |
---|
[206] | 253 | bool SDMemTable::setPol(Int whichPol) |
---|
| 254 | { |
---|
[50] | 255 | if ( whichPol >= 0 && whichPol < nPol()) { |
---|
[2] | 256 | polSel_ = whichPol; |
---|
| 257 | return true; |
---|
[50] | 258 | } |
---|
| 259 | return false; |
---|
[2] | 260 | } |
---|
| 261 | |
---|
[303] | 262 | void SDMemTable::resetCursor () |
---|
| 263 | { |
---|
| 264 | polSel_ = 0; |
---|
| 265 | IFSel_ = 0; |
---|
| 266 | beamSel_ = 0; |
---|
| 267 | } |
---|
| 268 | |
---|
[206] | 269 | bool SDMemTable::setMask(std::vector<int> whichChans) |
---|
| 270 | { |
---|
[16] | 271 | std::vector<int>::iterator it; |
---|
[322] | 272 | uInt n = flagsCol_.shape(0)(3); |
---|
[105] | 273 | if (whichChans.empty()) { |
---|
| 274 | chanMask_ = std::vector<bool>(n,true); |
---|
| 275 | return true; |
---|
| 276 | } |
---|
[16] | 277 | chanMask_.resize(n,true); |
---|
[39] | 278 | for (it = whichChans.begin(); it != whichChans.end(); ++it) { |
---|
[105] | 279 | if (*it < n) { |
---|
[16] | 280 | chanMask_[*it] = false; |
---|
[105] | 281 | } |
---|
[16] | 282 | } |
---|
[2] | 283 | return true; |
---|
| 284 | } |
---|
| 285 | |
---|
[16] | 286 | std::vector<bool> SDMemTable::getMask(Int whichRow) const { |
---|
| 287 | std::vector<bool> mask; |
---|
| 288 | Array<uChar> arr; |
---|
[322] | 289 | flagsCol_.get(whichRow, arr); |
---|
[206] | 290 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr); |
---|
[16] | 291 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 292 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0); |
---|
[16] | 293 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 294 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1); |
---|
[16] | 295 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 296 | |
---|
| 297 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) ); |
---|
| 298 | |
---|
| 299 | std::vector<bool> tmp; |
---|
| 300 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here |
---|
| 301 | std::vector<bool>::iterator miter; |
---|
| 302 | miter = tmp.begin(); |
---|
| 303 | |
---|
[206] | 304 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[16] | 305 | bool out =!static_cast<bool>(*i); |
---|
| 306 | if (useUserMask) { |
---|
| 307 | out = out && (*miter); |
---|
| 308 | miter++; |
---|
| 309 | } |
---|
| 310 | mask.push_back(out); |
---|
[89] | 311 | } |
---|
[16] | 312 | return mask; |
---|
[2] | 313 | } |
---|
[206] | 314 | std::vector<float> SDMemTable::getSpectrum(Int whichRow) const |
---|
| 315 | { |
---|
[2] | 316 | std::vector<float> spectrum; |
---|
| 317 | Array<Float> arr; |
---|
[322] | 318 | specCol_.get(whichRow, arr); |
---|
[206] | 319 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); |
---|
[2] | 320 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 321 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0); |
---|
[2] | 322 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 323 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); |
---|
[16] | 324 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
[206] | 325 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[16] | 326 | spectrum.push_back(*i); |
---|
[2] | 327 | } |
---|
| 328 | return spectrum; |
---|
| 329 | } |
---|
[206] | 330 | std::vector<string> SDMemTable::getCoordInfo() const |
---|
| 331 | { |
---|
[105] | 332 | String un; |
---|
| 333 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 334 | String sunit; |
---|
| 335 | t.keywordSet().get("UNIT",sunit); |
---|
| 336 | String dpl; |
---|
| 337 | t.keywordSet().get("DOPPLER",dpl); |
---|
| 338 | if (dpl == "") dpl = "RADIO"; |
---|
| 339 | String rfrm; |
---|
| 340 | t.keywordSet().get("REFFRAME",rfrm); |
---|
| 341 | std::vector<string> inf; |
---|
| 342 | inf.push_back(sunit); |
---|
| 343 | inf.push_back(rfrm); |
---|
| 344 | inf.push_back(dpl); |
---|
[263] | 345 | t.keywordSet().get("BASEREFFRAME",rfrm); |
---|
| 346 | inf.push_back(rfrm); |
---|
[105] | 347 | return inf; |
---|
| 348 | } |
---|
[39] | 349 | |
---|
[206] | 350 | void SDMemTable::setCoordInfo(std::vector<string> theinfo) |
---|
| 351 | { |
---|
[105] | 352 | std::vector<string>::iterator it; |
---|
[306] | 353 | String un,rfrm, brfrm,dpl; |
---|
| 354 | un = theinfo[0]; // Abcissa unit |
---|
| 355 | rfrm = theinfo[1]; // Active (or conversion) frame |
---|
| 356 | dpl = theinfo[2]; // Doppler |
---|
| 357 | brfrm = theinfo[3]; // Base frame |
---|
| 358 | // |
---|
[105] | 359 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); |
---|
[306] | 360 | // |
---|
[105] | 361 | Vector<Double> rstf; |
---|
| 362 | t.keywordSet().get("RESTFREQS",rstf); |
---|
[306] | 363 | // |
---|
[105] | 364 | Bool canDo = True; |
---|
| 365 | Unit u1("km/s");Unit u2("Hz"); |
---|
| 366 | if (Unit(un) == u1) { |
---|
| 367 | Vector<Double> rstf; |
---|
| 368 | t.keywordSet().get("RESTFREQS",rstf); |
---|
| 369 | if (rstf.nelements() == 0) { |
---|
| 370 | throw(AipsError("Can't set unit to km/s if no restfrequencies are specified")); |
---|
| 371 | } |
---|
| 372 | } else if (Unit(un) != u2 && un != "") { |
---|
| 373 | throw(AipsError("Unit not conformant with Spectral Coordinates")); |
---|
| 374 | } |
---|
| 375 | t.rwKeywordSet().define("UNIT", un); |
---|
[275] | 376 | // |
---|
[105] | 377 | MFrequency::Types mdr; |
---|
| 378 | if (!MFrequency::getType(mdr, rfrm)) { |
---|
| 379 | |
---|
| 380 | Int a,b;const uInt* c; |
---|
| 381 | const String* valid = MFrequency::allMyTypes(a, b, c); |
---|
| 382 | String pfix = "Please specify a legal frame type. Types are\n"; |
---|
| 383 | throw(AipsError(pfix+(*valid))); |
---|
| 384 | } else { |
---|
| 385 | t.rwKeywordSet().define("REFFRAME",rfrm); |
---|
| 386 | } |
---|
[275] | 387 | // |
---|
| 388 | MDoppler::Types dtype; |
---|
| 389 | dpl.upcase(); |
---|
| 390 | if (!MDoppler::getType(dtype, dpl)) { |
---|
| 391 | throw(AipsError("Doppler type unknown")); |
---|
| 392 | } else { |
---|
| 393 | t.rwKeywordSet().define("DOPPLER",dpl); |
---|
| 394 | } |
---|
[306] | 395 | // |
---|
| 396 | if (!MFrequency::getType(mdr, brfrm)) { |
---|
| 397 | Int a,b;const uInt* c; |
---|
| 398 | const String* valid = MFrequency::allMyTypes(a, b, c); |
---|
| 399 | String pfix = "Please specify a legal frame type. Types are\n"; |
---|
| 400 | throw(AipsError(pfix+(*valid))); |
---|
| 401 | } else { |
---|
| 402 | t.rwKeywordSet().define("BASEREFFRAME",brfrm); |
---|
| 403 | } |
---|
[105] | 404 | } |
---|
| 405 | |
---|
[286] | 406 | |
---|
[206] | 407 | std::vector<double> SDMemTable::getAbcissa(Int whichRow) const |
---|
| 408 | { |
---|
[286] | 409 | std::vector<double> abc(nChan()); |
---|
[206] | 410 | |
---|
[286] | 411 | // Get header units keyword |
---|
[206] | 412 | |
---|
[286] | 413 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
[105] | 414 | String sunit; |
---|
| 415 | t.keywordSet().get("UNIT",sunit); |
---|
| 416 | if (sunit == "") sunit = "pixel"; |
---|
| 417 | Unit u(sunit); |
---|
[286] | 418 | |
---|
| 419 | // Easy if just wanting pixels |
---|
| 420 | |
---|
| 421 | if (sunit==String("pixel")) { |
---|
| 422 | // assume channels/pixels |
---|
| 423 | std::vector<double>::iterator it; |
---|
| 424 | uInt i=0; |
---|
| 425 | for (it = abc.begin(); it != abc.end(); ++it) { |
---|
| 426 | (*it) = Double(i++); |
---|
| 427 | } |
---|
| 428 | // |
---|
| 429 | return abc; |
---|
[78] | 430 | } |
---|
| 431 | |
---|
[286] | 432 | // Continue with km/s or Hz. Get FreqID |
---|
| 433 | |
---|
| 434 | Vector<uInt> v; |
---|
[322] | 435 | freqidCol_.get(whichRow, v); |
---|
[286] | 436 | uInt specidx = v(IFSel_); |
---|
| 437 | |
---|
| 438 | // Get SpectralCoordinate, set reference frame conversion, |
---|
| 439 | // velocity conversion, and rest freq state |
---|
| 440 | |
---|
| 441 | SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow); |
---|
| 442 | // |
---|
| 443 | Vector<Double> pixel(nChan()); |
---|
| 444 | indgen(pixel); |
---|
| 445 | // |
---|
| 446 | if (u == Unit("km/s")) { |
---|
| 447 | Vector<Double> world; |
---|
| 448 | spc.pixelToVelocity(world,pixel); |
---|
| 449 | std::vector<double>::iterator it; |
---|
| 450 | uInt i = 0; |
---|
| 451 | for (it = abc.begin(); it != abc.end(); ++it) { |
---|
| 452 | (*it) = world[i]; |
---|
| 453 | i++; |
---|
| 454 | } |
---|
[39] | 455 | } else if (u == Unit("Hz")) { |
---|
[286] | 456 | |
---|
| 457 | // Set world axis units |
---|
| 458 | |
---|
[39] | 459 | Vector<String> wau(1); wau = u.getName(); |
---|
| 460 | spc.setWorldAxisUnits(wau); |
---|
[286] | 461 | // |
---|
[39] | 462 | std::vector<double>::iterator it; |
---|
| 463 | Double tmp; |
---|
| 464 | uInt i = 0; |
---|
[286] | 465 | for (it = abc.begin(); it != abc.end(); ++it) { |
---|
| 466 | spc.toWorld(tmp,pixel[i]); |
---|
[39] | 467 | (*it) = tmp; |
---|
| 468 | i++; |
---|
| 469 | } |
---|
| 470 | } |
---|
[286] | 471 | return abc; |
---|
[39] | 472 | } |
---|
| 473 | |
---|
[164] | 474 | std::string SDMemTable::getAbcissaString(Int whichRow) const |
---|
[105] | 475 | { |
---|
| 476 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
[286] | 477 | // |
---|
[105] | 478 | String sunit; |
---|
| 479 | t.keywordSet().get("UNIT",sunit); |
---|
| 480 | if (sunit == "") sunit = "pixel"; |
---|
| 481 | Unit u(sunit); |
---|
[286] | 482 | // |
---|
[105] | 483 | Vector<uInt> v; |
---|
[322] | 484 | freqidCol_.get(whichRow, v); |
---|
[105] | 485 | uInt specidx = v(IFSel_); |
---|
[286] | 486 | |
---|
| 487 | // Get SpectralCoordinate, with frame, velocity, rest freq state set |
---|
| 488 | |
---|
| 489 | SpectralCoordinate spc = getSpectralCoordinate(specidx, whichRow); |
---|
[275] | 490 | // |
---|
[105] | 491 | String s = "Channel"; |
---|
| 492 | if (u == Unit("km/s")) { |
---|
| 493 | s = CoordinateUtil::axisLabel(spc,0,True,True,True); |
---|
| 494 | } else if (u == Unit("Hz")) { |
---|
| 495 | Vector<String> wau(1);wau = u.getName(); |
---|
| 496 | spc.setWorldAxisUnits(wau); |
---|
[286] | 497 | // |
---|
| 498 | s = CoordinateUtil::axisLabel(spc,0,True,True,False); |
---|
[105] | 499 | } |
---|
| 500 | return s; |
---|
| 501 | } |
---|
| 502 | |
---|
[206] | 503 | void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow) |
---|
| 504 | { |
---|
[89] | 505 | Array<Float> arr; |
---|
[322] | 506 | specCol_.get(whichRow, arr); |
---|
[89] | 507 | if (spectrum.size() != arr.shape()(3)) { |
---|
| 508 | throw(AipsError("Attempting to set spectrum with incorrect length.")); |
---|
| 509 | } |
---|
| 510 | |
---|
[206] | 511 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); |
---|
[89] | 512 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 513 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0); |
---|
[89] | 514 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 515 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); |
---|
[89] | 516 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 517 | |
---|
| 518 | std::vector<float>::iterator it = spectrum.begin(); |
---|
[206] | 519 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[89] | 520 | (*i) = Float(*it); |
---|
| 521 | it++; |
---|
| 522 | } |
---|
[322] | 523 | specCol_.put(whichRow, arr); |
---|
[89] | 524 | } |
---|
| 525 | |
---|
[206] | 526 | void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const |
---|
| 527 | { |
---|
[21] | 528 | Array<Float> arr; |
---|
[322] | 529 | specCol_.get(whichRow, arr); |
---|
[21] | 530 | spectrum.resize(arr.shape()(3)); |
---|
[206] | 531 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); |
---|
[21] | 532 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 533 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0); |
---|
[21] | 534 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 535 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); |
---|
[21] | 536 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
[2] | 537 | |
---|
[206] | 538 | ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum); |
---|
| 539 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[21] | 540 | (*va) = (*i); |
---|
| 541 | va++; |
---|
| 542 | } |
---|
| 543 | } |
---|
[89] | 544 | /* |
---|
[68] | 545 | void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const { |
---|
[21] | 546 | Array<uChar> arr; |
---|
[322] | 547 | flagsCol_.get(whichRow, arr); |
---|
[21] | 548 | mask.resize(arr.shape()(3)); |
---|
| 549 | |
---|
[206] | 550 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr); |
---|
[21] | 551 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 552 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0); |
---|
[21] | 553 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 554 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1); |
---|
[21] | 555 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 556 | |
---|
| 557 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) ); |
---|
[89] | 558 | |
---|
[206] | 559 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask); |
---|
[21] | 560 | std::vector<bool> tmp; |
---|
| 561 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The |
---|
[89] | 562 | // iterator should work on chanMask_?? |
---|
[21] | 563 | std::vector<bool>::iterator miter; |
---|
| 564 | miter = tmp.begin(); |
---|
| 565 | |
---|
[206] | 566 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[21] | 567 | bool out =!static_cast<bool>(*i); |
---|
| 568 | if (useUserMask) { |
---|
| 569 | out = out && (*miter); |
---|
| 570 | miter++; |
---|
| 571 | } |
---|
| 572 | (*va) = out; |
---|
| 573 | va++; |
---|
[89] | 574 | } |
---|
[21] | 575 | } |
---|
[89] | 576 | */ |
---|
[16] | 577 | MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, |
---|
[164] | 578 | Bool useSelection) const |
---|
| 579 | { |
---|
[2] | 580 | Array<Float> arr; |
---|
| 581 | Array<uChar> farr; |
---|
[322] | 582 | specCol_.get(whichRow, arr); |
---|
| 583 | flagsCol_.get(whichRow, farr); |
---|
[2] | 584 | Array<Bool> barr(farr.shape());convertArray(barr, farr); |
---|
| 585 | MaskedArray<Float> marr; |
---|
[16] | 586 | if (useSelection) { |
---|
[206] | 587 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); |
---|
[16] | 588 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 589 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0); |
---|
[16] | 590 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 591 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); |
---|
[16] | 592 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
[89] | 593 | |
---|
[206] | 594 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > baa0(barr); |
---|
[16] | 595 | baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 596 | ArrayAccessor<Bool, Axis<asap::IFAxis> > baa1(baa0); |
---|
[16] | 597 | baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 598 | ArrayAccessor<Bool, Axis<asap::PolAxis> > baa2(baa1); |
---|
[16] | 599 | baa2.reset(baa2.begin(uInt(polSel_)));// go to pol |
---|
| 600 | |
---|
| 601 | Vector<Float> a(arr.shape()(3)); |
---|
| 602 | Vector<Bool> b(barr.shape()(3)); |
---|
[206] | 603 | ArrayAccessor<Float, Axis<asap::BeamAxis> > a0(a); |
---|
| 604 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > b0(b); |
---|
[16] | 605 | |
---|
[206] | 606 | ArrayAccessor<Bool, Axis<asap::ChanAxis> > j(baa2); |
---|
| 607 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); |
---|
| 608 | i != i.end(); ++i) { |
---|
[16] | 609 | (*a0) = (*i); |
---|
| 610 | (*b0) = !(*j); |
---|
| 611 | j++; |
---|
| 612 | a0++; |
---|
| 613 | b0++; |
---|
| 614 | } |
---|
| 615 | marr.setData(a,b); |
---|
| 616 | } else { |
---|
| 617 | marr.setData(arr,!barr); |
---|
| 618 | } |
---|
[2] | 619 | return marr; |
---|
| 620 | } |
---|
| 621 | |
---|
[206] | 622 | Float SDMemTable::getTsys(Int whichRow) const |
---|
| 623 | { |
---|
[2] | 624 | Array<Float> arr; |
---|
[322] | 625 | tsCol_.get(whichRow, arr); |
---|
[2] | 626 | Float out; |
---|
| 627 | IPosition ip(arr.shape()); |
---|
[16] | 628 | ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0; |
---|
[2] | 629 | out = arr(ip); |
---|
| 630 | return out; |
---|
| 631 | } |
---|
| 632 | |
---|
[281] | 633 | MDirection SDMemTable::getDirection(Int whichRow, Bool refBeam) const |
---|
[206] | 634 | { |
---|
[212] | 635 | MDirection::Types mdr = getDirectionReference(); |
---|
[206] | 636 | Array<Double> posit; |
---|
[322] | 637 | dirCol_.get(whichRow,posit); |
---|
[206] | 638 | Vector<Double> wpos(2); |
---|
| 639 | wpos[0] = posit(IPosition(2,beamSel_,0)); |
---|
| 640 | wpos[1] = posit(IPosition(2,beamSel_,1)); |
---|
| 641 | Quantum<Double> lon(wpos[0],Unit(String("rad"))); |
---|
| 642 | Quantum<Double> lat(wpos[1],Unit(String("rad"))); |
---|
[286] | 643 | return MDirection(lon, lat, mdr); |
---|
[206] | 644 | } |
---|
[39] | 645 | |
---|
[286] | 646 | MEpoch SDMemTable::getEpoch (Int whichRow) const |
---|
[206] | 647 | { |
---|
[286] | 648 | MEpoch::Types met = getTimeReference(); |
---|
| 649 | // |
---|
| 650 | Double obstime; |
---|
[322] | 651 | timeCol_.get(whichRow,obstime); |
---|
[286] | 652 | MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d")))); |
---|
| 653 | return MEpoch(tm2, met); |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | MPosition SDMemTable::getAntennaPosition () const |
---|
| 657 | { |
---|
| 658 | Vector<Double> antpos; |
---|
| 659 | table_.keywordSet().get("AntennaPosition", antpos); |
---|
| 660 | MVPosition mvpos(antpos(0),antpos(1),antpos(2)); |
---|
| 661 | return MPosition(mvpos); |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | |
---|
| 665 | SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx) const |
---|
| 666 | { |
---|
[206] | 667 | |
---|
[39] | 668 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 669 | if (whichIdx > t.nrow() ) { |
---|
[286] | 670 | throw(AipsError("SDMemTable::getSpectralCoordinate - whichIdx out of range")); |
---|
[39] | 671 | } |
---|
[89] | 672 | |
---|
[39] | 673 | Double rp,rv,inc; |
---|
| 674 | String rf; |
---|
| 675 | ROScalarColumn<Double> rpc(t, "REFPIX"); |
---|
| 676 | ROScalarColumn<Double> rvc(t, "REFVAL"); |
---|
| 677 | ROScalarColumn<Double> incc(t, "INCREMENT"); |
---|
[105] | 678 | t.keywordSet().get("BASEREFFRAME",rf); |
---|
[89] | 679 | |
---|
[286] | 680 | // Create SpectralCoordinate (units Hz) |
---|
| 681 | |
---|
[39] | 682 | MFrequency::Types mft; |
---|
| 683 | if (!MFrequency::getType(mft, rf)) { |
---|
| 684 | cerr << "Frequency type unknown assuming TOPO" << endl; |
---|
[89] | 685 | mft = MFrequency::TOPO; |
---|
| 686 | } |
---|
[39] | 687 | rpc.get(whichIdx, rp); |
---|
| 688 | rvc.get(whichIdx, rv); |
---|
| 689 | incc.get(whichIdx, inc); |
---|
[286] | 690 | // |
---|
[39] | 691 | SpectralCoordinate spec(mft,rv,inc,rp); |
---|
[286] | 692 | // |
---|
| 693 | return spec; |
---|
| 694 | } |
---|
| 695 | |
---|
| 696 | |
---|
| 697 | SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt whichIdx, uInt whichRow) const |
---|
| 698 | { |
---|
| 699 | // Create basic SC |
---|
| 700 | |
---|
| 701 | SpectralCoordinate spec = getSpectralCoordinate (whichIdx); |
---|
| 702 | // |
---|
| 703 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 704 | |
---|
| 705 | // Set rest frequencies |
---|
| 706 | |
---|
| 707 | Vector<Double> vec; |
---|
| 708 | t.keywordSet().get("RESTFREQS",vec); |
---|
| 709 | if (vec.nelements() > 0) { |
---|
[89] | 710 | spec.setRestFrequencies(vec); |
---|
[286] | 711 | |
---|
| 712 | // Select rest freq |
---|
| 713 | |
---|
| 714 | if (vec.nelements() >= nIF()) { |
---|
| 715 | spec.selectRestFrequency(uInt(IFSel_)); |
---|
| 716 | } |
---|
| 717 | } |
---|
| 718 | |
---|
| 719 | // Set up frame conversion layer |
---|
| 720 | |
---|
| 721 | String frm; |
---|
| 722 | t.keywordSet().get("REFFRAME",frm); |
---|
| 723 | if (frm == "") frm = "TOPO"; |
---|
| 724 | MFrequency::Types mtype; |
---|
| 725 | if (!MFrequency::getType(mtype, frm)) { |
---|
| 726 | cout << "Frequency type unknown assuming TOPO" << endl; // SHould never happen |
---|
| 727 | mtype = MFrequency::TOPO; |
---|
| 728 | } |
---|
| 729 | |
---|
| 730 | // Set reference frame conversion (requires row) |
---|
| 731 | |
---|
| 732 | MDirection direct = getDirection(whichRow); |
---|
| 733 | MEpoch epoch = getEpoch(whichRow); |
---|
| 734 | MPosition pos = getAntennaPosition(); |
---|
| 735 | if (!spec.setReferenceConversion(mtype,epoch,pos,direct)) { |
---|
| 736 | throw(AipsError("Couldn't convert frequency frame.")); |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | // Now velocity conversion if appropriate |
---|
| 740 | |
---|
| 741 | String unitStr; |
---|
| 742 | t.keywordSet().get("UNIT",unitStr); |
---|
| 743 | // |
---|
| 744 | String dpl; |
---|
| 745 | t.keywordSet().get("DOPPLER",dpl); |
---|
| 746 | MDoppler::Types dtype; |
---|
| 747 | MDoppler::getType(dtype, dpl); |
---|
| 748 | |
---|
| 749 | // Only set velocity unit if non-blank and non-Hz |
---|
| 750 | |
---|
| 751 | if (!unitStr.empty()) { |
---|
| 752 | Unit unitU(unitStr); |
---|
| 753 | if (unitU==Unit("Hz")) { |
---|
| 754 | } else { |
---|
| 755 | spec.setVelocity(unitStr, dtype); |
---|
| 756 | } |
---|
| 757 | } |
---|
| 758 | // |
---|
[39] | 759 | return spec; |
---|
| 760 | } |
---|
| 761 | |
---|
[286] | 762 | |
---|
[89] | 763 | Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord, |
---|
| 764 | uInt whichIdx) { |
---|
[50] | 765 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); |
---|
| 766 | if (whichIdx > t.nrow() ) { |
---|
[89] | 767 | throw(AipsError("SDMemTable::setCoordinate - coord no out of range")); |
---|
[50] | 768 | } |
---|
| 769 | ScalarColumn<Double> rpc(t, "REFPIX"); |
---|
| 770 | ScalarColumn<Double> rvc(t, "REFVAL"); |
---|
| 771 | ScalarColumn<Double> incc(t, "INCREMENT"); |
---|
[89] | 772 | |
---|
[50] | 773 | rpc.put(whichIdx, speccord.referencePixel()[0]); |
---|
| 774 | rvc.put(whichIdx, speccord.referenceValue()[0]); |
---|
| 775 | incc.put(whichIdx, speccord.increment()[0]); |
---|
| 776 | |
---|
| 777 | return True; |
---|
| 778 | } |
---|
| 779 | |
---|
[89] | 780 | Int SDMemTable::nCoordinates() const |
---|
| 781 | { |
---|
| 782 | return table_.keywordSet().asTable("FREQUENCIES").nrow(); |
---|
| 783 | } |
---|
[50] | 784 | |
---|
[206] | 785 | void SDMemTable::setRestFreqs(std::vector<double> freqs, |
---|
| 786 | const std::string& theunit) |
---|
[89] | 787 | { |
---|
| 788 | Vector<Double> tvec(freqs); |
---|
| 789 | Quantum<Vector<Double> > q(tvec, String(theunit)); |
---|
| 790 | tvec.resize(); |
---|
| 791 | tvec = q.getValue("Hz"); |
---|
| 792 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 793 | t.rwKeywordSet().define("RESTFREQS",tvec); |
---|
| 794 | } |
---|
| 795 | |
---|
[251] | 796 | std::vector<double> SDMemTable::getRestFreqs() const |
---|
| 797 | { |
---|
| 798 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 799 | Vector<Double> tvec; |
---|
| 800 | t.keywordSet().get("RESTFREQS",tvec); |
---|
| 801 | std::vector<double> stlout; |
---|
| 802 | tvec.tovector(stlout); |
---|
| 803 | return stlout; |
---|
| 804 | } |
---|
| 805 | |
---|
[206] | 806 | bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft) |
---|
| 807 | { |
---|
[39] | 808 | TableDesc td("", "1", TableDesc::Scratch); |
---|
| 809 | td.addColumn(ScalarColumnDesc<Double>("REFPIX")); |
---|
| 810 | td.addColumn(ScalarColumnDesc<Double>("REFVAL")); |
---|
| 811 | td.addColumn(ScalarColumnDesc<Double>("INCREMENT")); |
---|
| 812 | SetupNewTable aNewTab("freqs", td, Table::New); |
---|
| 813 | Table aTable (aNewTab, Table::Memory, sdft.length()); |
---|
| 814 | ScalarColumn<Double> sc0(aTable, "REFPIX"); |
---|
| 815 | ScalarColumn<Double> sc1(aTable, "REFVAL"); |
---|
| 816 | ScalarColumn<Double> sc2(aTable, "INCREMENT"); |
---|
| 817 | for (uInt i=0; i < sdft.length(); ++i) { |
---|
| 818 | sc0.put(i,sdft.referencePixel(i)); |
---|
| 819 | sc1.put(i,sdft.referenceValue(i)); |
---|
| 820 | sc2.put(i,sdft.increment(i)); |
---|
| 821 | } |
---|
[105] | 822 | String rf = sdft.refFrame(); |
---|
| 823 | if (rf.contains("TOPO")) rf = "TOPO"; |
---|
| 824 | |
---|
| 825 | aTable.rwKeywordSet().define("BASEREFFRAME", rf); |
---|
| 826 | aTable.rwKeywordSet().define("REFFRAME", rf); |
---|
[39] | 827 | aTable.rwKeywordSet().define("EQUINOX", sdft.equinox()); |
---|
[105] | 828 | aTable.rwKeywordSet().define("UNIT", String("")); |
---|
| 829 | aTable.rwKeywordSet().define("DOPPLER", String("RADIO")); |
---|
[89] | 830 | Vector<Double> rfvec; |
---|
[206] | 831 | String rfunit; |
---|
| 832 | sdft.restFrequencies(rfvec,rfunit); |
---|
| 833 | Quantum<Vector<Double> > q(rfvec, rfunit); |
---|
| 834 | rfvec.resize(); |
---|
| 835 | rfvec = q.getValue("Hz"); |
---|
[89] | 836 | aTable.rwKeywordSet().define("RESTFREQS", rfvec); |
---|
[39] | 837 | table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable); |
---|
| 838 | return True; |
---|
| 839 | } |
---|
| 840 | |
---|
[206] | 841 | SDFrequencyTable SDMemTable::getSDFreqTable() const |
---|
| 842 | { |
---|
[251] | 843 | const Table& t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
[39] | 844 | SDFrequencyTable sdft; |
---|
[306] | 845 | |
---|
| 846 | // Add refpix/refval/incr. What are the units ? Hz I suppose |
---|
| 847 | // but it's nowhere described... |
---|
| 848 | |
---|
| 849 | Vector<Double> refPix, refVal, incr; |
---|
| 850 | ScalarColumn<Double> refPixCol(t, "REFPIX"); |
---|
| 851 | ScalarColumn<Double> refValCol(t, "REFVAL"); |
---|
| 852 | ScalarColumn<Double> incrCol(t, "INCREMENT"); |
---|
| 853 | refPix = refPixCol.getColumn(); |
---|
| 854 | refVal = refValCol.getColumn(); |
---|
| 855 | incr = incrCol.getColumn(); |
---|
| 856 | // |
---|
| 857 | uInt n = refPix.nelements(); |
---|
| 858 | for (uInt i=0; i<n; i++) { |
---|
| 859 | sdft.addFrequency(refPix[i], refVal[i], incr[i]); |
---|
| 860 | } |
---|
| 861 | |
---|
| 862 | // Frequency reference frame. I don't know if this |
---|
| 863 | // is the correct frame. It might be 'REFFRAME' |
---|
| 864 | // rather than 'BASEREFFRAME' ? |
---|
| 865 | |
---|
| 866 | String baseFrame; |
---|
| 867 | t.keywordSet().get("BASEREFFRAME",baseFrame); |
---|
| 868 | sdft.setRefFrame(baseFrame); |
---|
| 869 | |
---|
| 870 | // Equinox |
---|
| 871 | |
---|
| 872 | Float equinox; |
---|
| 873 | t.keywordSet().get("EQUINOX", equinox); |
---|
| 874 | sdft.setEquinox(equinox); |
---|
| 875 | |
---|
| 876 | // Rest Frequency |
---|
| 877 | |
---|
| 878 | Vector<Double> restFreqs; |
---|
| 879 | t.keywordSet().get("RESTFREQS", restFreqs); |
---|
| 880 | for (uInt i=0; i<restFreqs.nelements(); i++) { |
---|
| 881 | sdft.addRestFrequency(restFreqs[i]); |
---|
| 882 | } |
---|
| 883 | sdft.setRestFrequencyUnit(String("Hz")); |
---|
| 884 | // |
---|
[39] | 885 | return sdft; |
---|
| 886 | } |
---|
| 887 | |
---|
[206] | 888 | bool SDMemTable::putSDContainer(const SDContainer& sdc) |
---|
| 889 | { |
---|
[2] | 890 | uInt rno = table_.nrow(); |
---|
| 891 | table_.addRow(); |
---|
[89] | 892 | |
---|
[322] | 893 | // mjd.put(rno, sdc.timestamp); |
---|
| 894 | timeCol_.put(rno, sdc.timestamp); |
---|
| 895 | srcnCol_.put(rno, sdc.sourcename); |
---|
| 896 | fldnCol_.put(rno, sdc.fieldname); |
---|
| 897 | specCol_.put(rno, sdc.getSpectrum()); |
---|
| 898 | flagsCol_.put(rno, sdc.getFlags()); |
---|
| 899 | tsCol_.put(rno, sdc.getTsys()); |
---|
| 900 | scanCol_.put(rno, sdc.scanid); |
---|
| 901 | integrCol_.put(rno, sdc.interval); |
---|
| 902 | freqidCol_.put(rno, sdc.getFreqMap()); |
---|
| 903 | dirCol_.put(rno, sdc.getDirection()); |
---|
| 904 | rbeamCol_.put(rno, sdc.refbeam); |
---|
| 905 | tcalCol_.put(rno, sdc.tcal); |
---|
| 906 | tcaltCol_.put(rno, sdc.tcaltime); |
---|
| 907 | azCol_.put(rno, sdc.azimuth); |
---|
| 908 | elCol_.put(rno, sdc.elevation); |
---|
| 909 | paraCol_.put(rno, sdc.parangle); |
---|
| 910 | histCol_.put(rno, sdc.getHistory()); |
---|
[89] | 911 | |
---|
[2] | 912 | return true; |
---|
| 913 | } |
---|
[18] | 914 | |
---|
[206] | 915 | SDContainer SDMemTable::getSDContainer(uInt whichRow) const |
---|
| 916 | { |
---|
[21] | 917 | SDContainer sdc(nBeam(),nIF(),nPol(),nChan()); |
---|
[322] | 918 | timeCol_.get(whichRow, sdc.timestamp); |
---|
| 919 | srcnCol_.get(whichRow, sdc.sourcename); |
---|
| 920 | integrCol_.get(whichRow, sdc.interval); |
---|
| 921 | scanCol_.get(whichRow, sdc.scanid); |
---|
| 922 | fldnCol_.get(whichRow, sdc.fieldname); |
---|
| 923 | rbeamCol_.get(whichRow, sdc.refbeam); |
---|
| 924 | azCol_.get(whichRow, sdc.azimuth); |
---|
| 925 | elCol_.get(whichRow, sdc.elevation); |
---|
| 926 | paraCol_.get(whichRow, sdc.parangle); |
---|
[105] | 927 | Vector<Float> tc; |
---|
[322] | 928 | tcalCol_.get(whichRow, tc); |
---|
[105] | 929 | sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1]; |
---|
[322] | 930 | tcaltCol_.get(whichRow, sdc.tcaltime); |
---|
[21] | 931 | Array<Float> spectrum; |
---|
| 932 | Array<Float> tsys; |
---|
| 933 | Array<uChar> flagtrum; |
---|
[39] | 934 | Vector<uInt> fmap; |
---|
[78] | 935 | Array<Double> direction; |
---|
[206] | 936 | Vector<String> histo; |
---|
[322] | 937 | specCol_.get(whichRow, spectrum); |
---|
[21] | 938 | sdc.putSpectrum(spectrum); |
---|
[322] | 939 | flagsCol_.get(whichRow, flagtrum); |
---|
[21] | 940 | sdc.putFlags(flagtrum); |
---|
[322] | 941 | tsCol_.get(whichRow, tsys); |
---|
[21] | 942 | sdc.putTsys(tsys); |
---|
[322] | 943 | freqidCol_.get(whichRow, fmap); |
---|
[39] | 944 | sdc.putFreqMap(fmap); |
---|
[322] | 945 | dirCol_.get(whichRow, direction); |
---|
[78] | 946 | sdc.putDirection(direction); |
---|
[322] | 947 | histCol_.get(whichRow, histo); |
---|
[206] | 948 | sdc.putHistory(histo); |
---|
[21] | 949 | return sdc; |
---|
| 950 | } |
---|
[78] | 951 | |
---|
[206] | 952 | bool SDMemTable::putSDHeader(const SDHeader& sdh) |
---|
| 953 | { |
---|
[18] | 954 | table_.rwKeywordSet().define("nIF", sdh.nif); |
---|
| 955 | table_.rwKeywordSet().define("nBeam", sdh.nbeam); |
---|
| 956 | table_.rwKeywordSet().define("nPol", sdh.npol); |
---|
| 957 | table_.rwKeywordSet().define("nChan", sdh.nchan); |
---|
| 958 | table_.rwKeywordSet().define("Observer", sdh.observer); |
---|
| 959 | table_.rwKeywordSet().define("Project", sdh.project); |
---|
| 960 | table_.rwKeywordSet().define("Obstype", sdh.obstype); |
---|
| 961 | table_.rwKeywordSet().define("AntennaName", sdh.antennaname); |
---|
| 962 | table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition); |
---|
| 963 | table_.rwKeywordSet().define("Equinox", sdh.equinox); |
---|
| 964 | table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref); |
---|
| 965 | table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq); |
---|
| 966 | table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth); |
---|
| 967 | table_.rwKeywordSet().define("UTC", sdh.utc); |
---|
[206] | 968 | table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit); |
---|
| 969 | table_.rwKeywordSet().define("Epoch", sdh.epoch); |
---|
[18] | 970 | return true; |
---|
[50] | 971 | } |
---|
[21] | 972 | |
---|
[206] | 973 | SDHeader SDMemTable::getSDHeader() const |
---|
| 974 | { |
---|
[21] | 975 | SDHeader sdh; |
---|
| 976 | table_.keywordSet().get("nBeam",sdh.nbeam); |
---|
| 977 | table_.keywordSet().get("nIF",sdh.nif); |
---|
| 978 | table_.keywordSet().get("nPol",sdh.npol); |
---|
| 979 | table_.keywordSet().get("nChan",sdh.nchan); |
---|
| 980 | table_.keywordSet().get("Observer", sdh.observer); |
---|
| 981 | table_.keywordSet().get("Project", sdh.project); |
---|
| 982 | table_.keywordSet().get("Obstype", sdh.obstype); |
---|
| 983 | table_.keywordSet().get("AntennaName", sdh.antennaname); |
---|
| 984 | table_.keywordSet().get("AntennaPosition", sdh.antennaposition); |
---|
| 985 | table_.keywordSet().get("Equinox", sdh.equinox); |
---|
| 986 | table_.keywordSet().get("FreqRefFrame", sdh.freqref); |
---|
| 987 | table_.keywordSet().get("FreqRefVal", sdh.reffreq); |
---|
| 988 | table_.keywordSet().get("Bandwidth", sdh.bandwidth); |
---|
| 989 | table_.keywordSet().get("UTC", sdh.utc); |
---|
[206] | 990 | table_.keywordSet().get("FluxUnit", sdh.fluxunit); |
---|
| 991 | table_.keywordSet().get("Epoch", sdh.epoch); |
---|
[21] | 992 | return sdh; |
---|
[18] | 993 | } |
---|
[206] | 994 | void SDMemTable::makePersistent(const std::string& filename) |
---|
| 995 | { |
---|
[2] | 996 | table_.deepCopy(filename,Table::New); |
---|
| 997 | } |
---|
| 998 | |
---|
[89] | 999 | Int SDMemTable::nScan() const { |
---|
[50] | 1000 | Int n = 0; |
---|
| 1001 | Int previous = -1;Int current=0; |
---|
[322] | 1002 | for (uInt i=0; i< scanCol_.nrow();i++) { |
---|
| 1003 | scanCol_.getScalar(i,current); |
---|
[50] | 1004 | if (previous != current) { |
---|
[89] | 1005 | previous = current; |
---|
[50] | 1006 | n++; |
---|
| 1007 | } |
---|
| 1008 | } |
---|
| 1009 | return n; |
---|
| 1010 | } |
---|
| 1011 | |
---|
[260] | 1012 | String SDMemTable::formatSec(Double x) const |
---|
[206] | 1013 | { |
---|
[105] | 1014 | Double xcop = x; |
---|
| 1015 | MVTime mvt(xcop/24./3600.); // make days |
---|
[281] | 1016 | |
---|
[105] | 1017 | if (x < 59.95) |
---|
[281] | 1018 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s"; |
---|
| 1019 | else if (x < 3599.95) |
---|
| 1020 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" "; |
---|
| 1021 | else { |
---|
| 1022 | ostringstream oss; |
---|
| 1023 | oss << setw(2) << std::right << setprecision(1) << mvt.hour(); |
---|
| 1024 | oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " "; |
---|
| 1025 | return String(oss); |
---|
| 1026 | } |
---|
[105] | 1027 | }; |
---|
| 1028 | |
---|
[281] | 1029 | String SDMemTable::formatDirection(const MDirection& md) const |
---|
| 1030 | { |
---|
| 1031 | Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue(); |
---|
| 1032 | Int prec = 7; |
---|
| 1033 | |
---|
| 1034 | MVAngle mvLon(t[0]); |
---|
| 1035 | String sLon = mvLon.string(MVAngle::TIME,prec); |
---|
| 1036 | MVAngle mvLat(t[1]); |
---|
| 1037 | String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec); |
---|
| 1038 | |
---|
| 1039 | return sLon + String(" ") + sLat; |
---|
| 1040 | } |
---|
| 1041 | |
---|
| 1042 | |
---|
[206] | 1043 | std::string SDMemTable::getFluxUnit() const |
---|
| 1044 | { |
---|
| 1045 | String tmp; |
---|
| 1046 | table_.keywordSet().get("FluxUnit", tmp); |
---|
| 1047 | return tmp; |
---|
| 1048 | } |
---|
| 1049 | |
---|
[218] | 1050 | void SDMemTable::setFluxUnit(const std::string& unit) |
---|
| 1051 | { |
---|
| 1052 | String tmp(unit); |
---|
| 1053 | Unit tU(tmp); |
---|
| 1054 | if (tU==Unit("K") || tU==Unit("Jy")) { |
---|
| 1055 | table_.rwKeywordSet().define(String("FluxUnit"), tmp); |
---|
| 1056 | } else { |
---|
| 1057 | throw AipsError("Illegal unit - must be compatible with Jy or K"); |
---|
| 1058 | } |
---|
| 1059 | } |
---|
| 1060 | |
---|
[275] | 1061 | |
---|
[236] | 1062 | void SDMemTable::setInstrument(const std::string& name) |
---|
| 1063 | { |
---|
| 1064 | Bool throwIt = True; |
---|
| 1065 | Instrument ins = convertInstrument (name, throwIt); |
---|
| 1066 | String nameU(name); |
---|
| 1067 | nameU.upcase(); |
---|
| 1068 | table_.rwKeywordSet().define(String("AntennaName"), nameU); |
---|
| 1069 | } |
---|
| 1070 | |
---|
[260] | 1071 | std::string SDMemTable::summary() const { |
---|
[281] | 1072 | |
---|
| 1073 | // get number of integrations per scan |
---|
| 1074 | int cIdx = 0; |
---|
| 1075 | int idx = 0; |
---|
| 1076 | int scount = 0; |
---|
| 1077 | std::vector<int> cycles; |
---|
[322] | 1078 | for (uInt i=0; i<scanCol_.nrow();++i) { |
---|
| 1079 | while (idx == cIdx && i<scanCol_.nrow()) { |
---|
| 1080 | scanCol_.getScalar(++i,cIdx); |
---|
[281] | 1081 | ++scount; |
---|
| 1082 | } |
---|
| 1083 | idx = cIdx; |
---|
| 1084 | cycles.push_back(scount); |
---|
| 1085 | scount=0; |
---|
| 1086 | --i; |
---|
| 1087 | } |
---|
| 1088 | |
---|
| 1089 | |
---|
[89] | 1090 | ostringstream oss; |
---|
| 1091 | oss << endl; |
---|
| 1092 | oss << "--------------------------------------------------" << endl; |
---|
| 1093 | oss << " Scan Table Summary" << endl; |
---|
| 1094 | oss << "--------------------------------------------------" << endl; |
---|
| 1095 | oss.flags(std::ios_base::left); |
---|
| 1096 | oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl |
---|
| 1097 | << setw(15) << "IFs:" << setw(4) << nIF() << endl |
---|
| 1098 | << setw(15) << "Polarisations:" << setw(4) << nPol() << endl |
---|
| 1099 | << setw(15) << "Channels:" << setw(4) << nChan() << endl; |
---|
| 1100 | oss << endl; |
---|
| 1101 | String tmp; |
---|
| 1102 | table_.keywordSet().get("Observer", tmp); |
---|
| 1103 | oss << setw(15) << "Observer:" << tmp << endl; |
---|
[281] | 1104 | oss << setw(15) << "Obs Date:" << getTime(-1,True) << endl; |
---|
[89] | 1105 | table_.keywordSet().get("Project", tmp); |
---|
| 1106 | oss << setw(15) << "Project:" << tmp << endl; |
---|
| 1107 | table_.keywordSet().get("Obstype", tmp); |
---|
| 1108 | oss << setw(15) << "Obs. Type:" << tmp << endl; |
---|
| 1109 | table_.keywordSet().get("AntennaName", tmp); |
---|
| 1110 | oss << setw(15) << "Antenna Name:" << tmp << endl; |
---|
[206] | 1111 | table_.keywordSet().get("FluxUnit", tmp); |
---|
| 1112 | oss << setw(15) << "Flux Unit:" << tmp << endl; |
---|
[260] | 1113 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
[105] | 1114 | Vector<Double> vec; |
---|
| 1115 | t.keywordSet().get("RESTFREQS",vec); |
---|
| 1116 | oss << setw(15) << "Rest Freqs:"; |
---|
| 1117 | if (vec.nelements() > 0) { |
---|
| 1118 | oss << setprecision(0) << vec << " [Hz]" << endl; |
---|
| 1119 | } else { |
---|
| 1120 | oss << "None set" << endl; |
---|
| 1121 | } |
---|
[158] | 1122 | oss << setw(15) << "Abcissa:" << getAbcissaString() << endl; |
---|
[105] | 1123 | oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] " |
---|
| 1124 | << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl; |
---|
[89] | 1125 | oss << endl; |
---|
[2] | 1126 | uInt count = 0; |
---|
| 1127 | String name; |
---|
| 1128 | Int previous = -1;Int current=0; |
---|
[89] | 1129 | Int integ = 0; |
---|
[281] | 1130 | String dirtype ="Position ("+ |
---|
| 1131 | MDirection::showType(getDirectionReference())+ |
---|
| 1132 | ")"; |
---|
[89] | 1133 | oss << setw(6) << "Scan" |
---|
[281] | 1134 | << setw(15) << "Source" |
---|
| 1135 | << setw(26) << dirtype |
---|
| 1136 | << setw(10) << "Time" |
---|
| 1137 | << setw(13) << "Integration" << endl; |
---|
| 1138 | oss << "-------------------------------------------------------------------------------" << endl; |
---|
| 1139 | |
---|
| 1140 | std::vector<int>::iterator it = cycles.begin(); |
---|
[322] | 1141 | for (uInt i=0; i< scanCol_.nrow();i++) { |
---|
| 1142 | scanCol_.getScalar(i,current); |
---|
[2] | 1143 | if (previous != current) { |
---|
[322] | 1144 | srcnCol_.getScalar(i,name); |
---|
[50] | 1145 | previous = current; |
---|
[105] | 1146 | String t = formatSec(Double(getInterval(i))); |
---|
[281] | 1147 | String posit = formatDirection(getDirection(i,True)); |
---|
| 1148 | oss << setw(6) << count |
---|
| 1149 | << setw(15) << name |
---|
| 1150 | << setw(26) << posit |
---|
| 1151 | << setw(10) << getTime(i,False) |
---|
| 1152 | << setw(3) << std::right << *it << " x " |
---|
| 1153 | << setw(10) |
---|
| 1154 | << t << std::left << endl; |
---|
[50] | 1155 | count++; |
---|
[281] | 1156 | it++; |
---|
[89] | 1157 | } else { |
---|
| 1158 | integ++; |
---|
[2] | 1159 | } |
---|
| 1160 | } |
---|
[89] | 1161 | oss << endl; |
---|
[321] | 1162 | oss << "Table contains " << table_.nrow() << " integration(s) in " << count << " scan(s)." << endl; |
---|
| 1163 | |
---|
| 1164 | // Frequency Table |
---|
| 1165 | |
---|
| 1166 | std::vector<string> info = getCoordInfo(); |
---|
| 1167 | SDFrequencyTable sdft = getSDFreqTable(); |
---|
| 1168 | oss << endl << endl; |
---|
| 1169 | oss << "FreqID Frame RefFreq(Hz) RefPix Increment(Hz)" << endl; |
---|
| 1170 | oss << "-------------------------------------------------------------------------------" << endl; |
---|
| 1171 | for (uInt i=0; i<sdft.length(); i++) { |
---|
| 1172 | oss << setw(8) << i << setw(8) |
---|
| 1173 | << info[3] << setw(13) |
---|
| 1174 | << sdft.referenceValue(i) << setw(10) |
---|
| 1175 | << sdft.referencePixel(i) << setw(12) |
---|
| 1176 | << sdft.increment(i) << endl; |
---|
| 1177 | } |
---|
| 1178 | oss << "-------------------------------------------------------------------------------" << endl; |
---|
[89] | 1179 | return String(oss); |
---|
[2] | 1180 | } |
---|
[18] | 1181 | |
---|
[206] | 1182 | Int SDMemTable::nBeam() const |
---|
| 1183 | { |
---|
[18] | 1184 | Int n; |
---|
| 1185 | table_.keywordSet().get("nBeam",n); |
---|
| 1186 | return n; |
---|
| 1187 | } |
---|
| 1188 | Int SDMemTable::nIF() const { |
---|
| 1189 | Int n; |
---|
| 1190 | table_.keywordSet().get("nIF",n); |
---|
| 1191 | return n; |
---|
| 1192 | } |
---|
| 1193 | Int SDMemTable::nPol() const { |
---|
| 1194 | Int n; |
---|
| 1195 | table_.keywordSet().get("nPol",n); |
---|
| 1196 | return n; |
---|
| 1197 | } |
---|
| 1198 | Int SDMemTable::nChan() const { |
---|
| 1199 | Int n; |
---|
| 1200 | table_.keywordSet().get("nChan",n); |
---|
| 1201 | return n; |
---|
| 1202 | } |
---|
[206] | 1203 | bool SDMemTable::appendHistory(const std::string& hist, int whichRow) |
---|
| 1204 | { |
---|
| 1205 | Vector<String> history; |
---|
[322] | 1206 | histCol_.get(whichRow, history); |
---|
[206] | 1207 | history.resize(history.nelements()+1,True); |
---|
| 1208 | history[history.nelements()-1] = hist; |
---|
[322] | 1209 | histCol_.put(whichRow, history); |
---|
[206] | 1210 | } |
---|
| 1211 | |
---|
| 1212 | std::vector<std::string> SDMemTable::history(int whichRow) const |
---|
| 1213 | { |
---|
| 1214 | Vector<String> history; |
---|
[322] | 1215 | histCol_.get(whichRow, history); |
---|
[206] | 1216 | std::vector<std::string> stlout; |
---|
| 1217 | // there is no Array<String>.tovector(std::vector<std::string>), so |
---|
| 1218 | // do it by hand |
---|
| 1219 | for (uInt i=0; i<history.nelements(); ++i) { |
---|
| 1220 | stlout.push_back(history[i]); |
---|
| 1221 | } |
---|
| 1222 | return stlout; |
---|
| 1223 | } |
---|
[16] | 1224 | /* |
---|
[18] | 1225 | void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) { |
---|
[89] | 1226 | |
---|
[16] | 1227 | std::vector<int>::iterator it; |
---|
[206] | 1228 | ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_); |
---|
[16] | 1229 | for (it = whichChans.begin(); it != whichChans.end(); it++) { |
---|
| 1230 | j.reset(j.begin(uInt(*it))); |
---|
[206] | 1231 | for (ArrayAccessor<uChar, Axis<asap::BeamAxis> > i(j); i != i.end(); ++i) { |
---|
| 1232 | for (ArrayAccessor<uChar, Axis<asap::IFAxis> > ii(i); ii != ii.end(); ++ii) { |
---|
| 1233 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > iii(ii); |
---|
[89] | 1234 | iii != iii.end(); ++iii) { |
---|
| 1235 | (*iii) = |
---|
| 1236 | } |
---|
[16] | 1237 | } |
---|
| 1238 | } |
---|
| 1239 | } |
---|
[89] | 1240 | |
---|
[16] | 1241 | } |
---|
| 1242 | */ |
---|
[206] | 1243 | void SDMemTable::flag(int whichRow) |
---|
| 1244 | { |
---|
[89] | 1245 | Array<uChar> arr; |
---|
[322] | 1246 | flagsCol_.get(whichRow, arr); |
---|
[89] | 1247 | |
---|
[206] | 1248 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr); |
---|
[89] | 1249 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 1250 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0); |
---|
[89] | 1251 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 1252 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1); |
---|
[89] | 1253 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 1254 | |
---|
[206] | 1255 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[89] | 1256 | (*i) = uChar(True); |
---|
| 1257 | } |
---|
| 1258 | |
---|
[322] | 1259 | flagsCol_.put(whichRow, arr); |
---|
[89] | 1260 | } |
---|
[212] | 1261 | |
---|
[281] | 1262 | MDirection::Types SDMemTable::getDirectionReference() const |
---|
[212] | 1263 | { |
---|
| 1264 | Float eq; |
---|
| 1265 | table_.keywordSet().get("Equinox",eq); |
---|
| 1266 | std::map<float,string> mp; |
---|
| 1267 | mp[2000.0] = "J2000"; |
---|
| 1268 | mp[1950.0] = "B1950"; |
---|
| 1269 | MDirection::Types mdr; |
---|
| 1270 | if (!MDirection::getType(mdr, mp[eq])) { |
---|
| 1271 | mdr = MDirection::J2000; |
---|
| 1272 | cerr << "Unknown equinox using J2000" << endl; |
---|
| 1273 | } |
---|
| 1274 | // |
---|
| 1275 | return mdr; |
---|
| 1276 | } |
---|
| 1277 | |
---|
| 1278 | MEpoch::Types SDMemTable::getTimeReference () const |
---|
| 1279 | { |
---|
| 1280 | MEpoch::Types met; |
---|
| 1281 | String ep; |
---|
| 1282 | table_.keywordSet().get("Epoch",ep); |
---|
| 1283 | if (!MEpoch::getType(met, ep)) { |
---|
| 1284 | cerr << "Epoch type uknown - using UTC" << endl; |
---|
| 1285 | met = MEpoch::UTC; |
---|
| 1286 | } |
---|
| 1287 | // |
---|
| 1288 | return met; |
---|
| 1289 | } |
---|
| 1290 | |
---|
[236] | 1291 | |
---|
| 1292 | Instrument SDMemTable::convertInstrument (const String& instrument, |
---|
| 1293 | Bool throwIt) |
---|
| 1294 | { |
---|
| 1295 | String t(instrument); |
---|
| 1296 | t.upcase(); |
---|
[293] | 1297 | |
---|
| 1298 | // The strings are what SDReader returns, after cunning interrogation |
---|
| 1299 | // of station names... :-( |
---|
| 1300 | |
---|
[236] | 1301 | Instrument inst = asap::UNKNOWN; |
---|
[293] | 1302 | if (t==String("DSS-43")) { |
---|
[236] | 1303 | inst = TIDBINBILLA; |
---|
| 1304 | } else if (t==String("ATPKSMB")) { |
---|
[292] | 1305 | inst = ATPKSMB; |
---|
| 1306 | } else if (t==String("ATPKSHOH")) { |
---|
| 1307 | inst = ATPKSHOH; |
---|
| 1308 | } else if (t==String("ATMOPRA")) { |
---|
| 1309 | inst = ATMOPRA; |
---|
| 1310 | } else if (t==String("CEDUNA")) { |
---|
| 1311 | inst = CEDUNA; |
---|
| 1312 | } else if (t==String("HOBART")) { |
---|
| 1313 | inst = HOBART; |
---|
[236] | 1314 | } else { |
---|
| 1315 | if (throwIt) { |
---|
| 1316 | throw AipsError("Unrecognized instrument - use function scan.set_instrument to set"); |
---|
| 1317 | } |
---|
| 1318 | } |
---|
| 1319 | return inst; |
---|
| 1320 | } |
---|
| 1321 | |
---|