1 | //#---------------------------------------------------------------------------
|
---|
2 | //# SDMathWrapper.cc: Wrapper classes to use CountedPtr
|
---|
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 |
|
---|
32 |
|
---|
33 | #include "SDMathWrapper.h"
|
---|
34 | #include "SDMath.h"
|
---|
35 |
|
---|
36 |
|
---|
37 | using namespace asap;
|
---|
38 | using namespace casa;
|
---|
39 |
|
---|
40 | SDMemTableWrapper SDMathWrapper::quotient(const SDMemTableWrapper& on,
|
---|
41 | const SDMemTableWrapper& off,
|
---|
42 | Bool preserveContinuum)
|
---|
43 | {
|
---|
44 | SDMath sdm;
|
---|
45 | Bool doTSys = True;
|
---|
46 | return SDMemTableWrapper(sdm.binaryOperate(on.getCP(), off.getCP(),
|
---|
47 | String("QUOTIENT"), preserveContinuum, doTSys));
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | SDMemTableWrapper SDMathWrapper::binaryOperate(const SDMemTableWrapper& left,
|
---|
52 | const SDMemTableWrapper& right,
|
---|
53 | const std::string& op, bool doTSys)
|
---|
54 | {
|
---|
55 | SDMath sdm;
|
---|
56 | return SDMemTableWrapper(sdm.binaryOperate(left.getCP(), right.getCP(),
|
---|
57 | String(op), False, Bool(doTSys)));
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | void SDMathWrapper::scaleInSitu(SDMemTableWrapper& in, float factor, bool doAll, bool doTSys)
|
---|
62 | {
|
---|
63 | SDMemTable* pIn = in.getPtr();
|
---|
64 | const uInt what = 0;
|
---|
65 | //
|
---|
66 | SDMath sdm;
|
---|
67 | SDMemTable* pOut = sdm.unaryOperate (*pIn, Float(factor),
|
---|
68 | Bool(doAll), what, Bool(doTSys));
|
---|
69 | *pIn = *pOut;
|
---|
70 | delete pOut;
|
---|
71 | }
|
---|
72 |
|
---|
73 | SDMemTableWrapper SDMathWrapper::scale(const SDMemTableWrapper& in,
|
---|
74 | float factor, bool doAll, bool doTSys)
|
---|
75 | {
|
---|
76 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
77 | const uInt what = 0;
|
---|
78 | SDMath sdm;
|
---|
79 | return CountedPtr<SDMemTable>(sdm.unaryOperate(*pIn, Float(factor), Bool(doAll),
|
---|
80 | what, Bool (doTSys)));
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 | void SDMathWrapper::addInSitu(SDMemTableWrapper& in, float offset, bool doAll)
|
---|
86 | {
|
---|
87 | SDMemTable* pIn = in.getPtr();
|
---|
88 | const uInt what = 1;
|
---|
89 | //
|
---|
90 | SDMath sdm;
|
---|
91 | Bool doTSys = False;
|
---|
92 | SDMemTable* pOut = sdm.unaryOperate (*pIn, Float(offset),
|
---|
93 | Bool(doAll), what, doTSys);
|
---|
94 | *pIn = *pOut;
|
---|
95 | delete pOut;
|
---|
96 | }
|
---|
97 |
|
---|
98 | SDMemTableWrapper SDMathWrapper::add(const SDMemTableWrapper& in,
|
---|
99 | float offset, bool doAll)
|
---|
100 | {
|
---|
101 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
102 | const uInt what = 1;
|
---|
103 | SDMath sdm;
|
---|
104 | Bool doTSys = False;
|
---|
105 | return CountedPtr<SDMemTable>(sdm.unaryOperate(*pIn, Float(offset),
|
---|
106 | Bool(doAll), what, doTSys));
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | void SDMathWrapper::smoothInSitu(SDMemTableWrapper& in,
|
---|
111 | const std::string& kernel, float width,
|
---|
112 | bool doAll)
|
---|
113 | {
|
---|
114 | SDMemTable* pIn = in.getPtr();
|
---|
115 | SDMath sdm;
|
---|
116 | SDMemTable* pOut = sdm.smooth(*pIn, String(kernel),
|
---|
117 | Float(width), Bool(doAll));
|
---|
118 | *pIn = *pOut;
|
---|
119 | delete pOut;
|
---|
120 | }
|
---|
121 |
|
---|
122 |
|
---|
123 | SDMemTableWrapper SDMathWrapper::smooth (const SDMemTableWrapper& in,
|
---|
124 | const std::string& kernel,
|
---|
125 | float width, bool doAll)
|
---|
126 | {
|
---|
127 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
128 | SDMath sdm;
|
---|
129 | return CountedPtr<SDMemTable>(sdm.smooth(*pIn, String(kernel),
|
---|
130 | Float(width), Bool(doAll)));
|
---|
131 | }
|
---|
132 |
|
---|
133 |
|
---|
134 |
|
---|
135 | void SDMathWrapper::binInSitu(SDMemTableWrapper& in, int width)
|
---|
136 | {
|
---|
137 | SDMemTable* pIn = in.getPtr();
|
---|
138 | SDMath sdm;
|
---|
139 | SDMemTable* pOut = sdm.bin (*pIn, Int(width));
|
---|
140 | *pIn = *pOut;
|
---|
141 | delete pOut;
|
---|
142 | }
|
---|
143 |
|
---|
144 | SDMemTableWrapper SDMathWrapper::bin (const SDMemTableWrapper& in,
|
---|
145 | int width)
|
---|
146 | {
|
---|
147 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
148 | SDMath sdm;
|
---|
149 | return CountedPtr<SDMemTable>(sdm.bin(*pIn, Int(width)));
|
---|
150 | }
|
---|
151 |
|
---|
152 | void SDMathWrapper::resampleInSitu(SDMemTableWrapper& in, const std::string& method,
|
---|
153 | float width)
|
---|
154 | {
|
---|
155 | SDMemTable* pIn = in.getPtr();
|
---|
156 | SDMath sdm;
|
---|
157 | SDMemTable* pOut = sdm.resample(*pIn, String(method), Float(width));
|
---|
158 | *pIn = *pOut;
|
---|
159 | delete pOut;
|
---|
160 | }
|
---|
161 |
|
---|
162 | SDMemTableWrapper SDMathWrapper::resample (const SDMemTableWrapper& in,
|
---|
163 | const std::string& method, float width)
|
---|
164 | {
|
---|
165 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
166 | SDMath sdm;
|
---|
167 | return CountedPtr<SDMemTable>(sdm.resample(*pIn, String(method), Float(width)));
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | void SDMathWrapper::averagePolInSitu(SDMemTableWrapper& in,
|
---|
172 | const std::vector<bool>& mask,
|
---|
173 | const std::string& weightStr)
|
---|
174 | {
|
---|
175 | SDMemTable* pIn = in.getPtr();
|
---|
176 | SDMath sdm;
|
---|
177 | Vector<Bool> tMask(mask);
|
---|
178 | SDMemTable* pOut = sdm.averagePol (*pIn, tMask, String(weightStr));
|
---|
179 | *pIn = *pOut;
|
---|
180 | delete pOut;
|
---|
181 | }
|
---|
182 |
|
---|
183 | SDMemTableWrapper SDMathWrapper::averagePol (const SDMemTableWrapper& in,
|
---|
184 | const std::vector<bool>& mask,
|
---|
185 | const std::string& weightStr)
|
---|
186 | {
|
---|
187 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
188 | SDMath sdm;
|
---|
189 | Vector<Bool> tMask(mask);
|
---|
190 | return CountedPtr<SDMemTable>(sdm.averagePol(*pIn, tMask, String(weightStr)));
|
---|
191 | }
|
---|
192 |
|
---|
193 |
|
---|
194 | std::vector<float> SDMathWrapper::statistic(const SDMemTableWrapper& in,
|
---|
195 | const std::vector<bool>& mask,
|
---|
196 | const std::string& which, int row)
|
---|
197 | {
|
---|
198 | SDMath sdm;
|
---|
199 | Vector<Bool> tMask(mask);
|
---|
200 | return sdm.statistic(in.getCP(), tMask, String(which), Int(row));
|
---|
201 | }
|
---|
202 |
|
---|
203 |
|
---|
204 | void SDMathWrapper::convertFluxInSitu(SDMemTableWrapper& in,
|
---|
205 | float area, float eta, bool doAll)
|
---|
206 | {
|
---|
207 | SDMemTable* pIn = in.getPtr();
|
---|
208 | SDMath sdm;
|
---|
209 | SDMemTable* pOut = sdm.convertFlux (*pIn, Float(area), Float(eta), Bool(doAll));
|
---|
210 | *pIn = *pOut;
|
---|
211 | delete pOut;
|
---|
212 | }
|
---|
213 |
|
---|
214 |
|
---|
215 | SDMemTableWrapper SDMathWrapper::convertFlux(const SDMemTableWrapper& in,
|
---|
216 | float area, float eta, bool doAll)
|
---|
217 | {
|
---|
218 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
219 | SDMath sdm;
|
---|
220 | return CountedPtr<SDMemTable>(sdm.convertFlux(*pIn, Float(area), Float(eta), Bool(doAll)));
|
---|
221 | }
|
---|
222 |
|
---|
223 |
|
---|
224 | void SDMathWrapper::gainElevationInSitu(SDMemTableWrapper& in,
|
---|
225 | const std::vector<float>& coeffs,
|
---|
226 | const string& fileName,
|
---|
227 | const string& method, bool doAll)
|
---|
228 | {
|
---|
229 | SDMemTable* pIn = in.getPtr();
|
---|
230 | Vector<Float> tCoeffs(coeffs);
|
---|
231 | SDMath sdm;
|
---|
232 | SDMemTable* pOut = sdm.gainElevation(*pIn, tCoeffs, String(fileName),
|
---|
233 | String(method), Bool(doAll));
|
---|
234 | *pIn = *pOut;
|
---|
235 | delete pOut;
|
---|
236 | }
|
---|
237 |
|
---|
238 |
|
---|
239 | SDMemTableWrapper SDMathWrapper::gainElevation(const SDMemTableWrapper& in,
|
---|
240 | const std::vector<float>& coeffs,
|
---|
241 | const string& fileName,
|
---|
242 | const string& method, bool doAll)
|
---|
243 | {
|
---|
244 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
245 | Vector<Float> tCoeffs(coeffs);
|
---|
246 | SDMath sdm;
|
---|
247 | return CountedPtr<SDMemTable>(sdm.gainElevation(*pIn, tCoeffs, String(fileName),
|
---|
248 | String(method), Bool(doAll)));
|
---|
249 | }
|
---|
250 |
|
---|
251 | void SDMathWrapper::frequencyAlignmentInSitu (SDMemTableWrapper& in, const std::string& refTime,
|
---|
252 | const std::string& method)
|
---|
253 | {
|
---|
254 | SDMemTable* pIn = in.getPtr();
|
---|
255 | SDMath sdm;
|
---|
256 | SDMemTable* pOut = sdm.frequencyAlignment(*pIn, String(refTime), String(method));
|
---|
257 | *pIn = *pOut;
|
---|
258 | delete pOut;
|
---|
259 | }
|
---|
260 |
|
---|
261 |
|
---|
262 | SDMemTableWrapper SDMathWrapper::frequencyAlignment (const SDMemTableWrapper& in,
|
---|
263 | const std::string& refTime,
|
---|
264 | const std::string& method)
|
---|
265 | {
|
---|
266 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
267 | SDMath sdm;
|
---|
268 | return CountedPtr<SDMemTable>(sdm.frequencyAlignment(*pIn, String(refTime), String(method)));
|
---|
269 | }
|
---|
270 |
|
---|
271 | void SDMathWrapper::opacityInSitu(SDMemTableWrapper& in, float tau, bool doAll)
|
---|
272 | {
|
---|
273 | SDMemTable* pIn = in.getPtr();
|
---|
274 | SDMath sdm;
|
---|
275 | SDMemTable* pOut = sdm.opacity(*pIn, Float(tau), Bool(doAll));
|
---|
276 | *pIn = *pOut;
|
---|
277 | delete pOut;
|
---|
278 | }
|
---|
279 |
|
---|
280 |
|
---|
281 | SDMemTableWrapper SDMathWrapper::opacity(const SDMemTableWrapper& in,
|
---|
282 | float tau, bool doAll)
|
---|
283 | {
|
---|
284 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
285 | SDMath sdm;
|
---|
286 | return CountedPtr<SDMemTable>(sdm.opacity(*pIn, Float(tau), Bool(doAll)));
|
---|
287 | }
|
---|
288 |
|
---|