source: sasview/inversionview/src/sans/perspectives/pr/pr_thread.py @ 11f5196

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 11f5196 was 11f5196, checked in by Jae Cho <jhjcho@…>, 13 years ago
  • Property mode set to 100644
File size: 4.2 KB
Line 
1
2################################################################################
3#This software was developed by the University of Tennessee as part of the
4#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
5#project funded by the US National Science Foundation.
6#
7#See the license text in license.txt
8#
9#copyright 2009, University of Tennessee
10################################################################################
11
12import sys
13import time
14from data_util.calcthread import CalcThread
15
16class CalcPr(CalcThread):
17    """
18    Compute P(r)
19    """
20   
21    def __init__(self, pr, nfunc=5, error_func=None,
22                 completefn = None,
23                 updatefn   = None,
24                 yieldtime  = 0.01,
25                 worktime   = 0.01
26                 ):
27        """
28        """
29        CalcThread.__init__(self,completefn,
30                 updatefn,
31                 yieldtime,
32                 worktime)
33        self.pr = pr
34        self.nfunc = nfunc
35        self.error_func = error_func
36        self.starttime = 0
37       
38    def compute(self):
39        """
40        Perform P(r) inversion
41        """
42        try:
43            self.starttime = time.time()
44            out, cov = self.pr.invert(self.nfunc)
45            #out, cov = self.pr.lstsq(self.nfunc)
46            #out, cov = self.pr.invert_optimize(self.nfunc)
47            elapsed = time.time()-self.starttime
48            self.complete(out=out, cov=cov, pr=self.pr, elapsed=elapsed)
49        except KeyboardInterrupt:
50            # Thread was interrupted, just proceed
51            pass
52        except:
53            if not self.error_func==None:
54                self.error_func("CalcPr.compute: %s" % sys.exc_value)
55
56class EstimatePr(CalcThread):
57    """
58    Estimate P(r)
59    """
60   
61    def __init__(self, pr, nfunc=5, error_func=None,
62                 completefn = None,
63                 updatefn   = None,
64                 yieldtime  = 0.01,
65                 worktime   = 0.01
66                 ):
67        CalcThread.__init__(self,completefn,
68                 updatefn,
69                 yieldtime,
70                 worktime)
71        self.pr = pr
72        self.nfunc = nfunc
73        self.error_func = error_func
74        self.starttime = 0
75       
76    def compute(self):
77        """
78        Calculates the estimate
79        """
80        try:           
81            alpha, message, elapsed = self.pr.estimate_alpha(self.nfunc)
82            self.isquit()
83            self.complete(alpha=alpha, message=message, elapsed=elapsed)
84        except KeyboardInterrupt:
85            # Thread was interrupted, just proceed
86            pass
87        except:
88            if not self.error_func==None:
89                self.error_func("EstimatePr.compute: %s" % sys.exc_value)
90
91class EstimateNT(CalcThread):
92    """
93    """
94    def __init__(self, pr, nfunc=5, error_func=None,
95                 completefn = None,
96                 updatefn   = None,
97                 yieldtime  = 0.01,
98                 worktime   = 0.01
99                 ):
100        CalcThread.__init__(self,completefn,
101                 updatefn,
102                 yieldtime,
103                 worktime)
104        self.pr = pr
105        self.nfunc = nfunc
106        self.error_func = error_func
107        self.starttime = 0
108        self._time_for_sleep = 0
109        self._sleep_delay = 1.0
110
111
112    def isquit(self):
113        """
114        """
115        CalcThread.isquit(self)
116        if time.time()>self._time_for_sleep+self._sleep_delay:
117            time.sleep(.2)
118            self._time_for_sleep = time.time()
119
120    def compute(self):
121        """
122        Calculates the estimate
123        """
124        try:           
125            t_0 = time.time()
126            self._time_for_sleep = t_0
127            nterms, alpha, message = self.pr.estimate_numterms(self.isquit)
128            t_1 = time.time()-t_0
129            self.isquit()
130            self.complete(nterms=nterms, alpha=alpha, message=message, elapsed=t_1)
131        except KeyboardInterrupt:
132            # Thread was interrupted, just proceed
133            pass
134        except:
135            if not self.error_func==None:
136                self.error_func("EstimatePr2.compute: %s" % sys.exc_value)
Note: See TracBrowser for help on using the repository browser.