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