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

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 cce0ad3 was 8b21fa7, checked in by Doucet, Mathieu <doucetm@…>, 10 years ago

pylint fixes

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