source: trunk/src/Scantable.h@ 2786

Last change on this file since 2786 was 2773, checked in by WataruKawasaki, 12 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: Yes

Module(s): sd

Description: optimisation/refactoring the baselining functions for scantable.


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