[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> |
---|
[455] | 42 | #include <casa/Arrays/VectorSTLIterator.h> |
---|
[206] | 43 | #include <casa/Arrays/Vector.h> |
---|
[418] | 44 | #include <casa/BasicMath/Math.h> |
---|
[286] | 45 | #include <casa/Quanta/MVAngle.h> |
---|
[2] | 46 | |
---|
[80] | 47 | #include <tables/Tables/TableParse.h> |
---|
| 48 | #include <tables/Tables/TableDesc.h> |
---|
| 49 | #include <tables/Tables/SetupNewTab.h> |
---|
| 50 | #include <tables/Tables/ScaColDesc.h> |
---|
| 51 | #include <tables/Tables/ArrColDesc.h> |
---|
[2] | 52 | |
---|
[80] | 53 | #include <tables/Tables/ExprNode.h> |
---|
| 54 | #include <tables/Tables/TableRecord.h> |
---|
| 55 | #include <measures/Measures/MFrequency.h> |
---|
| 56 | #include <measures/Measures/MeasTable.h> |
---|
[105] | 57 | #include <coordinates/Coordinates/CoordinateUtil.h> |
---|
[80] | 58 | #include <casa/Quanta/MVTime.h> |
---|
[281] | 59 | #include <casa/Quanta/MVAngle.h> |
---|
[2] | 60 | |
---|
[215] | 61 | #include "SDDefs.h" |
---|
[2] | 62 | #include "SDMemTable.h" |
---|
| 63 | #include "SDContainer.h" |
---|
[365] | 64 | #include "MathUtils.h" |
---|
[418] | 65 | #include "SDPol.h" |
---|
[2] | 66 | |
---|
[206] | 67 | |
---|
[457] | 68 | |
---|
[125] | 69 | using namespace casa; |
---|
[83] | 70 | using namespace asap; |
---|
[2] | 71 | |
---|
[18] | 72 | SDMemTable::SDMemTable() : |
---|
| 73 | IFSel_(0), |
---|
| 74 | beamSel_(0), |
---|
[206] | 75 | polSel_(0) |
---|
| 76 | { |
---|
[18] | 77 | setup(); |
---|
[322] | 78 | attach(); |
---|
[18] | 79 | } |
---|
[206] | 80 | |
---|
[2] | 81 | SDMemTable::SDMemTable(const std::string& name) : |
---|
| 82 | IFSel_(0), |
---|
| 83 | beamSel_(0), |
---|
[206] | 84 | polSel_(0) |
---|
| 85 | { |
---|
[50] | 86 | Table tab(name); |
---|
[22] | 87 | table_ = tab.copyToMemoryTable("dummy"); |
---|
[206] | 88 | //cerr << "hello from C SDMemTable @ " << this << endl; |
---|
[329] | 89 | attach(); |
---|
[2] | 90 | } |
---|
| 91 | |
---|
[206] | 92 | SDMemTable::SDMemTable(const SDMemTable& other, Bool clear) |
---|
| 93 | { |
---|
[148] | 94 | IFSel_= other.IFSel_; |
---|
| 95 | beamSel_= other.beamSel_; |
---|
| 96 | polSel_= other.polSel_; |
---|
| 97 | chanMask_ = other.chanMask_; |
---|
| 98 | table_ = other.table_.copyToMemoryTable(String("dummy")); |
---|
[2] | 99 | // clear all rows() |
---|
[16] | 100 | if (clear) { |
---|
[148] | 101 | table_.removeRow(this->table_.rowNumbers()); |
---|
[16] | 102 | } else { |
---|
[148] | 103 | IFSel_ = other.IFSel_; |
---|
| 104 | beamSel_ = other.beamSel_; |
---|
| 105 | polSel_ = other.polSel_; |
---|
[16] | 106 | } |
---|
[322] | 107 | // |
---|
| 108 | attach(); |
---|
[206] | 109 | //cerr << "hello from CC SDMemTable @ " << this << endl; |
---|
[2] | 110 | } |
---|
| 111 | |
---|
[80] | 112 | SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) : |
---|
[2] | 113 | IFSel_(0), |
---|
| 114 | beamSel_(0), |
---|
[206] | 115 | polSel_(0) |
---|
| 116 | { |
---|
[2] | 117 | Table t = tableCommand(exprs,tab); |
---|
[89] | 118 | if (t.nrow() == 0) |
---|
| 119 | throw(AipsError("Query unsuccessful.")); |
---|
[22] | 120 | table_ = t.copyToMemoryTable("dummy"); |
---|
[329] | 121 | attach(); |
---|
[380] | 122 | renumber(); |
---|
[2] | 123 | } |
---|
| 124 | |
---|
[206] | 125 | SDMemTable::~SDMemTable() |
---|
| 126 | { |
---|
[105] | 127 | //cerr << "goodbye from SDMemTable @ " << this << endl; |
---|
[2] | 128 | } |
---|
| 129 | |
---|
[206] | 130 | SDMemTable SDMemTable::getScan(Int scanID) const |
---|
| 131 | { |
---|
[80] | 132 | String cond("SELECT * from $1 WHERE SCANID == "); |
---|
| 133 | cond += String::toString(scanID); |
---|
| 134 | return SDMemTable(table_, cond); |
---|
[2] | 135 | } |
---|
| 136 | |
---|
[206] | 137 | SDMemTable &SDMemTable::operator=(const SDMemTable& other) |
---|
| 138 | { |
---|
[148] | 139 | if (this != &other) { |
---|
| 140 | IFSel_= other.IFSel_; |
---|
| 141 | beamSel_= other.beamSel_; |
---|
| 142 | polSel_= other.polSel_; |
---|
| 143 | chanMask_.resize(0); |
---|
| 144 | chanMask_ = other.chanMask_; |
---|
| 145 | table_ = other.table_.copyToMemoryTable(String("dummy")); |
---|
[322] | 146 | attach(); |
---|
[206] | 147 | } |
---|
| 148 | //cerr << "hello from ASS SDMemTable @ " << this << endl; |
---|
[138] | 149 | return *this; |
---|
| 150 | } |
---|
| 151 | |
---|
[206] | 152 | SDMemTable SDMemTable::getSource(const std::string& source) const |
---|
| 153 | { |
---|
[80] | 154 | String cond("SELECT * from $1 WHERE SRCNAME == "); |
---|
| 155 | cond += source; |
---|
| 156 | return SDMemTable(table_, cond); |
---|
| 157 | } |
---|
| 158 | |
---|
[206] | 159 | void SDMemTable::setup() |
---|
| 160 | { |
---|
[2] | 161 | TableDesc td("", "1", TableDesc::Scratch); |
---|
| 162 | td.comment() = "A SDMemTable"; |
---|
[455] | 163 | |
---|
[2] | 164 | td.addColumn(ScalarColumnDesc<Double>("TIME")); |
---|
| 165 | td.addColumn(ScalarColumnDesc<String>("SRCNAME")); |
---|
| 166 | td.addColumn(ArrayColumnDesc<Float>("SPECTRA")); |
---|
| 167 | td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA")); |
---|
[89] | 168 | td.addColumn(ArrayColumnDesc<Float>("TSYS")); |
---|
[418] | 169 | td.addColumn(ArrayColumnDesc<Float>("STOKES")); |
---|
[89] | 170 | td.addColumn(ScalarColumnDesc<Int>("SCANID")); |
---|
| 171 | td.addColumn(ScalarColumnDesc<Double>("INTERVAL")); |
---|
[39] | 172 | td.addColumn(ArrayColumnDesc<uInt>("FREQID")); |
---|
[386] | 173 | td.addColumn(ArrayColumnDesc<uInt>("RESTFREQID")); |
---|
[78] | 174 | td.addColumn(ArrayColumnDesc<Double>("DIRECTION")); |
---|
[105] | 175 | td.addColumn(ScalarColumnDesc<String>("FIELDNAME")); |
---|
| 176 | td.addColumn(ScalarColumnDesc<String>("TCALTIME")); |
---|
| 177 | td.addColumn(ArrayColumnDesc<Float>("TCAL")); |
---|
| 178 | td.addColumn(ScalarColumnDesc<Float>("AZIMUTH")); |
---|
| 179 | td.addColumn(ScalarColumnDesc<Float>("ELEVATION")); |
---|
| 180 | td.addColumn(ScalarColumnDesc<Float>("PARANGLE")); |
---|
| 181 | td.addColumn(ScalarColumnDesc<Int>("REFBEAM")); |
---|
[206] | 182 | td.addColumn(ArrayColumnDesc<String>("HISTORY")); |
---|
[455] | 183 | td.addColumn(ArrayColumnDesc<Int>("FITID")); |
---|
[105] | 184 | |
---|
[455] | 185 | |
---|
[418] | 186 | // Now create Table SetUp from the description. |
---|
[18] | 187 | |
---|
[22] | 188 | SetupNewTable aNewTab("dummy", td, Table::New); |
---|
[418] | 189 | |
---|
[455] | 190 | // Bind the Stokes Virtual machine to the STOKES column Because we |
---|
| 191 | // don't know how many polarizations will be in the data at this |
---|
| 192 | // point, we must bind the Virtual Engine regardless. The STOKES |
---|
| 193 | // column won't be accessed if not appropriate (nPol=4) |
---|
[418] | 194 | |
---|
[464] | 195 | |
---|
| 196 | SDStokesEngine::registerClass(); |
---|
[418] | 197 | SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA")); |
---|
| 198 | aNewTab.bindColumn ("STOKES", stokesEngine); |
---|
| 199 | |
---|
[455] | 200 | // Create Table |
---|
| 201 | table_ = Table(aNewTab, Table::Memory, 0); |
---|
| 202 | // add subtable |
---|
| 203 | TableDesc tdf("", "1", TableDesc::Scratch); |
---|
| 204 | tdf.addColumn(ArrayColumnDesc<String>("FUNCTIONS")); |
---|
| 205 | tdf.addColumn(ArrayColumnDesc<Int>("COMPONENTS")); |
---|
| 206 | tdf.addColumn(ArrayColumnDesc<Double>("PARAMETERS")); |
---|
| 207 | tdf.addColumn(ArrayColumnDesc<Bool>("PARMASK")); |
---|
| 208 | SetupNewTable fittab("fits", tdf, Table::New); |
---|
| 209 | Table fitTable(fittab, Table::Memory); |
---|
| 210 | table_.rwKeywordSet().defineTable("FITS", fitTable); |
---|
[418] | 211 | |
---|
[455] | 212 | |
---|
[2] | 213 | } |
---|
| 214 | |
---|
[380] | 215 | void SDMemTable::attach() |
---|
[322] | 216 | { |
---|
| 217 | timeCol_.attach(table_, "TIME"); |
---|
| 218 | srcnCol_.attach(table_, "SRCNAME"); |
---|
| 219 | specCol_.attach(table_, "SPECTRA"); |
---|
| 220 | flagsCol_.attach(table_, "FLAGTRA"); |
---|
| 221 | tsCol_.attach(table_, "TSYS"); |
---|
[418] | 222 | stokesCol_.attach(table_, "STOKES"); |
---|
[322] | 223 | scanCol_.attach(table_, "SCANID"); |
---|
| 224 | integrCol_.attach(table_, "INTERVAL"); |
---|
| 225 | freqidCol_.attach(table_, "FREQID"); |
---|
[386] | 226 | restfreqidCol_.attach(table_, "RESTFREQID"); |
---|
[322] | 227 | dirCol_.attach(table_, "DIRECTION"); |
---|
| 228 | fldnCol_.attach(table_, "FIELDNAME"); |
---|
| 229 | tcaltCol_.attach(table_, "TCALTIME"); |
---|
| 230 | tcalCol_.attach(table_, "TCAL"); |
---|
| 231 | azCol_.attach(table_, "AZIMUTH"); |
---|
| 232 | elCol_.attach(table_, "ELEVATION"); |
---|
| 233 | paraCol_.attach(table_, "PARANGLE"); |
---|
| 234 | rbeamCol_.attach(table_, "REFBEAM"); |
---|
| 235 | histCol_.attach(table_, "HISTORY"); |
---|
[455] | 236 | fitCol_.attach(table_,"FITID"); |
---|
[322] | 237 | } |
---|
| 238 | |
---|
| 239 | |
---|
[206] | 240 | std::string SDMemTable::getSourceName(Int whichRow) const |
---|
| 241 | { |
---|
[2] | 242 | String name; |
---|
[322] | 243 | srcnCol_.get(whichRow, name); |
---|
[2] | 244 | return name; |
---|
| 245 | } |
---|
| 246 | |
---|
[281] | 247 | std::string SDMemTable::getTime(Int whichRow, Bool showDate) const |
---|
[206] | 248 | { |
---|
[2] | 249 | Double tm; |
---|
[281] | 250 | if (whichRow > -1) { |
---|
[322] | 251 | timeCol_.get(whichRow, tm); |
---|
[281] | 252 | } else { |
---|
| 253 | table_.keywordSet().get("UTC",tm); |
---|
| 254 | } |
---|
[50] | 255 | MVTime mvt(tm); |
---|
[281] | 256 | if (showDate) |
---|
| 257 | mvt.setFormat(MVTime::YMD); |
---|
| 258 | else |
---|
| 259 | mvt.setFormat(MVTime::TIME); |
---|
[50] | 260 | ostringstream oss; |
---|
| 261 | oss << mvt; |
---|
[281] | 262 | return String(oss); |
---|
[2] | 263 | } |
---|
[281] | 264 | |
---|
[206] | 265 | double SDMemTable::getInterval(Int whichRow) const |
---|
| 266 | { |
---|
[50] | 267 | Double intval; |
---|
[322] | 268 | integrCol_.get(whichRow, intval); |
---|
[50] | 269 | return intval; |
---|
| 270 | } |
---|
[2] | 271 | |
---|
[206] | 272 | bool SDMemTable::setIF(Int whichIF) |
---|
| 273 | { |
---|
[50] | 274 | if ( whichIF >= 0 && whichIF < nIF()) { |
---|
[2] | 275 | IFSel_ = whichIF; |
---|
| 276 | return true; |
---|
[50] | 277 | } |
---|
| 278 | return false; |
---|
[2] | 279 | } |
---|
[50] | 280 | |
---|
[206] | 281 | bool SDMemTable::setBeam(Int whichBeam) |
---|
| 282 | { |
---|
[50] | 283 | if ( whichBeam >= 0 && whichBeam < nBeam()) { |
---|
[2] | 284 | beamSel_ = whichBeam; |
---|
| 285 | return true; |
---|
[50] | 286 | } |
---|
| 287 | return false; |
---|
| 288 | } |
---|
[2] | 289 | |
---|
[206] | 290 | bool SDMemTable::setPol(Int whichPol) |
---|
| 291 | { |
---|
[50] | 292 | if ( whichPol >= 0 && whichPol < nPol()) { |
---|
[2] | 293 | polSel_ = whichPol; |
---|
| 294 | return true; |
---|
[50] | 295 | } |
---|
| 296 | return false; |
---|
[2] | 297 | } |
---|
| 298 | |
---|
[380] | 299 | void SDMemTable::resetCursor() |
---|
[303] | 300 | { |
---|
| 301 | polSel_ = 0; |
---|
| 302 | IFSel_ = 0; |
---|
| 303 | beamSel_ = 0; |
---|
| 304 | } |
---|
| 305 | |
---|
[206] | 306 | bool SDMemTable::setMask(std::vector<int> whichChans) |
---|
| 307 | { |
---|
[16] | 308 | std::vector<int>::iterator it; |
---|
[322] | 309 | uInt n = flagsCol_.shape(0)(3); |
---|
[105] | 310 | if (whichChans.empty()) { |
---|
| 311 | chanMask_ = std::vector<bool>(n,true); |
---|
| 312 | return true; |
---|
| 313 | } |
---|
[16] | 314 | chanMask_.resize(n,true); |
---|
[39] | 315 | for (it = whichChans.begin(); it != whichChans.end(); ++it) { |
---|
[105] | 316 | if (*it < n) { |
---|
[16] | 317 | chanMask_[*it] = false; |
---|
[105] | 318 | } |
---|
[16] | 319 | } |
---|
[2] | 320 | return true; |
---|
| 321 | } |
---|
| 322 | |
---|
[447] | 323 | std::vector<bool> SDMemTable::getMask(Int whichRow) const |
---|
| 324 | { |
---|
| 325 | |
---|
[16] | 326 | std::vector<bool> mask; |
---|
[455] | 327 | |
---|
[16] | 328 | Array<uChar> arr; |
---|
[322] | 329 | flagsCol_.get(whichRow, arr); |
---|
[455] | 330 | |
---|
[206] | 331 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr); |
---|
[16] | 332 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 333 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0); |
---|
[16] | 334 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 335 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1); |
---|
[16] | 336 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 337 | |
---|
| 338 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) ); |
---|
| 339 | |
---|
| 340 | std::vector<bool> tmp; |
---|
| 341 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here |
---|
| 342 | std::vector<bool>::iterator miter; |
---|
| 343 | miter = tmp.begin(); |
---|
| 344 | |
---|
[206] | 345 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[16] | 346 | bool out =!static_cast<bool>(*i); |
---|
| 347 | if (useUserMask) { |
---|
| 348 | out = out && (*miter); |
---|
| 349 | miter++; |
---|
| 350 | } |
---|
| 351 | mask.push_back(out); |
---|
[89] | 352 | } |
---|
[16] | 353 | return mask; |
---|
[2] | 354 | } |
---|
[418] | 355 | |
---|
| 356 | |
---|
| 357 | |
---|
[206] | 358 | std::vector<float> SDMemTable::getSpectrum(Int whichRow) const |
---|
| 359 | { |
---|
[430] | 360 | |
---|
[2] | 361 | Array<Float> arr; |
---|
[322] | 362 | specCol_.get(whichRow, arr); |
---|
[455] | 363 | return getFloatSpectrum(arr); |
---|
[418] | 364 | } |
---|
| 365 | |
---|
[455] | 366 | std::vector<float> SDMemTable::getStokesSpectrum(Int whichRow, Bool doPol, |
---|
| 367 | Float paOffset) const |
---|
| 368 | // Gets |
---|
| 369 | // doPol=False : I,Q,U,V |
---|
| 370 | // doPol=True : I,P,PA,V ; P = sqrt(Q**2+U**2), PA = 0.5*atan2(Q,U) |
---|
| 371 | // |
---|
[418] | 372 | { |
---|
[430] | 373 | AlwaysAssert(asap::nAxes==4,AipsError); |
---|
[428] | 374 | if (nPol()!=1 && nPol()!=2 && nPol()!=4) { |
---|
| 375 | throw (AipsError("You must have 1,2 or 4 polarizations to get the Stokes parameters")); |
---|
[418] | 376 | } |
---|
| 377 | Array<Float> arr; |
---|
| 378 | stokesCol_.get(whichRow, arr); |
---|
[455] | 379 | |
---|
[430] | 380 | if (doPol && (polSel_==1 || polSel_==2)) { // Q,U --> P, P.A. |
---|
| 381 | |
---|
[455] | 382 | // Set current cursor location |
---|
[418] | 383 | const IPosition& shape = arr.shape(); |
---|
[430] | 384 | IPosition start, end; |
---|
| 385 | setCursorSlice (start, end, shape); |
---|
| 386 | |
---|
[455] | 387 | // Get Q and U slices |
---|
[430] | 388 | |
---|
[455] | 389 | Array<Float> Q = SDPolUtil::getStokesSlice(arr,start,end,"Q"); |
---|
| 390 | Array<Float> U = SDPolUtil::getStokesSlice(arr,start,end,"U"); |
---|
[430] | 391 | |
---|
[455] | 392 | // Compute output |
---|
[430] | 393 | |
---|
[418] | 394 | Array<Float> out; |
---|
| 395 | if (polSel_==1) { // P |
---|
| 396 | out = SDPolUtil::polarizedIntensity(Q,U); |
---|
| 397 | } else if (polSel_==2) { // P.A. |
---|
[426] | 398 | out = SDPolUtil::positionAngle(Q,U) + paOffset; |
---|
[418] | 399 | } |
---|
[430] | 400 | |
---|
[455] | 401 | // Copy to output |
---|
[430] | 402 | |
---|
[418] | 403 | IPosition vecShape(1,shape(asap::ChanAxis)); |
---|
| 404 | Vector<Float> outV = out.reform(vecShape); |
---|
[455] | 405 | std::vector<float> stlout; |
---|
| 406 | outV.tovector(stlout); |
---|
| 407 | return stlout; |
---|
| 408 | |
---|
[418] | 409 | } else { |
---|
[430] | 410 | |
---|
[455] | 411 | // Selects at the cursor location |
---|
| 412 | return getFloatSpectrum(arr); |
---|
[418] | 413 | } |
---|
| 414 | } |
---|
| 415 | |
---|
[455] | 416 | std::vector<float> SDMemTable::getCircularSpectrum(Int whichRow, |
---|
| 417 | Bool doRR) const |
---|
| 418 | // Gets |
---|
| 419 | // RR = I + V |
---|
| 420 | // LL = I - V |
---|
[430] | 421 | { |
---|
| 422 | AlwaysAssert(asap::nAxes==4,AipsError); |
---|
| 423 | if (nPol()!=4) { |
---|
| 424 | throw (AipsError("You must have 4 polarizations to get RR or LL")); |
---|
| 425 | } |
---|
| 426 | Array<Float> arr; |
---|
| 427 | stokesCol_.get(whichRow, arr); |
---|
| 428 | |
---|
[455] | 429 | // Set current cursor location |
---|
[430] | 430 | |
---|
| 431 | const IPosition& shape = arr.shape(); |
---|
| 432 | IPosition start, end; |
---|
[455] | 433 | setCursorSlice(start, end, shape); |
---|
[430] | 434 | |
---|
[455] | 435 | // Get I and V slices |
---|
[430] | 436 | |
---|
[455] | 437 | Array<Float> I = SDPolUtil::getStokesSlice(arr,start,end,"I"); |
---|
| 438 | Array<Float> V = SDPolUtil::getStokesSlice(arr,start,end,"V"); |
---|
[430] | 439 | |
---|
[455] | 440 | // Compute output |
---|
[430] | 441 | |
---|
[455] | 442 | Array<Float> out = SDPolUtil::circularPolarizationFromStokes(I, V, doRR); |
---|
[430] | 443 | |
---|
[455] | 444 | // Copy to output |
---|
[430] | 445 | |
---|
| 446 | IPosition vecShape(1,shape(asap::ChanAxis)); |
---|
| 447 | Vector<Float> outV = out.reform(vecShape); |
---|
[455] | 448 | std::vector<float> stlout; |
---|
| 449 | outV.tovector(stlout); |
---|
| 450 | |
---|
| 451 | return stlout; |
---|
[430] | 452 | } |
---|
| 453 | |
---|
[418] | 454 | |
---|
[206] | 455 | std::vector<string> SDMemTable::getCoordInfo() const |
---|
| 456 | { |
---|
[105] | 457 | String un; |
---|
| 458 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 459 | String sunit; |
---|
| 460 | t.keywordSet().get("UNIT",sunit); |
---|
| 461 | String dpl; |
---|
| 462 | t.keywordSet().get("DOPPLER",dpl); |
---|
| 463 | if (dpl == "") dpl = "RADIO"; |
---|
| 464 | String rfrm; |
---|
| 465 | t.keywordSet().get("REFFRAME",rfrm); |
---|
| 466 | std::vector<string> inf; |
---|
| 467 | inf.push_back(sunit); |
---|
| 468 | inf.push_back(rfrm); |
---|
| 469 | inf.push_back(dpl); |
---|
[263] | 470 | t.keywordSet().get("BASEREFFRAME",rfrm); |
---|
| 471 | inf.push_back(rfrm); |
---|
[105] | 472 | return inf; |
---|
| 473 | } |
---|
[39] | 474 | |
---|
[206] | 475 | void SDMemTable::setCoordInfo(std::vector<string> theinfo) |
---|
| 476 | { |
---|
[105] | 477 | std::vector<string>::iterator it; |
---|
[306] | 478 | String un,rfrm, brfrm,dpl; |
---|
| 479 | un = theinfo[0]; // Abcissa unit |
---|
| 480 | rfrm = theinfo[1]; // Active (or conversion) frame |
---|
| 481 | dpl = theinfo[2]; // Doppler |
---|
| 482 | brfrm = theinfo[3]; // Base frame |
---|
[455] | 483 | |
---|
[105] | 484 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); |
---|
[455] | 485 | |
---|
[105] | 486 | Vector<Double> rstf; |
---|
| 487 | t.keywordSet().get("RESTFREQS",rstf); |
---|
[455] | 488 | |
---|
[105] | 489 | Bool canDo = True; |
---|
| 490 | Unit u1("km/s");Unit u2("Hz"); |
---|
| 491 | if (Unit(un) == u1) { |
---|
| 492 | Vector<Double> rstf; |
---|
| 493 | t.keywordSet().get("RESTFREQS",rstf); |
---|
| 494 | if (rstf.nelements() == 0) { |
---|
| 495 | throw(AipsError("Can't set unit to km/s if no restfrequencies are specified")); |
---|
| 496 | } |
---|
| 497 | } else if (Unit(un) != u2 && un != "") { |
---|
| 498 | throw(AipsError("Unit not conformant with Spectral Coordinates")); |
---|
| 499 | } |
---|
| 500 | t.rwKeywordSet().define("UNIT", un); |
---|
[455] | 501 | |
---|
[105] | 502 | MFrequency::Types mdr; |
---|
| 503 | if (!MFrequency::getType(mdr, rfrm)) { |
---|
| 504 | |
---|
| 505 | Int a,b;const uInt* c; |
---|
| 506 | const String* valid = MFrequency::allMyTypes(a, b, c); |
---|
| 507 | String pfix = "Please specify a legal frame type. Types are\n"; |
---|
| 508 | throw(AipsError(pfix+(*valid))); |
---|
| 509 | } else { |
---|
| 510 | t.rwKeywordSet().define("REFFRAME",rfrm); |
---|
| 511 | } |
---|
[455] | 512 | |
---|
[275] | 513 | MDoppler::Types dtype; |
---|
| 514 | dpl.upcase(); |
---|
| 515 | if (!MDoppler::getType(dtype, dpl)) { |
---|
| 516 | throw(AipsError("Doppler type unknown")); |
---|
| 517 | } else { |
---|
| 518 | t.rwKeywordSet().define("DOPPLER",dpl); |
---|
| 519 | } |
---|
[455] | 520 | |
---|
[306] | 521 | if (!MFrequency::getType(mdr, brfrm)) { |
---|
| 522 | Int a,b;const uInt* c; |
---|
| 523 | const String* valid = MFrequency::allMyTypes(a, b, c); |
---|
| 524 | String pfix = "Please specify a legal frame type. Types are\n"; |
---|
| 525 | throw(AipsError(pfix+(*valid))); |
---|
| 526 | } else { |
---|
| 527 | t.rwKeywordSet().define("BASEREFFRAME",brfrm); |
---|
| 528 | } |
---|
[105] | 529 | } |
---|
| 530 | |
---|
[286] | 531 | |
---|
[206] | 532 | std::vector<double> SDMemTable::getAbcissa(Int whichRow) const |
---|
| 533 | { |
---|
[286] | 534 | std::vector<double> abc(nChan()); |
---|
[206] | 535 | |
---|
[455] | 536 | // Get header units keyword |
---|
[286] | 537 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
[105] | 538 | String sunit; |
---|
| 539 | t.keywordSet().get("UNIT",sunit); |
---|
| 540 | if (sunit == "") sunit = "pixel"; |
---|
| 541 | Unit u(sunit); |
---|
[286] | 542 | |
---|
[455] | 543 | // Easy if just wanting pixels |
---|
[286] | 544 | if (sunit==String("pixel")) { |
---|
| 545 | // assume channels/pixels |
---|
| 546 | std::vector<double>::iterator it; |
---|
| 547 | uInt i=0; |
---|
| 548 | for (it = abc.begin(); it != abc.end(); ++it) { |
---|
| 549 | (*it) = Double(i++); |
---|
| 550 | } |
---|
| 551 | return abc; |
---|
[78] | 552 | } |
---|
| 553 | |
---|
[455] | 554 | // Continue with km/s or Hz. Get FreqIDs |
---|
[347] | 555 | Vector<uInt> freqIDs; |
---|
| 556 | freqidCol_.get(whichRow, freqIDs); |
---|
| 557 | uInt freqID = freqIDs(IFSel_); |
---|
[386] | 558 | restfreqidCol_.get(whichRow, freqIDs); |
---|
| 559 | uInt restFreqID = freqIDs(IFSel_); |
---|
[286] | 560 | |
---|
[455] | 561 | // Get SpectralCoordinate, set reference frame conversion, |
---|
| 562 | // velocity conversion, and rest freq state |
---|
[286] | 563 | |
---|
[386] | 564 | SpectralCoordinate spc = getSpectralCoordinate(freqID, restFreqID, whichRow); |
---|
[286] | 565 | Vector<Double> pixel(nChan()); |
---|
| 566 | indgen(pixel); |
---|
[455] | 567 | |
---|
[286] | 568 | if (u == Unit("km/s")) { |
---|
| 569 | Vector<Double> world; |
---|
| 570 | spc.pixelToVelocity(world,pixel); |
---|
| 571 | std::vector<double>::iterator it; |
---|
| 572 | uInt i = 0; |
---|
| 573 | for (it = abc.begin(); it != abc.end(); ++it) { |
---|
| 574 | (*it) = world[i]; |
---|
| 575 | i++; |
---|
| 576 | } |
---|
[39] | 577 | } else if (u == Unit("Hz")) { |
---|
[286] | 578 | |
---|
[455] | 579 | // Set world axis units |
---|
[39] | 580 | Vector<String> wau(1); wau = u.getName(); |
---|
| 581 | spc.setWorldAxisUnits(wau); |
---|
[455] | 582 | |
---|
[39] | 583 | std::vector<double>::iterator it; |
---|
| 584 | Double tmp; |
---|
| 585 | uInt i = 0; |
---|
[286] | 586 | for (it = abc.begin(); it != abc.end(); ++it) { |
---|
| 587 | spc.toWorld(tmp,pixel[i]); |
---|
[39] | 588 | (*it) = tmp; |
---|
| 589 | i++; |
---|
| 590 | } |
---|
| 591 | } |
---|
[286] | 592 | return abc; |
---|
[39] | 593 | } |
---|
| 594 | |
---|
[164] | 595 | std::string SDMemTable::getAbcissaString(Int whichRow) const |
---|
[105] | 596 | { |
---|
| 597 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
[455] | 598 | |
---|
[105] | 599 | String sunit; |
---|
| 600 | t.keywordSet().get("UNIT",sunit); |
---|
| 601 | if (sunit == "") sunit = "pixel"; |
---|
| 602 | Unit u(sunit); |
---|
[455] | 603 | |
---|
[347] | 604 | Vector<uInt> freqIDs; |
---|
| 605 | freqidCol_.get(whichRow, freqIDs); |
---|
[386] | 606 | uInt freqID = freqIDs(IFSel_); |
---|
| 607 | restfreqidCol_.get(whichRow, freqIDs); |
---|
| 608 | uInt restFreqID = freqIDs(IFSel_); |
---|
[286] | 609 | |
---|
[455] | 610 | // Get SpectralCoordinate, with frame, velocity, rest freq state set |
---|
| 611 | SpectralCoordinate spc = getSpectralCoordinate(freqID, restFreqID, whichRow); |
---|
[286] | 612 | |
---|
[105] | 613 | String s = "Channel"; |
---|
| 614 | if (u == Unit("km/s")) { |
---|
| 615 | s = CoordinateUtil::axisLabel(spc,0,True,True,True); |
---|
| 616 | } else if (u == Unit("Hz")) { |
---|
| 617 | Vector<String> wau(1);wau = u.getName(); |
---|
| 618 | spc.setWorldAxisUnits(wau); |
---|
[455] | 619 | |
---|
[286] | 620 | s = CoordinateUtil::axisLabel(spc,0,True,True,False); |
---|
[105] | 621 | } |
---|
| 622 | return s; |
---|
| 623 | } |
---|
| 624 | |
---|
[206] | 625 | void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow) |
---|
| 626 | { |
---|
[89] | 627 | Array<Float> arr; |
---|
[322] | 628 | specCol_.get(whichRow, arr); |
---|
[455] | 629 | if (spectrum.size() != arr.shape()(asap::ChanAxis)) { |
---|
[89] | 630 | throw(AipsError("Attempting to set spectrum with incorrect length.")); |
---|
| 631 | } |
---|
| 632 | |
---|
[455] | 633 | // Setup accessors |
---|
[206] | 634 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); |
---|
[447] | 635 | aa0.reset(aa0.begin(uInt(beamSel_))); // Beam selection |
---|
[206] | 636 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0); |
---|
[447] | 637 | aa1.reset(aa1.begin(uInt(IFSel_))); // IF selection |
---|
[206] | 638 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); |
---|
[447] | 639 | aa2.reset(aa2.begin(uInt(polSel_))); // Pol selection |
---|
[89] | 640 | |
---|
[455] | 641 | // Iterate |
---|
[89] | 642 | std::vector<float>::iterator it = spectrum.begin(); |
---|
[206] | 643 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[89] | 644 | (*i) = Float(*it); |
---|
| 645 | it++; |
---|
| 646 | } |
---|
[322] | 647 | specCol_.put(whichRow, arr); |
---|
[89] | 648 | } |
---|
| 649 | |
---|
[206] | 650 | void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const |
---|
| 651 | { |
---|
[21] | 652 | Array<Float> arr; |
---|
[322] | 653 | specCol_.get(whichRow, arr); |
---|
[418] | 654 | |
---|
[455] | 655 | // Iterate and extract |
---|
[21] | 656 | spectrum.resize(arr.shape()(3)); |
---|
[206] | 657 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); |
---|
[21] | 658 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 659 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0); |
---|
[21] | 660 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 661 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); |
---|
[21] | 662 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
[455] | 663 | |
---|
[206] | 664 | ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum); |
---|
| 665 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[21] | 666 | (*va) = (*i); |
---|
| 667 | va++; |
---|
| 668 | } |
---|
| 669 | } |
---|
[418] | 670 | |
---|
| 671 | |
---|
[89] | 672 | /* |
---|
[68] | 673 | void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const { |
---|
[21] | 674 | Array<uChar> arr; |
---|
[322] | 675 | flagsCol_.get(whichRow, arr); |
---|
[21] | 676 | mask.resize(arr.shape()(3)); |
---|
| 677 | |
---|
[206] | 678 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr); |
---|
[21] | 679 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 680 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0); |
---|
[21] | 681 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 682 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1); |
---|
[21] | 683 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 684 | |
---|
| 685 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) ); |
---|
[89] | 686 | |
---|
[206] | 687 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask); |
---|
[21] | 688 | std::vector<bool> tmp; |
---|
| 689 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The |
---|
[89] | 690 | // iterator should work on chanMask_?? |
---|
[21] | 691 | std::vector<bool>::iterator miter; |
---|
| 692 | miter = tmp.begin(); |
---|
| 693 | |
---|
[206] | 694 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[21] | 695 | bool out =!static_cast<bool>(*i); |
---|
| 696 | if (useUserMask) { |
---|
| 697 | out = out && (*miter); |
---|
| 698 | miter++; |
---|
| 699 | } |
---|
| 700 | (*va) = out; |
---|
| 701 | va++; |
---|
[89] | 702 | } |
---|
[21] | 703 | } |
---|
[89] | 704 | */ |
---|
[447] | 705 | |
---|
[455] | 706 | MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, |
---|
| 707 | Bool toStokes) const |
---|
[164] | 708 | { |
---|
[455] | 709 | // Get flags |
---|
[441] | 710 | Array<uChar> farr; |
---|
| 711 | flagsCol_.get(whichRow, farr); |
---|
| 712 | |
---|
[455] | 713 | // Get data and convert mask to Bool |
---|
[2] | 714 | Array<Float> arr; |
---|
[441] | 715 | Array<Bool> mask; |
---|
[439] | 716 | if (toStokes) { |
---|
| 717 | stokesCol_.get(whichRow, arr); |
---|
[455] | 718 | |
---|
[441] | 719 | Array<Bool> tMask(farr.shape()); |
---|
| 720 | convertArray(tMask, farr); |
---|
[462] | 721 | mask = SDPolUtil::stokesData (tMask, True); |
---|
[439] | 722 | } else { |
---|
| 723 | specCol_.get(whichRow, arr); |
---|
[441] | 724 | mask.resize(farr.shape()); |
---|
| 725 | convertArray(mask, farr); |
---|
[439] | 726 | } |
---|
[455] | 727 | |
---|
[447] | 728 | return MaskedArray<Float>(arr,!mask); |
---|
[2] | 729 | } |
---|
| 730 | |
---|
[206] | 731 | Float SDMemTable::getTsys(Int whichRow) const |
---|
| 732 | { |
---|
[2] | 733 | Array<Float> arr; |
---|
[322] | 734 | tsCol_.get(whichRow, arr); |
---|
[2] | 735 | Float out; |
---|
[455] | 736 | |
---|
[2] | 737 | IPosition ip(arr.shape()); |
---|
[418] | 738 | ip(asap::BeamAxis) = beamSel_; |
---|
| 739 | ip(asap::IFAxis) = IFSel_; |
---|
| 740 | ip(asap::PolAxis) = polSel_; |
---|
| 741 | ip(asap::ChanAxis)=0; // First channel only |
---|
[455] | 742 | |
---|
[2] | 743 | out = arr(ip); |
---|
| 744 | return out; |
---|
| 745 | } |
---|
| 746 | |
---|
[281] | 747 | MDirection SDMemTable::getDirection(Int whichRow, Bool refBeam) const |
---|
[206] | 748 | { |
---|
[212] | 749 | MDirection::Types mdr = getDirectionReference(); |
---|
[206] | 750 | Array<Double> posit; |
---|
[322] | 751 | dirCol_.get(whichRow,posit); |
---|
[206] | 752 | Vector<Double> wpos(2); |
---|
[380] | 753 | Int rb; |
---|
| 754 | rbeamCol_.get(whichRow,rb); |
---|
[206] | 755 | wpos[0] = posit(IPosition(2,beamSel_,0)); |
---|
| 756 | wpos[1] = posit(IPosition(2,beamSel_,1)); |
---|
[380] | 757 | if (refBeam && rb > -1) { // use refBeam instead if it exists |
---|
| 758 | wpos[0] = posit(IPosition(2,rb,0)); |
---|
| 759 | wpos[1] = posit(IPosition(2,rb,1)); |
---|
| 760 | } |
---|
| 761 | |
---|
[206] | 762 | Quantum<Double> lon(wpos[0],Unit(String("rad"))); |
---|
| 763 | Quantum<Double> lat(wpos[1],Unit(String("rad"))); |
---|
[286] | 764 | return MDirection(lon, lat, mdr); |
---|
[206] | 765 | } |
---|
[39] | 766 | |
---|
[380] | 767 | MEpoch SDMemTable::getEpoch(Int whichRow) const |
---|
[206] | 768 | { |
---|
[286] | 769 | MEpoch::Types met = getTimeReference(); |
---|
[455] | 770 | |
---|
[286] | 771 | Double obstime; |
---|
[322] | 772 | timeCol_.get(whichRow,obstime); |
---|
[286] | 773 | MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d")))); |
---|
| 774 | return MEpoch(tm2, met); |
---|
| 775 | } |
---|
| 776 | |
---|
| 777 | MPosition SDMemTable::getAntennaPosition () const |
---|
| 778 | { |
---|
| 779 | Vector<Double> antpos; |
---|
| 780 | table_.keywordSet().get("AntennaPosition", antpos); |
---|
| 781 | MVPosition mvpos(antpos(0),antpos(1),antpos(2)); |
---|
| 782 | return MPosition(mvpos); |
---|
| 783 | } |
---|
| 784 | |
---|
| 785 | |
---|
[347] | 786 | SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID) const |
---|
[286] | 787 | { |
---|
[206] | 788 | |
---|
[39] | 789 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
[347] | 790 | if (freqID> t.nrow() ) { |
---|
| 791 | throw(AipsError("SDMemTable::getSpectralCoordinate - freqID out of range")); |
---|
[39] | 792 | } |
---|
[89] | 793 | |
---|
[39] | 794 | Double rp,rv,inc; |
---|
| 795 | String rf; |
---|
| 796 | ROScalarColumn<Double> rpc(t, "REFPIX"); |
---|
| 797 | ROScalarColumn<Double> rvc(t, "REFVAL"); |
---|
| 798 | ROScalarColumn<Double> incc(t, "INCREMENT"); |
---|
[105] | 799 | t.keywordSet().get("BASEREFFRAME",rf); |
---|
[89] | 800 | |
---|
[455] | 801 | // Create SpectralCoordinate (units Hz) |
---|
[39] | 802 | MFrequency::Types mft; |
---|
| 803 | if (!MFrequency::getType(mft, rf)) { |
---|
| 804 | cerr << "Frequency type unknown assuming TOPO" << endl; |
---|
[89] | 805 | mft = MFrequency::TOPO; |
---|
| 806 | } |
---|
[347] | 807 | rpc.get(freqID, rp); |
---|
| 808 | rvc.get(freqID, rv); |
---|
| 809 | incc.get(freqID, inc); |
---|
[455] | 810 | |
---|
[39] | 811 | SpectralCoordinate spec(mft,rv,inc,rp); |
---|
[286] | 812 | return spec; |
---|
| 813 | } |
---|
| 814 | |
---|
| 815 | |
---|
[455] | 816 | SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID, |
---|
| 817 | uInt restFreqID, |
---|
[386] | 818 | uInt whichRow) const |
---|
[286] | 819 | { |
---|
[455] | 820 | |
---|
| 821 | // Create basic SC |
---|
| 822 | SpectralCoordinate spec = getSpectralCoordinate (freqID); |
---|
[385] | 823 | |
---|
[286] | 824 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 825 | |
---|
[455] | 826 | // Set rest frequency |
---|
[386] | 827 | Vector<Double> restFreqIDs; |
---|
| 828 | t.keywordSet().get("RESTFREQS",restFreqIDs); |
---|
[455] | 829 | if (restFreqID < restFreqIDs.nelements()) { // Should always be true |
---|
[386] | 830 | spec.setRestFrequency(restFreqIDs(restFreqID),True); |
---|
[286] | 831 | } |
---|
| 832 | |
---|
[455] | 833 | // Set up frame conversion layer |
---|
[286] | 834 | String frm; |
---|
| 835 | t.keywordSet().get("REFFRAME",frm); |
---|
| 836 | if (frm == "") frm = "TOPO"; |
---|
| 837 | MFrequency::Types mtype; |
---|
| 838 | if (!MFrequency::getType(mtype, frm)) { |
---|
[455] | 839 | // Should never happen |
---|
| 840 | cerr << "Frequency type unknown assuming TOPO" << endl; |
---|
[286] | 841 | mtype = MFrequency::TOPO; |
---|
| 842 | } |
---|
| 843 | |
---|
[455] | 844 | // Set reference frame conversion (requires row) |
---|
[401] | 845 | MDirection dir = getDirection(whichRow); |
---|
[286] | 846 | MEpoch epoch = getEpoch(whichRow); |
---|
| 847 | MPosition pos = getAntennaPosition(); |
---|
[455] | 848 | |
---|
[401] | 849 | if (!spec.setReferenceConversion(mtype,epoch,pos,dir)) { |
---|
[286] | 850 | throw(AipsError("Couldn't convert frequency frame.")); |
---|
| 851 | } |
---|
| 852 | |
---|
[455] | 853 | // Now velocity conversion if appropriate |
---|
[286] | 854 | String unitStr; |
---|
| 855 | t.keywordSet().get("UNIT",unitStr); |
---|
[455] | 856 | |
---|
[286] | 857 | String dpl; |
---|
| 858 | t.keywordSet().get("DOPPLER",dpl); |
---|
| 859 | MDoppler::Types dtype; |
---|
| 860 | MDoppler::getType(dtype, dpl); |
---|
| 861 | |
---|
[455] | 862 | // Only set velocity unit if non-blank and non-Hz |
---|
[286] | 863 | if (!unitStr.empty()) { |
---|
| 864 | Unit unitU(unitStr); |
---|
| 865 | if (unitU==Unit("Hz")) { |
---|
| 866 | } else { |
---|
| 867 | spec.setVelocity(unitStr, dtype); |
---|
| 868 | } |
---|
| 869 | } |
---|
[455] | 870 | |
---|
[39] | 871 | return spec; |
---|
| 872 | } |
---|
| 873 | |
---|
[286] | 874 | |
---|
[89] | 875 | Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord, |
---|
[347] | 876 | uInt freqID) { |
---|
[50] | 877 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); |
---|
[347] | 878 | if (freqID > t.nrow() ) { |
---|
[89] | 879 | throw(AipsError("SDMemTable::setCoordinate - coord no out of range")); |
---|
[50] | 880 | } |
---|
| 881 | ScalarColumn<Double> rpc(t, "REFPIX"); |
---|
| 882 | ScalarColumn<Double> rvc(t, "REFVAL"); |
---|
| 883 | ScalarColumn<Double> incc(t, "INCREMENT"); |
---|
[89] | 884 | |
---|
[347] | 885 | rpc.put(freqID, speccord.referencePixel()[0]); |
---|
| 886 | rvc.put(freqID, speccord.referenceValue()[0]); |
---|
| 887 | incc.put(freqID, speccord.increment()[0]); |
---|
[50] | 888 | |
---|
| 889 | return True; |
---|
| 890 | } |
---|
| 891 | |
---|
[89] | 892 | Int SDMemTable::nCoordinates() const |
---|
| 893 | { |
---|
| 894 | return table_.keywordSet().asTable("FREQUENCIES").nrow(); |
---|
| 895 | } |
---|
[50] | 896 | |
---|
[89] | 897 | |
---|
[251] | 898 | std::vector<double> SDMemTable::getRestFreqs() const |
---|
| 899 | { |
---|
| 900 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
| 901 | Vector<Double> tvec; |
---|
| 902 | t.keywordSet().get("RESTFREQS",tvec); |
---|
| 903 | std::vector<double> stlout; |
---|
| 904 | tvec.tovector(stlout); |
---|
| 905 | return stlout; |
---|
| 906 | } |
---|
| 907 | |
---|
[206] | 908 | bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft) |
---|
| 909 | { |
---|
[39] | 910 | TableDesc td("", "1", TableDesc::Scratch); |
---|
| 911 | td.addColumn(ScalarColumnDesc<Double>("REFPIX")); |
---|
| 912 | td.addColumn(ScalarColumnDesc<Double>("REFVAL")); |
---|
| 913 | td.addColumn(ScalarColumnDesc<Double>("INCREMENT")); |
---|
| 914 | SetupNewTable aNewTab("freqs", td, Table::New); |
---|
| 915 | Table aTable (aNewTab, Table::Memory, sdft.length()); |
---|
| 916 | ScalarColumn<Double> sc0(aTable, "REFPIX"); |
---|
| 917 | ScalarColumn<Double> sc1(aTable, "REFVAL"); |
---|
| 918 | ScalarColumn<Double> sc2(aTable, "INCREMENT"); |
---|
| 919 | for (uInt i=0; i < sdft.length(); ++i) { |
---|
| 920 | sc0.put(i,sdft.referencePixel(i)); |
---|
| 921 | sc1.put(i,sdft.referenceValue(i)); |
---|
| 922 | sc2.put(i,sdft.increment(i)); |
---|
| 923 | } |
---|
[105] | 924 | String rf = sdft.refFrame(); |
---|
| 925 | if (rf.contains("TOPO")) rf = "TOPO"; |
---|
| 926 | |
---|
| 927 | aTable.rwKeywordSet().define("BASEREFFRAME", rf); |
---|
| 928 | aTable.rwKeywordSet().define("REFFRAME", rf); |
---|
[39] | 929 | aTable.rwKeywordSet().define("EQUINOX", sdft.equinox()); |
---|
[105] | 930 | aTable.rwKeywordSet().define("UNIT", String("")); |
---|
| 931 | aTable.rwKeywordSet().define("DOPPLER", String("RADIO")); |
---|
[89] | 932 | Vector<Double> rfvec; |
---|
[206] | 933 | String rfunit; |
---|
| 934 | sdft.restFrequencies(rfvec,rfunit); |
---|
| 935 | Quantum<Vector<Double> > q(rfvec, rfunit); |
---|
| 936 | rfvec.resize(); |
---|
| 937 | rfvec = q.getValue("Hz"); |
---|
[89] | 938 | aTable.rwKeywordSet().define("RESTFREQS", rfvec); |
---|
[455] | 939 | table_.rwKeywordSet().defineTable("FREQUENCIES", aTable); |
---|
| 940 | return true; |
---|
[39] | 941 | } |
---|
| 942 | |
---|
[455] | 943 | bool SDMemTable::putSDFitTable(const SDFitTable& sdft) |
---|
| 944 | { |
---|
| 945 | TableDesc td("", "1", TableDesc::Scratch); |
---|
| 946 | td.addColumn(ArrayColumnDesc<String>("FUNCTIONS")); |
---|
| 947 | td.addColumn(ArrayColumnDesc<Int>("COMPONENTS")); |
---|
| 948 | td.addColumn(ArrayColumnDesc<Double>("PARAMETERS")); |
---|
| 949 | td.addColumn(ArrayColumnDesc<Bool>("PARMASK")); |
---|
| 950 | SetupNewTable aNewTab("fits", td, Table::New); |
---|
| 951 | Table aTable(aNewTab, Table::Memory); |
---|
| 952 | ArrayColumn<String> sc0(aTable, "FUNCTIONS"); |
---|
| 953 | ArrayColumn<Int> sc1(aTable, "COMPONENTS"); |
---|
| 954 | ArrayColumn<Double> sc2(aTable, "PARAMETERS"); |
---|
| 955 | ArrayColumn<Bool> sc3(aTable, "PARMASK"); |
---|
| 956 | for (uInt i; i<sdft.length(); ++i) { |
---|
| 957 | const Vector<Double>& parms = sdft.getFitParameters(i); |
---|
| 958 | const Vector<Bool>& parmask = sdft.getFitParameterMask(i); |
---|
| 959 | const Vector<String>& funcs = sdft.getFitFunctions(i); |
---|
| 960 | const Vector<Int>& comps = sdft.getFitComponents(i); |
---|
| 961 | sc0.put(i,funcs); |
---|
| 962 | sc1.put(i,comps); |
---|
| 963 | sc3.put(i,parmask); |
---|
| 964 | sc2.put(i,parms); |
---|
| 965 | } |
---|
| 966 | table_.rwKeywordSet().defineTable("FITS", aTable); |
---|
| 967 | return true; |
---|
| 968 | } |
---|
| 969 | |
---|
| 970 | SDFitTable SDMemTable::getSDFitTable() const |
---|
| 971 | { |
---|
| 972 | const Table& t = table_.keywordSet().asTable("FITS"); |
---|
| 973 | Vector<Double> parms; |
---|
| 974 | Vector<Bool> parmask; |
---|
| 975 | Vector<String> funcs; |
---|
| 976 | Vector<Int> comps; |
---|
| 977 | ROArrayColumn<Double> parmsCol(t, "PARAMETERS"); |
---|
| 978 | ROArrayColumn<Bool> parmaskCol(t, "PARMASK"); |
---|
| 979 | ROArrayColumn<Int> compsCol(t, "COMPONENTS"); |
---|
| 980 | ROArrayColumn<String> funcsCol(t, "FUNCTIONS"); |
---|
| 981 | uInt n = t.nrow(); |
---|
| 982 | SDFitTable sdft(n); |
---|
| 983 | for (uInt i=0; i<n; ++i) { |
---|
| 984 | parmaskCol.get(i, parmask); |
---|
| 985 | sdft.putFitParameterMask(i, parmask); |
---|
| 986 | parmsCol.get(i, parms); |
---|
| 987 | sdft.putFitParameters(i, parms); |
---|
| 988 | funcsCol.get(i, funcs); |
---|
| 989 | sdft.putFitFunctions(i, funcs); |
---|
| 990 | compsCol.get(i, comps); |
---|
| 991 | sdft.putFitComponents(i, comps); |
---|
| 992 | } |
---|
| 993 | return sdft; |
---|
| 994 | } |
---|
| 995 | |
---|
| 996 | |
---|
| 997 | void SDMemTable::addFit(uInt whichRow, |
---|
| 998 | const Vector<Double>& p, const Vector<Bool>& m, |
---|
| 999 | const Vector<String>& f, const Vector<Int>& c) |
---|
| 1000 | { |
---|
| 1001 | if (whichRow >= nRow()) { |
---|
| 1002 | throw(AipsError("Specified row out of range")); |
---|
| 1003 | } |
---|
| 1004 | Table t = table_.keywordSet().asTable("FITS"); |
---|
| 1005 | uInt nrow = t.nrow(); |
---|
| 1006 | t.addRow(); |
---|
| 1007 | ArrayColumn<Double> parmsCol(t, "PARAMETERS"); |
---|
| 1008 | ArrayColumn<Bool> parmaskCol(t, "PARMASK"); |
---|
| 1009 | ArrayColumn<Int> compsCol(t, "COMPONENTS"); |
---|
| 1010 | ArrayColumn<String> funcsCol(t, "FUNCTIONS"); |
---|
| 1011 | parmsCol.put(nrow, p); |
---|
| 1012 | parmaskCol.put(nrow, m); |
---|
| 1013 | compsCol.put(nrow, c); |
---|
| 1014 | funcsCol.put(nrow, f); |
---|
| 1015 | |
---|
| 1016 | Array<Int> fitarr; |
---|
| 1017 | fitCol_.get(whichRow, fitarr); |
---|
| 1018 | |
---|
| 1019 | Array<Int> newarr; // The new Array containing the fitid |
---|
| 1020 | Int pos =-1; // The fitid position in the array |
---|
| 1021 | if ( fitarr.nelements() == 0 ) { // no fits at all in this row |
---|
| 1022 | Array<Int> arr(IPosition(4,nBeam(),nIF(),nPol(),1)); |
---|
| 1023 | arr = -1; |
---|
| 1024 | newarr.reference(arr); |
---|
| 1025 | pos = 0; |
---|
| 1026 | } else { |
---|
| 1027 | IPosition shp = fitarr.shape(); |
---|
| 1028 | IPosition start(4, beamSel_, IFSel_, polSel_,0); |
---|
| 1029 | IPosition end(4, beamSel_, IFSel_, polSel_, shp[3]-1); |
---|
| 1030 | // reform the output array slice to be of dim=1 |
---|
| 1031 | Array<Int> tmp = (fitarr(start, end)).reform(IPosition(1,shp[3])); |
---|
| 1032 | const Vector<Int>& fits = tmp; |
---|
| 1033 | VectorSTLIterator<Int> it(fits); |
---|
| 1034 | Int i = 0; |
---|
| 1035 | while (it != fits.end()) { |
---|
| 1036 | if (*it == -1) { |
---|
| 1037 | pos = i; |
---|
| 1038 | break; |
---|
| 1039 | } |
---|
| 1040 | ++i; |
---|
| 1041 | ++it; |
---|
| 1042 | }; |
---|
| 1043 | } |
---|
| 1044 | if (pos == -1) { |
---|
| 1045 | mathutil::extendLastArrayAxis(newarr,fitarr, -1); |
---|
| 1046 | pos = fitarr.shape()[3]; // the new element position |
---|
| 1047 | } else { |
---|
| 1048 | if (fitarr.nelements() > 0) |
---|
| 1049 | newarr = fitarr; |
---|
| 1050 | } |
---|
| 1051 | newarr(IPosition(4, beamSel_, IFSel_, polSel_, pos)) = Int(nrow); |
---|
| 1052 | fitCol_.put(whichRow, newarr); |
---|
| 1053 | |
---|
| 1054 | } |
---|
| 1055 | |
---|
[206] | 1056 | SDFrequencyTable SDMemTable::getSDFreqTable() const |
---|
| 1057 | { |
---|
[251] | 1058 | const Table& t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
[39] | 1059 | SDFrequencyTable sdft; |
---|
[306] | 1060 | |
---|
[455] | 1061 | // Add refpix/refval/incr. What are the units ? Hz I suppose |
---|
| 1062 | // but it's nowhere described... |
---|
[306] | 1063 | Vector<Double> refPix, refVal, incr; |
---|
| 1064 | ScalarColumn<Double> refPixCol(t, "REFPIX"); |
---|
| 1065 | ScalarColumn<Double> refValCol(t, "REFVAL"); |
---|
| 1066 | ScalarColumn<Double> incrCol(t, "INCREMENT"); |
---|
| 1067 | refPix = refPixCol.getColumn(); |
---|
| 1068 | refVal = refValCol.getColumn(); |
---|
| 1069 | incr = incrCol.getColumn(); |
---|
[455] | 1070 | |
---|
[306] | 1071 | uInt n = refPix.nelements(); |
---|
| 1072 | for (uInt i=0; i<n; i++) { |
---|
| 1073 | sdft.addFrequency(refPix[i], refVal[i], incr[i]); |
---|
| 1074 | } |
---|
| 1075 | |
---|
[455] | 1076 | // Frequency reference frame. I don't know if this |
---|
| 1077 | // is the correct frame. It might be 'REFFRAME' |
---|
| 1078 | // rather than 'BASEREFFRAME' ? |
---|
[306] | 1079 | String baseFrame; |
---|
| 1080 | t.keywordSet().get("BASEREFFRAME",baseFrame); |
---|
| 1081 | sdft.setRefFrame(baseFrame); |
---|
| 1082 | |
---|
[455] | 1083 | // Equinox |
---|
[306] | 1084 | Float equinox; |
---|
| 1085 | t.keywordSet().get("EQUINOX", equinox); |
---|
| 1086 | sdft.setEquinox(equinox); |
---|
| 1087 | |
---|
[455] | 1088 | // Rest Frequency |
---|
[306] | 1089 | Vector<Double> restFreqs; |
---|
| 1090 | t.keywordSet().get("RESTFREQS", restFreqs); |
---|
| 1091 | for (uInt i=0; i<restFreqs.nelements(); i++) { |
---|
| 1092 | sdft.addRestFrequency(restFreqs[i]); |
---|
| 1093 | } |
---|
| 1094 | sdft.setRestFrequencyUnit(String("Hz")); |
---|
[455] | 1095 | |
---|
[39] | 1096 | return sdft; |
---|
| 1097 | } |
---|
| 1098 | |
---|
[206] | 1099 | bool SDMemTable::putSDContainer(const SDContainer& sdc) |
---|
| 1100 | { |
---|
[2] | 1101 | uInt rno = table_.nrow(); |
---|
| 1102 | table_.addRow(); |
---|
[455] | 1103 | |
---|
[322] | 1104 | timeCol_.put(rno, sdc.timestamp); |
---|
| 1105 | srcnCol_.put(rno, sdc.sourcename); |
---|
| 1106 | fldnCol_.put(rno, sdc.fieldname); |
---|
| 1107 | specCol_.put(rno, sdc.getSpectrum()); |
---|
| 1108 | flagsCol_.put(rno, sdc.getFlags()); |
---|
| 1109 | tsCol_.put(rno, sdc.getTsys()); |
---|
| 1110 | scanCol_.put(rno, sdc.scanid); |
---|
| 1111 | integrCol_.put(rno, sdc.interval); |
---|
| 1112 | freqidCol_.put(rno, sdc.getFreqMap()); |
---|
[386] | 1113 | restfreqidCol_.put(rno, sdc.getRestFreqMap()); |
---|
[322] | 1114 | dirCol_.put(rno, sdc.getDirection()); |
---|
| 1115 | rbeamCol_.put(rno, sdc.refbeam); |
---|
| 1116 | tcalCol_.put(rno, sdc.tcal); |
---|
| 1117 | tcaltCol_.put(rno, sdc.tcaltime); |
---|
| 1118 | azCol_.put(rno, sdc.azimuth); |
---|
| 1119 | elCol_.put(rno, sdc.elevation); |
---|
| 1120 | paraCol_.put(rno, sdc.parangle); |
---|
| 1121 | histCol_.put(rno, sdc.getHistory()); |
---|
[455] | 1122 | fitCol_.put(rno, sdc.getFitMap()); |
---|
| 1123 | |
---|
[2] | 1124 | return true; |
---|
| 1125 | } |
---|
[18] | 1126 | |
---|
[206] | 1127 | SDContainer SDMemTable::getSDContainer(uInt whichRow) const |
---|
| 1128 | { |
---|
[21] | 1129 | SDContainer sdc(nBeam(),nIF(),nPol(),nChan()); |
---|
[322] | 1130 | timeCol_.get(whichRow, sdc.timestamp); |
---|
| 1131 | srcnCol_.get(whichRow, sdc.sourcename); |
---|
| 1132 | integrCol_.get(whichRow, sdc.interval); |
---|
| 1133 | scanCol_.get(whichRow, sdc.scanid); |
---|
| 1134 | fldnCol_.get(whichRow, sdc.fieldname); |
---|
| 1135 | rbeamCol_.get(whichRow, sdc.refbeam); |
---|
| 1136 | azCol_.get(whichRow, sdc.azimuth); |
---|
| 1137 | elCol_.get(whichRow, sdc.elevation); |
---|
| 1138 | paraCol_.get(whichRow, sdc.parangle); |
---|
[105] | 1139 | Vector<Float> tc; |
---|
[322] | 1140 | tcalCol_.get(whichRow, tc); |
---|
[105] | 1141 | sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1]; |
---|
[322] | 1142 | tcaltCol_.get(whichRow, sdc.tcaltime); |
---|
[455] | 1143 | |
---|
[21] | 1144 | Array<Float> spectrum; |
---|
| 1145 | Array<Float> tsys; |
---|
| 1146 | Array<uChar> flagtrum; |
---|
[39] | 1147 | Vector<uInt> fmap; |
---|
[78] | 1148 | Array<Double> direction; |
---|
[206] | 1149 | Vector<String> histo; |
---|
[455] | 1150 | Array<Int> fits; |
---|
| 1151 | |
---|
[322] | 1152 | specCol_.get(whichRow, spectrum); |
---|
[21] | 1153 | sdc.putSpectrum(spectrum); |
---|
[322] | 1154 | flagsCol_.get(whichRow, flagtrum); |
---|
[21] | 1155 | sdc.putFlags(flagtrum); |
---|
[322] | 1156 | tsCol_.get(whichRow, tsys); |
---|
[21] | 1157 | sdc.putTsys(tsys); |
---|
[322] | 1158 | freqidCol_.get(whichRow, fmap); |
---|
[39] | 1159 | sdc.putFreqMap(fmap); |
---|
[386] | 1160 | restfreqidCol_.get(whichRow, fmap); |
---|
| 1161 | sdc.putRestFreqMap(fmap); |
---|
[322] | 1162 | dirCol_.get(whichRow, direction); |
---|
[78] | 1163 | sdc.putDirection(direction); |
---|
[322] | 1164 | histCol_.get(whichRow, histo); |
---|
[206] | 1165 | sdc.putHistory(histo); |
---|
[455] | 1166 | fitCol_.get(whichRow, fits); |
---|
| 1167 | sdc.putFitMap(fits); |
---|
[21] | 1168 | return sdc; |
---|
| 1169 | } |
---|
[78] | 1170 | |
---|
[206] | 1171 | bool SDMemTable::putSDHeader(const SDHeader& sdh) |
---|
| 1172 | { |
---|
[18] | 1173 | table_.rwKeywordSet().define("nIF", sdh.nif); |
---|
| 1174 | table_.rwKeywordSet().define("nBeam", sdh.nbeam); |
---|
| 1175 | table_.rwKeywordSet().define("nPol", sdh.npol); |
---|
| 1176 | table_.rwKeywordSet().define("nChan", sdh.nchan); |
---|
| 1177 | table_.rwKeywordSet().define("Observer", sdh.observer); |
---|
| 1178 | table_.rwKeywordSet().define("Project", sdh.project); |
---|
| 1179 | table_.rwKeywordSet().define("Obstype", sdh.obstype); |
---|
| 1180 | table_.rwKeywordSet().define("AntennaName", sdh.antennaname); |
---|
| 1181 | table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition); |
---|
| 1182 | table_.rwKeywordSet().define("Equinox", sdh.equinox); |
---|
| 1183 | table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref); |
---|
| 1184 | table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq); |
---|
| 1185 | table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth); |
---|
| 1186 | table_.rwKeywordSet().define("UTC", sdh.utc); |
---|
[206] | 1187 | table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit); |
---|
| 1188 | table_.rwKeywordSet().define("Epoch", sdh.epoch); |
---|
[18] | 1189 | return true; |
---|
[50] | 1190 | } |
---|
[21] | 1191 | |
---|
[206] | 1192 | SDHeader SDMemTable::getSDHeader() const |
---|
| 1193 | { |
---|
[21] | 1194 | SDHeader sdh; |
---|
| 1195 | table_.keywordSet().get("nBeam",sdh.nbeam); |
---|
| 1196 | table_.keywordSet().get("nIF",sdh.nif); |
---|
| 1197 | table_.keywordSet().get("nPol",sdh.npol); |
---|
| 1198 | table_.keywordSet().get("nChan",sdh.nchan); |
---|
| 1199 | table_.keywordSet().get("Observer", sdh.observer); |
---|
| 1200 | table_.keywordSet().get("Project", sdh.project); |
---|
| 1201 | table_.keywordSet().get("Obstype", sdh.obstype); |
---|
| 1202 | table_.keywordSet().get("AntennaName", sdh.antennaname); |
---|
| 1203 | table_.keywordSet().get("AntennaPosition", sdh.antennaposition); |
---|
| 1204 | table_.keywordSet().get("Equinox", sdh.equinox); |
---|
| 1205 | table_.keywordSet().get("FreqRefFrame", sdh.freqref); |
---|
| 1206 | table_.keywordSet().get("FreqRefVal", sdh.reffreq); |
---|
| 1207 | table_.keywordSet().get("Bandwidth", sdh.bandwidth); |
---|
| 1208 | table_.keywordSet().get("UTC", sdh.utc); |
---|
[206] | 1209 | table_.keywordSet().get("FluxUnit", sdh.fluxunit); |
---|
| 1210 | table_.keywordSet().get("Epoch", sdh.epoch); |
---|
[21] | 1211 | return sdh; |
---|
[18] | 1212 | } |
---|
[206] | 1213 | void SDMemTable::makePersistent(const std::string& filename) |
---|
| 1214 | { |
---|
[2] | 1215 | table_.deepCopy(filename,Table::New); |
---|
| 1216 | } |
---|
| 1217 | |
---|
[89] | 1218 | Int SDMemTable::nScan() const { |
---|
[50] | 1219 | Int n = 0; |
---|
| 1220 | Int previous = -1;Int current=0; |
---|
[322] | 1221 | for (uInt i=0; i< scanCol_.nrow();i++) { |
---|
| 1222 | scanCol_.getScalar(i,current); |
---|
[50] | 1223 | if (previous != current) { |
---|
[89] | 1224 | previous = current; |
---|
[50] | 1225 | n++; |
---|
| 1226 | } |
---|
| 1227 | } |
---|
| 1228 | return n; |
---|
| 1229 | } |
---|
| 1230 | |
---|
[260] | 1231 | String SDMemTable::formatSec(Double x) const |
---|
[206] | 1232 | { |
---|
[105] | 1233 | Double xcop = x; |
---|
| 1234 | MVTime mvt(xcop/24./3600.); // make days |
---|
[365] | 1235 | |
---|
[105] | 1236 | if (x < 59.95) |
---|
[281] | 1237 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s"; |
---|
| 1238 | else if (x < 3599.95) |
---|
| 1239 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" "; |
---|
| 1240 | else { |
---|
| 1241 | ostringstream oss; |
---|
| 1242 | oss << setw(2) << std::right << setprecision(1) << mvt.hour(); |
---|
| 1243 | oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " "; |
---|
| 1244 | return String(oss); |
---|
| 1245 | } |
---|
[105] | 1246 | }; |
---|
| 1247 | |
---|
[281] | 1248 | String SDMemTable::formatDirection(const MDirection& md) const |
---|
| 1249 | { |
---|
| 1250 | Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue(); |
---|
| 1251 | Int prec = 7; |
---|
| 1252 | |
---|
| 1253 | MVAngle mvLon(t[0]); |
---|
| 1254 | String sLon = mvLon.string(MVAngle::TIME,prec); |
---|
| 1255 | MVAngle mvLat(t[1]); |
---|
| 1256 | String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec); |
---|
[380] | 1257 | return sLon + String(" ") + sLat; |
---|
[281] | 1258 | } |
---|
| 1259 | |
---|
| 1260 | |
---|
[206] | 1261 | std::string SDMemTable::getFluxUnit() const |
---|
| 1262 | { |
---|
| 1263 | String tmp; |
---|
| 1264 | table_.keywordSet().get("FluxUnit", tmp); |
---|
| 1265 | return tmp; |
---|
| 1266 | } |
---|
| 1267 | |
---|
[218] | 1268 | void SDMemTable::setFluxUnit(const std::string& unit) |
---|
| 1269 | { |
---|
| 1270 | String tmp(unit); |
---|
| 1271 | Unit tU(tmp); |
---|
| 1272 | if (tU==Unit("K") || tU==Unit("Jy")) { |
---|
| 1273 | table_.rwKeywordSet().define(String("FluxUnit"), tmp); |
---|
| 1274 | } else { |
---|
| 1275 | throw AipsError("Illegal unit - must be compatible with Jy or K"); |
---|
| 1276 | } |
---|
| 1277 | } |
---|
| 1278 | |
---|
[275] | 1279 | |
---|
[236] | 1280 | void SDMemTable::setInstrument(const std::string& name) |
---|
| 1281 | { |
---|
| 1282 | Bool throwIt = True; |
---|
[455] | 1283 | Instrument ins = convertInstrument(name, throwIt); |
---|
[236] | 1284 | String nameU(name); |
---|
| 1285 | nameU.upcase(); |
---|
| 1286 | table_.rwKeywordSet().define(String("AntennaName"), nameU); |
---|
| 1287 | } |
---|
| 1288 | |
---|
[380] | 1289 | std::string SDMemTable::summary(bool verbose) const { |
---|
[281] | 1290 | |
---|
[455] | 1291 | // Format header info |
---|
[89] | 1292 | ostringstream oss; |
---|
| 1293 | oss << endl; |
---|
[380] | 1294 | oss << "--------------------------------------------------------------------------------" << endl; |
---|
[89] | 1295 | oss << " Scan Table Summary" << endl; |
---|
[380] | 1296 | oss << "--------------------------------------------------------------------------------" << endl; |
---|
[89] | 1297 | oss.flags(std::ios_base::left); |
---|
| 1298 | oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl |
---|
| 1299 | << setw(15) << "IFs:" << setw(4) << nIF() << endl |
---|
| 1300 | << setw(15) << "Polarisations:" << setw(4) << nPol() << endl |
---|
| 1301 | << setw(15) << "Channels:" << setw(4) << nChan() << endl; |
---|
| 1302 | oss << endl; |
---|
| 1303 | String tmp; |
---|
| 1304 | table_.keywordSet().get("Observer", tmp); |
---|
| 1305 | oss << setw(15) << "Observer:" << tmp << endl; |
---|
[281] | 1306 | oss << setw(15) << "Obs Date:" << getTime(-1,True) << endl; |
---|
[89] | 1307 | table_.keywordSet().get("Project", tmp); |
---|
| 1308 | oss << setw(15) << "Project:" << tmp << endl; |
---|
| 1309 | table_.keywordSet().get("Obstype", tmp); |
---|
| 1310 | oss << setw(15) << "Obs. Type:" << tmp << endl; |
---|
| 1311 | table_.keywordSet().get("AntennaName", tmp); |
---|
| 1312 | oss << setw(15) << "Antenna Name:" << tmp << endl; |
---|
[206] | 1313 | table_.keywordSet().get("FluxUnit", tmp); |
---|
| 1314 | oss << setw(15) << "Flux Unit:" << tmp << endl; |
---|
[260] | 1315 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
[105] | 1316 | Vector<Double> vec; |
---|
| 1317 | t.keywordSet().get("RESTFREQS",vec); |
---|
| 1318 | oss << setw(15) << "Rest Freqs:"; |
---|
| 1319 | if (vec.nelements() > 0) { |
---|
| 1320 | oss << setprecision(0) << vec << " [Hz]" << endl; |
---|
| 1321 | } else { |
---|
| 1322 | oss << "None set" << endl; |
---|
| 1323 | } |
---|
[158] | 1324 | oss << setw(15) << "Abcissa:" << getAbcissaString() << endl; |
---|
[105] | 1325 | oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] " |
---|
| 1326 | << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl; |
---|
[89] | 1327 | oss << endl; |
---|
[455] | 1328 | |
---|
[385] | 1329 | String dirtype ="Position ("+ MDirection::showType(getDirectionReference()) + ")"; |
---|
[380] | 1330 | oss << setw(5) << "Scan" |
---|
[281] | 1331 | << setw(15) << "Source" |
---|
[380] | 1332 | << setw(24) << dirtype |
---|
[281] | 1333 | << setw(10) << "Time" |
---|
[365] | 1334 | << setw(18) << "Integration" |
---|
[380] | 1335 | << setw(7) << "FreqIDs" << endl; |
---|
| 1336 | oss << "--------------------------------------------------------------------------------" << endl; |
---|
[281] | 1337 | |
---|
[455] | 1338 | // Generate list of scan start and end integrations |
---|
[385] | 1339 | Vector<Int> scanIDs = scanCol_.getColumn(); |
---|
| 1340 | Vector<uInt> startInt, endInt; |
---|
| 1341 | mathutil::scanBoundaries(startInt, endInt, scanIDs); |
---|
[455] | 1342 | |
---|
[385] | 1343 | const uInt nScans = startInt.nelements(); |
---|
[365] | 1344 | String name; |
---|
| 1345 | Vector<uInt> freqIDs, listFQ; |
---|
[385] | 1346 | uInt nInt; |
---|
[455] | 1347 | |
---|
[385] | 1348 | for (uInt i=0; i<nScans; i++) { |
---|
[455] | 1349 | // Get things from first integration of scan |
---|
| 1350 | String time = getTime(startInt(i),False); |
---|
| 1351 | String tInt = formatSec(Double(getInterval(startInt(i)))); |
---|
| 1352 | String posit = formatDirection(getDirection(startInt(i),True)); |
---|
| 1353 | srcnCol_.getScalar(startInt(i),name); |
---|
[367] | 1354 | |
---|
[455] | 1355 | // Find all the FreqIDs in this scan |
---|
| 1356 | listFQ.resize(0); |
---|
| 1357 | for (uInt j=startInt(i); j<endInt(i)+1; j++) { |
---|
| 1358 | freqidCol_.get(j, freqIDs); |
---|
| 1359 | for (uInt k=0; k<freqIDs.nelements(); k++) { |
---|
| 1360 | mathutil::addEntry(listFQ, freqIDs(k)); |
---|
| 1361 | } |
---|
| 1362 | } |
---|
[367] | 1363 | |
---|
[455] | 1364 | nInt = endInt(i) - startInt(i) + 1; |
---|
| 1365 | oss << setw(3) << std::right << i << std::left << setw(2) << " " |
---|
| 1366 | << setw(15) << name |
---|
| 1367 | << setw(24) << posit |
---|
| 1368 | << setw(10) << time |
---|
| 1369 | << setw(3) << std::right << nInt << setw(3) << " x " << std::left |
---|
| 1370 | << setw(6) << tInt |
---|
| 1371 | << " " << listFQ << endl; |
---|
[2] | 1372 | } |
---|
[89] | 1373 | oss << endl; |
---|
[455] | 1374 | oss << "Table contains " << table_.nrow() << " integration(s) in " |
---|
| 1375 | << nScans << " scan(s)." << endl; |
---|
[321] | 1376 | |
---|
[455] | 1377 | // Frequency Table |
---|
[380] | 1378 | if (verbose) { |
---|
| 1379 | std::vector<string> info = getCoordInfo(); |
---|
| 1380 | SDFrequencyTable sdft = getSDFreqTable(); |
---|
| 1381 | oss << endl << endl; |
---|
| 1382 | oss << "FreqID Frame RefFreq(Hz) RefPix Increment(Hz)" << endl; |
---|
| 1383 | oss << "--------------------------------------------------------------------------------" << endl; |
---|
| 1384 | for (uInt i=0; i<sdft.length(); i++) { |
---|
| 1385 | oss << setw(8) << i << setw(8) |
---|
| 1386 | << info[3] << setw(16) << setprecision(8) |
---|
| 1387 | << sdft.referenceValue(i) << setw(10) |
---|
| 1388 | << sdft.referencePixel(i) << setw(12) |
---|
| 1389 | << sdft.increment(i) << endl; |
---|
| 1390 | } |
---|
| 1391 | oss << "--------------------------------------------------------------------------------" << endl; |
---|
[321] | 1392 | } |
---|
[89] | 1393 | return String(oss); |
---|
[2] | 1394 | } |
---|
[18] | 1395 | |
---|
[206] | 1396 | Int SDMemTable::nBeam() const |
---|
| 1397 | { |
---|
[18] | 1398 | Int n; |
---|
| 1399 | table_.keywordSet().get("nBeam",n); |
---|
| 1400 | return n; |
---|
| 1401 | } |
---|
[455] | 1402 | |
---|
[18] | 1403 | Int SDMemTable::nIF() const { |
---|
| 1404 | Int n; |
---|
| 1405 | table_.keywordSet().get("nIF",n); |
---|
| 1406 | return n; |
---|
| 1407 | } |
---|
[455] | 1408 | |
---|
[18] | 1409 | Int SDMemTable::nPol() const { |
---|
| 1410 | Int n; |
---|
| 1411 | table_.keywordSet().get("nPol",n); |
---|
| 1412 | return n; |
---|
| 1413 | } |
---|
[455] | 1414 | |
---|
[18] | 1415 | Int SDMemTable::nChan() const { |
---|
| 1416 | Int n; |
---|
| 1417 | table_.keywordSet().get("nChan",n); |
---|
| 1418 | return n; |
---|
| 1419 | } |
---|
[455] | 1420 | |
---|
[206] | 1421 | bool SDMemTable::appendHistory(const std::string& hist, int whichRow) |
---|
| 1422 | { |
---|
| 1423 | Vector<String> history; |
---|
[322] | 1424 | histCol_.get(whichRow, history); |
---|
[206] | 1425 | history.resize(history.nelements()+1,True); |
---|
| 1426 | history[history.nelements()-1] = hist; |
---|
[322] | 1427 | histCol_.put(whichRow, history); |
---|
[206] | 1428 | } |
---|
| 1429 | |
---|
| 1430 | std::vector<std::string> SDMemTable::history(int whichRow) const |
---|
| 1431 | { |
---|
| 1432 | Vector<String> history; |
---|
[322] | 1433 | histCol_.get(whichRow, history); |
---|
[206] | 1434 | std::vector<std::string> stlout; |
---|
| 1435 | // there is no Array<String>.tovector(std::vector<std::string>), so |
---|
| 1436 | // do it by hand |
---|
| 1437 | for (uInt i=0; i<history.nelements(); ++i) { |
---|
| 1438 | stlout.push_back(history[i]); |
---|
| 1439 | } |
---|
| 1440 | return stlout; |
---|
| 1441 | } |
---|
[16] | 1442 | /* |
---|
[18] | 1443 | void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) { |
---|
[89] | 1444 | |
---|
[16] | 1445 | std::vector<int>::iterator it; |
---|
[206] | 1446 | ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_); |
---|
[16] | 1447 | for (it = whichChans.begin(); it != whichChans.end(); it++) { |
---|
| 1448 | j.reset(j.begin(uInt(*it))); |
---|
[206] | 1449 | for (ArrayAccessor<uChar, Axis<asap::BeamAxis> > i(j); i != i.end(); ++i) { |
---|
| 1450 | for (ArrayAccessor<uChar, Axis<asap::IFAxis> > ii(i); ii != ii.end(); ++ii) { |
---|
| 1451 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > iii(ii); |
---|
[89] | 1452 | iii != iii.end(); ++iii) { |
---|
| 1453 | (*iii) = |
---|
| 1454 | } |
---|
[16] | 1455 | } |
---|
| 1456 | } |
---|
| 1457 | } |
---|
[89] | 1458 | |
---|
[16] | 1459 | } |
---|
| 1460 | */ |
---|
[206] | 1461 | void SDMemTable::flag(int whichRow) |
---|
| 1462 | { |
---|
[89] | 1463 | Array<uChar> arr; |
---|
[322] | 1464 | flagsCol_.get(whichRow, arr); |
---|
[89] | 1465 | |
---|
[206] | 1466 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr); |
---|
[89] | 1467 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
[206] | 1468 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0); |
---|
[89] | 1469 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
[206] | 1470 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1); |
---|
[89] | 1471 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
| 1472 | |
---|
[206] | 1473 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
[89] | 1474 | (*i) = uChar(True); |
---|
| 1475 | } |
---|
| 1476 | |
---|
[322] | 1477 | flagsCol_.put(whichRow, arr); |
---|
[89] | 1478 | } |
---|
[212] | 1479 | |
---|
[281] | 1480 | MDirection::Types SDMemTable::getDirectionReference() const |
---|
[212] | 1481 | { |
---|
| 1482 | Float eq; |
---|
| 1483 | table_.keywordSet().get("Equinox",eq); |
---|
| 1484 | std::map<float,string> mp; |
---|
| 1485 | mp[2000.0] = "J2000"; |
---|
| 1486 | mp[1950.0] = "B1950"; |
---|
| 1487 | MDirection::Types mdr; |
---|
| 1488 | if (!MDirection::getType(mdr, mp[eq])) { |
---|
| 1489 | mdr = MDirection::J2000; |
---|
| 1490 | cerr << "Unknown equinox using J2000" << endl; |
---|
| 1491 | } |
---|
[455] | 1492 | |
---|
[212] | 1493 | return mdr; |
---|
| 1494 | } |
---|
| 1495 | |
---|
[380] | 1496 | MEpoch::Types SDMemTable::getTimeReference() const |
---|
[212] | 1497 | { |
---|
| 1498 | MEpoch::Types met; |
---|
| 1499 | String ep; |
---|
| 1500 | table_.keywordSet().get("Epoch",ep); |
---|
| 1501 | if (!MEpoch::getType(met, ep)) { |
---|
[387] | 1502 | cerr << "Epoch type unknown - using UTC" << endl; |
---|
[212] | 1503 | met = MEpoch::UTC; |
---|
| 1504 | } |
---|
[455] | 1505 | |
---|
[212] | 1506 | return met; |
---|
| 1507 | } |
---|
| 1508 | |
---|
[236] | 1509 | |
---|
[380] | 1510 | Instrument SDMemTable::convertInstrument(const String& instrument, |
---|
| 1511 | Bool throwIt) |
---|
[236] | 1512 | { |
---|
| 1513 | String t(instrument); |
---|
| 1514 | t.upcase(); |
---|
[293] | 1515 | |
---|
[455] | 1516 | // The strings are what SDReader returns, after cunning interrogation |
---|
| 1517 | // of station names... :-( |
---|
[236] | 1518 | Instrument inst = asap::UNKNOWN; |
---|
[293] | 1519 | if (t==String("DSS-43")) { |
---|
[236] | 1520 | inst = TIDBINBILLA; |
---|
| 1521 | } else if (t==String("ATPKSMB")) { |
---|
[292] | 1522 | inst = ATPKSMB; |
---|
| 1523 | } else if (t==String("ATPKSHOH")) { |
---|
| 1524 | inst = ATPKSHOH; |
---|
| 1525 | } else if (t==String("ATMOPRA")) { |
---|
| 1526 | inst = ATMOPRA; |
---|
| 1527 | } else if (t==String("CEDUNA")) { |
---|
| 1528 | inst = CEDUNA; |
---|
| 1529 | } else if (t==String("HOBART")) { |
---|
| 1530 | inst = HOBART; |
---|
[236] | 1531 | } else { |
---|
[380] | 1532 | if (throwIt) { |
---|
| 1533 | throw AipsError("Unrecognized instrument - use function scan.set_instrument to set"); |
---|
| 1534 | } |
---|
[236] | 1535 | } |
---|
| 1536 | return inst; |
---|
| 1537 | } |
---|
| 1538 | |
---|
[455] | 1539 | Bool SDMemTable::setRestFreqs(const Vector<Double>& restFreqsIn, |
---|
| 1540 | const String& sUnit, |
---|
| 1541 | const vector<string>& lines, |
---|
| 1542 | const String& source, |
---|
| 1543 | Int whichIF) |
---|
[386] | 1544 | { |
---|
| 1545 | const Int nIFs = nIF(); |
---|
| 1546 | if (whichIF>=nIFs) { |
---|
| 1547 | throw(AipsError("Illegal IF index")); |
---|
| 1548 | } |
---|
| 1549 | |
---|
[455] | 1550 | // Find vector of restfrequencies |
---|
| 1551 | // Double takes precedence over String |
---|
[401] | 1552 | Unit unit; |
---|
| 1553 | Vector<Double> restFreqs; |
---|
| 1554 | if (restFreqsIn.nelements()>0) { |
---|
| 1555 | restFreqs.resize(restFreqsIn.nelements()); |
---|
| 1556 | restFreqs = restFreqsIn; |
---|
| 1557 | unit = Unit(sUnit); |
---|
| 1558 | } else if (lines.size()>0) { |
---|
| 1559 | const uInt nLines = lines.size(); |
---|
| 1560 | unit = Unit("Hz"); |
---|
| 1561 | restFreqs.resize(nLines); |
---|
| 1562 | MFrequency lineFreq; |
---|
| 1563 | for (uInt i=0; i<nLines; i++) { |
---|
| 1564 | String tS(lines[i]); |
---|
| 1565 | tS.upcase(); |
---|
| 1566 | if (MeasTable::Line(lineFreq, tS)) { |
---|
| 1567 | restFreqs[i] = lineFreq.getValue().getValue(); // Hz |
---|
| 1568 | } else { |
---|
[455] | 1569 | String s = String(lines[i]) + |
---|
| 1570 | String(" is an unrecognized spectral line"); |
---|
[401] | 1571 | throw(AipsError(s)); |
---|
| 1572 | } |
---|
| 1573 | } |
---|
| 1574 | } else { |
---|
| 1575 | throw(AipsError("You have not specified any rest frequencies or lines")); |
---|
| 1576 | } |
---|
| 1577 | |
---|
[455] | 1578 | // If multiple restfreqs, must be length nIF. In this |
---|
| 1579 | // case we will just replace the rest frequencies |
---|
[392] | 1580 | const uInt nRestFreqs = restFreqs.nelements(); |
---|
| 1581 | Int idx = -1; |
---|
[386] | 1582 | SDFrequencyTable sdft = getSDFreqTable(); |
---|
| 1583 | |
---|
[392] | 1584 | if (nRestFreqs>1) { |
---|
[455] | 1585 | // Replace restFreqs, one per IF |
---|
[392] | 1586 | if (nRestFreqs != nIFs) { |
---|
| 1587 | throw (AipsError("Number of rest frequencies must be equal to the number of IFs")); |
---|
| 1588 | } |
---|
[414] | 1589 | cout << "Replacing rest frequencies with given list, one per IF" << endl; |
---|
[392] | 1590 | sdft.deleteRestFrequencies(); |
---|
| 1591 | for (uInt i=0; i<nRestFreqs; i++) { |
---|
| 1592 | Quantum<Double> rf(restFreqs[i], unit); |
---|
| 1593 | sdft.addRestFrequency(rf.getValue("Hz")); |
---|
| 1594 | } |
---|
| 1595 | } else { |
---|
| 1596 | |
---|
[455] | 1597 | // Add new rest freq |
---|
[392] | 1598 | Quantum<Double> rf(restFreqs[0], unit); |
---|
| 1599 | idx = sdft.addRestFrequency(rf.getValue("Hz")); |
---|
[414] | 1600 | cout << "Selecting given rest frequency" << endl; |
---|
[392] | 1601 | } |
---|
[455] | 1602 | |
---|
| 1603 | // Replace |
---|
[386] | 1604 | Bool empty = source.empty(); |
---|
| 1605 | Bool ok = False; |
---|
| 1606 | if (putSDFreqTable(sdft)) { |
---|
| 1607 | const uInt nRow = table_.nrow(); |
---|
| 1608 | String srcName; |
---|
| 1609 | Vector<uInt> restFreqIDs; |
---|
| 1610 | for (uInt i=0; i<nRow; i++) { |
---|
| 1611 | srcnCol_.get(i, srcName); |
---|
| 1612 | restfreqidCol_.get(i,restFreqIDs); |
---|
[455] | 1613 | |
---|
[392] | 1614 | if (idx==-1) { |
---|
[455] | 1615 | // Replace vector of restFreqs; one per IF. |
---|
| 1616 | // No selection possible |
---|
[392] | 1617 | for (uInt i=0; i<nIFs; i++) restFreqIDs[i] = i; |
---|
| 1618 | } else { |
---|
[455] | 1619 | // Set RestFreqID for selected data |
---|
[392] | 1620 | if (empty || source==srcName) { |
---|
| 1621 | if (whichIF<0) { |
---|
| 1622 | restFreqIDs = idx; |
---|
| 1623 | } else { |
---|
| 1624 | restFreqIDs[whichIF] = idx; |
---|
| 1625 | } |
---|
[386] | 1626 | } |
---|
| 1627 | } |
---|
| 1628 | restfreqidCol_.put(i,restFreqIDs); |
---|
| 1629 | } |
---|
| 1630 | ok = True; |
---|
| 1631 | } else { |
---|
[455] | 1632 | ok = False; |
---|
[386] | 1633 | } |
---|
[455] | 1634 | |
---|
[386] | 1635 | return ok; |
---|
| 1636 | } |
---|
| 1637 | |
---|
[414] | 1638 | void SDMemTable::spectralLines() const |
---|
[401] | 1639 | { |
---|
| 1640 | Vector<String> lines = MeasTable::Lines(); |
---|
| 1641 | MFrequency lineFreq; |
---|
| 1642 | Double freq; |
---|
[455] | 1643 | |
---|
[414] | 1644 | cout.flags(std::ios_base::left); |
---|
| 1645 | cout << "Line Frequency (Hz)" << endl; |
---|
| 1646 | cout << "-----------------------" << endl; |
---|
[401] | 1647 | for (uInt i=0; i<lines.nelements(); i++) { |
---|
| 1648 | MeasTable::Line(lineFreq, lines[i]); |
---|
| 1649 | freq = lineFreq.getValue().getValue(); // Hz |
---|
[414] | 1650 | cout << setw(11) << lines[i] << setprecision(10) << freq << endl; |
---|
[401] | 1651 | } |
---|
| 1652 | } |
---|
[386] | 1653 | |
---|
[380] | 1654 | void SDMemTable::renumber() |
---|
| 1655 | { |
---|
| 1656 | uInt nRow = scanCol_.nrow(); |
---|
| 1657 | Int newscanid = 0; |
---|
| 1658 | Int cIdx;// the current scanid |
---|
| 1659 | // get the first scanid |
---|
| 1660 | scanCol_.getScalar(0,cIdx); |
---|
| 1661 | Int pIdx = cIdx;// the scanid of the previous row |
---|
| 1662 | for (uInt i=0; i<nRow;++i) { |
---|
| 1663 | scanCol_.getScalar(i,cIdx); |
---|
| 1664 | if (pIdx == cIdx) { |
---|
| 1665 | // renumber |
---|
| 1666 | scanCol_.put(i,newscanid); |
---|
| 1667 | } else { |
---|
| 1668 | ++newscanid; |
---|
| 1669 | pIdx = cIdx; // store scanid |
---|
| 1670 | --i; // don't increment next loop |
---|
| 1671 | } |
---|
| 1672 | } |
---|
| 1673 | } |
---|
[386] | 1674 | |
---|
[418] | 1675 | |
---|
[455] | 1676 | void SDMemTable::setCursorSlice(IPosition& start, IPosition& end, |
---|
| 1677 | const IPosition& shape) const |
---|
[430] | 1678 | { |
---|
[455] | 1679 | const uInt nDim = shape.nelements(); |
---|
| 1680 | start.resize(nDim); |
---|
| 1681 | end.resize(nDim); |
---|
| 1682 | |
---|
| 1683 | start(asap::BeamAxis) = beamSel_; |
---|
| 1684 | end(asap::BeamAxis) = beamSel_; |
---|
| 1685 | start(asap::IFAxis) = IFSel_; |
---|
| 1686 | end(asap::IFAxis) = IFSel_; |
---|
[430] | 1687 | |
---|
[455] | 1688 | start(asap::PolAxis) = polSel_; |
---|
| 1689 | end(asap::PolAxis) = polSel_; |
---|
[430] | 1690 | |
---|
[455] | 1691 | start(asap::ChanAxis) = 0; |
---|
| 1692 | end(asap::ChanAxis) = shape(asap::ChanAxis) - 1; |
---|
[430] | 1693 | } |
---|
| 1694 | |
---|
[447] | 1695 | |
---|
[455] | 1696 | std::vector<float> SDMemTable::getFloatSpectrum(const Array<Float>& arr) const |
---|
| 1697 | // Get spectrum at cursor location |
---|
[447] | 1698 | { |
---|
| 1699 | |
---|
[455] | 1700 | // Setup accessors |
---|
[447] | 1701 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr); |
---|
| 1702 | aa0.reset(aa0.begin(uInt(beamSel_))); // Beam selection |
---|
| 1703 | |
---|
| 1704 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0); |
---|
| 1705 | aa1.reset(aa1.begin(uInt(IFSel_))); // IF selection |
---|
| 1706 | |
---|
| 1707 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1); |
---|
| 1708 | aa2.reset(aa2.begin(uInt(polSel_))); // Pol selection |
---|
[455] | 1709 | |
---|
[447] | 1710 | std::vector<float> spectrum; |
---|
| 1711 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) { |
---|
| 1712 | spectrum.push_back(*i); |
---|
| 1713 | } |
---|
| 1714 | return spectrum; |
---|
| 1715 | } |
---|
| 1716 | |
---|