source: trunk/src/SDMemTable.cc@ 491

Last change on this file since 491 was 490, checked in by kil064, 20 years ago

add functions

stokesLength
getStokesSpectrumLabel
getCircularSpectrumLabel

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