source: sasview/src/sas/sasgui/perspectives/pr/pr_thread.py @ ebfdf4b

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since ebfdf4b was d85c194, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Remaining modules refactored

  • Property mode set to 100644
File size: 3.7 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 sas.sascalc.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, completefn=None,
22                 updatefn=None, yieldtime=0.01, worktime=0.01):
23        """
24        """
25        CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime)
26        self.pr = pr
27        self.nfunc = nfunc
28        self.error_func = error_func
29        self.starttime = 0
30
31    def compute(self):
32        """
33        Perform P(r) inversion
34        """
35        try:
36            self.starttime = time.time()
37            out, cov = self.pr.invert(self.nfunc)
38            elapsed = time.time() - self.starttime
39            self.complete(out=out, cov=cov, pr=self.pr, elapsed=elapsed)
40        except KeyboardInterrupt:
41            # Thread was interrupted, just proceed
42            pass
43        except:
44            if not self.error_func == None:
45                self.error_func("CalcPr.compute: %s" % sys.exc_value)
46
47class EstimatePr(CalcThread):
48    """
49    Estimate P(r)
50    """
51
52    def __init__(self, pr, nfunc=5, error_func=None, completefn=None,
53                 updatefn=None, yieldtime=0.01, worktime=0.01):
54        CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime)
55        self.pr = pr
56        self.nfunc = nfunc
57        self.error_func = error_func
58        self.starttime = 0
59
60    def compute(self):
61        """
62        Calculates the estimate
63        """
64        try:
65            alpha, message, elapsed = self.pr.estimate_alpha(self.nfunc)
66            self.isquit()
67            self.complete(alpha=alpha, message=message, elapsed=elapsed)
68        except KeyboardInterrupt:
69            # Thread was interrupted, just proceed
70            pass
71        except:
72            if not self.error_func == None:
73                self.error_func("EstimatePr.compute: %s" % sys.exc_value)
74
75class EstimateNT(CalcThread):
76    """
77    """
78    def __init__(self, pr, nfunc=5, error_func=None, completefn=None,
79                 updatefn=None, yieldtime=0.01, worktime=0.01):
80        CalcThread.__init__(self, completefn, updatefn, yieldtime, worktime)
81        self.pr = pr
82        self.nfunc = nfunc
83        self.error_func = error_func
84        self.starttime = 0
85        self._time_for_sleep = 0
86        self._sleep_delay = 1.0
87
88
89    def isquit(self):
90        """
91        """
92        CalcThread.isquit(self)
93        if time.time() > self._time_for_sleep + self._sleep_delay:
94            time.sleep(.2)
95            self._time_for_sleep = time.time()
96
97    def compute(self):
98        """
99        Calculates the estimate
100        """
101        try:
102            t_0 = time.time()
103            self._time_for_sleep = t_0
104            nterms, alpha, message = self.pr.estimate_numterms(self.isquit)
105            t_1 = time.time() - t_0
106            self.isquit()
107            self.complete(nterms=nterms, alpha=alpha, message=message, elapsed=t_1)
108        except KeyboardInterrupt:
109            # Thread was interrupted, just proceed
110            pass
111        except:
112            if not self.error_func == None:
113                self.error_func("EstimatePr2.compute: %s" % sys.exc_value)
Note: See TracBrowser for help on using the repository browser.