source: sasview/src/sas/qtgui/Perspectives/Inversion/Thread.py @ 84df556

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 84df556 was fa81e94, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Initial commit of the P(r) inversion perspective.
Code merged from Jeff Krzywon's ESS_GUI_Pr branch.
Also, minor 2to3 mods to sascalc/sasgui to enble error free setup.

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