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