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