[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 |
|
---|
[125] | 32 | #include <casa/aips.h>
|
---|
[80] | 33 | #include <casa/iostream.h>
|
---|
| 34 | #include <casa/iomanip.h>
|
---|
| 35 | #include <casa/Arrays/Array.h>
|
---|
| 36 | #include <casa/Arrays/ArrayMath.h>
|
---|
| 37 | #include <casa/Arrays/MaskArrMath.h>
|
---|
| 38 | #include <casa/Arrays/ArrayLogical.h>
|
---|
| 39 | #include <casa/Arrays/ArrayAccessor.h>
|
---|
[2] | 40 |
|
---|
[80] | 41 | #include <tables/Tables/TableParse.h>
|
---|
| 42 | #include <tables/Tables/TableDesc.h>
|
---|
| 43 | #include <tables/Tables/SetupNewTab.h>
|
---|
| 44 | #include <tables/Tables/ScaColDesc.h>
|
---|
| 45 | #include <tables/Tables/ArrColDesc.h>
|
---|
[2] | 46 |
|
---|
[80] | 47 | #include <tables/Tables/ExprNode.h>
|
---|
| 48 | #include <tables/Tables/ScalarColumn.h>
|
---|
| 49 | #include <tables/Tables/ArrayColumn.h>
|
---|
| 50 | #include <tables/Tables/TableRecord.h>
|
---|
| 51 | #include <measures/Measures/MFrequency.h>
|
---|
| 52 | #include <measures/Measures/MeasTable.h>
|
---|
[105] | 53 | #include <coordinates/Coordinates/CoordinateUtil.h>
|
---|
[80] | 54 | #include <casa/Quanta/MVTime.h>
|
---|
[2] | 55 |
|
---|
| 56 | #include "SDMemTable.h"
|
---|
| 57 | #include "SDContainer.h"
|
---|
| 58 |
|
---|
[125] | 59 | using namespace casa;
|
---|
[83] | 60 | using namespace asap;
|
---|
[2] | 61 |
|
---|
[18] | 62 | SDMemTable::SDMemTable() :
|
---|
| 63 | IFSel_(0),
|
---|
| 64 | beamSel_(0),
|
---|
| 65 | polSel_(0) {
|
---|
| 66 | setup();
|
---|
| 67 | }
|
---|
[2] | 68 | SDMemTable::SDMemTable(const std::string& name) :
|
---|
| 69 | IFSel_(0),
|
---|
| 70 | beamSel_(0),
|
---|
| 71 | polSel_(0) {
|
---|
[50] | 72 | Table tab(name);
|
---|
[22] | 73 | table_ = tab.copyToMemoryTable("dummy");
|
---|
[2] | 74 | }
|
---|
| 75 |
|
---|
[16] | 76 | SDMemTable::SDMemTable(const SDMemTable& other, Bool clear) {
|
---|
[2] | 77 | this->IFSel_= other.IFSel_;
|
---|
| 78 | this->beamSel_= other.beamSel_;
|
---|
| 79 | this->polSel_= other.polSel_;
|
---|
| 80 | this->chanMask_ = other.chanMask_;
|
---|
| 81 | this->table_ = other.table_.copyToMemoryTable(String("dummy"));
|
---|
| 82 | // clear all rows()
|
---|
[16] | 83 | if (clear) {
|
---|
| 84 | this->table_.removeRow(this->table_.rowNumbers());
|
---|
| 85 | } else {
|
---|
| 86 | this->IFSel_ = other.IFSel_;
|
---|
| 87 | this->beamSel_ = other.beamSel_;
|
---|
| 88 | this->polSel_ = other.polSel_;
|
---|
| 89 | }
|
---|
[2] | 90 | }
|
---|
| 91 |
|
---|
[80] | 92 | SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) :
|
---|
[2] | 93 | IFSel_(0),
|
---|
| 94 | beamSel_(0),
|
---|
| 95 | polSel_(0) {
|
---|
| 96 | Table t = tableCommand(exprs,tab);
|
---|
[89] | 97 | if (t.nrow() == 0)
|
---|
| 98 | throw(AipsError("Query unsuccessful."));
|
---|
[22] | 99 | table_ = t.copyToMemoryTable("dummy");
|
---|
[2] | 100 | }
|
---|
| 101 |
|
---|
| 102 | SDMemTable::~SDMemTable(){
|
---|
[105] | 103 | //cerr << "goodbye from SDMemTable @ " << this << endl;
|
---|
[2] | 104 | }
|
---|
| 105 |
|
---|
| 106 | SDMemTable SDMemTable::getScan(Int scanID) {
|
---|
[80] | 107 | String cond("SELECT * from $1 WHERE SCANID == ");
|
---|
| 108 | cond += String::toString(scanID);
|
---|
| 109 | return SDMemTable(table_, cond);
|
---|
[2] | 110 | }
|
---|
| 111 |
|
---|
[80] | 112 | SDMemTable SDMemTable::getSource(const std::string& source) {
|
---|
| 113 | String cond("SELECT * from $1 WHERE SRCNAME == ");
|
---|
| 114 | cond += source;
|
---|
| 115 | return SDMemTable(table_, cond);
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[2] | 118 | void SDMemTable::setup() {
|
---|
| 119 | TableDesc td("", "1", TableDesc::Scratch);
|
---|
| 120 | td.comment() = "A SDMemTable";
|
---|
| 121 | td.addColumn(ScalarColumnDesc<Double>("TIME"));
|
---|
| 122 | td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
|
---|
| 123 | td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
|
---|
| 124 | td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
|
---|
[89] | 125 | td.addColumn(ArrayColumnDesc<Float>("TSYS"));
|
---|
| 126 | td.addColumn(ScalarColumnDesc<Int>("SCANID"));
|
---|
| 127 | td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
|
---|
[39] | 128 | td.addColumn(ArrayColumnDesc<uInt>("FREQID"));
|
---|
[78] | 129 | td.addColumn(ArrayColumnDesc<Double>("DIRECTION"));
|
---|
[105] | 130 | td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
|
---|
| 131 | td.addColumn(ScalarColumnDesc<String>("TCALTIME"));
|
---|
| 132 | td.addColumn(ArrayColumnDesc<Float>("TCAL"));
|
---|
| 133 | td.addColumn(ScalarColumnDesc<Float>("AZIMUTH"));
|
---|
| 134 | td.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
|
---|
| 135 | td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
|
---|
| 136 | td.addColumn(ScalarColumnDesc<Int>("REFBEAM"));
|
---|
| 137 |
|
---|
[2] | 138 | // Now create a new table from the description.
|
---|
[18] | 139 |
|
---|
[22] | 140 | SetupNewTable aNewTab("dummy", td, Table::New);
|
---|
[89] | 141 | table_ = Table(aNewTab, Table::Memory, 0);
|
---|
[2] | 142 | }
|
---|
| 143 |
|
---|
| 144 | std::string SDMemTable::getSourceName(Int whichRow) const {
|
---|
| 145 | ROScalarColumn<String> src(table_, "SRCNAME");
|
---|
| 146 | String name;
|
---|
| 147 | src.get(whichRow, name);
|
---|
| 148 | return name;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[50] | 151 | std::string SDMemTable::getTime(Int whichRow) const {
|
---|
[2] | 152 | ROScalarColumn<Double> src(table_, "TIME");
|
---|
| 153 | Double tm;
|
---|
| 154 | src.get(whichRow, tm);
|
---|
[50] | 155 | MVTime mvt(tm);
|
---|
[105] | 156 | mvt.setFormat(MVTime::TIME);
|
---|
[50] | 157 | ostringstream oss;
|
---|
| 158 | oss << mvt;
|
---|
| 159 | String str(oss);
|
---|
| 160 | return str;
|
---|
[2] | 161 | }
|
---|
[50] | 162 | double SDMemTable::getInterval(Int whichRow) const {
|
---|
| 163 | ROScalarColumn<Double> src(table_, "INTERVAL");
|
---|
| 164 | Double intval;
|
---|
| 165 | src.get(whichRow, intval);
|
---|
| 166 | return intval;
|
---|
| 167 | }
|
---|
[2] | 168 |
|
---|
| 169 | bool SDMemTable::setIF(Int whichIF) {
|
---|
[50] | 170 | if ( whichIF >= 0 && whichIF < nIF()) {
|
---|
[2] | 171 | IFSel_ = whichIF;
|
---|
| 172 | return true;
|
---|
[50] | 173 | }
|
---|
| 174 | return false;
|
---|
[2] | 175 | }
|
---|
[50] | 176 |
|
---|
[2] | 177 | bool SDMemTable::setBeam(Int whichBeam) {
|
---|
[50] | 178 | if ( whichBeam >= 0 && whichBeam < nBeam()) {
|
---|
[2] | 179 | beamSel_ = whichBeam;
|
---|
| 180 | return true;
|
---|
[50] | 181 | }
|
---|
| 182 | return false;
|
---|
| 183 | }
|
---|
[2] | 184 |
|
---|
| 185 | bool SDMemTable::setPol(Int whichPol) {
|
---|
[50] | 186 | if ( whichPol >= 0 && whichPol < nPol()) {
|
---|
[2] | 187 | polSel_ = whichPol;
|
---|
| 188 | return true;
|
---|
[50] | 189 | }
|
---|
| 190 | return false;
|
---|
[2] | 191 | }
|
---|
| 192 |
|
---|
[68] | 193 | bool SDMemTable::setMask(std::vector<int> whichChans) {
|
---|
[16] | 194 | ROArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
| 195 | std::vector<int>::iterator it;
|
---|
| 196 | uInt n = spec.shape(0)(3);
|
---|
[105] | 197 | if (whichChans.empty()) {
|
---|
| 198 | chanMask_ = std::vector<bool>(n,true);
|
---|
| 199 | return true;
|
---|
| 200 | }
|
---|
[16] | 201 | chanMask_.resize(n,true);
|
---|
[39] | 202 | for (it = whichChans.begin(); it != whichChans.end(); ++it) {
|
---|
[105] | 203 | if (*it < n) {
|
---|
[16] | 204 | chanMask_[*it] = false;
|
---|
[105] | 205 | }
|
---|
[16] | 206 | }
|
---|
[2] | 207 | return true;
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[16] | 210 | std::vector<bool> SDMemTable::getMask(Int whichRow) const {
|
---|
| 211 | std::vector<bool> mask;
|
---|
| 212 | ROArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
| 213 | Array<uChar> arr;
|
---|
| 214 | spec.get(whichRow, arr);
|
---|
| 215 | ArrayAccessor<uChar, Axis<0> > aa0(arr);
|
---|
| 216 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
| 217 | ArrayAccessor<uChar, Axis<1> > aa1(aa0);
|
---|
| 218 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
| 219 | ArrayAccessor<uChar, Axis<2> > aa2(aa1);
|
---|
| 220 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
| 221 |
|
---|
| 222 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
|
---|
| 223 |
|
---|
| 224 | std::vector<bool> tmp;
|
---|
| 225 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here
|
---|
| 226 | std::vector<bool>::iterator miter;
|
---|
| 227 | miter = tmp.begin();
|
---|
| 228 |
|
---|
| 229 | for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) {
|
---|
| 230 | bool out =!static_cast<bool>(*i);
|
---|
| 231 | if (useUserMask) {
|
---|
| 232 | out = out && (*miter);
|
---|
| 233 | miter++;
|
---|
| 234 | }
|
---|
| 235 | mask.push_back(out);
|
---|
[89] | 236 | }
|
---|
[16] | 237 | return mask;
|
---|
[2] | 238 | }
|
---|
[50] | 239 | std::vector<float> SDMemTable::getSpectrum(Int whichRow) const {
|
---|
[2] | 240 |
|
---|
| 241 | std::vector<float> spectrum;
|
---|
| 242 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 243 | Array<Float> arr;
|
---|
| 244 | spec.get(whichRow, arr);
|
---|
| 245 | ArrayAccessor<Float, Axis<0> > aa0(arr);
|
---|
| 246 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
| 247 | ArrayAccessor<Float, Axis<1> > aa1(aa0);
|
---|
| 248 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
[16] | 249 | ArrayAccessor<Float, Axis<2> > aa2(aa1);
|
---|
| 250 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
| 251 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) {
|
---|
| 252 | spectrum.push_back(*i);
|
---|
[2] | 253 | }
|
---|
| 254 | return spectrum;
|
---|
| 255 | }
|
---|
[105] | 256 | std::vector<string> SDMemTable::getCoordInfo() const {
|
---|
| 257 | String un;
|
---|
| 258 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 259 | String sunit;
|
---|
| 260 | t.keywordSet().get("UNIT",sunit);
|
---|
| 261 | String dpl;
|
---|
| 262 | t.keywordSet().get("DOPPLER",dpl);
|
---|
| 263 | if (dpl == "") dpl = "RADIO";
|
---|
| 264 | String rfrm;
|
---|
| 265 | t.keywordSet().get("REFFRAME",rfrm);
|
---|
| 266 | std::vector<string> inf;
|
---|
| 267 | inf.push_back(sunit);
|
---|
| 268 | inf.push_back(rfrm);
|
---|
| 269 | inf.push_back(dpl);
|
---|
| 270 | return inf;
|
---|
| 271 | }
|
---|
[39] | 272 |
|
---|
[105] | 273 | void SDMemTable::setCoordInfo(std::vector<string> theinfo) {
|
---|
| 274 |
|
---|
| 275 | std::vector<string>::iterator it;
|
---|
| 276 | String un,rfrm,dpl;
|
---|
| 277 | un = theinfo[0];
|
---|
| 278 | rfrm = theinfo[1];
|
---|
| 279 | dpl = theinfo[2];
|
---|
| 280 |
|
---|
| 281 | //String un(theunit);
|
---|
| 282 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
|
---|
| 283 | Vector<Double> rstf;
|
---|
| 284 | t.keywordSet().get("RESTFREQS",rstf);
|
---|
| 285 | Bool canDo = True;
|
---|
| 286 | Unit u1("km/s");Unit u2("Hz");
|
---|
| 287 | if (Unit(un) == u1) {
|
---|
| 288 | Vector<Double> rstf;
|
---|
| 289 | t.keywordSet().get("RESTFREQS",rstf);
|
---|
| 290 | if (rstf.nelements() == 0) {
|
---|
| 291 | throw(AipsError("Can't set unit to km/s if no restfrequencies are specified"));
|
---|
| 292 | }
|
---|
| 293 | } else if (Unit(un) != u2 && un != "") {
|
---|
| 294 | throw(AipsError("Unit not conformant with Spectral Coordinates"));
|
---|
| 295 | }
|
---|
| 296 | t.rwKeywordSet().define("UNIT", un);
|
---|
| 297 |
|
---|
| 298 | MFrequency::Types mdr;
|
---|
| 299 | if (!MFrequency::getType(mdr, rfrm)) {
|
---|
| 300 |
|
---|
| 301 | Int a,b;const uInt* c;
|
---|
| 302 | const String* valid = MFrequency::allMyTypes(a, b, c);
|
---|
| 303 | String pfix = "Please specify a legal frame type. Types are\n";
|
---|
| 304 | throw(AipsError(pfix+(*valid)));
|
---|
| 305 | } else {
|
---|
| 306 | t.rwKeywordSet().define("REFFRAME",rfrm);
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | }
|
---|
| 310 |
|
---|
| 311 | std::vector<double> SDMemTable::getAbscissa(Int whichRow) {
|
---|
[39] | 312 | std::vector<double> absc(nChan());
|
---|
[89] | 313 | Vector<Double> absc1(nChan());
|
---|
[39] | 314 | indgen(absc1);
|
---|
| 315 | ROArrayColumn<uInt> fid(table_, "FREQID");
|
---|
| 316 | Vector<uInt> v;
|
---|
| 317 | fid.get(whichRow, v);
|
---|
| 318 | uInt specidx = v(IFSel_);
|
---|
| 319 | SpectralCoordinate spc = getCoordinate(specidx);
|
---|
[78] | 320 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 321 | String rf;
|
---|
[105] | 322 | //t.keywordSet().get("EQUINOX",rf);
|
---|
[78] | 323 | MDirection::Types mdr;
|
---|
[105] | 324 | //if (!MDirection::getType(mdr, rf)) {
|
---|
| 325 | mdr = MDirection::J2000;
|
---|
| 326 | //cout << "Unknown equinox using J2000" << endl;
|
---|
| 327 | //}
|
---|
[78] | 328 | ROArrayColumn<Double> dir(table_, "DIRECTION");
|
---|
| 329 | Array<Double> posit;
|
---|
| 330 | dir.get(whichRow,posit);
|
---|
| 331 | Vector<Double> wpos(2);
|
---|
| 332 | wpos[0] = posit(IPosition(2,beamSel_,0));
|
---|
| 333 | wpos[1] = posit(IPosition(2,beamSel_,1));
|
---|
| 334 | Quantum<Double> lon(wpos[0],Unit(String("rad")));
|
---|
| 335 | Quantum<Double> lat(wpos[1],Unit(String("rad")));
|
---|
| 336 | MDirection direct(lon, lat, mdr);
|
---|
| 337 | ROScalarColumn<Double> tme(table_, "TIME");
|
---|
| 338 | Double obstime;
|
---|
| 339 | tme.get(whichRow,obstime);
|
---|
[89] | 340 | MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
|
---|
[78] | 341 | MEpoch epoch(tm2);
|
---|
| 342 |
|
---|
| 343 | Vector<Double> antpos;
|
---|
| 344 | table_.keywordSet().get("AntennaPosition", antpos);
|
---|
| 345 | MVPosition mvpos(antpos(0),antpos(1),antpos(2));
|
---|
| 346 | MPosition pos(mvpos);
|
---|
[105] | 347 | String sunit;
|
---|
| 348 | t.keywordSet().get("UNIT",sunit);
|
---|
| 349 | if (sunit == "") sunit = "pixel";
|
---|
| 350 | Unit u(sunit);
|
---|
| 351 | String frm;
|
---|
| 352 | t.keywordSet().get("REFFRAME",frm);
|
---|
| 353 | if (frm == "") frm = "TOPO";
|
---|
| 354 | String dpl;
|
---|
| 355 | t.keywordSet().get("DOPPLER",dpl);
|
---|
| 356 | if (dpl == "") dpl = "RADIO";
|
---|
[78] | 357 | MFrequency::Types mtype;
|
---|
[105] | 358 | if (!MFrequency::getType(mtype, frm)) {
|
---|
[89] | 359 | cout << "Frequency type unknown assuming TOPO" << endl;
|
---|
[78] | 360 | mtype = MFrequency::TOPO;
|
---|
| 361 | }
|
---|
[105] | 362 |
|
---|
| 363 | if (!spc.setReferenceConversion(mtype,epoch,pos,direct)) {
|
---|
| 364 | throw(AipsError("Couldn't convert frequency frame."));
|
---|
| 365 | }
|
---|
[78] | 366 |
|
---|
[39] | 367 | if ( u == Unit("km/s") ) {
|
---|
[89] | 368 | Vector<Double> rstf;
|
---|
| 369 | t.keywordSet().get("RESTFREQS",rstf);
|
---|
| 370 | if (rstf.nelements() > 0) {
|
---|
[121] | 371 | if (rstf.nelements() >= nIF())
|
---|
[125] | 372 | spc.selectRestFrequency(uInt(IFSel_));
|
---|
[89] | 373 | spc.setVelocity(u.getName());
|
---|
[39] | 374 | Vector<Double> wrld;
|
---|
| 375 | spc.pixelToVelocity(wrld,absc1);
|
---|
| 376 | std::vector<double>::iterator it;
|
---|
| 377 | uInt i = 0;
|
---|
| 378 | for (it = absc.begin(); it != absc.end(); ++it) {
|
---|
[89] | 379 | (*it) = wrld[i];
|
---|
| 380 | i++;
|
---|
[39] | 381 | }
|
---|
| 382 | }
|
---|
| 383 | } else if (u == Unit("Hz")) {
|
---|
| 384 | Vector<String> wau(1); wau = u.getName();
|
---|
| 385 | spc.setWorldAxisUnits(wau);
|
---|
| 386 | std::vector<double>::iterator it;
|
---|
| 387 | Double tmp;
|
---|
| 388 | uInt i = 0;
|
---|
[89] | 389 | for (it = absc.begin(); it != absc.end(); ++it) {
|
---|
[39] | 390 | spc.toWorld(tmp,absc1[i]);
|
---|
| 391 | (*it) = tmp;
|
---|
| 392 | i++;
|
---|
| 393 | }
|
---|
[105] | 394 |
|
---|
| 395 | } else {
|
---|
| 396 | // assume channels/pixels
|
---|
| 397 | std::vector<double>::iterator it;
|
---|
| 398 | uInt i=0;
|
---|
| 399 | for (it = absc.begin(); it != absc.end(); ++it) {
|
---|
| 400 | (*it) = Double(i++);
|
---|
| 401 | }
|
---|
[39] | 402 | }
|
---|
| 403 | return absc;
|
---|
| 404 | }
|
---|
| 405 |
|
---|
[105] | 406 | std::string SDMemTable::getAbscissaString(Int whichRow)
|
---|
| 407 | {
|
---|
| 408 | ROArrayColumn<uInt> fid(table_, "FREQID");
|
---|
| 409 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 410 | String sunit;
|
---|
| 411 | t.keywordSet().get("UNIT",sunit);
|
---|
| 412 | if (sunit == "") sunit = "pixel";
|
---|
| 413 | Unit u(sunit);
|
---|
| 414 | Vector<uInt> v;
|
---|
| 415 | fid.get(whichRow, v);
|
---|
| 416 | uInt specidx = v(IFSel_);
|
---|
| 417 | SpectralCoordinate spc = getCoordinate(specidx);
|
---|
| 418 | String frm;
|
---|
| 419 | t.keywordSet().get("REFFRAME",frm);
|
---|
| 420 | MFrequency::Types mtype;
|
---|
| 421 | if (!MFrequency::getType(mtype, frm)) {
|
---|
| 422 | cout << "Frequency type unknown assuming TOPO" << endl;
|
---|
| 423 | mtype = MFrequency::TOPO;
|
---|
| 424 | }
|
---|
| 425 | spc.setFrequencySystem(mtype);
|
---|
| 426 | String s = "Channel";
|
---|
| 427 | if (u == Unit("km/s")) {
|
---|
| 428 | spc.setVelocity(u.getName());
|
---|
| 429 | s = CoordinateUtil::axisLabel(spc,0,True,True,True);
|
---|
| 430 | } else if (u == Unit("Hz")) {
|
---|
| 431 | Vector<String> wau(1);wau = u.getName();
|
---|
| 432 | spc.setWorldAxisUnits(wau);
|
---|
| 433 | s = CoordinateUtil::axisLabel(spc);
|
---|
| 434 | }
|
---|
| 435 | return s;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
[89] | 438 | void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow) {
|
---|
| 439 | ArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 440 | Array<Float> arr;
|
---|
| 441 | spec.get(whichRow, arr);
|
---|
| 442 | if (spectrum.size() != arr.shape()(3)) {
|
---|
| 443 | throw(AipsError("Attempting to set spectrum with incorrect length."));
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | ArrayAccessor<Float, Axis<0> > aa0(arr);
|
---|
| 447 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
| 448 | ArrayAccessor<Float, Axis<1> > aa1(aa0);
|
---|
| 449 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
| 450 | ArrayAccessor<Float, Axis<2> > aa2(aa1);
|
---|
| 451 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
| 452 |
|
---|
| 453 | std::vector<float>::iterator it = spectrum.begin();
|
---|
| 454 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) {
|
---|
| 455 | (*i) = Float(*it);
|
---|
| 456 | it++;
|
---|
| 457 | }
|
---|
| 458 | spec.put(whichRow, arr);
|
---|
| 459 | }
|
---|
| 460 |
|
---|
[68] | 461 | void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) {
|
---|
[21] | 462 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 463 | Array<Float> arr;
|
---|
| 464 | spec.get(whichRow, arr);
|
---|
| 465 | spectrum.resize(arr.shape()(3));
|
---|
| 466 | ArrayAccessor<Float, Axis<0> > aa0(arr);
|
---|
| 467 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
| 468 | ArrayAccessor<Float, Axis<1> > aa1(aa0);
|
---|
| 469 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
| 470 | ArrayAccessor<Float, Axis<2> > aa2(aa1);
|
---|
| 471 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
[2] | 472 |
|
---|
[21] | 473 | ArrayAccessor<Float, Axis<0> > va(spectrum);
|
---|
| 474 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) {
|
---|
| 475 | (*va) = (*i);
|
---|
| 476 | va++;
|
---|
| 477 | }
|
---|
| 478 | }
|
---|
[89] | 479 | /*
|
---|
[68] | 480 | void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
|
---|
[21] | 481 | ROArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
| 482 | Array<uChar> arr;
|
---|
| 483 | spec.get(whichRow, arr);
|
---|
| 484 | mask.resize(arr.shape()(3));
|
---|
| 485 |
|
---|
| 486 | ArrayAccessor<uChar, Axis<0> > aa0(arr);
|
---|
| 487 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
| 488 | ArrayAccessor<uChar, Axis<1> > aa1(aa0);
|
---|
| 489 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
| 490 | ArrayAccessor<uChar, Axis<2> > aa2(aa1);
|
---|
| 491 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
| 492 |
|
---|
| 493 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
|
---|
[89] | 494 |
|
---|
[21] | 495 | ArrayAccessor<Bool, Axis<0> > va(mask);
|
---|
| 496 | std::vector<bool> tmp;
|
---|
| 497 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
|
---|
[89] | 498 | // iterator should work on chanMask_??
|
---|
[21] | 499 | std::vector<bool>::iterator miter;
|
---|
| 500 | miter = tmp.begin();
|
---|
| 501 |
|
---|
| 502 | for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) {
|
---|
| 503 | bool out =!static_cast<bool>(*i);
|
---|
| 504 | if (useUserMask) {
|
---|
| 505 | out = out && (*miter);
|
---|
| 506 | miter++;
|
---|
| 507 | }
|
---|
| 508 | (*va) = out;
|
---|
| 509 | va++;
|
---|
[89] | 510 | }
|
---|
[21] | 511 | }
|
---|
[89] | 512 | */
|
---|
[16] | 513 | MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
|
---|
[89] | 514 | Bool useSelection) {
|
---|
[2] | 515 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 516 | Array<Float> arr;
|
---|
| 517 | ROArrayColumn<uChar> flag(table_, "FLAGTRA");
|
---|
| 518 | Array<uChar> farr;
|
---|
| 519 | spec.get(whichRow, arr);
|
---|
| 520 | flag.get(whichRow, farr);
|
---|
| 521 | Array<Bool> barr(farr.shape());convertArray(barr, farr);
|
---|
| 522 | MaskedArray<Float> marr;
|
---|
[16] | 523 | if (useSelection) {
|
---|
| 524 | ArrayAccessor<Float, Axis<0> > aa0(arr);
|
---|
| 525 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
| 526 | ArrayAccessor<Float, Axis<1> > aa1(aa0);
|
---|
| 527 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
| 528 | ArrayAccessor<Float, Axis<2> > aa2(aa1);
|
---|
| 529 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
[89] | 530 |
|
---|
[16] | 531 | ArrayAccessor<Bool, Axis<0> > baa0(barr);
|
---|
| 532 | baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam
|
---|
| 533 | ArrayAccessor<Bool, Axis<1> > baa1(baa0);
|
---|
| 534 | baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF
|
---|
| 535 | ArrayAccessor<Bool, Axis<2> > baa2(baa1);
|
---|
| 536 | baa2.reset(baa2.begin(uInt(polSel_)));// go to pol
|
---|
| 537 |
|
---|
| 538 | Vector<Float> a(arr.shape()(3));
|
---|
| 539 | Vector<Bool> b(barr.shape()(3));
|
---|
| 540 | ArrayAccessor<Float, Axis<0> > a0(a);
|
---|
| 541 | ArrayAccessor<Bool, Axis<0> > b0(b);
|
---|
| 542 |
|
---|
| 543 | ArrayAccessor<Bool, Axis<3> > j(baa2);
|
---|
| 544 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) {
|
---|
| 545 | (*a0) = (*i);
|
---|
| 546 | (*b0) = !(*j);
|
---|
| 547 | j++;
|
---|
| 548 | a0++;
|
---|
| 549 | b0++;
|
---|
| 550 | }
|
---|
| 551 | marr.setData(a,b);
|
---|
| 552 | } else {
|
---|
| 553 | marr.setData(arr,!barr);
|
---|
| 554 | }
|
---|
[2] | 555 | return marr;
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | Float SDMemTable::getTsys(Int whichRow) const {
|
---|
| 559 | ROArrayColumn<Float> ts(table_, "TSYS");
|
---|
| 560 | Array<Float> arr;
|
---|
| 561 | ts.get(whichRow, arr);
|
---|
| 562 | Float out;
|
---|
| 563 | IPosition ip(arr.shape());
|
---|
[16] | 564 | ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0;
|
---|
[2] | 565 | out = arr(ip);
|
---|
| 566 | return out;
|
---|
| 567 | }
|
---|
| 568 |
|
---|
[39] | 569 | SpectralCoordinate SDMemTable::getCoordinate(uInt whichIdx) const {
|
---|
| 570 |
|
---|
| 571 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 572 | if (whichIdx > t.nrow() ) {
|
---|
| 573 | cerr << "SDMemTable::getCoordinate - whichIdx out of range" << endl;
|
---|
[68] | 574 | return SpectralCoordinate();
|
---|
[39] | 575 | }
|
---|
[89] | 576 |
|
---|
[39] | 577 | Double rp,rv,inc;
|
---|
| 578 | String rf;
|
---|
[89] | 579 | Vector<Double> vec;
|
---|
[39] | 580 | ROScalarColumn<Double> rpc(t, "REFPIX");
|
---|
| 581 | ROScalarColumn<Double> rvc(t, "REFVAL");
|
---|
| 582 | ROScalarColumn<Double> incc(t, "INCREMENT");
|
---|
[89] | 583 | t.keywordSet().get("RESTFREQS",vec);
|
---|
[105] | 584 | t.keywordSet().get("BASEREFFRAME",rf);
|
---|
[89] | 585 |
|
---|
[39] | 586 | MFrequency::Types mft;
|
---|
| 587 | if (!MFrequency::getType(mft, rf)) {
|
---|
| 588 | cerr << "Frequency type unknown assuming TOPO" << endl;
|
---|
[89] | 589 | mft = MFrequency::TOPO;
|
---|
| 590 | }
|
---|
[39] | 591 | rpc.get(whichIdx, rp);
|
---|
| 592 | rvc.get(whichIdx, rv);
|
---|
| 593 | incc.get(whichIdx, inc);
|
---|
| 594 | SpectralCoordinate spec(mft,rv,inc,rp);
|
---|
[89] | 595 | if (vec.nelements() > 0)
|
---|
| 596 | spec.setRestFrequencies(vec);
|
---|
[39] | 597 | return spec;
|
---|
| 598 | }
|
---|
| 599 |
|
---|
[89] | 600 | Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
|
---|
| 601 | uInt whichIdx) {
|
---|
[50] | 602 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
|
---|
| 603 | if (whichIdx > t.nrow() ) {
|
---|
[89] | 604 | throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
|
---|
[50] | 605 | }
|
---|
| 606 | ScalarColumn<Double> rpc(t, "REFPIX");
|
---|
| 607 | ScalarColumn<Double> rvc(t, "REFVAL");
|
---|
| 608 | ScalarColumn<Double> incc(t, "INCREMENT");
|
---|
[89] | 609 |
|
---|
[50] | 610 | rpc.put(whichIdx, speccord.referencePixel()[0]);
|
---|
| 611 | rvc.put(whichIdx, speccord.referenceValue()[0]);
|
---|
| 612 | incc.put(whichIdx, speccord.increment()[0]);
|
---|
| 613 |
|
---|
| 614 | return True;
|
---|
| 615 | }
|
---|
| 616 |
|
---|
[89] | 617 | Int SDMemTable::nCoordinates() const
|
---|
| 618 | {
|
---|
| 619 | return table_.keywordSet().asTable("FREQUENCIES").nrow();
|
---|
| 620 | }
|
---|
[50] | 621 |
|
---|
[89] | 622 | void SDMemTable::setRestFreqs(std::vector<double> freqs, const std::string& theunit)
|
---|
| 623 | {
|
---|
| 624 | Vector<Double> tvec(freqs);
|
---|
| 625 | Quantum<Vector<Double> > q(tvec, String(theunit));
|
---|
| 626 | tvec.resize();
|
---|
| 627 | tvec = q.getValue("Hz");
|
---|
| 628 | Table t = table_.keywordSet().asTable("FREQUENCIES");
|
---|
| 629 | t.rwKeywordSet().define("RESTFREQS",tvec);
|
---|
| 630 | }
|
---|
| 631 |
|
---|
[39] | 632 | bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft) {
|
---|
| 633 | TableDesc td("", "1", TableDesc::Scratch);
|
---|
| 634 | td.addColumn(ScalarColumnDesc<Double>("REFPIX"));
|
---|
| 635 | td.addColumn(ScalarColumnDesc<Double>("REFVAL"));
|
---|
| 636 | td.addColumn(ScalarColumnDesc<Double>("INCREMENT"));
|
---|
| 637 | SetupNewTable aNewTab("freqs", td, Table::New);
|
---|
| 638 | Table aTable (aNewTab, Table::Memory, sdft.length());
|
---|
| 639 | ScalarColumn<Double> sc0(aTable, "REFPIX");
|
---|
| 640 | ScalarColumn<Double> sc1(aTable, "REFVAL");
|
---|
| 641 | ScalarColumn<Double> sc2(aTable, "INCREMENT");
|
---|
| 642 | for (uInt i=0; i < sdft.length(); ++i) {
|
---|
| 643 | sc0.put(i,sdft.referencePixel(i));
|
---|
| 644 | sc1.put(i,sdft.referenceValue(i));
|
---|
| 645 | sc2.put(i,sdft.increment(i));
|
---|
| 646 | }
|
---|
[105] | 647 | String rf = sdft.refFrame();
|
---|
| 648 | if (rf.contains("TOPO")) rf = "TOPO";
|
---|
| 649 |
|
---|
| 650 | aTable.rwKeywordSet().define("BASEREFFRAME", rf);
|
---|
| 651 | aTable.rwKeywordSet().define("REFFRAME", rf);
|
---|
[39] | 652 | aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
|
---|
[105] | 653 | aTable.rwKeywordSet().define("UNIT", String(""));
|
---|
| 654 | aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
|
---|
[89] | 655 | Vector<Double> rfvec;
|
---|
| 656 | aTable.rwKeywordSet().define("RESTFREQS", rfvec);
|
---|
[39] | 657 | table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable);
|
---|
| 658 | return True;
|
---|
| 659 | }
|
---|
| 660 |
|
---|
| 661 | SDFrequencyTable SDMemTable::getSDFreqTable() const {
|
---|
| 662 | SDFrequencyTable sdft;
|
---|
[89] | 663 |
|
---|
[39] | 664 | return sdft;
|
---|
| 665 | }
|
---|
| 666 |
|
---|
[2] | 667 | bool SDMemTable::putSDContainer(const SDContainer& sdc) {
|
---|
| 668 | ScalarColumn<Double> mjd(table_, "TIME");
|
---|
| 669 | ScalarColumn<String> srcn(table_, "SRCNAME");
|
---|
[105] | 670 | ScalarColumn<String> fldn(table_, "FIELDNAME");
|
---|
[2] | 671 | ArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 672 | ArrayColumn<uChar> flags(table_, "FLAGTRA");
|
---|
| 673 | ArrayColumn<Float> ts(table_, "TSYS");
|
---|
| 674 | ScalarColumn<Int> scan(table_, "SCANID");
|
---|
[16] | 675 | ScalarColumn<Double> integr(table_, "INTERVAL");
|
---|
[39] | 676 | ArrayColumn<uInt> freqid(table_, "FREQID");
|
---|
[78] | 677 | ArrayColumn<Double> dir(table_, "DIRECTION");
|
---|
[105] | 678 | ScalarColumn<Int> rbeam(table_, "REFBEAM");
|
---|
| 679 | ArrayColumn<Float> tcal(table_, "TCAL");
|
---|
| 680 | ScalarColumn<String> tcalt(table_, "TCALTIME");
|
---|
| 681 | ScalarColumn<Float> az(table_, "AZIMUTH");
|
---|
| 682 | ScalarColumn<Float> el(table_, "ELEVATION");
|
---|
| 683 | ScalarColumn<Float> para(table_, "PARANGLE");
|
---|
[2] | 684 |
|
---|
| 685 | uInt rno = table_.nrow();
|
---|
| 686 | table_.addRow();
|
---|
[89] | 687 |
|
---|
[2] | 688 | mjd.put(rno, sdc.timestamp);
|
---|
| 689 | srcn.put(rno, sdc.sourcename);
|
---|
[105] | 690 | fldn.put(rno, sdc.fieldname);
|
---|
[2] | 691 | spec.put(rno, sdc.getSpectrum());
|
---|
| 692 | flags.put(rno, sdc.getFlags());
|
---|
| 693 | ts.put(rno, sdc.getTsys());
|
---|
| 694 | scan.put(rno, sdc.scanid);
|
---|
[16] | 695 | integr.put(rno, sdc.interval);
|
---|
[39] | 696 | freqid.put(rno, sdc.getFreqMap());
|
---|
[78] | 697 | dir.put(rno, sdc.getDirection());
|
---|
[105] | 698 | rbeam.put(rno, sdc.refbeam);
|
---|
| 699 | tcal.put(rno, sdc.tcal);
|
---|
| 700 | tcalt.put(rno, sdc.tcaltime);
|
---|
| 701 | az.put(rno, sdc.azimuth);
|
---|
| 702 | el.put(rno, sdc.elevation);
|
---|
| 703 | para.put(rno, sdc.parangle);
|
---|
[89] | 704 |
|
---|
[2] | 705 | return true;
|
---|
| 706 | }
|
---|
[18] | 707 |
|
---|
[21] | 708 | SDContainer SDMemTable::getSDContainer(uInt whichRow) const {
|
---|
| 709 | ROScalarColumn<Double> mjd(table_, "TIME");
|
---|
| 710 | ROScalarColumn<String> srcn(table_, "SRCNAME");
|
---|
[105] | 711 | ROScalarColumn<String> fldn(table_, "FIELDNAME");
|
---|
[21] | 712 | ROArrayColumn<Float> spec(table_, "SPECTRA");
|
---|
| 713 | ROArrayColumn<uChar> flags(table_, "FLAGTRA");
|
---|
| 714 | ROArrayColumn<Float> ts(table_, "TSYS");
|
---|
| 715 | ROScalarColumn<Int> scan(table_, "SCANID");
|
---|
| 716 | ROScalarColumn<Double> integr(table_, "INTERVAL");
|
---|
[39] | 717 | ROArrayColumn<uInt> freqid(table_, "FREQID");
|
---|
[78] | 718 | ROArrayColumn<Double> dir(table_, "DIRECTION");
|
---|
[105] | 719 | ROScalarColumn<Int> rbeam(table_, "REFBEAM");
|
---|
| 720 | ROArrayColumn<Float> tcal(table_, "TCAL");
|
---|
| 721 | ROScalarColumn<String> tcalt(table_, "TCALTIME");
|
---|
| 722 | ROScalarColumn<Float> az(table_, "AZIMUTH");
|
---|
| 723 | ROScalarColumn<Float> el(table_, "ELEVATION");
|
---|
| 724 | ROScalarColumn<Float> para(table_, "PARANGLE");
|
---|
[21] | 725 |
|
---|
| 726 | SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
|
---|
| 727 | mjd.get(whichRow, sdc.timestamp);
|
---|
| 728 | srcn.get(whichRow, sdc.sourcename);
|
---|
| 729 | integr.get(whichRow, sdc.interval);
|
---|
| 730 | scan.get(whichRow, sdc.scanid);
|
---|
[105] | 731 | fldn.get(whichRow, sdc.fieldname);
|
---|
| 732 | rbeam.get(whichRow, sdc.refbeam);
|
---|
| 733 | az.get(whichRow, sdc.azimuth);
|
---|
| 734 | el.get(whichRow, sdc.elevation);
|
---|
| 735 | para.get(whichRow, sdc.parangle);
|
---|
| 736 | Vector<Float> tc;
|
---|
| 737 | tcal.get(whichRow, tc);
|
---|
| 738 | sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
|
---|
| 739 | tcalt.get(whichRow, sdc.tcaltime);
|
---|
[21] | 740 | Array<Float> spectrum;
|
---|
| 741 | Array<Float> tsys;
|
---|
| 742 | Array<uChar> flagtrum;
|
---|
[39] | 743 | Vector<uInt> fmap;
|
---|
[78] | 744 | Array<Double> direction;
|
---|
[21] | 745 | spec.get(whichRow, spectrum);
|
---|
| 746 | sdc.putSpectrum(spectrum);
|
---|
| 747 | flags.get(whichRow, flagtrum);
|
---|
| 748 | sdc.putFlags(flagtrum);
|
---|
| 749 | ts.get(whichRow, tsys);
|
---|
| 750 | sdc.putTsys(tsys);
|
---|
[39] | 751 | freqid.get(whichRow, fmap);
|
---|
| 752 | sdc.putFreqMap(fmap);
|
---|
[78] | 753 | dir.get(whichRow, direction);
|
---|
| 754 | sdc.putDirection(direction);
|
---|
[21] | 755 | return sdc;
|
---|
| 756 | }
|
---|
[78] | 757 |
|
---|
[18] | 758 | bool SDMemTable::putSDHeader(const SDHeader& sdh) {
|
---|
| 759 | table_.lock();
|
---|
| 760 | table_.rwKeywordSet().define("nIF", sdh.nif);
|
---|
| 761 | table_.rwKeywordSet().define("nBeam", sdh.nbeam);
|
---|
| 762 | table_.rwKeywordSet().define("nPol", sdh.npol);
|
---|
| 763 | table_.rwKeywordSet().define("nChan", sdh.nchan);
|
---|
| 764 | table_.rwKeywordSet().define("Observer", sdh.observer);
|
---|
| 765 | table_.rwKeywordSet().define("Project", sdh.project);
|
---|
| 766 | table_.rwKeywordSet().define("Obstype", sdh.obstype);
|
---|
| 767 | table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
|
---|
| 768 | table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
|
---|
| 769 | table_.rwKeywordSet().define("Equinox", sdh.equinox);
|
---|
| 770 | table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
|
---|
| 771 | table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
|
---|
| 772 | table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
|
---|
| 773 | table_.rwKeywordSet().define("UTC", sdh.utc);
|
---|
| 774 | table_.unlock();
|
---|
| 775 | return true;
|
---|
[50] | 776 | }
|
---|
[21] | 777 |
|
---|
| 778 | SDHeader SDMemTable::getSDHeader() const {
|
---|
| 779 | SDHeader sdh;
|
---|
| 780 | table_.keywordSet().get("nBeam",sdh.nbeam);
|
---|
| 781 | table_.keywordSet().get("nIF",sdh.nif);
|
---|
| 782 | table_.keywordSet().get("nPol",sdh.npol);
|
---|
| 783 | table_.keywordSet().get("nChan",sdh.nchan);
|
---|
| 784 | table_.keywordSet().get("Observer", sdh.observer);
|
---|
| 785 | table_.keywordSet().get("Project", sdh.project);
|
---|
| 786 | table_.keywordSet().get("Obstype", sdh.obstype);
|
---|
| 787 | table_.keywordSet().get("AntennaName", sdh.antennaname);
|
---|
| 788 | table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
|
---|
| 789 | table_.keywordSet().get("Equinox", sdh.equinox);
|
---|
| 790 | table_.keywordSet().get("FreqRefFrame", sdh.freqref);
|
---|
| 791 | table_.keywordSet().get("FreqRefVal", sdh.reffreq);
|
---|
| 792 | table_.keywordSet().get("Bandwidth", sdh.bandwidth);
|
---|
| 793 | table_.keywordSet().get("UTC", sdh.utc);
|
---|
| 794 | return sdh;
|
---|
[18] | 795 | }
|
---|
[2] | 796 | void SDMemTable::makePersistent(const std::string& filename) {
|
---|
| 797 | table_.deepCopy(filename,Table::New);
|
---|
| 798 | }
|
---|
| 799 |
|
---|
[89] | 800 | Int SDMemTable::nScan() const {
|
---|
[50] | 801 | Int n = 0;
|
---|
| 802 | ROScalarColumn<Int> scans(table_, "SCANID");
|
---|
| 803 | Int previous = -1;Int current=0;
|
---|
| 804 | for (uInt i=0; i< scans.nrow();i++) {
|
---|
| 805 | scans.getScalar(i,current);
|
---|
| 806 | if (previous != current) {
|
---|
[89] | 807 | previous = current;
|
---|
[50] | 808 | n++;
|
---|
| 809 | }
|
---|
| 810 | }
|
---|
| 811 | return n;
|
---|
| 812 | }
|
---|
| 813 |
|
---|
[105] | 814 | String SDMemTable::formatSec(Double x) {
|
---|
| 815 | Double xcop = x;
|
---|
| 816 | MVTime mvt(xcop/24./3600.); // make days
|
---|
| 817 | if (x < 59.95)
|
---|
| 818 | return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
|
---|
| 819 | return mvt.string(MVTime::TIME_CLEAN_NO_H, 7)+" ";
|
---|
| 820 | };
|
---|
| 821 |
|
---|
| 822 | std::string SDMemTable::summary() {
|
---|
[2] | 823 | ROScalarColumn<Int> scans(table_, "SCANID");
|
---|
| 824 | ROScalarColumn<String> srcs(table_, "SRCNAME");
|
---|
[89] | 825 | ostringstream oss;
|
---|
| 826 | oss << endl;
|
---|
| 827 | oss << "--------------------------------------------------" << endl;
|
---|
| 828 | oss << " Scan Table Summary" << endl;
|
---|
| 829 | oss << "--------------------------------------------------" << endl;
|
---|
| 830 | oss.flags(std::ios_base::left);
|
---|
| 831 | oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
|
---|
| 832 | << setw(15) << "IFs:" << setw(4) << nIF() << endl
|
---|
| 833 | << setw(15) << "Polarisations:" << setw(4) << nPol() << endl
|
---|
| 834 | << setw(15) << "Channels:" << setw(4) << nChan() << endl;
|
---|
| 835 | oss << endl;
|
---|
| 836 | String tmp;
|
---|
| 837 | table_.keywordSet().get("Observer", tmp);
|
---|
| 838 | oss << setw(15) << "Observer:" << tmp << endl;
|
---|
| 839 | table_.keywordSet().get("Project", tmp);
|
---|
| 840 | oss << setw(15) << "Project:" << tmp << endl;
|
---|
| 841 | table_.keywordSet().get("Obstype", tmp);
|
---|
| 842 | oss << setw(15) << "Obs. Type:" << tmp << endl;
|
---|
| 843 | table_.keywordSet().get("AntennaName", tmp);
|
---|
| 844 | oss << setw(15) << "Antenna Name:" << tmp << endl;
|
---|
[105] | 845 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
|
---|
| 846 | Vector<Double> vec;
|
---|
| 847 | t.keywordSet().get("RESTFREQS",vec);
|
---|
| 848 | oss << setw(15) << "Rest Freqs:";
|
---|
| 849 | if (vec.nelements() > 0) {
|
---|
| 850 | oss << setprecision(0) << vec << " [Hz]" << endl;
|
---|
| 851 | } else {
|
---|
| 852 | oss << "None set" << endl;
|
---|
| 853 | }
|
---|
| 854 | oss << setw(15) << "Abscissa:" << getAbscissaString() << endl;
|
---|
| 855 | oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
|
---|
| 856 | << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
|
---|
[89] | 857 | oss << endl;
|
---|
[2] | 858 | uInt count = 0;
|
---|
| 859 | String name;
|
---|
| 860 | Int previous = -1;Int current=0;
|
---|
[89] | 861 | Int integ = 0;
|
---|
| 862 | oss << setw(6) << "Scan"
|
---|
| 863 | << setw(12) << "Source"
|
---|
| 864 | << setw(21) << "Time"
|
---|
| 865 | << setw(11) << "Integration" << endl;
|
---|
[105] | 866 | oss << "--------------------------------------------------" << endl;
|
---|
[2] | 867 | for (uInt i=0; i< scans.nrow();i++) {
|
---|
| 868 | scans.getScalar(i,current);
|
---|
| 869 | if (previous != current) {
|
---|
| 870 | srcs.getScalar(i,name);
|
---|
[50] | 871 | previous = current;
|
---|
[105] | 872 | String t = formatSec(Double(getInterval(i)));
|
---|
[89] | 873 | oss << setw(6) << count << setw(12) << name << setw(21) << getTime(i)
|
---|
[105] | 874 | << setw(2) << setprecision(1)
|
---|
| 875 | << t << endl;
|
---|
[50] | 876 | count++;
|
---|
[89] | 877 | } else {
|
---|
| 878 | integ++;
|
---|
[2] | 879 | }
|
---|
| 880 | }
|
---|
[89] | 881 | oss << endl;
|
---|
| 882 | oss << "Table contains " << table_.nrow() << " integration(s)." << endl;
|
---|
| 883 | oss << "in " << count << " scan(s)." << endl;
|
---|
| 884 | oss << "--------------------------------------------------";
|
---|
| 885 | return String(oss);
|
---|
[2] | 886 | }
|
---|
[18] | 887 |
|
---|
| 888 | Int SDMemTable::nBeam() const {
|
---|
| 889 | Int n;
|
---|
| 890 | table_.keywordSet().get("nBeam",n);
|
---|
| 891 | return n;
|
---|
| 892 | }
|
---|
| 893 | Int SDMemTable::nIF() const {
|
---|
| 894 | Int n;
|
---|
| 895 | table_.keywordSet().get("nIF",n);
|
---|
| 896 | return n;
|
---|
| 897 | }
|
---|
| 898 | Int SDMemTable::nPol() const {
|
---|
| 899 | Int n;
|
---|
| 900 | table_.keywordSet().get("nPol",n);
|
---|
| 901 | return n;
|
---|
| 902 | }
|
---|
| 903 | Int SDMemTable::nChan() const {
|
---|
| 904 | Int n;
|
---|
| 905 | table_.keywordSet().get("nChan",n);
|
---|
| 906 | return n;
|
---|
| 907 | }
|
---|
[16] | 908 | /*
|
---|
[18] | 909 | void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
|
---|
[89] | 910 |
|
---|
[16] | 911 | std::vector<int>::iterator it;
|
---|
| 912 | ArrayAccessor<uChar, Axis<2> > j(flags_);
|
---|
| 913 | for (it = whichChans.begin(); it != whichChans.end(); it++) {
|
---|
| 914 | j.reset(j.begin(uInt(*it)));
|
---|
| 915 | for (ArrayAccessor<uChar, Axis<0> > i(j); i != i.end(); ++i) {
|
---|
| 916 | for (ArrayAccessor<uChar, Axis<1> > ii(i); ii != ii.end(); ++ii) {
|
---|
[89] | 917 | for (ArrayAccessor<uChar, Axis<3> > iii(ii);
|
---|
| 918 | iii != iii.end(); ++iii) {
|
---|
| 919 | (*iii) =
|
---|
| 920 | }
|
---|
[16] | 921 | }
|
---|
| 922 | }
|
---|
| 923 | }
|
---|
[89] | 924 |
|
---|
[16] | 925 | }
|
---|
| 926 | */
|
---|
[89] | 927 | void SDMemTable::flag(int whichRow) {
|
---|
| 928 | ArrayColumn<uChar> spec(table_, "FLAGTRA");
|
---|
| 929 | Array<uChar> arr;
|
---|
| 930 | spec.get(whichRow, arr);
|
---|
| 931 |
|
---|
| 932 | ArrayAccessor<uChar, Axis<0> > aa0(arr);
|
---|
| 933 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
|
---|
| 934 | ArrayAccessor<uChar, Axis<1> > aa1(aa0);
|
---|
| 935 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
|
---|
| 936 | ArrayAccessor<uChar, Axis<2> > aa2(aa1);
|
---|
| 937 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
|
---|
| 938 |
|
---|
| 939 | for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) {
|
---|
| 940 | (*i) = uChar(True);
|
---|
| 941 | }
|
---|
| 942 |
|
---|
| 943 | spec.put(whichRow, arr);
|
---|
| 944 | }
|
---|