source: trunk/src/ScantableWrapper.h@ 3072

Last change on this file since 3072 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
Line 
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
14
15#include <iostream>
16#include <string>
17#include <vector>
18
19#include <casa/Arrays/Vector.h>
20
21#include "MathUtils.h"
22#include "Scantable.h"
23#include "STCoordinate.h"
24#include "STFit.h"
25#include "STFitEntry.h"
26#include "GILHandler.h"
27
28namespace asap {
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 {
41
42public:
43 explicit ScantableWrapper( const std::string& name,
44 int type=0)
45 {
46 GILHandler scopedRelease;
47 casa::Table::TableType tp = casa::Table::Memory;
48 if ( type == 1 ) tp = casa::Table::Plain;
49 table_ = new Scantable(name, tp);
50 }
51
52 explicit ScantableWrapper(int type=0)
53 {
54 GILHandler scopedRelease;
55 casa::Table::TableType tp = casa::Table::Memory;
56 if ( type == 1) tp = casa::Table::Plain;
57 table_= new Scantable(tp);
58 }
59
60 explicit ScantableWrapper(casa::CountedPtr<Scantable> cp) : table_(cp) {;}
61
62 ScantableWrapper(const ScantableWrapper& mt) :
63 table_(mt.getCP()) {;}
64
65 ~ScantableWrapper()
66 {
67 GILHandler scopedRelease;
68 table_.reset();
69 }
70
71 void assign(const ScantableWrapper& mt)
72 { table_= mt.getCP(); }
73
74 ScantableWrapper copy() {
75 GILHandler scopedRelease;
76 return ScantableWrapper(new Scantable(*(this->getCP()), false));
77 }
78
79 std::vector<float> getSpectrum( int whichrow=0,
80 const std::string& poltype="" ) const {
81 return table_->getSpectrum(whichrow, poltype);
82 }
83 // std::string getPolarizationLabel(bool linear, bool stokes, bool linPol, int polIdx) const {
84 // Boost fails with 4 arguments.
85 std::string getPolarizationLabel(int index, const std::string& ptype) const {
86 return table_->getPolarizationLabel(index, ptype);
87 }
88
89 std::vector<double> getAbcissa(int whichrow=0) const
90 { return table_->getAbcissa(whichrow); }
91
92 std::string getAbcissaLabel(int whichrow=0) const
93 { return table_->getAbcissaLabel(whichrow); }
94
95 float getTsys(int whichrow=0) const
96 { return table_->getTsys(whichrow); }
97
98 std::vector<float> getTsysSpectrum(int whichrow=0) const
99 { return table_->getTsysSpectrum(whichrow); }
100
101 void setTsys(const std::vector<float>& newvals, int whichrow=-1)
102 { return table_->setTsys(newvals, whichrow); }
103
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)); }
108
109 double getIntTime(int whichrow=0) const
110 { return table_->getIntTime(whichrow); }
111
112 std::string getDirectionString(int whichrow=0) const
113 { return table_->getDirectionString(whichrow); }
114
115 std::string getFluxUnit() const { return table_->getFluxUnit(); }
116
117 void setFluxUnit(const std::string& unit) { table_->setFluxUnit(unit); }
118
119 void setInstrument(const std::string& name) {table_->setInstrument(name);}
120 void setFeedType(const std::string& ftype) {table_->setFeedType(ftype);}
121
122 std::vector<bool> getMask(int whichrow=0) const
123 { return table_->getMask(whichrow); }
124
125 /**
126 void flag(const std::vector<bool>& msk=std::vector<bool>())
127 { table_->flag(msk); }
128 **/
129 /**
130 void flag(const std::vector<bool>& msk=std::vector<bool>(), bool unflag=false)
131 { table_->flag(msk, unflag); }
132 **/
133 void flag(int whichrow=-1, const std::vector<bool>& msk=std::vector<bool>(), bool unflag=false)
134 { table_->flag(whichrow, msk, unflag); }
135
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
148 std::string getSourceName(int whichrow=0) const
149 { return table_->getSourceName(whichrow); }
150
151 float getElevation(int whichrow=0) const
152 { return table_->getElevation(whichrow); }
153
154 float getAzimuth(int whichrow=0) const
155 { return table_->getAzimuth(whichrow); }
156
157 float getParAngle(int whichrow=0) const
158 { return table_->getParAngle(whichrow); }
159
160
161 void setSpectrum(std::vector<float> spectrum, int whichrow=0)
162 { table_->setSpectrum(spectrum, whichrow); }
163
164 std::vector<uint> getIFNos() { return table_->getIFNos(); }
165 int getIF(int whichrow) const {return table_->getIF(whichrow);}
166 std::vector<uint> getBeamNos() { return table_->getBeamNos(); }
167 int getBeam(int whichrow) const {return table_->getBeam(whichrow);}
168 std::vector<uint> getPolNos() { return table_->getPolNos(); }
169 int getPol(int whichrow) const {return table_->getPol(whichrow);}
170 std::vector<uint> getCycleNos() { return table_->getCycleNos(); }
171 int getCycle(int whichrow) const {return table_->getCycle(whichrow);}
172 std::vector<uint> getScanNos() { return table_->getScanNos(); }
173 int getScan(int whichrow) const {return table_->getScan(whichrow);}
174 std::vector<uint> getMolNos() { return table_->getMolNos();}
175
176 STSelector getSelection() const { return table_->getSelection(); }
177 void setSelection(const STSelector& sts)
178 { return table_->setSelection(sts);}
179
180 std::string getPolType() const { return table_->getPolType(); }
181
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();}
188 int ncycle(int scanno) const {return table_->ncycle(scanno);}
189
190 void makePersistent(const std::string& fname)
191 {
192 GILHandler scopedRelease;
193 table_->makePersistent(fname);
194 }
195
196 void setSourceType(int stype)
197 { table_->setSourceType(stype); }
198
199 void setSourceName(const std::string& name)
200 { table_->setSourceName(name); }
201
202 void shift(int npix)
203 { table_->shift(npix); }
204
205/**
206 commented out by TT
207 void setRestFrequencies(double rf, const std::string& name,
208 const std::string& unit)
209 { table_->setRestFrequencies(rf, name, unit); }
210**/
211 void setRestFrequencies(vector<double> rf, const vector<std::string>& name,
212 const std::string& unit)
213 { table_->setRestFrequencies(rf, name, unit); }
214
215/*
216 void setRestFrequencies(const std::string& name) {
217 table_->setRestFrequencies(name);
218 }
219*/
220
221/*
222 std::vector<double> getRestFrequencies() const
223 { return table_->getRestFrequencies(); }
224*/
225 std::vector<double> getRestFrequency(int id) const
226 { return table_->getRestFrequency(id); }
227
228 void setCoordInfo(std::vector<string> theinfo) {
229 table_->setCoordInfo(theinfo);
230 }
231 std::vector<string> getCoordInfo() const {
232 return table_->getCoordInfo();
233 }
234
235 void setDirection(const std::string& refstr="")
236 { table_->setDirectionRefString(refstr); }
237
238 casa::CountedPtr<Scantable> getCP() const {return table_;}
239 Scantable* getPtr() {return &(*table_);}
240
241 // std::string summary() const {
242 // return table_->summary();
243 // }
244 void summary(const std::string& filename="") {
245 //std::string summary(const std::string& filename="") const {
246 table_->summary(filename);
247 }
248
249 std::string listHeader() const {
250 return table_->headerSummary();
251 }
252
253 std::vector<std::string> getHistory(int nrow=-1, int start=0) const
254 { return table_->getHistory(nrow, start); }
255
256 uint historyLength() {
257 return table_->historyLength();
258 }
259
260 void dropHistory() { table_->dropHistory(); }
261
262 void addHistory(const std::string& hist)
263 { table_->addHistory(hist); }
264
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
271 void calculateAZEL() { table_->calculateAZEL(); }
272
273 std::vector<std::string> columnNames() const
274 { return table_->columnNames(); }
275
276 std::string getAntennaName() const
277 { return table_->getAntennaName(); }
278
279 int checkScanInfo(const vector<int>& scanlist) const
280 { return table_->checkScanInfo(scanlist); }
281
282 std::vector<double> getDirectionVector(int whichrow) const
283 { return table_->getDirectionVector(whichrow); }
284
285 void parallactify(bool flag)
286 { table_->parallactify(flag); }
287
288 STCoordinate getCoordinate(int row) {
289 return STCoordinate(table_->getSpectralCoordinate(row));
290 }
291
292 std::vector<float> getWeather(int whichrow) const
293 { return table_->getWeather(whichrow); }
294
295 void reshapeSpectrum( int nmin, int nmax )
296 { table_->reshapeSpectrum( nmin, nmax ); }
297
298 void regridSpecChannel( double dnu, int nchan )
299 { table_->regridSpecChannel( dnu, nchan ); }
300
301 std::vector<std::string> applyBaselineTable(const std::string& bltable, const bool returnfitresult, const std::string& outbltable, const bool outbltableexists, const bool overwrite)
302 {
303 GILHandler scopedRelease;
304 return table_->applyBaselineTable(bltable, returnfitresult, outbltable, outbltableexists, overwrite);
305 }
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)
307 {
308 GILHandler scopedRelease;
309 return table_->subBaseline(blinfo, returnfitresult, outbltable, outbltableexists, overwrite);
310 }
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); }
313
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); }
316
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); }
319
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); }
322
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); }
325
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); }
328
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); }
331
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); }
334
335 float getRms(const std::vector<bool>& mask, int whichrow)
336 { return table_->getRms(mask, whichrow); }
337
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); }
340
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); }
343
344 bool isAllChannelsFlagged(int whichrow=0) const
345 { return table_->isAllChannelsFlagged(casa::uInt(whichrow)); }
346
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); }
349
350 std::vector<uint> getMoleculeIdColumnData() const
351 { return table_->getMoleculeIdColumnData(); }
352 void setMoleculeIdColumnData(const std::vector<uint>& molids)
353 { table_->setMoleculeIdColumnData(molids); }
354
355 std::vector<uint> getRootTableRowNumbers() const
356 { return table_->getRootTableRowNumbers(); }
357
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); }
360
361 void dropXPol() { table_->dropXPol(); }
362
363private:
364 casa::CountedPtr<Scantable> table_;
365};
366
367} // namespace
368#endif
Note: See TracBrowser for help on using the repository browser.