source: trunk/src/ScantableWrapper.h @ 3046

Last change on this file since 3046 was 3046, 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:


Release GIL in some time-consuming functions. Currently the following functions releases GIL:


  • MSFiller::fill
  • MSWriter::write
  • Scantable::applyBaselineTable
  • Scantable::subBaseline
  • CalibrationManager::calibrate
  • CalibrationManager::apply
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 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    casa::Table::TableType tp = casa::Table::Memory;
47    if ( type == 1 ) tp = casa::Table::Plain;
48    table_ = new Scantable(name, tp);
49  }
50
51  explicit ScantableWrapper(int type=0)
52  {
53    casa::Table::TableType tp = casa::Table::Memory;
54    if ( type == 1) tp = casa::Table::Plain;
55    table_= new Scantable(tp);
56  }
57
58  explicit ScantableWrapper(casa::CountedPtr<Scantable> cp) : table_(cp) {;}
59
60  ScantableWrapper(const ScantableWrapper& mt) :
61    table_(mt.getCP()) {;}
62
63  ~ScantableWrapper()
64  {
65  }
66
67  void assign(const ScantableWrapper& mt)
68    { table_= mt.getCP(); }
69
70  ScantableWrapper copy() {
71    return ScantableWrapper(new Scantable(*(this->getCP()), false));
72  }
73
74  std::vector<float> getSpectrum( int whichrow=0,
75                                  const std::string& poltype="" ) const {
76    return table_->getSpectrum(whichrow, poltype);
77  }
78  //  std::string getPolarizationLabel(bool linear, bool stokes, bool linPol, int polIdx) const {
79  // Boost fails with 4 arguments.
80  std::string getPolarizationLabel(int index, const std::string& ptype) const {
81    return table_->getPolarizationLabel(index, ptype);
82  }
83
84  std::vector<double> getAbcissa(int whichrow=0) const
85    { return table_->getAbcissa(whichrow); }
86
87  std::string getAbcissaLabel(int whichrow=0) const
88    { return table_->getAbcissaLabel(whichrow); }
89
90  float getTsys(int whichrow=0) const
91    { return table_->getTsys(whichrow); }
92
93  std::vector<float> getTsysSpectrum(int whichrow=0) const
94    { return table_->getTsysSpectrum(whichrow); }
95
96  void setTsys(const std::vector<float>& newvals, int whichrow=-1)
97  { return table_->setTsys(newvals, whichrow); }
98
99  //std::string getTime(int whichrow=0) const
100  //  { return table_->getTime(whichrow); }
101  std::string getTime(int whichrow=0, int prec = 0) const
102    { return table_->getTime(whichrow, true, casa::uInt(prec)); }
103
104  double getIntTime(int whichrow=0) const
105    { return table_->getIntTime(whichrow); }
106
107  std::string getDirectionString(int whichrow=0) const
108    { return table_->getDirectionString(whichrow); }
109
110  std::string getFluxUnit() const { return table_->getFluxUnit(); }
111
112  void setFluxUnit(const std::string& unit) { table_->setFluxUnit(unit); }
113
114  void setInstrument(const std::string& name) {table_->setInstrument(name);}
115  void setFeedType(const std::string& ftype) {table_->setFeedType(ftype);}
116
117  std::vector<bool> getMask(int whichrow=0) const
118    { return table_->getMask(whichrow); }
119
120  /**
121  void flag(const std::vector<bool>& msk=std::vector<bool>())
122    { table_->flag(msk); }
123  **/
124  /**
125  void flag(const std::vector<bool>& msk=std::vector<bool>(), bool unflag=false)
126    { table_->flag(msk, unflag); }
127  **/
128  void flag(int whichrow=-1, const std::vector<bool>& msk=std::vector<bool>(), bool unflag=false)
129    { table_->flag(whichrow, msk, unflag); }
130
131  void flagRow(const std::vector<casa::uInt>& rows=std::vector<casa::uInt>(), bool unflag=false)
132    { table_->flagRow(rows, unflag); }
133
134  bool getFlagRow(int whichrow=0) const
135    { return table_->getFlagRow(whichrow); }
136
137  void clip(const casa::Float uthres, const casa::Float dthres, bool clipoutside=true, bool unflag=false)
138    { table_->clip(uthres, dthres, clipoutside, unflag); }
139
140  std::vector<bool> getClipMask(int whichrow, const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag) const
141    { return table_->getClipMask(whichrow, uthres, dthres, clipoutside, unflag); }
142
143  std::string getSourceName(int whichrow=0) const
144    { return table_->getSourceName(whichrow); }
145
146  float getElevation(int whichrow=0) const
147    { return table_->getElevation(whichrow); }
148
149  float getAzimuth(int whichrow=0) const
150    { return table_->getAzimuth(whichrow); }
151
152  float getParAngle(int whichrow=0) const
153    { return table_->getParAngle(whichrow); }
154
155
156  void setSpectrum(std::vector<float> spectrum, int whichrow=0)
157    { table_->setSpectrum(spectrum, whichrow); }
158
159  std::vector<uint> getIFNos() { return table_->getIFNos(); }
160  int getIF(int whichrow) const {return table_->getIF(whichrow);}
161  std::vector<uint> getBeamNos() { return table_->getBeamNos(); }
162  int getBeam(int whichrow) const {return table_->getBeam(whichrow);}
163  std::vector<uint> getPolNos() { return table_->getPolNos(); }
164  int getPol(int whichrow) const {return table_->getPol(whichrow);}
165  std::vector<uint> getCycleNos() { return table_->getCycleNos(); }
166  int getCycle(int whichrow) const {return table_->getCycle(whichrow);}
167  std::vector<uint> getScanNos() { return table_->getScanNos(); }
168  int getScan(int whichrow) const {return table_->getScan(whichrow);}
169  std::vector<uint> getMolNos() { return table_->getMolNos();}
170
171  STSelector getSelection() const { return table_->getSelection(); }
172  void setSelection(const STSelector& sts)
173    { return table_->setSelection(sts);}
174
175  std::string getPolType() const { return table_->getPolType(); }
176
177  int nif(int scanno=-1) const {return table_->nif(scanno);}
178  int nbeam(int scanno=-1) const {return table_->nbeam(scanno);}
179  int npol(int scanno=-1) const {return table_->npol(scanno);}
180  int nchan(int ifno=-1) const {return table_->nchan(ifno);}
181  int nscan() const {return table_->nscan();}
182  int nrow() const {return table_->nrow();}
183  int ncycle(int scanno) const {return table_->ncycle(scanno);}
184
185  void makePersistent(const std::string& fname)
186    { table_->makePersistent(fname); }
187
188  void setSourceType(int stype)
189    { table_->setSourceType(stype); }
190
191  void setSourceName(const std::string& name)
192    { table_->setSourceName(name); }
193
194  void shift(int npix)
195  { table_->shift(npix); }
196
197/**
198  commented out by TT
199  void setRestFrequencies(double rf, const std::string& name,
200                          const std::string& unit)
201    { table_->setRestFrequencies(rf, name, unit); }
202**/
203  void setRestFrequencies(vector<double> rf, const vector<std::string>& name,
204                          const std::string& unit)
205    { table_->setRestFrequencies(rf, name, unit); }
206
207/*
208  void setRestFrequencies(const std::string& name) {
209    table_->setRestFrequencies(name);
210  }
211*/
212
213/*
214  std::vector<double> getRestFrequencies() const
215    { return table_->getRestFrequencies(); }
216*/
217  std::vector<double> getRestFrequency(int id) const
218    { return table_->getRestFrequency(id); }
219
220  void setCoordInfo(std::vector<string> theinfo) {
221    table_->setCoordInfo(theinfo);
222  }
223  std::vector<string> getCoordInfo() const {
224    return table_->getCoordInfo();
225  }
226
227  void setDirection(const std::string& refstr="")
228    { table_->setDirectionRefString(refstr); }
229
230  casa::CountedPtr<Scantable> getCP() const {return table_;}
231  Scantable* getPtr() {return &(*table_);}
232
233  //  std::string summary() const {
234  //  return table_->summary();
235  //  }
236  void summary(const std::string& filename="") {
237    //std::string summary(const std::string& filename="") const {
238    table_->summary(filename);
239  }
240
241  std::string listHeader() const {
242    return table_->headerSummary();
243  }
244
245  std::vector<std::string> getHistory(int nrow=-1, int start=0) const
246    { return table_->getHistory(nrow, start); }
247
248  uint historyLength() {
249    return table_->historyLength();
250  }
251
252  void dropHistory() { table_->dropHistory(); }
253
254  void addHistory(const std::string& hist)
255    { table_->addHistory(hist); }
256
257  void addFit(const STFitEntry& fit, int row)
258    { table_->addFit(fit, row); }
259
260  STFitEntry getFit(int whichrow) const
261  { return table_->getFit(whichrow); }
262
263  void calculateAZEL() { table_->calculateAZEL(); }
264
265  std::vector<std::string> columnNames() const
266    { return table_->columnNames(); }
267
268  std::string getAntennaName() const
269    { return table_->getAntennaName(); }
270
271  int checkScanInfo(const vector<int>& scanlist) const
272    { return table_->checkScanInfo(scanlist); }
273 
274  std::vector<double> getDirectionVector(int whichrow) const
275    { return table_->getDirectionVector(whichrow); }
276
277  void parallactify(bool flag)
278    { table_->parallactify(flag); }
279
280  STCoordinate getCoordinate(int row) {
281    return STCoordinate(table_->getSpectralCoordinate(row));
282  }
283
284  std::vector<float> getWeather(int whichrow) const
285    { return table_->getWeather(whichrow); }
286
287  void reshapeSpectrum( int nmin, int nmax )
288  { table_->reshapeSpectrum( nmin, nmax ); }
289
290  void regridSpecChannel( double dnu, int nchan )
291  { table_->regridSpecChannel( dnu, nchan ); }
292
293  std::vector<std::string> applyBaselineTable(const std::string& bltable, const bool returnfitresult, const std::string& outbltable, const bool outbltableexists, const bool overwrite)
294  {
295    GILHandler scopedRelease;
296    return table_->applyBaselineTable(bltable, returnfitresult, outbltable, outbltableexists, overwrite);
297  }
298  std::vector<std::string> subBaseline(const std::vector<std::string>& blinfo, const bool returnfitresult, const std::string& outbltable, const bool outbltableexists, const bool overwrite)
299  {
300    GILHandler scopedRelease;
301    return table_->subBaseline(blinfo, returnfitresult, outbltable, outbltableexists, overwrite);
302  }
303  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="")
304  { table_->polyBaseline(mask, order, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); }
305
306  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="")
307  { table_->autoPolyBaseline(mask, order, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); }
308
309  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="")
310  { table_->chebyshevBaseline(mask, order, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); }
311
312  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="")
313  { table_->autoChebyshevBaseline(mask, order, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); }
314
315  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="")
316  { table_->cubicSplineBaseline(mask, npiece, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); }
317
318  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="")
319  { table_->autoCubicSplineBaseline(mask, npiece, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); }
320
321  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="")
322  { table_->sinusoidBaseline(mask, fftinfo, addwn, rejwn, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); }
323
324  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="")
325  { table_->autoSinusoidBaseline(mask, fftinfo, addwn, rejwn, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); }
326
327  float getRms(const std::vector<bool>& mask, int whichrow)
328  { return table_->getRms(mask, whichrow); }
329
330  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)
331  { return table_->formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, verbose, csvformat); }
332
333  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)
334  { return table_->formatPiecewiseBaselineParams(ranges, params, fixed, rms, -1, masklist, whichrow, verbose, csvformat); }
335
336  bool isAllChannelsFlagged(int whichrow=0) const
337  { return table_->isAllChannelsFlagged(casa::uInt(whichrow)); }
338
339  std::vector<float> execFFT(int whichrow, const std::vector<bool>& mask, bool getRealImag=false, bool getAmplitudeOnly=false)
340  { return table_->execFFT(whichrow, mask, getRealImag, getAmplitudeOnly); }
341
342  std::vector<uint> getMoleculeIdColumnData() const
343  { return table_->getMoleculeIdColumnData(); }
344  void setMoleculeIdColumnData(const std::vector<uint>& molids)
345  { table_->setMoleculeIdColumnData(molids); }
346
347  std::vector<uint> getRootTableRowNumbers() const
348  { return table_->getRootTableRowNumbers(); }
349
350  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)
351  { return table_->calculateModelSelectionCriteria(valname, blfunc, order, inMask, whichrow, useLineFinder, edge, threshold, chanAvgLimit); }
352
353  void dropXPol() { table_->dropXPol(); }
354
355private:
356  casa::CountedPtr<Scantable> table_;
357};
358
359} // namespace
360#endif
Note: See TracBrowser for help on using the repository browser.