source: trunk/src/Scantable.h @ 2767

Last change on this file since 2767 was 2767, checked in by WataruKawasaki, 11 years ago

New Development: Yes

JIRA Issue: Yes CAS-4794

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sd

Description: functions to apply/write STBaselineTable in which baseline parameters stored.


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