source: trunk/src/SDMath.h @ 317

Last change on this file since 317 was 317, checked in by kil064, 19 years ago

add interpolatiun method argument to function 'frequencyAlign'

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.2 KB
Line 
1//#---------------------------------------------------------------------------
2//# SDMath.h: A collection of single dish mathematical operations
3//#---------------------------------------------------------------------------
4//# Copyright (C) 2004
5//# ATNF
6//#
7//# This program is free software; you can redistribute it and/or modify it
8//# under the terms of the GNU General Public License as published by the Free
9//# Software Foundation; either version 2 of the License, or (at your option)
10//# any later version.
11//#
12//# This program is distributed in the hope that it will be useful, but
13//# WITHOUT ANY WARRANTY; without even the implied warranty of
14//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15//# Public License for more details.
16//#
17//# You should have received a copy of the GNU General Public License along
18//# with this program; if not, write to the Free Software Foundation, Inc.,
19//# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
20//#
21//# Correspondence concerning this software should be addressed as follows:
22//#        Internet email: Malte.Marquarding@csiro.au
23//#        Postal address: Malte Marquarding,
24//#                        Australia Telescope National Facility,
25//#                        P.O. Box 76,
26//#                        Epping, NSW, 2121,
27//#                        AUSTRALIA
28//#
29//# $Id:
30//#---------------------------------------------------------------------------
31#ifndef SDMATH_H
32#define SDMATH_H
33
34#include <string>
35#include <vector>
36#include <casa/aips.h>
37#include <casa/Utilities/CountedPtr.h>
38#include <coordinates/Coordinates/FrequencyAligner.h>
39
40#include "SDDefs.h"
41
42class casa::Table;
43class casa::MEpoch;
44class casa::MPosition;
45template<class T> class casa::PtrBlock;
46
47
48namespace asap {
49
50class SDMemTable;
51
52class SDMath {
53
54 public:
55
56// Default constructor
57   SDMath();
58
59// Copy Constructor (copy semantics)
60   SDMath (const SDMath& other);
61
62// Assignment  (copy semantics)
63   SDMath &operator=(const SDMath& other);
64
65// Destructor
66   ~SDMath();
67
68// Binary Table operators. op=ADD, SUB, MUL, DIV, QUOTIENT
69   casa::CountedPtr<SDMemTable> binaryOperate (const casa::CountedPtr<SDMemTable>& left,
70                                               const casa::CountedPtr<SDMemTable>& right,
71                                               const casa::String& op, casa::Bool preserve,
72                                               casa::Bool tSys) const;
73
74// Average in time
75   casa::CountedPtr<SDMemTable>  average(const casa::Block<casa::CountedPtr<SDMemTable> >& in,
76                                         const casa::Vector<casa::Bool>& mask,
77                                         casa::Bool scanAverage,
78                                         const casa::String& weightStr,
79                                         casa::Bool align=casa::False) const;
80
81// Statistics. If row<0, all rows are done otherwise, just the
82// specified row.
83   std::vector<float> statistic(const casa::CountedPtr<SDMemTable>& in,
84                                const casa::Vector<casa::Bool>& mask,
85                                const casa::String& which, casa::Int row) const;
86
87// Bin up spectra
88   SDMemTable* bin(const SDMemTable& in, casa::Int width) const;
89
90// Resample spectra
91   SDMemTable* resample(const SDMemTable& in, const casa::String& method,
92                        casa::Float factor) const;
93
94// Smooth
95   SDMemTable* smooth (const SDMemTable& in, const casa::String& kernel,
96                       casa::Float width, casa::Bool doAll) const;
97
98// Flux conversion between Jansky and Kelvin
99   SDMemTable* convertFlux (const SDMemTable& in, casa::Float area,
100                            casa::Float eta, casa::Bool doAll) const;
101
102// Gain-elevation correction
103   SDMemTable* gainElevation (const SDMemTable& in, const casa::Vector<casa::Float>& coeffs,
104                              const casa::String& fileName,
105                              const casa::String& method, casa::Bool doAll) const;
106
107// Frequency Alignment
108   SDMemTable* frequencyAlignment (const SDMemTable& in, const casa::String& refTime,
109                                   const casa::String& method) const;
110
111// Opacity correction
112   SDMemTable* opacity (const SDMemTable& in, casa::Float tau, casa::Bool doAll) const;
113
114// Simple unary mathematical operations.  what=0 (mul) or 1 (add)
115   SDMemTable* unaryOperate(const SDMemTable& in, casa::Float offset,
116                            casa::Bool doAll, casa::uInt what, casa::Bool tSys) const;
117
118// Average polarizations
119   SDMemTable* averagePol(const SDMemTable& in, const casa::Vector<casa::Bool>& mask,
120                          const casa::String& wtStr) const;
121
122 private:
123
124// Weighting type for time averaging
125
126  enum WeightType {NONE,VAR,TSYS};
127
128// Function to use accumulate data during time averaging
129
130  void accumulate (casa::Double& timeSum, casa::Double& intSum, casa::Int& nAccum,
131                   casa::MaskedArray<casa::Float>& sum, casa::Array<casa::Float>& sumSq,
132                   casa::Array<casa::Float>& nPts, casa::Array<casa::Float>& tSysSum,
133                   const casa::Array<casa::Float>& tSys,  const casa::Array<casa::Float>& nInc,
134                   const casa::Vector<casa::Bool>& mask, casa::Double time, casa::Double interval,
135                   const casa::Block<casa::CountedPtr<SDMemTable> >& in,
136                   casa::uInt iTab, casa::uInt iRow, casa::uInt axis, casa::uInt nAxesSub,
137                   casa::Bool useMask, WeightType wtType) const;
138
139// Function to fill Scan Container when averaging in time
140
141  void fillSDC (SDContainer& sc, const casa::Array<casa::Bool>& mask,
142                const casa::Array<casa::Float>& data,
143                const casa::Array<casa::Float>& tSys,
144                casa::Int scanID, casa::Double timeStamp,
145                casa::Double interval, const casa::String& sourceName,
146                const casa::Vector<casa::uInt>& freqID) const;
147
148// Put the data and mask into the SDContainer
149   void putDataInSDC (SDContainer& sc, const casa::Array<casa::Float>& data,
150                      const casa::Array<casa::Bool>& mask) const;
151
152// Function to normalize data when averaging in time
153
154  void normalize (casa::MaskedArray<casa::Float>& data,
155                  const casa::Array<casa::Float>& sumSq,
156                  const casa::Array<casa::Float>& nPts,
157                  WeightType wtType, casa::Int axis, casa::Int nAxes) const;
158
159// Function to get the current cursor location
160   void getCursorLocation (casa::IPosition& start, casa::IPosition& end,
161                           const SDMemTable& in) const;
162
163// Convert weight string to enum value
164
165   void convertWeightString (WeightType& wt, const casa::String& weightStr) const;
166
167// Convert interpolation type string
168//   void convertInterpString(casa::Int& type, const casa::String& interp) const;
169   void convertInterpString(casa::InterpolateArray1D<casa::Double,casa::Float>::InterpolationMethod& method, 
170                             const casa::String& interp) const;
171
172// Correct data from an ascii Table
173   void correctFromAsciiTable(SDMemTable* pTabOut, const SDMemTable& in,
174                              const casa::String& fileName,
175                              const casa::String& col0, const casa::String& col1,
176                              const casa::String& methodStr, casa::Bool doAll,
177                              const casa::Vector<casa::Float>& xOut) const;
178
179// Correct data from a Table
180   void correctFromTable(SDMemTable* pTabOut, const SDMemTable& in, const casa::Table& tTable,
181                         const casa::String& col0, const casa::String& col1,
182                         const casa::String& methodStr, casa::Bool doAll,
183                         const casa::Vector<casa::Float>& xOut) const;
184
185// Correct data from a Vector
186   void correctFromVector (SDMemTable* pTabOut, const SDMemTable& in,
187                           casa::Bool doAll, const casa::Vector<casa::Float>& factor) const;
188
189// Read ascii file into a Table
190
191   casa::Table readAsciiFile (const casa::String& fileName) const;
192
193// Generate source table
194   void generateSourceTable (casa::Vector<casa::String>& srcTab,
195                             casa::Vector<casa::uInt>& srcIdx,
196                             casa::Vector<casa::uInt>& firstRow,
197                             const casa::Vector<casa::String>& srcNames) const;
198
199// Generate frequency aligners
200   void generateFrequencyAligners (casa::PtrBlock<casa::FrequencyAligner<casa::Float>* >& a,
201                                   const SDMemTable& in, casa::uInt nChan,
202                                   casa::uInt nFreqIDs, casa::uInt nSrcTab,
203                                   const casa::Vector<casa::uInt>& firstRow,
204                                   casa::MFrequency::Types system,
205                                   const casa::MPosition& refPos,
206                                   const casa::MEpoch& refEpoch) const;
207
208// Align in Frequency
209   SDMemTable* frequencyAlign (const SDMemTable& in,
210                              casa::MFrequency::Types system,
211                              const casa::String& timeRef,
212                              const casa::String& method) const;
213
214// Convert time String to Epoch
215   casa::MEpoch epochFromString (const casa::String& str, casa::MEpoch::Types timeRef) const;
216
217// Format EPoch
218   casa::String formatEpoch(const casa::MEpoch& epoch)  const;
219};
220
221} // namespace
222
223#endif
Note: See TracBrowser for help on using the repository browser.