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