[2] | 1 | //#---------------------------------------------------------------------------
|
---|
| 2 | //# SDMemTable.cc: A MemoryTable container for single dish integrations
|
---|
| 3 | //#---------------------------------------------------------------------------
|
---|
| 4 | //# Copyright (C) 2004
|
---|
[125] | 5 | //# ATNF
|
---|
[2] | 6 | //#
|
---|
| 7 | //# This program is free software; you can redistribute it and/or modify it
|
---|
| 8 | //# under the terms of the GNU General Public License as published by the Free
|
---|
| 9 | //# Software Foundation; either version 2 of the License, or (at your option)
|
---|
| 10 | //# any later version.
|
---|
| 11 | //#
|
---|
| 12 | //# This program is distributed in the hope that it will be useful, but
|
---|
| 13 | //# WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
---|
| 15 | //# Public License for more details.
|
---|
| 16 | //#
|
---|
| 17 | //# You should have received a copy of the GNU General Public License along
|
---|
| 18 | //# with this program; if not, write to the Free Software Foundation, Inc.,
|
---|
| 19 | //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
|
---|
| 20 | //#
|
---|
| 21 | //# Correspondence concerning this software should be addressed as follows:
|
---|
| 22 | //# Internet email: Malte.Marquarding@csiro.au
|
---|
| 23 | //# Postal address: Malte Marquarding,
|
---|
| 24 | //# Australia Telescope National Facility,
|
---|
| 25 | //# P.O. Box 76,
|
---|
| 26 | //# Epping, NSW, 2121,
|
---|
| 27 | //# AUSTRALIA
|
---|
| 28 | //#
|
---|
| 29 | //# $Id:
|
---|
| 30 | //#---------------------------------------------------------------------------
|
---|
| 31 |
|
---|
[206] | 32 | #include <map>
|
---|
| 33 |
|
---|
[125] | 34 | #include <casa/aips.h>
|
---|
[80] | 35 | #include <casa/iostream.h>
|
---|
| 36 | #include <casa/iomanip.h>
|
---|
| 37 | #include <casa/Arrays/Array.h>
|
---|
| 38 | #include <casa/Arrays/ArrayMath.h>
|
---|
| 39 | #include <casa/Arrays/MaskArrMath.h>
|
---|
| 40 | #include <casa/Arrays/ArrayLogical.h>
|
---|
| 41 | #include <casa/Arrays/ArrayAccessor.h>
|
---|
[206] | 42 | #include <casa/Arrays/Vector.h>
|
---|
[2] | 43 |
|
---|
[80] | 44 | #include <tables/Tables/TableParse.h>
|
---|
| 45 | #include <tables/Tables/TableDesc.h>
|
---|
| 46 | #include <tables/Tables/SetupNewTab.h>
|
---|
| 47 | #include <tables/Tables/ScaColDesc.h>
|
---|
| 48 | #include <tables/Tables/ArrColDesc.h>
|
---|
[2] | 49 |
|
---|
[80] | 50 | #include <tables/Tables/ExprNode.h>
|
---|
| 51 | #include <tables/Tables/ScalarColumn.h>
|
---|
| 52 | #include <tables/Tables/ArrayColumn.h>
|
---|
| 53 | #include <tables/Tables/TableRecord.h>
|
---|
| 54 | #include <measures/Measures/MFrequency.h>
|
---|
| 55 | #include <measures/Measures/MeasTable.h>
|
---|
[105] | 56 | #include <coordinates/Coordinates/CoordinateUtil.h>
|
---|
[80] | 57 | #include <casa/Quanta/MVTime.h>
|
---|
[2] | 58 |
|
---|
[215] | 59 | #include "SDDefs.h"
|
---|
[2] | 60 | #include "SDMemTable.h"
|
---|
| 61 | #include "SDContainer.h"
|
---|
| 62 |
|
---|
[206] | 63 |
|
---|
[125] | 64 | using namespace casa;
|
---|
[83] | 65 | using namespace asap;
|
---|
[2] | 66 |
|
---|
[18] | 67 | SDMemTable::SDMemTable() :
|
---|
| 68 | IFSel_(0),
|
---|
| 69 | beamSel_(0),
|
---|
[206] | 70 | polSel_(0)
|
---|
| 71 | {
|
---|
[18] | 72 | setup();
|
---|
| 73 | }
|
---|
[206] | 74 |
|
---|
[2] | 75 | SDMemTable::SDMemTable(const std::string& name) :
|
---|
| 76 | IFSel_(0),
|
---|
| 77 | beamSel_(0),
|
---|
[206] | 78 | polSel_(0)
|
---|
| 79 | {
|
---|
[50] | 80 | Table tab(name);
|
---|
[22] | 81 | table_ = tab.copyToMemoryTable("dummy");
|
---|
[206] | 82 | //cerr << "hello from C SDMemTable @ " << this << endl;
|
---|
[2] | 83 | }
|
---|
| 84 |
|
---|
[206] | 85 | SDMemTable::SDMemTable(const SDMemTable& other, Bool clear)
|
---|
| 86 | {
|
---|
[148] | 87 | IFSel_= other.IFSel_;
|
---|
| 88 | beamSel_= other.beamSel_;
|
---|
| 89 | polSel_= other.polSel_;
|
---|
| 90 | chanMask_ = other.chanMask_;
|
---|
| 91 | table_ = other.table_.copyToMemoryTable(String("dummy"));
|
---|
[2] | 92 | // clear all rows()
|
---|
[16] | 93 | if (clear) {
|
---|
[148] | 94 | table_.removeRow(this->table_.rowNumbers());
|
---|
[16] | 95 | } else {
|
---|
[148] | 96 | IFSel_ = other.IFSel_;
|
---|
| 97 | beamSel_ = other.beamSel_;
|
---|
| 98 | polSel_ = other.polSel_;
|
---|
[16] | 99 | }
|
---|
[206] | 100 | //cerr << "hello from CC SDMemTable @ " << this << endl;
|
---|
[2] | 101 | }
|
---|
| 102 |
|
---|
[80] | 103 | SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) :
|
---|
[2] | 104 | IFSel_(0),
|
---|
| 105 | beamSel_(0),
|
---|
[206] | 106 | polSel_(0)
|
---|
| 107 | {
|
---|
[2] | 108 | Table t = tableCommand(exprs,tab);
|
---|
[89] | 109 | if (t.nrow() == 0)
|
---|
| 110 | throw(AipsError("Query unsuccessful."));
|
---|
[22] | 111 | table_ = t.copyToMemoryTable("dummy");
|
---|
[2] | 112 | }
|
---|
| 113 |
|
---|
[206] | 114 | SDMemTable::~SDMemTable()
|
---|
| 115 | {
|
---|
[105] | 116 | //cerr << "goodbye from SDMemTable @ " << this << endl;
|
---|
[2] | 117 | }
|
---|
| 118 |
|
---|
[206] | 119 | SDMemTable SDMemTable::getScan(Int scanID) const
|
---|
| 120 | {
|
---|
[80] | 121 | String cond("SELECT * from $1 WHERE SCANID == ");
|
---|
| 122 | cond += String::toString(scanID);
|
---|
| 123 | return SDMemTable(table_, cond);
|
---|
[2] | 124 | }
|
---|
| 125 |
|
---|
[206] | 126 | SDMemTable &SDMemTable::operator=(const SDMemTable& other)
|
---|
| 127 | {
|
---|
[148] | 128 | if (this != &other) {
|
---|
| 129 | IFSel_= other.IFSel_;
|
---|
| 130 | beamSel_= other.beamSel_;
|
---|
| 131 | polSel_= other.polSel_;
|
---|
| 132 | chanMask_.resize(0);
|
---|
| 133 | chanMask_ = other.chanMask_;
|
---|
| 134 | table_ = other.table_.copyToMemoryTable(String("dummy"));
|
---|
[206] | 135 | }
|
---|
| 136 | //cerr << "hello from ASS SDMemTable @ " << this << endl;
|
---|
[138] | 137 | return *this;
|
---|
| 138 | }
|
---|
| 139 |
|
---|
[206] | 140 | SDMemTable SDMemTable::getSource(const std::string& source) const
|
---|
| 141 | {
|
---|
[80] | 142 | String cond("SELECT * from $1 WHERE SRCNAME == ");
|
---|
| 143 | cond += source;
|
---|
| 144 | return SDMemTable(table_, cond);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[206] | 147 | void SDMemTable::setup()
|
---|
| 148 | {
|
---|
[2] | 149 | TableDesc td("", "1", TableDesc::Scratch);
|
---|
| 150 | td.comment() = "A SDMemTable";
|
---|
| 151 | td.addColumn(ScalarColumnDesc<Double>("TIME"));
|
---|
| 152 | td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
|
---|
| 153 | td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
|
---|
| 154 | td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
|
---|
[89] | 155 | td.addColumn(ArrayColumnDesc<Float>("TSYS"));
|
---|
| 156 | td.addColumn(ScalarColumnDesc<Int>("SCANID"));
|
---|
| 157 | td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
|
---|
[39] | 158 | td.addColumn(ArrayColumnDesc<uInt>("FREQID"));
|
---|
[78] | 159 | td.addColumn(ArrayColumnDesc<Double>("DIRECTION"));
|
---|
[105] | 160 | td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
|
---|
| 161 | td.addColumn(ScalarColumnDesc<String>("TCALTIME"));
|
---|
| 162 | td.addColumn(ArrayColumnDesc<Float>("TCAL"));
|
---|
| 163 | td.addColumn(ScalarColumnDesc<Float>("AZIMUTH"));
|
---|
| 164 | td.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
|
---|
| 165 | td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
|
---|
| 166 | td.addColumn(ScalarColumnDesc<Int>("REFBEAM"));
|
---|
[206] | 167 | td.addColumn(ArrayColumnDesc<String>("HISTORY"));
|
---|
[105] | 168 |
|
---|
[2] | 169 | // Now create a new table from the description.
|
---|
[18] | 170 |
|
---|
[22] | 171 | SetupNewTable aNewTab("dummy", td, Table::New);
|
---|
[89] | 172 | table_ = Table(aNewTab, Table::Memory, 0);
|
---|
[2] | 173 | }
|
---|
| 174 |
|
---|
[206] | 175 | std::string SDMemTable::getSourceName(Int whichRow) const
|
---|
| 176 | {
|
---|
[2] | 177 | ROScalarColumn<String> src(table_, "SRCNAME");
|
---|
| 178 | String name;
|
---|
| 179 | src.get(whichRow, name);
|
---|
| 180 | return name;
|
---|
| 181 | }
|
---|
| 182 |
|
---|
[206] | 183 | std::string SDMemTable::getTime(Int whichRow) const
|
---|
| 184 | {
|
---|
[2] | 185 | ROScalarColumn<Double> src(table_, "TIME");
|
---|
| 186 | Double tm;
|
---|
| 187 | src.get(whichRow, tm);
|
---|
[50] | 188 | MVTime mvt(tm);
|
---|
[105] | 189 | mvt.setFormat(MVTime::TIME);
|
---|
[50] | 190 | ostringstream oss;
|
---|
| 191 | oss << mvt;
|
---|
| 192 | String str(oss);
|
---|
| 193 | return str;
|
---|
[2] | 194 | }
|
---|
[206] | 195 | double SDMemTable::getInterval(Int whichRow) const
|
---|
| 196 | {
|
---|
[50] | 197 | ROScalarColumn<Double> src(table_, "INTERVAL");
|
---|
| 198 | Double intval;
|
---|
| 199 | src.get(whichRow, intval);
|
---|
| 200 | return intval;
|
---|
| 201 | }
|
---|
[2] | 202 |
|
---|
[206] | 203 | bool SDMemTable::setIF(Int whichIF)
|
---|
| 204 | {
|
---|
[50] | 205 | if ( whichIF >= 0 && whichIF < nIF()) {
|
---|
[2] | 206 | IFSel_ = whichIF;
|
---|
| 207 | return true;
|
---|
[50] | 208 | }
|
---|
| 209 | return false;
|
---|
[2] | 210 | }
|
---|
[50] | 211 |
|
---|
[206] | 212 | bool SDMemTable::setBeam(Int whichBeam)
|
---|
| 213 | {
|
---|
[50] | 214 | if ( whichBeam >= 0 && whichBeam < nBeam()) {
|
---|
[2] | 215 | beamSel_ = whichBeam;
|
---|
| 216 | return true;
|
---|
[50] | 217 | }
|
---|
| 218 | return false;
|
---|
| 219 | }
|
---|
[2] | 220 |
|
---|
[206] | 221 | bool SDMemTable::setPol(Int whichPol)
|
---|
| 222 | {
|
---|
[50] | 223 | if ( whichPol >= 0 && whichPol < nPol()) {
|
---|
[2] | 224 | polSel_ = whichPol;
|
---|
| 225 | return true;
|
---|
[50] | 226 | }
|
---|
| 227 | return false;
|
---|
[2] | 228 | }
|
---|
| 229 |
|
---|
[206] | 230 | bool SDMemTable::setMask(std::vector<int> whichChans)
|
---|
| 231 | {
|
---|
[16] | 232 | ROArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
| 233 | std::vector<int>::iterator it;
|
---|
| 234 | uInt n = spec.shape(0)(3);
|
---|
[105] | 235 | if (whichChans.empty()) {
|
---|
| 236 | chanMask_ = std::vector<bool>(n,true);
|
---|
| 237 | return true;
|
---|
| 238 | }
|
---|
[16] | 239 | chanMask_.resize(n,true);
|
---|
[39] | 240 | for (it = whichChans.begin(); it != whichChans.end(); ++it) {
|
---|
[105] | 241 | if (*it < n) {
|
---|
[16] | 242 | chanMask_[*it] = false;
|
---|
[105] | 243 | }
|
---|
[16] | 244 | }
|
---|
[2] | 245 | return true;
|
---|
| 246 | }
|
---|
| 247 |
|
---|
[16] | 248 | std::vector<bool> SDMemTable::getMask(Int whichRow) const {
|
---|
| 249 | std::vector<bool> mask;
|
---|
| 250 | ROArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
| 251 | Array<uChar> arr;
|
---|
| 252 | spec.get(whichRow, arr);
|
---|
[206] | 253 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
|
---|
[16] | 254 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
[206] | 255 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
|
---|
[16] | 256 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
[206] | 257 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
|
---|
[16] | 258 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
| 259 |
|
---|
| 260 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
|
---|
| 261 |
|
---|
| 262 | std::vector<bool> tmp;
|
---|
| 263 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here
|
---|
| 264 | std::vector<bool>::iterator miter;
|
---|
| 265 | miter = tmp.begin();
|
---|
| 266 |
|
---|
[206] | 267 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
[16] | 268 | bool out =!static_cast<bool>(*i);
|
---|
| 269 | if (useUserMask) {
|
---|
| 270 | out = out && (*miter);
|
---|
| 271 | miter++;
|
---|
| 272 | }
|
---|
| 273 | mask.push_back(out);
|
---|
[89] | 274 | }
|
---|
[16] | 275 | return mask;
|
---|
[2] | 276 | }
|
---|
[206] | 277 | std::vector<float> SDMemTable::getSpectrum(Int whichRow) const
|
---|
| 278 | {
|
---|
[2] | 279 | std::vector<float> spectrum;
|
---|
| 280 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 281 | Array<Float> arr;
|
---|
| 282 | spec.get(whichRow, arr);
|
---|
[206] | 283 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
|
---|
[2] | 284 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
[206] | 285 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
|
---|
[2] | 286 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
[206] | 287 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
|
---|
[16] | 288 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
[206] | 289 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
[16] | 290 | spectrum.push_back(*i);
|
---|
[2] | 291 | }
|
---|
| 292 | return spectrum;
|
---|
| 293 | }
|
---|
[206] | 294 | std::vector<string> SDMemTable::getCoordInfo() const
|
---|
| 295 | {
|
---|
[105] | 296 | String un;
|
---|
| 297 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 298 | String sunit;
|
---|
| 299 | t.keywordSet().get("UNIT",sunit);
|
---|
| 300 | String dpl;
|
---|
| 301 | t.keywordSet().get("DOPPLER",dpl);
|
---|
| 302 | if (dpl == "") dpl = "RADIO";
|
---|
| 303 | String rfrm;
|
---|
| 304 | t.keywordSet().get("REFFRAME",rfrm);
|
---|
| 305 | std::vector<string> inf;
|
---|
| 306 | inf.push_back(sunit);
|
---|
| 307 | inf.push_back(rfrm);
|
---|
| 308 | inf.push_back(dpl);
|
---|
[263] | 309 | t.keywordSet().get("BASEREFFRAME",rfrm);
|
---|
| 310 | inf.push_back(rfrm);
|
---|
[105] | 311 | return inf;
|
---|
| 312 | }
|
---|
[39] | 313 |
|
---|
[206] | 314 | void SDMemTable::setCoordInfo(std::vector<string> theinfo)
|
---|
| 315 | {
|
---|
[105] | 316 | std::vector<string>::iterator it;
|
---|
| 317 | String un,rfrm,dpl;
|
---|
| 318 | un = theinfo[0];
|
---|
| 319 | rfrm = theinfo[1];
|
---|
| 320 | dpl = theinfo[2];
|
---|
| 321 |
|
---|
| 322 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
|
---|
| 323 | Vector<Double> rstf;
|
---|
| 324 | t.keywordSet().get("RESTFREQS",rstf);
|
---|
| 325 | Bool canDo = True;
|
---|
| 326 | Unit u1("km/s");Unit u2("Hz");
|
---|
| 327 | if (Unit(un) == u1) {
|
---|
| 328 | Vector<Double> rstf;
|
---|
| 329 | t.keywordSet().get("RESTFREQS",rstf);
|
---|
| 330 | if (rstf.nelements() == 0) {
|
---|
| 331 | throw(AipsError("Can't set unit to km/s if no restfrequencies are specified"));
|
---|
| 332 | }
|
---|
| 333 | } else if (Unit(un) != u2 && un != "") {
|
---|
| 334 | throw(AipsError("Unit not conformant with Spectral Coordinates"));
|
---|
| 335 | }
|
---|
| 336 | t.rwKeywordSet().define("UNIT", un);
|
---|
| 337 |
|
---|
| 338 | MFrequency::Types mdr;
|
---|
| 339 | if (!MFrequency::getType(mdr, rfrm)) {
|
---|
| 340 |
|
---|
| 341 | Int a,b;const uInt* c;
|
---|
| 342 | const String* valid = MFrequency::allMyTypes(a, b, c);
|
---|
| 343 | String pfix = "Please specify a legal frame type. Types are\n";
|
---|
| 344 | throw(AipsError(pfix+(*valid)));
|
---|
| 345 | } else {
|
---|
| 346 | t.rwKeywordSet().define("REFFRAME",rfrm);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
| 349 | }
|
---|
| 350 |
|
---|
[206] | 351 | std::vector<double> SDMemTable::getAbcissa(Int whichRow) const
|
---|
| 352 | {
|
---|
[39] | 353 | std::vector<double> absc(nChan());
|
---|
[89] | 354 | Vector<Double> absc1(nChan());
|
---|
[39] | 355 | indgen(absc1);
|
---|
| 356 | ROArrayColumn<uInt> fid(table_, "FREQID");
|
---|
| 357 | Vector<uInt> v;
|
---|
| 358 | fid.get(whichRow, v);
|
---|
| 359 | uInt specidx = v(IFSel_);
|
---|
| 360 | SpectralCoordinate spc = getCoordinate(specidx);
|
---|
[78] | 361 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
[206] | 362 |
|
---|
| 363 | MDirection direct = getDirection(whichRow);
|
---|
| 364 |
|
---|
[78] | 365 | ROScalarColumn<Double> tme(table_, "TIME");
|
---|
| 366 | Double obstime;
|
---|
| 367 | tme.get(whichRow,obstime);
|
---|
[89] | 368 | MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
|
---|
[212] | 369 | MEpoch::Types met = getTimeReference();
|
---|
[206] | 370 | MEpoch epoch(tm2, met);
|
---|
| 371 |
|
---|
[78] | 372 | Vector<Double> antpos;
|
---|
| 373 | table_.keywordSet().get("AntennaPosition", antpos);
|
---|
| 374 | MVPosition mvpos(antpos(0),antpos(1),antpos(2));
|
---|
| 375 | MPosition pos(mvpos);
|
---|
[105] | 376 | String sunit;
|
---|
| 377 | t.keywordSet().get("UNIT",sunit);
|
---|
| 378 | if (sunit == "") sunit = "pixel";
|
---|
| 379 | Unit u(sunit);
|
---|
| 380 | String frm;
|
---|
| 381 | t.keywordSet().get("REFFRAME",frm);
|
---|
| 382 | if (frm == "") frm = "TOPO";
|
---|
| 383 | String dpl;
|
---|
| 384 | t.keywordSet().get("DOPPLER",dpl);
|
---|
| 385 | if (dpl == "") dpl = "RADIO";
|
---|
[78] | 386 | MFrequency::Types mtype;
|
---|
[105] | 387 | if (!MFrequency::getType(mtype, frm)) {
|
---|
[89] | 388 | cout << "Frequency type unknown assuming TOPO" << endl;
|
---|
[78] | 389 | mtype = MFrequency::TOPO;
|
---|
| 390 | }
|
---|
[105] | 391 |
|
---|
| 392 | if (!spc.setReferenceConversion(mtype,epoch,pos,direct)) {
|
---|
| 393 | throw(AipsError("Couldn't convert frequency frame."));
|
---|
| 394 | }
|
---|
[78] | 395 |
|
---|
[39] | 396 | if ( u == Unit("km/s") ) {
|
---|
[89] | 397 | Vector<Double> rstf;
|
---|
| 398 | t.keywordSet().get("RESTFREQS",rstf);
|
---|
| 399 | if (rstf.nelements() > 0) {
|
---|
[121] | 400 | if (rstf.nelements() >= nIF())
|
---|
[125] | 401 | spc.selectRestFrequency(uInt(IFSel_));
|
---|
[89] | 402 | spc.setVelocity(u.getName());
|
---|
[39] | 403 | Vector<Double> wrld;
|
---|
| 404 | spc.pixelToVelocity(wrld,absc1);
|
---|
| 405 | std::vector<double>::iterator it;
|
---|
| 406 | uInt i = 0;
|
---|
| 407 | for (it = absc.begin(); it != absc.end(); ++it) {
|
---|
[89] | 408 | (*it) = wrld[i];
|
---|
| 409 | i++;
|
---|
[39] | 410 | }
|
---|
| 411 | }
|
---|
| 412 | } else if (u == Unit("Hz")) {
|
---|
| 413 | Vector<String> wau(1); wau = u.getName();
|
---|
| 414 | spc.setWorldAxisUnits(wau);
|
---|
| 415 | std::vector<double>::iterator it;
|
---|
| 416 | Double tmp;
|
---|
| 417 | uInt i = 0;
|
---|
[89] | 418 | for (it = absc.begin(); it != absc.end(); ++it) {
|
---|
[39] | 419 | spc.toWorld(tmp,absc1[i]);
|
---|
| 420 | (*it) = tmp;
|
---|
| 421 | i++;
|
---|
| 422 | }
|
---|
[105] | 423 |
|
---|
| 424 | } else {
|
---|
| 425 | // assume channels/pixels
|
---|
| 426 | std::vector<double>::iterator it;
|
---|
| 427 | uInt i=0;
|
---|
| 428 | for (it = absc.begin(); it != absc.end(); ++it) {
|
---|
| 429 | (*it) = Double(i++);
|
---|
| 430 | }
|
---|
[39] | 431 | }
|
---|
| 432 | return absc;
|
---|
| 433 | }
|
---|
| 434 |
|
---|
[164] | 435 | std::string SDMemTable::getAbcissaString(Int whichRow) const
|
---|
[105] | 436 | {
|
---|
| 437 | ROArrayColumn<uInt> fid(table_, "FREQID");
|
---|
| 438 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 439 | String sunit;
|
---|
| 440 | t.keywordSet().get("UNIT",sunit);
|
---|
| 441 | if (sunit == "") sunit = "pixel";
|
---|
| 442 | Unit u(sunit);
|
---|
| 443 | Vector<uInt> v;
|
---|
| 444 | fid.get(whichRow, v);
|
---|
| 445 | uInt specidx = v(IFSel_);
|
---|
| 446 | SpectralCoordinate spc = getCoordinate(specidx);
|
---|
| 447 | String frm;
|
---|
| 448 | t.keywordSet().get("REFFRAME",frm);
|
---|
| 449 | MFrequency::Types mtype;
|
---|
| 450 | if (!MFrequency::getType(mtype, frm)) {
|
---|
| 451 | cout << "Frequency type unknown assuming TOPO" << endl;
|
---|
| 452 | mtype = MFrequency::TOPO;
|
---|
| 453 | }
|
---|
| 454 | spc.setFrequencySystem(mtype);
|
---|
| 455 | String s = "Channel";
|
---|
| 456 | if (u == Unit("km/s")) {
|
---|
| 457 | spc.setVelocity(u.getName());
|
---|
| 458 | s = CoordinateUtil::axisLabel(spc,0,True,True,True);
|
---|
| 459 | } else if (u == Unit("Hz")) {
|
---|
| 460 | Vector<String> wau(1);wau = u.getName();
|
---|
| 461 | spc.setWorldAxisUnits(wau);
|
---|
| 462 | s = CoordinateUtil::axisLabel(spc);
|
---|
| 463 | }
|
---|
| 464 | return s;
|
---|
| 465 | }
|
---|
| 466 |
|
---|
[206] | 467 | void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow)
|
---|
| 468 | {
|
---|
[89] | 469 | ArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 470 | Array<Float> arr;
|
---|
| 471 | spec.get(whichRow, arr);
|
---|
| 472 | if (spectrum.size() != arr.shape()(3)) {
|
---|
| 473 | throw(AipsError("Attempting to set spectrum with incorrect length."));
|
---|
| 474 | }
|
---|
| 475 |
|
---|
[206] | 476 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
|
---|
[89] | 477 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
[206] | 478 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
|
---|
[89] | 479 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
[206] | 480 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
|
---|
[89] | 481 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
| 482 |
|
---|
| 483 | std::vector<float>::iterator it = spectrum.begin();
|
---|
[206] | 484 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
[89] | 485 | (*i) = Float(*it);
|
---|
| 486 | it++;
|
---|
| 487 | }
|
---|
| 488 | spec.put(whichRow, arr);
|
---|
| 489 | }
|
---|
| 490 |
|
---|
[206] | 491 | void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const
|
---|
| 492 | {
|
---|
[21] | 493 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 494 | Array<Float> arr;
|
---|
| 495 | spec.get(whichRow, arr);
|
---|
| 496 | spectrum.resize(arr.shape()(3));
|
---|
[206] | 497 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
|
---|
[21] | 498 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
[206] | 499 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
|
---|
[21] | 500 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
[206] | 501 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
|
---|
[21] | 502 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
[2] | 503 |
|
---|
[206] | 504 | ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
|
---|
| 505 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
[21] | 506 | (*va) = (*i);
|
---|
| 507 | va++;
|
---|
| 508 | }
|
---|
| 509 | }
|
---|
[89] | 510 | /*
|
---|
[68] | 511 | void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
|
---|
[21] | 512 | ROArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
| 513 | Array<uChar> arr;
|
---|
| 514 | spec.get(whichRow, arr);
|
---|
| 515 | mask.resize(arr.shape()(3));
|
---|
| 516 |
|
---|
[206] | 517 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
|
---|
[21] | 518 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
[206] | 519 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
|
---|
[21] | 520 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
[206] | 521 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
|
---|
[21] | 522 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
| 523 |
|
---|
| 524 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
|
---|
[89] | 525 |
|
---|
[206] | 526 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask);
|
---|
[21] | 527 | std::vector<bool> tmp;
|
---|
| 528 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
|
---|
[89] | 529 | // iterator should work on chanMask_??
|
---|
[21] | 530 | std::vector<bool>::iterator miter;
|
---|
| 531 | miter = tmp.begin();
|
---|
| 532 |
|
---|
[206] | 533 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
[21] | 534 | bool out =!static_cast<bool>(*i);
|
---|
| 535 | if (useUserMask) {
|
---|
| 536 | out = out && (*miter);
|
---|
| 537 | miter++;
|
---|
| 538 | }
|
---|
| 539 | (*va) = out;
|
---|
| 540 | va++;
|
---|
[89] | 541 | }
|
---|
[21] | 542 | }
|
---|
[89] | 543 | */
|
---|
[16] | 544 | MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
|
---|
[164] | 545 | Bool useSelection) const
|
---|
| 546 | {
|
---|
[2] | 547 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 548 | Array<Float> arr;
|
---|
| 549 | ROArrayColumn<uChar> flag(table_, "FLAGTRA");
|
---|
| 550 | Array<uChar> farr;
|
---|
| 551 | spec.get(whichRow, arr);
|
---|
| 552 | flag.get(whichRow, farr);
|
---|
| 553 | Array<Bool> barr(farr.shape());convertArray(barr, farr);
|
---|
| 554 | MaskedArray<Float> marr;
|
---|
[16] | 555 | if (useSelection) {
|
---|
[206] | 556 | ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
|
---|
[16] | 557 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
[206] | 558 | ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
|
---|
[16] | 559 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
[206] | 560 | ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
|
---|
[16] | 561 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
[89] | 562 |
|
---|
[206] | 563 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > baa0(barr);
|
---|
[16] | 564 | baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam
|
---|
[206] | 565 | ArrayAccessor<Bool, Axis<asap::IFAxis> > baa1(baa0);
|
---|
[16] | 566 | baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF
|
---|
[206] | 567 | ArrayAccessor<Bool, Axis<asap::PolAxis> > baa2(baa1);
|
---|
[16] | 568 | baa2.reset(baa2.begin(uInt(polSel_)));// go to pol
|
---|
| 569 |
|
---|
| 570 | Vector<Float> a(arr.shape()(3));
|
---|
| 571 | Vector<Bool> b(barr.shape()(3));
|
---|
[206] | 572 | ArrayAccessor<Float, Axis<asap::BeamAxis> > a0(a);
|
---|
| 573 | ArrayAccessor<Bool, Axis<asap::BeamAxis> > b0(b);
|
---|
[16] | 574 |
|
---|
[206] | 575 | ArrayAccessor<Bool, Axis<asap::ChanAxis> > j(baa2);
|
---|
| 576 | for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2);
|
---|
| 577 | i != i.end(); ++i) {
|
---|
[16] | 578 | (*a0) = (*i);
|
---|
| 579 | (*b0) = !(*j);
|
---|
| 580 | j++;
|
---|
| 581 | a0++;
|
---|
| 582 | b0++;
|
---|
| 583 | }
|
---|
| 584 | marr.setData(a,b);
|
---|
| 585 | } else {
|
---|
| 586 | marr.setData(arr,!barr);
|
---|
| 587 | }
|
---|
[2] | 588 | return marr;
|
---|
| 589 | }
|
---|
| 590 |
|
---|
[206] | 591 | Float SDMemTable::getTsys(Int whichRow) const
|
---|
| 592 | {
|
---|
[2] | 593 | ROArrayColumn<Float> ts(table_, "TSYS");
|
---|
| 594 | Array<Float> arr;
|
---|
| 595 | ts.get(whichRow, arr);
|
---|
| 596 | Float out;
|
---|
| 597 | IPosition ip(arr.shape());
|
---|
[16] | 598 | ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0;
|
---|
[2] | 599 | out = arr(ip);
|
---|
| 600 | return out;
|
---|
| 601 | }
|
---|
| 602 |
|
---|
[206] | 603 | MDirection SDMemTable::getDirection(Int whichRow) const
|
---|
| 604 | {
|
---|
[212] | 605 | MDirection::Types mdr = getDirectionReference();
|
---|
[206] | 606 | ROArrayColumn<Double> dir(table_, "DIRECTION");
|
---|
| 607 | Array<Double> posit;
|
---|
| 608 | dir.get(whichRow,posit);
|
---|
| 609 | Vector<Double> wpos(2);
|
---|
| 610 | wpos[0] = posit(IPosition(2,beamSel_,0));
|
---|
| 611 | wpos[1] = posit(IPosition(2,beamSel_,1));
|
---|
| 612 | Quantum<Double> lon(wpos[0],Unit(String("rad")));
|
---|
| 613 | Quantum<Double> lat(wpos[1],Unit(String("rad")));
|
---|
| 614 | MDirection direct(lon, lat, mdr);
|
---|
| 615 | return direct;
|
---|
| 616 | }
|
---|
[39] | 617 |
|
---|
[206] | 618 | SpectralCoordinate SDMemTable::getCoordinate(uInt whichIdx) const
|
---|
| 619 | {
|
---|
| 620 |
|
---|
[39] | 621 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 622 | if (whichIdx > t.nrow() ) {
|
---|
[206] | 623 | throw(AipsError("SDMemTable::getCoordinate - whichIdx out of range"));
|
---|
[39] | 624 | }
|
---|
[89] | 625 |
|
---|
[39] | 626 | Double rp,rv,inc;
|
---|
| 627 | String rf;
|
---|
[89] | 628 | Vector<Double> vec;
|
---|
[39] | 629 | ROScalarColumn<Double> rpc(t, "REFPIX");
|
---|
| 630 | ROScalarColumn<Double> rvc(t, "REFVAL");
|
---|
| 631 | ROScalarColumn<Double> incc(t, "INCREMENT");
|
---|
[89] | 632 | t.keywordSet().get("RESTFREQS",vec);
|
---|
[105] | 633 | t.keywordSet().get("BASEREFFRAME",rf);
|
---|
[89] | 634 |
|
---|
[39] | 635 | MFrequency::Types mft;
|
---|
| 636 | if (!MFrequency::getType(mft, rf)) {
|
---|
| 637 | cerr << "Frequency type unknown assuming TOPO" << endl;
|
---|
[89] | 638 | mft = MFrequency::TOPO;
|
---|
| 639 | }
|
---|
[39] | 640 | rpc.get(whichIdx, rp);
|
---|
| 641 | rvc.get(whichIdx, rv);
|
---|
| 642 | incc.get(whichIdx, inc);
|
---|
| 643 | SpectralCoordinate spec(mft,rv,inc,rp);
|
---|
[89] | 644 | if (vec.nelements() > 0)
|
---|
| 645 | spec.setRestFrequencies(vec);
|
---|
[39] | 646 | return spec;
|
---|
| 647 | }
|
---|
| 648 |
|
---|
[89] | 649 | Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
|
---|
| 650 | uInt whichIdx) {
|
---|
[50] | 651 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
|
---|
| 652 | if (whichIdx > t.nrow() ) {
|
---|
[89] | 653 | throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
|
---|
[50] | 654 | }
|
---|
| 655 | ScalarColumn<Double> rpc(t, "REFPIX");
|
---|
| 656 | ScalarColumn<Double> rvc(t, "REFVAL");
|
---|
| 657 | ScalarColumn<Double> incc(t, "INCREMENT");
|
---|
[89] | 658 |
|
---|
[50] | 659 | rpc.put(whichIdx, speccord.referencePixel()[0]);
|
---|
| 660 | rvc.put(whichIdx, speccord.referenceValue()[0]);
|
---|
| 661 | incc.put(whichIdx, speccord.increment()[0]);
|
---|
| 662 |
|
---|
| 663 | return True;
|
---|
| 664 | }
|
---|
| 665 |
|
---|
[89] | 666 | Int SDMemTable::nCoordinates() const
|
---|
| 667 | {
|
---|
| 668 | return table_.keywordSet().asTable("FREQUENCIES").nrow();
|
---|
| 669 | }
|
---|
[50] | 670 |
|
---|
[206] | 671 | void SDMemTable::setRestFreqs(std::vector<double> freqs,
|
---|
| 672 | const std::string& theunit)
|
---|
[89] | 673 | {
|
---|
| 674 | Vector<Double> tvec(freqs);
|
---|
| 675 | Quantum<Vector<Double> > q(tvec, String(theunit));
|
---|
| 676 | tvec.resize();
|
---|
| 677 | tvec = q.getValue("Hz");
|
---|
| 678 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 679 | t.rwKeywordSet().define("RESTFREQS",tvec);
|
---|
| 680 | }
|
---|
| 681 |
|
---|
[251] | 682 | std::vector<double> SDMemTable::getRestFreqs() const
|
---|
| 683 | {
|
---|
| 684 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 685 | Vector<Double> tvec;
|
---|
| 686 | t.keywordSet().get("RESTFREQS",tvec);
|
---|
| 687 | std::vector<double> stlout;
|
---|
| 688 | tvec.tovector(stlout);
|
---|
| 689 | return stlout;
|
---|
| 690 | }
|
---|
| 691 |
|
---|
[206] | 692 | bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft)
|
---|
| 693 | {
|
---|
[39] | 694 | TableDesc td("", "1", TableDesc::Scratch);
|
---|
| 695 | td.addColumn(ScalarColumnDesc<Double>("REFPIX"));
|
---|
| 696 | td.addColumn(ScalarColumnDesc<Double>("REFVAL"));
|
---|
| 697 | td.addColumn(ScalarColumnDesc<Double>("INCREMENT"));
|
---|
| 698 | SetupNewTable aNewTab("freqs", td, Table::New);
|
---|
| 699 | Table aTable (aNewTab, Table::Memory, sdft.length());
|
---|
| 700 | ScalarColumn<Double> sc0(aTable, "REFPIX");
|
---|
| 701 | ScalarColumn<Double> sc1(aTable, "REFVAL");
|
---|
| 702 | ScalarColumn<Double> sc2(aTable, "INCREMENT");
|
---|
| 703 | for (uInt i=0; i < sdft.length(); ++i) {
|
---|
| 704 | sc0.put(i,sdft.referencePixel(i));
|
---|
| 705 | sc1.put(i,sdft.referenceValue(i));
|
---|
| 706 | sc2.put(i,sdft.increment(i));
|
---|
| 707 | }
|
---|
[105] | 708 | String rf = sdft.refFrame();
|
---|
| 709 | if (rf.contains("TOPO")) rf = "TOPO";
|
---|
| 710 |
|
---|
| 711 | aTable.rwKeywordSet().define("BASEREFFRAME", rf);
|
---|
| 712 | aTable.rwKeywordSet().define("REFFRAME", rf);
|
---|
[39] | 713 | aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
|
---|
[105] | 714 | aTable.rwKeywordSet().define("UNIT", String(""));
|
---|
| 715 | aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
|
---|
[89] | 716 | Vector<Double> rfvec;
|
---|
[206] | 717 | String rfunit;
|
---|
| 718 | sdft.restFrequencies(rfvec,rfunit);
|
---|
| 719 | Quantum<Vector<Double> > q(rfvec, rfunit);
|
---|
| 720 | rfvec.resize();
|
---|
| 721 | rfvec = q.getValue("Hz");
|
---|
[89] | 722 | aTable.rwKeywordSet().define("RESTFREQS", rfvec);
|
---|
[39] | 723 | table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
|
---|
| 724 | return True;
|
---|
| 725 | }
|
---|
| 726 |
|
---|
[206] | 727 | SDFrequencyTable SDMemTable::getSDFreqTable() const
|
---|
| 728 | {
|
---|
[251] | 729 | // TODO !!!!! implement this properly USE with care
|
---|
| 730 | const Table& t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
[39] | 731 | SDFrequencyTable sdft;
|
---|
[251] | 732 | sdft.setLength(t.nrow());
|
---|
[39] | 733 | return sdft;
|
---|
| 734 | }
|
---|
| 735 |
|
---|
[206] | 736 | bool SDMemTable::putSDContainer(const SDContainer& sdc)
|
---|
| 737 | {
|
---|
[2] | 738 | ScalarColumn<Double> mjd(table_, "TIME");
|
---|
| 739 | ScalarColumn<String> srcn(table_, "SRCNAME");
|
---|
[105] | 740 | ScalarColumn<String> fldn(table_, "FIELDNAME");
|
---|
[2] | 741 | ArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 742 | ArrayColumn<uChar> flags(table_, "FLAGTRA");
|
---|
| 743 | ArrayColumn<Float> ts(table_, "TSYS");
|
---|
| 744 | ScalarColumn<Int> scan(table_, "SCANID");
|
---|
[16] | 745 | ScalarColumn<Double> integr(table_, "INTERVAL");
|
---|
[39] | 746 | ArrayColumn<uInt> freqid(table_, "FREQID");
|
---|
[78] | 747 | ArrayColumn<Double> dir(table_, "DIRECTION");
|
---|
[105] | 748 | ScalarColumn<Int> rbeam(table_, "REFBEAM");
|
---|
| 749 | ArrayColumn<Float> tcal(table_, "TCAL");
|
---|
| 750 | ScalarColumn<String> tcalt(table_, "TCALTIME");
|
---|
| 751 | ScalarColumn<Float> az(table_, "AZIMUTH");
|
---|
| 752 | ScalarColumn<Float> el(table_, "ELEVATION");
|
---|
| 753 | ScalarColumn<Float> para(table_, "PARANGLE");
|
---|
[206] | 754 | ArrayColumn<String> hist(table_, "HISTORY");
|
---|
[2] | 755 |
|
---|
| 756 | uInt rno = table_.nrow();
|
---|
| 757 | table_.addRow();
|
---|
[89] | 758 |
|
---|
[2] | 759 | mjd.put(rno, sdc.timestamp);
|
---|
| 760 | srcn.put(rno, sdc.sourcename);
|
---|
[105] | 761 | fldn.put(rno, sdc.fieldname);
|
---|
[2] | 762 | spec.put(rno, sdc.getSpectrum());
|
---|
| 763 | flags.put(rno, sdc.getFlags());
|
---|
| 764 | ts.put(rno, sdc.getTsys());
|
---|
| 765 | scan.put(rno, sdc.scanid);
|
---|
[16] | 766 | integr.put(rno, sdc.interval);
|
---|
[39] | 767 | freqid.put(rno, sdc.getFreqMap());
|
---|
[78] | 768 | dir.put(rno, sdc.getDirection());
|
---|
[105] | 769 | rbeam.put(rno, sdc.refbeam);
|
---|
| 770 | tcal.put(rno, sdc.tcal);
|
---|
| 771 | tcalt.put(rno, sdc.tcaltime);
|
---|
| 772 | az.put(rno, sdc.azimuth);
|
---|
| 773 | el.put(rno, sdc.elevation);
|
---|
| 774 | para.put(rno, sdc.parangle);
|
---|
[206] | 775 | hist.put(rno, sdc.getHistory());
|
---|
[89] | 776 |
|
---|
[2] | 777 | return true;
|
---|
| 778 | }
|
---|
[18] | 779 |
|
---|
[206] | 780 | SDContainer SDMemTable::getSDContainer(uInt whichRow) const
|
---|
| 781 | {
|
---|
[21] | 782 | ROScalarColumn<Double> mjd(table_, "TIME");
|
---|
| 783 | ROScalarColumn<String> srcn(table_, "SRCNAME");
|
---|
[105] | 784 | ROScalarColumn<String> fldn(table_, "FIELDNAME");
|
---|
[21] | 785 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 786 | ROArrayColumn<uChar> flags(table_, "FLAGTRA");
|
---|
| 787 | ROArrayColumn<Float> ts(table_, "TSYS");
|
---|
| 788 | ROScalarColumn<Int> scan(table_, "SCANID");
|
---|
| 789 | ROScalarColumn<Double> integr(table_, "INTERVAL");
|
---|
[39] | 790 | ROArrayColumn<uInt> freqid(table_, "FREQID");
|
---|
[78] | 791 | ROArrayColumn<Double> dir(table_, "DIRECTION");
|
---|
[105] | 792 | ROScalarColumn<Int> rbeam(table_, "REFBEAM");
|
---|
| 793 | ROArrayColumn<Float> tcal(table_, "TCAL");
|
---|
| 794 | ROScalarColumn<String> tcalt(table_, "TCALTIME");
|
---|
| 795 | ROScalarColumn<Float> az(table_, "AZIMUTH");
|
---|
| 796 | ROScalarColumn<Float> el(table_, "ELEVATION");
|
---|
| 797 | ROScalarColumn<Float> para(table_, "PARANGLE");
|
---|
[206] | 798 | ROArrayColumn<String> hist(table_, "HISTORY");
|
---|
[21] | 799 |
|
---|
| 800 | SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
|
---|
| 801 | mjd.get(whichRow, sdc.timestamp);
|
---|
| 802 | srcn.get(whichRow, sdc.sourcename);
|
---|
| 803 | integr.get(whichRow, sdc.interval);
|
---|
| 804 | scan.get(whichRow, sdc.scanid);
|
---|
[105] | 805 | fldn.get(whichRow, sdc.fieldname);
|
---|
| 806 | rbeam.get(whichRow, sdc.refbeam);
|
---|
| 807 | az.get(whichRow, sdc.azimuth);
|
---|
| 808 | el.get(whichRow, sdc.elevation);
|
---|
| 809 | para.get(whichRow, sdc.parangle);
|
---|
| 810 | Vector<Float> tc;
|
---|
| 811 | tcal.get(whichRow, tc);
|
---|
| 812 | sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
|
---|
| 813 | tcalt.get(whichRow, sdc.tcaltime);
|
---|
[21] | 814 | Array<Float> spectrum;
|
---|
| 815 | Array<Float> tsys;
|
---|
| 816 | Array<uChar> flagtrum;
|
---|
[39] | 817 | Vector<uInt> fmap;
|
---|
[78] | 818 | Array<Double> direction;
|
---|
[206] | 819 | Vector<String> histo;
|
---|
[21] | 820 | spec.get(whichRow, spectrum);
|
---|
| 821 | sdc.putSpectrum(spectrum);
|
---|
| 822 | flags.get(whichRow, flagtrum);
|
---|
| 823 | sdc.putFlags(flagtrum);
|
---|
| 824 | ts.get(whichRow, tsys);
|
---|
| 825 | sdc.putTsys(tsys);
|
---|
[39] | 826 | freqid.get(whichRow, fmap);
|
---|
| 827 | sdc.putFreqMap(fmap);
|
---|
[78] | 828 | dir.get(whichRow, direction);
|
---|
| 829 | sdc.putDirection(direction);
|
---|
[206] | 830 | hist.get(whichRow, histo);
|
---|
| 831 | sdc.putHistory(histo);
|
---|
[21] | 832 | return sdc;
|
---|
| 833 | }
|
---|
[78] | 834 |
|
---|
[206] | 835 | bool SDMemTable::putSDHeader(const SDHeader& sdh)
|
---|
| 836 | {
|
---|
[18] | 837 | table_.rwKeywordSet().define("nIF", sdh.nif);
|
---|
| 838 | table_.rwKeywordSet().define("nBeam", sdh.nbeam);
|
---|
| 839 | table_.rwKeywordSet().define("nPol", sdh.npol);
|
---|
| 840 | table_.rwKeywordSet().define("nChan", sdh.nchan);
|
---|
| 841 | table_.rwKeywordSet().define("Observer", sdh.observer);
|
---|
| 842 | table_.rwKeywordSet().define("Project", sdh.project);
|
---|
| 843 | table_.rwKeywordSet().define("Obstype", sdh.obstype);
|
---|
| 844 | table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
|
---|
| 845 | table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
|
---|
| 846 | table_.rwKeywordSet().define("Equinox", sdh.equinox);
|
---|
| 847 | table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
|
---|
| 848 | table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
|
---|
| 849 | table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
|
---|
| 850 | table_.rwKeywordSet().define("UTC", sdh.utc);
|
---|
[206] | 851 | table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
|
---|
| 852 | table_.rwKeywordSet().define("Epoch", sdh.epoch);
|
---|
[18] | 853 | return true;
|
---|
[50] | 854 | }
|
---|
[21] | 855 |
|
---|
[206] | 856 | SDHeader SDMemTable::getSDHeader() const
|
---|
| 857 | {
|
---|
[21] | 858 | SDHeader sdh;
|
---|
| 859 | table_.keywordSet().get("nBeam",sdh.nbeam);
|
---|
| 860 | table_.keywordSet().get("nIF",sdh.nif);
|
---|
| 861 | table_.keywordSet().get("nPol",sdh.npol);
|
---|
| 862 | table_.keywordSet().get("nChan",sdh.nchan);
|
---|
| 863 | table_.keywordSet().get("Observer", sdh.observer);
|
---|
| 864 | table_.keywordSet().get("Project", sdh.project);
|
---|
| 865 | table_.keywordSet().get("Obstype", sdh.obstype);
|
---|
| 866 | table_.keywordSet().get("AntennaName", sdh.antennaname);
|
---|
| 867 | table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
|
---|
| 868 | table_.keywordSet().get("Equinox", sdh.equinox);
|
---|
| 869 | table_.keywordSet().get("FreqRefFrame", sdh.freqref);
|
---|
| 870 | table_.keywordSet().get("FreqRefVal", sdh.reffreq);
|
---|
| 871 | table_.keywordSet().get("Bandwidth", sdh.bandwidth);
|
---|
| 872 | table_.keywordSet().get("UTC", sdh.utc);
|
---|
[206] | 873 | table_.keywordSet().get("FluxUnit", sdh.fluxunit);
|
---|
| 874 | table_.keywordSet().get("Epoch", sdh.epoch);
|
---|
[21] | 875 | return sdh;
|
---|
[18] | 876 | }
|
---|
[206] | 877 | void SDMemTable::makePersistent(const std::string& filename)
|
---|
| 878 | {
|
---|
[2] | 879 | table_.deepCopy(filename,Table::New);
|
---|
| 880 | }
|
---|
| 881 |
|
---|
[89] | 882 | Int SDMemTable::nScan() const {
|
---|
[50] | 883 | Int n = 0;
|
---|
| 884 | ROScalarColumn<Int> scans(table_, "SCANID");
|
---|
| 885 | Int previous = -1;Int current=0;
|
---|
| 886 | for (uInt i=0; i< scans.nrow();i++) {
|
---|
| 887 | scans.getScalar(i,current);
|
---|
| 888 | if (previous != current) {
|
---|
[89] | 889 | previous = current;
|
---|
[50] | 890 | n++;
|
---|
| 891 | }
|
---|
| 892 | }
|
---|
| 893 | return n;
|
---|
| 894 | }
|
---|
| 895 |
|
---|
[260] | 896 | String SDMemTable::formatSec(Double x) const
|
---|
[206] | 897 | {
|
---|
[105] | 898 | Double xcop = x;
|
---|
| 899 | MVTime mvt(xcop/24./3600.); // make days
|
---|
| 900 | if (x < 59.95)
|
---|
| 901 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
|
---|
| 902 | return mvt.string(MVTime::TIME_CLEAN_NO_H, 7)+" ";
|
---|
| 903 | };
|
---|
| 904 |
|
---|
[206] | 905 | std::string SDMemTable::getFluxUnit() const
|
---|
| 906 | {
|
---|
| 907 | String tmp;
|
---|
| 908 | table_.keywordSet().get("FluxUnit", tmp);
|
---|
| 909 | return tmp;
|
---|
| 910 | }
|
---|
| 911 |
|
---|
[218] | 912 | void SDMemTable::setFluxUnit(const std::string& unit)
|
---|
| 913 | {
|
---|
| 914 | String tmp(unit);
|
---|
| 915 | Unit tU(tmp);
|
---|
| 916 | if (tU==Unit("K") || tU==Unit("Jy")) {
|
---|
| 917 | table_.rwKeywordSet().define(String("FluxUnit"), tmp);
|
---|
| 918 | } else {
|
---|
| 919 | throw AipsError("Illegal unit - must be compatible with Jy or K");
|
---|
| 920 | }
|
---|
| 921 | }
|
---|
| 922 |
|
---|
[236] | 923 | void SDMemTable::setInstrument(const std::string& name)
|
---|
| 924 | {
|
---|
| 925 | Bool throwIt = True;
|
---|
| 926 | Instrument ins = convertInstrument (name, throwIt);
|
---|
| 927 | String nameU(name);
|
---|
| 928 | nameU.upcase();
|
---|
| 929 | table_.rwKeywordSet().define(String("AntennaName"), nameU);
|
---|
| 930 | }
|
---|
| 931 |
|
---|
[260] | 932 | std::string SDMemTable::summary() const {
|
---|
[2] | 933 | ROScalarColumn<Int> scans(table_, "SCANID");
|
---|
| 934 | ROScalarColumn<String> srcs(table_, "SRCNAME");
|
---|
[89] | 935 | ostringstream oss;
|
---|
| 936 | oss << endl;
|
---|
| 937 | oss << "--------------------------------------------------" << endl;
|
---|
| 938 | oss << " Scan Table Summary" << endl;
|
---|
| 939 | oss << "--------------------------------------------------" << endl;
|
---|
| 940 | oss.flags(std::ios_base::left);
|
---|
| 941 | oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
|
---|
| 942 | << setw(15) << "IFs:" << setw(4) << nIF() << endl
|
---|
| 943 | << setw(15) << "Polarisations:" << setw(4) << nPol() << endl
|
---|
| 944 | << setw(15) << "Channels:" << setw(4) << nChan() << endl;
|
---|
| 945 | oss << endl;
|
---|
| 946 | String tmp;
|
---|
| 947 | table_.keywordSet().get("Observer", tmp);
|
---|
| 948 | oss << setw(15) << "Observer:" << tmp << endl;
|
---|
| 949 | table_.keywordSet().get("Project", tmp);
|
---|
| 950 | oss << setw(15) << "Project:" << tmp << endl;
|
---|
| 951 | table_.keywordSet().get("Obstype", tmp);
|
---|
| 952 | oss << setw(15) << "Obs. Type:" << tmp << endl;
|
---|
| 953 | table_.keywordSet().get("AntennaName", tmp);
|
---|
| 954 | oss << setw(15) << "Antenna Name:" << tmp << endl;
|
---|
[206] | 955 | table_.keywordSet().get("FluxUnit", tmp);
|
---|
| 956 | oss << setw(15) << "Flux Unit:" << tmp << endl;
|
---|
[260] | 957 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
[105] | 958 | Vector<Double> vec;
|
---|
| 959 | t.keywordSet().get("RESTFREQS",vec);
|
---|
| 960 | oss << setw(15) << "Rest Freqs:";
|
---|
| 961 | if (vec.nelements() > 0) {
|
---|
| 962 | oss << setprecision(0) << vec << " [Hz]" << endl;
|
---|
| 963 | } else {
|
---|
| 964 | oss << "None set" << endl;
|
---|
| 965 | }
|
---|
[158] | 966 | oss << setw(15) << "Abcissa:" << getAbcissaString() << endl;
|
---|
[105] | 967 | oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
|
---|
| 968 | << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
|
---|
[89] | 969 | oss << endl;
|
---|
[2] | 970 | uInt count = 0;
|
---|
| 971 | String name;
|
---|
| 972 | Int previous = -1;Int current=0;
|
---|
[89] | 973 | Int integ = 0;
|
---|
| 974 | oss << setw(6) << "Scan"
|
---|
| 975 | << setw(12) << "Source"
|
---|
| 976 | << setw(21) << "Time"
|
---|
| 977 | << setw(11) << "Integration" << endl;
|
---|
[105] | 978 | oss << "--------------------------------------------------" << endl;
|
---|
[2] | 979 | for (uInt i=0; i< scans.nrow();i++) {
|
---|
| 980 | scans.getScalar(i,current);
|
---|
| 981 | if (previous != current) {
|
---|
| 982 | srcs.getScalar(i,name);
|
---|
[50] | 983 | previous = current;
|
---|
[105] | 984 | String t = formatSec(Double(getInterval(i)));
|
---|
[89] | 985 | oss << setw(6) << count << setw(12) << name << setw(21) << getTime(i)
|
---|
[105] | 986 | << setw(2) << setprecision(1)
|
---|
| 987 | << t << endl;
|
---|
[50] | 988 | count++;
|
---|
[89] | 989 | } else {
|
---|
| 990 | integ++;
|
---|
[2] | 991 | }
|
---|
| 992 | }
|
---|
[89] | 993 | oss << endl;
|
---|
| 994 | oss << "Table contains " << table_.nrow() << " integration(s)." << endl;
|
---|
| 995 | oss << "in " << count << " scan(s)." << endl;
|
---|
| 996 | oss << "--------------------------------------------------";
|
---|
| 997 | return String(oss);
|
---|
[2] | 998 | }
|
---|
[18] | 999 |
|
---|
[206] | 1000 | Int SDMemTable::nBeam() const
|
---|
| 1001 | {
|
---|
[18] | 1002 | Int n;
|
---|
| 1003 | table_.keywordSet().get("nBeam",n);
|
---|
| 1004 | return n;
|
---|
| 1005 | }
|
---|
| 1006 | Int SDMemTable::nIF() const {
|
---|
| 1007 | Int n;
|
---|
| 1008 | table_.keywordSet().get("nIF",n);
|
---|
| 1009 | return n;
|
---|
| 1010 | }
|
---|
| 1011 | Int SDMemTable::nPol() const {
|
---|
| 1012 | Int n;
|
---|
| 1013 | table_.keywordSet().get("nPol",n);
|
---|
| 1014 | return n;
|
---|
| 1015 | }
|
---|
| 1016 | Int SDMemTable::nChan() const {
|
---|
| 1017 | Int n;
|
---|
| 1018 | table_.keywordSet().get("nChan",n);
|
---|
| 1019 | return n;
|
---|
| 1020 | }
|
---|
[206] | 1021 | bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
|
---|
| 1022 | {
|
---|
| 1023 | ArrayColumn<String> histo(table_, "HISTORY");
|
---|
| 1024 | Vector<String> history;
|
---|
| 1025 | histo.get(whichRow, history);
|
---|
| 1026 | history.resize(history.nelements()+1,True);
|
---|
| 1027 | history[history.nelements()-1] = hist;
|
---|
| 1028 | histo.put(whichRow, history);
|
---|
| 1029 | }
|
---|
| 1030 |
|
---|
| 1031 | std::vector<std::string> SDMemTable::history(int whichRow) const
|
---|
| 1032 | {
|
---|
| 1033 | ROArrayColumn<String> hist(table_, "HISTORY");
|
---|
| 1034 | Vector<String> history;
|
---|
| 1035 | hist.get(whichRow, history);
|
---|
| 1036 | std::vector<std::string> stlout;
|
---|
| 1037 | // there is no Array<String>.tovector(std::vector<std::string>), so
|
---|
| 1038 | // do it by hand
|
---|
| 1039 | for (uInt i=0; i<history.nelements(); ++i) {
|
---|
| 1040 | stlout.push_back(history[i]);
|
---|
| 1041 | }
|
---|
| 1042 | return stlout;
|
---|
| 1043 | }
|
---|
[16] | 1044 | /*
|
---|
[18] | 1045 | void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
|
---|
[89] | 1046 |
|
---|
[16] | 1047 | std::vector<int>::iterator it;
|
---|
[206] | 1048 | ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_);
|
---|
[16] | 1049 | for (it = whichChans.begin(); it != whichChans.end(); it++) {
|
---|
| 1050 | j.reset(j.begin(uInt(*it)));
|
---|
[206] | 1051 | for (ArrayAccessor<uChar, Axis<asap::BeamAxis> > i(j); i != i.end(); ++i) {
|
---|
| 1052 | for (ArrayAccessor<uChar, Axis<asap::IFAxis> > ii(i); ii != ii.end(); ++ii) {
|
---|
| 1053 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > iii(ii);
|
---|
[89] | 1054 | iii != iii.end(); ++iii) {
|
---|
| 1055 | (*iii) =
|
---|
| 1056 | }
|
---|
[16] | 1057 | }
|
---|
| 1058 | }
|
---|
| 1059 | }
|
---|
[89] | 1060 |
|
---|
[16] | 1061 | }
|
---|
| 1062 | */
|
---|
[206] | 1063 | void SDMemTable::flag(int whichRow)
|
---|
| 1064 | {
|
---|
[89] | 1065 | ArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
| 1066 | Array<uChar> arr;
|
---|
| 1067 | spec.get(whichRow, arr);
|
---|
| 1068 |
|
---|
[206] | 1069 | ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
|
---|
[89] | 1070 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
[206] | 1071 | ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
|
---|
[89] | 1072 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
[206] | 1073 | ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
|
---|
[89] | 1074 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
| 1075 |
|
---|
[206] | 1076 | for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
|
---|
[89] | 1077 | (*i) = uChar(True);
|
---|
| 1078 | }
|
---|
| 1079 |
|
---|
| 1080 | spec.put(whichRow, arr);
|
---|
| 1081 | }
|
---|
[212] | 1082 |
|
---|
| 1083 | MDirection::Types SDMemTable::getDirectionReference () const
|
---|
| 1084 | {
|
---|
| 1085 | Float eq;
|
---|
| 1086 | table_.keywordSet().get("Equinox",eq);
|
---|
| 1087 | std::map<float,string> mp;
|
---|
| 1088 | mp[2000.0] = "J2000";
|
---|
| 1089 | mp[1950.0] = "B1950";
|
---|
| 1090 | MDirection::Types mdr;
|
---|
| 1091 | if (!MDirection::getType(mdr, mp[eq])) {
|
---|
| 1092 | mdr = MDirection::J2000;
|
---|
| 1093 | cerr << "Unknown equinox using J2000" << endl;
|
---|
| 1094 | }
|
---|
| 1095 | //
|
---|
| 1096 | return mdr;
|
---|
| 1097 | }
|
---|
| 1098 |
|
---|
| 1099 | MEpoch::Types SDMemTable::getTimeReference () const
|
---|
| 1100 | {
|
---|
| 1101 | MEpoch::Types met;
|
---|
| 1102 | String ep;
|
---|
| 1103 | table_.keywordSet().get("Epoch",ep);
|
---|
| 1104 | if (!MEpoch::getType(met, ep)) {
|
---|
| 1105 | cerr << "Epoch type uknown - using UTC" << endl;
|
---|
| 1106 | met = MEpoch::UTC;
|
---|
| 1107 | }
|
---|
| 1108 | //
|
---|
| 1109 | return met;
|
---|
| 1110 | }
|
---|
| 1111 |
|
---|
[236] | 1112 |
|
---|
| 1113 | Instrument SDMemTable::convertInstrument (const String& instrument,
|
---|
| 1114 | Bool throwIt)
|
---|
| 1115 | {
|
---|
| 1116 | String t(instrument);
|
---|
| 1117 | t.upcase();
|
---|
| 1118 | //
|
---|
| 1119 | Instrument inst = asap::UNKNOWN;
|
---|
| 1120 | if (t==String("TID")) {
|
---|
| 1121 | inst = TIDBINBILLA;
|
---|
| 1122 | } else if (t==String("ATPKSMB")) {
|
---|
| 1123 | inst = PKSMULTIBEAM;
|
---|
| 1124 | } else if (t==String("ATPKSSB")) {
|
---|
| 1125 | inst = PKSSINGLEBEAM;
|
---|
| 1126 | } else if (t==String("MOPRA")) {
|
---|
| 1127 | inst = MOPRA;
|
---|
| 1128 | } else {
|
---|
| 1129 | if (throwIt) {
|
---|
| 1130 | throw AipsError("Unrecognized instrument - use function scan.set_instrument to set");
|
---|
| 1131 | }
|
---|
| 1132 | }
|
---|
| 1133 | return inst;
|
---|
| 1134 | }
|
---|
| 1135 |
|
---|