source: trunk/src/STMath.h@ 2997

Last change on this file since 2997 was 2952, checked in by WataruKawasaki, 10 years ago

New Development: No

JIRA Issue: Yes CAS-6598

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: add a parameter for some functions

Test Programs: test_sdscale

Put in Release Notes:

Module(s): sd

Description: add a parameter 'skip_flaggedrow' for STMath::unaryOperate(), STMath::arrayOperate(), STMath::arrayOperateChannel(), STMath::arrayOperateRow() and their python interfaces if exist. the default value of 'skip_flaggedrow' is false so default behaviour of these functions will not change.


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