source: sasview/prview/perspectives/pr/pr_thread.py @ 79ac6f8

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 79ac6f8 was 7116b6e0, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on documentation

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[f3d51f6]1import sys, time
[1ebb590]2from data_util.calcthread import CalcThread
[f3d51f6]3
4class CalcPr(CalcThread):
5    """
[7116b6e0]6    Compute P(r)
[f3d51f6]7    """
8   
9    def __init__(self, pr, nfunc=5, error_func=None,
10                 completefn = None,
11                 updatefn   = None,
12                 yieldtime  = 0.01,
13                 worktime   = 0.01
14                 ):
[7116b6e0]15        """
16        """
[f3d51f6]17        CalcThread.__init__(self,completefn,
18                 updatefn,
19                 yieldtime,
20                 worktime)
21        self.pr = pr
22        self.nfunc = nfunc
23        self.error_func = error_func
24        self.starttime = 0
25       
26    def compute(self):
[4318af7f]27        """
[7116b6e0]28        Perform P(r) inversion
[4318af7f]29        """
[f3d51f6]30        try:
31            self.starttime = time.time()
[7cb0353]32            out, cov = self.pr.invert(self.nfunc)
33            #out, cov = self.pr.lstsq(self.nfunc)
34            #out, cov = self.pr.invert_optimize(self.nfunc)
[f3d51f6]35            elapsed = time.time()-self.starttime
36            self.complete(out=out, cov=cov, pr=self.pr, elapsed=elapsed)
[2a92852]37        except KeyboardInterrupt:
38            # Thread was interrupted, just proceed
[4318af7f]39            pass
[f3d51f6]40        except:
41            if not self.error_func==None:
42                self.error_func("CalcPr.compute: %s" % sys.exc_value)
43
44class EstimatePr(CalcThread):
45    """
[7116b6e0]46    Estimate P(r)
[f3d51f6]47    """
48   
49    def __init__(self, pr, nfunc=5, error_func=None,
50                 completefn = None,
51                 updatefn   = None,
52                 yieldtime  = 0.01,
53                 worktime   = 0.01
54                 ):
55        CalcThread.__init__(self,completefn,
56                 updatefn,
57                 yieldtime,
58                 worktime)
59        self.pr = pr
60        self.nfunc = nfunc
61        self.error_func = error_func
62        self.starttime = 0
63       
64    def compute(self):
[634f1cf]65        """
[7116b6e0]66        Calculates the estimate
[634f1cf]67        """
[32dffae4]68        try:           
[634f1cf]69            alpha, message, elapsed = self.pr.estimate_alpha(self.nfunc)
[35adaf6]70            self.isquit()
[634f1cf]71            self.complete(alpha=alpha, message=message, elapsed=elapsed)
[2a92852]72        except KeyboardInterrupt:
73            # Thread was interrupted, just proceed
[4318af7f]74            pass
[f3d51f6]75        except:
76            if not self.error_func==None:
[2a92852]77                self.error_func("EstimatePr.compute: %s" % sys.exc_value)
[f3d51f6]78
[35adaf6]79class EstimateNT(CalcThread):
[7116b6e0]80    """
81    """
[35adaf6]82    def __init__(self, pr, nfunc=5, error_func=None,
83                 completefn = None,
84                 updatefn   = None,
85                 yieldtime  = 0.01,
86                 worktime   = 0.01
87                 ):
88        CalcThread.__init__(self,completefn,
89                 updatefn,
90                 yieldtime,
91                 worktime)
92        self.pr = pr
93        self.nfunc = nfunc
94        self.error_func = error_func
95        self.starttime = 0
[357b79b]96        self._time_for_sleep = 0
97        self._sleep_delay = 1.0
98
99
100    def isquit(self):
[7116b6e0]101        """
102        """
[357b79b]103        CalcThread.isquit(self)
104        if time.time()>self._time_for_sleep+self._sleep_delay:
105            time.sleep(.2)
106            self._time_for_sleep = time.time()
107
[35adaf6]108    def compute(self):
109        """
[7116b6e0]110        Calculates the estimate
[35adaf6]111        """
112        try:           
113            t_0 = time.time()
[357b79b]114            self._time_for_sleep = t_0
[35adaf6]115            nterms, alpha, message = self.pr.estimate_numterms(self.isquit)
116            t_1 = time.time()-t_0
117            self.isquit()
118            self.complete(nterms=nterms, alpha=alpha, message=message, elapsed=t_1)
[2a92852]119        except KeyboardInterrupt:
120            # Thread was interrupted, just proceed
[4318af7f]121            pass
[35adaf6]122        except:
123            if not self.error_func==None:
[2a92852]124                self.error_func("EstimatePr2.compute: %s" % sys.exc_value)
Note: See TracBrowser for help on using the repository browser.