[529] | 1 | from _asap import sdfit |
---|
| 2 | from asap import rcParams |
---|
| 3 | |
---|
| 4 | class asapfit(sdfit): |
---|
| 5 | |
---|
| 6 | def __init__(self, other): |
---|
| 7 | sdfit.__init__(self,other) |
---|
| 8 | |
---|
| 9 | def __str__(self): |
---|
| 10 | if self.__len__() == 0: |
---|
| 11 | return "No fits" |
---|
| 12 | out = "" |
---|
| 13 | for i in range(self.__len__()): |
---|
| 14 | out += "Fit No %d:" % (i) |
---|
| 15 | pars = self.getparameters(i) |
---|
| 16 | mask = self.getfixedparameters(i) |
---|
| 17 | funcs = self.getfunctions(i) |
---|
| 18 | comps = self.getcomponents(i) |
---|
| 19 | finfo = self.getframeinfo(i) |
---|
| 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) |
---|
| 34 | out += "\n" |
---|
| 35 | out += "\n" |
---|
| 36 | return out |
---|
| 37 | |
---|
| 38 | def as_dict(self): |
---|
| 39 | out = [] |
---|
| 40 | for i in range(self.__len__()): |
---|
| 41 | pars = self.getparameters(i) |
---|
| 42 | mask = self.getfixedparameters(i) |
---|
| 43 | funcs = self.getfunctions(i) |
---|
| 44 | comps = self.getcomponents(i) |
---|
| 45 | pos=0 |
---|
| 46 | k=0 |
---|
| 47 | comp = [] |
---|
| 48 | for f in funcs: |
---|
| 49 | s = pos |
---|
| 50 | pos += comps[k] |
---|
| 51 | ps = pars[s:pos] |
---|
| 52 | d = {'function' : f, |
---|
| 53 | 'parameters' : pars[s:pos], |
---|
| 54 | 'fixed' : mask[s:pos], |
---|
| 55 | 'frame' : self.getframeinfo(i) |
---|
| 56 | } |
---|
| 57 | comp.append(d) |
---|
| 58 | out.append(comp) |
---|
| 59 | return out |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | def _format_pars(self, pars, ftype, unit): |
---|
| 63 | out = '' |
---|
| 64 | if ftype == 'poly': |
---|
| 65 | i = 0 |
---|
| 66 | for p in pars: |
---|
| 67 | out += ' p%d = %3.3f %s,' % (i,p,unit) |
---|
| 68 | i+=1 |
---|
| 69 | out = out[1:-1] |
---|
| 70 | elif ftype == 'gauss': |
---|
| 71 | out += 'peak = %3.3f , centre = %3.3f %s, FWHM = %3.3f %s' % (pars[0],pars[1],unit,pars[2],unit) |
---|
| 72 | |
---|
| 73 | return out |
---|