1 | //#--------------------------------------------------------------------------- |
---|
2 | //# SDMemTable.cc: A MemoryTable container for single dish integrations |
---|
3 | //#--------------------------------------------------------------------------- |
---|
4 | //# Copyright (C) 2004 |
---|
5 | //# Malte Marquarding, 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 | |
---|
33 | #include <aips/iostream.h> |
---|
34 | #include <aips/iomanip.h> |
---|
35 | #include <aips/Arrays/Array.h> |
---|
36 | #include <aips/Arrays/ArrayMath.h> |
---|
37 | #include <aips/Arrays/MaskArrMath.h> |
---|
38 | #include <aips/Arrays/ArrayLogical.h> |
---|
39 | #include <aips/Arrays/ArrayAccessor.h> |
---|
40 | |
---|
41 | #include <aips/Tables/TableParse.h> |
---|
42 | #include <aips/Tables/TableDesc.h> |
---|
43 | #include <aips/Tables/SetupNewTab.h> |
---|
44 | #include <aips/Tables/ScaColDesc.h> |
---|
45 | #include <aips/Tables/ArrColDesc.h> |
---|
46 | |
---|
47 | #include <aips/Tables/ExprNode.h> |
---|
48 | #include <aips/Tables/ScalarColumn.h> |
---|
49 | #include <aips/Tables/ArrayColumn.h> |
---|
50 | #include <aips/Tables/TableRecord.h> |
---|
51 | #include <aips/Measures/MFrequency.h> |
---|
52 | #include <aips/Measures/MeasTable.h> |
---|
53 | #include <aips/Quanta/MVTime.h> |
---|
54 | |
---|
55 | #include "SDMemTable.h" |
---|
56 | #include "SDContainer.h" |
---|
57 | |
---|
58 | using namespace atnf_sd; |
---|
59 | |
---|
60 | SDMemTable::SDMemTable() : |
---|
61 | IFSel_(0), |
---|
62 | beamSel_(0), |
---|
63 | polSel_(0) { |
---|
64 | setup(); |
---|
65 | } |
---|
66 | SDMemTable::SDMemTable(const std::string& name) : |
---|
67 | IFSel_(0), |
---|
68 | beamSel_(0), |
---|
69 | polSel_(0) { |
---|
70 | Table tab(name); |
---|
71 | table_ = tab.copyToMemoryTable("dummy"); |
---|
72 | } |
---|
73 | |
---|
74 | SDMemTable::SDMemTable(const SDMemTable& other, Bool clear) { |
---|
75 | this->IFSel_= other.IFSel_; |
---|
76 | this->beamSel_= other.beamSel_; |
---|
77 | this->polSel_= other.polSel_; |
---|
78 | this->chanMask_ = other.chanMask_; |
---|
79 | this->table_ = other.table_.copyToMemoryTable(String("dummy")); |
---|
80 | // clear all rows() |
---|
81 | if (clear) { |
---|
82 | this->table_.removeRow(this->table_.rowNumbers()); |
---|
83 | } else { |
---|
84 | this->IFSel_ = other.IFSel_; |
---|
85 | this->beamSel_ = other.beamSel_; |
---|
86 | this->polSel_ = other.polSel_; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | SDMemTable::SDMemTable(const Table& tab, Int scanID) : |
---|
91 | IFSel_(0), |
---|
92 | beamSel_(0), |
---|
93 | polSel_(0) { |
---|
94 | String exprs = String("select * from $1 where SCANID == ") |
---|
95 | +String::toString(scanID); |
---|
96 | //cerr << exprs << endl; |
---|
97 | Table t = tableCommand(exprs,tab); |
---|
98 | table_ = t.copyToMemoryTable("dummy"); |
---|
99 | } |
---|
100 | |
---|
101 | SDMemTable::~SDMemTable(){ |
---|
102 | //cerr << "goodbye from SDMemTable @ " << this << endl; |
---|
103 | } |
---|
104 | |
---|
105 | SDMemTable SDMemTable::getScan(Int scanID) { |
---|
106 | return SDMemTable(table_, scanID); |
---|
107 | } |
---|
108 | |
---|
109 | void SDMemTable::setup() { |
---|
110 | TableDesc td("", "1", TableDesc::Scratch); |
---|
111 | td.comment() = "A SDMemTable"; |
---|
112 | td.addColumn(ScalarColumnDesc<Double>("TIME")); |
---|
113 | td.addColumn(ScalarColumnDesc<String>("SRCNAME")); |
---|
114 | td.addColumn(ArrayColumnDesc<Float>("SPECTRA")); |
---|
115 | td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA")); |
---|
116 | td.addColumn(ArrayColumnDesc<Float>("TSYS")); |
---|
117 | td.addColumn(ScalarColumnDesc<Int>("SCANID")); |
---|
118 | td.addColumn(ScalarColumnDesc<Double>("INTERVAL")); |
---|
119 | td.addColumn(ArrayColumnDesc<uInt>("FREQID")); |
---|
120 | td.addColumn(ArrayColumnDesc<Double>("DIRECTION")); |
---|
121 | // Now create a new table from the description. |
---|
122 | |
---|
123 | SetupNewTable aNewTab("dummy", td, Table::New); |
---|
124 | table_ = Table(aNewTab, Table::Memory, 0); |
---|
125 | } |
---|
126 | |
---|
127 | std::string SDMemTable::getSourceName(Int whichRow) const { |
---|
128 | ROScalarColumn<String> src(table_, "SRCNAME"); |
---|
129 | String name; |
---|
130 | src.get(whichRow, name); |
---|
131 | return name; |
---|
132 | } |
---|
133 | |
---|
134 | std::string SDMemTable::getTime(Int whichRow) const { |
---|
135 | ROScalarColumn<Double> src(table_, "TIME"); |
---|
136 | Double tm; |
---|
137 | src.get(whichRow, tm); |
---|
138 | MVTime mvt(tm); |
---|
139 | mvt.setFormat(MVTime::YMD); |
---|
140 | ostringstream oss; |
---|
141 | oss << mvt; |
---|
142 | String str(oss); |
---|
143 | return str; |
---|
144 | } |
---|
145 | double SDMemTable::getInterval(Int whichRow) const { |
---|
146 | ROScalarColumn<Double> src(table_, "INTERVAL"); |
---|
147 | Double intval; |
---|
148 | src.get(whichRow, intval); |
---|
149 | return intval; |
---|
150 | } |
---|
151 | |
---|
152 | bool SDMemTable::setIF(Int whichIF) { |
---|
153 | if ( whichIF >= 0 && whichIF < nIF()) { |
---|
154 | IFSel_ = whichIF; |
---|
155 | return true; |
---|
156 | } |
---|
157 | return false; |
---|
158 | } |
---|
159 | |
---|
160 | bool SDMemTable::setBeam(Int whichBeam) { |
---|
161 | if ( whichBeam >= 0 && whichBeam < nBeam()) { |
---|
162 | beamSel_ = whichBeam; |
---|
163 | return true; |
---|
164 | } |
---|
165 | return false; |
---|
166 | } |
---|
167 | |
---|
168 | bool SDMemTable::setPol(Int whichPol) { |
---|
169 | if ( whichPol >= 0 && whichPol < nPol()) { |
---|
170 | polSel_ = whichPol; |
---|
171 | return true; |
---|
172 | } |
---|
173 | return false; |
---|
174 | } |
---|
175 | |
---|
176 | bool SDMemTable::setMask(std::vector<int> whichChans) { |
---|
177 | ROArrayColumn<uChar> spec(table_, "FLAGTRA"); |
---|
178 | |
---|
179 | std::vector<int>::iterator it; |
---|
180 | uInt n = spec.shape(0)(3); |
---|
181 | chanMask_.resize(n,true); |
---|
182 | for (it = whichChans.begin(); it != whichChans.end(); ++it) { |
---|
183 | if (*it < n) |
---|
184 | chanMask_[*it] = false; |
---|
185 | } |
---|
186 | return true; |
---|
187 | } |
---|
188 | |
---|
189 | std::vector<bool> SDMemTable::getMask(Int whichRow) const { |
---|
190 | std::vector<bool> mask; |
---|
191 | ROArrayColumn<uChar> spec(table_, "FLAGTRA"); |
---|
192 | Array<uChar> arr; |
---|
193 | spec.get(whichRow, arr); |
---|
194 | ArrayAccessor<uChar, Axis<0> > aa0(arr); |
---|
195 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
196 | ArrayAccessor<uChar, Axis<1> > aa1(aa0); |
---|
197 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
198 | ArrayAccessor<uChar, Axis<2> > aa2(aa1); |
---|
199 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
200 | |
---|
201 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) ); |
---|
202 | |
---|
203 | std::vector<bool> tmp; |
---|
204 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here |
---|
205 | std::vector<bool>::iterator miter; |
---|
206 | miter = tmp.begin(); |
---|
207 | |
---|
208 | for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
209 | bool out =!static_cast<bool>(*i); |
---|
210 | if (useUserMask) { |
---|
211 | out = out && (*miter); |
---|
212 | miter++; |
---|
213 | } |
---|
214 | mask.push_back(out); |
---|
215 | } |
---|
216 | return mask; |
---|
217 | } |
---|
218 | std::vector<float> SDMemTable::getSpectrum(Int whichRow) const { |
---|
219 | |
---|
220 | std::vector<float> spectrum; |
---|
221 | ROArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
222 | Array<Float> arr; |
---|
223 | spec.get(whichRow, arr); |
---|
224 | ArrayAccessor<Float, Axis<0> > aa0(arr); |
---|
225 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
226 | ArrayAccessor<Float, Axis<1> > aa1(aa0); |
---|
227 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
228 | ArrayAccessor<Float, Axis<2> > aa2(aa1); |
---|
229 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
230 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
231 | spectrum.push_back(*i); |
---|
232 | } |
---|
233 | return spectrum; |
---|
234 | } |
---|
235 | |
---|
236 | std::vector<double> SDMemTable::getAbscissa(Int whichRow, |
---|
237 | const std::string& whichUnit, |
---|
238 | const std::string& whichFrame, |
---|
239 | double restfreq) { |
---|
240 | std::vector<double> absc(nChan()); |
---|
241 | Vector<Double> absc1(nChan()); |
---|
242 | indgen(absc1); |
---|
243 | ROArrayColumn<uInt> fid(table_, "FREQID"); |
---|
244 | Vector<uInt> v; |
---|
245 | fid.get(whichRow, v); |
---|
246 | uInt specidx = v(IFSel_); |
---|
247 | Unit u; |
---|
248 | if (whichUnit == "") { |
---|
249 | // get unit from table |
---|
250 | } else { |
---|
251 | u = String(whichUnit); |
---|
252 | } |
---|
253 | SpectralCoordinate spc = getCoordinate(specidx); |
---|
254 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
255 | String rf; |
---|
256 | t.keywordSet().get("REFFRAME",rf); |
---|
257 | MDirection::Types mdr; |
---|
258 | MDirection::getType(mdr, rf); |
---|
259 | ROArrayColumn<Double> dir(table_, "DIRECTION"); |
---|
260 | Array<Double> posit; |
---|
261 | dir.get(whichRow,posit); |
---|
262 | Vector<Double> wpos(2); |
---|
263 | wpos[0] = posit(IPosition(2,beamSel_,0)); |
---|
264 | wpos[1] = posit(IPosition(2,beamSel_,1)); |
---|
265 | Quantum<Double> lon(wpos[0],Unit(String("rad"))); |
---|
266 | Quantum<Double> lat(wpos[1],Unit(String("rad"))); |
---|
267 | MDirection direct(lon, lat, mdr); |
---|
268 | ROScalarColumn<Double> tme(table_, "TIME"); |
---|
269 | Double obstime; |
---|
270 | tme.get(whichRow,obstime); |
---|
271 | Quantum<Double> tm(obstime, Unit(String("d"))); |
---|
272 | MVEpoch tm2(tm); |
---|
273 | MEpoch epoch(tm2); |
---|
274 | |
---|
275 | Vector<Double> antpos; |
---|
276 | table_.keywordSet().get("AntennaPosition", antpos); |
---|
277 | //MPosition pos; |
---|
278 | MVPosition mvpos(antpos(0),antpos(1),antpos(2)); |
---|
279 | MPosition pos(mvpos); |
---|
280 | //MeasTable::Observatory(pos, String("ATCA")); |
---|
281 | |
---|
282 | MFrequency::Types mtype; |
---|
283 | if (!MFrequency::getType(mtype, whichFrame)) { |
---|
284 | cerr << "Frequency type unknown assuming TOPO" << endl; |
---|
285 | mtype = MFrequency::TOPO; |
---|
286 | } |
---|
287 | spc.setReferenceConversion(mtype,epoch,pos,direct); |
---|
288 | |
---|
289 | if ( u == Unit("km/s") ) { |
---|
290 | if (Double(restfreq) > Double(0.000001)) { |
---|
291 | cerr << "converting to velocities"<< endl; |
---|
292 | spc.setRestFrequency(Double(restfreq)); |
---|
293 | spc.setVelocity(u.getName()); |
---|
294 | Vector<Double> wrld; |
---|
295 | spc.pixelToVelocity(wrld,absc1); |
---|
296 | std::vector<double>::iterator it; |
---|
297 | uInt i = 0; |
---|
298 | for (it = absc.begin(); it != absc.end(); ++it) { |
---|
299 | (*it) = wrld[i]; |
---|
300 | i++; |
---|
301 | } |
---|
302 | } |
---|
303 | } else if (u == Unit("Hz")) { |
---|
304 | Vector<String> wau(1); wau = u.getName(); |
---|
305 | spc.setWorldAxisUnits(wau); |
---|
306 | cerr << " converting in frequency" << endl; |
---|
307 | std::vector<double>::iterator it; |
---|
308 | Double tmp; |
---|
309 | uInt i = 0; |
---|
310 | for (it = absc.begin(); it != absc.end(); ++it) { |
---|
311 | spc.toWorld(tmp,absc1[i]); |
---|
312 | (*it) = tmp; |
---|
313 | i++; |
---|
314 | } |
---|
315 | } |
---|
316 | return absc; |
---|
317 | } |
---|
318 | |
---|
319 | void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) { |
---|
320 | ROArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
321 | Array<Float> arr; |
---|
322 | spec.get(whichRow, arr); |
---|
323 | spectrum.resize(arr.shape()(3)); |
---|
324 | ArrayAccessor<Float, Axis<0> > aa0(arr); |
---|
325 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
326 | ArrayAccessor<Float, Axis<1> > aa1(aa0); |
---|
327 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
328 | ArrayAccessor<Float, Axis<2> > aa2(aa1); |
---|
329 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
330 | |
---|
331 | ArrayAccessor<Float, Axis<0> > va(spectrum); |
---|
332 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
333 | (*va) = (*i); |
---|
334 | va++; |
---|
335 | } |
---|
336 | } |
---|
337 | |
---|
338 | void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const { |
---|
339 | ROArrayColumn<uChar> spec(table_, "FLAGTRA"); |
---|
340 | Array<uChar> arr; |
---|
341 | spec.get(whichRow, arr); |
---|
342 | mask.resize(arr.shape()(3)); |
---|
343 | |
---|
344 | ArrayAccessor<uChar, Axis<0> > aa0(arr); |
---|
345 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
346 | ArrayAccessor<uChar, Axis<1> > aa1(aa0); |
---|
347 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
348 | ArrayAccessor<uChar, Axis<2> > aa2(aa1); |
---|
349 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
350 | |
---|
351 | Bool useUserMask = ( chanMask_.size() == arr.shape()(3) ); |
---|
352 | |
---|
353 | ArrayAccessor<Bool, Axis<0> > va(mask); |
---|
354 | std::vector<bool> tmp; |
---|
355 | tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The |
---|
356 | // iterator should work on chanMask_?? |
---|
357 | std::vector<bool>::iterator miter; |
---|
358 | miter = tmp.begin(); |
---|
359 | |
---|
360 | for (ArrayAccessor<uChar, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
361 | bool out =!static_cast<bool>(*i); |
---|
362 | if (useUserMask) { |
---|
363 | out = out && (*miter); |
---|
364 | miter++; |
---|
365 | } |
---|
366 | (*va) = out; |
---|
367 | va++; |
---|
368 | } |
---|
369 | } |
---|
370 | |
---|
371 | MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow, |
---|
372 | Bool useSelection) { |
---|
373 | ROArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
374 | Array<Float> arr; |
---|
375 | ROArrayColumn<uChar> flag(table_, "FLAGTRA"); |
---|
376 | Array<uChar> farr; |
---|
377 | spec.get(whichRow, arr); |
---|
378 | flag.get(whichRow, farr); |
---|
379 | Array<Bool> barr(farr.shape());convertArray(barr, farr); |
---|
380 | MaskedArray<Float> marr; |
---|
381 | if (useSelection) { |
---|
382 | ArrayAccessor<Float, Axis<0> > aa0(arr); |
---|
383 | aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam |
---|
384 | ArrayAccessor<Float, Axis<1> > aa1(aa0); |
---|
385 | aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF |
---|
386 | ArrayAccessor<Float, Axis<2> > aa2(aa1); |
---|
387 | aa2.reset(aa2.begin(uInt(polSel_)));// go to pol |
---|
388 | |
---|
389 | ArrayAccessor<Bool, Axis<0> > baa0(barr); |
---|
390 | baa0.reset(baa0.begin(uInt(beamSel_)));//go to beam |
---|
391 | ArrayAccessor<Bool, Axis<1> > baa1(baa0); |
---|
392 | baa1.reset(baa1.begin(uInt(IFSel_)));// go to IF |
---|
393 | ArrayAccessor<Bool, Axis<2> > baa2(baa1); |
---|
394 | baa2.reset(baa2.begin(uInt(polSel_)));// go to pol |
---|
395 | |
---|
396 | Vector<Float> a(arr.shape()(3)); |
---|
397 | Vector<Bool> b(barr.shape()(3)); |
---|
398 | ArrayAccessor<Float, Axis<0> > a0(a); |
---|
399 | ArrayAccessor<Bool, Axis<0> > b0(b); |
---|
400 | |
---|
401 | ArrayAccessor<Bool, Axis<3> > j(baa2); |
---|
402 | for (ArrayAccessor<Float, Axis<3> > i(aa2); i != i.end(); ++i) { |
---|
403 | (*a0) = (*i); |
---|
404 | (*b0) = !(*j); |
---|
405 | j++; |
---|
406 | a0++; |
---|
407 | b0++; |
---|
408 | } |
---|
409 | marr.setData(a,b); |
---|
410 | } else { |
---|
411 | marr.setData(arr,!barr); |
---|
412 | } |
---|
413 | return marr; |
---|
414 | } |
---|
415 | |
---|
416 | Float SDMemTable::getTsys(Int whichRow) const { |
---|
417 | ROArrayColumn<Float> ts(table_, "TSYS"); |
---|
418 | Array<Float> arr; |
---|
419 | ts.get(whichRow, arr); |
---|
420 | Float out; |
---|
421 | IPosition ip(arr.shape()); |
---|
422 | ip(0) = beamSel_;ip(1) = IFSel_;ip(2) = polSel_;ip(3)=0; |
---|
423 | out = arr(ip); |
---|
424 | return out; |
---|
425 | } |
---|
426 | |
---|
427 | SpectralCoordinate SDMemTable::getCoordinate(uInt whichIdx) const { |
---|
428 | |
---|
429 | Table t = table_.keywordSet().asTable("FREQUENCIES"); |
---|
430 | if (whichIdx > t.nrow() ) { |
---|
431 | cerr << "SDMemTable::getCoordinate - whichIdx out of range" << endl; |
---|
432 | return SpectralCoordinate(); |
---|
433 | } |
---|
434 | |
---|
435 | Double rp,rv,inc; |
---|
436 | String rf; |
---|
437 | ROScalarColumn<Double> rpc(t, "REFPIX"); |
---|
438 | ROScalarColumn<Double> rvc(t, "REFVAL"); |
---|
439 | ROScalarColumn<Double> incc(t, "INCREMENT"); |
---|
440 | t.keywordSet().get("REFFRAME",rf); |
---|
441 | |
---|
442 | MFrequency::Types mft; |
---|
443 | if (!MFrequency::getType(mft, rf)) { |
---|
444 | cerr << "Frequency type unknown assuming TOPO" << endl; |
---|
445 | mft = MFrequency::TOPO; |
---|
446 | } |
---|
447 | rpc.get(whichIdx, rp); |
---|
448 | rvc.get(whichIdx, rv); |
---|
449 | incc.get(whichIdx, inc); |
---|
450 | //cerr << "creating speccord from " << whichIdx << ": " |
---|
451 | // << rp <<", " << rv << ", " << inc << ", " << mft <<endl; |
---|
452 | SpectralCoordinate spec(mft,rv,inc,rp); |
---|
453 | return spec; |
---|
454 | } |
---|
455 | |
---|
456 | Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord, |
---|
457 | uInt whichIdx) { |
---|
458 | Table t = table_.rwKeywordSet().asTable("FREQUENCIES"); |
---|
459 | if (whichIdx > t.nrow() ) { |
---|
460 | cerr << "SDMemTable::setCoordinate - whichIdx out of range" << endl; |
---|
461 | return False; |
---|
462 | } |
---|
463 | ScalarColumn<Double> rpc(t, "REFPIX"); |
---|
464 | ScalarColumn<Double> rvc(t, "REFVAL"); |
---|
465 | ScalarColumn<Double> incc(t, "INCREMENT"); |
---|
466 | |
---|
467 | rpc.put(whichIdx, speccord.referencePixel()[0]); |
---|
468 | rvc.put(whichIdx, speccord.referenceValue()[0]); |
---|
469 | incc.put(whichIdx, speccord.increment()[0]); |
---|
470 | |
---|
471 | return True; |
---|
472 | } |
---|
473 | |
---|
474 | |
---|
475 | bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft) { |
---|
476 | TableDesc td("", "1", TableDesc::Scratch); |
---|
477 | td.addColumn(ScalarColumnDesc<Double>("REFPIX")); |
---|
478 | td.addColumn(ScalarColumnDesc<Double>("REFVAL")); |
---|
479 | td.addColumn(ScalarColumnDesc<Double>("INCREMENT")); |
---|
480 | SetupNewTable aNewTab("freqs", td, Table::New); |
---|
481 | Table aTable (aNewTab, Table::Memory, sdft.length()); |
---|
482 | ScalarColumn<Double> sc0(aTable, "REFPIX"); |
---|
483 | ScalarColumn<Double> sc1(aTable, "REFVAL"); |
---|
484 | ScalarColumn<Double> sc2(aTable, "INCREMENT"); |
---|
485 | for (uInt i=0; i < sdft.length(); ++i) { |
---|
486 | sc0.put(i,sdft.referencePixel(i)); |
---|
487 | sc1.put(i,sdft.referenceValue(i)); |
---|
488 | sc2.put(i,sdft.increment(i)); |
---|
489 | } |
---|
490 | aTable.rwKeywordSet().define("REFFRAME", sdft.refFrame()); |
---|
491 | aTable.rwKeywordSet().define("EQUINOX", sdft.equinox()); |
---|
492 | aTable.rwKeywordSet().define("Unit", String("kms-1")); |
---|
493 | table_.rwKeywordSet().defineTable ("FREQUENCIES", aTable); |
---|
494 | return True; |
---|
495 | } |
---|
496 | |
---|
497 | SDFrequencyTable SDMemTable::getSDFreqTable() const { |
---|
498 | SDFrequencyTable sdft; |
---|
499 | |
---|
500 | return sdft; |
---|
501 | } |
---|
502 | |
---|
503 | bool SDMemTable::putSDContainer(const SDContainer& sdc) { |
---|
504 | ScalarColumn<Double> mjd(table_, "TIME"); |
---|
505 | ScalarColumn<String> srcn(table_, "SRCNAME"); |
---|
506 | ArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
507 | ArrayColumn<uChar> flags(table_, "FLAGTRA"); |
---|
508 | ArrayColumn<Float> ts(table_, "TSYS"); |
---|
509 | ScalarColumn<Int> scan(table_, "SCANID"); |
---|
510 | ScalarColumn<Double> integr(table_, "INTERVAL"); |
---|
511 | ArrayColumn<uInt> freqid(table_, "FREQID"); |
---|
512 | ArrayColumn<Double> dir(table_, "DIRECTION"); |
---|
513 | |
---|
514 | uInt rno = table_.nrow(); |
---|
515 | table_.addRow(); |
---|
516 | |
---|
517 | mjd.put(rno, sdc.timestamp); |
---|
518 | srcn.put(rno, sdc.sourcename); |
---|
519 | spec.put(rno, sdc.getSpectrum()); |
---|
520 | flags.put(rno, sdc.getFlags()); |
---|
521 | ts.put(rno, sdc.getTsys()); |
---|
522 | scan.put(rno, sdc.scanid); |
---|
523 | integr.put(rno, sdc.interval); |
---|
524 | freqid.put(rno, sdc.getFreqMap()); |
---|
525 | dir.put(rno, sdc.getDirection()); |
---|
526 | |
---|
527 | return true; |
---|
528 | } |
---|
529 | |
---|
530 | SDContainer SDMemTable::getSDContainer(uInt whichRow) const { |
---|
531 | ROScalarColumn<Double> mjd(table_, "TIME"); |
---|
532 | ROScalarColumn<String> srcn(table_, "SRCNAME"); |
---|
533 | ROArrayColumn<Float> spec(table_, "SPECTRA"); |
---|
534 | ROArrayColumn<uChar> flags(table_, "FLAGTRA"); |
---|
535 | ROArrayColumn<Float> ts(table_, "TSYS"); |
---|
536 | ROScalarColumn<Int> scan(table_, "SCANID"); |
---|
537 | ROScalarColumn<Double> integr(table_, "INTERVAL"); |
---|
538 | ROArrayColumn<uInt> freqid(table_, "FREQID"); |
---|
539 | ROArrayColumn<Double> dir(table_, "DIRECTION"); |
---|
540 | |
---|
541 | SDContainer sdc(nBeam(),nIF(),nPol(),nChan()); |
---|
542 | mjd.get(whichRow, sdc.timestamp); |
---|
543 | srcn.get(whichRow, sdc.sourcename); |
---|
544 | integr.get(whichRow, sdc.interval); |
---|
545 | scan.get(whichRow, sdc.scanid); |
---|
546 | Array<Float> spectrum; |
---|
547 | Array<Float> tsys; |
---|
548 | Array<uChar> flagtrum; |
---|
549 | Vector<uInt> fmap; |
---|
550 | Array<Double> direction; |
---|
551 | spec.get(whichRow, spectrum); |
---|
552 | sdc.putSpectrum(spectrum); |
---|
553 | flags.get(whichRow, flagtrum); |
---|
554 | sdc.putFlags(flagtrum); |
---|
555 | ts.get(whichRow, tsys); |
---|
556 | sdc.putTsys(tsys); |
---|
557 | freqid.get(whichRow, fmap); |
---|
558 | sdc.putFreqMap(fmap); |
---|
559 | dir.get(whichRow, direction); |
---|
560 | sdc.putDirection(direction); |
---|
561 | return sdc; |
---|
562 | } |
---|
563 | |
---|
564 | bool SDMemTable::putSDHeader(const SDHeader& sdh) { |
---|
565 | table_.lock(); |
---|
566 | table_.rwKeywordSet().define("nIF", sdh.nif); |
---|
567 | table_.rwKeywordSet().define("nBeam", sdh.nbeam); |
---|
568 | table_.rwKeywordSet().define("nPol", sdh.npol); |
---|
569 | table_.rwKeywordSet().define("nChan", sdh.nchan); |
---|
570 | table_.rwKeywordSet().define("Observer", sdh.observer); |
---|
571 | table_.rwKeywordSet().define("Project", sdh.project); |
---|
572 | table_.rwKeywordSet().define("Obstype", sdh.obstype); |
---|
573 | table_.rwKeywordSet().define("AntennaName", sdh.antennaname); |
---|
574 | table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition); |
---|
575 | table_.rwKeywordSet().define("Equinox", sdh.equinox); |
---|
576 | table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref); |
---|
577 | table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq); |
---|
578 | table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth); |
---|
579 | table_.rwKeywordSet().define("UTC", sdh.utc); |
---|
580 | table_.unlock(); |
---|
581 | return true; |
---|
582 | } |
---|
583 | |
---|
584 | SDHeader SDMemTable::getSDHeader() const { |
---|
585 | SDHeader sdh; |
---|
586 | table_.keywordSet().get("nBeam",sdh.nbeam); |
---|
587 | table_.keywordSet().get("nIF",sdh.nif); |
---|
588 | table_.keywordSet().get("nPol",sdh.npol); |
---|
589 | table_.keywordSet().get("nChan",sdh.nchan); |
---|
590 | table_.keywordSet().get("Observer", sdh.observer); |
---|
591 | table_.keywordSet().get("Project", sdh.project); |
---|
592 | table_.keywordSet().get("Obstype", sdh.obstype); |
---|
593 | table_.keywordSet().get("AntennaName", sdh.antennaname); |
---|
594 | table_.keywordSet().get("AntennaPosition", sdh.antennaposition); |
---|
595 | table_.keywordSet().get("Equinox", sdh.equinox); |
---|
596 | table_.keywordSet().get("FreqRefFrame", sdh.freqref); |
---|
597 | table_.keywordSet().get("FreqRefVal", sdh.reffreq); |
---|
598 | table_.keywordSet().get("Bandwidth", sdh.bandwidth); |
---|
599 | table_.keywordSet().get("UTC", sdh.utc); |
---|
600 | return sdh; |
---|
601 | } |
---|
602 | void SDMemTable::makePersistent(const std::string& filename) { |
---|
603 | table_.deepCopy(filename,Table::New); |
---|
604 | } |
---|
605 | |
---|
606 | Int SDMemTable::nScans() const { |
---|
607 | Int n = 0; |
---|
608 | ROScalarColumn<Int> scans(table_, "SCANID"); |
---|
609 | Int previous = -1;Int current=0; |
---|
610 | for (uInt i=0; i< scans.nrow();i++) { |
---|
611 | scans.getScalar(i,current); |
---|
612 | if (previous != current) { |
---|
613 | previous = current; |
---|
614 | n++; |
---|
615 | } |
---|
616 | } |
---|
617 | return n; |
---|
618 | } |
---|
619 | |
---|
620 | void SDMemTable::summary() const { |
---|
621 | ROScalarColumn<Int> scans(table_, "SCANID"); |
---|
622 | ROScalarColumn<String> srcs(table_, "SRCNAME"); |
---|
623 | cout << "*************** Header ***************" << endl; |
---|
624 | cout << "nBeam = " << nBeam() << "\t" |
---|
625 | << "nIF = " << nIF() << endl |
---|
626 | << "nPol = " << nPol() << "\t" |
---|
627 | << "nChan = " << nChan() << "\t" << endl; |
---|
628 | cout << "*************** Header ***************" << endl; |
---|
629 | uInt count = 0; |
---|
630 | String name; |
---|
631 | Int previous = -1;Int current=0; |
---|
632 | cout << "Scan\tSource\t\tTime\t\tIntegration" << endl; |
---|
633 | for (uInt i=0; i< scans.nrow();i++) { |
---|
634 | scans.getScalar(i,current); |
---|
635 | if (previous != current) { |
---|
636 | srcs.getScalar(i,name); |
---|
637 | previous = current; |
---|
638 | Double t = getInterval(); |
---|
639 | String unit("sec"); |
---|
640 | if (t/60.0 > 1.0) { |
---|
641 | t/=60.0;unit = "min"; |
---|
642 | } |
---|
643 | cout << count << "\t" |
---|
644 | << name << "\t" |
---|
645 | << getTime() << "\t" |
---|
646 | << setprecision(2) << setiosflags(std::ios_base::fixed) |
---|
647 | << t << " " << unit << endl |
---|
648 | << endl; |
---|
649 | count++; |
---|
650 | } |
---|
651 | } |
---|
652 | cout << "Table contains " << table_.nrow() << " integration(s)." << endl; |
---|
653 | cout << "in " << count << " scan(s)." << endl; |
---|
654 | } |
---|
655 | |
---|
656 | Int SDMemTable::nBeam() const { |
---|
657 | Int n; |
---|
658 | table_.keywordSet().get("nBeam",n); |
---|
659 | return n; |
---|
660 | } |
---|
661 | Int SDMemTable::nIF() const { |
---|
662 | Int n; |
---|
663 | table_.keywordSet().get("nIF",n); |
---|
664 | return n; |
---|
665 | } |
---|
666 | Int SDMemTable::nPol() const { |
---|
667 | Int n; |
---|
668 | table_.keywordSet().get("nPol",n); |
---|
669 | return n; |
---|
670 | } |
---|
671 | Int SDMemTable::nChan() const { |
---|
672 | Int n; |
---|
673 | table_.keywordSet().get("nChan",n); |
---|
674 | return n; |
---|
675 | } |
---|
676 | /* |
---|
677 | void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) { |
---|
678 | |
---|
679 | std::vector<int>::iterator it; |
---|
680 | ArrayAccessor<uChar, Axis<2> > j(flags_); |
---|
681 | for (it = whichChans.begin(); it != whichChans.end(); it++) { |
---|
682 | j.reset(j.begin(uInt(*it))); |
---|
683 | for (ArrayAccessor<uChar, Axis<0> > i(j); i != i.end(); ++i) { |
---|
684 | for (ArrayAccessor<uChar, Axis<1> > ii(i); ii != ii.end(); ++ii) { |
---|
685 | for (ArrayAccessor<uChar, Axis<3> > iii(ii); |
---|
686 | iii != iii.end(); ++iii) { |
---|
687 | (*iii) = |
---|
688 | } |
---|
689 | } |
---|
690 | } |
---|
691 | } |
---|
692 | |
---|
693 | } |
---|
694 | */ |
---|