source: trunk/src/STMath.h@ 3126

Last change on this file since 3126 was 3106, checked in by Takeshi Nakazato, 8 years ago

New Development: No

JIRA Issue: No

Ready for Test: Yes/No

Interface Changes: Yes/No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No

Module(s): Module Names change impacts.

Description: Describe your changes here...


Check-in asap modifications from Jim regarding casacore namespace conversion.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.4 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>
[2952]17#include <iostream>
[805]18
[130]19#include <casa/aips.h>
[2177]20#include <casa/Arrays/Vector.h>
21#include <casa/BasicSL/String.h>
[81]22#include <casa/Utilities/CountedPtr.h>
[2177]23
[805]24#include <scimath/Mathematics/InterpolateArray1D.h>
[294]25
[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*/
[2658]36class STMath {
[716]37public:
[1106]38 // typedef for long method name
[3106]39 typedef casacore::InterpolateArray1D<casacore::Double,
40 casacore::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".
[3106]71 * @return a casacore::CountedPtr<Scantable> which either holds a new Scantable
[1140]72 * or returns the imput pointer.
73 */
[3106]74 casacore::CountedPtr<Scantable>
75 average( const std::vector<casacore::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".
[3106]85 * @return a casacore::CountedPtr<Scantable> which either holds a new Scantable
[1140]86 * or returns the imput pointer.
87 */
[3106]88 casacore::CountedPtr<Scantable>
89 averageChannel( const casacore::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 */
[3106]101 casacore::CountedPtr< Scantable >
102 averagePolarisations( const casacore::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 */
[3106]113 casacore::CountedPtr< Scantable >
114 averageBeams( const casacore::CountedPtr< Scantable > & in,
[1145]115 const std::vector<bool>& mask,
116 const std::string& weight );
117
[3106]118 casacore::CountedPtr<Scantable>
119 unaryOperate( const casacore::CountedPtr<Scantable>& in, float val,
[2952]120 const std::string& mode, bool tsys=false,
121 bool skip_flaggedrow=false );
[169]122
[1819]123 // array operation
[3106]124 casacore::CountedPtr<Scantable>
125 arrayOperate( const casacore::CountedPtr<Scantable>& in,
[1819]126 const std::vector<float> val,
127 const std::string& mode,
128 const std::string& opmode="channel",
[2952]129 bool tsys=false,
130 bool skip_flaggedrow=false );
[1819]131
132 // channel operation
[3106]133 casacore::CountedPtr<Scantable>
134 arrayOperateChannel( const casacore::CountedPtr<Scantable>& in,
[1819]135 const std::vector<float> val,
[2952]136 const std::string& mode, bool tsys=false,
137 bool skip_flaggedrow=false );
[1819]138
139 // row operation
[3106]140 casacore::CountedPtr<Scantable>
141 arrayOperateRow( const casacore::CountedPtr<Scantable>& in,
[1819]142 const std::vector<float> val,
[2952]143 const std::string& mode, bool tsys=false,
144 bool skip_flaggedrow=false );
[1819]145
146 // 2d array operation
[3106]147 casacore::CountedPtr<Scantable>
148 array2dOperate( const casacore::CountedPtr<Scantable>& in,
[1819]149 const std::vector< std::vector<float> > val,
150 const std::string& mode, bool tsys=false );
151
[3106]152 casacore::CountedPtr<Scantable>
153 binaryOperate( const casacore::CountedPtr<Scantable>& left,
154 const casacore::CountedPtr<Scantable>& right,
[1308]155 const std::string& mode);
156
[3106]157 casacore::CountedPtr<Scantable> autoQuotient(const casacore::CountedPtr<Scantable>& in,
[1066]158 const std::string& mode = "NEAREST",
159 bool preserve = true);
160
[3106]161 casacore::CountedPtr<Scantable> quotient( const casacore::CountedPtr<Scantable>& on,
162 const casacore::CountedPtr<Scantable>& off,
[805]163 bool preserve = true );
[169]164
[1391]165 /**
166 * Calibrate total power scans (translated from GBTIDL)
[1819]167 * @param calon uncalibrated Scantable with CAL noise signal
[1391]168 * @param caloff uncalibrated Scantable with no CAL signal
169 * @param tcal optional scalar Tcal, CAL temperature (K)
[3106]170 * @return casacore::CountedPtr<Scantable> which holds a calibrated Scantable
[1391]171 * (spectrum - average of the two CAL on and off spectra;
172 * tsys - mean Tsys = <caloff>*Tcal/<calon-caloff> + Tcal/2)
[1819]173 */
[3106]174 casacore::CountedPtr<Scantable> dototalpower( const casacore::CountedPtr<Scantable>& calon,
175 const casacore::CountedPtr<Scantable>& caloff,
176 casacore::Float tcal=1.0 );
[1391]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)
[1819]184 * @param tsysv optional scalar Tsys value at the zenith, required to
185 * set tau, as well
[1391]186 * @param tau optional scalar Tau value
[3106]187 * @return casacore::CountedPtr<Scantable> which holds combined scans
[1391]188 * (spectrum = (sig-ref)/ref * Tsys )
189 */
[3106]190 casacore::CountedPtr<Scantable> dosigref( const casacore::CountedPtr<Scantable>& sig,
191 const casacore::CountedPtr<Scantable>& ref,
[1391]192 int smoothref=1,
[3106]193 casacore::Float tsysv=0.0,
194 casacore::Float tau=0.0 );
[1391]195
[1819]196 /**
[1391]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
[1819]203 * @param tau optional scalar Tau value
[1391]204 * @param tcal optional scalar Tcal, CAL temperature (K)
[3106]205 * @return casacore::CountedPtr<Scantable> which holds calibrated scans
[1391]206 */
[3106]207 casacore::CountedPtr<Scantable> donod( const casacore::CountedPtr<Scantable>& s,
[1391]208 const std::vector<int>& scans,
209 int smoothref=1,
[3106]210 casacore::Float tsysv=0.0,
211 casacore::Float tau=0.0,
212 casacore::Float tcal=0.0 );
[1391]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)
[3106]223 * @return casacore::CountedPtr<Scantable> which holds calibrated scans
[1391]224 */
[3106]225 casacore::CountedPtr<Scantable> dofs( const casacore::CountedPtr<Scantable>& s,
[1391]226 const std::vector<int>& scans,
227 int smoothref=1,
[3106]228 casacore::Float tsysv=0.0,
229 casacore::Float tau=0.0,
230 casacore::Float tcal=0.0 );
[1391]231
[1819]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 **/
[3106]243 casacore::CountedPtr<Scantable> cwcal( const casacore::CountedPtr<Scantable>& s,
244 const casacore::String calmode,
245 const casacore::String antname );
[1391]246
[1819]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 **/
[3106]256 casacore::CountedPtr<Scantable> cwcalfs( const casacore::CountedPtr<Scantable>& s,
257 const casacore::String antname );
[1819]258
259
260 /**
261 * Folding frequency-switch data
262 * @param sig
263 * @param ref
264 * @param choffset
265 **/
[3106]266 casacore::CountedPtr<Scantable> dofold( const casacore::CountedPtr<Scantable> &sig,
267 const casacore::CountedPtr<Scantable> &ref,
268 casacore::Double choffset,
269 casacore::Double choffset2 = 0.0 );
[1819]270
271 /**
272 * ALMA calibration
273 **/
[3106]274 casacore::CountedPtr<Scantable> almacal( const casacore::CountedPtr<Scantable>& s,
275 const casacore::String calmode ) ;
276 casacore::CountedPtr<Scantable> almacalfs( const casacore::CountedPtr<Scantable>& s ) ;
[1819]277
[3106]278 casacore::CountedPtr<Scantable>
279 freqSwitch( const casacore::CountedPtr<Scantable>& in );
[716]280
[3106]281 std::vector<float> statistic(const casacore::CountedPtr<Scantable>& in,
[805]282 const std::vector<bool>& mask,
283 const std::string& which);
[457]284
[3106]285 std::vector<float> statisticRow(const casacore::CountedPtr<Scantable>& in,
[1907]286 const std::vector<bool>& mask,
287 const std::string& which,
288 int row);
289
[3106]290 std::vector< int > minMaxChan(const casacore::CountedPtr<Scantable>& in,
[1819]291 const std::vector<bool>& mask,
292 const std::string& which);
293
[3106]294 casacore::CountedPtr<Scantable> bin( const casacore::CountedPtr<Scantable>& in,
[805]295 int width=5);
[3106]296 casacore::CountedPtr<Scantable>
297 resample(const casacore::CountedPtr<Scantable>& in,
[805]298 const std::string& method, float width);
[457]299
[3106]300 casacore::CountedPtr<Scantable>
301 smooth(const casacore::CountedPtr<Scantable>& in, const std::string& kernel,
[1570]302 float width, int order=2);
[169]303
[3106]304 casacore::CountedPtr<Scantable>
305 gainElevation(const casacore::CountedPtr<Scantable>& in,
[867]306 const std::vector<float>& coeff,
[805]307 const std::string& fileName,
[995]308 const std::string& method);
[3106]309 casacore::CountedPtr<Scantable>
310 convertFlux(const casacore::CountedPtr<Scantable>& in, float d,
[805]311 float etaap, float jyperk);
[152]312
[3106]313 casacore::CountedPtr<Scantable> opacity(const casacore::CountedPtr<Scantable>& in,
[1689]314 const std::vector<float>& tau);
[144]315
[3106]316 casacore::CountedPtr<Scantable>
317 merge(const std::vector<casacore::CountedPtr<Scantable> >& in,
[2900]318 const std::string &freqTol = "");
[841]319
[3106]320 casacore::CountedPtr<Scantable>
321 invertPhase( const casacore::CountedPtr<Scantable>& in);
[912]322
[3106]323 casacore::CountedPtr<Scantable>
324 rotateXYPhase( const casacore::CountedPtr<Scantable>& in, float phase);
[912]325
[3106]326 casacore::CountedPtr<Scantable>
327 rotateLinPolPhase( const casacore::CountedPtr<Scantable>& in, float phase);
[896]328
[3106]329 casacore::CountedPtr<Scantable>
330 swapPolarisations(const casacore::CountedPtr<Scantable>& in);
[896]331
[3106]332 casacore::CountedPtr<Scantable>
333 frequencyAlign( const casacore::CountedPtr<Scantable>& in,
[927]334 const std::string& refTime = "",
335 const std::string& method = "cubic" );
[917]336
[3106]337 casacore::CountedPtr<Scantable>
338 convertPolarisation( const casacore::CountedPtr<Scantable>& in,
[992]339 const std::string& newtype);
[1143]340
[3106]341 casacore::CountedPtr<Scantable>
342 mxExtract( const casacore::CountedPtr<Scantable>& in,
[1143]343 const std::string& srctype = "on");
[992]344
[1192]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 */
[3106]350 casacore::CountedPtr<Scantable>
351 lagFlag( const casacore::CountedPtr<Scantable>& in, double start,
[1570]352 double end, const std::string& mode="frequency");
[1192]353
[2177]354 std::vector<float>
[3106]355 fft( const casacore::CountedPtr<Scantable>& in,
[2177]356 const std::vector<int>& whichrow,
357 bool getRealImag=false );
358
[1819]359 // test for average spectra with different channel/resolution
[3106]360 casacore::CountedPtr<Scantable>
361 new_average( const std::vector<casacore::CountedPtr<Scantable> >& in,
[1819]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" )
[3106]366 throw (casacore::AipsError) ;
[1819]367
[805]368private:
[3106]369 casacore::CountedPtr<Scantable> applyToPol( const casacore::CountedPtr<Scantable>& in,
[896]370 STPol::polOperation fptr,
[3106]371 casacore::Float phase);
[896]372
[805]373 static imethod stringToIMethod(const std::string& in);
374 static WeightType stringToWeight(const std::string& in);
[146]375
[3106]376 void scaleByVector(casacore::Table& in,
377 const casacore::Vector<casacore::Float>& factor,
[805]378 bool dotsys);
[152]379
[3106]380 void scaleFromAsciiTable(casacore::Table& in, const std::string& filename,
[805]381 const std::string& method,
[3106]382 const casacore::Vector<casacore::Float>& xout,
[805]383 bool dotsys);
[162]384
[3106]385 void scaleFromTable(casacore::Table& in, const casacore::Table& table,
[805]386 const std::string& method,
[3106]387 const casacore::Vector<casacore::Float>& xout, bool dotsys);
[227]388
[3106]389 void convertBrightnessUnits(casacore::CountedPtr<Scantable>& in,
[805]390 bool tokelvin, float cfac);
[227]391
[3106]392 casacore::CountedPtr< Scantable >
393 smoothOther( const casacore::CountedPtr< Scantable >& in,
[1374]394 const std::string& kernel,
[1570]395 float width, int order=2 );
[1374]396
[3106]397 casacore::CountedPtr< Scantable >
398 getScantable(const casacore::CountedPtr< Scantable >& in, bool droprows);
[230]399
[3106]400 casacore::MaskedArray<casacore::Float>
401 maskedArray( const casacore::Vector<casacore::Float>& s,
402 const casacore::Vector<casacore::uChar>& f );
403 casacore::MaskedArray<casacore::Double>
404 maskedArray( const casacore::Vector<casacore::Double>& s,
405 const casacore::Vector<casacore::uChar>& f );
406 casacore::Vector<casacore::uChar>
407 flagsFromMA(const casacore::MaskedArray<casacore::Float>& ma);
[230]408
[2580]409 // Frequency switching
[3106]410 void calibrateFS( casacore::CountedPtr<Scantable> &sig,
411 casacore::CountedPtr<Scantable> &ref,
412 const casacore::CountedPtr<Scantable> &rsig,
413 const casacore::CountedPtr<Scantable> &rref,
414 const casacore::CountedPtr<Scantable> &sky,
415 const casacore::CountedPtr<Scantable> &hot,
416 const casacore::CountedPtr<Scantable> &cold,
417 const casacore::Vector<casacore::uInt> &rows ) ;
418 void calibrateAPEXFS( casacore::CountedPtr<Scantable> &sig,
419 casacore::CountedPtr<Scantable> &ref,
420 const vector< casacore::CountedPtr<Scantable> > &on,
421 const vector< casacore::CountedPtr<Scantable> > &sky,
422 const vector< casacore::CountedPtr<Scantable> > &hot,
423 const vector< casacore::CountedPtr<Scantable> > &cold,
424 const casacore::Vector<casacore::uInt> &rows ) ;
425 void copyRows( casacore::Table &out,
426 const casacore::Table &in,
427 casacore::uInt startout,
428 casacore::uInt startin,
429 casacore::uInt nrow,
430 casacore::Bool copySpectra=true,
431 casacore::Bool copyFlagtra=true,
432 casacore::Bool copyTsys=true ) ;
433 casacore::CountedPtr<Scantable> averageWithinSession( casacore::CountedPtr<Scantable> &s,
[2580]434 vector<bool> &mask,
435 string weight ) ;
436
[805]437 bool insitu_;
438};
[234]439
[805]440}
[165]441#endif
Note: See TracBrowser for help on using the repository browser.