[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, |
---|
| 41 | const SDMemTableWrapper& off) |
---|
| 42 | { |
---|
[170] | 43 | SDMath sdm; |
---|
| 44 | return SDMemTableWrapper(sdm.quotient(on.getCP(), off.getCP())); |
---|
[169] | 45 | } |
---|
| 46 | |
---|
| 47 | |
---|
[235] | 48 | SDMemTableWrapper 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 | |
---|
[170] | 58 | void SDMathWrapper::scaleInSitu(SDMemTableWrapper& in, float factor, bool doAll) |
---|
[169] | 59 | { |
---|
| 60 | SDMemTable* pIn = in.getPtr(); |
---|
| 61 | const uInt what = 0; |
---|
[170] | 62 | // |
---|
| 63 | SDMath sdm; |
---|
[209] | 64 | SDMemTable* pOut = sdm.simpleOperate (*pIn, Float(factor), |
---|
| 65 | Bool(doAll), what); |
---|
[169] | 66 | *pIn = *pOut; |
---|
| 67 | delete pOut; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | SDMemTableWrapper SDMathWrapper::scale(const SDMemTableWrapper& in, |
---|
[170] | 71 | float factor, bool doAll) |
---|
[169] | 72 | { |
---|
| 73 | const CountedPtr<SDMemTable>& pIn = in.getCP(); |
---|
| 74 | const uInt what = 0; |
---|
[170] | 75 | SDMath sdm; |
---|
[209] | 76 | return CountedPtr<SDMemTable>(sdm.simpleOperate(*pIn, |
---|
| 77 | Float(factor), |
---|
| 78 | Bool(doAll), what)); |
---|
[169] | 79 | } |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|
[170] | 83 | void SDMathWrapper::addInSitu(SDMemTableWrapper& in, float offset, bool doAll) |
---|
[169] | 84 | { |
---|
| 85 | SDMemTable* pIn = in.getPtr(); |
---|
| 86 | const uInt what = 1; |
---|
[170] | 87 | // |
---|
| 88 | SDMath sdm; |
---|
[209] | 89 | SDMemTable* pOut = sdm.simpleOperate (*pIn, Float(offset), |
---|
| 90 | Bool(doAll), what); |
---|
[169] | 91 | *pIn = *pOut; |
---|
| 92 | delete pOut; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | SDMemTableWrapper SDMathWrapper::add(const SDMemTableWrapper& in, |
---|
[170] | 96 | float offset, bool doAll) |
---|
[169] | 97 | { |
---|
| 98 | const CountedPtr<SDMemTable>& pIn = in.getCP(); |
---|
| 99 | const uInt what = 1; |
---|
[170] | 100 | SDMath sdm; |
---|
[209] | 101 | return CountedPtr<SDMemTable>(sdm.simpleOperate(*pIn, Float(offset), |
---|
| 102 | Bool(doAll), what)); |
---|
[169] | 103 | } |
---|
| 104 | |
---|
[178] | 105 | |
---|
[209] | 106 | void SDMathWrapper::smoothInSitu(SDMemTableWrapper& in, |
---|
| 107 | const std::string& kernel, float width, |
---|
| 108 | bool doAll) |
---|
[171] | 109 | { |
---|
| 110 | SDMemTable* pIn = in.getPtr(); |
---|
| 111 | SDMath sdm; |
---|
[209] | 112 | SDMemTable* pOut = sdm.smooth(*pIn, String(kernel), |
---|
| 113 | Float(width), Bool(doAll)); |
---|
[171] | 114 | *pIn = *pOut; |
---|
| 115 | delete pOut; |
---|
| 116 | } |
---|
[169] | 117 | |
---|
[178] | 118 | |
---|
[209] | 119 | SDMemTableWrapper SDMathWrapper::smooth (const SDMemTableWrapper& in, |
---|
| 120 | const std::string& kernel, |
---|
[178] | 121 | float width, bool doAll) |
---|
[169] | 122 | { |
---|
[171] | 123 | const CountedPtr<SDMemTable>& pIn = in.getCP(); |
---|
[170] | 124 | SDMath sdm; |
---|
[209] | 125 | return CountedPtr<SDMemTable>(sdm.smooth(*pIn, String(kernel), |
---|
| 126 | Float(width), Bool(doAll))); |
---|
[169] | 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
[171] | 130 | |
---|
[169] | 131 | void SDMathWrapper::binInSitu(SDMemTableWrapper& in, int width) |
---|
| 132 | { |
---|
| 133 | SDMemTable* pIn = in.getPtr(); |
---|
[170] | 134 | SDMath sdm; |
---|
| 135 | SDMemTable* pOut = sdm.bin (*pIn, Int(width)); |
---|
[169] | 136 | *pIn = *pOut; |
---|
| 137 | delete pOut; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | SDMemTableWrapper SDMathWrapper::bin (const SDMemTableWrapper& in, |
---|
| 141 | int width) |
---|
| 142 | { |
---|
| 143 | const CountedPtr<SDMemTable>& pIn = in.getCP(); |
---|
[170] | 144 | SDMath sdm; |
---|
| 145 | return CountedPtr<SDMemTable>(sdm.bin(*pIn, Int(width))); |
---|
[169] | 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
[209] | 149 | void SDMathWrapper::averagePolInSitu(SDMemTableWrapper& in, |
---|
| 150 | const std::vector<bool>& mask) |
---|
[169] | 151 | { |
---|
| 152 | SDMemTable* pIn = in.getPtr(); |
---|
[170] | 153 | SDMath sdm; |
---|
[235] | 154 | Vector<Bool> tMask(mask); |
---|
| 155 | SDMemTable* pOut = sdm.averagePol (*pIn, tMask); |
---|
[169] | 156 | *pIn = *pOut; |
---|
| 157 | delete pOut; |
---|
| 158 | } |
---|
| 159 | |
---|
[209] | 160 | SDMemTableWrapper SDMathWrapper::averagePol (const SDMemTableWrapper& in, |
---|
| 161 | const std::vector<bool>& mask) |
---|
[169] | 162 | |
---|
| 163 | { |
---|
| 164 | const CountedPtr<SDMemTable>& pIn = in.getCP(); |
---|
[170] | 165 | SDMath sdm; |
---|
[235] | 166 | Vector<Bool> tMask(mask); |
---|
| 167 | return CountedPtr<SDMemTable>(sdm.averagePol(*pIn, tMask)); |
---|
[169] | 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | std::vector<float> SDMathWrapper::statistic(const SDMemTableWrapper& in, |
---|
| 172 | const std::vector<bool>& mask, |
---|
[235] | 173 | const std::string& which, int row) |
---|
[169] | 174 | { |
---|
[170] | 175 | SDMath sdm; |
---|
[235] | 176 | Vector<Bool> tMask(mask); |
---|
| 177 | return sdm.statistic(in.getCP(), tMask, String(which), Int(row)); |
---|
[169] | 178 | } |
---|
[222] | 179 | |
---|
| 180 | |
---|
| 181 | void 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 | |
---|
| 192 | SDMemTableWrapper 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 | |
---|
[227] | 200 | |
---|
[235] | 201 | void SDMathWrapper::gainElevationInSitu(SDMemTableWrapper& in, |
---|
| 202 | const std::vector<float>& coeffs, |
---|
| 203 | const string& fileName, |
---|
[227] | 204 | const string& method, bool doAll) |
---|
| 205 | { |
---|
| 206 | SDMemTable* pIn = in.getPtr(); |
---|
[235] | 207 | Vector<Float> tCoeffs(coeffs); |
---|
[227] | 208 | SDMath sdm; |
---|
[235] | 209 | SDMemTable* pOut = sdm.gainElevation(*pIn, tCoeffs, String(fileName), |
---|
| 210 | String(method), Bool(doAll)); |
---|
[227] | 211 | *pIn = *pOut; |
---|
| 212 | delete pOut; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | |
---|
| 216 | SDMemTableWrapper SDMathWrapper::gainElevation(const SDMemTableWrapper& in, |
---|
[235] | 217 | const std::vector<float>& coeffs, |
---|
[227] | 218 | const string& fileName, |
---|
| 219 | const string& method, bool doAll) |
---|
| 220 | { |
---|
| 221 | const CountedPtr<SDMemTable>& pIn = in.getCP(); |
---|
[235] | 222 | Vector<Float> tCoeffs(coeffs); |
---|
[227] | 223 | SDMath sdm; |
---|
[235] | 224 | return CountedPtr<SDMemTable>(sdm.gainElevation(*pIn, tCoeffs, String(fileName), |
---|
[227] | 225 | String(method), Bool(doAll))); |
---|
| 226 | } |
---|
| 227 | |
---|
[235] | 228 | void 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 | |
---|
| 238 | SDMemTableWrapper 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 | |
---|