source: trunk/src/SDMathWrapper.cc @ 236

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

Add binary table operator

opacity
gain elevation now handles polynomials
pass on row arg to SDMath::statistics

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 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
33#include "SDMathWrapper.h"
34#include "SDMath.h"
35
36
37using namespace asap;
38using namespace casa;
39
40SDMemTableWrapper SDMathWrapper::quotient(const SDMemTableWrapper& on,
41                                          const SDMemTableWrapper& off)
42{
43    SDMath sdm;
44    return SDMemTableWrapper(sdm.quotient(on.getCP(), off.getCP()));
45}
46
47
48SDMemTableWrapper SDMathWrapper::simpleBinaryOperate(const SDMemTableWrapper& left,
49                                                     const SDMemTableWrapper& right,
50                                                     const std::string& op)
51{
52    SDMath sdm;
53    return SDMemTableWrapper(sdm.simpleBinaryOperate(left.getCP(), right.getCP(),
54                                                     String(op)));
55}
56
57
58void SDMathWrapper::scaleInSitu(SDMemTableWrapper& in, float factor, bool doAll)
59{
60  SDMemTable* pIn = in.getPtr();
61  const uInt what = 0;
62//
63  SDMath sdm;
64  SDMemTable* pOut = sdm.simpleOperate (*pIn, Float(factor),
65                                        Bool(doAll), what);
66  *pIn = *pOut;
67   delete pOut;
68}
69
70SDMemTableWrapper SDMathWrapper::scale(const SDMemTableWrapper& in,
71                          float factor, bool doAll)
72{
73  const CountedPtr<SDMemTable>& pIn = in.getCP();
74  const uInt what = 0;
75  SDMath sdm;
76  return CountedPtr<SDMemTable>(sdm.simpleOperate(*pIn,
77                                                  Float(factor),
78                                                  Bool(doAll), what));
79}
80
81
82
83void SDMathWrapper::addInSitu(SDMemTableWrapper& in, float offset, bool doAll)
84{
85  SDMemTable* pIn = in.getPtr();
86  const uInt what = 1;
87//
88  SDMath sdm;
89  SDMemTable* pOut = sdm.simpleOperate (*pIn, Float(offset),
90                                        Bool(doAll), what);
91  *pIn = *pOut;
92   delete pOut;
93}
94
95SDMemTableWrapper SDMathWrapper::add(const SDMemTableWrapper& in,
96                                     float offset, bool doAll)
97{
98  const CountedPtr<SDMemTable>& pIn = in.getCP();
99  const uInt what = 1;
100  SDMath sdm;
101  return CountedPtr<SDMemTable>(sdm.simpleOperate(*pIn, Float(offset),
102                                                  Bool(doAll), what));
103}
104
105
106void SDMathWrapper::smoothInSitu(SDMemTableWrapper& in,
107                                 const std::string& kernel, float width,
108                                 bool doAll)
109{
110  SDMemTable* pIn = in.getPtr();
111  SDMath sdm;
112  SDMemTable* pOut = sdm.smooth(*pIn, String(kernel),
113                                Float(width), Bool(doAll));
114  *pIn = *pOut;
115   delete pOut;
116}
117
118
119SDMemTableWrapper SDMathWrapper::smooth (const SDMemTableWrapper& in,
120                                         const std::string& kernel,
121                                         float width, bool doAll)
122{
123  const CountedPtr<SDMemTable>& pIn = in.getCP();
124  SDMath sdm;
125  return CountedPtr<SDMemTable>(sdm.smooth(*pIn, String(kernel),
126                                           Float(width), Bool(doAll)));
127}
128
129
130
131void SDMathWrapper::binInSitu(SDMemTableWrapper& in, int width)
132{
133  SDMemTable* pIn = in.getPtr();
134  SDMath sdm;
135  SDMemTable* pOut = sdm.bin (*pIn, Int(width));
136  *pIn = *pOut;
137   delete pOut;
138}
139
140SDMemTableWrapper SDMathWrapper::bin (const SDMemTableWrapper& in,
141                                      int width)
142{
143  const CountedPtr<SDMemTable>& pIn = in.getCP();
144  SDMath sdm;
145  return CountedPtr<SDMemTable>(sdm.bin(*pIn, Int(width)));
146}
147
148
149void SDMathWrapper::averagePolInSitu(SDMemTableWrapper& in,
150                                     const std::vector<bool>& mask)
151{
152  SDMemTable* pIn = in.getPtr();
153  SDMath sdm;
154  Vector<Bool> tMask(mask);
155  SDMemTable* pOut = sdm.averagePol (*pIn, tMask);
156  *pIn = *pOut;
157   delete pOut;
158}
159
160SDMemTableWrapper SDMathWrapper::averagePol (const SDMemTableWrapper& in,
161                                             const std::vector<bool>& mask)
162
163{
164  const CountedPtr<SDMemTable>& pIn = in.getCP();
165  SDMath sdm;
166  Vector<Bool> tMask(mask);
167  return CountedPtr<SDMemTable>(sdm.averagePol(*pIn, tMask));
168}
169
170
171std::vector<float> SDMathWrapper::statistic(const SDMemTableWrapper& in,
172                                            const std::vector<bool>& mask,
173                                            const std::string& which, int row)
174{
175  SDMath sdm;
176  Vector<Bool> tMask(mask);
177  return sdm.statistic(in.getCP(), tMask, String(which), Int(row));
178}
179
180
181void SDMathWrapper::convertFluxInSitu(SDMemTableWrapper& in,
182                                      float area, float eta, bool doAll)
183{
184  SDMemTable* pIn = in.getPtr();
185  SDMath sdm;
186  SDMemTable* pOut = sdm.convertFlux (*pIn, Float(area), Float(eta), Bool(doAll));
187  *pIn = *pOut;
188  delete pOut;
189}
190
191
192SDMemTableWrapper SDMathWrapper::convertFlux(const SDMemTableWrapper& in,
193                                             float area, float eta, bool doAll)
194{
195  const CountedPtr<SDMemTable>& pIn = in.getCP();
196  SDMath sdm;
197  return CountedPtr<SDMemTable>(sdm.convertFlux(*pIn, Float(area), Float(eta), Bool(doAll)));
198}
199
200
201void SDMathWrapper::gainElevationInSitu(SDMemTableWrapper& in,
202                                        const std::vector<float>& coeffs,
203                                        const string& fileName,
204                                        const string& method, bool doAll)
205{
206  SDMemTable* pIn = in.getPtr();
207  Vector<Float> tCoeffs(coeffs);
208  SDMath sdm;
209  SDMemTable* pOut = sdm.gainElevation(*pIn, tCoeffs, String(fileName),
210                                       String(method), Bool(doAll));
211  *pIn = *pOut;
212  delete pOut;
213}
214
215
216SDMemTableWrapper SDMathWrapper::gainElevation(const SDMemTableWrapper& in,
217                                               const std::vector<float>& coeffs,
218                                               const string& fileName,
219                                               const string& method, bool doAll)
220{
221  const CountedPtr<SDMemTable>& pIn = in.getCP();
222  Vector<Float> tCoeffs(coeffs);
223  SDMath sdm;
224  return CountedPtr<SDMemTable>(sdm.gainElevation(*pIn, tCoeffs, String(fileName),
225                                                  String(method), Bool(doAll)));
226}
227
228void SDMathWrapper::opacityInSitu(SDMemTableWrapper& in, float tau, bool doAll)
229{
230  SDMemTable* pIn = in.getPtr();
231  SDMath sdm;
232  SDMemTable* pOut = sdm.opacity(*pIn, Float(tau), Bool(doAll));
233  *pIn = *pOut;
234  delete pOut;
235}
236
237
238SDMemTableWrapper SDMathWrapper::opacity(const SDMemTableWrapper& in,
239                                         float tau, bool doAll)
240{
241  const CountedPtr<SDMemTable>& pIn = in.getCP();
242  SDMath sdm;
243  return CountedPtr<SDMemTable>(sdm.opacity(*pIn, Float(tau), Bool(doAll)));
244}
245
Note: See TracBrowser for help on using the repository browser.