source: sasview/prview/perspectives/pr/pr_thread.py @ 634f1cf

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 634f1cf was 634f1cf, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

Allow user to set q_min/q_max

  • Property mode set to 100644
File size: 2.8 KB
Line 
1import sys, time
2from calcthread import CalcThread
3from sans.pr.invertor import Invertor
4import numpy
5from config import printEVT
6
7class 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            elapsed = time.time()-self.starttime
44            self.complete(out=out, cov=cov, pr=self.pr, elapsed=elapsed)
45        except:
46            if not self.error_func==None:
47                self.error_func("CalcPr.compute: %s" % sys.exc_value)
48
49class EstimatePr(CalcThread):
50    """
51        Compute 2D model
52        This calculation assumes a 2-fold symmetry of the model
53        where points are computed for one half of the detector
54        and I(qx, qy) = I(-qx, -qy) is assumed.
55    """
56   
57    def __init__(self, pr, nfunc=5, error_func=None,
58                 completefn = None,
59                 updatefn   = None,
60                 yieldtime  = 0.01,
61                 worktime   = 0.01
62                 ):
63        CalcThread.__init__(self,completefn,
64                 updatefn,
65                 yieldtime,
66                 worktime)
67        self.pr = pr
68        self.nfunc = nfunc
69        self.error_func = error_func
70        self.starttime = 0
71       
72    def isquit(self):
73        try:
74            CalcThread.isquit(self)
75        except KeyboardInterrupt:
76            printEVT("P(r) calc interrupted")
77            raise KeyboardInterrupt   
78       
79    def compute(self):
80        """
81            Calculates the estimate
82        """
83        try:           
84            alpha, message, elapsed = self.pr.estimate_alpha(self.nfunc)
85            self.complete(alpha=alpha, message=message, elapsed=elapsed)
86        except:
87            if not self.error_func==None:
88                printEVT("EstimatePr.compute: %s" % sys.exc_value)
89
90   
Note: See TracBrowser for help on using the repository browser.