[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 | #include "SDMathWrapper.h"
|
---|
| 33 |
|
---|
| 34 | using namespace asap;
|
---|
| 35 | using namespace casa;
|
---|
| 36 |
|
---|
[716] | 37 |
|
---|
[169] | 38 | SDMemTableWrapper SDMathWrapper::quotient(const SDMemTableWrapper& on,
|
---|
[244] | 39 | const SDMemTableWrapper& off,
|
---|
| 40 | Bool preserveContinuum)
|
---|
[169] | 41 | {
|
---|
[716] | 42 |
|
---|
[295] | 43 | Bool doTSys = True;
|
---|
[716] | 44 | return SDMemTableWrapper(sdmath.binaryOperate(on.getCP(), off.getCP(),
|
---|
| 45 | String("QUOTIENT"),
|
---|
| 46 | preserveContinuum, doTSys));
|
---|
[169] | 47 | }
|
---|
| 48 |
|
---|
| 49 |
|
---|
[249] | 50 | SDMemTableWrapper SDMathWrapper::binaryOperate(const SDMemTableWrapper& left,
|
---|
| 51 | const SDMemTableWrapper& right,
|
---|
[716] | 52 | const std::string& op,
|
---|
| 53 | bool doTSys)
|
---|
[235] | 54 | {
|
---|
[716] | 55 |
|
---|
| 56 | return SDMemTableWrapper(sdmath.binaryOperate(left.getCP(), right.getCP(),
|
---|
| 57 | String(op), False,
|
---|
| 58 | Bool(doTSys)));
|
---|
[235] | 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
[716] | 62 | void SDMathWrapper::scaleInSitu(SDMemTableWrapper& in, float factor,
|
---|
| 63 | bool doAll, bool doTSys)
|
---|
[169] | 64 | {
|
---|
| 65 | SDMemTable* pIn = in.getPtr();
|
---|
| 66 | const uInt what = 0;
|
---|
[716] | 67 |
|
---|
| 68 | SDMemTable* pOut = sdmath.unaryOperate (*pIn, Float(factor),
|
---|
[295] | 69 | Bool(doAll), what, Bool(doTSys));
|
---|
[169] | 70 | *pIn = *pOut;
|
---|
| 71 | delete pOut;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | SDMemTableWrapper SDMathWrapper::scale(const SDMemTableWrapper& in,
|
---|
[295] | 75 | float factor, bool doAll, bool doTSys)
|
---|
[169] | 76 | {
|
---|
| 77 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
| 78 | const uInt what = 0;
|
---|
[716] | 79 |
|
---|
| 80 | return CountedPtr<SDMemTable>(sdmath.unaryOperate(*pIn, Float(factor), Bool(doAll),
|
---|
[295] | 81 | what, Bool (doTSys)));
|
---|
[169] | 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;
|
---|
[716] | 89 |
|
---|
[295] | 90 | Bool doTSys = False;
|
---|
[716] | 91 | SDMemTable* pOut = sdmath.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;
|
---|
[716] | 102 |
|
---|
[295] | 103 | Bool doTSys = False;
|
---|
[716] | 104 | return CountedPtr<SDMemTable>(sdmath.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();
|
---|
[716] | 114 |
|
---|
| 115 | SDMemTable* pOut = sdmath.smooth(*pIn, String(kernel),
|
---|
[209] | 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();
|
---|
[716] | 127 |
|
---|
| 128 | return CountedPtr<SDMemTable>(sdmath.smooth(*pIn, String(kernel),
|
---|
[209] | 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();
|
---|
[716] | 137 |
|
---|
| 138 | SDMemTable* pOut = sdmath.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();
|
---|
[716] | 147 |
|
---|
| 148 | return CountedPtr<SDMemTable>(sdmath.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();
|
---|
[716] | 155 |
|
---|
| 156 | SDMemTable* pOut = sdmath.resample(*pIn, String(method), Float(width));
|
---|
[300] | 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();
|
---|
[716] | 165 |
|
---|
| 166 | return CountedPtr<SDMemTable>(sdmath.resample(*pIn, String(method), Float(width)));
|
---|
[300] | 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();
|
---|
[716] | 175 |
|
---|
[235] | 176 | Vector<Bool> tMask(mask);
|
---|
[716] | 177 | SDMemTable* pOut = sdmath.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();
|
---|
[716] | 187 |
|
---|
[235] | 188 | Vector<Bool> tMask(mask);
|
---|
[716] | 189 | return CountedPtr<SDMemTable>(sdmath.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 | {
|
---|
[716] | 197 |
|
---|
[235] | 198 | Vector<Bool> tMask(mask);
|
---|
[716] | 199 | return sdmath.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();
|
---|
[716] | 207 |
|
---|
| 208 | SDMemTable* pOut = sdmath.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();
|
---|
[716] | 218 |
|
---|
| 219 | return CountedPtr<SDMemTable>(sdmath.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);
|
---|
[716] | 230 |
|
---|
| 231 | SDMemTable* pOut = sdmath.gainElevation(*pIn, tCoeffs, String(fileName),
|
---|
[235] | 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);
|
---|
[716] | 245 |
|
---|
| 246 | return CountedPtr<SDMemTable>(sdmath.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();
|
---|
[716] | 254 |
|
---|
| 255 | SDMemTable* pOut = sdmath.frequencyAlignment(*pIn, String(refTime), String(method),
|
---|
[398] | 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();
|
---|
[716] | 268 |
|
---|
| 269 | return CountedPtr<SDMemTable>(sdmath.frequencyAlignment(*pIn, String(refTime),
|
---|
[398] | 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();
|
---|
[716] | 276 |
|
---|
| 277 | sdmath.rotateXYPhase(*pIn, Float(angle), Bool(doAll));
|
---|
[457] | 278 | }
|
---|
| 279 |
|
---|
| 280 |
|
---|
[502] | 281 | void SDMathWrapper::rotateLinPolPhaseInSitu(SDMemTableWrapper& in, float angle, bool doAll)
|
---|
| 282 | {
|
---|
| 283 | SDMemTable* pIn = in.getPtr();
|
---|
[716] | 284 |
|
---|
| 285 | sdmath.rotateLinPolPhase(*pIn, Float(angle), Bool(doAll));
|
---|
[502] | 286 | }
|
---|
[457] | 287 |
|
---|
| 288 |
|
---|
[502] | 289 |
|
---|
| 290 |
|
---|
[235] | 291 | void SDMathWrapper::opacityInSitu(SDMemTableWrapper& in, float tau, bool doAll)
|
---|
| 292 | {
|
---|
| 293 | SDMemTable* pIn = in.getPtr();
|
---|
[716] | 294 |
|
---|
| 295 | SDMemTable* pOut = sdmath.opacity(*pIn, Float(tau), Bool(doAll));
|
---|
[235] | 296 | *pIn = *pOut;
|
---|
| 297 | delete pOut;
|
---|
| 298 | }
|
---|
| 299 |
|
---|
| 300 | SDMemTableWrapper SDMathWrapper::opacity(const SDMemTableWrapper& in,
|
---|
| 301 | float tau, bool doAll)
|
---|
| 302 | {
|
---|
| 303 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
[716] | 304 |
|
---|
| 305 | return CountedPtr<SDMemTable>(sdmath.opacity(*pIn, Float(tau), Bool(doAll)));
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | void SDMathWrapper::frequencySwitchInSitu(SDMemTableWrapper& in)
|
---|
| 309 | {
|
---|
| 310 | SDMemTable* pIn = in.getPtr();
|
---|
[235] | 311 | SDMath sdm;
|
---|
[716] | 312 | SDMemTable* pOut = sdm.frequencySwitch(*pIn);
|
---|
| 313 | *pIn = *pOut;
|
---|
| 314 | delete pOut;
|
---|
[235] | 315 | }
|
---|
| 316 |
|
---|
[716] | 317 | SDMemTableWrapper SDMathWrapper::frequencySwitch(const SDMemTableWrapper& in)
|
---|
| 318 | {
|
---|
| 319 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
| 320 | SDMath sdm;
|
---|
| 321 | return CountedPtr<SDMemTable>(sdm.frequencySwitch(*pIn));
|
---|
| 322 | }
|
---|