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