source: trunk/src/Scantable.h @ 3090

Last change on this file since 3090 was 3090, checked in by Kana Sugimoto, 8 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: No

Module(s):

Description: yet another modification to get rid of clang build warnings.


  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 33.2 KB
RevLine 
[824]1//
2// C++ Interface: Scantable
3//
4// Description:
5//
6//
7// Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2005
8//
9// Copyright: See COPYING file that comes with this distribution
10//
11//
12#ifndef ASAPSCANTABLE_H
13#define ASAPSCANTABLE_H
[2]14
15// STL
[2186]16#include <fstream>
17#include <iostream>
18#include <sstream>
[2]19#include <string>
20#include <vector>
[3043]21#include <map>
[2]22// AIPS++
[455]23#include <casa/aips.h>
[322]24#include <casa/Arrays/MaskedArray.h>
[2186]25#include <casa/Arrays/Vector.h>
[80]26#include <casa/BasicSL/String.h>
[2186]27#include <casa/Containers/Record.h>
28#include <casa/Exceptions/Error.h>
29#include <casa/Quanta/Quantum.h>
[824]30#include <casa/Utilities/CountedPtr.h>
[2186]31#include <coordinates/Coordinates/SpectralCoordinate.h>
[824]32#include <measures/TableMeasures/ScalarMeasColumn.h>
[2186]33#include <scimath/Mathematics/FFTServer.h>
34#include <tables/Tables/ArrayColumn.h>
35#include <tables/Tables/ScalarColumn.h>
36#include <tables/Tables/Table.h>
[1819]37
[2186]38#include "MathUtils.h"
[2767]39#include "STBaselineEnum.h"
[2186]40#include "STFit.h"
41#include "STFitEntry.h"
42#include "STFocus.h"
43#include "STFrequencies.h"
[901]44#include "STHeader.h"
[2186]45#include "STHistory.h"
[824]46#include "STMolecules.h"
[2186]47#include "STPol.h"
[824]48#include "STSelector.h"
[2186]49#include "STTcal.h"
50#include "STWeather.h"
[2]51
[824]52namespace asap {
[2]53
[2666]54class Fitter;
[3090]55struct STLineFinder;
[2773]56class STBaselineTable;
[2666]57
[824]58/**
59  * This class contains and wraps a casa::Table, which is used to store
60  * all the information. This can be either a MemoryTable or a
61  * disk based Table.
62  * It provides access functions to the underlying table
63  * It contains n subtables:
64  * @li weather
65  * @li frequencies
66  * @li molecules
67  * @li tcal
68  * @li focus
69  * @li fits
70  *
71  * @brief The main ASAP data container
72  * @author Malte Marquarding
73  * @date
74  * @version
75*/
[2658]76class Scantable
[824]77{
[902]78
79friend class STMath;
80
[2]81public:
[824]82  /**
83   * Default constructor
84   */
[1350]85  explicit Scantable(casa::Table::TableType ttype = casa::Table::Memory);
[19]86
[824]87  /**
[2321]88   * Create a Scantable object from an existing table on disk
[824]89   * @param[in] name the name of the existing Scantable
90   */
[2321]91  explicit Scantable(const std::string& name,
92                     casa::Table::TableType ttype = casa::Table::Memory);
[2]93
[824]94  /// @fixme this is only sensible for MemoryTables....
95  Scantable(const Scantable& other, bool clear=true);
[161]96
[824]97  /**
98   * Destructor
99   */
100  virtual ~Scantable();
[745]101
[824]102  /**
103   * get a const reference to the underlying casa::Table
[1104]104   * @return const \ref casa::Table reference
[824]105   */
106  const casa::Table& table() const;
[19]107
[824]108  /**
109   * get a reference to the underlying casa::Table with the Selection
110   * object applied if set
111   * @return casa::Table reference
112   */
113  casa::Table& table();
[21]114
[845]115
116  /**
117   * Get a handle to the selection object
118   * @return constant STSelector reference
119   */
120  const STSelector& getSelection() const { return selector_; }
121
122  /**
123   * Set the data to be a subset as defined by the STSelector
124   * @param selection a STSelector object
125   */
[824]126  void setSelection(const STSelector& selection);
[845]127
128  /**
129   * unset the selection of the data
130   */
[824]131  void unsetSelection();
132  /**
133   * set the header
[1295]134   * @param[in] sth an STHeader object
[824]135   */
[901]136  void setHeader( const STHeader& sth );
[386]137
[824]138  /**
139   * get the header information
[901]140   * @return an STHeader object
[824]141   */
[901]142  STHeader getHeader( ) const;
[1068]143
[824]144  /**
145   * Checks if the "other" Scantable is conformant with this,
146   * i.e. if  header values are the same.
147   * @param[in] other another Scantable
148   * @return true or false
149   */
150  bool conformant( const Scantable& other);
[430]151
[824]152  /**
[1068]153   *
154   * @param stype The type of the source, 0 = on, 1 = off
155   */
156  void setSourceType(int stype);
157
[2818]158  /**
159   *
160   * @param stype The name of the source
161   */
162  void setSourceName(const std::string& name);
[1068]163
[2818]164
[1068]165  /**
[1104]166   * The number of scans in the table
[824]167   * @return number of scans in the table
168   */
[845]169  int nscan() const;
[490]170
[915]171  casa::MEpoch::Types getTimeReference() const;
[21]172
[1411]173
174  casa::MEpoch getEpoch(int whichrow) const;
175
[824]176  /**
177   * Get global antenna position
[845]178   * @return casa::MPosition
[824]179   */
180  casa::MPosition getAntennaPosition() const;
[490]181
[1441]182  /**
183   * the @ref casa::MDirection for a specific row
184   * @param[in] whichrow the row number
185   * return casa::MDirection
186   */
[987]187  casa::MDirection getDirection( int whichrow ) const;
[1598]188
[1441]189  /**
190   * get the direction type as a string, e.g. "J2000"
191   * @param[in] whichrow the row number
192   * return the direction string
193   */
[1068]194  std::string getDirectionString( int whichrow ) const;
195
[1441]196  /**
197   * set the direction type as a string, e.g. "J2000"
198   * @param[in] refstr the direction type
199   */
[987]200  void setDirectionRefString(const std::string& refstr="");
[1441]201
[1104]202  /**
203   * get the direction reference string
204   * @return a string describing the direction reference
205   */
[1598]206  std::string getDirectionRefString() const;
[987]207
[824]208  /**
[845]209   *  Return the Flux unit of the data, e.g. "Jy" or "K"
210   * @return string
[824]211   */
212  std::string getFluxUnit() const;
[472]213
[824]214  /**
[845]215   * Set the Flux unit of the data
216   * @param unit a string representing the unit, e.g "Jy" or "K"
[824]217   */
218  void setFluxUnit( const std::string& unit );
[472]219
[824]220  /**
[1189]221   * Set the Stokes type of the data
[1295]222   * @param feedtype a string representing the type, e.g "circular" or "linear"
[1189]223   */
224  void setFeedType( const std::string& feedtype );
225
226  /**
[824]227   *
[845]228   * @param instrument a string representing an insturment. see xxx
[824]229   */
230  void setInstrument( const std::string& instrument );
[2]231
[845]232  /**
233   * (Re)calculate the azimuth and elevationnfor all rows
234   */
[824]235  void calculateAZEL();
[745]236
[824]237  /**
[845]238   * "hard" flag the data, this flags everything selected in setSelection()
[1104]239   * param[in] msk a boolean mask of length nchan describing the points to
240   * to be flagged
[824]241   */
[1430]242  //void flag( const std::vector<bool>& msk = std::vector<bool>());
[1994]243  //void flag( const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
[455]244
[1994]245  void flag( int whichrow = -1, const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
246
[852]247  /**
[1819]248   * Flag the data in a row-based manner. (CAS-1433 Wataru Kawasaki)
249   * param[in] rows    list of row numbers to be flagged
250   */
251  void flagRow( const std::vector<casa::uInt>& rows = std::vector<casa::uInt>(), bool unflag=false);
252
253  /**
254   * Get flagRow info at the specified row. If true, the whole data
255   * at the row should be flagged.
256   */
257  bool getFlagRow(int whichrow) const
258    { return (flagrowCol_(whichrow) > 0); }
259
260  /**
261   * Flag the data outside a specified range (in a channel-based manner).
262   * (CAS-1807 Wataru Kawasaki)
263   */
264  void clip(const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag);
265
266  /**
267   * Return a list of booleans with the size of nchan for a specified row, to get info
268   * about which channel is clipped.
269   */
270  std::vector<bool> getClipMask(int whichrow, const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag);
271  void srchChannelsToClip(casa::uInt whichrow, const casa::Float uthres, const casa::Float dthres, bool clipoutside, bool unflag,
272                          casa::Vector<casa::uChar> flgs);
273
274  /**
[852]275   * Return a list of row numbers with respect to the original table.
[902]276   * @return a list of unsigned ints
[852]277   */
278  std::vector<unsigned int> rownumbers() const;
[845]279
[852]280
[845]281  /**
282   * Get the number of beams in the data or a specific scan
283   * @param scanno the scan number to get the number of beams for.
284   * If scanno<0 the number is retrieved from the header.
285   * @return an integer number
286   */
[824]287  int nbeam(int scanno=-1) const;
[845]288  /**
289   * Get the number of IFs in the data or a specific scan
290   * @param scanno the scan number to get the number of IFs for.
291   * If scanno<0 the number is retrieved from the header.
292   * @return an integer number
293   */
[824]294  int nif(int scanno=-1) const;
[845]295  /**
296   * Get the number of polarizations in the data or a specific scan
297   * @param scanno the scan number to get the number of polarizations for.
298   * If scanno<0 the number is retrieved from the header.
299   * @return an integer number
300   */
[824]301  int npol(int scanno=-1) const;
[794]302
[896]303  std::string getPolType() const;
304
[845]305
306  /**
307   * Get the number of integartion cycles
308   * @param scanno the scan number to get the number of rows for.
309   * If scanno<0 the number is retrieved from the header.
[1104]310   * @return the number of rows (for the specified scanno)
[845]311   */
[824]312  int nrow(int scanno=-1) const;
[794]313
[1111]314  int getBeam(int whichrow) const;
[1694]315  std::vector<uint> getBeamNos() const { return getNumbers(beamCol_); }
[50]316
[847]317  int getIF(int whichrow) const;
[1694]318  std::vector<uint> getIFNos() const { return getNumbers(ifCol_); }
[1111]319
[847]320  int getPol(int whichrow) const;
[1694]321  std::vector<uint> getPolNos() const { return getNumbers(polCol_); }
[1111]322
[1694]323  std::vector<uint> getScanNos() const { return getNumbers(scanCol_); }
[865]324  int getScan(int whichrow) const { return scanCol_(whichrow); }
[1111]325
[2667]326  std::vector<uint> getCycleNos() const { return getNumbers(cycleCol_); }
327  int getCycle(int whichrow) const { return cycleCol_(whichrow); }
328
[1819]329  //TT addition
330  std::vector<uint> getMolNos() {return getNumbers(mmolidCol_); }
331
[1111]332  /**
333   * Get the number of channels in the data or a specific IF. This currently
334   * varies only with IF number
335   * @param ifno the IF number to get the number of channels for.
336   * If ifno<0 the number is retrieved from the header.
337   * @return an integer number
338   */
339  int nchan(int ifno=-1) const;
[923]340  int getChannels(int whichrow) const;
[206]341
[1111]342  int ncycle(int scanno=-1) const;
343
[2667]344
[847]345  double getInterval(int whichrow) const
346    { return integrCol_(whichrow); }
[845]347
[865]348  float getTsys(int whichrow) const
349    { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
[2161]350  std::vector<float> getTsysSpectrum(int whichrow) const ;
[2791]351 
352  void setTsys(const std::vector<float>& newvals, int whichrow);
353
[847]354  float getElevation(int whichrow) const
355    { return elCol_(whichrow); }
356  float getAzimuth(int whichrow) const
357    { return azCol_(whichrow); }
[865]358  float getParAngle(int whichrow) const
[1819]359    { return focus().getParAngle(mfocusidCol_(whichrow)); }
360  int getTcalId(int whichrow) const
361    { return mtcalidCol_(whichrow); }
[386]362
[865]363  std::string getSourceName(int whichrow) const
364    { return srcnCol_(whichrow); }
365
[847]366  std::vector<bool> getMask(int whichrow) const;
[896]367  std::vector<float> getSpectrum(int whichrow,
[905]368                                 const std::string& poltype = "" ) const;
[847]369
[884]370  void setSpectrum(const std::vector<float>& spec, int whichrow);
371
[902]372  std::string getPolarizationLabel(int index, const std::string& ptype) const
373    { return STPol::getPolLabel(index, ptype ); }
[401]374
[845]375  /**
376   * Write the Scantable to disk
377   * @param filename the output file name
378   */
[824]379  void makePersistent(const std::string& filename);
[745]380
[2820]381  std::vector<std::string> getHistory(int nrow=-1, int start=0) const
382    { return historyTable_.getHistory(nrow, start); }
[483]383
[2820]384  uint historyLength()
385  { return historyTable_.nrow(); }
386 
387  void dropHistory() { historyTable_.drop(); }
388
[860]389  void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
[488]390
[860]391  void appendToHistoryTable(const STHistory& otherhist)
392    { historyTable_.append(otherhist); }
393
[2163]394  std::string headerSummary();
[2290]395  void summary(const std::string& filename="");
396  std::string oldheaderSummary();
[2286]397  //  std::string summary();
[2290]398  void oldsummary(const std::string& filename="");
399
[1947]400  //std::string getTime(int whichrow=-1, bool showdate=true) const;
[2818]401  std::string getTime(int whichrow=-1, bool showdate=true,
402                      casa::uInt prec=0) const;
[1350]403  double getIntTime(int whichrow) const { return integrCol_(whichrow); }
[19]404
[847]405  // returns unit, conversion frame, doppler, base-frame
[18]406
[847]407  /**
408   * Get the frequency set up
409   * This is forwarded to the STFrequencies subtable
410   * @return unit, frame, doppler
411   */
412  std::vector<std::string> getCoordInfo() const
413    { return freqTable_.getInfo(); };
414
415  void setCoordInfo(std::vector<string> theinfo)
416    { return freqTable_.setInfo(theinfo); };
417
[865]418
419  std::vector<double> getAbcissa(int whichrow) const;
420
[1730]421  std::vector<float> getWeather(int whichrow) const;
422
[847]423  std::string getAbcissaLabel(int whichrow) const;
424  std::vector<double> getRestFrequencies() const
425    { return moleculeTable_.getRestFrequencies(); }
[1819]426  std::vector<double> getRestFrequency(int id) const
427    { return moleculeTable_.getRestFrequency(id); }
[847]428
[1819]429  /**
[1170]430  void setRestFrequencies(double rf, const std::string& name = "",
431                          const std::string& = "Hz");
[1819]432  **/
433  // Modified by Takeshi Nakazato 05/09/2008
434  /***
435  void setRestFrequencies(vector<double> rf, const vector<std::string>& name = "",
436                          const std::string& = "Hz");
437  ***/
438  void setRestFrequencies(vector<double> rf,
439                          const vector<std::string>& name = vector<std::string>(1,""),
440                          const std::string& = "Hz");
[847]441
[1819]442  //void setRestFrequencies(const std::string& name);
443  void setRestFrequencies(const vector<std::string>& name);
444
[1360]445  void shift(int npix);
446
[1598]447  casa::SpectralCoordinate getSpectralCoordinate(int whichrow) const;
448
[987]449  void convertDirection(const std::string& newframe);
450
[824]451  STFrequencies& frequencies() { return freqTable_; }
[1375]452  const STFrequencies& frequencies() const { return freqTable_; }
[824]453  STWeather& weather() { return weatherTable_; }
[1375]454  const STWeather& weather() const { return weatherTable_; }
[824]455  STFocus& focus() { return focusTable_; }
[1375]456  const STFocus& focus() const { return focusTable_; }
[824]457  STTcal& tcal() { return tcalTable_; }
[1375]458  const STTcal& tcal() const { return tcalTable_; }
[824]459  STMolecules& molecules() { return moleculeTable_; }
[1375]460  const STMolecules& molecules() const { return moleculeTable_; }
[860]461  STHistory& history() { return historyTable_; }
[1375]462  const STHistory& history() const { return historyTable_; }
[972]463  STFit& fit() { return fitTable_; }
[1375]464  const STFit& fit() const { return fitTable_; }
[2]465
[902]466  std::vector<std::string> columnNames() const;
[896]467
[972]468  void addFit(const STFitEntry& fit, int row);
469  STFitEntry getFit(int row) const
470    { STFitEntry fe; fitTable_.getEntry(fe, mfitidCol_(row)); return fe; }
471
[1391]472  //Added by TT
473  /**
474   * Get the antenna name
475   * @return antenna name string
476   */
[1819]477  casa::String getAntennaName() const;
[1391]478
479  /**
480   * For GBT MS data only. check a scan list
481   * against the information found in GBT_GO table for
482   * scan number orders to get correct pairs.
483   * @param[in] scan list
484   * @return status
485   */
486  int checkScanInfo(const std::vector<int>& scanlist) const;
487
488  /**
489   * Get the direction as a vector, for a specific row
490   * @param[in] whichrow the row numbyyer
491   * @return the direction in a vector
492   */
493  std::vector<double> getDirectionVector(int whichrow) const;
494
[1586]495  /**
496   * Set a flag indicating whether the data was parallactified
497   * @param[in] flag true or false
498   */
[1598]499  void parallactify(bool flag)
[2357]500    { focusTable_.setParallactify(flag); }
[1727]501
[1819]502  /**
503   * Reshape spectrum
504   * @param[in] nmin, nmax minimum and maximum channel
505   * @param[in] irow       row number
506   *
507   * 30/07/2008 Takeshi Nakazato
508   **/
509  void reshapeSpectrum( int nmin, int nmax ) throw( casa::AipsError );
510  void reshapeSpectrum( int nmin, int nmax, int irow ) ;
511
512  /**
513   * Change channel number under fixed bandwidth
514   * @param[in] nchan, dnu new channel number and spectral resolution
515   * @param[in] irow       row number
516   *
517   * 27/08/2008 Takeshi Nakazato
518   **/
519  void regridChannel( int nchan, double dnu ) ;
520  void regridChannel( int nchan, double dnu, int irow ) ;
[2595]521  void regridChannel( int nchan, double dnu, double fmin, int irow ) ;
[2435]522  void regridSpecChannel( double dnu, int nchan=-1 ) ;
523
[2831]524  bool isAllChannelsFlagged(casa::uInt whichrow);
[1819]525
[2811]526  std::vector<std::string> applyBaselineTable(const std::string& bltable,
527                                              const bool returnfitresult,
528                                              const std::string& outbltable,
529                                              const bool outbltableexists,
530                                              const bool overwrite);
531  std::vector<std::string> subBaseline(const std::vector<std::string>& blInfoList,
532                                       const bool returnfitresult,
533                                       const std::string& outbltable,
534                                       const bool outbltableexists,
535                                       const bool overwrite);
[2767]536  void polyBaseline(const std::vector<bool>& mask,
537                    int order,
538                    float thresClip,
539                    int nIterClip,
[2094]540                    bool getResidual=true,
[2189]541                    const std::string& progressInfo="true,1000",
[2767]542                    const bool outLogger=false,
543                    const std::string& blfile="",
544                    const std::string& bltable="");
[2012]545  void autoPolyBaseline(const std::vector<bool>& mask,
[2767]546                        int order,
547                        float thresClip,
548                        int nIterClip,
549                        const std::vector<int>& edge,
550                        float threshold=3.0,
551                        int chanAvgLimit=1,
552                        bool getResidual=true,
553                        const std::string& progressInfo="true,1000",
554                        const bool outLogger=false,
555                        const std::string& blfile="",
556                        const std::string& bltable="");
[2645]557  void chebyshevBaseline(const std::vector<bool>& mask,
558                         int order,
559                         float thresClip,
560                         int nIterClip,
561                         bool getResidual=true,
562                         const std::string& progressInfo="true,1000",
563                         const bool outLogger=false,
[2767]564                         const std::string& blfile="",
565                         const std::string& bltable="");
[2645]566  void autoChebyshevBaseline(const std::vector<bool>& mask,
567                             int order,
568                             float thresClip,
569                             int nIterClip,
570                             const std::vector<int>& edge,
571                             float threshold=3.0,
572                             int chanAvgLimit=1,
573                             bool getResidual=true,
574                             const std::string& progressInfo="true,1000",
575                             const bool outLogger=false,
[2767]576                             const std::string& blfile="",
577                             const std::string& bltable="");
[2012]578  void cubicSplineBaseline(const std::vector<bool>& mask,
579                           int nPiece,
580                           float thresClip,
581                           int nIterClip,
[2094]582                           bool getResidual=true,
[2189]583                           const std::string& progressInfo="true,1000",
584                           const bool outLogger=false,
[2767]585                           const std::string& blfile="",
586                           const std::string& bltable="");
[2012]587  void autoCubicSplineBaseline(const std::vector<bool>& mask,
588                               int nPiece,
589                               float thresClip,
590                               int nIterClip,
591                               const std::vector<int>& edge,
592                               float threshold=3.0,
593                               int chanAvgLimit=1,
[2094]594                               bool getResidual=true,
[2189]595                               const std::string& progressInfo="true,1000",
596                               const bool outLogger=false,
[2767]597                               const std::string& blfile="",
598                               const std::string& bltable="");
[2047]599  void sinusoidBaseline(const std::vector<bool>& mask,
[2767]600                        const std::string& fftInfo,
[2186]601                        const std::vector<int>& addNWaves,
602                        const std::vector<int>& rejectNWaves,
[2047]603                        float thresClip,
604                        int nIterClip,
[2081]605                        bool getResidual=true,
[2189]606                        const std::string& progressInfo="true,1000",
607                        const bool outLogger=false,
[2767]608                        const std::string& blfile="",
609                        const std::string& bltable="");
[2047]610  void autoSinusoidBaseline(const std::vector<bool>& mask,
[2767]611                            const std::string& fftInfo,
[2186]612                            const std::vector<int>& addNWaves,
613                            const std::vector<int>& rejectNWaves,
[2047]614                            float thresClip,
615                            int nIterClip,
616                            const std::vector<int>& edge,
617                            float threshold=3.0,
618                            int chanAvgLimit=1,
[2081]619                            bool getResidual=true,
[2189]620                            const std::string& progressInfo="true,1000",
621                            const bool outLogger=false,
[2767]622                            const std::string& blfile="",
623                            const std::string& bltable="");
[2186]624  std::vector<float> execFFT(const int whichrow,
625                             const std::vector<bool>& inMask,
626                             bool getRealImag=false,
627                             bool getAmplitudeOnly=false);
[2012]628  float getRms(const std::vector<bool>& mask, int whichrow);
629  std::string formatBaselineParams(const std::vector<float>& params,
630                                   const std::vector<bool>& fixed,
631                                   float rms,
[2193]632                                   int nClipped,
[2012]633                                   const std::string& masklist,
634                                   int whichrow,
[2064]635                                   bool verbose=false,
[2641]636                                   bool csvformat=false,
[2064]637                                   int start=-1,
638                                   int count=-1,
639                                   bool resetparamid=false) const;
[2012]640  std::string formatPiecewiseBaselineParams(const std::vector<int>& ranges,
641                                            const std::vector<float>& params,
642                                            const std::vector<bool>& fixed,
643                                            float rms,
[2193]644                                            int nClipped,
[2012]645                                            const std::string& masklist,
646                                            int whichrow,
[2641]647                                            bool verbose=false,
648                                            bool csvformat=false) const;
[2591]649  std::vector<uint> getMoleculeIdColumnData() const;
650  void setMoleculeIdColumnData(const std::vector<uint>& molids);
[2888]651
652  /**
653   * Get row idx of root table
654   **/
655  std::vector<uint> getRootTableRowNumbers() const;
656
[2713]657  double calculateModelSelectionCriteria(const std::string& valname,
658                                         const std::string& blfunc,
659                                         int order,
660                                         const std::vector<bool>& inMask,
661                                         int whichrow,
662                                         bool useLineFinder,
663                                         const std::vector<int>& edge,
664                                         float threshold,
665                                         int chanAvgLimit);
[2767]666  static std::vector<bool> getMaskFromMaskList(const int nchan,
[2789]667                                          const std::vector<int>& masklist);
668  static casa::Vector<casa::uInt> getMaskListFromMask(
669                                           const std::vector<bool>& mask);
670  static std::vector<int> splitToIntList(const std::string& str,
671                                         const char delim);
672  static std::vector<string> splitToStringList(const std::string& str,
673                                               const char delim);
[1907]674
[2789]675  void dropXPol();
[2012]676
[824]677private:
[896]678
679  casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
680
[824]681  /**
[2005]682   * Turns a time value into a formatted string
[824]683   * @param x
684   * @return
685   */
686  std::string formatSec(casa::Double x) const;
[18]687
[824]688  std::string formatTime(const casa::MEpoch& me, bool showdate)const;
[2818]689  std::string formatTime(const casa::MEpoch& me, bool showdate,
690                         casa::uInt prec)const;
[22]691
[824]692  /**
693   *  Turns a casa::MDirection into a nicely formatted string
694   * @param md an casa::MDirection
[2969]695   * @param prec output precision of direction
[824]696   * @return
697   */
[2969]698  std::string formatDirection(const casa::MDirection& md, casa::Int prec=7) const;
[19]699
[824]700  /**
701   * Create a unique file name for the paged (temporary) table
702   * @return just the name
703   */
704  static casa::String generateName();
[286]705
[824]706  /**
707   * attach to cached columns
708   */
709  void attach();
[50]710
[824]711  /**
712   * Set up the main casa::Table
713   */
714  void setupMainTable();
[88]715
[859]716  void attachSubtables();
[865]717  void copySubtables(const Scantable& other);
718
[824]719  /**
720   * Convert an "old" asap1 style row index into a new index
721   * @param[in] therow
722   * @return and index into @table_
723   */
724  int rowToScanIndex(int therow);
[212]725
[1694]726  std::vector<uint> getNumbers(const casa::ScalarColumn<casa::uInt>& col) const;
[1111]727
[3023]728  /**
729   * Returns a number of elements with "true" in a bool vector.
730   * @param[in] mask (boolean vector)
731   * @return the numerb of elements in true
732   */
733  std::size_t nValidMask(const std::vector<bool>& mask);
734
[2321]735  static const casa::uInt version_ = 4;
[286]736
[824]737  STSelector selector_;
[236]738
[824]739  casa::Table::TableType type_;
[465]740
[824]741  // the actual data
742  casa::Table table_;
743  casa::Table originalTable_;
[745]744
[824]745  STTcal tcalTable_;
746  STFrequencies freqTable_;
747  STWeather weatherTable_;
748  STFocus focusTable_;
749  STMolecules moleculeTable_;
[860]750  STHistory historyTable_;
[960]751  STFit fitTable_;
[860]752
[824]753  // Cached Columns to avoid reconstructing them for each row get/put
[847]754  casa::ScalarColumn<casa::Double> integrCol_;
[824]755  casa::MDirection::ScalarColumn dirCol_;
[847]756  casa::MEpoch::ScalarColumn timeCol_;
[923]757  casa::ScalarColumn<casa::Float> azCol_;
758  casa::ScalarColumn<casa::Float> elCol_;
[824]759  casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
[1819]760  casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_, flagrowCol_;
[1068]761  casa::ScalarColumn<casa::Int> rbeamCol_, srctCol_;
[865]762  casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
[824]763  casa::ArrayColumn<casa::uChar> flagsCol_;
[430]764
[824]765  // id in frequencies table
766  casa::ScalarColumn<casa::uInt> mfreqidCol_;
767  // id in tcal table
768  casa::ScalarColumn<casa::uInt> mtcalidCol_;
[430]769
[824]770  casa::ArrayColumn<casa::String> histitemCol_;
[972]771  casa::ScalarColumn<casa::Int> mfitidCol_;
[824]772  casa::ScalarColumn<casa::uInt> mweatheridCol_;
[322]773
[824]774  casa::ScalarColumn<casa::uInt> mfocusidCol_;
775
776  casa::ScalarColumn<casa::uInt> mmolidCol_;
777
[896]778  static std::map<std::string, STPol::STPolFactory *> factories_;
779  void initFactories();
780
[1819]781  /**
782   * Add an auxiliary column to the main table and attach it to a
783   * cached column. Use for adding new columns that the original asap2
784   * tables do not have.
785   * @param[in] col      reference to the cached column to be attached
786   * @param[in] colName  column name in asap table
787   * @param[in] defValue default value to fill in the column
788   *
789   * 25/10/2009 Wataru Kawasaki
790   */
791  template<class T, class T2> void attachAuxColumnDef(casa::ScalarColumn<T>&,
792                                                       const casa::String&,
793                                                       const T2&);
794  template<class T, class T2> void attachAuxColumnDef(casa::ArrayColumn<T>&,
795                                                      const casa::String&,
796                                                      const casa::Array<T2>&);
[1907]797
[2767]798  double getNormalPolynomial(int n, double x);
[2645]799  double getChebyshevPolynomial(int n, double x);
[2773]800  std::vector<std::vector<double> > getPolynomialModel(int order,
801                                                       int nchan,
802                                                       double (Scantable::*pfunc)(int, double));
803  std::vector<std::vector<std::vector<double> > > getPolynomialModelReservoir(int order,
804                                                                              double (Scantable::*pfunc)(int, double),
805                                                                              std::vector<int>& nChanNos);
[2767]806  std::vector<float> doPolynomialFitting(const std::vector<float>& data,
807                                         const std::vector<bool>& mask,
808                                         int order,
809                                         std::vector<float>& params,
810                                         float& rms,
811                                         std::vector<bool>& finalMask,
812                                         float clipth,
813                                         int clipn);
814  std::vector<float> doPolynomialFitting(const std::vector<float>& data,
815                                         const std::vector<bool>& mask,
816                                         int order,
817                                         std::vector<float>& params,
818                                         float& rms,
819                                         std::vector<bool>& finalMask,
820                                         int& nClipped,
821                                         float thresClip=3.0,
822                                         int nIterClip=0,
823                                         bool getResidual=true);
[2645]824  std::vector<float> doChebyshevFitting(const std::vector<float>& data,
[2767]825                                        const std::vector<bool>& mask,
826                                        int order,
827                                        std::vector<float>& params,
828                                        float& rms,
829                                        std::vector<bool>& finalMask,
830                                        float clipth,
831                                        int clipn);
832  std::vector<float> doChebyshevFitting(const std::vector<float>& data,
833                                        const std::vector<bool>& mask,
834                                        int order,
835                                        std::vector<float>& params,
836                                        float& rms,
837                                        std::vector<bool>& finalMask,
838                                        int& nClipped,
839                                        float thresClip=3.0,
840                                        int nIterClip=0,
841                                        bool getResidual=true);
842  std::vector<float> doLeastSquareFitting(const std::vector<float>& data,
843                                          const std::vector<bool>& mask,
[2773]844                                          const std::vector<std::vector<double> >& model,
[2767]845                                          std::vector<float>& params,
846                                          float& rms,
847                                          std::vector<bool>& finalMask,
848                                          int& nClipped,
849                                          float thresClip=3.0,
850                                          int nIterClip=0,
851                                          bool getResidual=true);
852  std::vector<float> doCubicSplineFitting(const std::vector<float>& data,
[2645]853                                          const std::vector<bool>& mask,
[2767]854                                          std::vector<int>& idxEdge,
[2645]855                                          std::vector<float>& params,
[2767]856                                          float& rms,
[2737]857                                          std::vector<bool>& finalMask,
[2767]858                                          float clipth,
859                                          int clipn);
860  std::vector<float> doCubicSplineFitting(const std::vector<float>& data,
861                                          const std::vector<bool>& mask,
862                                          int nPiece,
863                                          std::vector<int>& idxEdge,
864                                          std::vector<float>& params,
[2737]865                                          float& rms,
[2767]866                                          std::vector<bool>& finalMask,
867                                          float clipth,
868                                          int clipn);
[2012]869  std::vector<float> doCubicSplineFitting(const std::vector<float>& data,
870                                          const std::vector<bool>& mask,
[2081]871                                          int nPiece,
[2767]872                                          bool useGivenPieceBoundary,
[2064]873                                          std::vector<int>& idxEdge,
[2012]874                                          std::vector<float>& params,
[2767]875                                          float& rms,
876                                          std::vector<bool>& finalMask,
[2193]877                                          int& nClipped,
[2012]878                                          float thresClip=3.0,
[2767]879                                          int nIterClip=0,
[2094]880                                          bool getResidual=true);
[2773]881  std::vector<float> doCubicSplineLeastSquareFitting(const std::vector<float>& data,
882                                                     const std::vector<bool>& mask,
883                                                     const std::vector<std::vector<double> >& model,
884                                                     int nPiece,
885                                                     bool useGivenPieceBoundary,
886                                                     std::vector<int>& idxEdge,
887                                                     std::vector<float>& params,
888                                                     float& rms,
889                                                     std::vector<bool>& finalMask,
890                                                     int& nClipped,
891                                                     float thresClip=3.0,
892                                                     int nIterClip=0,
893                                                     bool getResidual=true);
[2047]894  std::vector<float> doSinusoidFitting(const std::vector<float>& data,
895                                       const std::vector<bool>& mask,
[2081]896                                       const std::vector<int>& waveNumbers,
[2047]897                                       std::vector<float>& params,
[2767]898                                       float& rms,
899                                       std::vector<bool>& finalMask,
900                                       float clipth,
901                                       int clipn);
902  std::vector<float> doSinusoidFitting(const std::vector<float>& data,
903                                       const std::vector<bool>& mask,
904                                       const std::vector<int>& waveNumbers,
905                                       std::vector<float>& params,
906                                       float& rms,
907                                       std::vector<bool>& finalMask,
[2193]908                                       int& nClipped,
[2047]909                                       float thresClip=3.0,
[2767]910                                       int nIterClip=0,
[2094]911                                       bool getResidual=true);
[2773]912  std::vector<std::vector<double> > getSinusoidModel(const std::vector<int>& waveNumbers, int nchan);
913  std::vector<std::vector<std::vector<double> > > getSinusoidModelReservoir(const std::vector<int>& waveNumbers,
914                                                                            std::vector<int>& nChanNos);
915  std::vector<int> selectWaveNumbers(const std::vector<int>& addNWaves,
916                                     const std::vector<int>& rejectNWaves);
917  std::vector<int> selectWaveNumbers(const int whichrow,
918                                     const std::vector<bool>& chanMask,
919                                     //const std::string& fftInfo,
920                                     const bool applyFFT,
921                                     const std::string& fftMethod,
922                                     const std::string& fftThresh,
923                                     const std::vector<int>& addNWaves,
924                                     const std::vector<int>& rejectNWaves);
925  int getIdxOfNchan(const int nChan, const std::vector<int>& nChanNos);
[2767]926  void parseFFTInfo(const std::string& fftInfo,
927                    bool& applyFFT,
928                    std::string& fftMethod,
929                    std::string& fftThresh);
[2773]930  void parseFFTThresholdInfo(const std::string& fftThresh,
931                             std::string& fftThAttr,
932                             float& fftThSigma,
933                             int& fftThTop);
[2186]934  void doSelectWaveNumbers(const int whichrow,
935                           const std::vector<bool>& chanMask,
936                           const std::string& fftMethod,
937                           const float fftThSigma,
938                           const int fftThTop,
939                           const std::string& fftThAttr,
940                           std::vector<int>& nWaves);
[2411]941  void addAuxWaveNumbers(const int whichrow,
942                         const std::vector<int>& addNWaves,
[2186]943                         const std::vector<int>& rejectNWaves,
944                         std::vector<int>& nWaves);
[2411]945  void setWaveNumberListUptoNyquistFreq(const int whichrow,
946                                        std::vector<int>& nWaves);
[2773]947  void initialiseBaselining(const std::string& blfile,
948                            std::ofstream& ofs,
949                            const bool outLogger,
950                            bool& outTextFile,
951                            bool& csvFormat,
952                            casa::String& coordInfo,
953                            bool& hasSameNchan,
954                            const std::string& progressInfo,
955                            bool& showProgress,
956                            int& minNRow,
957                            casa::Vector<casa::Double>& timeSecCol);
958  void finaliseBaselining(const bool outBaselineTable,
959                          STBaselineTable* pbt,
960                          const string& bltable,
961                          const bool outTextFile,
962                          std::ofstream& ofs);
963  void initLineFinder(const std::vector<int>& edge,
964                      const float threshold,
965                      const int chanAvgLimit,
966                      STLineFinder& lineFinder);
[2012]967  bool hasSameNchanOverIFs();
968  std::string getMaskRangeList(const std::vector<bool>& mask,
969                                int whichrow,
970                                const casa::String& coordInfo,
[2047]971                                bool hasSameNchan,
972                                bool verbose=false);
973  std::vector<int> getMaskEdgeIndices(const std::vector<bool>& mask);
[2641]974  std::string formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const;
975  std::string formatBaselineParamsFooter(float rms, int nClipped, bool verbose, bool csvformat) const;
[2012]976  std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask);
[2773]977  std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask, const std::vector<int>& edge, std::vector<int>& currEdge, STLineFinder& lineFinder);
[2641]978  void outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<int>& edge, const std::vector<float>& params, const int nClipped);
979  void outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<float>& params, const int nClipped);
[2189]980  void parseProgressInfo(const std::string& progressInfo, bool& showProgress, int& minNRow);
981  void showProgressOnTerminal(const int nProcessed, const int nTotal, const bool showProgress=true, const int nTotalThreshold=1000);
[1994]982
983  void applyChanFlag( casa::uInt whichrow, const std::vector<bool>& msk, casa::uChar flagval);
984
[2713]985  double doCalculateModelSelectionCriteria(const std::string& valname,
986                                           const std::vector<float>& spec,
987                                           const std::vector<bool>& mask,
988                                           const std::string& blfunc,
989                                           int order);
[2737]990  double doGetRms(const std::vector<bool>& mask, const casa::Vector<casa::Float>& spec);
[2767]991  std::string packFittingResults(const int irow, const std::vector<float>& params, const float rms);
992  void parseBlInfo(const std::string& blInfo, int& whichrow, STBaselineFunc::FuncName& ftype, std::vector<int>& fpar, std::vector<bool>& mask, float& thresClip, int& nIterClip, bool& useLineFinder, float& thresLF, std::vector<int>& edgeLF, int& avgLF);
[3048]993  std::vector<float> doApplyBaselineTable(std::vector<float>& spec, std::vector<bool>& mask, const STBaselineFunc::FuncName ftype, std::vector<int>& fpar, std::vector<float>& params, float&rms, int irow);
[2767]994 std::vector<float> doSubtractBaseline(std::vector<float>& spec, std::vector<bool>& mask, const STBaselineFunc::FuncName ftype, std::vector<int>& fpar, std::vector<float>& params, float&rms, std::vector<bool>& finalmask, float clipth, int clipn, bool uself, int irow, float lfth, std::vector<int>& lfedge, int lfavg);
[2713]995
[3043]996 // storage of cubic spline model for various number of channels
997 map<size_t, vector< vector<double> > > cubicSplineModelPool_;
998
[2]999};
[824]1000} // namespace
1001
[2]1002#endif
Note: See TracBrowser for help on using the repository browser.