[805] | 1 | //
|
---|
| 2 | // C++ Interface: STMath
|
---|
| 3 | //
|
---|
| 4 | // Description:
|
---|
| 5 | //
|
---|
| 6 | //
|
---|
| 7 | // Author: Malte Marquarding <asap@atnf.csiro.au>, (C) 2006
|
---|
| 8 | //
|
---|
| 9 | // Copyright: See COPYING file that comes with this distribution
|
---|
| 10 | //
|
---|
| 11 | //
|
---|
| 12 | #ifndef ASAPSTMATH_H
|
---|
| 13 | #define ASAPSTMATH_H
|
---|
[2] | 14 |
|
---|
[38] | 15 | #include <string>
|
---|
[805] | 16 | #include <map>
|
---|
| 17 |
|
---|
[130] | 18 | #include <casa/aips.h>
|
---|
[81] | 19 | #include <casa/Utilities/CountedPtr.h>
|
---|
[805] | 20 | #include <casa/BasicSL/String.h>
|
---|
| 21 | #include <casa/Arrays/Vector.h>
|
---|
| 22 | #include <scimath/Mathematics/InterpolateArray1D.h>
|
---|
[294] | 23 |
|
---|
[805] | 24 | #include "Scantable.h"
|
---|
[834] | 25 | #include "STDefs.h"
|
---|
[896] | 26 | #include "STPol.h"
|
---|
[894] | 27 | #include "Logger.h"
|
---|
[2] | 28 |
|
---|
[83] | 29 | namespace asap {
|
---|
[2] | 30 |
|
---|
[805] | 31 | /**
|
---|
[1106] | 32 | * Mathmatical operations on Scantable objects
|
---|
| 33 | * @author Malte Marquarding
|
---|
[805] | 34 | */
|
---|
[890] | 35 | class STMath : private Logger {
|
---|
[716] | 36 | public:
|
---|
[1106] | 37 | // typedef for long method name
|
---|
[805] | 38 | typedef casa::InterpolateArray1D<casa::Double,
|
---|
| 39 | casa::Float>::InterpolationMethod imethod;
|
---|
[299] | 40 |
|
---|
[1106] | 41 | // typedef for std::map
|
---|
[805] | 42 | typedef std::map<std::string, imethod> imap;
|
---|
[177] | 43 |
|
---|
[1106] | 44 | /**
|
---|
| 45 | * whether to operate on the given Scantable or return a new one
|
---|
| 46 | * @param insitu the toggle for this behaviour
|
---|
| 47 | */
|
---|
[1353] | 48 | explicit STMath(bool insitu=true);
|
---|
[221] | 49 |
|
---|
[995] | 50 | virtual ~STMath();
|
---|
[227] | 51 |
|
---|
[805] | 52 | /**
|
---|
[1295] | 53 | * get the currnt @attr inistu_ state
|
---|
[805] | 54 | */
|
---|
| 55 | bool insitu() const { return insitu_;};
|
---|
[1143] | 56 |
|
---|
[1106] | 57 | /**
|
---|
| 58 | * set the currnt @attr inistu state
|
---|
| 59 | * @param b the new state
|
---|
| 60 | */
|
---|
[805] | 61 | void setInsitu(bool b) { insitu_ = b; };
|
---|
[262] | 62 |
|
---|
[1106] | 63 |
|
---|
[1140] | 64 | /**
|
---|
| 65 | * average a vector of Scantables
|
---|
| 66 | * @param in the vector of Scantables to average
|
---|
[1603] | 67 | * @param mask an optional mask to apply on specific weights
|
---|
[1140] | 68 | * @param weight weighting scheme
|
---|
| 69 | * @param avmode the mode ov averaging. Per "SCAN" or "ALL".
|
---|
| 70 | * @return a casa::CountedPtr<Scantable> which either holds a new Scantable
|
---|
| 71 | * or returns the imput pointer.
|
---|
| 72 | */
|
---|
[805] | 73 | casa::CountedPtr<Scantable>
|
---|
| 74 | average( const std::vector<casa::CountedPtr<Scantable> >& in,
|
---|
[858] | 75 | const std::vector<bool>& mask = std::vector<bool>(),
|
---|
| 76 | const std::string& weight = "NONE",
|
---|
[977] | 77 | const std::string& avmode = "SCAN");
|
---|
[1066] | 78 |
|
---|
[1140] | 79 | /**
|
---|
| 80 | * median average a vector of Scantables. See also STMath::average
|
---|
| 81 | * @param in the Scantable to average
|
---|
| 82 | * @param mode the averaging mode. Currently only "MEDIAN"
|
---|
| 83 | * @param avmode the mode ov averaging. Per "SCAN" or "ALL".
|
---|
| 84 | * @return a casa::CountedPtr<Scantable> which either holds a new Scantable
|
---|
| 85 | * or returns the imput pointer.
|
---|
| 86 | */
|
---|
[1069] | 87 | casa::CountedPtr<Scantable>
|
---|
| 88 | averageChannel( const casa::CountedPtr<Scantable> & in,
|
---|
[1078] | 89 | const std::string& mode = "MEDIAN",
|
---|
| 90 | const std::string& avmode = "SCAN");
|
---|
[1069] | 91 |
|
---|
[1140] | 92 | /**
|
---|
[1145] | 93 | * Average polarisations together. really only useful if only linears are
|
---|
| 94 | * available.
|
---|
[1140] | 95 | * @param in the input Scantable
|
---|
| 96 | * @param mask an optional mask if weight allows one
|
---|
| 97 | * @param weight weighting scheme
|
---|
[1143] | 98 | * @return
|
---|
[1140] | 99 | */
|
---|
[940] | 100 | casa::CountedPtr< Scantable >
|
---|
| 101 | averagePolarisations( const casa::CountedPtr< Scantable > & in,
|
---|
[1140] | 102 | const std::vector<bool>& mask,
|
---|
| 103 | const std::string& weight );
|
---|
[234] | 104 |
|
---|
[1145] | 105 | /**
|
---|
| 106 | * Average beams together.
|
---|
| 107 | * @param in the input Scantable
|
---|
| 108 | * @param mask an optional mask if weight allows one
|
---|
| 109 | * @param weight weighting scheme
|
---|
| 110 | * @return
|
---|
| 111 | */
|
---|
| 112 | casa::CountedPtr< Scantable >
|
---|
| 113 | averageBeams( const casa::CountedPtr< Scantable > & in,
|
---|
| 114 | const std::vector<bool>& mask,
|
---|
| 115 | const std::string& weight );
|
---|
| 116 |
|
---|
[805] | 117 | casa::CountedPtr<Scantable>
|
---|
| 118 | unaryOperate( const casa::CountedPtr<Scantable>& in, float val,
|
---|
| 119 | const std::string& mode, bool tsys=false );
|
---|
[169] | 120 |
|
---|
[1308] | 121 | casa::CountedPtr<Scantable>
|
---|
| 122 | binaryOperate( const casa::CountedPtr<Scantable>& left,
|
---|
| 123 | const casa::CountedPtr<Scantable>& right,
|
---|
| 124 | const std::string& mode);
|
---|
| 125 |
|
---|
[1066] | 126 | casa::CountedPtr<Scantable> autoQuotient(const casa::CountedPtr<Scantable>& in,
|
---|
| 127 | const std::string& mode = "NEAREST",
|
---|
| 128 | bool preserve = true);
|
---|
| 129 |
|
---|
| 130 | casa::CountedPtr<Scantable> quotient( const casa::CountedPtr<Scantable>& on,
|
---|
| 131 | const casa::CountedPtr<Scantable>& off,
|
---|
[805] | 132 | bool preserve = true );
|
---|
[169] | 133 |
|
---|
[1388] | 134 | /**
|
---|
| 135 | * Calibrate total power scans (translated from GBTIDL)
|
---|
[1446] | 136 | * @param calon uncalibrated Scantable with CAL noise signal
|
---|
[1388] | 137 | * @param caloff uncalibrated Scantable with no CAL signal
|
---|
| 138 | * @param tcal optional scalar Tcal, CAL temperature (K)
|
---|
[1446] | 139 | * @return casa::CountedPtr<Scantable> which holds a calibrated Scantable
|
---|
[1388] | 140 | * (spectrum - average of the two CAL on and off spectra;
|
---|
| 141 | * tsys - mean Tsys = <caloff>*Tcal/<calon-caloff> + Tcal/2)
|
---|
[1446] | 142 | */
|
---|
[1388] | 143 | casa::CountedPtr<Scantable> dototalpower( const casa::CountedPtr<Scantable>& calon,
|
---|
| 144 | const casa::CountedPtr<Scantable>& caloff,
|
---|
| 145 | casa::Float tcal=1.0 );
|
---|
| 146 |
|
---|
| 147 | /**
|
---|
| 148 | * Combine signal and reference scans (translated from GBTIDL)
|
---|
| 149 | * @param sig Scantable which contains signal scans
|
---|
| 150 | * @param ref Scantable which contains reference scans
|
---|
| 151 | * @param smoothref optional Boxcar smooth width of the reference scans
|
---|
| 152 | * default: no smoothing (=1)
|
---|
[1446] | 153 | * @param tsysv optional scalar Tsys value at the zenith, required to
|
---|
| 154 | * set tau, as well
|
---|
[1388] | 155 | * @param tau optional scalar Tau value
|
---|
| 156 | * @return casa::CountedPtr<Scantable> which holds combined scans
|
---|
| 157 | * (spectrum = (sig-ref)/ref * Tsys )
|
---|
| 158 | */
|
---|
| 159 | casa::CountedPtr<Scantable> dosigref( const casa::CountedPtr<Scantable>& sig,
|
---|
| 160 | const casa::CountedPtr<Scantable>& ref,
|
---|
| 161 | int smoothref=1,
|
---|
| 162 | casa::Float tsysv=0.0,
|
---|
| 163 | casa::Float tau=0.0 );
|
---|
| 164 |
|
---|
[1446] | 165 | /**
|
---|
[1388] | 166 | * Calibrate GBT Nod scan pairs (translated from GBTIDL)
|
---|
| 167 | * @param s Scantable which contains Nod scans
|
---|
| 168 | * @param scans Vector of scan numbers
|
---|
| 169 | * @param smoothref optional Boxcar smooth width of the reference scans
|
---|
| 170 | * @param tsysv optional scalar Tsys value at the zenith, required to
|
---|
| 171 | * set tau, as well
|
---|
[1446] | 172 | * @param tau optional scalar Tau value
|
---|
[1388] | 173 | * @param tcal optional scalar Tcal, CAL temperature (K)
|
---|
| 174 | * @return casa::CountedPtr<Scantable> which holds calibrated scans
|
---|
| 175 | */
|
---|
| 176 | casa::CountedPtr<Scantable> donod( const casa::CountedPtr<Scantable>& s,
|
---|
| 177 | const std::vector<int>& scans,
|
---|
| 178 | int smoothref=1,
|
---|
| 179 | casa::Float tsysv=0.0,
|
---|
| 180 | casa::Float tau=0.0,
|
---|
| 181 | casa::Float tcal=0.0 );
|
---|
| 182 |
|
---|
| 183 | /**
|
---|
| 184 | * Calibrate frequency switched scans (translated from GBTIDL)
|
---|
| 185 | * @param s Scantable which contains frequency switched scans
|
---|
| 186 | * @param scans Vector of scan numbers
|
---|
| 187 | * @param smoothref optional Boxcar smooth width of the reference scans
|
---|
| 188 | * @param tsysv optional scalar Tsys value at the zenith, required to
|
---|
| 189 | * set tau, as well
|
---|
| 190 | * @param tau optional scalar Tau value
|
---|
| 191 | * @param tcal optional scalar Tcal, CAL temperature (K)
|
---|
| 192 | * @return casa::CountedPtr<Scantable> which holds calibrated scans
|
---|
| 193 | */
|
---|
| 194 | casa::CountedPtr<Scantable> dofs( const casa::CountedPtr<Scantable>& s,
|
---|
| 195 | const std::vector<int>& scans,
|
---|
| 196 | int smoothref=1,
|
---|
| 197 | casa::Float tsysv=0.0,
|
---|
| 198 | casa::Float tau=0.0,
|
---|
| 199 | casa::Float tcal=0.0 );
|
---|
| 200 |
|
---|
[1609] | 201 | /**
|
---|
[1633] | 202 | * Calibrate data with Chopper-Wheel like calibration method
|
---|
| 203 | * which adopts position switching by antenna motion,
|
---|
| 204 | * wobbler (nutator) switching and On-The-Fly observation.
|
---|
| 205 | *
|
---|
| 206 | * The method is applicable to APEX, and other telescopes other than GBT.
|
---|
| 207 | *
|
---|
| 208 | * @param a Scantable which contains ON and OFF scans
|
---|
| 209 | * @param a string that indicates calibration mode
|
---|
| 210 | * @param a string that indicates antenna name
|
---|
| 211 | **/
|
---|
| 212 | casa::CountedPtr<Scantable> cwcal( const casa::CountedPtr<Scantable>& s,
|
---|
| 213 | const casa::String calmode,
|
---|
| 214 | const casa::String antname );
|
---|
| 215 |
|
---|
| 216 | /**
|
---|
| 217 | * Calibrate frequency switched scans with Chopper-Wheel like
|
---|
| 218 | * calibration method.
|
---|
| 219 | *
|
---|
| 220 | * The method is applicable to APEX, and other telescopes other than GBT.
|
---|
| 221 | *
|
---|
| 222 | * @param a Scantable which contains ON and OFF scans
|
---|
| 223 | * @param a string that indicates antenna name
|
---|
| 224 | **/
|
---|
| 225 | casa::CountedPtr<Scantable> cwcalfs( const casa::CountedPtr<Scantable>& s,
|
---|
| 226 | const casa::String antname );
|
---|
| 227 |
|
---|
| 228 |
|
---|
| 229 | /**
|
---|
[1609] | 230 | * Folding frequency-switch data
|
---|
| 231 | * @param sig
|
---|
| 232 | * @param ref
|
---|
| 233 | * @param choffset
|
---|
| 234 | **/
|
---|
| 235 | casa::CountedPtr<Scantable> dofold( const casa::CountedPtr<Scantable> &sig,
|
---|
| 236 | const casa::CountedPtr<Scantable> &ref,
|
---|
[1633] | 237 | casa::Double choffset,
|
---|
| 238 | casa::Double choffset = 0.0 );
|
---|
[1388] | 239 |
|
---|
[805] | 240 | casa::CountedPtr<Scantable>
|
---|
| 241 | freqSwitch( const casa::CountedPtr<Scantable>& in );
|
---|
[716] | 242 |
|
---|
[805] | 243 | std::vector<float> statistic(const casa::CountedPtr<Scantable>& in,
|
---|
| 244 | const std::vector<bool>& mask,
|
---|
| 245 | const std::string& which);
|
---|
[457] | 246 |
|
---|
[1516] | 247 | std::vector< int > minMaxChan(const casa::CountedPtr<Scantable>& in,
|
---|
| 248 | const std::vector<bool>& mask,
|
---|
| 249 | const std::string& which);
|
---|
[1514] | 250 |
|
---|
[805] | 251 | casa::CountedPtr<Scantable> bin( const casa::CountedPtr<Scantable>& in,
|
---|
| 252 | int width=5);
|
---|
| 253 | casa::CountedPtr<Scantable>
|
---|
| 254 | resample(const casa::CountedPtr<Scantable>& in,
|
---|
| 255 | const std::string& method, float width);
|
---|
[457] | 256 |
|
---|
[805] | 257 | casa::CountedPtr<Scantable>
|
---|
| 258 | smooth(const casa::CountedPtr<Scantable>& in, const std::string& kernel,
|
---|
[995] | 259 | float width);
|
---|
[169] | 260 |
|
---|
[805] | 261 | casa::CountedPtr<Scantable>
|
---|
| 262 | gainElevation(const casa::CountedPtr<Scantable>& in,
|
---|
[867] | 263 | const std::vector<float>& coeff,
|
---|
[805] | 264 | const std::string& fileName,
|
---|
[995] | 265 | const std::string& method);
|
---|
[805] | 266 | casa::CountedPtr<Scantable>
|
---|
| 267 | convertFlux(const casa::CountedPtr<Scantable>& in, float d,
|
---|
| 268 | float etaap, float jyperk);
|
---|
[152] | 269 |
|
---|
[805] | 270 | casa::CountedPtr<Scantable> opacity(const casa::CountedPtr<Scantable>& in,
|
---|
| 271 | float tau);
|
---|
[144] | 272 |
|
---|
[841] | 273 | casa::CountedPtr<Scantable>
|
---|
| 274 | merge(const std::vector<casa::CountedPtr<Scantable> >& in);
|
---|
| 275 |
|
---|
[896] | 276 | casa::CountedPtr<Scantable>
|
---|
| 277 | invertPhase( const casa::CountedPtr<Scantable>& in);
|
---|
[912] | 278 |
|
---|
[896] | 279 | casa::CountedPtr<Scantable>
|
---|
| 280 | rotateXYPhase( const casa::CountedPtr<Scantable>& in, float phase);
|
---|
[912] | 281 |
|
---|
[896] | 282 | casa::CountedPtr<Scantable>
|
---|
| 283 | rotateLinPolPhase( const casa::CountedPtr<Scantable>& in, float phase);
|
---|
| 284 |
|
---|
| 285 | casa::CountedPtr<Scantable>
|
---|
| 286 | swapPolarisations(const casa::CountedPtr<Scantable>& in);
|
---|
| 287 |
|
---|
[917] | 288 | casa::CountedPtr<Scantable>
|
---|
| 289 | frequencyAlign( const casa::CountedPtr<Scantable>& in,
|
---|
[927] | 290 | const std::string& refTime = "",
|
---|
| 291 | const std::string& method = "cubic" );
|
---|
[917] | 292 |
|
---|
[992] | 293 | casa::CountedPtr<Scantable>
|
---|
| 294 | convertPolarisation( const casa::CountedPtr<Scantable>& in,
|
---|
| 295 | const std::string& newtype);
|
---|
[1143] | 296 |
|
---|
[1140] | 297 | casa::CountedPtr<Scantable>
|
---|
[1143] | 298 | mxExtract( const casa::CountedPtr<Scantable>& in,
|
---|
| 299 | const std::string& srctype = "on");
|
---|
[992] | 300 |
|
---|
[1192] | 301 | /**
|
---|
| 302 | * "hard" flag the data, this flags everything selected in setSelection()
|
---|
| 303 | * @param frequency the frequency to remove
|
---|
| 304 | * @param width the number of lags to flag left to the side of the frequency
|
---|
| 305 | */
|
---|
| 306 | casa::CountedPtr<Scantable>
|
---|
| 307 | lagFlag( const casa::CountedPtr<Scantable>& in, double frequency,
|
---|
[1200] | 308 | double width);
|
---|
[1192] | 309 |
|
---|
[1446] | 310 | // test for average spectra with different channel/resolution
|
---|
| 311 | casa::CountedPtr<Scantable>
|
---|
| 312 | new_average( const std::vector<casa::CountedPtr<Scantable> >& in,
|
---|
| 313 | const bool& compel,
|
---|
| 314 | const std::vector<bool>& mask = std::vector<bool>(),
|
---|
| 315 | const std::string& weight = "NONE",
|
---|
| 316 | const std::string& avmode = "SCAN" )
|
---|
| 317 | throw (casa::AipsError) ;
|
---|
| 318 |
|
---|
| 319 |
|
---|
[805] | 320 | private:
|
---|
[896] | 321 | casa::CountedPtr<Scantable> applyToPol( const casa::CountedPtr<Scantable>& in,
|
---|
| 322 | STPol::polOperation fptr,
|
---|
| 323 | casa::Float phase);
|
---|
| 324 |
|
---|
[805] | 325 | static imethod stringToIMethod(const std::string& in);
|
---|
| 326 | static WeightType stringToWeight(const std::string& in);
|
---|
[146] | 327 |
|
---|
[805] | 328 | void scaleByVector(casa::Table& in,
|
---|
| 329 | const casa::Vector<casa::Float>& factor,
|
---|
| 330 | bool dotsys);
|
---|
[152] | 331 |
|
---|
[805] | 332 | void scaleFromAsciiTable(casa::Table& in, const std::string& filename,
|
---|
| 333 | const std::string& method,
|
---|
| 334 | const casa::Vector<casa::Float>& xout,
|
---|
| 335 | bool dotsys);
|
---|
[162] | 336 |
|
---|
[805] | 337 | void scaleFromTable(casa::Table& in, const casa::Table& table,
|
---|
| 338 | const std::string& method,
|
---|
| 339 | const casa::Vector<casa::Float>& xout, bool dotsys);
|
---|
[227] | 340 |
|
---|
[805] | 341 | void convertBrightnessUnits(casa::CountedPtr<Scantable>& in,
|
---|
| 342 | bool tokelvin, float cfac);
|
---|
[227] | 343 |
|
---|
[1374] | 344 | casa::CountedPtr< Scantable >
|
---|
| 345 | smoothOther( const casa::CountedPtr< Scantable >& in,
|
---|
| 346 | const std::string& kernel,
|
---|
| 347 | float width );
|
---|
| 348 |
|
---|
[805] | 349 | casa::CountedPtr< Scantable >
|
---|
| 350 | getScantable(const casa::CountedPtr< Scantable >& in, bool droprows);
|
---|
[230] | 351 |
|
---|
[805] | 352 | casa::MaskedArray<casa::Float>
|
---|
| 353 | maskedArray( const casa::Vector<casa::Float>& s,
|
---|
| 354 | const casa::Vector<casa::uChar>& f );
|
---|
[1607] | 355 | casa::MaskedArray<casa::Double>
|
---|
| 356 | maskedArray( const casa::Vector<casa::Double>& s,
|
---|
| 357 | const casa::Vector<casa::uChar>& f );
|
---|
[805] | 358 | casa::Vector<casa::uChar>
|
---|
| 359 | flagsFromMA(const casa::MaskedArray<casa::Float>& ma);
|
---|
[230] | 360 |
|
---|
[1633] | 361 | vector<float> getSpectrumFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode = "before" ) ;
|
---|
| 362 | vector<float> getTcalFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode="before" ) ;
|
---|
| 363 | vector<int> getRowIdFromTime( string reftime, casa::CountedPtr<Scantable>& s ) ;
|
---|
| 364 | vector<float> getCalibratedSpectra( casa::CountedPtr<Scantable>& on,
|
---|
| 365 | casa::CountedPtr<Scantable>& off,
|
---|
| 366 | casa::CountedPtr<Scantable>& sky,
|
---|
| 367 | casa::CountedPtr<Scantable>& hot,
|
---|
| 368 | casa::CountedPtr<Scantable>& cold,
|
---|
| 369 | int index,
|
---|
| 370 | string antname ) ;
|
---|
| 371 | vector<float> getFSCalibratedSpectra( casa::CountedPtr<Scantable>& sig,
|
---|
| 372 | casa::CountedPtr<Scantable>& ref,
|
---|
| 373 | casa::CountedPtr<Scantable>& sky,
|
---|
| 374 | casa::CountedPtr<Scantable>& hot,
|
---|
| 375 | casa::CountedPtr<Scantable>& cold,
|
---|
| 376 | int index ) ;
|
---|
| 377 | vector<float> getFSCalibratedSpectra( casa::CountedPtr<Scantable>& sig,
|
---|
| 378 | casa::CountedPtr<Scantable>& ref,
|
---|
| 379 | vector< casa::CountedPtr<Scantable> >& sky,
|
---|
| 380 | vector< casa::CountedPtr<Scantable> >& hot,
|
---|
| 381 | vector< casa::CountedPtr<Scantable> >& cold,
|
---|
| 382 | int index ) ;
|
---|
| 383 | double getMJD( string strtime ) ;
|
---|
| 384 |
|
---|
[805] | 385 | bool insitu_;
|
---|
| 386 | };
|
---|
[234] | 387 |
|
---|
[805] | 388 | }
|
---|
[165] | 389 | #endif
|
---|