Changeset 1232 for trunk/python
- Timestamp:
- 09/01/06 13:14:11 (18 years ago)
- Location:
- trunk/python
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapfit.py
r974 r1232 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 -
trunk/python/asapfitter.py
r1217 r1232 100 100 101 101 self.fitter.setexpression(self.fitfunc,n) 102 self.fitted = False 102 103 return 103 104 … … 142 143 self.fitter.estimate() 143 144 try: 145 fxdpar = list(self.fitter.getfixedparameters()) 146 if len(fxdpar) and fxdpar.count(0) == 0: 147 raise RuntimeError,"No point fitting, if all parameters are fixed." 144 148 converged = self.fitter.fit() 145 149 if not converged: … … 155 159 return 156 160 157 def store_fit(self): 158 """ 159 Store the fit parameters in the scantable. 161 def store_fit(self, filename=None): 162 """ 163 Save the fit parameters. 164 Parameters: 165 filename: if specified save as an ASCII file, if None (default) 166 store it in the scnatable 160 167 """ 161 168 if self.fitted and self.data is not None: … … 169 176 fit.setcomponents(self.components) 170 177 fit.setframeinfo(self.data._getcoordinfo()) 171 self.data._addfit(fit,self._fittedrow) 178 if filename is not None: 179 import os 180 filename = os.path.expandvars(os.path.expanduser(filename)) 181 if os.path.exists(filename): 182 raise IOError("File '%s' exists." % filename) 183 fit.save(filename) 184 else: 185 self.data._addfit(fit,self._fittedrow) 172 186 173 187 #def set_parameters(self, params, fixed=None, component=None): … … 224 238 Set the Parameters of a 'Gaussian' component, set with set_function. 225 239 Parameters: 226 peak, centre, f hwm: The gaussian parameters240 peak, centre, fwhm: The gaussian parameters 227 241 peakfixed, 228 242 centerfixed, … … 352 366 for i in range(len(pars)): 353 367 fix = "" 354 if fixed[i]: fix = "(fixed)"368 if len(fixed) and fixed[i]: fix = "(fixed)" 355 369 if errors : 356 370 out += ' p%d%s= %3.6f (%1.6f),' % (c,fix,pars[i], errors[i]) -
trunk/python/asapmath.py
r1085 r1232 12 12 scanav: True averages each scan separately. 13 13 False (default) averages all scans together, 14 weight: Weighting scheme. 'none, 'var' (1/var(spec) 15 weighted), 'tsys' (1/Tsys**2 weighted), 'tint' 16 (integration time weighted) or 'tintsys' (Tsys 17 and tint). The default is 'tint' 14 weight: Weighting scheme. 15 'none' (mean no weight) 16 'var' (1/var(spec) weighted) 17 'tsys' (1/Tsys**2 weighted) 18 'tint' (integration time weighted) 19 'tintsys' (Tint/Tsys**2) 20 'median' ( median averaging) 18 21 align: align the spectra in velocity before averaging. It takes 19 22 the time of the first spectrum in the first scantable … … 70 73 else: 71 74 alignedlst = lst 72 s = scantable(stm._average(alignedlst, mask, weight.upper(), scanav)) 75 if weight.upper() == 'MEDIAN': 76 # median doesn't support list of scantables - merge first 77 merged = None 78 if len(alignedlst) > 1: 79 merged = merge(alignedlst) 80 else: 81 merged = alignedlst[0] 82 s = scantable(stm._averagechannel(merged, 'MEDIAN', scanav)) 83 del merged 84 else: 85 s = scantable(stm._average(alignedlst, mask, weight.upper(), scanav)) 73 86 s._add_history("average_time",varlist) 74 87 print_log() -
trunk/python/asapplotter.py
r1217 r1232 123 123 del self._plotter.axes.patches[-1] 124 124 axvspan. __doc__ = matplotlib.axes.Axes.axvspan.__doc__ 125 125 126 def axhspan(self, *args, **kwargs): 126 self._axes_callback("a hvspan", *args, **kwargs)127 self._axes_callback("axhspan", *args, **kwargs) 127 128 # hack to preventy mpl from redrawing the patch 128 129 # it seem to convert the patch into lines on every draw.
Note:
See TracChangeset
for help on using the changeset viewer.