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