source: branches/Release12/src/SDMathWrapper.cc@ 2838

Last change on this file since 2838 was 798, checked in by phi196, 19 years ago

Added swap_pol & invert_phase

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 KB
Line 
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#include "SDMathWrapper.h"
33
34using namespace asap;
35using namespace casa;
36
37
38SDMemTableWrapper SDMathWrapper::quotient(const SDMemTableWrapper& on,
39 const SDMemTableWrapper& off,
40 Bool preserveContinuum)
41{
42
43 Bool doTSys = True;
44 return SDMemTableWrapper(sdmath.binaryOperate(on.getCP(), off.getCP(),
45 String("QUOTIENT"),
46 preserveContinuum, doTSys));
47}
48
49
50SDMemTableWrapper SDMathWrapper::binaryOperate(const SDMemTableWrapper& left,
51 const SDMemTableWrapper& right,
52 const std::string& op,
53 bool doTSys)
54{
55
56 return SDMemTableWrapper(sdmath.binaryOperate(left.getCP(), right.getCP(),
57 String(op), False,
58 Bool(doTSys)));
59}
60
61
62void SDMathWrapper::scaleInSitu(SDMemTableWrapper& in, float factor,
63 bool doAll, bool doTSys)
64{
65 SDMemTable* pIn = in.getPtr();
66 const uInt what = 0;
67
68 SDMemTable* pOut = sdmath.unaryOperate (*pIn, Float(factor),
69 Bool(doAll), what, Bool(doTSys));
70 *pIn = *pOut;
71 delete pOut;
72}
73
74SDMemTableWrapper SDMathWrapper::scale(const SDMemTableWrapper& in,
75 float factor, bool doAll, bool doTSys)
76{
77 const CountedPtr<SDMemTable>& pIn = in.getCP();
78 const uInt what = 0;
79
80 return CountedPtr<SDMemTable>(sdmath.unaryOperate(*pIn, Float(factor), Bool(doAll),
81 what, Bool (doTSys)));
82}
83
84
85void SDMathWrapper::addInSitu(SDMemTableWrapper& in, float offset, bool doAll)
86{
87 SDMemTable* pIn = in.getPtr();
88 const uInt what = 1;
89
90 Bool doTSys = False;
91 SDMemTable* pOut = sdmath.unaryOperate (*pIn, Float(offset),
92 Bool(doAll), what, doTSys);
93 *pIn = *pOut;
94 delete pOut;
95}
96
97SDMemTableWrapper SDMathWrapper::add(const SDMemTableWrapper& in,
98 float offset, bool doAll)
99{
100 const CountedPtr<SDMemTable>& pIn = in.getCP();
101 const uInt what = 1;
102
103 Bool doTSys = False;
104 return CountedPtr<SDMemTable>(sdmath.unaryOperate(*pIn, Float(offset),
105 Bool(doAll), what, doTSys));
106}
107
108
109void SDMathWrapper::smoothInSitu(SDMemTableWrapper& in,
110 const std::string& kernel, float width,
111 bool doAll)
112{
113 SDMemTable* pIn = in.getPtr();
114
115 SDMemTable* pOut = sdmath.smooth(*pIn, String(kernel),
116 Float(width), Bool(doAll));
117 *pIn = *pOut;
118 delete pOut;
119}
120
121
122SDMemTableWrapper SDMathWrapper::smooth (const SDMemTableWrapper& in,
123 const std::string& kernel,
124 float width, bool doAll)
125{
126 const CountedPtr<SDMemTable>& pIn = in.getCP();
127
128 return CountedPtr<SDMemTable>(sdmath.smooth(*pIn, String(kernel),
129 Float(width), Bool(doAll)));
130}
131
132
133
134void SDMathWrapper::binInSitu(SDMemTableWrapper& in, int width)
135{
136 SDMemTable* pIn = in.getPtr();
137
138 SDMemTable* pOut = sdmath.bin (*pIn, Int(width));
139 *pIn = *pOut;
140 delete pOut;
141}
142
143SDMemTableWrapper SDMathWrapper::bin (const SDMemTableWrapper& in,
144 int width)
145{
146 const CountedPtr<SDMemTable>& pIn = in.getCP();
147
148 return CountedPtr<SDMemTable>(sdmath.bin(*pIn, Int(width)));
149}
150
151void SDMathWrapper::resampleInSitu(SDMemTableWrapper& in, const std::string& method,
152 float width)
153{
154 SDMemTable* pIn = in.getPtr();
155
156 SDMemTable* pOut = sdmath.resample(*pIn, String(method), Float(width));
157 *pIn = *pOut;
158 delete pOut;
159}
160
161SDMemTableWrapper SDMathWrapper::resample (const SDMemTableWrapper& in,
162 const std::string& method, float width)
163{
164 const CountedPtr<SDMemTable>& pIn = in.getCP();
165
166 return CountedPtr<SDMemTable>(sdmath.resample(*pIn, String(method), Float(width)));
167}
168
169
170void SDMathWrapper::averagePolInSitu(SDMemTableWrapper& in,
171 const std::vector<bool>& mask,
172 const std::string& weightStr)
173{
174 SDMemTable* pIn = in.getPtr();
175
176 Vector<Bool> tMask(mask);
177 SDMemTable* pOut = sdmath.averagePol (*pIn, tMask, String(weightStr));
178 *pIn = *pOut;
179 delete pOut;
180}
181
182SDMemTableWrapper SDMathWrapper::averagePol (const SDMemTableWrapper& in,
183 const std::vector<bool>& mask,
184 const std::string& weightStr)
185{
186 const CountedPtr<SDMemTable>& pIn = in.getCP();
187
188 Vector<Bool> tMask(mask);
189 return CountedPtr<SDMemTable>(sdmath.averagePol(*pIn, tMask, String(weightStr)));
190}
191
192
193std::vector<float> SDMathWrapper::statistic(const SDMemTableWrapper& in,
194 const std::vector<bool>& mask,
195 const std::string& which, int row)
196{
197
198 Vector<Bool> tMask(mask);
199 return sdmath.statistic(in.getCP(), tMask, String(which), Int(row));
200}
201
202
203void SDMathWrapper::convertFluxInSitu(SDMemTableWrapper& in, float D,
204 float eta, float JyPerK, bool doAll)
205{
206 SDMemTable* pIn = in.getPtr();
207
208 SDMemTable* pOut = sdmath.convertFlux (*pIn, Float(D), Float(eta), Float(JyPerK), Bool(doAll));
209 *pIn = *pOut;
210 delete pOut;
211}
212
213
214SDMemTableWrapper SDMathWrapper::convertFlux(const SDMemTableWrapper& in, float D, float eta,
215 float JyPerK, bool doAll)
216{
217 const CountedPtr<SDMemTable>& pIn = in.getCP();
218
219 return CountedPtr<SDMemTable>(sdmath.convertFlux(*pIn, Float(D), Float(eta), Float(JyPerK), Bool(doAll)));
220}
221
222
223void SDMathWrapper::gainElevationInSitu(SDMemTableWrapper& in,
224 const std::vector<float>& coeffs,
225 const string& fileName,
226 const string& method, bool doAll)
227{
228 SDMemTable* pIn = in.getPtr();
229 Vector<Float> tCoeffs(coeffs);
230
231 SDMemTable* pOut = sdmath.gainElevation(*pIn, tCoeffs, String(fileName),
232 String(method), Bool(doAll));
233 *pIn = *pOut;
234 delete pOut;
235}
236
237
238SDMemTableWrapper SDMathWrapper::gainElevation(const SDMemTableWrapper& in,
239 const std::vector<float>& coeffs,
240 const string& fileName,
241 const string& method, bool doAll)
242{
243 const CountedPtr<SDMemTable>& pIn = in.getCP();
244 Vector<Float> tCoeffs(coeffs);
245
246 return CountedPtr<SDMemTable>(sdmath.gainElevation(*pIn, tCoeffs, String(fileName),
247 String(method), Bool(doAll)));
248}
249
250void SDMathWrapper::frequencyAlignmentInSitu (SDMemTableWrapper& in, const std::string& refTime,
251 const std::string& method, bool perFreqID)
252{
253 SDMemTable* pIn = in.getPtr();
254
255 SDMemTable* pOut = sdmath.frequencyAlignment(*pIn, String(refTime), String(method),
256 Bool(perFreqID));
257 *pIn = *pOut;
258 delete pOut;
259}
260
261
262SDMemTableWrapper SDMathWrapper::frequencyAlignment (const SDMemTableWrapper& in,
263 const std::string& refTime,
264 const std::string& method,
265 bool perFreqID)
266{
267 const CountedPtr<SDMemTable>& pIn = in.getCP();
268
269 return CountedPtr<SDMemTable>(sdmath.frequencyAlignment(*pIn, String(refTime),
270 String(method), Bool(perFreqID)));
271}
272
273void SDMathWrapper::rotateXYPhaseInSitu(SDMemTableWrapper& in, float angle, bool doAll)
274{
275 SDMemTable* pIn = in.getPtr();
276
277 sdmath.rotateXYPhase(*pIn, Float(angle), Bool(doAll));
278}
279
280void SDMathWrapper::invertPhaseInSitu(SDMemTableWrapper& in, bool doAll)
281{
282 SDMemTable* pIn = in.getPtr();
283
284 sdmath.invertPhase(*pIn, Bool(doAll));
285}
286
287void SDMathWrapper::swapPolInSitu(SDMemTableWrapper& in, bool doAll)
288{
289 SDMemTable* pIn = in.getPtr();
290
291 sdmath.swapPol(*pIn, Bool(doAll));
292}
293
294
295void SDMathWrapper::rotateLinPolPhaseInSitu(SDMemTableWrapper& in, float angle, bool doAll)
296{
297 SDMemTable* pIn = in.getPtr();
298
299 sdmath.rotateLinPolPhase(*pIn, Float(angle), Bool(doAll));
300}
301
302
303
304
305void SDMathWrapper::opacityInSitu(SDMemTableWrapper& in, float tau, bool doAll)
306{
307 SDMemTable* pIn = in.getPtr();
308
309 SDMemTable* pOut = sdmath.opacity(*pIn, Float(tau), Bool(doAll));
310 *pIn = *pOut;
311 delete pOut;
312}
313
314SDMemTableWrapper SDMathWrapper::opacity(const SDMemTableWrapper& in,
315 float tau, bool doAll)
316{
317 const CountedPtr<SDMemTable>& pIn = in.getCP();
318
319 return CountedPtr<SDMemTable>(sdmath.opacity(*pIn, Float(tau), Bool(doAll)));
320}
321
322void SDMathWrapper::frequencySwitchInSitu(SDMemTableWrapper& in)
323{
324 SDMemTable* pIn = in.getPtr();
325 SDMath sdm;
326 SDMemTable* pOut = sdm.frequencySwitch(*pIn);
327 *pIn = *pOut;
328 delete pOut;
329}
330
331SDMemTableWrapper SDMathWrapper::frequencySwitch(const SDMemTableWrapper& in)
332{
333 const CountedPtr<SDMemTable>& pIn = in.getCP();
334 SDMath sdm;
335 return CountedPtr<SDMemTable>(sdm.frequencySwitch(*pIn));
336}
Note: See TracBrowser for help on using the repository browser.