source: trunk/src/ScantableWrapper.h@ 3058

Last change on this file since 3058 was 3052, checked in by Takeshi Nakazato, 9 years ago

New Development: No

JIRA Issue: Yes CAS-7764

Ready for Test: Yes

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description:

Applied a patch provided by Julian. The patch releases GIL in some (potentially) time-consuming functions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.3 KB
RevLine 
[847]1//
2// C++ Interface: Scantable
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef ASAPSCANTABLEWRAPPER_H
13#define ASAPSCANTABLEWRAPPER_H
[2]14
[2587]15#include <iostream>
16#include <string>
[2]17#include <vector>
[2587]18
[380]19#include <casa/Arrays/Vector.h>
[2]20
[465]21#include "MathUtils.h"
[2587]22#include "Scantable.h"
23#include "STCoordinate.h"
[901]24#include "STFit.h"
[1931]25#include "STFitEntry.h"
[3046]26#include "GILHandler.h"
[2]27
[83]28namespace asap {
[847]29/**
30 * This class contains and wraps a CountedPtr<Scantable>, as the CountedPtr
31 * class does not provide the dor operator which is need for references
32 * in boost::python
33 * see Scantable for interfce description
34 *
35 * @brief The main ASAP data container wrapper
36 * @author Malte Marquarding
37 * @date 2006-02-23
38 * @version 2.0a
39*/
40class ScantableWrapper {
[2]41
42public:
[1385]43 explicit ScantableWrapper( const std::string& name,
[1077]44 int type=0)
[864]45 {
[3052]46 GILHandler scopedRelease;
[864]47 casa::Table::TableType tp = casa::Table::Memory;
[1077]48 if ( type == 1 ) tp = casa::Table::Plain;
[864]49 table_ = new Scantable(name, tp);
50 }
[90]51
[1350]52 explicit ScantableWrapper(int type=0)
[864]53 {
[3052]54 GILHandler scopedRelease;
[864]55 casa::Table::TableType tp = casa::Table::Memory;
[1077]56 if ( type == 1) tp = casa::Table::Plain;
[864]57 table_= new Scantable(tp);
58 }
[90]59
[1350]60 explicit ScantableWrapper(casa::CountedPtr<Scantable> cp) : table_(cp) {;}
[90]61
[847]62 ScantableWrapper(const ScantableWrapper& mt) :
63 table_(mt.getCP()) {;}
[90]64
[2587]65 ~ScantableWrapper()
66 {
[3052]67 GILHandler scopedRelease;
68 table_.reset();
[2587]69 }
70
[868]71 void assign(const ScantableWrapper& mt)
72 { table_= mt.getCP(); }
73
[847]74 ScantableWrapper copy() {
[3052]75 GILHandler scopedRelease;
[847]76 return ScantableWrapper(new Scantable(*(this->getCP()), false));
[80]77 }
[868]78
[896]79 std::vector<float> getSpectrum( int whichrow=0,
[905]80 const std::string& poltype="" ) const {
[896]81 return table_->getSpectrum(whichrow, poltype);
[2]82 }
[527]83 // std::string getPolarizationLabel(bool linear, bool stokes, bool linPol, int polIdx) const {
84 // Boost fails with 4 arguments.
[902]85 std::string getPolarizationLabel(int index, const std::string& ptype) const {
86 return table_->getPolarizationLabel(index, ptype);
[494]87 }
[527]88
[896]89 std::vector<double> getAbcissa(int whichrow=0) const
90 { return table_->getAbcissa(whichrow); }
[41]91
[896]92 std::string getAbcissaLabel(int whichrow=0) const
93 { return table_->getAbcissaLabel(whichrow); }
[157]94
[896]95 float getTsys(int whichrow=0) const
96 { return table_->getTsys(whichrow); }
[2]97
[2161]98 std::vector<float> getTsysSpectrum(int whichrow=0) const
99 { return table_->getTsysSpectrum(whichrow); }
100
[2791]101 void setTsys(const std::vector<float>& newvals, int whichrow=-1)
102 { return table_->setTsys(newvals, whichrow); }
103
[1947]104 //std::string getTime(int whichrow=0) const
105 // { return table_->getTime(whichrow); }
106 std::string getTime(int whichrow=0, int prec = 0) const
107 { return table_->getTime(whichrow, true, casa::uInt(prec)); }
[207]108
[1350]109 double getIntTime(int whichrow=0) const
110 { return table_->getIntTime(whichrow); }
111
[1068]112 std::string getDirectionString(int whichrow=0) const
113 { return table_->getDirectionString(whichrow); }
114
[864]115 std::string getFluxUnit() const { return table_->getFluxUnit(); }
116
117 void setFluxUnit(const std::string& unit) { table_->setFluxUnit(unit); }
118
[238]119 void setInstrument(const std::string& name) {table_->setInstrument(name);}
[1189]120 void setFeedType(const std::string& ftype) {table_->setFeedType(ftype);}
[238]121
[896]122 std::vector<bool> getMask(int whichrow=0) const
123 { return table_->getMask(whichrow); }
[2]124
[1430]125 /**
[1000]126 void flag(const std::vector<bool>& msk=std::vector<bool>())
127 { table_->flag(msk); }
[1430]128 **/
[1994]129 /**
[1430]130 void flag(const std::vector<bool>& msk=std::vector<bool>(), bool unflag=false)
131 { table_->flag(msk, unflag); }
[1994]132 **/
133 void flag(int whichrow=-1, const std::vector<bool>& msk=std::vector<bool>(), bool unflag=false)
134 { table_->flag(whichrow, msk, unflag); }
[2]135
[1819]136 void flagRow(const std::vector<casa::uInt>& rows=std::vector<casa::uInt>(), bool unflag=false)
137 { table_->flagRow(rows, unflag); }
138
139 bool getFlagRow(int whichrow=0) const
140 { return table_->getFlagRow(whichrow); }
141
142 void clip(const casa::Float uthres, const casa::Float dthres, bool clipoutside=true, bool unflag=false)
143 { table_->clip(uthres, dthres, clipoutside, unflag); }
144
145 std::vector<bool> getClipMask(int whichrow, const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag) const
146 { return table_->getClipMask(whichrow, uthres, dthres, clipoutside, unflag); }
147
[896]148 std::string getSourceName(int whichrow=0) const
149 { return table_->getSourceName(whichrow); }
[794]150
[896]151 float getElevation(int whichrow=0) const
152 { return table_->getElevation(whichrow); }
[90]153
[896]154 float getAzimuth(int whichrow=0) const
155 { return table_->getAzimuth(whichrow); }
[2]156
[896]157 float getParAngle(int whichrow=0) const
158 { return table_->getParAngle(whichrow); }
[2]159
[864]160
[884]161 void setSpectrum(std::vector<float> spectrum, int whichrow=0)
162 { table_->setSpectrum(spectrum, whichrow); }
[868]163
[1111]164 std::vector<uint> getIFNos() { return table_->getIFNos(); }
[864]165 int getIF(int whichrow) const {return table_->getIF(whichrow);}
[1111]166 std::vector<uint> getBeamNos() { return table_->getBeamNos(); }
[864]167 int getBeam(int whichrow) const {return table_->getBeam(whichrow);}
[1111]168 std::vector<uint> getPolNos() { return table_->getPolNos(); }
[864]169 int getPol(int whichrow) const {return table_->getPol(whichrow);}
[2667]170 std::vector<uint> getCycleNos() { return table_->getCycleNos(); }
[868]171 int getCycle(int whichrow) const {return table_->getCycle(whichrow);}
[1111]172 std::vector<uint> getScanNos() { return table_->getScanNos(); }
[868]173 int getScan(int whichrow) const {return table_->getScan(whichrow);}
[1819]174 std::vector<uint> getMolNos() { return table_->getMolNos();}
[864]175
176 STSelector getSelection() const { return table_->getSelection(); }
[868]177 void setSelection(const STSelector& sts)
178 { return table_->setSelection(sts);}
[864]179
[896]180 std::string getPolType() const { return table_->getPolType(); }
181
[864]182 int nif(int scanno=-1) const {return table_->nif(scanno);}
183 int nbeam(int scanno=-1) const {return table_->nbeam(scanno);}
184 int npol(int scanno=-1) const {return table_->npol(scanno);}
185 int nchan(int ifno=-1) const {return table_->nchan(ifno);}
186 int nscan() const {return table_->nscan();}
187 int nrow() const {return table_->nrow();}
[902]188 int ncycle(int scanno) const {return table_->ncycle(scanno);}
[2]189
[864]190 void makePersistent(const std::string& fname)
[3052]191 {
192 GILHandler scopedRelease;
193 table_->makePersistent(fname);
194 }
[90]195
[1068]196 void setSourceType(int stype)
197 { table_->setSourceType(stype); }
198
[2818]199 void setSourceName(const std::string& name)
200 { table_->setSourceName(name); }
201
[1360]202 void shift(int npix)
203 { table_->shift(npix); }
204
[1819]205/**
206 commented out by TT
[1170]207 void setRestFrequencies(double rf, const std::string& name,
208 const std::string& unit)
209 { table_->setRestFrequencies(rf, name, unit); }
[1819]210**/
211 void setRestFrequencies(vector<double> rf, const vector<std::string>& name,
212 const std::string& unit)
213 { table_->setRestFrequencies(rf, name, unit); }
214
[925]215/*
[868]216 void setRestFrequencies(const std::string& name) {
217 table_->setRestFrequencies(name);
[847]218 }
[925]219*/
[745]220
[1819]221/*
[864]222 std::vector<double> getRestFrequencies() const
223 { return table_->getRestFrequencies(); }
[1819]224*/
225 std::vector<double> getRestFrequency(int id) const
226 { return table_->getRestFrequency(id); }
[251]227
[105]228 void setCoordInfo(std::vector<string> theinfo) {
229 table_->setCoordInfo(theinfo);
230 }
231 std::vector<string> getCoordInfo() const {
232 return table_->getCoordInfo();
233 }
[90]234
[987]235 void setDirection(const std::string& refstr="")
236 { table_->setDirectionRefString(refstr); }
237
[847]238 casa::CountedPtr<Scantable> getCP() const {return table_;}
239 Scantable* getPtr() {return &(*table_);}
[380]240
[2286]241 // std::string summary() const {
242 // return table_->summary();
243 // }
244 void summary(const std::string& filename="") {
[2290]245 //std::string summary(const std::string& filename="") const {
246 table_->summary(filename);
[380]247 }
[745]248
[2178]249 std::string listHeader() const {
[2163]250 return table_->headerSummary();
[2111]251 }
252
[2820]253 std::vector<std::string> getHistory(int nrow=-1, int start=0) const
254 { return table_->getHistory(nrow, start); }
[207]255
[2820]256 uint historyLength() {
257 return table_->historyLength();
258 }
259
260 void dropHistory() { table_->dropHistory(); }
261
[864]262 void addHistory(const std::string& hist)
263 { table_->addHistory(hist); }
[745]264
[972]265 void addFit(const STFitEntry& fit, int row)
266 { table_->addFit(fit, row); }
267
268 STFitEntry getFit(int whichrow) const
269 { return table_->getFit(whichrow); }
270
[2012]271 void calculateAZEL() { table_->calculateAZEL(); }
[465]272
[1003]273 std::vector<std::string> columnNames() const
274 { return table_->columnNames(); }
275
[1391]276 std::string getAntennaName() const
277 { return table_->getAntennaName(); }
278
279 int checkScanInfo(const vector<int>& scanlist) const
280 { return table_->checkScanInfo(scanlist); }
[1819]281
[1730]282 std::vector<double> getDirectionVector(int whichrow) const
[1391]283 { return table_->getDirectionVector(whichrow); }
284
[1586]285 void parallactify(bool flag)
286 { table_->parallactify(flag); }
287
[1598]288 STCoordinate getCoordinate(int row) {
289 return STCoordinate(table_->getSpectralCoordinate(row));
290 }
291
[1730]292 std::vector<float> getWeather(int whichrow) const
293 { return table_->getWeather(whichrow); }
294
[1819]295 void reshapeSpectrum( int nmin, int nmax )
296 { table_->reshapeSpectrum( nmin, nmax ); }
297
[2435]298 void regridSpecChannel( double dnu, int nchan )
299 { table_->regridSpecChannel( dnu, nchan ); }
300
[2811]301 std::vector<std::string> applyBaselineTable(const std::string& bltable, const bool returnfitresult, const std::string& outbltable, const bool outbltableexists, const bool overwrite)
[3046]302 {
303 GILHandler scopedRelease;
304 return table_->applyBaselineTable(bltable, returnfitresult, outbltable, outbltableexists, overwrite);
305 }
[2811]306 std::vector<std::string> subBaseline(const std::vector<std::string>& blinfo, const bool returnfitresult, const std::string& outbltable, const bool outbltableexists, const bool overwrite)
[3046]307 {
308 GILHandler scopedRelease;
309 return table_->subBaseline(blinfo, returnfitresult, outbltable, outbltableexists, overwrite);
310 }
[2767]311 void polyBaseline(const std::vector<bool>& mask, int order, float clipthresh, int clipniter, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="")
312 { table_->polyBaseline(mask, order, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); }
[1907]313
[2767]314 void autoPolyBaseline(const std::vector<bool>& mask, int order, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="")
315 { table_->autoPolyBaseline(mask, order, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); }
[1907]316
[2767]317 void chebyshevBaseline(const std::vector<bool>& mask, int order, float clipthresh, int clipniter, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="")
318 { table_->chebyshevBaseline(mask, order, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); }
[2645]319
[2767]320 void autoChebyshevBaseline(const std::vector<bool>& mask, int order, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="")
321 { table_->autoChebyshevBaseline(mask, order, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); }
[2645]322
[2767]323 void cubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="")
324 { table_->cubicSplineBaseline(mask, npiece, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); }
[2012]325
[2767]326 void autoCubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="")
327 { table_->autoCubicSplineBaseline(mask, npiece, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); }
[2012]328
[2767]329 void sinusoidBaseline(const std::vector<bool>& mask, const std::string& fftinfo, const std::vector<int>& addwn, const std::vector<int>& rejwn, float clipthresh, int clipniter, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="")
330 { table_->sinusoidBaseline(mask, fftinfo, addwn, rejwn, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); }
[2047]331
[2767]332 void autoSinusoidBaseline(const std::vector<bool>& mask, const std::string& fftinfo, const std::vector<int>& addwn, const std::vector<int>& rejwn, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="")
333 { table_->autoSinusoidBaseline(mask, fftinfo, addwn, rejwn, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); }
[2047]334
[2012]335 float getRms(const std::vector<bool>& mask, int whichrow)
336 { return table_->getRms(mask, whichrow); }
337
[2641]338 std::string formatBaselineParams(const std::vector<float>& params, const std::vector<bool>& fixed, float rms, const std::string& masklist, int whichrow, bool verbose=false, bool csvformat=false)
339 { return table_->formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, verbose, csvformat); }
[2012]340
[2641]341 std::string formatPiecewiseBaselineParams(const std::vector<int>& ranges, const std::vector<float>& params, const std::vector<bool>& fixed, float rms, const std::string& masklist, int whichrow, bool verbose=false, bool csvformat=false)
342 { return table_->formatPiecewiseBaselineParams(ranges, params, fixed, rms, -1, masklist, whichrow, verbose, csvformat); }
[2012]343
[2831]344 bool isAllChannelsFlagged(int whichrow=0) const
345 { return table_->isAllChannelsFlagged(casa::uInt(whichrow)); }
[1907]346
[2186]347 std::vector<float> execFFT(int whichrow, const std::vector<bool>& mask, bool getRealImag=false, bool getAmplitudeOnly=false)
348 { return table_->execFFT(whichrow, mask, getRealImag, getAmplitudeOnly); }
[1907]349
[2591]350 std::vector<uint> getMoleculeIdColumnData() const
351 { return table_->getMoleculeIdColumnData(); }
352 void setMoleculeIdColumnData(const std::vector<uint>& molids)
353 { table_->setMoleculeIdColumnData(molids); }
[2888]354
355 std::vector<uint> getRootTableRowNumbers() const
356 { return table_->getRootTableRowNumbers(); }
357
[2713]358 double calculateModelSelectionCriteria(const std::string& valname, const std::string& blfunc, int order, const std::vector<bool>& inMask, int whichrow, bool useLineFinder, const std::vector<int>& edge, float threshold, int chanAvgLimit)
359 { return table_->calculateModelSelectionCriteria(valname, blfunc, order, inMask, whichrow, useLineFinder, edge, threshold, chanAvgLimit); }
[2012]360
[2789]361 void dropXPol() { table_->dropXPol(); }
362
[2]363private:
[847]364 casa::CountedPtr<Scantable> table_;
[2]365};
366
367} // namespace
368#endif
Note: See TracBrowser for help on using the repository browser.