source: trunk/src/Scantable.h @ 2888

Last change on this file since 2888 was 2888, checked in by Kana Sugimoto, 10 years ago

New Development: Yes

JIRA Issue: Yes (CAS-5860)

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: Added scantable a method, asap.scantable.._get_root_row_idx(), and underlying c++ functions, ScantableWrapper:::getRootTableRowNumbers() and Scantable:::getRootTableRowNumbers()

Test Programs: TBD

Put in Release Notes: No

Module(s): asap.scantable and CASA task, tsdstat

Description:

Added a scantable method, asap.scantable._get_root_row_idx().
The method returns row indices (uint std::vecotr) in the root table for selected rows of scantable.


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