source: branches/Release12/src/SDMemTable.cc@ 1236

Last change on this file since 1236 was 800, checked in by mar637, 19 years ago

Request: added channel based flagging

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