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