| 1 | // | 
|---|
| 2 | // C++ Interface: STMathWrapper | 
|---|
| 3 | // | 
|---|
| 4 | // Description: | 
|---|
| 5 | // | 
|---|
| 6 | // | 
|---|
| 7 | // Author: Malte Marquarding <Malte.Marquarding@csiro.au>, (C) 2006 | 
|---|
| 8 | // | 
|---|
| 9 | // Copyright: See COPYING file that comes with this distribution | 
|---|
| 10 | // | 
|---|
| 11 | // | 
|---|
| 12 | #ifndef ASAPSTMATHWRAPPER_H | 
|---|
| 13 | #define ASAPSTMATHWRAPPER_H | 
|---|
| 14 |  | 
|---|
| 15 | #include <vector> | 
|---|
| 16 | #include <string> | 
|---|
| 17 |  | 
|---|
| 18 | #include <casa/Utilities/CountedPtr.h> | 
|---|
| 19 |  | 
|---|
| 20 | #include "STMath.h" | 
|---|
| 21 | #include "Scantable.h" | 
|---|
| 22 | #include "ScantableWrapper.h" | 
|---|
| 23 |  | 
|---|
| 24 | namespace asap { | 
|---|
| 25 |  | 
|---|
| 26 | /** | 
|---|
| 27 | Wrapper class to handle ScantableWrapper | 
|---|
| 28 |  | 
|---|
| 29 | @author Malte Marquarding | 
|---|
| 30 | */ | 
|---|
| 31 | class STMathWrapper : public STMath { | 
|---|
| 32 | public: | 
|---|
| 33 | STMathWrapper() {;} | 
|---|
| 34 | explicit STMathWrapper(bool insitu) : STMath(insitu) {;} | 
|---|
| 35 |  | 
|---|
| 36 | virtual ~STMathWrapper() {;} | 
|---|
| 37 |  | 
|---|
| 38 | ScantableWrapper | 
|---|
| 39 | average( const std::vector<ScantableWrapper>& in, | 
|---|
| 40 | const std::vector<bool>& mask, | 
|---|
| 41 | const std::string& weight, | 
|---|
| 42 | const std::string& avmode ) | 
|---|
| 43 | { | 
|---|
| 44 | std::vector<casa::CountedPtr<Scantable> > sts; | 
|---|
| 45 | for (unsigned int i=0; i<in.size(); ++i) sts.push_back(in[i].getCP()); | 
|---|
| 46 | return ScantableWrapper(STMath::average(sts, mask, weight, avmode)); | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | ScantableWrapper | 
|---|
| 50 | averageChannel( const ScantableWrapper& in, | 
|---|
| 51 | const std::string& mode = "MEDIAN", | 
|---|
| 52 | const std::string& avmode = "NONE") | 
|---|
| 53 | { | 
|---|
| 54 | return ScantableWrapper(STMath::averageChannel(in.getCP(), mode, avmode)); | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 | ScantableWrapper | 
|---|
| 58 | averagePolarisations( const ScantableWrapper& in, | 
|---|
| 59 | const std::vector<bool>& mask, | 
|---|
| 60 | const std::string& weight) | 
|---|
| 61 | { return ScantableWrapper(STMath::averagePolarisations(in.getCP(),mask, weight));} | 
|---|
| 62 |  | 
|---|
| 63 | ScantableWrapper | 
|---|
| 64 | averageBeams( const ScantableWrapper& in, | 
|---|
| 65 | const std::vector<bool>& mask, | 
|---|
| 66 | const std::string& weight) | 
|---|
| 67 |  | 
|---|
| 68 | { return ScantableWrapper(STMath::averageBeams(in.getCP(),mask, weight));} | 
|---|
| 69 |  | 
|---|
| 70 | ScantableWrapper | 
|---|
| 71 | unaryOperate( const ScantableWrapper& in, float val, | 
|---|
| 72 | const std::string& mode, bool tsys=false, | 
|---|
| 73 | bool skip_flaggedrow=false ) | 
|---|
| 74 | { return ScantableWrapper(STMath::unaryOperate(in.getCP(), val, mode, tsys, skip_flaggedrow)); } | 
|---|
| 75 |  | 
|---|
| 76 | ScantableWrapper arrayOperate( const ScantableWrapper& in, | 
|---|
| 77 | const std::vector<float> val, | 
|---|
| 78 | const std::string& mode, | 
|---|
| 79 | bool tsys=false, | 
|---|
| 80 | bool skip_flaggedrow=false ) | 
|---|
| 81 | { return ScantableWrapper(STMath::arrayOperateChannel(in.getCP(), val, mode, tsys, skip_flaggedrow)); } | 
|---|
| 82 |  | 
|---|
| 83 | ScantableWrapper array2dOperate( const ScantableWrapper& in, | 
|---|
| 84 | const std::vector< std::vector<float> > val, | 
|---|
| 85 | const std::string& mode, bool tsys=false ) | 
|---|
| 86 | { return ScantableWrapper(STMath::array2dOperate(in.getCP(), val, mode, tsys)); } | 
|---|
| 87 |  | 
|---|
| 88 | ScantableWrapper binaryOperate( const ScantableWrapper& left, | 
|---|
| 89 | const ScantableWrapper& right, | 
|---|
| 90 | const std::string& mode) | 
|---|
| 91 | { return ScantableWrapper( STMath::binaryOperate( left.getCP(), right.getCP(), | 
|---|
| 92 | mode ) ); } | 
|---|
| 93 |  | 
|---|
| 94 |  | 
|---|
| 95 | ScantableWrapper autoQuotient( const ScantableWrapper& in, | 
|---|
| 96 | const std::string& mode = "NEAREST", | 
|---|
| 97 | bool preserve = true ) | 
|---|
| 98 | { return ScantableWrapper(STMath::autoQuotient(in.getCP(), mode, preserve)); } | 
|---|
| 99 |  | 
|---|
| 100 | ScantableWrapper quotient( const ScantableWrapper& on, | 
|---|
| 101 | const ScantableWrapper& off, | 
|---|
| 102 | bool preserve = true ) | 
|---|
| 103 | { return ScantableWrapper( STMath::quotient( on.getCP(), off.getCP(), | 
|---|
| 104 | preserve ) ); } | 
|---|
| 105 |  | 
|---|
| 106 | ScantableWrapper dototalpower( const ScantableWrapper& calon, | 
|---|
| 107 | const ScantableWrapper& caloff, casa::Float tcal= 0 ) | 
|---|
| 108 | { return ScantableWrapper( STMath::dototalpower( calon.getCP(), caloff.getCP(), tcal ) ); } | 
|---|
| 109 |  | 
|---|
| 110 | ScantableWrapper dosigref( const ScantableWrapper& sig, | 
|---|
| 111 | const ScantableWrapper& ref, | 
|---|
| 112 | int smoothref = 0, casa::Float tsysv=0.0, casa::Float tau=0.0) | 
|---|
| 113 | { return ScantableWrapper( STMath::dosigref( sig.getCP(), ref.getCP(), smoothref, tsysv, tau ) ); } | 
|---|
| 114 |  | 
|---|
| 115 | ScantableWrapper donod( const ScantableWrapper& s, | 
|---|
| 116 | const std::vector<int>& scans, | 
|---|
| 117 | int smoothref = 0, | 
|---|
| 118 | casa::Float tsysv=0.0, casa::Float tau=0.0, casa::Float tcal=0.0 ) | 
|---|
| 119 | { return ScantableWrapper( STMath::donod( s.getCP(), scans, smoothref, tsysv, tau, tcal ) ); } | 
|---|
| 120 |  | 
|---|
| 121 | ScantableWrapper dofs( const ScantableWrapper& s, | 
|---|
| 122 | const std::vector<int>& scans, | 
|---|
| 123 | int smoothref = 0, | 
|---|
| 124 | casa::Float tsysv=0.0, casa::Float tau=0.0, casa::Float tcal=0.0 ) | 
|---|
| 125 | { return ScantableWrapper( STMath::dofs( s.getCP(), scans, smoothref, tsysv, tau, tcal ) ); } | 
|---|
| 126 |  | 
|---|
| 127 | ScantableWrapper | 
|---|
| 128 | freqSwitch( const ScantableWrapper& in ) | 
|---|
| 129 | { return ScantableWrapper(STMath::freqSwitch(in.getCP())); } | 
|---|
| 130 |  | 
|---|
| 131 | std::vector<float> statistic(const ScantableWrapper& in, | 
|---|
| 132 | const std::vector<bool>& mask, | 
|---|
| 133 | const std::string& which) | 
|---|
| 134 | { return STMath::statistic(in.getCP(), mask, which); } | 
|---|
| 135 |  | 
|---|
| 136 | std::vector<float> statisticRow(const ScantableWrapper& in, | 
|---|
| 137 | const std::vector<bool>& mask, | 
|---|
| 138 | const std::string& which, | 
|---|
| 139 | int row) | 
|---|
| 140 | { return STMath::statisticRow(in.getCP(), mask, which, row); } | 
|---|
| 141 |  | 
|---|
| 142 | std::vector<int> minMaxChan(const ScantableWrapper& in, | 
|---|
| 143 | const std::vector<bool>& mask, | 
|---|
| 144 | const std::string& which) | 
|---|
| 145 | { return STMath::minMaxChan(in.getCP(), mask, which); } | 
|---|
| 146 |  | 
|---|
| 147 | ScantableWrapper bin( const ScantableWrapper& in, int width=5) | 
|---|
| 148 | { return ScantableWrapper(STMath::bin(in.getCP(), width)); } | 
|---|
| 149 |  | 
|---|
| 150 | ScantableWrapper | 
|---|
| 151 | resample(const ScantableWrapper& in, | 
|---|
| 152 | const std::string& method, float width) | 
|---|
| 153 | { return ScantableWrapper(STMath::resample(in.getCP(), method, width)); } | 
|---|
| 154 |  | 
|---|
| 155 | ScantableWrapper | 
|---|
| 156 | smooth(const ScantableWrapper& in, const std::string& kernel, float width, | 
|---|
| 157 | int order=2) | 
|---|
| 158 | { return ScantableWrapper(STMath::smooth(in.getCP(), kernel, width, order)); } | 
|---|
| 159 |  | 
|---|
| 160 | ScantableWrapper | 
|---|
| 161 | gainElevation(const ScantableWrapper& in, | 
|---|
| 162 | const std::vector<float>& coeff, | 
|---|
| 163 | const std::string& filename, | 
|---|
| 164 | const std::string& method) | 
|---|
| 165 |  | 
|---|
| 166 | { return | 
|---|
| 167 | ScantableWrapper(STMath::gainElevation(in.getCP(), coeff, filename, method)); } | 
|---|
| 168 |  | 
|---|
| 169 | ScantableWrapper | 
|---|
| 170 | convertFlux(const ScantableWrapper& in, float d, | 
|---|
| 171 | float etaap, float jyperk) | 
|---|
| 172 | { return ScantableWrapper(STMath::convertFlux(in.getCP(), d, etaap, jyperk)); } | 
|---|
| 173 |  | 
|---|
| 174 | ScantableWrapper opacity(const ScantableWrapper& in, | 
|---|
| 175 | const std::vector<float>& tau) | 
|---|
| 176 | { return ScantableWrapper(STMath::opacity(in.getCP(), tau)); } | 
|---|
| 177 |  | 
|---|
| 178 | ScantableWrapper | 
|---|
| 179 | merge(const std::vector<ScantableWrapper >& in, | 
|---|
| 180 | const std::string &freqTol) | 
|---|
| 181 | { | 
|---|
| 182 | std::vector<casa::CountedPtr<Scantable> > sts; | 
|---|
| 183 | for (unsigned int i=0; i<in.size(); ++i) sts.push_back(in[i].getCP()); | 
|---|
| 184 | return ScantableWrapper(STMath::merge(sts, freqTol)); } | 
|---|
| 185 |  | 
|---|
| 186 | ScantableWrapper rotateXYPhase( const ScantableWrapper& in, float angle) | 
|---|
| 187 | { return ScantableWrapper(STMath::rotateXYPhase(in.getCP(), angle)); } | 
|---|
| 188 |  | 
|---|
| 189 | ScantableWrapper rotateLinPolPhase( const ScantableWrapper& in, float angle) | 
|---|
| 190 | { return ScantableWrapper(STMath::rotateLinPolPhase(in.getCP(), angle)); } | 
|---|
| 191 |  | 
|---|
| 192 | ScantableWrapper invertPhase( const ScantableWrapper& in ) | 
|---|
| 193 | { return ScantableWrapper(STMath::invertPhase(in.getCP())); } | 
|---|
| 194 |  | 
|---|
| 195 | ScantableWrapper swapPolarisations( const ScantableWrapper& in ) | 
|---|
| 196 | { return ScantableWrapper(STMath::swapPolarisations(in.getCP())); } | 
|---|
| 197 |  | 
|---|
| 198 | ScantableWrapper frequencyAlign( const ScantableWrapper& in, | 
|---|
| 199 | const std::string& refTime, | 
|---|
| 200 | const std::string& method  ) | 
|---|
| 201 | { return ScantableWrapper(STMath::frequencyAlign(in.getCP(), | 
|---|
| 202 | refTime, method)); } | 
|---|
| 203 |  | 
|---|
| 204 | ScantableWrapper convertPolarisation( const ScantableWrapper& in, | 
|---|
| 205 | const std::string& newtype ) | 
|---|
| 206 | { return ScantableWrapper(STMath::convertPolarisation(in.getCP(),newtype)); } | 
|---|
| 207 |  | 
|---|
| 208 | ScantableWrapper mxExtract( const ScantableWrapper& in, | 
|---|
| 209 | const std::string& scantype="on" ) | 
|---|
| 210 | { return ScantableWrapper(STMath::mxExtract(in.getCP(),scantype)); } | 
|---|
| 211 |  | 
|---|
| 212 | ScantableWrapper lagFlag( const ScantableWrapper& in, | 
|---|
| 213 | double start, double end, | 
|---|
| 214 | const std::string& mode="frequency" ) | 
|---|
| 215 | { return ScantableWrapper(STMath::lagFlag(in.getCP(), start, end, | 
|---|
| 216 | mode)); } | 
|---|
| 217 |  | 
|---|
| 218 | std::vector<float> fft( const ScantableWrapper& in, | 
|---|
| 219 | const std::vector<int>& whichrow, | 
|---|
| 220 | const bool getRealImag=false ) | 
|---|
| 221 | { return STMath::fft(in.getCP(), whichrow, getRealImag); } | 
|---|
| 222 |  | 
|---|
| 223 | // test for average spectra with different channel/resolution | 
|---|
| 224 | ScantableWrapper | 
|---|
| 225 | new_average( const std::vector<ScantableWrapper>& in, | 
|---|
| 226 | const bool& compel, | 
|---|
| 227 | const std::vector<bool>& mask, | 
|---|
| 228 | const std::string& weight, | 
|---|
| 229 | const std::string& avmode ) | 
|---|
| 230 | { | 
|---|
| 231 | std::vector<casa::CountedPtr<Scantable> > sts; | 
|---|
| 232 | for (unsigned int i=0; i<in.size(); ++i) sts.push_back(in[i].getCP()); | 
|---|
| 233 | return ScantableWrapper(STMath::new_average(sts, compel, mask, weight, avmode)); | 
|---|
| 234 | } | 
|---|
| 235 |  | 
|---|
| 236 | // cwcal | 
|---|
| 237 | ScantableWrapper cwcal( const ScantableWrapper &in, | 
|---|
| 238 | const std::string calmode, | 
|---|
| 239 | const std::string antname ) | 
|---|
| 240 | { | 
|---|
| 241 | casa::CountedPtr<Scantable> tab = in.getCP() ; | 
|---|
| 242 | casa::String mode( calmode ) ; | 
|---|
| 243 | casa::String name( antname ) ; | 
|---|
| 244 | return ScantableWrapper( STMath::cwcal( tab, mode, name ) ) ; | 
|---|
| 245 | } | 
|---|
| 246 | // almacal | 
|---|
| 247 | ScantableWrapper almacal( const ScantableWrapper &in, | 
|---|
| 248 | const std::string calmode ) | 
|---|
| 249 | { | 
|---|
| 250 | casa::CountedPtr<Scantable> tab = in.getCP() ; | 
|---|
| 251 | casa::String mode( calmode ) ; | 
|---|
| 252 | return ScantableWrapper( STMath::almacal( tab, mode ) ) ; | 
|---|
| 253 | } | 
|---|
| 254 | }; | 
|---|
| 255 |  | 
|---|
| 256 | } | 
|---|
| 257 |  | 
|---|
| 258 | #endif | 
|---|