1 | import sys, time |
---|
2 | from calcthread import CalcThread |
---|
3 | from sans.pr.invertor import Invertor |
---|
4 | import numpy |
---|
5 | from config import printEVT |
---|
6 | |
---|
7 | class CalcPr(CalcThread): |
---|
8 | """ |
---|
9 | Compute 2D model |
---|
10 | This calculation assumes a 2-fold symmetry of the model |
---|
11 | where points are computed for one half of the detector |
---|
12 | and I(qx, qy) = I(-qx, -qy) is assumed. |
---|
13 | """ |
---|
14 | |
---|
15 | def __init__(self, pr, nfunc=5, error_func=None, |
---|
16 | completefn = None, |
---|
17 | updatefn = None, |
---|
18 | yieldtime = 0.01, |
---|
19 | worktime = 0.01 |
---|
20 | ): |
---|
21 | CalcThread.__init__(self,completefn, |
---|
22 | updatefn, |
---|
23 | yieldtime, |
---|
24 | worktime) |
---|
25 | self.pr = pr |
---|
26 | self.nfunc = nfunc |
---|
27 | self.error_func = error_func |
---|
28 | self.starttime = 0 |
---|
29 | |
---|
30 | def isquit(self): |
---|
31 | try: |
---|
32 | CalcThread.isquit(self) |
---|
33 | except KeyboardInterrupt: |
---|
34 | printEVT("P(r) calc interrupted") |
---|
35 | raise KeyboardInterrupt |
---|
36 | |
---|
37 | def compute(self): |
---|
38 | import time |
---|
39 | try: |
---|
40 | self.starttime = time.time() |
---|
41 | out, cov = self.pr.invert(self.nfunc) |
---|
42 | #out, cov = self.pr.lstsq(self.nfunc) |
---|
43 | #out, cov = self.pr.invert_optimize(self.nfunc) |
---|
44 | elapsed = time.time()-self.starttime |
---|
45 | self.complete(out=out, cov=cov, pr=self.pr, elapsed=elapsed) |
---|
46 | except: |
---|
47 | if not self.error_func==None: |
---|
48 | self.error_func("CalcPr.compute: %s" % sys.exc_value) |
---|
49 | |
---|
50 | class EstimatePr(CalcThread): |
---|
51 | """ |
---|
52 | Compute 2D model |
---|
53 | This calculation assumes a 2-fold symmetry of the model |
---|
54 | where points are computed for one half of the detector |
---|
55 | and I(qx, qy) = I(-qx, -qy) is assumed. |
---|
56 | """ |
---|
57 | |
---|
58 | def __init__(self, pr, nfunc=5, error_func=None, |
---|
59 | completefn = None, |
---|
60 | updatefn = None, |
---|
61 | yieldtime = 0.01, |
---|
62 | worktime = 0.01 |
---|
63 | ): |
---|
64 | CalcThread.__init__(self,completefn, |
---|
65 | updatefn, |
---|
66 | yieldtime, |
---|
67 | worktime) |
---|
68 | self.pr = pr |
---|
69 | self.nfunc = nfunc |
---|
70 | self.error_func = error_func |
---|
71 | self.starttime = 0 |
---|
72 | |
---|
73 | def isquit(self): |
---|
74 | try: |
---|
75 | CalcThread.isquit(self) |
---|
76 | except KeyboardInterrupt: |
---|
77 | printEVT("P(r) calc interrupted") |
---|
78 | raise KeyboardInterrupt |
---|
79 | |
---|
80 | def compute(self): |
---|
81 | """ |
---|
82 | Calculates the estimate |
---|
83 | """ |
---|
84 | try: |
---|
85 | alpha, message, elapsed = self.pr.estimate_alpha(self.nfunc) |
---|
86 | self.complete(alpha=alpha, message=message, elapsed=elapsed) |
---|
87 | except: |
---|
88 | if not self.error_func==None: |
---|
89 | printEVT("EstimatePr.compute: %s" % sys.exc_value) |
---|
90 | |
---|
91 | |
---|