source: trunk/src/SDMemTable.cc@ 474

Last change on this file since 474 was 472, checked in by kil064, 20 years ago

add a new getStokesSPectrum function (for the writer) which gets all
Stokes or a beam/IF slice

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 50.5 KB
RevLine 
[2]1//#---------------------------------------------------------------------------
2//# SDMemTable.cc: A MemoryTable container for single dish integrations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
[125]5//# ATNF
[2]6//#
7//# This program is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU General Public License as published by the Free
9//# Software Foundation; either version 2 of the License, or (at your option)
10//# any later version.
11//#
12//# This program is distributed in the hope that it will be useful, but
13//# WITHOUT ANY WARRANTY; without even the implied warranty of
14//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15//# Public License for more details.
16//#
17//# You should have received a copy of the GNU General Public License along
18//# with this program; if not, write to the Free Software Foundation, Inc.,
19//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning this software should be addressed as follows:
22//# Internet email: Malte.Marquarding@csiro.au
23//# Postal address: Malte Marquarding,
24//# Australia Telescope National Facility,
25//# P.O. Box 76,
26//# Epping, NSW, 2121,
27//# AUSTRALIA
28//#
29//# $Id:
30//#---------------------------------------------------------------------------
31
[206]32#include <map>
33
[125]34#include <casa/aips.h>
[80]35#include <casa/iostream.h>
36#include <casa/iomanip.h>
37#include <casa/Arrays/Array.h>
38#include <casa/Arrays/ArrayMath.h>
39#include <casa/Arrays/MaskArrMath.h>
40#include <casa/Arrays/ArrayLogical.h>
41#include <casa/Arrays/ArrayAccessor.h>
[455]42#include <casa/Arrays/VectorSTLIterator.h>
[206]43#include <casa/Arrays/Vector.h>
[418]44#include <casa/BasicMath/Math.h>
[286]45#include <casa/Quanta/MVAngle.h>
[2]46
[80]47#include <tables/Tables/TableParse.h>
48#include <tables/Tables/TableDesc.h>
49#include <tables/Tables/SetupNewTab.h>
50#include <tables/Tables/ScaColDesc.h>
51#include <tables/Tables/ArrColDesc.h>
[2]52
[80]53#include <tables/Tables/ExprNode.h>
54#include <tables/Tables/TableRecord.h>
55#include <measures/Measures/MFrequency.h>
56#include <measures/Measures/MeasTable.h>
[105]57#include <coordinates/Coordinates/CoordinateUtil.h>
[80]58#include <casa/Quanta/MVTime.h>
[281]59#include <casa/Quanta/MVAngle.h>
[2]60
[215]61#include "SDDefs.h"
[2]62#include "SDContainer.h"
[365]63#include "MathUtils.h"
[418]64#include "SDPol.h"
[2]65
[465]66#include "SDMemTable.h"
[206]67
[125]68using namespace casa;
[83]69using namespace asap;
[2]70
[18]71SDMemTable::SDMemTable() :
72 IFSel_(0),
73 beamSel_(0),
[206]74 polSel_(0)
75{
[18]76 setup();
[322]77 attach();
[18]78}
[206]79
[2]80SDMemTable::SDMemTable(const std::string& name) :
81 IFSel_(0),
82 beamSel_(0),
[206]83 polSel_(0)
84{
[50]85 Table tab(name);
[22]86 table_ = tab.copyToMemoryTable("dummy");
[206]87 //cerr << "hello from C SDMemTable @ " << this << endl;
[329]88 attach();
[2]89}
90
[206]91SDMemTable::SDMemTable(const SDMemTable& other, Bool clear)
92{
[148]93 IFSel_= other.IFSel_;
94 beamSel_= other.beamSel_;
95 polSel_= other.polSel_;
96 chanMask_ = other.chanMask_;
97 table_ = other.table_.copyToMemoryTable(String("dummy"));
[2]98 // clear all rows()
[16]99 if (clear) {
[148]100 table_.removeRow(this->table_.rowNumbers());
[16]101 } else {
[148]102 IFSel_ = other.IFSel_;
103 beamSel_ = other.beamSel_;
104 polSel_ = other.polSel_;
[16]105 }
[322]106//
107 attach();
[206]108 //cerr << "hello from CC SDMemTable @ " << this << endl;
[2]109}
110
[80]111SDMemTable::SDMemTable(const Table& tab, const std::string& exprs) :
[2]112 IFSel_(0),
113 beamSel_(0),
[206]114 polSel_(0)
115{
[2]116 Table t = tableCommand(exprs,tab);
[89]117 if (t.nrow() == 0)
118 throw(AipsError("Query unsuccessful."));
[22]119 table_ = t.copyToMemoryTable("dummy");
[329]120 attach();
[380]121 renumber();
[2]122}
123
[206]124SDMemTable::~SDMemTable()
125{
[105]126 //cerr << "goodbye from SDMemTable @ " << this << endl;
[2]127}
128
[206]129SDMemTable SDMemTable::getScan(Int scanID) const
130{
[80]131 String cond("SELECT * from $1 WHERE SCANID == ");
132 cond += String::toString(scanID);
133 return SDMemTable(table_, cond);
[2]134}
135
[206]136SDMemTable &SDMemTable::operator=(const SDMemTable& other)
137{
[148]138 if (this != &other) {
139 IFSel_= other.IFSel_;
140 beamSel_= other.beamSel_;
141 polSel_= other.polSel_;
142 chanMask_.resize(0);
143 chanMask_ = other.chanMask_;
144 table_ = other.table_.copyToMemoryTable(String("dummy"));
[322]145 attach();
[206]146 }
147 //cerr << "hello from ASS SDMemTable @ " << this << endl;
[138]148 return *this;
149}
150
[206]151SDMemTable SDMemTable::getSource(const std::string& source) const
152{
[80]153 String cond("SELECT * from $1 WHERE SRCNAME == ");
154 cond += source;
155 return SDMemTable(table_, cond);
156}
157
[206]158void SDMemTable::setup()
159{
[2]160 TableDesc td("", "1", TableDesc::Scratch);
161 td.comment() = "A SDMemTable";
[455]162
[2]163 td.addColumn(ScalarColumnDesc<Double>("TIME"));
164 td.addColumn(ScalarColumnDesc<String>("SRCNAME"));
165 td.addColumn(ArrayColumnDesc<Float>("SPECTRA"));
166 td.addColumn(ArrayColumnDesc<uChar>("FLAGTRA"));
[89]167 td.addColumn(ArrayColumnDesc<Float>("TSYS"));
[418]168 td.addColumn(ArrayColumnDesc<Float>("STOKES"));
[89]169 td.addColumn(ScalarColumnDesc<Int>("SCANID"));
170 td.addColumn(ScalarColumnDesc<Double>("INTERVAL"));
[39]171 td.addColumn(ArrayColumnDesc<uInt>("FREQID"));
[386]172 td.addColumn(ArrayColumnDesc<uInt>("RESTFREQID"));
[78]173 td.addColumn(ArrayColumnDesc<Double>("DIRECTION"));
[105]174 td.addColumn(ScalarColumnDesc<String>("FIELDNAME"));
175 td.addColumn(ScalarColumnDesc<String>("TCALTIME"));
176 td.addColumn(ArrayColumnDesc<Float>("TCAL"));
177 td.addColumn(ScalarColumnDesc<Float>("AZIMUTH"));
178 td.addColumn(ScalarColumnDesc<Float>("ELEVATION"));
179 td.addColumn(ScalarColumnDesc<Float>("PARANGLE"));
180 td.addColumn(ScalarColumnDesc<Int>("REFBEAM"));
[206]181 td.addColumn(ArrayColumnDesc<String>("HISTORY"));
[455]182 td.addColumn(ArrayColumnDesc<Int>("FITID"));
[105]183
[455]184
[418]185 // Now create Table SetUp from the description.
[18]186
[22]187 SetupNewTable aNewTab("dummy", td, Table::New);
[418]188
[455]189 // Bind the Stokes Virtual machine to the STOKES column Because we
190 // don't know how many polarizations will be in the data at this
191 // point, we must bind the Virtual Engine regardless. The STOKES
192 // column won't be accessed if not appropriate (nPol=4)
[418]193
[464]194
195 SDStokesEngine::registerClass();
[418]196 SDStokesEngine stokesEngine(String("STOKES"), String("SPECTRA"));
197 aNewTab.bindColumn ("STOKES", stokesEngine);
198
[455]199 // Create Table
200 table_ = Table(aNewTab, Table::Memory, 0);
201 // add subtable
202 TableDesc tdf("", "1", TableDesc::Scratch);
203 tdf.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
204 tdf.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
205 tdf.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
206 tdf.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
[465]207 tdf.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
[455]208 SetupNewTable fittab("fits", tdf, Table::New);
209 Table fitTable(fittab, Table::Memory);
210 table_.rwKeywordSet().defineTable("FITS", fitTable);
[418]211
[455]212
[2]213}
214
[380]215void SDMemTable::attach()
[322]216{
217 timeCol_.attach(table_, "TIME");
218 srcnCol_.attach(table_, "SRCNAME");
219 specCol_.attach(table_, "SPECTRA");
220 flagsCol_.attach(table_, "FLAGTRA");
221 tsCol_.attach(table_, "TSYS");
[418]222 stokesCol_.attach(table_, "STOKES");
[322]223 scanCol_.attach(table_, "SCANID");
224 integrCol_.attach(table_, "INTERVAL");
225 freqidCol_.attach(table_, "FREQID");
[386]226 restfreqidCol_.attach(table_, "RESTFREQID");
[322]227 dirCol_.attach(table_, "DIRECTION");
228 fldnCol_.attach(table_, "FIELDNAME");
229 tcaltCol_.attach(table_, "TCALTIME");
230 tcalCol_.attach(table_, "TCAL");
231 azCol_.attach(table_, "AZIMUTH");
232 elCol_.attach(table_, "ELEVATION");
233 paraCol_.attach(table_, "PARANGLE");
234 rbeamCol_.attach(table_, "REFBEAM");
235 histCol_.attach(table_, "HISTORY");
[455]236 fitCol_.attach(table_,"FITID");
[322]237}
238
239
[206]240std::string SDMemTable::getSourceName(Int whichRow) const
241{
[2]242 String name;
[322]243 srcnCol_.get(whichRow, name);
[2]244 return name;
245}
246
[281]247std::string SDMemTable::getTime(Int whichRow, Bool showDate) const
[206]248{
[2]249 Double tm;
[281]250 if (whichRow > -1) {
[322]251 timeCol_.get(whichRow, tm);
[281]252 } else {
253 table_.keywordSet().get("UTC",tm);
254 }
[50]255 MVTime mvt(tm);
[281]256 if (showDate)
257 mvt.setFormat(MVTime::YMD);
258 else
259 mvt.setFormat(MVTime::TIME);
[50]260 ostringstream oss;
261 oss << mvt;
[281]262 return String(oss);
[2]263}
[281]264
[206]265double SDMemTable::getInterval(Int whichRow) const
266{
[50]267 Double intval;
[322]268 integrCol_.get(whichRow, intval);
[50]269 return intval;
270}
[2]271
[206]272bool SDMemTable::setIF(Int whichIF)
273{
[50]274 if ( whichIF >= 0 && whichIF < nIF()) {
[2]275 IFSel_ = whichIF;
276 return true;
[50]277 }
278 return false;
[2]279}
[50]280
[206]281bool SDMemTable::setBeam(Int whichBeam)
282{
[50]283 if ( whichBeam >= 0 && whichBeam < nBeam()) {
[2]284 beamSel_ = whichBeam;
285 return true;
[50]286 }
287 return false;
288}
[2]289
[206]290bool SDMemTable::setPol(Int whichPol)
291{
[50]292 if ( whichPol >= 0 && whichPol < nPol()) {
[2]293 polSel_ = whichPol;
294 return true;
[50]295 }
296 return false;
[2]297}
298
[380]299void SDMemTable::resetCursor()
[303]300{
301 polSel_ = 0;
302 IFSel_ = 0;
303 beamSel_ = 0;
304}
305
[206]306bool SDMemTable::setMask(std::vector<int> whichChans)
307{
[16]308 std::vector<int>::iterator it;
[322]309 uInt n = flagsCol_.shape(0)(3);
[105]310 if (whichChans.empty()) {
311 chanMask_ = std::vector<bool>(n,true);
312 return true;
313 }
[16]314 chanMask_.resize(n,true);
[39]315 for (it = whichChans.begin(); it != whichChans.end(); ++it) {
[105]316 if (*it < n) {
[16]317 chanMask_[*it] = false;
[105]318 }
[16]319 }
[2]320 return true;
321}
322
[447]323std::vector<bool> SDMemTable::getMask(Int whichRow) const
324{
325
[16]326 std::vector<bool> mask;
[455]327
[16]328 Array<uChar> arr;
[322]329 flagsCol_.get(whichRow, arr);
[455]330
[206]331 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[16]332 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]333 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[16]334 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]335 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[16]336 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
337
338 Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
339
340 std::vector<bool> tmp;
341 tmp = chanMask_; // WHY the fxxx do I have to make a copy here
342 std::vector<bool>::iterator miter;
343 miter = tmp.begin();
344
[206]345 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[16]346 bool out =!static_cast<bool>(*i);
347 if (useUserMask) {
348 out = out && (*miter);
349 miter++;
350 }
351 mask.push_back(out);
[89]352 }
[16]353 return mask;
[2]354}
[418]355
356
357
[206]358std::vector<float> SDMemTable::getSpectrum(Int whichRow) const
359{
[430]360
[2]361 Array<Float> arr;
[322]362 specCol_.get(whichRow, arr);
[455]363 return getFloatSpectrum(arr);
[418]364}
365
[455]366std::vector<float> SDMemTable::getStokesSpectrum(Int whichRow, Bool doPol,
367 Float paOffset) const
[472]368//
369// Gets one STokes parameter depending on cursor polSel location
370// doPol=False : I,Q,U,V
371// doPol=True : I,P,PA,V ; P = sqrt(Q**2+U**2), PA = 0.5*atan2(Q,U)
372//
[418]373{
[430]374 AlwaysAssert(asap::nAxes==4,AipsError);
[428]375 if (nPol()!=1 && nPol()!=2 && nPol()!=4) {
376 throw (AipsError("You must have 1,2 or 4 polarizations to get the Stokes parameters"));
[418]377 }
378 Array<Float> arr;
379 stokesCol_.get(whichRow, arr);
[455]380
[430]381 if (doPol && (polSel_==1 || polSel_==2)) { // Q,U --> P, P.A.
382
[455]383 // Set current cursor location
[418]384 const IPosition& shape = arr.shape();
[430]385 IPosition start, end;
386 setCursorSlice (start, end, shape);
387
[455]388 // Get Q and U slices
[430]389
[455]390 Array<Float> Q = SDPolUtil::getStokesSlice(arr,start,end,"Q");
391 Array<Float> U = SDPolUtil::getStokesSlice(arr,start,end,"U");
[430]392
[455]393 // Compute output
[430]394
[418]395 Array<Float> out;
396 if (polSel_==1) { // P
397 out = SDPolUtil::polarizedIntensity(Q,U);
398 } else if (polSel_==2) { // P.A.
[426]399 out = SDPolUtil::positionAngle(Q,U) + paOffset;
[418]400 }
[430]401
[455]402 // Copy to output
[430]403
[418]404 IPosition vecShape(1,shape(asap::ChanAxis));
405 Vector<Float> outV = out.reform(vecShape);
[455]406 std::vector<float> stlout;
407 outV.tovector(stlout);
408 return stlout;
409
[418]410 } else {
[430]411
[455]412 // Selects at the cursor location
413 return getFloatSpectrum(arr);
[418]414 }
415}
416
[455]417std::vector<float> SDMemTable::getCircularSpectrum(Int whichRow,
418 Bool doRR) const
419 // Gets
420 // RR = I + V
421 // LL = I - V
[430]422{
423 AlwaysAssert(asap::nAxes==4,AipsError);
424 if (nPol()!=4) {
425 throw (AipsError("You must have 4 polarizations to get RR or LL"));
426 }
427 Array<Float> arr;
428 stokesCol_.get(whichRow, arr);
429
[455]430 // Set current cursor location
[430]431
432 const IPosition& shape = arr.shape();
433 IPosition start, end;
[455]434 setCursorSlice(start, end, shape);
[430]435
[455]436 // Get I and V slices
[430]437
[455]438 Array<Float> I = SDPolUtil::getStokesSlice(arr,start,end,"I");
439 Array<Float> V = SDPolUtil::getStokesSlice(arr,start,end,"V");
[430]440
[455]441 // Compute output
[430]442
[455]443 Array<Float> out = SDPolUtil::circularPolarizationFromStokes(I, V, doRR);
[430]444
[455]445 // Copy to output
[430]446
447 IPosition vecShape(1,shape(asap::ChanAxis));
448 Vector<Float> outV = out.reform(vecShape);
[455]449 std::vector<float> stlout;
450 outV.tovector(stlout);
451
452 return stlout;
[430]453}
454
[472]455Array<Float> SDMemTable::getStokesSpectrum(Int whichRow, Int iBeam, Int iIF) const
456{
[418]457
[472]458// Get data
459
460 Array<Float> arr;
461 stokesCol_.get(whichRow, arr);
462
463// Set current cursor location and overwrite polarization axis
464
465 const IPosition& shape = arr.shape();
466 IPosition start(shape.nelements(),0);
467 IPosition end(shape-1);
468 if (iBeam!=-1) {
469 start(asap::BeamAxis) = iBeam;
470 end(asap::BeamAxis) = iBeam;
471 }
472 if (iIF!=-1) {
473 start(asap::IFAxis) = iIF;
474 end(asap::IFAxis) = iIF;
475 }
476
477// Get slice
478
479 return arr(start,end);
480}
481
482
[206]483std::vector<string> SDMemTable::getCoordInfo() const
484{
[105]485 String un;
486 Table t = table_.keywordSet().asTable("FREQUENCIES");
487 String sunit;
488 t.keywordSet().get("UNIT",sunit);
489 String dpl;
490 t.keywordSet().get("DOPPLER",dpl);
491 if (dpl == "") dpl = "RADIO";
492 String rfrm;
493 t.keywordSet().get("REFFRAME",rfrm);
494 std::vector<string> inf;
495 inf.push_back(sunit);
496 inf.push_back(rfrm);
497 inf.push_back(dpl);
[263]498 t.keywordSet().get("BASEREFFRAME",rfrm);
499 inf.push_back(rfrm);
[105]500 return inf;
501}
[39]502
[206]503void SDMemTable::setCoordInfo(std::vector<string> theinfo)
504{
[105]505 std::vector<string>::iterator it;
[306]506 String un,rfrm, brfrm,dpl;
507 un = theinfo[0]; // Abcissa unit
508 rfrm = theinfo[1]; // Active (or conversion) frame
509 dpl = theinfo[2]; // Doppler
510 brfrm = theinfo[3]; // Base frame
[455]511
[105]512 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
[455]513
[105]514 Vector<Double> rstf;
515 t.keywordSet().get("RESTFREQS",rstf);
[455]516
[105]517 Bool canDo = True;
518 Unit u1("km/s");Unit u2("Hz");
519 if (Unit(un) == u1) {
520 Vector<Double> rstf;
521 t.keywordSet().get("RESTFREQS",rstf);
522 if (rstf.nelements() == 0) {
523 throw(AipsError("Can't set unit to km/s if no restfrequencies are specified"));
524 }
525 } else if (Unit(un) != u2 && un != "") {
526 throw(AipsError("Unit not conformant with Spectral Coordinates"));
527 }
528 t.rwKeywordSet().define("UNIT", un);
[455]529
[105]530 MFrequency::Types mdr;
531 if (!MFrequency::getType(mdr, rfrm)) {
532
533 Int a,b;const uInt* c;
534 const String* valid = MFrequency::allMyTypes(a, b, c);
535 String pfix = "Please specify a legal frame type. Types are\n";
536 throw(AipsError(pfix+(*valid)));
537 } else {
538 t.rwKeywordSet().define("REFFRAME",rfrm);
539 }
[455]540
[275]541 MDoppler::Types dtype;
542 dpl.upcase();
543 if (!MDoppler::getType(dtype, dpl)) {
544 throw(AipsError("Doppler type unknown"));
545 } else {
546 t.rwKeywordSet().define("DOPPLER",dpl);
547 }
[455]548
[306]549 if (!MFrequency::getType(mdr, brfrm)) {
550 Int a,b;const uInt* c;
551 const String* valid = MFrequency::allMyTypes(a, b, c);
552 String pfix = "Please specify a legal frame type. Types are\n";
553 throw(AipsError(pfix+(*valid)));
554 } else {
555 t.rwKeywordSet().define("BASEREFFRAME",brfrm);
556 }
[105]557}
558
[286]559
[206]560std::vector<double> SDMemTable::getAbcissa(Int whichRow) const
561{
[286]562 std::vector<double> abc(nChan());
[206]563
[455]564 // Get header units keyword
[286]565 Table t = table_.keywordSet().asTable("FREQUENCIES");
[105]566 String sunit;
567 t.keywordSet().get("UNIT",sunit);
568 if (sunit == "") sunit = "pixel";
569 Unit u(sunit);
[286]570
[455]571 // Easy if just wanting pixels
[286]572 if (sunit==String("pixel")) {
573 // assume channels/pixels
574 std::vector<double>::iterator it;
575 uInt i=0;
576 for (it = abc.begin(); it != abc.end(); ++it) {
577 (*it) = Double(i++);
578 }
579 return abc;
[78]580 }
581
[455]582 // Continue with km/s or Hz. Get FreqIDs
[347]583 Vector<uInt> freqIDs;
584 freqidCol_.get(whichRow, freqIDs);
585 uInt freqID = freqIDs(IFSel_);
[386]586 restfreqidCol_.get(whichRow, freqIDs);
587 uInt restFreqID = freqIDs(IFSel_);
[286]588
[455]589 // Get SpectralCoordinate, set reference frame conversion,
590 // velocity conversion, and rest freq state
[286]591
[386]592 SpectralCoordinate spc = getSpectralCoordinate(freqID, restFreqID, whichRow);
[286]593 Vector<Double> pixel(nChan());
594 indgen(pixel);
[455]595
[286]596 if (u == Unit("km/s")) {
597 Vector<Double> world;
598 spc.pixelToVelocity(world,pixel);
599 std::vector<double>::iterator it;
600 uInt i = 0;
601 for (it = abc.begin(); it != abc.end(); ++it) {
602 (*it) = world[i];
603 i++;
604 }
[39]605 } else if (u == Unit("Hz")) {
[286]606
[455]607 // Set world axis units
[39]608 Vector<String> wau(1); wau = u.getName();
609 spc.setWorldAxisUnits(wau);
[455]610
[39]611 std::vector<double>::iterator it;
612 Double tmp;
613 uInt i = 0;
[286]614 for (it = abc.begin(); it != abc.end(); ++it) {
615 spc.toWorld(tmp,pixel[i]);
[39]616 (*it) = tmp;
617 i++;
618 }
619 }
[286]620 return abc;
[39]621}
622
[164]623std::string SDMemTable::getAbcissaString(Int whichRow) const
[105]624{
625 Table t = table_.keywordSet().asTable("FREQUENCIES");
[455]626
[105]627 String sunit;
628 t.keywordSet().get("UNIT",sunit);
629 if (sunit == "") sunit = "pixel";
630 Unit u(sunit);
[455]631
[347]632 Vector<uInt> freqIDs;
633 freqidCol_.get(whichRow, freqIDs);
[386]634 uInt freqID = freqIDs(IFSel_);
635 restfreqidCol_.get(whichRow, freqIDs);
636 uInt restFreqID = freqIDs(IFSel_);
[286]637
[455]638 // Get SpectralCoordinate, with frame, velocity, rest freq state set
639 SpectralCoordinate spc = getSpectralCoordinate(freqID, restFreqID, whichRow);
[286]640
[105]641 String s = "Channel";
642 if (u == Unit("km/s")) {
643 s = CoordinateUtil::axisLabel(spc,0,True,True,True);
644 } else if (u == Unit("Hz")) {
645 Vector<String> wau(1);wau = u.getName();
646 spc.setWorldAxisUnits(wau);
[455]647
[286]648 s = CoordinateUtil::axisLabel(spc,0,True,True,False);
[105]649 }
650 return s;
651}
652
[206]653void SDMemTable::setSpectrum(std::vector<float> spectrum, int whichRow)
654{
[89]655 Array<Float> arr;
[322]656 specCol_.get(whichRow, arr);
[455]657 if (spectrum.size() != arr.shape()(asap::ChanAxis)) {
[89]658 throw(AipsError("Attempting to set spectrum with incorrect length."));
659 }
660
[455]661 // Setup accessors
[206]662 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[447]663 aa0.reset(aa0.begin(uInt(beamSel_))); // Beam selection
[206]664 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[447]665 aa1.reset(aa1.begin(uInt(IFSel_))); // IF selection
[206]666 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[447]667 aa2.reset(aa2.begin(uInt(polSel_))); // Pol selection
[89]668
[455]669 // Iterate
[89]670 std::vector<float>::iterator it = spectrum.begin();
[206]671 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[89]672 (*i) = Float(*it);
673 it++;
674 }
[322]675 specCol_.put(whichRow, arr);
[89]676}
677
[206]678void SDMemTable::getSpectrum(Vector<Float>& spectrum, Int whichRow) const
679{
[21]680 Array<Float> arr;
[322]681 specCol_.get(whichRow, arr);
[418]682
[455]683 // Iterate and extract
[21]684 spectrum.resize(arr.shape()(3));
[206]685 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
[21]686 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]687 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
[21]688 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]689 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
[21]690 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
[455]691
[206]692 ArrayAccessor<Float, Axis<asap::BeamAxis> > va(spectrum);
693 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[21]694 (*va) = (*i);
695 va++;
696 }
697}
[418]698
699
[89]700/*
[68]701void SDMemTable::getMask(Vector<Bool>& mask, Int whichRow) const {
[21]702 Array<uChar> arr;
[322]703 flagsCol_.get(whichRow, arr);
[21]704 mask.resize(arr.shape()(3));
705
[206]706 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[21]707 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]708 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[21]709 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]710 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[21]711 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
712
713 Bool useUserMask = ( chanMask_.size() == arr.shape()(3) );
[89]714
[206]715 ArrayAccessor<Bool, Axis<asap::BeamAxis> > va(mask);
[21]716 std::vector<bool> tmp;
717 tmp = chanMask_; // WHY the fxxx do I have to make a copy here. The
[89]718 // iterator should work on chanMask_??
[21]719 std::vector<bool>::iterator miter;
720 miter = tmp.begin();
721
[206]722 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[21]723 bool out =!static_cast<bool>(*i);
724 if (useUserMask) {
725 out = out && (*miter);
726 miter++;
727 }
728 (*va) = out;
729 va++;
[89]730 }
[21]731}
[89]732*/
[447]733
[455]734MaskedArray<Float> SDMemTable::rowAsMaskedArray(uInt whichRow,
735 Bool toStokes) const
[164]736{
[455]737 // Get flags
[441]738 Array<uChar> farr;
739 flagsCol_.get(whichRow, farr);
740
[455]741 // Get data and convert mask to Bool
[2]742 Array<Float> arr;
[441]743 Array<Bool> mask;
[439]744 if (toStokes) {
745 stokesCol_.get(whichRow, arr);
[455]746
[441]747 Array<Bool> tMask(farr.shape());
748 convertArray(tMask, farr);
[462]749 mask = SDPolUtil::stokesData (tMask, True);
[439]750 } else {
751 specCol_.get(whichRow, arr);
[441]752 mask.resize(farr.shape());
753 convertArray(mask, farr);
[439]754 }
[455]755
[447]756 return MaskedArray<Float>(arr,!mask);
[2]757}
758
[206]759Float SDMemTable::getTsys(Int whichRow) const
760{
[2]761 Array<Float> arr;
[322]762 tsCol_.get(whichRow, arr);
[2]763 Float out;
[455]764
[2]765 IPosition ip(arr.shape());
[418]766 ip(asap::BeamAxis) = beamSel_;
767 ip(asap::IFAxis) = IFSel_;
768 ip(asap::PolAxis) = polSel_;
769 ip(asap::ChanAxis)=0; // First channel only
[455]770
[2]771 out = arr(ip);
772 return out;
773}
774
[281]775MDirection SDMemTable::getDirection(Int whichRow, Bool refBeam) const
[206]776{
[212]777 MDirection::Types mdr = getDirectionReference();
[206]778 Array<Double> posit;
[322]779 dirCol_.get(whichRow,posit);
[206]780 Vector<Double> wpos(2);
[380]781 Int rb;
782 rbeamCol_.get(whichRow,rb);
[206]783 wpos[0] = posit(IPosition(2,beamSel_,0));
784 wpos[1] = posit(IPosition(2,beamSel_,1));
[380]785 if (refBeam && rb > -1) { // use refBeam instead if it exists
786 wpos[0] = posit(IPosition(2,rb,0));
787 wpos[1] = posit(IPosition(2,rb,1));
788 }
789
[206]790 Quantum<Double> lon(wpos[0],Unit(String("rad")));
791 Quantum<Double> lat(wpos[1],Unit(String("rad")));
[286]792 return MDirection(lon, lat, mdr);
[206]793}
[39]794
[380]795MEpoch SDMemTable::getEpoch(Int whichRow) const
[206]796{
[286]797 MEpoch::Types met = getTimeReference();
[455]798
[286]799 Double obstime;
[322]800 timeCol_.get(whichRow,obstime);
[286]801 MVEpoch tm2(Quantum<Double>(obstime, Unit(String("d"))));
802 return MEpoch(tm2, met);
803}
804
805MPosition SDMemTable::getAntennaPosition () const
806{
807 Vector<Double> antpos;
808 table_.keywordSet().get("AntennaPosition", antpos);
809 MVPosition mvpos(antpos(0),antpos(1),antpos(2));
810 return MPosition(mvpos);
811}
812
813
[347]814SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID) const
[286]815{
[206]816
[39]817 Table t = table_.keywordSet().asTable("FREQUENCIES");
[347]818 if (freqID> t.nrow() ) {
819 throw(AipsError("SDMemTable::getSpectralCoordinate - freqID out of range"));
[39]820 }
[89]821
[39]822 Double rp,rv,inc;
823 String rf;
824 ROScalarColumn<Double> rpc(t, "REFPIX");
825 ROScalarColumn<Double> rvc(t, "REFVAL");
826 ROScalarColumn<Double> incc(t, "INCREMENT");
[105]827 t.keywordSet().get("BASEREFFRAME",rf);
[89]828
[455]829 // Create SpectralCoordinate (units Hz)
[39]830 MFrequency::Types mft;
831 if (!MFrequency::getType(mft, rf)) {
832 cerr << "Frequency type unknown assuming TOPO" << endl;
[89]833 mft = MFrequency::TOPO;
834 }
[347]835 rpc.get(freqID, rp);
836 rvc.get(freqID, rv);
837 incc.get(freqID, inc);
[455]838
[39]839 SpectralCoordinate spec(mft,rv,inc,rp);
[286]840 return spec;
841}
842
843
[455]844SpectralCoordinate SDMemTable::getSpectralCoordinate(uInt freqID,
845 uInt restFreqID,
[386]846 uInt whichRow) const
[286]847{
[455]848
849 // Create basic SC
850 SpectralCoordinate spec = getSpectralCoordinate (freqID);
[385]851
[286]852 Table t = table_.keywordSet().asTable("FREQUENCIES");
853
[455]854 // Set rest frequency
[386]855 Vector<Double> restFreqIDs;
856 t.keywordSet().get("RESTFREQS",restFreqIDs);
[455]857 if (restFreqID < restFreqIDs.nelements()) { // Should always be true
[386]858 spec.setRestFrequency(restFreqIDs(restFreqID),True);
[286]859 }
860
[455]861 // Set up frame conversion layer
[286]862 String frm;
863 t.keywordSet().get("REFFRAME",frm);
864 if (frm == "") frm = "TOPO";
865 MFrequency::Types mtype;
866 if (!MFrequency::getType(mtype, frm)) {
[455]867 // Should never happen
868 cerr << "Frequency type unknown assuming TOPO" << endl;
[286]869 mtype = MFrequency::TOPO;
870 }
871
[455]872 // Set reference frame conversion (requires row)
[401]873 MDirection dir = getDirection(whichRow);
[286]874 MEpoch epoch = getEpoch(whichRow);
875 MPosition pos = getAntennaPosition();
[455]876
[401]877 if (!spec.setReferenceConversion(mtype,epoch,pos,dir)) {
[286]878 throw(AipsError("Couldn't convert frequency frame."));
879 }
880
[455]881 // Now velocity conversion if appropriate
[286]882 String unitStr;
883 t.keywordSet().get("UNIT",unitStr);
[455]884
[286]885 String dpl;
886 t.keywordSet().get("DOPPLER",dpl);
887 MDoppler::Types dtype;
888 MDoppler::getType(dtype, dpl);
889
[455]890 // Only set velocity unit if non-blank and non-Hz
[286]891 if (!unitStr.empty()) {
892 Unit unitU(unitStr);
893 if (unitU==Unit("Hz")) {
894 } else {
895 spec.setVelocity(unitStr, dtype);
896 }
897 }
[455]898
[39]899 return spec;
900}
901
[286]902
[89]903Bool SDMemTable::setCoordinate(const SpectralCoordinate& speccord,
[347]904 uInt freqID) {
[50]905 Table t = table_.rwKeywordSet().asTable("FREQUENCIES");
[347]906 if (freqID > t.nrow() ) {
[89]907 throw(AipsError("SDMemTable::setCoordinate - coord no out of range"));
[50]908 }
909 ScalarColumn<Double> rpc(t, "REFPIX");
910 ScalarColumn<Double> rvc(t, "REFVAL");
911 ScalarColumn<Double> incc(t, "INCREMENT");
[89]912
[347]913 rpc.put(freqID, speccord.referencePixel()[0]);
914 rvc.put(freqID, speccord.referenceValue()[0]);
915 incc.put(freqID, speccord.increment()[0]);
[50]916
917 return True;
918}
919
[89]920Int SDMemTable::nCoordinates() const
921{
922 return table_.keywordSet().asTable("FREQUENCIES").nrow();
923}
[50]924
[89]925
[251]926std::vector<double> SDMemTable::getRestFreqs() const
927{
928 Table t = table_.keywordSet().asTable("FREQUENCIES");
929 Vector<Double> tvec;
930 t.keywordSet().get("RESTFREQS",tvec);
931 std::vector<double> stlout;
932 tvec.tovector(stlout);
933 return stlout;
934}
935
[206]936bool SDMemTable::putSDFreqTable(const SDFrequencyTable& sdft)
937{
[39]938 TableDesc td("", "1", TableDesc::Scratch);
939 td.addColumn(ScalarColumnDesc<Double>("REFPIX"));
940 td.addColumn(ScalarColumnDesc<Double>("REFVAL"));
941 td.addColumn(ScalarColumnDesc<Double>("INCREMENT"));
942 SetupNewTable aNewTab("freqs", td, Table::New);
943 Table aTable (aNewTab, Table::Memory, sdft.length());
944 ScalarColumn<Double> sc0(aTable, "REFPIX");
945 ScalarColumn<Double> sc1(aTable, "REFVAL");
946 ScalarColumn<Double> sc2(aTable, "INCREMENT");
947 for (uInt i=0; i < sdft.length(); ++i) {
948 sc0.put(i,sdft.referencePixel(i));
949 sc1.put(i,sdft.referenceValue(i));
950 sc2.put(i,sdft.increment(i));
951 }
[105]952 String rf = sdft.refFrame();
953 if (rf.contains("TOPO")) rf = "TOPO";
954
955 aTable.rwKeywordSet().define("BASEREFFRAME", rf);
956 aTable.rwKeywordSet().define("REFFRAME", rf);
[39]957 aTable.rwKeywordSet().define("EQUINOX", sdft.equinox());
[105]958 aTable.rwKeywordSet().define("UNIT", String(""));
959 aTable.rwKeywordSet().define("DOPPLER", String("RADIO"));
[89]960 Vector<Double> rfvec;
[206]961 String rfunit;
962 sdft.restFrequencies(rfvec,rfunit);
963 Quantum<Vector<Double> > q(rfvec, rfunit);
964 rfvec.resize();
965 rfvec = q.getValue("Hz");
[89]966 aTable.rwKeywordSet().define("RESTFREQS", rfvec);
[455]967 table_.rwKeywordSet().defineTable("FREQUENCIES", aTable);
968 return true;
[39]969}
970
[455]971bool SDMemTable::putSDFitTable(const SDFitTable& sdft)
972{
973 TableDesc td("", "1", TableDesc::Scratch);
974 td.addColumn(ArrayColumnDesc<String>("FUNCTIONS"));
975 td.addColumn(ArrayColumnDesc<Int>("COMPONENTS"));
976 td.addColumn(ArrayColumnDesc<Double>("PARAMETERS"));
977 td.addColumn(ArrayColumnDesc<Bool>("PARMASK"));
[465]978 td.addColumn(ArrayColumnDesc<String>("FRAMEINFO"));
[455]979 SetupNewTable aNewTab("fits", td, Table::New);
980 Table aTable(aNewTab, Table::Memory);
981 ArrayColumn<String> sc0(aTable, "FUNCTIONS");
982 ArrayColumn<Int> sc1(aTable, "COMPONENTS");
983 ArrayColumn<Double> sc2(aTable, "PARAMETERS");
984 ArrayColumn<Bool> sc3(aTable, "PARMASK");
[465]985 ArrayColumn<String> sc4(aTable, "FRAMEINFO");
[455]986 for (uInt i; i<sdft.length(); ++i) {
[465]987 const Vector<Double>& parms = sdft.getParameters(i);
988 const Vector<Bool>& parmask = sdft.getParameterMask(i);
989 const Vector<String>& funcs = sdft.getFunctions(i);
990 const Vector<Int>& comps = sdft.getComponents(i);
991 const Vector<String>& finfo = sdft.getFrameInfo(i);
[455]992 sc0.put(i,funcs);
993 sc1.put(i,comps);
994 sc3.put(i,parmask);
995 sc2.put(i,parms);
[465]996 sc4.put(i,finfo);
[455]997 }
998 table_.rwKeywordSet().defineTable("FITS", aTable);
999 return true;
1000}
1001
1002SDFitTable SDMemTable::getSDFitTable() const
1003{
1004 const Table& t = table_.keywordSet().asTable("FITS");
1005 Vector<Double> parms;
1006 Vector<Bool> parmask;
1007 Vector<String> funcs;
[465]1008 Vector<String> finfo;
[455]1009 Vector<Int> comps;
1010 ROArrayColumn<Double> parmsCol(t, "PARAMETERS");
1011 ROArrayColumn<Bool> parmaskCol(t, "PARMASK");
1012 ROArrayColumn<Int> compsCol(t, "COMPONENTS");
1013 ROArrayColumn<String> funcsCol(t, "FUNCTIONS");
[465]1014 ROArrayColumn<String> finfoCol(t, "FRAMEINFO");
[455]1015 uInt n = t.nrow();
[465]1016 SDFitTable sdft;
[455]1017 for (uInt i=0; i<n; ++i) {
1018 parmaskCol.get(i, parmask);
1019 parmsCol.get(i, parms);
1020 funcsCol.get(i, funcs);
1021 compsCol.get(i, comps);
[465]1022 finfoCol.get(i, finfo);
1023 sdft.addFit(parms, parmask, funcs, comps, finfo);
[455]1024 }
1025 return sdft;
1026}
1027
[465]1028SDFitTable SDMemTable::getSDFitTable(uInt whichRow) const {
1029 Array<Int> fitid;
1030 fitCol_.get(whichRow, fitid);
1031 if (fitid.nelements() == 0) return SDFitTable();
[455]1032
[465]1033 IPosition shp = fitid.shape();
1034 IPosition start(4, beamSel_, IFSel_, polSel_,0);
1035 IPosition end(4, beamSel_, IFSel_, polSel_, shp[3]-1);
1036
1037 // reform the output array slice to be of dim=1
1038 Vector<Int> tmp = (fitid(start, end)).reform(IPosition(1,shp[3]));
1039
1040 const Table& t = table_.keywordSet().asTable("FITS");
1041 Vector<Double> parms;
1042 Vector<Bool> parmask;
1043 Vector<String> funcs;
1044 Vector<String> finfo;
1045 Vector<Int> comps;
1046 ROArrayColumn<Double> parmsCol(t, "PARAMETERS");
1047 ROArrayColumn<Bool> parmaskCol(t, "PARMASK");
1048 ROArrayColumn<Int> compsCol(t, "COMPONENTS");
1049 ROArrayColumn<String> funcsCol(t, "FUNCTIONS");
1050 ROArrayColumn<String> finfoCol(t, "FRAMEINFO");
1051 if (t.nrow() == 0) return SDFitTable();
1052 SDFitTable sdft;
1053 Int k=-1;
1054 for (uInt i=0; i< tmp.nelements(); ++i) {
1055 k = tmp[i];
1056 if ( k > -1 && k < t.nrow() ) {
1057 parms.resize();
1058 parmsCol.get(k, parms);
1059 parmask.resize();
1060 parmaskCol.get(k, parmask);
1061 funcs.resize();
1062 funcsCol.get(k, funcs);
1063 comps.resize();
1064 compsCol.get(k, comps);
1065 finfo.resize();
1066 finfoCol.get(k, finfo);
1067 sdft.addFit(parms, parmask, funcs, comps, finfo);
1068 }
1069 }
1070 return sdft;
1071}
1072
[455]1073void SDMemTable::addFit(uInt whichRow,
1074 const Vector<Double>& p, const Vector<Bool>& m,
1075 const Vector<String>& f, const Vector<Int>& c)
1076{
1077 if (whichRow >= nRow()) {
1078 throw(AipsError("Specified row out of range"));
1079 }
1080 Table t = table_.keywordSet().asTable("FITS");
1081 uInt nrow = t.nrow();
1082 t.addRow();
1083 ArrayColumn<Double> parmsCol(t, "PARAMETERS");
1084 ArrayColumn<Bool> parmaskCol(t, "PARMASK");
1085 ArrayColumn<Int> compsCol(t, "COMPONENTS");
1086 ArrayColumn<String> funcsCol(t, "FUNCTIONS");
[465]1087 ArrayColumn<String> finfoCol(t, "FRAMEINFO");
[455]1088 parmsCol.put(nrow, p);
1089 parmaskCol.put(nrow, m);
1090 compsCol.put(nrow, c);
1091 funcsCol.put(nrow, f);
[465]1092 Vector<String> fi = mathutil::toVectorString(getCoordInfo());
1093 finfoCol.put(nrow, fi);
[455]1094
1095 Array<Int> fitarr;
1096 fitCol_.get(whichRow, fitarr);
1097
1098 Array<Int> newarr; // The new Array containing the fitid
1099 Int pos =-1; // The fitid position in the array
1100 if ( fitarr.nelements() == 0 ) { // no fits at all in this row
1101 Array<Int> arr(IPosition(4,nBeam(),nIF(),nPol(),1));
1102 arr = -1;
1103 newarr.reference(arr);
1104 pos = 0;
1105 } else {
1106 IPosition shp = fitarr.shape();
1107 IPosition start(4, beamSel_, IFSel_, polSel_,0);
1108 IPosition end(4, beamSel_, IFSel_, polSel_, shp[3]-1);
1109 // reform the output array slice to be of dim=1
1110 Array<Int> tmp = (fitarr(start, end)).reform(IPosition(1,shp[3]));
1111 const Vector<Int>& fits = tmp;
1112 VectorSTLIterator<Int> it(fits);
1113 Int i = 0;
1114 while (it != fits.end()) {
1115 if (*it == -1) {
1116 pos = i;
1117 break;
1118 }
1119 ++i;
1120 ++it;
1121 };
1122 }
1123 if (pos == -1) {
1124 mathutil::extendLastArrayAxis(newarr,fitarr, -1);
1125 pos = fitarr.shape()[3]; // the new element position
1126 } else {
1127 if (fitarr.nelements() > 0)
1128 newarr = fitarr;
1129 }
1130 newarr(IPosition(4, beamSel_, IFSel_, polSel_, pos)) = Int(nrow);
1131 fitCol_.put(whichRow, newarr);
1132
1133}
1134
[206]1135SDFrequencyTable SDMemTable::getSDFreqTable() const
1136{
[251]1137 const Table& t = table_.keywordSet().asTable("FREQUENCIES");
[39]1138 SDFrequencyTable sdft;
[306]1139
[455]1140 // Add refpix/refval/incr. What are the units ? Hz I suppose
1141 // but it's nowhere described...
[306]1142 Vector<Double> refPix, refVal, incr;
1143 ScalarColumn<Double> refPixCol(t, "REFPIX");
1144 ScalarColumn<Double> refValCol(t, "REFVAL");
1145 ScalarColumn<Double> incrCol(t, "INCREMENT");
1146 refPix = refPixCol.getColumn();
1147 refVal = refValCol.getColumn();
1148 incr = incrCol.getColumn();
[455]1149
[306]1150 uInt n = refPix.nelements();
1151 for (uInt i=0; i<n; i++) {
1152 sdft.addFrequency(refPix[i], refVal[i], incr[i]);
1153 }
1154
[455]1155 // Frequency reference frame. I don't know if this
1156 // is the correct frame. It might be 'REFFRAME'
1157 // rather than 'BASEREFFRAME' ?
[306]1158 String baseFrame;
1159 t.keywordSet().get("BASEREFFRAME",baseFrame);
1160 sdft.setRefFrame(baseFrame);
1161
[455]1162 // Equinox
[306]1163 Float equinox;
1164 t.keywordSet().get("EQUINOX", equinox);
1165 sdft.setEquinox(equinox);
1166
[455]1167 // Rest Frequency
[306]1168 Vector<Double> restFreqs;
1169 t.keywordSet().get("RESTFREQS", restFreqs);
1170 for (uInt i=0; i<restFreqs.nelements(); i++) {
1171 sdft.addRestFrequency(restFreqs[i]);
1172 }
1173 sdft.setRestFrequencyUnit(String("Hz"));
[455]1174
[39]1175 return sdft;
1176}
1177
[206]1178bool SDMemTable::putSDContainer(const SDContainer& sdc)
1179{
[2]1180 uInt rno = table_.nrow();
1181 table_.addRow();
[455]1182
[322]1183 timeCol_.put(rno, sdc.timestamp);
1184 srcnCol_.put(rno, sdc.sourcename);
1185 fldnCol_.put(rno, sdc.fieldname);
1186 specCol_.put(rno, sdc.getSpectrum());
1187 flagsCol_.put(rno, sdc.getFlags());
1188 tsCol_.put(rno, sdc.getTsys());
1189 scanCol_.put(rno, sdc.scanid);
1190 integrCol_.put(rno, sdc.interval);
1191 freqidCol_.put(rno, sdc.getFreqMap());
[386]1192 restfreqidCol_.put(rno, sdc.getRestFreqMap());
[322]1193 dirCol_.put(rno, sdc.getDirection());
1194 rbeamCol_.put(rno, sdc.refbeam);
1195 tcalCol_.put(rno, sdc.tcal);
1196 tcaltCol_.put(rno, sdc.tcaltime);
1197 azCol_.put(rno, sdc.azimuth);
1198 elCol_.put(rno, sdc.elevation);
1199 paraCol_.put(rno, sdc.parangle);
1200 histCol_.put(rno, sdc.getHistory());
[455]1201 fitCol_.put(rno, sdc.getFitMap());
[2]1202 return true;
1203}
[18]1204
[206]1205SDContainer SDMemTable::getSDContainer(uInt whichRow) const
1206{
[21]1207 SDContainer sdc(nBeam(),nIF(),nPol(),nChan());
[322]1208 timeCol_.get(whichRow, sdc.timestamp);
1209 srcnCol_.get(whichRow, sdc.sourcename);
1210 integrCol_.get(whichRow, sdc.interval);
1211 scanCol_.get(whichRow, sdc.scanid);
1212 fldnCol_.get(whichRow, sdc.fieldname);
1213 rbeamCol_.get(whichRow, sdc.refbeam);
1214 azCol_.get(whichRow, sdc.azimuth);
1215 elCol_.get(whichRow, sdc.elevation);
1216 paraCol_.get(whichRow, sdc.parangle);
[105]1217 Vector<Float> tc;
[322]1218 tcalCol_.get(whichRow, tc);
[105]1219 sdc.tcal[0] = tc[0];sdc.tcal[1] = tc[1];
[322]1220 tcaltCol_.get(whichRow, sdc.tcaltime);
[455]1221
[21]1222 Array<Float> spectrum;
1223 Array<Float> tsys;
1224 Array<uChar> flagtrum;
[39]1225 Vector<uInt> fmap;
[78]1226 Array<Double> direction;
[206]1227 Vector<String> histo;
[455]1228 Array<Int> fits;
1229
[322]1230 specCol_.get(whichRow, spectrum);
[21]1231 sdc.putSpectrum(spectrum);
[322]1232 flagsCol_.get(whichRow, flagtrum);
[21]1233 sdc.putFlags(flagtrum);
[322]1234 tsCol_.get(whichRow, tsys);
[21]1235 sdc.putTsys(tsys);
[322]1236 freqidCol_.get(whichRow, fmap);
[39]1237 sdc.putFreqMap(fmap);
[386]1238 restfreqidCol_.get(whichRow, fmap);
1239 sdc.putRestFreqMap(fmap);
[322]1240 dirCol_.get(whichRow, direction);
[78]1241 sdc.putDirection(direction);
[322]1242 histCol_.get(whichRow, histo);
[206]1243 sdc.putHistory(histo);
[455]1244 fitCol_.get(whichRow, fits);
1245 sdc.putFitMap(fits);
[21]1246 return sdc;
1247}
[78]1248
[206]1249bool SDMemTable::putSDHeader(const SDHeader& sdh)
1250{
[18]1251 table_.rwKeywordSet().define("nIF", sdh.nif);
1252 table_.rwKeywordSet().define("nBeam", sdh.nbeam);
1253 table_.rwKeywordSet().define("nPol", sdh.npol);
1254 table_.rwKeywordSet().define("nChan", sdh.nchan);
1255 table_.rwKeywordSet().define("Observer", sdh.observer);
1256 table_.rwKeywordSet().define("Project", sdh.project);
1257 table_.rwKeywordSet().define("Obstype", sdh.obstype);
1258 table_.rwKeywordSet().define("AntennaName", sdh.antennaname);
1259 table_.rwKeywordSet().define("AntennaPosition", sdh.antennaposition);
1260 table_.rwKeywordSet().define("Equinox", sdh.equinox);
1261 table_.rwKeywordSet().define("FreqRefFrame", sdh.freqref);
1262 table_.rwKeywordSet().define("FreqRefVal", sdh.reffreq);
1263 table_.rwKeywordSet().define("Bandwidth", sdh.bandwidth);
1264 table_.rwKeywordSet().define("UTC", sdh.utc);
[206]1265 table_.rwKeywordSet().define("FluxUnit", sdh.fluxunit);
1266 table_.rwKeywordSet().define("Epoch", sdh.epoch);
[18]1267 return true;
[50]1268}
[21]1269
[206]1270SDHeader SDMemTable::getSDHeader() const
1271{
[21]1272 SDHeader sdh;
1273 table_.keywordSet().get("nBeam",sdh.nbeam);
1274 table_.keywordSet().get("nIF",sdh.nif);
1275 table_.keywordSet().get("nPol",sdh.npol);
1276 table_.keywordSet().get("nChan",sdh.nchan);
1277 table_.keywordSet().get("Observer", sdh.observer);
1278 table_.keywordSet().get("Project", sdh.project);
1279 table_.keywordSet().get("Obstype", sdh.obstype);
1280 table_.keywordSet().get("AntennaName", sdh.antennaname);
1281 table_.keywordSet().get("AntennaPosition", sdh.antennaposition);
1282 table_.keywordSet().get("Equinox", sdh.equinox);
1283 table_.keywordSet().get("FreqRefFrame", sdh.freqref);
1284 table_.keywordSet().get("FreqRefVal", sdh.reffreq);
1285 table_.keywordSet().get("Bandwidth", sdh.bandwidth);
1286 table_.keywordSet().get("UTC", sdh.utc);
[206]1287 table_.keywordSet().get("FluxUnit", sdh.fluxunit);
1288 table_.keywordSet().get("Epoch", sdh.epoch);
[21]1289 return sdh;
[18]1290}
[206]1291void SDMemTable::makePersistent(const std::string& filename)
1292{
[2]1293 table_.deepCopy(filename,Table::New);
1294}
1295
[89]1296Int SDMemTable::nScan() const {
[50]1297 Int n = 0;
1298 Int previous = -1;Int current=0;
[322]1299 for (uInt i=0; i< scanCol_.nrow();i++) {
1300 scanCol_.getScalar(i,current);
[50]1301 if (previous != current) {
[89]1302 previous = current;
[50]1303 n++;
1304 }
1305 }
1306 return n;
1307}
1308
[260]1309String SDMemTable::formatSec(Double x) const
[206]1310{
[105]1311 Double xcop = x;
1312 MVTime mvt(xcop/24./3600.); // make days
[365]1313
[105]1314 if (x < 59.95)
[281]1315 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_HM, 7)+"s";
1316 else if (x < 3599.95)
1317 return String(" ") + mvt.string(MVTime::TIME_CLEAN_NO_H,7)+" ";
1318 else {
1319 ostringstream oss;
1320 oss << setw(2) << std::right << setprecision(1) << mvt.hour();
1321 oss << ":" << mvt.string(MVTime::TIME_CLEAN_NO_H,7) << " ";
1322 return String(oss);
1323 }
[105]1324};
1325
[281]1326String SDMemTable::formatDirection(const MDirection& md) const
1327{
1328 Vector<Double> t = md.getAngle(Unit(String("rad"))).getValue();
1329 Int prec = 7;
1330
1331 MVAngle mvLon(t[0]);
1332 String sLon = mvLon.string(MVAngle::TIME,prec);
1333 MVAngle mvLat(t[1]);
1334 String sLat = mvLat.string(MVAngle::ANGLE+MVAngle::DIG2,prec);
[380]1335 return sLon + String(" ") + sLat;
[281]1336}
1337
1338
[206]1339std::string SDMemTable::getFluxUnit() const
1340{
1341 String tmp;
1342 table_.keywordSet().get("FluxUnit", tmp);
1343 return tmp;
1344}
1345
[218]1346void SDMemTable::setFluxUnit(const std::string& unit)
1347{
1348 String tmp(unit);
1349 Unit tU(tmp);
1350 if (tU==Unit("K") || tU==Unit("Jy")) {
1351 table_.rwKeywordSet().define(String("FluxUnit"), tmp);
1352 } else {
1353 throw AipsError("Illegal unit - must be compatible with Jy or K");
1354 }
1355}
1356
[275]1357
[236]1358void SDMemTable::setInstrument(const std::string& name)
1359{
1360 Bool throwIt = True;
[455]1361 Instrument ins = convertInstrument(name, throwIt);
[236]1362 String nameU(name);
1363 nameU.upcase();
1364 table_.rwKeywordSet().define(String("AntennaName"), nameU);
1365}
1366
[380]1367std::string SDMemTable::summary(bool verbose) const {
[281]1368
[455]1369 // Format header info
[89]1370 ostringstream oss;
1371 oss << endl;
[380]1372 oss << "--------------------------------------------------------------------------------" << endl;
[89]1373 oss << " Scan Table Summary" << endl;
[380]1374 oss << "--------------------------------------------------------------------------------" << endl;
[89]1375 oss.flags(std::ios_base::left);
1376 oss << setw(15) << "Beams:" << setw(4) << nBeam() << endl
1377 << setw(15) << "IFs:" << setw(4) << nIF() << endl
1378 << setw(15) << "Polarisations:" << setw(4) << nPol() << endl
1379 << setw(15) << "Channels:" << setw(4) << nChan() << endl;
1380 oss << endl;
1381 String tmp;
1382 table_.keywordSet().get("Observer", tmp);
1383 oss << setw(15) << "Observer:" << tmp << endl;
[281]1384 oss << setw(15) << "Obs Date:" << getTime(-1,True) << endl;
[89]1385 table_.keywordSet().get("Project", tmp);
1386 oss << setw(15) << "Project:" << tmp << endl;
1387 table_.keywordSet().get("Obstype", tmp);
1388 oss << setw(15) << "Obs. Type:" << tmp << endl;
1389 table_.keywordSet().get("AntennaName", tmp);
1390 oss << setw(15) << "Antenna Name:" << tmp << endl;
[206]1391 table_.keywordSet().get("FluxUnit", tmp);
1392 oss << setw(15) << "Flux Unit:" << tmp << endl;
[260]1393 Table t = table_.keywordSet().asTable("FREQUENCIES");
[105]1394 Vector<Double> vec;
1395 t.keywordSet().get("RESTFREQS",vec);
1396 oss << setw(15) << "Rest Freqs:";
1397 if (vec.nelements() > 0) {
1398 oss << setprecision(0) << vec << " [Hz]" << endl;
1399 } else {
1400 oss << "None set" << endl;
1401 }
[158]1402 oss << setw(15) << "Abcissa:" << getAbcissaString() << endl;
[105]1403 oss << setw(15) << "Cursor:" << "Beam[" << getBeam() << "] "
1404 << "IF[" << getIF() << "] " << "Pol[" << getPol() << "]" << endl;
[89]1405 oss << endl;
[455]1406
[385]1407 String dirtype ="Position ("+ MDirection::showType(getDirectionReference()) + ")";
[380]1408 oss << setw(5) << "Scan"
[281]1409 << setw(15) << "Source"
[380]1410 << setw(24) << dirtype
[281]1411 << setw(10) << "Time"
[365]1412 << setw(18) << "Integration"
[380]1413 << setw(7) << "FreqIDs" << endl;
1414 oss << "--------------------------------------------------------------------------------" << endl;
[281]1415
[455]1416 // Generate list of scan start and end integrations
[385]1417 Vector<Int> scanIDs = scanCol_.getColumn();
1418 Vector<uInt> startInt, endInt;
1419 mathutil::scanBoundaries(startInt, endInt, scanIDs);
[455]1420
[385]1421 const uInt nScans = startInt.nelements();
[365]1422 String name;
1423 Vector<uInt> freqIDs, listFQ;
[385]1424 uInt nInt;
[455]1425
[385]1426 for (uInt i=0; i<nScans; i++) {
[455]1427 // Get things from first integration of scan
1428 String time = getTime(startInt(i),False);
1429 String tInt = formatSec(Double(getInterval(startInt(i))));
1430 String posit = formatDirection(getDirection(startInt(i),True));
1431 srcnCol_.getScalar(startInt(i),name);
[367]1432
[455]1433 // Find all the FreqIDs in this scan
1434 listFQ.resize(0);
1435 for (uInt j=startInt(i); j<endInt(i)+1; j++) {
1436 freqidCol_.get(j, freqIDs);
1437 for (uInt k=0; k<freqIDs.nelements(); k++) {
1438 mathutil::addEntry(listFQ, freqIDs(k));
1439 }
1440 }
[367]1441
[455]1442 nInt = endInt(i) - startInt(i) + 1;
1443 oss << setw(3) << std::right << i << std::left << setw(2) << " "
1444 << setw(15) << name
1445 << setw(24) << posit
1446 << setw(10) << time
1447 << setw(3) << std::right << nInt << setw(3) << " x " << std::left
1448 << setw(6) << tInt
1449 << " " << listFQ << endl;
[2]1450 }
[89]1451 oss << endl;
[455]1452 oss << "Table contains " << table_.nrow() << " integration(s) in "
1453 << nScans << " scan(s)." << endl;
[321]1454
[455]1455 // Frequency Table
[380]1456 if (verbose) {
1457 std::vector<string> info = getCoordInfo();
1458 SDFrequencyTable sdft = getSDFreqTable();
1459 oss << endl << endl;
1460 oss << "FreqID Frame RefFreq(Hz) RefPix Increment(Hz)" << endl;
1461 oss << "--------------------------------------------------------------------------------" << endl;
1462 for (uInt i=0; i<sdft.length(); i++) {
1463 oss << setw(8) << i << setw(8)
1464 << info[3] << setw(16) << setprecision(8)
1465 << sdft.referenceValue(i) << setw(10)
1466 << sdft.referencePixel(i) << setw(12)
1467 << sdft.increment(i) << endl;
1468 }
1469 oss << "--------------------------------------------------------------------------------" << endl;
[321]1470 }
[89]1471 return String(oss);
[2]1472}
[18]1473
[206]1474Int SDMemTable::nBeam() const
1475{
[18]1476 Int n;
1477 table_.keywordSet().get("nBeam",n);
1478 return n;
1479}
[455]1480
[18]1481Int SDMemTable::nIF() const {
1482 Int n;
1483 table_.keywordSet().get("nIF",n);
1484 return n;
1485}
[455]1486
[18]1487Int SDMemTable::nPol() const {
1488 Int n;
1489 table_.keywordSet().get("nPol",n);
1490 return n;
1491}
[455]1492
[18]1493Int SDMemTable::nChan() const {
1494 Int n;
1495 table_.keywordSet().get("nChan",n);
1496 return n;
1497}
[455]1498
[206]1499bool SDMemTable::appendHistory(const std::string& hist, int whichRow)
1500{
1501 Vector<String> history;
[322]1502 histCol_.get(whichRow, history);
[206]1503 history.resize(history.nelements()+1,True);
1504 history[history.nelements()-1] = hist;
[322]1505 histCol_.put(whichRow, history);
[206]1506}
1507
1508std::vector<std::string> SDMemTable::history(int whichRow) const
1509{
1510 Vector<String> history;
[322]1511 histCol_.get(whichRow, history);
[465]1512 std::vector<std::string> stlout = mathutil::tovectorstring(history);
[206]1513 return stlout;
1514}
[16]1515/*
[18]1516void SDMemTable::maskChannels(const std::vector<Int>& whichChans ) {
[89]1517
[16]1518 std::vector<int>::iterator it;
[206]1519 ArrayAccessor<uChar, Axis<asap::PolAxis> > j(flags_);
[16]1520 for (it = whichChans.begin(); it != whichChans.end(); it++) {
1521 j.reset(j.begin(uInt(*it)));
[206]1522 for (ArrayAccessor<uChar, Axis<asap::BeamAxis> > i(j); i != i.end(); ++i) {
1523 for (ArrayAccessor<uChar, Axis<asap::IFAxis> > ii(i); ii != ii.end(); ++ii) {
1524 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > iii(ii);
[89]1525 iii != iii.end(); ++iii) {
1526 (*iii) =
1527 }
[16]1528 }
1529 }
1530 }
[89]1531
[16]1532}
1533*/
[206]1534void SDMemTable::flag(int whichRow)
1535{
[89]1536 Array<uChar> arr;
[322]1537 flagsCol_.get(whichRow, arr);
[89]1538
[206]1539 ArrayAccessor<uChar, Axis<asap::BeamAxis> > aa0(arr);
[89]1540 aa0.reset(aa0.begin(uInt(beamSel_)));//go to beam
[206]1541 ArrayAccessor<uChar, Axis<asap::IFAxis> > aa1(aa0);
[89]1542 aa1.reset(aa1.begin(uInt(IFSel_)));// go to IF
[206]1543 ArrayAccessor<uChar, Axis<asap::PolAxis> > aa2(aa1);
[89]1544 aa2.reset(aa2.begin(uInt(polSel_)));// go to pol
1545
[206]1546 for (ArrayAccessor<uChar, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
[89]1547 (*i) = uChar(True);
1548 }
1549
[322]1550 flagsCol_.put(whichRow, arr);
[89]1551}
[212]1552
[281]1553MDirection::Types SDMemTable::getDirectionReference() const
[212]1554{
1555 Float eq;
1556 table_.keywordSet().get("Equinox",eq);
1557 std::map<float,string> mp;
1558 mp[2000.0] = "J2000";
1559 mp[1950.0] = "B1950";
1560 MDirection::Types mdr;
1561 if (!MDirection::getType(mdr, mp[eq])) {
1562 mdr = MDirection::J2000;
1563 cerr << "Unknown equinox using J2000" << endl;
1564 }
[455]1565
[212]1566 return mdr;
1567}
1568
[380]1569MEpoch::Types SDMemTable::getTimeReference() const
[212]1570{
1571 MEpoch::Types met;
1572 String ep;
1573 table_.keywordSet().get("Epoch",ep);
1574 if (!MEpoch::getType(met, ep)) {
[387]1575 cerr << "Epoch type unknown - using UTC" << endl;
[212]1576 met = MEpoch::UTC;
1577 }
[455]1578
[212]1579 return met;
1580}
1581
[236]1582
[380]1583Instrument SDMemTable::convertInstrument(const String& instrument,
1584 Bool throwIt)
[236]1585{
1586 String t(instrument);
1587 t.upcase();
[293]1588
[455]1589 // The strings are what SDReader returns, after cunning interrogation
1590 // of station names... :-(
[236]1591 Instrument inst = asap::UNKNOWN;
[293]1592 if (t==String("DSS-43")) {
[236]1593 inst = TIDBINBILLA;
1594 } else if (t==String("ATPKSMB")) {
[292]1595 inst = ATPKSMB;
1596 } else if (t==String("ATPKSHOH")) {
1597 inst = ATPKSHOH;
1598 } else if (t==String("ATMOPRA")) {
1599 inst = ATMOPRA;
1600 } else if (t==String("CEDUNA")) {
1601 inst = CEDUNA;
1602 } else if (t==String("HOBART")) {
1603 inst = HOBART;
[236]1604 } else {
[380]1605 if (throwIt) {
1606 throw AipsError("Unrecognized instrument - use function scan.set_instrument to set");
1607 }
[236]1608 }
1609 return inst;
1610}
1611
[455]1612Bool SDMemTable::setRestFreqs(const Vector<Double>& restFreqsIn,
1613 const String& sUnit,
1614 const vector<string>& lines,
1615 const String& source,
1616 Int whichIF)
[386]1617{
1618 const Int nIFs = nIF();
1619 if (whichIF>=nIFs) {
1620 throw(AipsError("Illegal IF index"));
1621 }
1622
[455]1623 // Find vector of restfrequencies
1624 // Double takes precedence over String
[401]1625 Unit unit;
1626 Vector<Double> restFreqs;
1627 if (restFreqsIn.nelements()>0) {
1628 restFreqs.resize(restFreqsIn.nelements());
1629 restFreqs = restFreqsIn;
1630 unit = Unit(sUnit);
1631 } else if (lines.size()>0) {
1632 const uInt nLines = lines.size();
1633 unit = Unit("Hz");
1634 restFreqs.resize(nLines);
1635 MFrequency lineFreq;
1636 for (uInt i=0; i<nLines; i++) {
1637 String tS(lines[i]);
1638 tS.upcase();
1639 if (MeasTable::Line(lineFreq, tS)) {
1640 restFreqs[i] = lineFreq.getValue().getValue(); // Hz
1641 } else {
[455]1642 String s = String(lines[i]) +
1643 String(" is an unrecognized spectral line");
[401]1644 throw(AipsError(s));
1645 }
1646 }
1647 } else {
1648 throw(AipsError("You have not specified any rest frequencies or lines"));
1649 }
1650
[455]1651 // If multiple restfreqs, must be length nIF. In this
1652 // case we will just replace the rest frequencies
[392]1653 const uInt nRestFreqs = restFreqs.nelements();
1654 Int idx = -1;
[386]1655 SDFrequencyTable sdft = getSDFreqTable();
1656
[392]1657 if (nRestFreqs>1) {
[455]1658 // Replace restFreqs, one per IF
[392]1659 if (nRestFreqs != nIFs) {
1660 throw (AipsError("Number of rest frequencies must be equal to the number of IFs"));
1661 }
[414]1662 cout << "Replacing rest frequencies with given list, one per IF" << endl;
[392]1663 sdft.deleteRestFrequencies();
1664 for (uInt i=0; i<nRestFreqs; i++) {
1665 Quantum<Double> rf(restFreqs[i], unit);
1666 sdft.addRestFrequency(rf.getValue("Hz"));
1667 }
1668 } else {
1669
[455]1670 // Add new rest freq
[392]1671 Quantum<Double> rf(restFreqs[0], unit);
1672 idx = sdft.addRestFrequency(rf.getValue("Hz"));
[414]1673 cout << "Selecting given rest frequency" << endl;
[392]1674 }
[455]1675
1676 // Replace
[386]1677 Bool empty = source.empty();
1678 Bool ok = False;
1679 if (putSDFreqTable(sdft)) {
1680 const uInt nRow = table_.nrow();
1681 String srcName;
1682 Vector<uInt> restFreqIDs;
1683 for (uInt i=0; i<nRow; i++) {
1684 srcnCol_.get(i, srcName);
1685 restfreqidCol_.get(i,restFreqIDs);
[455]1686
[392]1687 if (idx==-1) {
[455]1688 // Replace vector of restFreqs; one per IF.
1689 // No selection possible
[392]1690 for (uInt i=0; i<nIFs; i++) restFreqIDs[i] = i;
1691 } else {
[455]1692 // Set RestFreqID for selected data
[392]1693 if (empty || source==srcName) {
1694 if (whichIF<0) {
1695 restFreqIDs = idx;
1696 } else {
1697 restFreqIDs[whichIF] = idx;
1698 }
[386]1699 }
1700 }
1701 restfreqidCol_.put(i,restFreqIDs);
1702 }
1703 ok = True;
1704 } else {
[455]1705 ok = False;
[386]1706 }
[455]1707
[386]1708 return ok;
1709}
1710
[414]1711void SDMemTable::spectralLines() const
[401]1712{
1713 Vector<String> lines = MeasTable::Lines();
1714 MFrequency lineFreq;
1715 Double freq;
[455]1716
[414]1717 cout.flags(std::ios_base::left);
1718 cout << "Line Frequency (Hz)" << endl;
1719 cout << "-----------------------" << endl;
[401]1720 for (uInt i=0; i<lines.nelements(); i++) {
1721 MeasTable::Line(lineFreq, lines[i]);
1722 freq = lineFreq.getValue().getValue(); // Hz
[414]1723 cout << setw(11) << lines[i] << setprecision(10) << freq << endl;
[401]1724 }
1725}
[386]1726
[380]1727void SDMemTable::renumber()
1728{
1729 uInt nRow = scanCol_.nrow();
1730 Int newscanid = 0;
1731 Int cIdx;// the current scanid
1732 // get the first scanid
1733 scanCol_.getScalar(0,cIdx);
1734 Int pIdx = cIdx;// the scanid of the previous row
1735 for (uInt i=0; i<nRow;++i) {
1736 scanCol_.getScalar(i,cIdx);
1737 if (pIdx == cIdx) {
1738 // renumber
1739 scanCol_.put(i,newscanid);
1740 } else {
1741 ++newscanid;
1742 pIdx = cIdx; // store scanid
1743 --i; // don't increment next loop
1744 }
1745 }
1746}
[386]1747
[418]1748
[455]1749void SDMemTable::setCursorSlice(IPosition& start, IPosition& end,
1750 const IPosition& shape) const
[430]1751{
[455]1752 const uInt nDim = shape.nelements();
1753 start.resize(nDim);
1754 end.resize(nDim);
1755
1756 start(asap::BeamAxis) = beamSel_;
1757 end(asap::BeamAxis) = beamSel_;
1758 start(asap::IFAxis) = IFSel_;
1759 end(asap::IFAxis) = IFSel_;
[430]1760
[455]1761 start(asap::PolAxis) = polSel_;
1762 end(asap::PolAxis) = polSel_;
[430]1763
[455]1764 start(asap::ChanAxis) = 0;
1765 end(asap::ChanAxis) = shape(asap::ChanAxis) - 1;
[430]1766}
1767
[447]1768
[455]1769std::vector<float> SDMemTable::getFloatSpectrum(const Array<Float>& arr) const
1770 // Get spectrum at cursor location
[447]1771{
1772
[455]1773 // Setup accessors
[447]1774 ArrayAccessor<Float, Axis<asap::BeamAxis> > aa0(arr);
1775 aa0.reset(aa0.begin(uInt(beamSel_))); // Beam selection
1776
1777 ArrayAccessor<Float, Axis<asap::IFAxis> > aa1(aa0);
1778 aa1.reset(aa1.begin(uInt(IFSel_))); // IF selection
1779
1780 ArrayAccessor<Float, Axis<asap::PolAxis> > aa2(aa1);
1781 aa2.reset(aa2.begin(uInt(polSel_))); // Pol selection
[455]1782
[447]1783 std::vector<float> spectrum;
1784 for (ArrayAccessor<Float, Axis<asap::ChanAxis> > i(aa2); i != i.end(); ++i) {
1785 spectrum.push_back(*i);
1786 }
1787 return spectrum;
1788}
1789
Note: See TracBrowser for help on using the repository browser.