source: trunk/src/STMath.h@ 2512

Last change on this file since 2512 was 2186, checked in by WataruKawasaki, 13 years ago

New Development: Yes

JIRA Issue: Yes CAS-3149

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: scantable.*sinusoid_baseline() params

Test Programs:

Put in Release Notes: Yes

Module(s):

Description: (1) Implemented an automated sinusoidal fitting functionality

(2) FFT available with scantable.fft()
(3) fixed a bug of parsing 'edge' param used by linefinder.
(4) a function to show progress status for row-based iterations.


  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.1 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
[2177]25#include "Logger.h"
[805]26#include "Scantable.h"
[834]27#include "STDefs.h"
[896]28#include "STPol.h"
[2]29
[83]30namespace asap {
[2]31
[805]32/**
[1106]33 * Mathmatical operations on Scantable objects
34 * @author Malte Marquarding
[805]35*/
[890]36class STMath : private Logger {
[716]37public:
[1106]38 // typedef for long method name
[805]39 typedef casa::InterpolateArray1D<casa::Double,
40 casa::Float>::InterpolationMethod imethod;
[299]41
[1106]42 // typedef for std::map
[805]43 typedef std::map<std::string, imethod> imap;
[177]44
[1106]45/**
46 * whether to operate on the given Scantable or return a new one
47 * @param insitu the toggle for this behaviour
48 */
[1353]49 explicit STMath(bool insitu=true);
[221]50
[995]51 virtual ~STMath();
[227]52
[805]53 /**
[1295]54 * get the currnt @attr inistu_ state
[805]55 */
56 bool insitu() const { return insitu_;};
[1143]57
[1106]58 /**
59 * set the currnt @attr inistu state
60 * @param b the new state
61 */
[805]62 void setInsitu(bool b) { insitu_ = b; };
[262]63
[1106]64
[1140]65 /**
66 * average a vector of Scantables
67 * @param in the vector of Scantables to average
[1295]68 * @param mask an optional mask to apply on specific weights
[1140]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 */
[805]74 casa::CountedPtr<Scantable>
75 average( const std::vector<casa::CountedPtr<Scantable> >& in,
[858]76 const std::vector<bool>& mask = std::vector<bool>(),
77 const std::string& weight = "NONE",
[977]78 const std::string& avmode = "SCAN");
[1066]79
[1140]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 */
[1069]88 casa::CountedPtr<Scantable>
89 averageChannel( const casa::CountedPtr<Scantable> & in,
[1078]90 const std::string& mode = "MEDIAN",
91 const std::string& avmode = "SCAN");
[1069]92
[1140]93 /**
[1145]94 * Average polarisations together. really only useful if only linears are
95 * available.
[1140]96 * @param in the input Scantable
97 * @param mask an optional mask if weight allows one
98 * @param weight weighting scheme
[1143]99 * @return
[1140]100 */
[940]101 casa::CountedPtr< Scantable >
102 averagePolarisations( const casa::CountedPtr< Scantable > & in,
[1140]103 const std::vector<bool>& mask,
104 const std::string& weight );
[234]105
[1145]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
[805]118 casa::CountedPtr<Scantable>
119 unaryOperate( const casa::CountedPtr<Scantable>& in, float val,
120 const std::string& mode, bool tsys=false );
[169]121
[1819]122 // array operation
[1308]123 casa::CountedPtr<Scantable>
[1819]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>
[1570]149 binaryOperate( const casa::CountedPtr<Scantable>& left,
150 const casa::CountedPtr<Scantable>& right,
[1308]151 const std::string& mode);
152
[1066]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,
[805]159 bool preserve = true );
[169]160
[1391]161 /**
162 * Calibrate total power scans (translated from GBTIDL)
[1819]163 * @param calon uncalibrated Scantable with CAL noise signal
[1391]164 * @param caloff uncalibrated Scantable with no CAL signal
165 * @param tcal optional scalar Tcal, CAL temperature (K)
[1819]166 * @return casa::CountedPtr<Scantable> which holds a calibrated Scantable
[1391]167 * (spectrum - average of the two CAL on and off spectra;
168 * tsys - mean Tsys = <caloff>*Tcal/<calon-caloff> + Tcal/2)
[1819]169 */
[1391]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)
[1819]180 * @param tsysv optional scalar Tsys value at the zenith, required to
181 * set tau, as well
[1391]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
[1819]192 /**
[1391]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
[1819]199 * @param tau optional scalar Tau value
[1391]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
[1819]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 );
[1391]242
[1819]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,
[1937]265 casa::Double choffset2 = 0.0 );
[1819]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
[805]274 casa::CountedPtr<Scantable>
275 freqSwitch( const casa::CountedPtr<Scantable>& in );
[716]276
[805]277 std::vector<float> statistic(const casa::CountedPtr<Scantable>& in,
278 const std::vector<bool>& mask,
279 const std::string& which);
[457]280
[1907]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
[1819]286 std::vector< int > minMaxChan(const casa::CountedPtr<Scantable>& in,
287 const std::vector<bool>& mask,
288 const std::string& which);
289
[805]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);
[457]295
[805]296 casa::CountedPtr<Scantable>
297 smooth(const casa::CountedPtr<Scantable>& in, const std::string& kernel,
[1570]298 float width, int order=2);
[169]299
[805]300 casa::CountedPtr<Scantable>
301 gainElevation(const casa::CountedPtr<Scantable>& in,
[867]302 const std::vector<float>& coeff,
[805]303 const std::string& fileName,
[995]304 const std::string& method);
[805]305 casa::CountedPtr<Scantable>
306 convertFlux(const casa::CountedPtr<Scantable>& in, float d,
307 float etaap, float jyperk);
[152]308
[805]309 casa::CountedPtr<Scantable> opacity(const casa::CountedPtr<Scantable>& in,
[1689]310 const std::vector<float>& tau);
[144]311
[841]312 casa::CountedPtr<Scantable>
313 merge(const std::vector<casa::CountedPtr<Scantable> >& in);
314
[896]315 casa::CountedPtr<Scantable>
316 invertPhase( const casa::CountedPtr<Scantable>& in);
[912]317
[896]318 casa::CountedPtr<Scantable>
319 rotateXYPhase( const casa::CountedPtr<Scantable>& in, float phase);
[912]320
[896]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
[917]327 casa::CountedPtr<Scantable>
328 frequencyAlign( const casa::CountedPtr<Scantable>& in,
[927]329 const std::string& refTime = "",
330 const std::string& method = "cubic" );
[917]331
[992]332 casa::CountedPtr<Scantable>
333 convertPolarisation( const casa::CountedPtr<Scantable>& in,
334 const std::string& newtype);
[1143]335
[1140]336 casa::CountedPtr<Scantable>
[1143]337 mxExtract( const casa::CountedPtr<Scantable>& in,
338 const std::string& srctype = "on");
[992]339
[1192]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>
[1570]346 lagFlag( const casa::CountedPtr<Scantable>& in, double start,
347 double end, const std::string& mode="frequency");
[1192]348
[2177]349 std::vector<float>
350 fft( const casa::CountedPtr<Scantable>& in,
351 const std::vector<int>& whichrow,
352 bool getRealImag=false );
353
[1819]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
[805]363private:
[896]364 casa::CountedPtr<Scantable> applyToPol( const casa::CountedPtr<Scantable>& in,
365 STPol::polOperation fptr,
366 casa::Float phase);
367
[805]368 static imethod stringToIMethod(const std::string& in);
369 static WeightType stringToWeight(const std::string& in);
[146]370
[805]371 void scaleByVector(casa::Table& in,
372 const casa::Vector<casa::Float>& factor,
373 bool dotsys);
[152]374
[805]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);
[162]379
[805]380 void scaleFromTable(casa::Table& in, const casa::Table& table,
381 const std::string& method,
382 const casa::Vector<casa::Float>& xout, bool dotsys);
[227]383
[805]384 void convertBrightnessUnits(casa::CountedPtr<Scantable>& in,
385 bool tokelvin, float cfac);
[227]386
[1570]387 casa::CountedPtr< Scantable >
[1374]388 smoothOther( const casa::CountedPtr< Scantable >& in,
389 const std::string& kernel,
[1570]390 float width, int order=2 );
[1374]391
[805]392 casa::CountedPtr< Scantable >
393 getScantable(const casa::CountedPtr< Scantable >& in, bool droprows);
[230]394
[805]395 casa::MaskedArray<casa::Float>
396 maskedArray( const casa::Vector<casa::Float>& s,
397 const casa::Vector<casa::uChar>& f );
[1819]398 casa::MaskedArray<casa::Double>
399 maskedArray( const casa::Vector<casa::Double>& s,
400 const casa::Vector<casa::uChar>& f );
[805]401 casa::Vector<casa::uChar>
402 flagsFromMA(const casa::MaskedArray<casa::Float>& ma);
[230]403
[1819]404 vector<float> getSpectrumFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode = "before" ) ;
405 vector<float> getTcalFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode="before" ) ;
406 vector<float> getTsysFromTime( string reftime, casa::CountedPtr<Scantable>& s, string mode="before" ) ;
407 vector<int> getRowIdFromTime( string reftime, casa::CountedPtr<Scantable>& s ) ;
408
409 // Chopper-Wheel type calibration
410 vector<float> getCalibratedSpectra( casa::CountedPtr<Scantable>& on,
411 casa::CountedPtr<Scantable>& off,
412 casa::CountedPtr<Scantable>& sky,
413 casa::CountedPtr<Scantable>& hot,
414 casa::CountedPtr<Scantable>& cold,
415 int index,
416 string antname ) ;
417 // Tsys * (ON-OFF)/OFF
418 vector<float> getCalibratedSpectra( casa::CountedPtr<Scantable>& on,
419 casa::CountedPtr<Scantable>& off,
420 int index ) ;
421 vector<float> getFSCalibratedSpectra( casa::CountedPtr<Scantable>& sig,
422 casa::CountedPtr<Scantable>& ref,
423 casa::CountedPtr<Scantable>& sky,
424 casa::CountedPtr<Scantable>& hot,
425 casa::CountedPtr<Scantable>& cold,
426 int index ) ;
427 vector<float> getFSCalibratedSpectra( casa::CountedPtr<Scantable>& sig,
428 casa::CountedPtr<Scantable>& ref,
429 vector< casa::CountedPtr<Scantable> >& sky,
430 vector< casa::CountedPtr<Scantable> >& hot,
431 vector< casa::CountedPtr<Scantable> >& cold,
432 int index ) ;
433 double getMJD( string strtime ) ;
434
[805]435 bool insitu_;
436};
[234]437
[805]438}
[165]439#endif
Note: See TracBrowser for help on using the repository browser.