[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 |
|
---|
| 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;
|
---|
[295] | 91 | Bool doTSys = False;
|
---|
[249] | 92 | SDMemTable* pOut = sdm.unaryOperate (*pIn, Float(offset),
|
---|
[295] | 93 | Bool(doAll), what, doTSys);
|
---|
[169] | 94 | *pIn = *pOut;
|
---|
| 95 | delete pOut;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | SDMemTableWrapper SDMathWrapper::add(const SDMemTableWrapper& in,
|
---|
[170] | 99 | float offset, bool doAll)
|
---|
[169] | 100 | {
|
---|
| 101 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
| 102 | const uInt what = 1;
|
---|
[170] | 103 | SDMath sdm;
|
---|
[295] | 104 | Bool doTSys = False;
|
---|
[249] | 105 | return CountedPtr<SDMemTable>(sdm.unaryOperate(*pIn, Float(offset),
|
---|
[295] | 106 | Bool(doAll), what, doTSys));
|
---|
[169] | 107 | }
|
---|
| 108 |
|
---|
[178] | 109 |
|
---|
[209] | 110 | void SDMathWrapper::smoothInSitu(SDMemTableWrapper& in,
|
---|
| 111 | const std::string& kernel, float width,
|
---|
| 112 | bool doAll)
|
---|
[171] | 113 | {
|
---|
| 114 | SDMemTable* pIn = in.getPtr();
|
---|
| 115 | SDMath sdm;
|
---|
[209] | 116 | SDMemTable* pOut = sdm.smooth(*pIn, String(kernel),
|
---|
| 117 | Float(width), Bool(doAll));
|
---|
[171] | 118 | *pIn = *pOut;
|
---|
| 119 | delete pOut;
|
---|
| 120 | }
|
---|
[169] | 121 |
|
---|
[178] | 122 |
|
---|
[209] | 123 | SDMemTableWrapper SDMathWrapper::smooth (const SDMemTableWrapper& in,
|
---|
| 124 | const std::string& kernel,
|
---|
[178] | 125 | float width, bool doAll)
|
---|
[169] | 126 | {
|
---|
[171] | 127 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
[170] | 128 | SDMath sdm;
|
---|
[209] | 129 | return CountedPtr<SDMemTable>(sdm.smooth(*pIn, String(kernel),
|
---|
| 130 | Float(width), Bool(doAll)));
|
---|
[169] | 131 | }
|
---|
| 132 |
|
---|
| 133 |
|
---|
[171] | 134 |
|
---|
[169] | 135 | void SDMathWrapper::binInSitu(SDMemTableWrapper& in, int width)
|
---|
| 136 | {
|
---|
| 137 | SDMemTable* pIn = in.getPtr();
|
---|
[170] | 138 | SDMath sdm;
|
---|
| 139 | SDMemTable* pOut = sdm.bin (*pIn, Int(width));
|
---|
[169] | 140 | *pIn = *pOut;
|
---|
| 141 | delete pOut;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | SDMemTableWrapper SDMathWrapper::bin (const SDMemTableWrapper& in,
|
---|
| 145 | int width)
|
---|
| 146 | {
|
---|
| 147 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
[170] | 148 | SDMath sdm;
|
---|
| 149 | return CountedPtr<SDMemTable>(sdm.bin(*pIn, Int(width)));
|
---|
[169] | 150 | }
|
---|
| 151 |
|
---|
| 152 |
|
---|
[209] | 153 | void SDMathWrapper::averagePolInSitu(SDMemTableWrapper& in,
|
---|
| 154 | const std::vector<bool>& mask)
|
---|
[169] | 155 | {
|
---|
| 156 | SDMemTable* pIn = in.getPtr();
|
---|
[170] | 157 | SDMath sdm;
|
---|
[235] | 158 | Vector<Bool> tMask(mask);
|
---|
| 159 | SDMemTable* pOut = sdm.averagePol (*pIn, tMask);
|
---|
[169] | 160 | *pIn = *pOut;
|
---|
| 161 | delete pOut;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
[209] | 164 | SDMemTableWrapper SDMathWrapper::averagePol (const SDMemTableWrapper& in,
|
---|
| 165 | const std::vector<bool>& mask)
|
---|
[169] | 166 |
|
---|
| 167 | {
|
---|
| 168 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
[170] | 169 | SDMath sdm;
|
---|
[235] | 170 | Vector<Bool> tMask(mask);
|
---|
| 171 | return CountedPtr<SDMemTable>(sdm.averagePol(*pIn, tMask));
|
---|
[169] | 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | std::vector<float> SDMathWrapper::statistic(const SDMemTableWrapper& in,
|
---|
| 176 | const std::vector<bool>& mask,
|
---|
[235] | 177 | const std::string& which, int row)
|
---|
[169] | 178 | {
|
---|
[170] | 179 | SDMath sdm;
|
---|
[235] | 180 | Vector<Bool> tMask(mask);
|
---|
| 181 | return sdm.statistic(in.getCP(), tMask, String(which), Int(row));
|
---|
[169] | 182 | }
|
---|
[222] | 183 |
|
---|
| 184 |
|
---|
| 185 | void SDMathWrapper::convertFluxInSitu(SDMemTableWrapper& in,
|
---|
| 186 | float area, float eta, bool doAll)
|
---|
| 187 | {
|
---|
| 188 | SDMemTable* pIn = in.getPtr();
|
---|
| 189 | SDMath sdm;
|
---|
| 190 | SDMemTable* pOut = sdm.convertFlux (*pIn, Float(area), Float(eta), Bool(doAll));
|
---|
| 191 | *pIn = *pOut;
|
---|
| 192 | delete pOut;
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | SDMemTableWrapper SDMathWrapper::convertFlux(const SDMemTableWrapper& in,
|
---|
| 197 | float area, float eta, bool doAll)
|
---|
| 198 | {
|
---|
| 199 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
| 200 | SDMath sdm;
|
---|
| 201 | return CountedPtr<SDMemTable>(sdm.convertFlux(*pIn, Float(area), Float(eta), Bool(doAll)));
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[227] | 204 |
|
---|
[235] | 205 | void SDMathWrapper::gainElevationInSitu(SDMemTableWrapper& in,
|
---|
| 206 | const std::vector<float>& coeffs,
|
---|
| 207 | const string& fileName,
|
---|
[227] | 208 | const string& method, bool doAll)
|
---|
| 209 | {
|
---|
| 210 | SDMemTable* pIn = in.getPtr();
|
---|
[235] | 211 | Vector<Float> tCoeffs(coeffs);
|
---|
[227] | 212 | SDMath sdm;
|
---|
[235] | 213 | SDMemTable* pOut = sdm.gainElevation(*pIn, tCoeffs, String(fileName),
|
---|
| 214 | String(method), Bool(doAll));
|
---|
[227] | 215 | *pIn = *pOut;
|
---|
| 216 | delete pOut;
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 |
|
---|
| 220 | SDMemTableWrapper SDMathWrapper::gainElevation(const SDMemTableWrapper& in,
|
---|
[235] | 221 | const std::vector<float>& coeffs,
|
---|
[227] | 222 | const string& fileName,
|
---|
| 223 | const string& method, bool doAll)
|
---|
| 224 | {
|
---|
| 225 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
[235] | 226 | Vector<Float> tCoeffs(coeffs);
|
---|
[227] | 227 | SDMath sdm;
|
---|
[235] | 228 | return CountedPtr<SDMemTable>(sdm.gainElevation(*pIn, tCoeffs, String(fileName),
|
---|
[227] | 229 | String(method), Bool(doAll)));
|
---|
| 230 | }
|
---|
| 231 |
|
---|
[272] | 232 | void SDMathWrapper::velocityAlignmentInSitu (SDMemTableWrapper& in, const std::string& refTime)
|
---|
[268] | 233 | {
|
---|
| 234 | SDMemTable* pIn = in.getPtr();
|
---|
| 235 | SDMath sdm;
|
---|
[272] | 236 | SDMemTable* pOut = sdm.velocityAlignment(*pIn, String(refTime));
|
---|
[268] | 237 | *pIn = *pOut;
|
---|
| 238 | delete pOut;
|
---|
| 239 | }
|
---|
| 240 |
|
---|
| 241 |
|
---|
[272] | 242 | SDMemTableWrapper SDMathWrapper::velocityAlignment (const SDMemTableWrapper& in,
|
---|
| 243 | const std::string& refTime)
|
---|
[262] | 244 | {
|
---|
| 245 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
| 246 | SDMath sdm;
|
---|
[272] | 247 | return CountedPtr<SDMemTable>(sdm.velocityAlignment(*pIn, String(refTime)));
|
---|
[262] | 248 | }
|
---|
| 249 |
|
---|
[235] | 250 | void SDMathWrapper::opacityInSitu(SDMemTableWrapper& in, float tau, bool doAll)
|
---|
| 251 | {
|
---|
| 252 | SDMemTable* pIn = in.getPtr();
|
---|
| 253 | SDMath sdm;
|
---|
| 254 | SDMemTable* pOut = sdm.opacity(*pIn, Float(tau), Bool(doAll));
|
---|
| 255 | *pIn = *pOut;
|
---|
| 256 | delete pOut;
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 |
|
---|
| 260 | SDMemTableWrapper SDMathWrapper::opacity(const SDMemTableWrapper& in,
|
---|
| 261 | float tau, bool doAll)
|
---|
| 262 | {
|
---|
| 263 | const CountedPtr<SDMemTable>& pIn = in.getCP();
|
---|
| 264 | SDMath sdm;
|
---|
| 265 | return CountedPtr<SDMemTable>(sdm.opacity(*pIn, Float(tau), Bool(doAll)));
|
---|
| 266 | }
|
---|
| 267 |
|
---|