source: trunk/src/STMath.h@ 2766

Last change on this file since 2766 was 2658, checked in by Malte Marquarding, 12 years ago

Ticket #199: Excised Logger::pushLog; now everything is using LogIO

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.9 KB
RevLine 
[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
[2177]15#include <map>
[38]16#include <string>
[805]17
[130]18#include <casa/aips.h>
[2177]19#include <casa/Arrays/Vector.h>
20#include <casa/BasicSL/String.h>
[81]21#include <casa/Utilities/CountedPtr.h>
[2177]22
[805]23#include <scimath/Mathematics/InterpolateArray1D.h>
[294]24
[805]25#include "Scantable.h"
[834]26#include "STDefs.h"
[896]27#include "STPol.h"
[2]28
[83]29namespace asap {
[2]30
[805]31/**
[1106]32 * Mathmatical operations on Scantable objects
33 * @author Malte Marquarding
[805]34*/
[2658]35class STMath {
[716]36public:
[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
[1295]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
[1819]121 // array operation
[1308]122 casa::CountedPtr<Scantable>
[1819]123 arrayOperate( const casa::CountedPtr<Scantable>& in,
124 const std::vector<float> val,
125 const std::string& mode,
126 const std::string& opmode="channel",
127 bool tsys=false );
128
129 // channel operation
130 casa::CountedPtr<Scantable>
131 arrayOperateChannel( const casa::CountedPtr<Scantable>& in,
132 const std::vector<float> val,
133 const std::string& mode, bool tsys=false );
134
135 // row operation
136 casa::CountedPtr<Scantable>
137 arrayOperateRow( const casa::CountedPtr<Scantable>& in,
138 const std::vector<float> val,
139 const std::string& mode, bool tsys=false );
140
141 // 2d array operation
142 casa::CountedPtr<Scantable>
143 array2dOperate( const casa::CountedPtr<Scantable>& in,
144 const std::vector< std::vector<float> > val,
145 const std::string& mode, bool tsys=false );
146
147 casa::CountedPtr<Scantable>
[1570]148 binaryOperate( const casa::CountedPtr<Scantable>& left,
149 const casa::CountedPtr<Scantable>& right,
[1308]150 const std::string& mode);
151
[1066]152 casa::CountedPtr<Scantable> autoQuotient(const casa::CountedPtr<Scantable>& in,
153 const std::string& mode = "NEAREST",
154 bool preserve = true);
155
156 casa::CountedPtr<Scantable> quotient( const casa::CountedPtr<Scantable>& on,
157 const casa::CountedPtr<Scantable>& off,
[805]158 bool preserve = true );
[169]159
[1391]160 /**
161 * Calibrate total power scans (translated from GBTIDL)
[1819]162 * @param calon uncalibrated Scantable with CAL noise signal
[1391]163 * @param caloff uncalibrated Scantable with no CAL signal
164 * @param tcal optional scalar Tcal, CAL temperature (K)
[1819]165 * @return casa::CountedPtr<Scantable> which holds a calibrated Scantable
[1391]166 * (spectrum - average of the two CAL on and off spectra;
167 * tsys - mean Tsys = <caloff>*Tcal/<calon-caloff> + Tcal/2)
[1819]168 */
[1391]169 casa::CountedPtr<Scantable> dototalpower( const casa::CountedPtr<Scantable>& calon,
170 const casa::CountedPtr<Scantable>& caloff,
171 casa::Float tcal=1.0 );
172
173 /**
174 * Combine signal and reference scans (translated from GBTIDL)
175 * @param sig Scantable which contains signal scans
176 * @param ref Scantable which contains reference scans
177 * @param smoothref optional Boxcar smooth width of the reference scans
178 * default: no smoothing (=1)
[1819]179 * @param tsysv optional scalar Tsys value at the zenith, required to
180 * set tau, as well
[1391]181 * @param tau optional scalar Tau value
182 * @return casa::CountedPtr<Scantable> which holds combined scans
183 * (spectrum = (sig-ref)/ref * Tsys )
184 */
185 casa::CountedPtr<Scantable> dosigref( const casa::CountedPtr<Scantable>& sig,
186 const casa::CountedPtr<Scantable>& ref,
187 int smoothref=1,
188 casa::Float tsysv=0.0,
189 casa::Float tau=0.0 );
190
[1819]191 /**
[1391]192 * Calibrate GBT Nod scan pairs (translated from GBTIDL)
193 * @param s Scantable which contains Nod scans
194 * @param scans Vector of scan numbers
195 * @param smoothref optional Boxcar smooth width of the reference scans
196 * @param tsysv optional scalar Tsys value at the zenith, required to
197 * set tau, as well
[1819]198 * @param tau optional scalar Tau value
[1391]199 * @param tcal optional scalar Tcal, CAL temperature (K)
200 * @return casa::CountedPtr<Scantable> which holds calibrated scans
201 */
202 casa::CountedPtr<Scantable> donod( const casa::CountedPtr<Scantable>& s,
203 const std::vector<int>& scans,
204 int smoothref=1,
205 casa::Float tsysv=0.0,
206 casa::Float tau=0.0,
207 casa::Float tcal=0.0 );
208
209 /**
210 * Calibrate frequency switched scans (translated from GBTIDL)
211 * @param s Scantable which contains frequency switched scans
212 * @param scans Vector of scan numbers
213 * @param smoothref optional Boxcar smooth width of the reference scans
214 * @param tsysv optional scalar Tsys value at the zenith, required to
215 * set tau, as well
216 * @param tau optional scalar Tau value
217 * @param tcal optional scalar Tcal, CAL temperature (K)
218 * @return casa::CountedPtr<Scantable> which holds calibrated scans
219 */
220 casa::CountedPtr<Scantable> dofs( const casa::CountedPtr<Scantable>& s,
221 const std::vector<int>& scans,
222 int smoothref=1,
223 casa::Float tsysv=0.0,
224 casa::Float tau=0.0,
225 casa::Float tcal=0.0 );
226
[1819]227 /**
228 * Calibrate data with Chopper-Wheel like calibration method
229 * which adopts position switching by antenna motion,
230 * wobbler (nutator) switching and On-The-Fly observation.
231 *
232 * The method is applicable to APEX, and other telescopes other than GBT.
233 *
234 * @param a Scantable which contains ON and OFF scans
235 * @param a string that indicates calibration mode
236 * @param a string that indicates antenna name
237 **/
238 casa::CountedPtr<Scantable> cwcal( const casa::CountedPtr<Scantable>& s,
239 const casa::String calmode,
240 const casa::String antname );
[1391]241
[1819]242 /**
243 * Calibrate frequency switched scans with Chopper-Wheel like
244 * calibration method.
245 *
246 * The method is applicable to APEX, and other telescopes other than GBT.
247 *
248 * @param a Scantable which contains ON and OFF scans
249 * @param a string that indicates antenna name
250 **/
251 casa::CountedPtr<Scantable> cwcalfs( const casa::CountedPtr<Scantable>& s,
252 const casa::String antname );
253
254
255 /**
256 * Folding frequency-switch data
257 * @param sig
258 * @param ref
259 * @param choffset
260 **/
261 casa::CountedPtr<Scantable> dofold( const casa::CountedPtr<Scantable> &sig,
262 const casa::CountedPtr<Scantable> &ref,
263 casa::Double choffset,
[1937]264 casa::Double choffset2 = 0.0 );
[1819]265
266 /**
267 * ALMA calibration
268 **/
269 casa::CountedPtr<Scantable> almacal( const casa::CountedPtr<Scantable>& s,
270 const casa::String calmode ) ;
271 casa::CountedPtr<Scantable> almacalfs( const casa::CountedPtr<Scantable>& s ) ;
272
[805]273 casa::CountedPtr<Scantable>
274 freqSwitch( const casa::CountedPtr<Scantable>& in );
[716]275
[805]276 std::vector<float> statistic(const casa::CountedPtr<Scantable>& in,
277 const std::vector<bool>& mask,
278 const std::string& which);
[457]279
[1907]280 std::vector<float> statisticRow(const casa::CountedPtr<Scantable>& in,
281 const std::vector<bool>& mask,
282 const std::string& which,
283 int row);
284
[1819]285 std::vector< int > minMaxChan(const casa::CountedPtr<Scantable>& in,
286 const std::vector<bool>& mask,
287 const std::string& which);
288
[805]289 casa::CountedPtr<Scantable> bin( const casa::CountedPtr<Scantable>& in,
290 int width=5);
291 casa::CountedPtr<Scantable>
292 resample(const casa::CountedPtr<Scantable>& in,
293 const std::string& method, float width);
[457]294
[805]295 casa::CountedPtr<Scantable>
296 smooth(const casa::CountedPtr<Scantable>& in, const std::string& kernel,
[1570]297 float width, int order=2);
[169]298
[805]299 casa::CountedPtr<Scantable>
300 gainElevation(const casa::CountedPtr<Scantable>& in,
[867]301 const std::vector<float>& coeff,
[805]302 const std::string& fileName,
[995]303 const std::string& method);
[805]304 casa::CountedPtr<Scantable>
305 convertFlux(const casa::CountedPtr<Scantable>& in, float d,
306 float etaap, float jyperk);
[152]307
[805]308 casa::CountedPtr<Scantable> opacity(const casa::CountedPtr<Scantable>& in,
[1689]309 const std::vector<float>& tau);
[144]310
[841]311 casa::CountedPtr<Scantable>
312 merge(const std::vector<casa::CountedPtr<Scantable> >& in);
313
[896]314 casa::CountedPtr<Scantable>
315 invertPhase( const casa::CountedPtr<Scantable>& in);
[912]316
[896]317 casa::CountedPtr<Scantable>
318 rotateXYPhase( const casa::CountedPtr<Scantable>& in, float phase);
[912]319
[896]320 casa::CountedPtr<Scantable>
321 rotateLinPolPhase( const casa::CountedPtr<Scantable>& in, float phase);
322
323 casa::CountedPtr<Scantable>
324 swapPolarisations(const casa::CountedPtr<Scantable>& in);
325
[917]326 casa::CountedPtr<Scantable>
327 frequencyAlign( const casa::CountedPtr<Scantable>& in,
[927]328 const std::string& refTime = "",
329 const std::string& method = "cubic" );
[917]330
[992]331 casa::CountedPtr<Scantable>
332 convertPolarisation( const casa::CountedPtr<Scantable>& in,
333 const std::string& newtype);
[1143]334
[1140]335 casa::CountedPtr<Scantable>
[1143]336 mxExtract( const casa::CountedPtr<Scantable>& in,
337 const std::string& srctype = "on");
[992]338
[1192]339 /**
340 * "hard" flag the data, this flags everything selected in setSelection()
341 * @param frequency the frequency to remove
342 * @param width the number of lags to flag left to the side of the frequency
343 */
344 casa::CountedPtr<Scantable>
[1570]345 lagFlag( const casa::CountedPtr<Scantable>& in, double start,
346 double end, const std::string& mode="frequency");
[1192]347
[2177]348 std::vector<float>
349 fft( const casa::CountedPtr<Scantable>& in,
350 const std::vector<int>& whichrow,
351 bool getRealImag=false );
352
[1819]353 // test for average spectra with different channel/resolution
354 casa::CountedPtr<Scantable>
355 new_average( const std::vector<casa::CountedPtr<Scantable> >& in,
356 const bool& compel,
357 const std::vector<bool>& mask = std::vector<bool>(),
358 const std::string& weight = "NONE",
359 const std::string& avmode = "SCAN" )
360 throw (casa::AipsError) ;
361
[805]362private:
[896]363 casa::CountedPtr<Scantable> applyToPol( const casa::CountedPtr<Scantable>& in,
364 STPol::polOperation fptr,
365 casa::Float phase);
366
[805]367 static imethod stringToIMethod(const std::string& in);
368 static WeightType stringToWeight(const std::string& in);
[146]369
[805]370 void scaleByVector(casa::Table& in,
371 const casa::Vector<casa::Float>& factor,
372 bool dotsys);
[152]373
[805]374 void scaleFromAsciiTable(casa::Table& in, const std::string& filename,
375 const std::string& method,
376 const casa::Vector<casa::Float>& xout,
377 bool dotsys);
[162]378
[805]379 void scaleFromTable(casa::Table& in, const casa::Table& table,
380 const std::string& method,
381 const casa::Vector<casa::Float>& xout, bool dotsys);
[227]382
[805]383 void convertBrightnessUnits(casa::CountedPtr<Scantable>& in,
384 bool tokelvin, float cfac);
[227]385
[1570]386 casa::CountedPtr< Scantable >
[1374]387 smoothOther( const casa::CountedPtr< Scantable >& in,
388 const std::string& kernel,
[1570]389 float width, int order=2 );
[1374]390
[805]391 casa::CountedPtr< Scantable >
392 getScantable(const casa::CountedPtr< Scantable >& in, bool droprows);
[230]393
[805]394 casa::MaskedArray<casa::Float>
395 maskedArray( const casa::Vector<casa::Float>& s,
396 const casa::Vector<casa::uChar>& f );
[1819]397 casa::MaskedArray<casa::Double>
398 maskedArray( const casa::Vector<casa::Double>& s,
399 const casa::Vector<casa::uChar>& f );
[805]400 casa::Vector<casa::uChar>
401 flagsFromMA(const casa::MaskedArray<casa::Float>& ma);
[230]402
[2580]403 casa::Vector<casa::Float> getSpectrumFromTime( double reftime, const casa::Vector<casa::Double> &v, const vector<int> &idx, const casa::Matrix<casa::Float>& sp, string mode = "before" ) ;
404 casa::Vector<casa::Float> getTcalFromTime( double reftime, const casa::Vector<casa::Double> &v, const vector<int> &idx, const casa::CountedPtr<Scantable>& s, string mode="before" ) ;
405 casa::Vector<casa::Float> getTsysFromTime( double reftime, const casa::Vector<casa::Double> &v, const vector<int> &idx, const casa::CountedPtr<Scantable>& s, string mode="before" ) ;
406 vector<int> getRowIdFromTime( double reftime, const casa::Vector<casa::Double>& t ) ;
[1819]407
408 // Chopper-Wheel type calibration
[2580]409 void calibrateCW( casa::CountedPtr<Scantable> &out,
410 const casa::CountedPtr<Scantable> &on,
411 const casa::CountedPtr<Scantable> &off,
412 const casa::CountedPtr<Scantable> &sky,
413 const casa::CountedPtr<Scantable> &hot,
414 const casa::CountedPtr<Scantable> &cold,
415 const casa::Vector<casa::uInt> &rows,
416 const casa::String &antname ) ;
417
[1819]418 // Tsys * (ON-OFF)/OFF
[2580]419 void calibrateALMA( casa::CountedPtr<Scantable>& out,
420 const casa::CountedPtr<Scantable>& on,
421 const casa::CountedPtr<Scantable>& off,
422 const casa::Vector<casa::uInt>& rows ) ;
[1819]423
[2580]424 // Frequency switching
425 void calibrateFS( casa::CountedPtr<Scantable> &sig,
426 casa::CountedPtr<Scantable> &ref,
427 const casa::CountedPtr<Scantable> &rsig,
428 const casa::CountedPtr<Scantable> &rref,
429 const casa::CountedPtr<Scantable> &sky,
430 const casa::CountedPtr<Scantable> &hot,
431 const casa::CountedPtr<Scantable> &cold,
432 const casa::Vector<casa::uInt> &rows ) ;
433 void calibrateAPEXFS( casa::CountedPtr<Scantable> &sig,
434 casa::CountedPtr<Scantable> &ref,
435 const vector< casa::CountedPtr<Scantable> > &on,
436 const vector< casa::CountedPtr<Scantable> > &sky,
437 const vector< casa::CountedPtr<Scantable> > &hot,
438 const vector< casa::CountedPtr<Scantable> > &cold,
439 const casa::Vector<casa::uInt> &rows ) ;
440 void copyRows( casa::Table &out,
441 const casa::Table &in,
442 casa::uInt startout,
443 casa::uInt startin,
444 casa::uInt nrow,
445 casa::Bool copySpectra=true,
446 casa::Bool copyFlagtra=true,
447 casa::Bool copyTsys=true ) ;
448 casa::CountedPtr<Scantable> averageWithinSession( casa::CountedPtr<Scantable> &s,
449 vector<bool> &mask,
450 string weight ) ;
451
[805]452 bool insitu_;
453};
[234]454
[805]455}
[165]456#endif
Note: See TracBrowser for help on using the repository browser.