Changeset 1701 for branches/alma
- Timestamp:
- 02/16/10 16:29:35 (15 years ago)
- Location:
- branches/alma/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/python/asapfitter.py
r1676 r1701 82 82 lpoly: use polynomial of the order given with linear least squares fit 83 83 gauss: fit the number of gaussian specified 84 lorentz: fit the number of lorentzian specified 84 85 Example: 85 fitter.set_function(gauss=2) # will fit two gaussians86 86 fitter.set_function(poly=3) # will fit a 3rd order polynomial via nonlinear method 87 87 fitter.set_function(lpoly=3) # will fit a 3rd order polynomial via linear method 88 fitter.set_function(gauss=2) # will fit two gaussians 89 fitter.set_function(lorentz=2) # will fit two lorentzians 88 90 """ 89 91 #default poly order 0 … … 105 107 self.components = [ 3 for i in range(n) ] 106 108 self.uselinear = False 109 elif kwargs.has_key('lorentz'): 110 n = kwargs.get('lorentz') 111 self.fitfunc = 'lorentz' 112 self.fitfuncs = [ 'lorentz' for i in range(n) ] 113 self.components = [ 3 for i in range(n) ] 114 self.uselinear = False 107 115 else: 108 116 msg = "Invalid function type." … … 160 168 asaplog.push(out,False) 161 169 self.fitter.setdata(self.x, self.y, self.mask) 162 if self.fitfunc == 'gauss' :170 if self.fitfunc == 'gauss' or self.fitfunc == 'lorentz': 163 171 ps = self.fitter.getparameters() 164 172 if len(ps) == 0 or estimate: … … 243 251 else: 244 252 raise RuntimeError(msg) 245 if self.fitfunc == "gauss"and component is not None:253 if (self.fitfunc == "gauss" or self.fitfunc == 'lorentz') and component is not None: 246 254 if not self.fitted and sum(self.fitter.getparameters()) == 0: 247 255 pars = _n_bools(len(self.components)*3, False) … … 301 309 raise ValueError(msg) 302 310 311 def set_lorentz_parameters(self, peak, centre, fwhm, 312 peakfixed=0, centrefixed=0, 313 fwhmfixed=0, 314 component=0): 315 """ 316 Set the Parameters of a 'Lorentzian' component, set with set_function. 317 Parameters: 318 peak, centre, fwhm: The gaussian parameters 319 peakfixed, 320 centrefixed, 321 fwhmfixed: Optional parameters to indicate if 322 the paramters should be held fixed during 323 the fitting process. The default is to keep 324 all parameters flexible. 325 component: The number of the component (Default is the 326 component 0) 327 """ 328 if self.fitfunc != "lorentz": 329 msg = "Function only operates on Lorentzian components." 330 if rcParams['verbose']: 331 #print msg 332 asaplog.push(msg) 333 print_log('ERROR') 334 return 335 else: 336 raise ValueError(msg) 337 if 0 <= component < len(self.components): 338 d = {'params':[peak, centre, fwhm], 339 'fixed':[peakfixed, centrefixed, fwhmfixed]} 340 self.set_parameters(d, component) 341 else: 342 msg = "Please select a valid component." 343 if rcParams['verbose']: 344 #print msg 345 asaplog.push(msg) 346 print_log('ERROR') 347 return 348 else: 349 raise ValueError(msg) 350 303 351 def get_area(self, component=None): 304 352 """ 305 Return the area under the fitted gaussian component.306 Parameters: 307 component: the gaussian component selection,353 Return the area under the fitted gaussian/lorentzian component. 354 Parameters: 355 component: the gaussian/lorentzian component selection, 308 356 default (None) is the sum of all components 309 357 Note: 310 This will only work for gaussian fits.358 This will only work for gaussian/lorentzian fits. 311 359 """ 312 360 if not self.fitted: return 313 if self.fitfunc == "gauss" :361 if self.fitfunc == "gauss" or self.fitfunc == "lorentz": 314 362 pars = list(self.fitter.getparameters()) 315 363 from math import log,pi,sqrt 316 fac = sqrt(pi/log(16.0)) 364 if self.fitfunc == "gauss": 365 fac = sqrt(pi/log(16.0)) 366 elif self.fitfunc == "lorentz": 367 fac = pi/2.0 317 368 areas = [] 318 369 for i in range(len(self.components)): … … 346 397 cerrs = errs 347 398 if component is not None: 348 if self.fitfunc == "gauss" :399 if self.fitfunc == "gauss" or self.fitfunc == "lorentz": 349 400 i = 3*component 350 401 if i < len(errs): … … 373 424 area = [] 374 425 if component is not None: 375 if self.fitfunc == "gauss" :426 if self.fitfunc == "gauss" or self.fitfunc == "lorentz": 376 427 i = 3*component 377 428 cpars = pars[i:i+3] … … 388 439 cfixed = fixed 389 440 cerrs = errs 390 if self.fitfunc == "gauss" :441 if self.fitfunc == "gauss" or self.fitfunc == "lorentz": 391 442 for c in range(len(self.components)): 392 443 a = self.get_area(c) … … 413 464 c+=1 414 465 out = out[:-1] # remove trailing ',' 415 elif self.fitfunc == 'gauss' :466 elif self.fitfunc == 'gauss' or self.fitfunc == 'lorentz': 416 467 i = 0 417 468 c = 0 -
branches/alma/python/scantable.py
r1685 r1701 862 862 self._add_history("flag_row", varlist) 863 863 864 def clip(self, uthres=None, dthres=None, clipoutside=True, unflag=False): 865 """ 866 Flag the selected data outside a specified range (in channel-base) 867 Parameters: 868 uthres: upper threshold. 869 dthres: lower threshold 870 clipoutside: True for flagging data outside the range [dthres:uthres]. 871 False for glagging data inside the range. 872 unflag : if True, unflag the data. 873 """ 874 varlist = vars() 875 try: 876 self._clip(uthres, dthres, clipoutside, unflag) 877 except RuntimeError, msg: 878 if rcParams['verbose']: 879 print_log() 880 asaplog.push(str(msg)) 881 print_log('ERROR') 882 return 883 else: raise 884 self._add_history("clip", varlist) 864 885 865 886 def lag_flag(self, frequency, width=0.0, unit="GHz", insitu=None):
Note:
See TracChangeset
for help on using the changeset viewer.