Go to the documentation of this file.00001 from _asap import fitentry
00002 from asap.parameters import rcParams
00003
00004 class asapfit(fitentry):
00005
00006 def __init__(self, other=None):
00007 if isinstance(other, fitentry):
00008 fitentry.__init__(self,other)
00009 else:
00010 fitentry.__init__(self)
00011
00012 def __str__(self):
00013 out = ""
00014 out += "Fit:"
00015 pars = self.getparameters()
00016 mask = self.getfixedparameters()
00017 funcs = self.getfunctions()
00018 comps = self.getcomponents()
00019 finfo = self.getframeinfo()
00020 pos=0
00021 k = 0
00022 for f in funcs:
00023 out += "\n Type: "
00024 out += f
00025 s = pos
00026 pos += comps[k]
00027 ps = pars[s:pos]
00028 out += "\n Parameters: "
00029 out += self._format_pars(pars[s:pos],f, finfo[0])
00030 out += "\n Fixed Parms: "
00031 out += str(mask[s:pos])
00032 out += "\n Frame: "
00033 out += str(finfo)
00034 out += "\n"
00035 out += "\n"
00036 return out
00037
00038 def as_dict(self):
00039 out = []
00040 pars = self.getparameters()
00041 mask = self.getfixedparameters()
00042 funcs = self.getfunctions()
00043 comps = self.getcomponents()
00044 pos=0
00045 k=0
00046 comp = []
00047 for f in funcs:
00048 s = pos
00049 pos += comps[k]
00050 ps = pars[s:pos]
00051 d = {'function' : f,
00052 'parameters' : pars[s:pos],
00053 'fixed' : mask[s:pos],
00054 'frame' : self.getframeinfo()
00055 }
00056 comp.append(d)
00057 k+=1
00058 out.append(comp)
00059 return out
00060
00061 def save(self, filename):
00062 f = file(filename, 'w')
00063 parstr = ""
00064 for i in xrange(self.getcomponents()[0]):
00065 pname = "P%d"% (i)
00066 parstr += "%-12s " % (pname)
00067 header = "#%-12s %s\n" % ("Function", parstr)
00068 f.write(header)
00069 i = 0
00070 funcs=self.getfunctions()
00071 pars=self.getparameters()
00072 for c in self.getcomponents():
00073 line = " %-12s " % (funcs[i])
00074 for j in xrange(c):
00075 line += "%3.8f " % (pars[i*c+j])
00076 i+=1
00077 f.write(line+"\n")
00078 f.close()
00079
00080 def _format_pars(self, pars, ftype, unit):
00081 out = ''
00082 if ftype == 'poly':
00083 i = 0
00084 for p in pars:
00085 out += ' p%d = %3.6f %s,' % (i,p,unit)
00086 i+=1
00087 out = out[1:-1]
00088 elif ftype == 'gauss':
00089 out += 'peak = %3.6f , centre = %3.6f %s, FWHM = %3.6f %s' % (pars[0],pars[1],unit,pars[2],unit)
00090 return out