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