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