source: trunk/python/asapfit.py@ 1191

Last change on this file since 1191 was 974, checked in by mar637, 19 years ago

Completed Ticket #7 - storing of fits.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.9 KB
RevLine 
[974]1from _asap import fitentry
[529]2from asap import rcParams
3
[974]4class asapfit(fitentry):
[722]5
[974]6 def __init__(self, other=None):
7 if isinstance(other, fitentry):
8 fitentry.__init__(self,other)
9 else:
10 fitentry.__init__(self)
[529]11
12 def __str__(self):
13 out = ""
[974]14 out += "Fit:"
15 pars = self.getparameters()
16 mask = self.getfixedparameters()
17 funcs = self.getfunctions()
18 comps = self.getcomponents()
19 finfo = self.getframeinfo()
20 pos=0
21 k = 0
22 for f in funcs:
23 out += "\n Type: "
24 out += f
25 s = pos
26 pos += comps[k]
27 ps = pars[s:pos]
28 out += "\n Parameters: "
29 out += self._format_pars(pars[s:pos],f, finfo[0])
30 out += "\n Fixed Parms: "
31 out += str(mask[s:pos])
32 out += "\n Frame: "
33 out += str(finfo)
[529]34 out += "\n"
[974]35 out += "\n"
[529]36 return out
37
38 def as_dict(self):
39 out = []
[974]40 pars = self.getparameters()
41 mask = self.getfixedparameters()
42 funcs = self.getfunctions()
43 comps = self.getcomponents()
44 pos=0
45 k=0
46 comp = []
47 for f in funcs:
48 s = pos
49 pos += comps[k]
50 ps = pars[s:pos]
51 d = {'function' : f,
52 'parameters' : pars[s:pos],
53 'fixed' : mask[s:pos],
54 'frame' : self.getframeinfo()
55 }
56 comp.append(d)
57 out.append(comp)
[529]58 return out
59
60 def _format_pars(self, pars, ftype, unit):
61 out = ''
62 if ftype == 'poly':
63 i = 0
64 for p in pars:
65 out += ' p%d = %3.3f %s,' % (i,p,unit)
66 i+=1
67 out = out[1:-1]
[722]68 elif ftype == 'gauss':
[529]69 out += 'peak = %3.3f , centre = %3.3f %s, FWHM = %3.3f %s' % (pars[0],pars[1],unit,pars[2],unit)
70 return out
Note: See TracBrowser for help on using the repository browser.