[2] | 1 | //#--------------------------------------------------------------------------- |
---|
| 2 | //# SDMemTable.cc: A MemoryTable container for single dish integrations |
---|
| 3 | //#--------------------------------------------------------------------------- |
---|
| 4 | //# Copyright (C) 2004 |
---|
| 5 | //# Malte Marquarding, ATNF |
---|
| 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 | |
---|
[16] | 32 | |
---|
[80] | 33 | #include <casa/iostream.h> |
---|
| 34 | #include <casa/iomanip.h> |
---|
| 35 | #include <casa/Arrays/Array.h> |
---|
| 36 | #include <casa/Arrays/ArrayMath.h> |
---|
| 37 | #include <casa/Arrays/MaskArrMath.h> |
---|
| 38 | #include <casa/Arrays/ArrayLogical.h> |
---|
| 39 | #include <casa/Arrays/ArrayAccessor.h> |
---|
[2] | 40 | |
---|
[80] | 41 | #include <tables/Tables/TableParse.h> |
---|
| 42 | #include <tables/Tables/TableDesc.h> |
---|
| 43 | #include <tables/Tables/SetupNewTab.h> |
---|
| 44 | #include <tables/Tables/ScaColDesc.h> |
---|
| 45 | #include <tables/Tables/ArrColDesc.h> |
---|
[2] | 46 | |
---|
[80] | 47 | #include <tables/Tables/ExprNode.h> |
---|
| 48 | #include <tables/Tables/ScalarColumn.h> |
---|
| 49 | #include <tables/Tables/ArrayColumn.h> |
---|
| 50 | #include <tables/Tables/TableRecord.h> |
---|
| 51 | #include <measures/Measures/MFrequency.h> |
---|
| 52 | #include <measures/Measures/MeasTable.h> |
---|
| 53 | #include <casa/Quanta/MVTime.h> |
---|
[2] | 54 | |
---|
| 55 | #include "SDMemTable.h" |
---|
| 56 | #include "SDContainer.h" |
---|
| 57 | |
---|
| 58 | using namespace atnf_sd; |
---|
| 59 | |
---|
[18] | 60 | SDMemTable::SDMemTable() : |
---|
| 61 | IFSel_(0), |
---|
| 62 | beamSel_(0), |
---|
| 63 | polSel_(0) { |
---|
| 64 | setup(); |
---|
| 65 | } |
---|
[2] | 66 | SDMemTable::SDMemTable(const std::string& name) : |
---|
| 67 | IFSel_(0), |
---|
| 68 | beamSel_(0), |
---|
| 69 | polSel_(0) { |
---|
[50] | 70 | Table tab(name); |
---|
[22] | 71 | table_ = tab.copyToMemoryTable("dummy"); |
---|
[2] | 72 | } |
---|
| 73 | |
---|
[16] | 74 | SDMemTable::SDMemTable(const SDMemTable& other, Bool clear) { |
---|
[2] | 75 | this->IFSel_= other.IFSel_; |
---|
| 76 | this->beamSel_= other.beamSel_; |
---|
| 77 | this->polSel_= other.polSel_; |
---|
| 78 | this->chanMask_ = other.chanMask_; |
---|
| 79 | this->table_ = other.table_.copyToMemoryTable(String("dummy")); |
---|
| 80 | // clear all rows() |
---|
[16] | 81 | if (clear) { |
---|
| 82 | this->table_.removeRow(this->table_.rowNumbers()); |
---|
| 83 | } else { |
---|
| 84 | this->IFSel_ = other.IFSel_; |
---|
| 85 | this->beamSel_ = other.beamSel_; |
---|
| 86 | this->polSel_ = other.polSel_; |
---|
| 87 | } |
---|
[2] | 88 | } |
---|
| 89 | |
---|
[80] | 90 | SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) : |
---|
[2] | 91 | IFSel_(0), |
---|
| 92 | beamSel_(0), |
---|
| 93 | polSel_(0) { |
---|
[50] | 94 | //cerr << exprs << endl; |
---|
[2] | 95 | Table t = tableCommand(exprs,tab); |
---|
[22] | 96 | table_ = t.copyToMemoryTable("dummy"); |
---|
[2] | 97 | } |
---|
| 98 | |
---|
| 99 | SDMemTable::~SDMemTable(){ |
---|
[50] | 100 | //cerr << "goodbye from SDMemTable @ " << this << endl; |
---|
[2] | 101 | } |
---|
| 102 | |
---|
| 103 | SDMemTable SDMemTable::getScan(Int scanID) { |
---|
[80] | 104 | String cond("SELECT * from $1 WHERE SCANID == "); |
---|
| 105 | cond += String::toString(scanID); |
---|
| 106 | return SDMemTable(table_, cond); |
---|
[2] | 107 | } |
---|
| 108 | |
---|
[80] | 109 | SDMemTable SDMemTable::getSource(const std::string& source) { |
---|
| 110 | String cond("SELECT * from $1 WHERE SRCNAME == "); |
---|
| 111 | cond += source; |
---|
| 112 | return SDMemTable(table_, cond); |
---|
| 113 | } |
---|
| 114 | |
---|
[2] | 115 | void SDMemTable::setup() { |
---|
| 116 | TableDesc td("", "1", TableDesc::Scratch); |
---|
| 117 | td.comment() = "A SDMemTable"; |
---|
| 118 | td.addColumn(ScalarColumnDesc<Double>("TIME")); |
---|
| 119 | td.addColumn(ScalarColumnDesc<String>("SRCNAME")); |
---|
| 120 | td.addColumn(ArrayColumnDesc<Float>("SPECTRA")); |
---|
| 121 | td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA")); |
---|
| 122 | td.addColumn(ArrayColumnDesc<Float>("TSYS")); |
---|
| 123 | td.addColumn(ScalarColumnDesc<Int>("SCANID")); |
---|
[16] | 124 | td.addColumn(ScalarColumnDesc<Double>("INTERVAL")); |
---|
[39] | 125 | td.addColumn(ArrayColumnDesc<uInt>("FREQID")); |
---|
[78] | 126 | td.addColumn(ArrayColumnDesc<Double>("DIRECTION")); |
---|
[2] | 127 | // Now create a new table from the description. |
---|
[18] | 128 | |
---|
[22] | 129 | SetupNewTable aNewTab("dummy", td, Table::New); |
---|
[2] | 130 | table_ = Table(aNewTab, Table::Memory, 0); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | std::string SDMemTable::getSourceName(Int whichRow) const { |
---|
| 134 | ROScalarColumn<String> src(table_, "SRCNAME"); |
---|
| 135 | String name; |
---|
| 136 | src.get(whichRow, name); |
---|
| 137 | return name; |
---|
| 138 | } |
---|
| 139 | |
---|
[50] | 140 | std::string SDMemTable::getTime(Int whichRow) const { |
---|
[2] | 141 | ROScalarColumn<Double> src(table_, "TIME"); |
---|
| 142 | Double tm; |
---|
| 143 | src.get(whichRow, tm); |
---|
[50] | 144 | MVTime mvt(tm); |
---|
| 145 | mvt.setFormat(MVTime::YMD); |
---|
| 146 | ostringstream oss; |
---|
| 147 | oss << mvt; |
---|
| 148 | String str(oss); |
---|
| 149 | return str; |
---|
[2] | 150 | } |
---|
[50] | 151 | double SDMemTable::getInterval(Int whichRow) const { |
---|
| 152 | ROScalarColumn<Double> src(table_, "INTERVAL"); |
---|
| 153 | Double intval; |
---|
| 154 | src.get(whichRow, intval); |
---|
| 155 | return intval; |
---|
| 156 | } |
---|
[2] | 157 | |
---|
| 158 | bool SDMemTable::setIF(Int whichIF) { |
---|
[50] | 159 | if ( whichIF >= 0 && whichIF < nIF()) { |
---|
[2] | 160 | IFSel_ = whichIF; |
---|
| 161 | return true; |
---|
[50] | 162 | } |
---|
| 163 | return false; |
---|
[2] | 164 | } |
---|
[50] | 165 | |
---|
[2] | 166 | bool SDMemTable::setBeam(Int whichBeam) { |
---|
[50] | 167 | if ( whichBeam >= 0 && whichBeam < nBeam()) { |
---|
[2] | 168 | beamSel_ = whichBeam; |
---|
| 169 | return true; |
---|
[50] | 170 | } |
---|
| 171 | return false; |
---|
| 172 | } |
---|
[2] | 173 | |
---|
| 174 | bool SDMemTable::setPol(Int whichPol) { |
---|
[50] | 175 | if ( whichPol >= 0 && whichPol < nPol()) { |
---|
[2] | 176 | polSel_ = whichPol; |
---|
| 177 | return true; |
---|
[50] | 178 | } |
---|
| 179 | return false; |
---|
[2] | 180 | } |
---|
| 181 | |
---|
[68] | 182 | bool SDMemTable::setMask(std::vector<int> whichChans) { |
---|
[16] | 183 | ROArrayColumn<uChar> spec(table_, "FLAGTRA"); |
---|
| 184 | |
---|
| 185 | std::vector<int>::iterator it; |
---|
| 186 | uInt n = spec.shape(0)(3); |
---|
| 187 | chanMask_.resize(n,true); |
---|
[39] | 188 | for (it = whichChans.begin(); it != whichChans.end(); ++it) { |
---|
[16] | 189 | if (*it < n) |
---|
| 190 | chanMask_[*it] = false; |
---|
| 191 | } |
---|
[2] | 192 | return true; |
---|
| 193 | } |
---|
| 194 | |
---|
[16] | 195 | std::vector<bool> SDMemTable::getMask(Int whichRow) const { |
---|
| 196 | std::vector<bool> mask; |
---|
| 197 | ROArrayColumn<uChar> spec(table_, "FLAGTRA"); |
---|
| 198 | Array<uChar> arr; |
---|
| 199 | spec.get(whichRow, arr); |
---|
| 200 | ArrayAccessor<uChar, Axis<0> > aa0(arr); |
---|
| 201 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
| 202 | ArrayAccessor<uChar, Axis<1> > aa1(aa0); |
---|
| 203 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
| 204 | ArrayAccessor<uChar, Axis<2> > aa2(aa1); |
---|
| 205 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 206 | |
---|
| 207 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) ); |
---|
| 208 | |
---|
| 209 | std::vector<bool> tmp; |
---|
| 210 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here |
---|
| 211 | std::vector<bool>::iterator miter; |
---|
| 212 | miter = tmp.begin(); |
---|
| 213 | |
---|
| 214 | for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
| 215 | bool out =!static_cast<bool>(*i); |
---|
| 216 | if (useUserMask) { |
---|
| 217 | out = out && (*miter); |
---|
| 218 | miter++; |
---|
| 219 | } |
---|
| 220 | mask.push_back(out); |
---|
| 221 | } |
---|
| 222 | return mask; |
---|
[2] | 223 | } |
---|
[50] | 224 | std::vector<float> SDMemTable::getSpectrum(Int whichRow) const { |
---|
[2] | 225 | |
---|
| 226 | std::vector<float> spectrum; |
---|
| 227 | ROArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
| 228 | Array<Float> arr; |
---|
| 229 | spec.get(whichRow, arr); |
---|
| 230 | ArrayAccessor<Float, Axis<0> > aa0(arr); |
---|
| 231 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
| 232 | ArrayAccessor<Float, Axis<1> > aa1(aa0); |
---|
| 233 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[16] | 234 | ArrayAccessor<Float, Axis<2> > aa2(aa1); |
---|
| 235 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 236 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
| 237 | spectrum.push_back(*i); |
---|
[2] | 238 | } |
---|
| 239 | return spectrum; |
---|
| 240 | } |
---|
[39] | 241 | |
---|
| 242 | std::vector<double> SDMemTable::getAbscissa(Int whichRow, |
---|
| 243 | const std::string& whichUnit, |
---|
[78] | 244 | const std::string& whichFrame, |
---|
[39] | 245 | double restfreq) { |
---|
| 246 | std::vector<double> absc(nChan()); |
---|
| 247 | Vector<Double> absc1(nChan()); |
---|
| 248 | indgen(absc1); |
---|
| 249 | ROArrayColumn<uInt> fid(table_, "FREQID"); |
---|
| 250 | Vector<uInt> v; |
---|
| 251 | fid.get(whichRow, v); |
---|
| 252 | uInt specidx = v(IFSel_); |
---|
| 253 | Unit u; |
---|
| 254 | if (whichUnit == "") { |
---|
| 255 | // get unit from table |
---|
| 256 | } else { |
---|
| 257 | u = String(whichUnit); |
---|
| 258 | } |
---|
| 259 | SpectralCoordinate spc = getCoordinate(specidx); |
---|
[78] | 260 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 261 | String rf; |
---|
| 262 | t.keywordSet().get("REFFRAME",rf); |
---|
| 263 | MDirection::Types mdr; |
---|
| 264 | MDirection::getType(mdr, rf); |
---|
| 265 | ROArrayColumn<Double> dir(table_, "DIRECTION"); |
---|
| 266 | Array<Double> posit; |
---|
| 267 | dir.get(whichRow,posit); |
---|
| 268 | Vector<Double> wpos(2); |
---|
| 269 | wpos[0] = posit(IPosition(2,beamSel_,0)); |
---|
| 270 | wpos[1] = posit(IPosition(2,beamSel_,1)); |
---|
| 271 | Quantum<Double> lon(wpos[0],Unit(String("rad"))); |
---|
| 272 | Quantum<Double> lat(wpos[1],Unit(String("rad"))); |
---|
| 273 | MDirection direct(lon, lat, mdr); |
---|
| 274 | ROScalarColumn<Double> tme(table_, "TIME"); |
---|
| 275 | Double obstime; |
---|
| 276 | tme.get(whichRow,obstime); |
---|
| 277 | Quantum<Double> tm(obstime, Unit(String("d"))); |
---|
| 278 | MVEpoch tm2(tm); |
---|
| 279 | MEpoch epoch(tm2); |
---|
| 280 | |
---|
| 281 | Vector<Double> antpos; |
---|
| 282 | table_.keywordSet().get("AntennaPosition", antpos); |
---|
| 283 | //MPosition pos; |
---|
| 284 | MVPosition mvpos(antpos(0),antpos(1),antpos(2)); |
---|
| 285 | MPosition pos(mvpos); |
---|
| 286 | //MeasTable::Observatory(pos, String("ATCA")); |
---|
| 287 | |
---|
| 288 | MFrequency::Types mtype; |
---|
| 289 | if (!MFrequency::getType(mtype, whichFrame)) { |
---|
| 290 | cerr << "Frequency type unknown assuming TOPO" << endl; |
---|
| 291 | mtype = MFrequency::TOPO; |
---|
| 292 | } |
---|
| 293 | spc.setReferenceConversion(mtype,epoch,pos,direct); |
---|
| 294 | |
---|
[39] | 295 | if ( u == Unit("km/s") ) { |
---|
| 296 | if (Double(restfreq) > Double(0.000001)) { |
---|
| 297 | cerr << "converting to velocities"<< endl; |
---|
| 298 | spc.setRestFrequency(Double(restfreq)); |
---|
| 299 | spc.setVelocity(u.getName()); |
---|
| 300 | Vector<Double> wrld; |
---|
| 301 | spc.pixelToVelocity(wrld,absc1); |
---|
| 302 | std::vector<double>::iterator it; |
---|
| 303 | uInt i = 0; |
---|
| 304 | for (it = absc.begin(); it != absc.end(); ++it) { |
---|
| 305 | (*it) = wrld[i]; |
---|
| 306 | i++; |
---|
| 307 | } |
---|
| 308 | } |
---|
| 309 | } else if (u == Unit("Hz")) { |
---|
| 310 | Vector<String> wau(1); wau = u.getName(); |
---|
| 311 | spc.setWorldAxisUnits(wau); |
---|
| 312 | cerr << " converting in frequency" << endl; |
---|
| 313 | std::vector<double>::iterator it; |
---|
| 314 | Double tmp; |
---|
| 315 | uInt i = 0; |
---|
[50] | 316 | for (it = absc.begin(); it != absc.end(); ++it) { |
---|
[39] | 317 | spc.toWorld(tmp,absc1[i]); |
---|
| 318 | (*it) = tmp; |
---|
| 319 | i++; |
---|
| 320 | } |
---|
| 321 | } |
---|
| 322 | return absc; |
---|
| 323 | } |
---|
| 324 | |
---|
[68] | 325 | void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) { |
---|
[21] | 326 | ROArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
| 327 | Array<Float> arr; |
---|
| 328 | spec.get(whichRow, arr); |
---|
| 329 | spectrum.resize(arr.shape()(3)); |
---|
| 330 | ArrayAccessor<Float, Axis<0> > aa0(arr); |
---|
| 331 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
| 332 | ArrayAccessor<Float, Axis<1> > aa1(aa0); |
---|
| 333 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
| 334 | ArrayAccessor<Float, Axis<2> > aa2(aa1); |
---|
| 335 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
[2] | 336 | |
---|
[21] | 337 | ArrayAccessor<Float, Axis<0> > va(spectrum); |
---|
| 338 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
| 339 | (*va) = (*i); |
---|
| 340 | va++; |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | |
---|
[68] | 344 | void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const { |
---|
[21] | 345 | ROArrayColumn<uChar> spec(table_, "FLAGTRA"); |
---|
| 346 | Array<uChar> arr; |
---|
| 347 | spec.get(whichRow, arr); |
---|
| 348 | mask.resize(arr.shape()(3)); |
---|
| 349 | |
---|
| 350 | ArrayAccessor<uChar, Axis<0> > aa0(arr); |
---|
| 351 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
| 352 | ArrayAccessor<uChar, Axis<1> > aa1(aa0); |
---|
| 353 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
| 354 | ArrayAccessor<uChar, Axis<2> > aa2(aa1); |
---|
| 355 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 356 | |
---|
| 357 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) ); |
---|
| 358 | |
---|
| 359 | ArrayAccessor<Bool, Axis<0> > va(mask); |
---|
| 360 | std::vector<bool> tmp; |
---|
| 361 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The |
---|
| 362 | // iterator should work on chanMask_?? |
---|
| 363 | std::vector<bool>::iterator miter; |
---|
| 364 | miter = tmp.begin(); |
---|
| 365 | |
---|
| 366 | for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
| 367 | bool out =!static_cast<bool>(*i); |
---|
| 368 | if (useUserMask) { |
---|
| 369 | out = out && (*miter); |
---|
| 370 | miter++; |
---|
| 371 | } |
---|
| 372 | (*va) = out; |
---|
| 373 | va++; |
---|
| 374 | } |
---|
| 375 | } |
---|
| 376 | |
---|
[16] | 377 | MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, |
---|
| 378 | Bool useSelection) { |
---|
[2] | 379 | ROArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
| 380 | Array<Float> arr; |
---|
| 381 | ROArrayColumn<uChar> flag(table_, "FLAGTRA"); |
---|
| 382 | Array<uChar> farr; |
---|
| 383 | spec.get(whichRow, arr); |
---|
| 384 | flag.get(whichRow, farr); |
---|
| 385 | Array<Bool> barr(farr.shape());convertArray(barr, farr); |
---|
| 386 | MaskedArray<Float> marr; |
---|
[16] | 387 | if (useSelection) { |
---|
| 388 | ArrayAccessor<Float, Axis<0> > aa0(arr); |
---|
| 389 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
| 390 | ArrayAccessor<Float, Axis<1> > aa1(aa0); |
---|
| 391 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
| 392 | ArrayAccessor<Float, Axis<2> > aa2(aa1); |
---|
| 393 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 394 | |
---|
| 395 | ArrayAccessor<Bool, Axis<0> > baa0(barr); |
---|
| 396 | baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam |
---|
| 397 | ArrayAccessor<Bool, Axis<1> > baa1(baa0); |
---|
| 398 | baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF |
---|
| 399 | ArrayAccessor<Bool, Axis<2> > baa2(baa1); |
---|
| 400 | baa2.reset(baa2.begin(uInt(polSel_)));// go to pol |
---|
| 401 | |
---|
| 402 | Vector<Float> a(arr.shape()(3)); |
---|
| 403 | Vector<Bool> b(barr.shape()(3)); |
---|
| 404 | ArrayAccessor<Float, Axis<0> > a0(a); |
---|
| 405 | ArrayAccessor<Bool, Axis<0> > b0(b); |
---|
| 406 | |
---|
| 407 | ArrayAccessor<Bool, Axis<3> > j(baa2); |
---|
| 408 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
| 409 | (*a0) = (*i); |
---|
| 410 | (*b0) = !(*j); |
---|
| 411 | j++; |
---|
| 412 | a0++; |
---|
| 413 | b0++; |
---|
| 414 | } |
---|
| 415 | marr.setData(a,b); |
---|
| 416 | } else { |
---|
| 417 | marr.setData(arr,!barr); |
---|
| 418 | } |
---|
[2] | 419 | return marr; |
---|
| 420 | } |
---|
| 421 | |
---|
| 422 | Float SDMemTable::getTsys(Int whichRow) const { |
---|
| 423 | ROArrayColumn<Float> ts(table_, "TSYS"); |
---|
| 424 | Array<Float> arr; |
---|
| 425 | ts.get(whichRow, arr); |
---|
| 426 | Float out; |
---|
| 427 | IPosition ip(arr.shape()); |
---|
[16] | 428 | ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0; |
---|
[2] | 429 | out = arr(ip); |
---|
| 430 | return out; |
---|
| 431 | } |
---|
| 432 | |
---|
[39] | 433 | SpectralCoordinate SDMemTable::getCoordinate(uInt whichIdx) const { |
---|
| 434 | |
---|
| 435 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 436 | if (whichIdx > t.nrow() ) { |
---|
| 437 | cerr << "SDMemTable::getCoordinate - whichIdx out of range" << endl; |
---|
[68] | 438 | return SpectralCoordinate(); |
---|
[39] | 439 | } |
---|
[78] | 440 | |
---|
[39] | 441 | Double rp,rv,inc; |
---|
| 442 | String rf; |
---|
| 443 | ROScalarColumn<Double> rpc(t, "REFPIX"); |
---|
| 444 | ROScalarColumn<Double> rvc(t, "REFVAL"); |
---|
| 445 | ROScalarColumn<Double> incc(t, "INCREMENT"); |
---|
| 446 | t.keywordSet().get("REFFRAME",rf); |
---|
| 447 | |
---|
| 448 | MFrequency::Types mft; |
---|
| 449 | if (!MFrequency::getType(mft, rf)) { |
---|
| 450 | cerr << "Frequency type unknown assuming TOPO" << endl; |
---|
| 451 | mft = MFrequency::TOPO; |
---|
| 452 | } |
---|
| 453 | rpc.get(whichIdx, rp); |
---|
| 454 | rvc.get(whichIdx, rv); |
---|
| 455 | incc.get(whichIdx, inc); |
---|
[50] | 456 | //cerr << "creating speccord from " << whichIdx << ": " |
---|
| 457 | // << rp <<", " << rv << ", " << inc << ", " << mft <<endl; |
---|
[39] | 458 | SpectralCoordinate spec(mft,rv,inc,rp); |
---|
| 459 | return spec; |
---|
| 460 | } |
---|
| 461 | |
---|
[50] | 462 | Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord, |
---|
| 463 | uInt whichIdx) { |
---|
| 464 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); |
---|
| 465 | if (whichIdx > t.nrow() ) { |
---|
| 466 | cerr << "SDMemTable::setCoordinate - whichIdx out of range" << endl; |
---|
[68] | 467 | return False; |
---|
[50] | 468 | } |
---|
| 469 | ScalarColumn<Double> rpc(t, "REFPIX"); |
---|
| 470 | ScalarColumn<Double> rvc(t, "REFVAL"); |
---|
| 471 | ScalarColumn<Double> incc(t, "INCREMENT"); |
---|
| 472 | |
---|
| 473 | rpc.put(whichIdx, speccord.referencePixel()[0]); |
---|
| 474 | rvc.put(whichIdx, speccord.referenceValue()[0]); |
---|
| 475 | incc.put(whichIdx, speccord.increment()[0]); |
---|
| 476 | |
---|
| 477 | return True; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | |
---|
[39] | 481 | bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft) { |
---|
| 482 | TableDesc td("", "1", TableDesc::Scratch); |
---|
| 483 | td.addColumn(ScalarColumnDesc<Double>("REFPIX")); |
---|
| 484 | td.addColumn(ScalarColumnDesc<Double>("REFVAL")); |
---|
| 485 | td.addColumn(ScalarColumnDesc<Double>("INCREMENT")); |
---|
| 486 | SetupNewTable aNewTab("freqs", td, Table::New); |
---|
| 487 | Table aTable (aNewTab, Table::Memory, sdft.length()); |
---|
| 488 | ScalarColumn<Double> sc0(aTable, "REFPIX"); |
---|
| 489 | ScalarColumn<Double> sc1(aTable, "REFVAL"); |
---|
| 490 | ScalarColumn<Double> sc2(aTable, "INCREMENT"); |
---|
| 491 | for (uInt i=0; i < sdft.length(); ++i) { |
---|
| 492 | sc0.put(i,sdft.referencePixel(i)); |
---|
| 493 | sc1.put(i,sdft.referenceValue(i)); |
---|
| 494 | sc2.put(i,sdft.increment(i)); |
---|
| 495 | } |
---|
| 496 | aTable.rwKeywordSet().define("REFFRAME", sdft.refFrame()); |
---|
| 497 | aTable.rwKeywordSet().define("EQUINOX", sdft.equinox()); |
---|
| 498 | aTable.rwKeywordSet().define("Unit", String("kms-1")); |
---|
| 499 | table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable); |
---|
| 500 | return True; |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | SDFrequencyTable SDMemTable::getSDFreqTable() const { |
---|
| 504 | SDFrequencyTable sdft; |
---|
| 505 | |
---|
| 506 | return sdft; |
---|
| 507 | } |
---|
| 508 | |
---|
[2] | 509 | bool SDMemTable::putSDContainer(const SDContainer& sdc) { |
---|
| 510 | ScalarColumn<Double> mjd(table_, "TIME"); |
---|
| 511 | ScalarColumn<String> srcn(table_, "SRCNAME"); |
---|
| 512 | ArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
| 513 | ArrayColumn<uChar> flags(table_, "FLAGTRA"); |
---|
| 514 | ArrayColumn<Float> ts(table_, "TSYS"); |
---|
| 515 | ScalarColumn<Int> scan(table_, "SCANID"); |
---|
[16] | 516 | ScalarColumn<Double> integr(table_, "INTERVAL"); |
---|
[39] | 517 | ArrayColumn<uInt> freqid(table_, "FREQID"); |
---|
[78] | 518 | ArrayColumn<Double> dir(table_, "DIRECTION"); |
---|
[2] | 519 | |
---|
| 520 | uInt rno = table_.nrow(); |
---|
| 521 | table_.addRow(); |
---|
| 522 | |
---|
| 523 | mjd.put(rno, sdc.timestamp); |
---|
| 524 | srcn.put(rno, sdc.sourcename); |
---|
| 525 | spec.put(rno, sdc.getSpectrum()); |
---|
| 526 | flags.put(rno, sdc.getFlags()); |
---|
| 527 | ts.put(rno, sdc.getTsys()); |
---|
| 528 | scan.put(rno, sdc.scanid); |
---|
[16] | 529 | integr.put(rno, sdc.interval); |
---|
[39] | 530 | freqid.put(rno, sdc.getFreqMap()); |
---|
[78] | 531 | dir.put(rno, sdc.getDirection()); |
---|
[16] | 532 | |
---|
[2] | 533 | return true; |
---|
| 534 | } |
---|
[18] | 535 | |
---|
[21] | 536 | SDContainer SDMemTable::getSDContainer(uInt whichRow) const { |
---|
| 537 | ROScalarColumn<Double> mjd(table_, "TIME"); |
---|
| 538 | ROScalarColumn<String> srcn(table_, "SRCNAME"); |
---|
| 539 | ROArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
| 540 | ROArrayColumn<uChar> flags(table_, "FLAGTRA"); |
---|
| 541 | ROArrayColumn<Float> ts(table_, "TSYS"); |
---|
| 542 | ROScalarColumn<Int> scan(table_, "SCANID"); |
---|
| 543 | ROScalarColumn<Double> integr(table_, "INTERVAL"); |
---|
[39] | 544 | ROArrayColumn<uInt> freqid(table_, "FREQID"); |
---|
[78] | 545 | ROArrayColumn<Double> dir(table_, "DIRECTION"); |
---|
[21] | 546 | |
---|
| 547 | SDContainer sdc(nBeam(),nIF(),nPol(),nChan()); |
---|
| 548 | mjd.get(whichRow, sdc.timestamp); |
---|
| 549 | srcn.get(whichRow, sdc.sourcename); |
---|
| 550 | integr.get(whichRow, sdc.interval); |
---|
| 551 | scan.get(whichRow, sdc.scanid); |
---|
| 552 | Array<Float> spectrum; |
---|
| 553 | Array<Float> tsys; |
---|
| 554 | Array<uChar> flagtrum; |
---|
[39] | 555 | Vector<uInt> fmap; |
---|
[78] | 556 | Array<Double> direction; |
---|
[21] | 557 | spec.get(whichRow, spectrum); |
---|
| 558 | sdc.putSpectrum(spectrum); |
---|
| 559 | flags.get(whichRow, flagtrum); |
---|
| 560 | sdc.putFlags(flagtrum); |
---|
| 561 | ts.get(whichRow, tsys); |
---|
| 562 | sdc.putTsys(tsys); |
---|
[39] | 563 | freqid.get(whichRow, fmap); |
---|
| 564 | sdc.putFreqMap(fmap); |
---|
[78] | 565 | dir.get(whichRow, direction); |
---|
| 566 | sdc.putDirection(direction); |
---|
[21] | 567 | return sdc; |
---|
| 568 | } |
---|
[78] | 569 | |
---|
[18] | 570 | bool SDMemTable::putSDHeader(const SDHeader& sdh) { |
---|
| 571 | table_.lock(); |
---|
| 572 | table_.rwKeywordSet().define("nIF", sdh.nif); |
---|
| 573 | table_.rwKeywordSet().define("nBeam", sdh.nbeam); |
---|
| 574 | table_.rwKeywordSet().define("nPol", sdh.npol); |
---|
| 575 | table_.rwKeywordSet().define("nChan", sdh.nchan); |
---|
| 576 | table_.rwKeywordSet().define("Observer", sdh.observer); |
---|
| 577 | table_.rwKeywordSet().define("Project", sdh.project); |
---|
| 578 | table_.rwKeywordSet().define("Obstype", sdh.obstype); |
---|
| 579 | table_.rwKeywordSet().define("AntennaName", sdh.antennaname); |
---|
| 580 | table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition); |
---|
| 581 | table_.rwKeywordSet().define("Equinox", sdh.equinox); |
---|
| 582 | table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref); |
---|
| 583 | table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq); |
---|
| 584 | table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth); |
---|
| 585 | table_.rwKeywordSet().define("UTC", sdh.utc); |
---|
| 586 | table_.unlock(); |
---|
| 587 | return true; |
---|
[50] | 588 | } |
---|
[21] | 589 | |
---|
| 590 | SDHeader SDMemTable::getSDHeader() const { |
---|
| 591 | SDHeader sdh; |
---|
| 592 | table_.keywordSet().get("nBeam",sdh.nbeam); |
---|
| 593 | table_.keywordSet().get("nIF",sdh.nif); |
---|
| 594 | table_.keywordSet().get("nPol",sdh.npol); |
---|
| 595 | table_.keywordSet().get("nChan",sdh.nchan); |
---|
| 596 | table_.keywordSet().get("Observer", sdh.observer); |
---|
| 597 | table_.keywordSet().get("Project", sdh.project); |
---|
| 598 | table_.keywordSet().get("Obstype", sdh.obstype); |
---|
| 599 | table_.keywordSet().get("AntennaName", sdh.antennaname); |
---|
| 600 | table_.keywordSet().get("AntennaPosition", sdh.antennaposition); |
---|
| 601 | table_.keywordSet().get("Equinox", sdh.equinox); |
---|
| 602 | table_.keywordSet().get("FreqRefFrame", sdh.freqref); |
---|
| 603 | table_.keywordSet().get("FreqRefVal", sdh.reffreq); |
---|
| 604 | table_.keywordSet().get("Bandwidth", sdh.bandwidth); |
---|
| 605 | table_.keywordSet().get("UTC", sdh.utc); |
---|
| 606 | return sdh; |
---|
[18] | 607 | } |
---|
[2] | 608 | void SDMemTable::makePersistent(const std::string& filename) { |
---|
| 609 | table_.deepCopy(filename,Table::New); |
---|
| 610 | } |
---|
| 611 | |
---|
[50] | 612 | Int SDMemTable::nScans() const { |
---|
| 613 | Int n = 0; |
---|
| 614 | ROScalarColumn<Int> scans(table_, "SCANID"); |
---|
| 615 | Int previous = -1;Int current=0; |
---|
| 616 | for (uInt i=0; i< scans.nrow();i++) { |
---|
| 617 | scans.getScalar(i,current); |
---|
| 618 | if (previous != current) { |
---|
| 619 | previous = current; |
---|
| 620 | n++; |
---|
| 621 | } |
---|
| 622 | } |
---|
| 623 | return n; |
---|
| 624 | } |
---|
| 625 | |
---|
[2] | 626 | void SDMemTable::summary() const { |
---|
| 627 | ROScalarColumn<Int> scans(table_, "SCANID"); |
---|
| 628 | ROScalarColumn<String> srcs(table_, "SRCNAME"); |
---|
[18] | 629 | cout << "*************** Header ***************" << endl; |
---|
| 630 | cout << "nBeam = " << nBeam() << "\t" |
---|
| 631 | << "nIF = " << nIF() << endl |
---|
| 632 | << "nPol = " << nPol() << "\t" |
---|
| 633 | << "nChan = " << nChan() << "\t" << endl; |
---|
| 634 | cout << "*************** Header ***************" << endl; |
---|
[2] | 635 | uInt count = 0; |
---|
| 636 | String name; |
---|
| 637 | Int previous = -1;Int current=0; |
---|
[50] | 638 | cout << "Scan\tSource\t\tTime\t\tIntegration" << endl; |
---|
[2] | 639 | for (uInt i=0; i< scans.nrow();i++) { |
---|
| 640 | scans.getScalar(i,current); |
---|
| 641 | if (previous != current) { |
---|
| 642 | srcs.getScalar(i,name); |
---|
[50] | 643 | previous = current; |
---|
| 644 | Double t = getInterval(); |
---|
| 645 | String unit("sec"); |
---|
| 646 | if (t/60.0 > 1.0) { |
---|
| 647 | t/=60.0;unit = "min"; |
---|
| 648 | } |
---|
[16] | 649 | cout << count << "\t" |
---|
[50] | 650 | << name << "\t" |
---|
| 651 | << getTime() << "\t" |
---|
| 652 | << setprecision(2) << setiosflags(std::ios_base::fixed) |
---|
| 653 | << t << " " << unit << endl |
---|
[16] | 654 | << endl; |
---|
[50] | 655 | count++; |
---|
[2] | 656 | } |
---|
| 657 | } |
---|
[18] | 658 | cout << "Table contains " << table_.nrow() << " integration(s)." << endl; |
---|
| 659 | cout << "in " << count << " scan(s)." << endl; |
---|
[2] | 660 | } |
---|
[18] | 661 | |
---|
| 662 | Int SDMemTable::nBeam() const { |
---|
| 663 | Int n; |
---|
| 664 | table_.keywordSet().get("nBeam",n); |
---|
| 665 | return n; |
---|
| 666 | } |
---|
| 667 | Int SDMemTable::nIF() const { |
---|
| 668 | Int n; |
---|
| 669 | table_.keywordSet().get("nIF",n); |
---|
| 670 | return n; |
---|
| 671 | } |
---|
| 672 | Int SDMemTable::nPol() const { |
---|
| 673 | Int n; |
---|
| 674 | table_.keywordSet().get("nPol",n); |
---|
| 675 | return n; |
---|
| 676 | } |
---|
| 677 | Int SDMemTable::nChan() const { |
---|
| 678 | Int n; |
---|
| 679 | table_.keywordSet().get("nChan",n); |
---|
| 680 | return n; |
---|
| 681 | } |
---|
[16] | 682 | /* |
---|
[18] | 683 | void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) { |
---|
[16] | 684 | |
---|
| 685 | std::vector<int>::iterator it; |
---|
| 686 | ArrayAccessor<uChar, Axis<2> > j(flags_); |
---|
| 687 | for (it = whichChans.begin(); it != whichChans.end(); it++) { |
---|
| 688 | j.reset(j.begin(uInt(*it))); |
---|
| 689 | for (ArrayAccessor<uChar, Axis<0> > i(j); i != i.end(); ++i) { |
---|
| 690 | for (ArrayAccessor<uChar, Axis<1> > ii(i); ii != ii.end(); ++ii) { |
---|
| 691 | for (ArrayAccessor<uChar, Axis<3> > iii(ii); |
---|
| 692 | iii != iii.end(); ++iii) { |
---|
| 693 | (*iii) = |
---|
| 694 | } |
---|
| 695 | } |
---|
| 696 | } |
---|
| 697 | } |
---|
| 698 | |
---|
| 699 | } |
---|
| 700 | */ |
---|