source: trunk/src/STMath.h@ 2178

Last change on this file since 2178 was 2177, checked in by WataruKawasaki, 13 years ago

New Development: Yes

JIRA Issue: Yes CAS-2828

Ready for Test: Yes

Interface Changes:

What Interface Changed:

Test Programs:

Put in Release Notes:

Module(s): SD

Description: created a tool function sd.scantable.fft() to apply FFT for scantable data.


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