Changeset 1017 for trunk/python
- Timestamp:
- 04/18/06 15:53:48 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapfitter.py
r975 r1017 166 166 self.data._addfit(fit,self._fittedrow) 167 167 168 def set_parameters(self, params, fixed=None, component=None): 168 #def set_parameters(self, params, fixed=None, component=None): 169 def set_parameters(self,*args,**kwargs): 169 170 """ 170 171 Set the parameters to be fitted. … … 175 176 component: in case of multiple gaussians, the index of the 176 177 component 177 """ 178 """ 179 component = None 180 fixed = None 181 params = None 182 183 if len(args) and isinstance(args[0],dict): 184 kwargs = args[0] 185 if kwargs.has_key("fixed"): fixed = kwargs["fixed"] 186 if kwargs.has_key("params"): params = kwargs["params"] 187 if len(args) == 2 and isinstance(args[1], int): 188 component = args[1] 178 189 if self.fitfunc is None: 179 190 msg = "Please specify a fitting function first." … … 184 195 raise RuntimeError(msg) 185 196 if self.fitfunc == "gauss" and component is not None: 186 if not self.fitted :197 if not self.fitted and sum(self.fitter.getparameters()) == 0: 187 198 from numarray import zeros 188 199 pars = list(zeros(len(self.components)*3)) … … 203 214 204 215 def set_gauss_parameters(self, peak, centre, fhwm, 205 peakfixed= False, centerfixed=False,206 fhwmfixed= False,216 peakfixed=0, centerfixed=0, 217 fhwmfixed=0, 207 218 component=0): 208 219 """ … … 227 238 raise ValueError(msg) 228 239 if 0 <= component < len(self.components): 229 self.set_parameters([peak, centre, fhwm],230 [peakfixed, centerfixed, fhwmfixed],231 240 d = {'params':[peak, centre, fhwm], 241 'fixed':[peakfixed, centerfixed, fhwmfixed]} 242 self.set_parameters(d, component) 232 243 else: 233 244 msg = "Please select a valid component." … … 294 305 if rcParams['verbose']: 295 306 print fpars 296 return cpars, cfixed, fpars307 return {'params':cpars, 'fixed':cfixed} 297 308 298 309 def _format_pars(self, pars, fixed, area): … … 315 326 ounit = self.data.get_fluxunit() 316 327 while i < len(pars): 317 out += ' %2d: peak = %3.3f %s , centre = %3.3f %s, FWHM = %3.3f %s\n area = %3.3f %s %s\n' % (c,pars[i],ounit,pars[i+1],aunit,pars[i+2],aunit, area,ounit,aunit) 328 if area: 329 out += ' %2d: peak = %3.3f %s , centre = %3.3f %s, FWHM = %3.3f %s\n area = %3.3f %s %s\n' % (c,pars[i],ounit,pars[i+1],aunit,pars[i+2],aunit, area,ounit,aunit) 330 else: 331 out += ' %2d: peak = %3.3f %s , centre = %3.3f %s, FWHM = %3.3f %s\n' % (c,pars[i],ounit,pars[i+1],aunit,pars[i+2],aunit,ounit,aunit) 318 332 c+=1 319 333 i+=3 … … 327 341 fixed = self.fitter.getfixedparameters() 328 342 if rcParams['verbose']: 329 print self._format_pars(pars,fixed )343 print self._format_pars(pars,fixed,None) 330 344 return pars 331 345 … … 422 436 tlab = 'Spectrum' 423 437 xlab = 'Abcissa' 424 m = () 438 ylab = 'Ordinate' 439 m = None 425 440 if self.data: 426 441 tlab = self.data._getsourcename(self._fittedrow)
Note:
See TracChangeset
for help on using the changeset viewer.