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