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