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 "SDDefs.h" |
---|
39 | |
---|
40 | class casa::Table; |
---|
41 | |
---|
42 | namespace asap { |
---|
43 | |
---|
44 | class SDMemTable; |
---|
45 | |
---|
46 | class SDMath { |
---|
47 | |
---|
48 | public: |
---|
49 | |
---|
50 | // Default constructor |
---|
51 | SDMath(); |
---|
52 | |
---|
53 | // Copy Constructor (copy semantics) |
---|
54 | SDMath (const SDMath& other); |
---|
55 | |
---|
56 | // Assignment (copy semantics) |
---|
57 | SDMath &operator=(const SDMath& other); |
---|
58 | |
---|
59 | // Destructor |
---|
60 | ~SDMath(); |
---|
61 | |
---|
62 | // Quotient |
---|
63 | casa::CountedPtr<SDMemTable> quotient(const casa::CountedPtr<SDMemTable>& on, |
---|
64 | const casa::CountedPtr<SDMemTable>& off, |
---|
65 | casa::Bool preserveContinuum=casa::True) const; |
---|
66 | |
---|
67 | // Simple binary Table operators. add, subtract, multiply, divide (what=0,1,2,3) |
---|
68 | casa::CountedPtr<SDMemTable> simpleBinaryOperate (const casa::CountedPtr<SDMemTable>& left, |
---|
69 | const casa::CountedPtr<SDMemTable>& right, |
---|
70 | const casa::String& op) const; |
---|
71 | |
---|
72 | // Average in time |
---|
73 | casa::CountedPtr<SDMemTable> average(const casa::Block<casa::CountedPtr<SDMemTable> >& in, |
---|
74 | const casa::Vector<casa::Bool>& mask, |
---|
75 | casa::Bool scanAverage, |
---|
76 | const casa::String& weightStr) const; |
---|
77 | // casa::Bool alignVelocity) const; |
---|
78 | |
---|
79 | // Statistics. If row<0, all rows are done otherwise, just the |
---|
80 | // specified row. |
---|
81 | std::vector<float> statistic(const casa::CountedPtr<SDMemTable>& in, |
---|
82 | const casa::Vector<casa::Bool>& mask, |
---|
83 | const casa::String& which, casa::Int row) const; |
---|
84 | |
---|
85 | // Bin up spectra |
---|
86 | SDMemTable* bin(const SDMemTable& in, casa::Int width) const; |
---|
87 | |
---|
88 | // Smooth |
---|
89 | SDMemTable* smooth (const SDMemTable& in, const casa::String& kernel, |
---|
90 | casa::Float width, casa::Bool doAll) const; |
---|
91 | |
---|
92 | // Flux conversion between Jansky and Kelvin |
---|
93 | SDMemTable* convertFlux (const SDMemTable& in, casa::Float area, |
---|
94 | casa::Float eta, casa::Bool doAll) const; |
---|
95 | |
---|
96 | // Gain-elevation correction |
---|
97 | SDMemTable* gainElevation (const SDMemTable& in, const casa::Vector<casa::Float>& coeffs, |
---|
98 | const casa::String& fileName, |
---|
99 | const casa::String& method, casa::Bool doAll) const; |
---|
100 | |
---|
101 | // Opacity correction |
---|
102 | SDMemTable* opacity (const SDMemTable& in, casa::Float tau, casa::Bool doAll) const; |
---|
103 | |
---|
104 | // Simple mathematical operations. what=0 (mul) or 1 (add) |
---|
105 | SDMemTable* simpleOperate(const SDMemTable& in, casa::Float offset, |
---|
106 | casa::Bool doAll, casa::uInt what) const; |
---|
107 | |
---|
108 | // Average polarizations |
---|
109 | SDMemTable* averagePol(const SDMemTable& in, const casa::Vector<casa::Bool>& mask) const; |
---|
110 | |
---|
111 | private: |
---|
112 | |
---|
113 | // Weighting type for time averaging |
---|
114 | |
---|
115 | enum WeightType {NONE,VAR,TSYS}; |
---|
116 | |
---|
117 | // Function to use accumulate data during time averaging |
---|
118 | |
---|
119 | void accumulate (casa::Double& timeSum, casa::Double& intSum, casa::Int& nAccum, |
---|
120 | casa::MaskedArray<casa::Float>& sum, casa::Array<casa::Float>& sumSq, |
---|
121 | casa::Array<casa::Float>& nPts, casa::Array<casa::Float>& tSysSum, |
---|
122 | const casa::Array<casa::Float>& tSys, const casa::Array<casa::Float>& nInc, |
---|
123 | const casa::Vector<casa::Bool>& mask, casa::Double time, casa::Double interval, |
---|
124 | const casa::Block<casa::CountedPtr<SDMemTable> >& in, |
---|
125 | casa::uInt iTab, casa::uInt iRow, casa::uInt axis, casa::uInt nAxesSub, |
---|
126 | casa::Bool useMask, WeightType wtType) const; |
---|
127 | |
---|
128 | // Function to fill Scan Container when averaging in time |
---|
129 | |
---|
130 | void fillSDC (SDContainer& sc, const casa::Array<casa::Bool>& mask, |
---|
131 | const casa::Array<casa::Float>& data, |
---|
132 | const casa::Array<casa::Float>& tSys, |
---|
133 | casa::Int scanID, casa::Double timeStamp, |
---|
134 | casa::Double interval, const casa::String& sourceName, |
---|
135 | const casa::Vector<casa::uInt>& freqID) const; |
---|
136 | |
---|
137 | // Put the data and mask into the SDContainer |
---|
138 | void putDataInSDC (SDContainer& sc, const casa::Array<casa::Float>& data, |
---|
139 | const casa::Array<casa::Bool>& mask) const; |
---|
140 | |
---|
141 | // Function to normalize data when averaging in time |
---|
142 | |
---|
143 | void normalize (casa::MaskedArray<casa::Float>& data, |
---|
144 | const casa::Array<casa::Float>& sumSq, |
---|
145 | const casa::Array<casa::Float>& nPts, |
---|
146 | WeightType wtType, casa::Int axis, casa::Int nAxes) const; |
---|
147 | |
---|
148 | // Function to get the current cursor location |
---|
149 | void getCursorLocation (casa::IPosition& start, casa::IPosition& end, |
---|
150 | const SDMemTable& in) const; |
---|
151 | |
---|
152 | // Convert weight string to enum value |
---|
153 | |
---|
154 | void convertWeightString (WeightType& wt, const casa::String& weightStr) const; |
---|
155 | |
---|
156 | // Convert interpolation type string |
---|
157 | void convertInterpString(casa::Int& type, const casa::String& interp) const; |
---|
158 | |
---|
159 | // Correct data from an ascii Table |
---|
160 | void correctFromAsciiTable(SDMemTable* pTabOut, const SDMemTable& in, |
---|
161 | const casa::String& fileName, |
---|
162 | const casa::String& col0, const casa::String& col1, |
---|
163 | const casa::String& methodStr, casa::Bool doAll, |
---|
164 | const casa::Vector<casa::Float>& xOut) const; |
---|
165 | |
---|
166 | // Correct data from a Table |
---|
167 | void correctFromTable(SDMemTable* pTabOut, const SDMemTable& in, const casa::Table& tTable, |
---|
168 | const casa::String& col0, const casa::String& col1, |
---|
169 | const casa::String& methodStr, casa::Bool doAll, |
---|
170 | const casa::Vector<casa::Float>& xOut) const; |
---|
171 | |
---|
172 | // Correct data from a Vector |
---|
173 | void correctFromVector (SDMemTable* pTabOut, const SDMemTable& in, |
---|
174 | casa::Bool doAll, const casa::Vector<casa::Float>& factor) const; |
---|
175 | |
---|
176 | |
---|
177 | |
---|
178 | // Read ascii file into a Table |
---|
179 | |
---|
180 | casa::Table readAsciiFile (const casa::String& fileName) const; |
---|
181 | }; |
---|
182 | |
---|
183 | } // namespace |
---|
184 | |
---|
185 | #endif |
---|