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
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#include <map>
22// AIPS++
23#include <casa/aips.h>
24#include <casa/Arrays/MaskedArray.h>
25#include <casa/Arrays/Vector.h>
26#include <casa/BasicSL/String.h>
27#include <casa/Containers/Record.h>
28#include <casa/Exceptions/Error.h>
29#include <casa/Quanta/Quantum.h>
30#include <casa/Utilities/CountedPtr.h>
31#include <coordinates/Coordinates/SpectralCoordinate.h>
32#include <measures/TableMeasures/ScalarMeasColumn.h>
33#include <scimath/Mathematics/FFTServer.h>
34#include <tables/Tables/ArrayColumn.h>
35#include <tables/Tables/ScalarColumn.h>
36#include <tables/Tables/Table.h>
37
38#include "MathUtils.h"
39#include "STBaselineEnum.h"
40#include "STFit.h"
41#include "STFitEntry.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;
55struct STLineFinder;
56class STBaselineTable;
57
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*/
76class Scantable
77{
78
79friend class STMath;
80
81public:
82  /**
83   * Default constructor
84   */
85  explicit Scantable(casa::Table::TableType ttype = casa::Table::Memory);
86
87  /**
88   * Create a Scantable object from an existing table on disk
89   * @param[in] name the name of the existing Scantable
90   */
91  explicit Scantable(const std::string& name,
92                     casa::Table::TableType ttype = casa::Table::Memory);
93
94  /// @fixme this is only sensible for MemoryTables....
95  Scantable(const Scantable& other, bool clear=true);
96
97  /**
98   * Destructor
99   */
100  virtual ~Scantable();
101
102  /**
103   * get a const reference to the underlying casa::Table
104   * @return const \ref casa::Table reference
105   */
106  const casa::Table& table() const;
107
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();
114
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   */
126  void setSelection(const STSelector& selection);
127
128  /**
129   * unset the selection of the data
130   */
131  void unsetSelection();
132  /**
133   * set the header
134   * @param[in] sth an STHeader object
135   */
136  void setHeader( const STHeader& sth );
137
138  /**
139   * get the header information
140   * @return an STHeader object
141   */
142  STHeader getHeader( ) const;
143
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);
151
152  /**
153   *
154   * @param stype The type of the source, 0 = on, 1 = off
155   */
156  void setSourceType(int stype);
157
158  /**
159   *
160   * @param stype The name of the source
161   */
162  void setSourceName(const std::string& name);
163
164
165  /**
166   * The number of scans in the table
167   * @return number of scans in the table
168   */
169  int nscan() const;
170
171  casa::MEpoch::Types getTimeReference() const;
172
173
174  casa::MEpoch getEpoch(int whichrow) const;
175
176  /**
177   * Get global antenna position
178   * @return casa::MPosition
179   */
180  casa::MPosition getAntennaPosition() const;
181
182  /**
183   * the @ref casa::MDirection for a specific row
184   * @param[in] whichrow the row number
185   * return casa::MDirection
186   */
187  casa::MDirection getDirection( int whichrow ) const;
188
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   */
194  std::string getDirectionString( int whichrow ) const;
195
196  /**
197   * set the direction type as a string, e.g. "J2000"
198   * @param[in] refstr the direction type
199   */
200  void setDirectionRefString(const std::string& refstr="");
201
202  /**
203   * get the direction reference string
204   * @return a string describing the direction reference
205   */
206  std::string getDirectionRefString() const;
207
208  /**
209   *  Return the Flux unit of the data, e.g. "Jy" or "K"
210   * @return string
211   */
212  std::string getFluxUnit() const;
213
214  /**
215   * Set the Flux unit of the data
216   * @param unit a string representing the unit, e.g "Jy" or "K"
217   */
218  void setFluxUnit( const std::string& unit );
219
220  /**
221   * Set the Stokes type of the data
222   * @param feedtype a string representing the type, e.g "circular" or "linear"
223   */
224  void setFeedType( const std::string& feedtype );
225
226  /**
227   *
228   * @param instrument a string representing an insturment. see xxx
229   */
230  void setInstrument( const std::string& instrument );
231
232  /**
233   * (Re)calculate the azimuth and elevationnfor all rows
234   */
235  void calculateAZEL();
236
237  /**
238   * "hard" flag the data, this flags everything selected in setSelection()
239   * param[in] msk a boolean mask of length nchan describing the points to
240   * to be flagged
241   */
242  //void flag( const std::vector<bool>& msk = std::vector<bool>());
243  //void flag( const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
244
245  void flag( int whichrow = -1, const std::vector<bool>& msk = std::vector<bool>(), bool unflag=false);
246
247  /**
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  /**
275   * Return a list of row numbers with respect to the original table.
276   * @return a list of unsigned ints
277   */
278  std::vector<unsigned int> rownumbers() const;
279
280
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   */
287  int nbeam(int scanno=-1) const;
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   */
294  int nif(int scanno=-1) const;
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   */
301  int npol(int scanno=-1) const;
302
303  std::string getPolType() const;
304
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.
310   * @return the number of rows (for the specified scanno)
311   */
312  int nrow(int scanno=-1) const;
313
314  int getBeam(int whichrow) const;
315  std::vector<uint> getBeamNos() const { return getNumbers(beamCol_); }
316
317  int getIF(int whichrow) const;
318  std::vector<uint> getIFNos() const { return getNumbers(ifCol_); }
319
320  int getPol(int whichrow) const;
321  std::vector<uint> getPolNos() const { return getNumbers(polCol_); }
322
323  std::vector<uint> getScanNos() const { return getNumbers(scanCol_); }
324  int getScan(int whichrow) const { return scanCol_(whichrow); }
325
326  std::vector<uint> getCycleNos() const { return getNumbers(cycleCol_); }
327  int getCycle(int whichrow) const { return cycleCol_(whichrow); }
328
329  //TT addition
330  std::vector<uint> getMolNos() {return getNumbers(mmolidCol_); }
331
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;
340  int getChannels(int whichrow) const;
341
342  int ncycle(int scanno=-1) const;
343
344
345  double getInterval(int whichrow) const
346    { return integrCol_(whichrow); }
347
348  float getTsys(int whichrow) const
349    { return casa::Vector<casa::Float>(tsysCol_(whichrow))(0); }
350  std::vector<float> getTsysSpectrum(int whichrow) const ;
351 
352  void setTsys(const std::vector<float>& newvals, int whichrow);
353
354  float getElevation(int whichrow) const
355    { return elCol_(whichrow); }
356  float getAzimuth(int whichrow) const
357    { return azCol_(whichrow); }
358  float getParAngle(int whichrow) const
359    { return focus().getParAngle(mfocusidCol_(whichrow)); }
360  int getTcalId(int whichrow) const
361    { return mtcalidCol_(whichrow); }
362
363  std::string getSourceName(int whichrow) const
364    { return srcnCol_(whichrow); }
365
366  std::vector<bool> getMask(int whichrow) const;
367  std::vector<float> getSpectrum(int whichrow,
368                                 const std::string& poltype = "" ) const;
369
370  void setSpectrum(const std::vector<float>& spec, int whichrow);
371
372  std::string getPolarizationLabel(int index, const std::string& ptype) const
373    { return STPol::getPolLabel(index, ptype ); }
374
375  /**
376   * Write the Scantable to disk
377   * @param filename the output file name
378   */
379  void makePersistent(const std::string& filename);
380
381  std::vector<std::string> getHistory(int nrow=-1, int start=0) const
382    { return historyTable_.getHistory(nrow, start); }
383
384  uint historyLength()
385  { return historyTable_.nrow(); }
386 
387  void dropHistory() { historyTable_.drop(); }
388
389  void addHistory(const std::string& hist) { historyTable_.addEntry(hist); }
390
391  void appendToHistoryTable(const STHistory& otherhist)
392    { historyTable_.append(otherhist); }
393
394  std::string headerSummary();
395  void summary(const std::string& filename="");
396  std::string oldheaderSummary();
397  //  std::string summary();
398  void oldsummary(const std::string& filename="");
399
400  //std::string getTime(int whichrow=-1, bool showdate=true) const;
401  std::string getTime(int whichrow=-1, bool showdate=true,
402                      casa::uInt prec=0) const;
403  double getIntTime(int whichrow) const { return integrCol_(whichrow); }
404
405  // returns unit, conversion frame, doppler, base-frame
406
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
418
419  std::vector<double> getAbcissa(int whichrow) const;
420
421  std::vector<float> getWeather(int whichrow) const;
422
423  std::string getAbcissaLabel(int whichrow) const;
424  std::vector<double> getRestFrequencies() const
425    { return moleculeTable_.getRestFrequencies(); }
426  std::vector<double> getRestFrequency(int id) const
427    { return moleculeTable_.getRestFrequency(id); }
428
429  /**
430  void setRestFrequencies(double rf, const std::string& name = "",
431                          const std::string& = "Hz");
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");
441
442  //void setRestFrequencies(const std::string& name);
443  void setRestFrequencies(const vector<std::string>& name);
444
445  void shift(int npix);
446
447  casa::SpectralCoordinate getSpectralCoordinate(int whichrow) const;
448
449  void convertDirection(const std::string& newframe);
450
451  STFrequencies& frequencies() { return freqTable_; }
452  const STFrequencies& frequencies() const { return freqTable_; }
453  STWeather& weather() { return weatherTable_; }
454  const STWeather& weather() const { return weatherTable_; }
455  STFocus& focus() { return focusTable_; }
456  const STFocus& focus() const { return focusTable_; }
457  STTcal& tcal() { return tcalTable_; }
458  const STTcal& tcal() const { return tcalTable_; }
459  STMolecules& molecules() { return moleculeTable_; }
460  const STMolecules& molecules() const { return moleculeTable_; }
461  STHistory& history() { return historyTable_; }
462  const STHistory& history() const { return historyTable_; }
463  STFit& fit() { return fitTable_; }
464  const STFit& fit() const { return fitTable_; }
465
466  std::vector<std::string> columnNames() const;
467
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
472  //Added by TT
473  /**
474   * Get the antenna name
475   * @return antenna name string
476   */
477  casa::String getAntennaName() const;
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
495  /**
496   * Set a flag indicating whether the data was parallactified
497   * @param[in] flag true or false
498   */
499  void parallactify(bool flag)
500    { focusTable_.setParallactify(flag); }
501
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 ) ;
521  void regridChannel( int nchan, double dnu, double fmin, int irow ) ;
522  void regridSpecChannel( double dnu, int nchan=-1 ) ;
523
524  bool isAllChannelsFlagged(casa::uInt whichrow);
525
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);
536  void polyBaseline(const std::vector<bool>& mask,
537                    int order,
538                    float thresClip,
539                    int nIterClip,
540                    bool getResidual=true,
541                    const std::string& progressInfo="true,1000",
542                    const bool outLogger=false,
543                    const std::string& blfile="",
544                    const std::string& bltable="");
545  void autoPolyBaseline(const std::vector<bool>& mask,
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="");
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,
564                         const std::string& blfile="",
565                         const std::string& bltable="");
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,
576                             const std::string& blfile="",
577                             const std::string& bltable="");
578  void cubicSplineBaseline(const std::vector<bool>& mask,
579                           int nPiece,
580                           float thresClip,
581                           int nIterClip,
582                           bool getResidual=true,
583                           const std::string& progressInfo="true,1000",
584                           const bool outLogger=false,
585                           const std::string& blfile="",
586                           const std::string& bltable="");
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,
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  void sinusoidBaseline(const std::vector<bool>& mask,
600                        const std::string& fftInfo,
601                        const std::vector<int>& addNWaves,
602                        const std::vector<int>& rejectNWaves,
603                        float thresClip,
604                        int nIterClip,
605                        bool getResidual=true,
606                        const std::string& progressInfo="true,1000",
607                        const bool outLogger=false,
608                        const std::string& blfile="",
609                        const std::string& bltable="");
610  void autoSinusoidBaseline(const std::vector<bool>& mask,
611                            const std::string& fftInfo,
612                            const std::vector<int>& addNWaves,
613                            const std::vector<int>& rejectNWaves,
614                            float thresClip,
615                            int nIterClip,
616                            const std::vector<int>& edge,
617                            float threshold=3.0,
618                            int chanAvgLimit=1,
619                            bool getResidual=true,
620                            const std::string& progressInfo="true,1000",
621                            const bool outLogger=false,
622                            const std::string& blfile="",
623                            const std::string& bltable="");
624  std::vector<float> execFFT(const int whichrow,
625                             const std::vector<bool>& inMask,
626                             bool getRealImag=false,
627                             bool getAmplitudeOnly=false);
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,
632                                   int nClipped,
633                                   const std::string& masklist,
634                                   int whichrow,
635                                   bool verbose=false,
636                                   bool csvformat=false,
637                                   int start=-1,
638                                   int count=-1,
639                                   bool resetparamid=false) const;
640  std::string formatPiecewiseBaselineParams(const std::vector<int>& ranges,
641                                            const std::vector<float>& params,
642                                            const std::vector<bool>& fixed,
643                                            float rms,
644                                            int nClipped,
645                                            const std::string& masklist,
646                                            int whichrow,
647                                            bool verbose=false,
648                                            bool csvformat=false) const;
649  std::vector<uint> getMoleculeIdColumnData() const;
650  void setMoleculeIdColumnData(const std::vector<uint>& molids);
651
652  /**
653   * Get row idx of root table
654   **/
655  std::vector<uint> getRootTableRowNumbers() const;
656
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);
666  static std::vector<bool> getMaskFromMaskList(const int nchan,
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);
674
675  void dropXPol();
676
677private:
678
679  casa::Matrix<casa::Float> getPolMatrix( casa::uInt whichrow ) const;
680
681  /**
682   * Turns a time value into a formatted string
683   * @param x
684   * @return
685   */
686  std::string formatSec(casa::Double x) const;
687
688  std::string formatTime(const casa::MEpoch& me, bool showdate)const;
689  std::string formatTime(const casa::MEpoch& me, bool showdate,
690                         casa::uInt prec)const;
691
692  /**
693   *  Turns a casa::MDirection into a nicely formatted string
694   * @param md an casa::MDirection
695   * @param prec output precision of direction
696   * @return
697   */
698  std::string formatDirection(const casa::MDirection& md, casa::Int prec=7) const;
699
700  /**
701   * Create a unique file name for the paged (temporary) table
702   * @return just the name
703   */
704  static casa::String generateName();
705
706  /**
707   * attach to cached columns
708   */
709  void attach();
710
711  /**
712   * Set up the main casa::Table
713   */
714  void setupMainTable();
715
716  void attachSubtables();
717  void copySubtables(const Scantable& other);
718
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);
725
726  std::vector<uint> getNumbers(const casa::ScalarColumn<casa::uInt>& col) const;
727
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
735  static const casa::uInt version_ = 4;
736
737  STSelector selector_;
738
739  casa::Table::TableType type_;
740
741  // the actual data
742  casa::Table table_;
743  casa::Table originalTable_;
744
745  STTcal tcalTable_;
746  STFrequencies freqTable_;
747  STWeather weatherTable_;
748  STFocus focusTable_;
749  STMolecules moleculeTable_;
750  STHistory historyTable_;
751  STFit fitTable_;
752
753  // Cached Columns to avoid reconstructing them for each row get/put
754  casa::ScalarColumn<casa::Double> integrCol_;
755  casa::MDirection::ScalarColumn dirCol_;
756  casa::MEpoch::ScalarColumn timeCol_;
757  casa::ScalarColumn<casa::Float> azCol_;
758  casa::ScalarColumn<casa::Float> elCol_;
759  casa::ScalarColumn<casa::String> srcnCol_, fldnCol_;
760  casa::ScalarColumn<casa::uInt> scanCol_, beamCol_, ifCol_, polCol_, cycleCol_, flagrowCol_;
761  casa::ScalarColumn<casa::Int> rbeamCol_, srctCol_;
762  casa::ArrayColumn<casa::Float> specCol_, tsysCol_;
763  casa::ArrayColumn<casa::uChar> flagsCol_;
764
765  // id in frequencies table
766  casa::ScalarColumn<casa::uInt> mfreqidCol_;
767  // id in tcal table
768  casa::ScalarColumn<casa::uInt> mtcalidCol_;
769
770  casa::ArrayColumn<casa::String> histitemCol_;
771  casa::ScalarColumn<casa::Int> mfitidCol_;
772  casa::ScalarColumn<casa::uInt> mweatheridCol_;
773
774  casa::ScalarColumn<casa::uInt> mfocusidCol_;
775
776  casa::ScalarColumn<casa::uInt> mmolidCol_;
777
778  static std::map<std::string, STPol::STPolFactory *> factories_;
779  void initFactories();
780
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>&);
797
798  double getNormalPolynomial(int n, double x);
799  double getChebyshevPolynomial(int n, double x);
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);
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);
824  std::vector<float> doChebyshevFitting(const std::vector<float>& data,
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,
844                                          const std::vector<std::vector<double> >& model,
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,
853                                          const std::vector<bool>& mask,
854                                          std::vector<int>& idxEdge,
855                                          std::vector<float>& params,
856                                          float& rms,
857                                          std::vector<bool>& finalMask,
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,
865                                          float& rms,
866                                          std::vector<bool>& finalMask,
867                                          float clipth,
868                                          int clipn);
869  std::vector<float> doCubicSplineFitting(const std::vector<float>& data,
870                                          const std::vector<bool>& mask,
871                                          int nPiece,
872                                          bool useGivenPieceBoundary,
873                                          std::vector<int>& idxEdge,
874                                          std::vector<float>& params,
875                                          float& rms,
876                                          std::vector<bool>& finalMask,
877                                          int& nClipped,
878                                          float thresClip=3.0,
879                                          int nIterClip=0,
880                                          bool getResidual=true);
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);
894  std::vector<float> doSinusoidFitting(const std::vector<float>& data,
895                                       const std::vector<bool>& mask,
896                                       const std::vector<int>& waveNumbers,
897                                       std::vector<float>& params,
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,
908                                       int& nClipped,
909                                       float thresClip=3.0,
910                                       int nIterClip=0,
911                                       bool getResidual=true);
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);
926  void parseFFTInfo(const std::string& fftInfo,
927                    bool& applyFFT,
928                    std::string& fftMethod,
929                    std::string& fftThresh);
930  void parseFFTThresholdInfo(const std::string& fftThresh,
931                             std::string& fftThAttr,
932                             float& fftThSigma,
933                             int& fftThTop);
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);
941  void addAuxWaveNumbers(const int whichrow,
942                         const std::vector<int>& addNWaves,
943                         const std::vector<int>& rejectNWaves,
944                         std::vector<int>& nWaves);
945  void setWaveNumberListUptoNyquistFreq(const int whichrow,
946                                        std::vector<int>& nWaves);
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);
967  bool hasSameNchanOverIFs();
968  std::string getMaskRangeList(const std::vector<bool>& mask,
969                                int whichrow,
970                                const casa::String& coordInfo,
971                                bool hasSameNchan,
972                                bool verbose=false);
973  std::vector<int> getMaskEdgeIndices(const std::vector<bool>& mask);
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;
976  std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask);
977  std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask, const std::vector<int>& edge, std::vector<int>& currEdge, STLineFinder& lineFinder);
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);
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);
982
983  void applyChanFlag( casa::uInt whichrow, const std::vector<bool>& msk, casa::uChar flagval);
984
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);
990  double doGetRms(const std::vector<bool>& mask, const casa::Vector<casa::Float>& spec);
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);
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);
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);
995
996 // storage of cubic spline model for various number of channels
997 map<size_t, vector< vector<double> > > cubicSplineModelPool_;
998
999};
1000} // namespace
1001
1002#endif
Note: See TracBrowser for help on using the repository browser.