Changeset 1075 for trunk/python
- Timestamp:
- 07/06/06 11:24:51 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapfitter.py
r1061 r1075 63 63 self.fitted = False 64 64 self.data = thescan 65 self.mask = None 65 66 if mask is None: 66 67 from numarray import ones … … 102 103 return 103 104 104 def fit(self, row=0 ):105 def fit(self, row=0, estimate=False): 105 106 """ 106 107 Execute the actual fitting process. All the state has to be set. 107 108 Parameters: 108 row: specify the row in the scantable 109 row: specify the row in the scantable 110 estimate: auto-compute an initial parameter set (default False) 111 This can be used to compute estimates even if fit was 112 called before. 109 113 Example: 110 114 s = scantable('myscan.asap') … … 132 136 i = row 133 137 out = "Scan[%d] Beam[%d] IF[%d] Pol[%d] Cycle[%d]" % (self.data.getscan(i),self.data.getbeam(i),self.data.getif(i),self.data.getpol(i), self.data.getcycle(i)) 134 asaplog.push(out )138 asaplog.push(out,False) 135 139 self.fitter.setdata(self.x, self.y, self.mask) 136 140 if self.fitfunc == 'gauss': 137 141 ps = self.fitter.getparameters() 138 if len(ps) == 0 :142 if len(ps) == 0 or estimate: 139 143 self.fitter.estimate() 140 144 try: 141 self.fitter.fit() 145 converged = self.fitter.fit() 146 if not converged: 147 raise RuntimeError,"Fit didn't converge." 142 148 except RuntimeError, msg: 143 149 if rcParams['verbose']: … … 275 281 return sum(areas) 276 282 277 def get_parameters(self, component=None): 283 def get_errors(self, component=None): 284 """ 285 Return the errors in the parameters. 286 Parameters: 287 component: get the errors for the specified component 288 only, default is all components 289 """ 290 if not self.fitted: 291 msg = "Not yet fitted." 292 if rcParams['verbose']: 293 print msg 294 return 295 else: 296 raise RuntimeError(msg) 297 errs = list(self.fitter.geterrors()) 298 cerrs = errs 299 if component is not None: 300 if self.fitfunc == "gauss": 301 i = 3*component 302 if i < len(errs): 303 cerrs = errs[i:i+3] 304 return cerrs 305 306 def get_parameters(self, component=None, errors=False): 278 307 """ 279 308 Return the fit paramters. … … 291 320 pars = list(self.fitter.getparameters()) 292 321 fixed = list(self.fitter.getfixedparameters()) 322 errs = list(self.fitter.geterrors()) 293 323 area = [] 294 324 if component is not None: … … 297 327 cpars = pars[i:i+3] 298 328 cfixed = fixed[i:i+3] 329 cerrs = errs[i:i+3] 299 330 a = self.get_area(component) 300 331 area = [a for i in range(3)] … … 302 333 cpars = pars 303 334 cfixed = fixed 335 cerrs = errs 304 336 else: 305 337 cpars = pars 306 338 cfixed = fixed 339 cerrs = errs 307 340 if self.fitfunc == "gauss": 308 341 for c in range(len(self.components)): 309 342 a = self.get_area(c) 310 343 area += [a for i in range(3)] 311 312 fpars = self._format_pars(cpars, cfixed, area) 344 fpars = self._format_pars(cpars, cfixed, None, area) 313 345 if rcParams['verbose']: 314 346 print fpars 315 return {'params':cpars, 'fixed':cfixed, 'formatted': fpars} 316 317 def _format_pars(self, pars, fixed, area): 347 return {'params':cpars, 'fixed':cfixed, 'formatted': fpars, 348 'errors':cerrs} 349 350 def _format_pars(self, pars, fixed, errors, area): 318 351 out = '' 319 352 if self.fitfunc == 'poly': … … 452 485 ylab = self.data._get_ordinate_label() 453 486 454 colours = ["#777777","# bbbbbb","red","orange","purple","green","magenta", "cyan"]487 colours = ["#777777","#dddddd","red","orange","purple","green","magenta", "cyan"] 455 488 self._p.palette(0,colours) 456 489 self._p.set_line(label='Spectrum')
Note:
See TracChangeset
for help on using the changeset viewer.