source: trunk/src/Scantable.h @ 2818

Last change on this file since 2818 was 2818, checked in by Malte Marquarding, 11 years ago

Issue #291: added scantable.set_sourcename to overwrite sourcename to allow freq_align to work. Exposed 'SOURCE' averaging to python api. Added some logging to freq_align refering to the sources it aligns to

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