- Timestamp:
- 09/01/06 10:45:58 (18 years ago)
- Location:
- tags/Release2.1.0b/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tags/Release2.1.0b/python/asapfit.py
r974 r1230 55 55 } 56 56 comp.append(d) 57 k+=1 57 58 out.append(comp) 58 59 return out 60 61 def save(self, filename): 62 f = file(filename, 'w') 63 parstr = "" 64 for i in xrange(self.getcomponents()[0]): 65 pname = "P%d"% (i) 66 parstr += "%-12s " % (pname) 67 header = "#%-12s %s\n" % ("Function", parstr) 68 f.write(header) 69 i = 0 70 funcs=self.getfunctions() 71 pars=self.getparameters() 72 for c in self.getcomponents(): 73 line = " %-12s " % (funcs[i]) 74 for j in xrange(c): 75 line += "%3.8f " % (pars[i*c+j]) 76 i+=1 77 f.write(line+"\n") 78 f.close() 59 79 60 80 def _format_pars(self, pars, ftype, unit): … … 63 83 i = 0 64 84 for p in pars: 65 out += ' p%d = %3. 3f %s,' % (i,p,unit)85 out += ' p%d = %3.6f %s,' % (i,p,unit) 66 86 i+=1 67 87 out = out[1:-1] 68 88 elif ftype == 'gauss': 69 out += 'peak = %3. 3f , centre = %3.3f %s, FWHM = %3.3f %s' % (pars[0],pars[1],unit,pars[2],unit)89 out += 'peak = %3.6f , centre = %3.6f %s, FWHM = %3.6f %s' % (pars[0],pars[1],unit,pars[2],unit) 70 90 return out -
tags/Release2.1.0b/python/asapfitter.py
r1228 r1230 156 156 return 157 157 158 def store_fit(self): 159 """ 160 Store the fit parameters in the scantable. 158 def store_fit(self, filename=None): 159 """ 160 Save the fit parameters. 161 Parameters: 162 filename: if specified save as an ASCII file, if None (default) 163 store it in the scnatable 161 164 """ 162 165 if self.fitted and self.data is not None: … … 170 173 fit.setcomponents(self.components) 171 174 fit.setframeinfo(self.data._getcoordinfo()) 172 self.data._addfit(fit,self._fittedrow) 175 if filename is not None: 176 import os 177 filename = os.path.expandvars(os.path.expanduser(filename)) 178 if os.path.exists(filename): 179 raise IOError("File '%s' exists." % filename) 180 fit.save(filename) 181 else: 182 self.data._addfit(fit,self._fittedrow) 173 183 174 184 #def set_parameters(self, params, fixed=None, component=None): … … 353 363 for i in range(len(pars)): 354 364 fix = "" 355 if fixed[i]: fix = "(fixed)"365 if len(fixed) and fixed[i]: fix = "(fixed)" 356 366 if errors : 357 367 out += ' p%d%s= %3.6f (%1.6f),' % (c,fix,pars[i], errors[i])
Note:
See TracChangeset
for help on using the changeset viewer.