source: branches/hpc34/src/STMath.h@ 2926

Last change on this file since 2926 was 2580, checked in by ShinnosukeKawakami, 12 years ago

hpc33 merged asap-trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.0 KB
Line 
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
14
15#include <map>
16#include <string>
17
18#include <casa/aips.h>
19#include <casa/Arrays/Vector.h>
20#include <casa/BasicSL/String.h>
21#include <casa/Utilities/CountedPtr.h>
22
23#include <scimath/Mathematics/InterpolateArray1D.h>
24
25#include "Logger.h"
26#include "Scantable.h"
27#include "STDefs.h"
28#include "STPol.h"
29
30namespace asap {
31
32/**
33 * Mathmatical operations on Scantable objects
34 * @author Malte Marquarding
35*/
36class STMath : private Logger {
37public:
38 // typedef for long method name
39 typedef casa::InterpolateArray1D<casa::Double,
40 casa::Float>::InterpolationMethod imethod;
41
42 // typedef for std::map
43 typedef std::map<std::string, imethod> imap;
44
45/**
46 * whether to operate on the given Scantable or return a new one
47 * @param insitu the toggle for this behaviour
48 */
49 explicit STMath(bool insitu=true);
50
51 virtual ~STMath();
52
53 /**
54 * get the currnt @attr inistu_ state
55 */
56 bool insitu() const { return insitu_;};
57
58 /**
59 * set the currnt @attr inistu state
60 * @param b the new state
61 */
62 void setInsitu(bool b) { insitu_ = b; };
63
64
65 /**
66 * average a vector of Scantables
67 * @param in the vector of Scantables to average
68 * @param mask an optional mask to apply on specific weights
69 * @param weight weighting scheme
70 * @param avmode the mode ov averaging. Per "SCAN" or "ALL".
71 * @return a casa::CountedPtr<Scantable> which either holds a new Scantable
72 * or returns the imput pointer.
73 */
74 casa::CountedPtr<Scantable>
75 average( const std::vector<casa::CountedPtr<Scantable> >& in,
76 const std::vector<bool>& mask = std::vector<bool>(),
77 const std::string& weight = "NONE",
78 const std::string& avmode = "SCAN");
79
80 /**
81 * median average a vector of Scantables. See also STMath::average
82 * @param in the Scantable to average
83 * @param mode the averaging mode. Currently only "MEDIAN"
84 * @param avmode the mode ov averaging. Per "SCAN" or "ALL".
85 * @return a casa::CountedPtr<Scantable> which either holds a new Scantable
86 * or returns the imput pointer.
87 */
88 casa::CountedPtr<Scantable>
89 averageChannel( const casa::CountedPtr<Scantable> & in,
90 const std::string& mode = "MEDIAN",
91 const std::string& avmode = "SCAN");
92
93 /**
94 * Average polarisations together. really only useful if only linears are
95 * available.
96 * @param in the input Scantable
97 * @param mask an optional mask if weight allows one
98 * @param weight weighting scheme
99 * @return
100 */
101 casa::CountedPtr< Scantable >
102 averagePolarisations( const casa::CountedPtr< Scantable > & in,
103 const std::vector<bool>& mask,
104 const std::string& weight );
105
106 /**
107 * Average beams together.
108 * @param in the input Scantable
109 * @param mask an optional mask if weight allows one
110 * @param weight weighting scheme
111 * @return
112 */
113 casa::CountedPtr< Scantable >
114 averageBeams( const casa::CountedPtr< Scantable > & in,
115 const std::vector<bool>& mask,
116 const std::string& weight );
117
118 casa::CountedPtr<Scantable>
119 unaryOperate( const casa::CountedPtr<Scantable>& in, float val,
120 const std::string& mode, bool tsys=false );
121
122 // array operation
123 casa::CountedPtr<Scantable>
124 arrayOperate( const casa::CountedPtr<Scantable>& in,
125 const std::vector<float> val,
126 const std::string& mode,
127 const std::string& opmode="channel",
128 bool tsys=false );
129
130 // channel operation
131 casa::CountedPtr<Scantable>
132 arrayOperateChannel( const casa::CountedPtr<Scantable>& in,
133 const std::vector<float> val,
134 const std::string& mode, bool tsys=false );
135
136 // row operation
137 casa::CountedPtr<Scantable>
138 arrayOperateRow( const casa::CountedPtr<Scantable>& in,
139 const std::vector<float> val,
140 const std::string& mode, bool tsys=false );
141
142 // 2d array operation
143 casa::CountedPtr<Scantable>
144 array2dOperate( const casa::CountedPtr<Scantable>& in,
145 const std::vector< std::vector<float> > val,
146 const std::string& mode, bool tsys=false );
147
148 casa::CountedPtr<Scantable>
149 binaryOperate( const casa::CountedPtr<Scantable>& left,
150 const casa::CountedPtr<Scantable>& right,
151 const std::string& mode);
152
153 casa::CountedPtr<Scantable> autoQuotient(const casa::CountedPtr<Scantable>& in,
154 const std::string& mode = "NEAREST",
155 bool preserve = true);
156
157 casa::CountedPtr<Scantable> quotient( const casa::CountedPtr<Scantable>& on,
158 const casa::CountedPtr<Scantable>& off,
159 bool preserve = true );
160
161 /**
162 * Calibrate total power scans (translated from GBTIDL)
163 * @param calon uncalibrated Scantable with CAL noise signal
164 * @param caloff uncalibrated Scantable with no CAL signal
165 * @param tcal optional scalar Tcal, CAL temperature (K)
166 * @return casa::CountedPtr<Scantable> which holds a calibrated Scantable
167 * (spectrum - average of the two CAL on and off spectra;
168 * tsys - mean Tsys = <caloff>*Tcal/<calon-caloff> + Tcal/2)
169 */
170 casa::CountedPtr<Scantable> dototalpower( const casa::CountedPtr<Scantable>& calon,
171 const casa::CountedPtr<Scantable>& caloff,
172 casa::Float tcal=1.0 );
173
174 /**
175 * Combine signal and reference scans (translated from GBTIDL)
176 * @param sig Scantable which contains signal scans
177 * @param ref Scantable which contains reference scans
178 * @param smoothref optional Boxcar smooth width of the reference scans
179 * default: no smoothing (=1)
180 * @param tsysv optional scalar Tsys value at the zenith, required to
181 * set tau, as well
182 * @param tau optional scalar Tau value
183 * @return casa::CountedPtr<Scantable> which holds combined scans
184 * (spectrum = (sig-ref)/ref * Tsys )
185 */
186 casa::CountedPtr<Scantable> dosigref( const casa::CountedPtr<Scantable>& sig,
187 const casa::CountedPtr<Scantable>& ref,
188 int smoothref=1,
189 casa::Float tsysv=0.0,
190 casa::Float tau=0.0 );
191
192 /**
193 * Calibrate GBT Nod scan pairs (translated from GBTIDL)
194 * @param s Scantable which contains Nod scans
195 * @param scans Vector of scan numbers
196 * @param smoothref optional Boxcar smooth width of the reference scans
197 * @param tsysv optional scalar Tsys value at the zenith, required to
198 * set tau, as well
199 * @param tau optional scalar Tau value
200 * @param tcal optional scalar Tcal, CAL temperature (K)
201 * @return casa::CountedPtr<Scantable> which holds calibrated scans
202 */
203 casa::CountedPtr<Scantable> donod( const casa::CountedPtr<Scantable>& s,
204 const std::vector<int>& scans,
205 int smoothref=1,
206 casa::Float tsysv=0.0,
207 casa::Float tau=0.0,
208 casa::Float tcal=0.0 );
209
210 /**
211 * Calibrate frequency switched scans (translated from GBTIDL)
212 * @param s Scantable which contains frequency switched scans
213 * @param scans Vector of scan numbers
214 * @param smoothref optional Boxcar smooth width of the reference scans
215 * @param tsysv optional scalar Tsys value at the zenith, required to
216 * set tau, as well
217 * @param tau optional scalar Tau value
218 * @param tcal optional scalar Tcal, CAL temperature (K)
219 * @return casa::CountedPtr<Scantable> which holds calibrated scans
220 */
221 casa::CountedPtr<Scantable> dofs( const casa::CountedPtr<Scantable>& s,
222 const std::vector<int>& scans,
223 int smoothref=1,
224 casa::Float tsysv=0.0,
225 casa::Float tau=0.0,
226 casa::Float tcal=0.0 );
227
228 /**
229 * Calibrate data with Chopper-Wheel like calibration method
230 * which adopts position switching by antenna motion,
231 * wobbler (nutator) switching and On-The-Fly observation.
232 *
233 * The method is applicable to APEX, and other telescopes other than GBT.
234 *
235 * @param a Scantable which contains ON and OFF scans
236 * @param a string that indicates calibration mode
237 * @param a string that indicates antenna name
238 **/
239 casa::CountedPtr<Scantable> cwcal( const casa::CountedPtr<Scantable>& s,
240 const casa::String calmode,
241 const casa::String antname );
242
243 /**
244 * Calibrate frequency switched scans with Chopper-Wheel like
245 * calibration method.
246 *
247 * The method is applicable to APEX, and other telescopes other than GBT.
248 *
249 * @param a Scantable which contains ON and OFF scans
250 * @param a string that indicates antenna name
251 **/
252 casa::CountedPtr<Scantable> cwcalfs( const casa::CountedPtr<Scantable>& s,
253 const casa::String antname );
254
255
256 /**
257 * Folding frequency-switch data
258 * @param sig
259 * @param ref
260 * @param choffset
261 **/
262 casa::CountedPtr<Scantable> dofold( const casa::CountedPtr<Scantable> &sig,
263 const casa::CountedPtr<Scantable> &ref,
264 casa::Double choffset,
265 casa::Double choffset2 = 0.0 );
266
267 /**
268 * ALMA calibration
269 **/
270 casa::CountedPtr<Scantable> almacal( const casa::CountedPtr<Scantable>& s,
271 const casa::String calmode ) ;
272 casa::CountedPtr<Scantable> almacalfs( const casa::CountedPtr<Scantable>& s ) ;
273
274 casa::CountedPtr<Scantable>
275 freqSwitch( const casa::CountedPtr<Scantable>& in );
276
277 std::vector<float> statistic(const casa::CountedPtr<Scantable>& in,
278 const std::vector<bool>& mask,
279 const std::string& which);
280
281 std::vector<float> statisticRow(const casa::CountedPtr<Scantable>& in,
282 const std::vector<bool>& mask,
283 const std::string& which,
284 int row);
285
286 std::vector< int > minMaxChan(const casa::CountedPtr<Scantable>& in,
287 const std::vector<bool>& mask,
288 const std::string& which);
289
290 casa::CountedPtr<Scantable> bin( const casa::CountedPtr<Scantable>& in,
291 int width=5);
292 casa::CountedPtr<Scantable>
293 resample(const casa::CountedPtr<Scantable>& in,
294 const std::string& method, float width);
295
296 casa::CountedPtr<Scantable>
297 smooth(const casa::CountedPtr<Scantable>& in, const std::string& kernel,
298 float width, int order=2);
299
300 casa::CountedPtr<Scantable>
301 gainElevation(const casa::CountedPtr<Scantable>& in,
302 const std::vector<float>& coeff,
303 const std::string& fileName,
304 const std::string& method);
305 casa::CountedPtr<Scantable>
306 convertFlux(const casa::CountedPtr<Scantable>& in, float d,
307 float etaap, float jyperk);
308
309 casa::CountedPtr<Scantable> opacity(const casa::CountedPtr<Scantable>& in,
310 const std::vector<float>& tau);
311
312 casa::CountedPtr<Scantable>
313 merge(const std::vector<casa::CountedPtr<Scantable> >& in);
314
315 casa::CountedPtr<Scantable>
316 invertPhase( const casa::CountedPtr<Scantable>& in);
317
318 casa::CountedPtr<Scantable>
319 rotateXYPhase( const casa::CountedPtr<Scantable>& in, float phase);
320
321 casa::CountedPtr<Scantable>
322 rotateLinPolPhase( const casa::CountedPtr<Scantable>& in, float phase);
323
324 casa::CountedPtr<Scantable>
325 swapPolarisations(const casa::CountedPtr<Scantable>& in);
326
327 casa::CountedPtr<Scantable>
328 frequencyAlign( const casa::CountedPtr<Scantable>& in,
329 const std::string& refTime = "",
330 const std::string& method = "cubic" );
331
332 casa::CountedPtr<Scantable>
333 convertPolarisation( const casa::CountedPtr<Scantable>& in,
334 const std::string& newtype);
335
336 casa::CountedPtr<Scantable>
337 mxExtract( const casa::CountedPtr<Scantable>& in,
338 const std::string& srctype = "on");
339
340 /**
341 * "hard" flag the data, this flags everything selected in setSelection()
342 * @param frequency the frequency to remove
343 * @param width the number of lags to flag left to the side of the frequency
344 */
345 casa::CountedPtr<Scantable>
346 lagFlag( const casa::CountedPtr<Scantable>& in, double start,
347 double end, const std::string& mode="frequency");
348
349 std::vector<float>
350 fft( const casa::CountedPtr<Scantable>& in,
351 const std::vector<int>& whichrow,
352 bool getRealImag=false );
353
354 // test for average spectra with different channel/resolution
355 casa::CountedPtr<Scantable>
356 new_average( const std::vector<casa::CountedPtr<Scantable> >& in,
357 const bool& compel,
358 const std::vector<bool>& mask = std::vector<bool>(),
359 const std::string& weight = "NONE",
360 const std::string& avmode = "SCAN" )
361 throw (casa::AipsError) ;
362
363private:
364 casa::CountedPtr<Scantable> applyToPol( const casa::CountedPtr<Scantable>& in,
365 STPol::polOperation fptr,
366 casa::Float phase);
367
368 static imethod stringToIMethod(const std::string& in);
369 static WeightType stringToWeight(const std::string& in);
370
371 void scaleByVector(casa::Table& in,
372 const casa::Vector<casa::Float>& factor,
373 bool dotsys);
374
375 void scaleFromAsciiTable(casa::Table& in, const std::string& filename,
376 const std::string& method,
377 const casa::Vector<casa::Float>& xout,
378 bool dotsys);
379
380 void scaleFromTable(casa::Table& in, const casa::Table& table,
381 const std::string& method,
382 const casa::Vector<casa::Float>& xout, bool dotsys);
383
384 void convertBrightnessUnits(casa::CountedPtr<Scantable>& in,
385 bool tokelvin, float cfac);
386
387 casa::CountedPtr< Scantable >
388 smoothOther( const casa::CountedPtr< Scantable >& in,
389 const std::string& kernel,
390 float width, int order=2 );
391
392 casa::CountedPtr< Scantable >
393 getScantable(const casa::CountedPtr< Scantable >& in, bool droprows);
394
395 casa::MaskedArray<casa::Float>
396 maskedArray( const casa::Vector<casa::Float>& s,
397 const casa::Vector<casa::uChar>& f );
398 casa::MaskedArray<casa::Double>
399 maskedArray( const casa::Vector<casa::Double>& s,
400 const casa::Vector<casa::uChar>& f );
401 casa::Vector<casa::uChar>
402 flagsFromMA(const casa::MaskedArray<casa::Float>& ma);
403
404 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" ) ;
405 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" ) ;
406 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" ) ;
407 vector<int> getRowIdFromTime( double reftime, const casa::Vector<casa::Double>& t ) ;
408
409 // Chopper-Wheel type calibration
410 void calibrateCW( casa::CountedPtr<Scantable> &out,
411 const casa::CountedPtr<Scantable> &on,
412 const casa::CountedPtr<Scantable> &off,
413 const casa::CountedPtr<Scantable> &sky,
414 const casa::CountedPtr<Scantable> &hot,
415 const casa::CountedPtr<Scantable> &cold,
416 const casa::Vector<casa::uInt> &rows,
417 const casa::String &antname ) ;
418
419 // Tsys * (ON-OFF)/OFF
420 void calibrateALMA( casa::CountedPtr<Scantable>& out,
421 const casa::CountedPtr<Scantable>& on,
422 const casa::CountedPtr<Scantable>& off,
423 const casa::Vector<casa::uInt>& rows ) ;
424
425 // Frequency switching
426 void calibrateFS( casa::CountedPtr<Scantable> &sig,
427 casa::CountedPtr<Scantable> &ref,
428 const casa::CountedPtr<Scantable> &rsig,
429 const casa::CountedPtr<Scantable> &rref,
430 const casa::CountedPtr<Scantable> &sky,
431 const casa::CountedPtr<Scantable> &hot,
432 const casa::CountedPtr<Scantable> &cold,
433 const casa::Vector<casa::uInt> &rows ) ;
434 void calibrateAPEXFS( casa::CountedPtr<Scantable> &sig,
435 casa::CountedPtr<Scantable> &ref,
436 const vector< casa::CountedPtr<Scantable> > &on,
437 const vector< casa::CountedPtr<Scantable> > &sky,
438 const vector< casa::CountedPtr<Scantable> > &hot,
439 const vector< casa::CountedPtr<Scantable> > &cold,
440 const casa::Vector<casa::uInt> &rows ) ;
441 void copyRows( casa::Table &out,
442 const casa::Table &in,
443 casa::uInt startout,
444 casa::uInt startin,
445 casa::uInt nrow,
446 casa::Bool copySpectra=true,
447 casa::Bool copyFlagtra=true,
448 casa::Bool copyTsys=true ) ;
449 casa::CountedPtr<Scantable> averageWithinSession( casa::CountedPtr<Scantable> &s,
450 vector<bool> &mask,
451 string weight ) ;
452
453 bool insitu_;
454};
455
456}
457#endif
Note: See TracBrowser for help on using the repository browser.