source: branches/Release-1-fixes/src/SDMemTable.cc@ 935

Last change on this file since 935 was 586, checked in by mar637, 20 years ago

Fix bug asap0001

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