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