source: sasview/fittingview/src/sans/perspectives/fitting/fit_thread.py @ 9905d79

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 9905d79 was 49c69de, checked in by Gervaise Alina <gervyh@…>, 13 years ago

move perspective from sansview to fittingview

  • Property mode set to 100644
File size: 3.1 KB
Line 
1
2import sys
3from data_util.calcthread import CalcThread
4
5def map_getattr(classInstance, classFunc, *args):
6    """
7    Take an instance of a class and a function name as a string.
8    Execute class.function and return result
9    """
10    return  getattr(classInstance,classFunc)(*args)
11
12def map_apply(arguments):
13    return apply(arguments[0], arguments[1:])
14
15class FitThread(CalcThread):
16    """Thread performing the fit """
17   
18    def __init__(self, 
19                  fn,
20                  page_id,
21                   handler,
22                  pars=None,
23                 completefn = None,
24                 updatefn   = None,
25                 yieldtime  = 0.01,
26                 worktime   = 0.01,
27                 ftol       = None):
28        CalcThread.__init__(self,completefn,
29                 updatefn,
30                 yieldtime,
31                 worktime)
32        self.handler = handler
33        self.fitter = fn
34        self.pars = pars
35        self.page_id = page_id
36        self.starttime = 0
37        self.updatefn = updatefn
38        #Relative error desired in the sum of squares.
39        self.ftol = ftol
40   
41    def isquit(self):
42        """
43        :raise KeyboardInterrupt: when the thread is interrupted
44       
45        """
46        try:
47            CalcThread.isquit(self)
48        except KeyboardInterrupt:
49            raise KeyboardInterrupt
50       
51    def compute(self):
52        """
53        Perform a fit
54        """
55        msg = ""
56        try:
57            list_handler = []
58            list_curr_thread = [] 
59            list_ftol = []
60            list_map_get_attr = []
61            list_fit_function = []
62            list_q = []
63            for i in range(len(self.fitter)):
64                list_handler.append(None)
65                list_q.append(None)
66                list_curr_thread.append(None)
67                list_ftol.append(self.ftol)
68                list_fit_function.append('fit')
69                list_map_get_attr.append(map_getattr)
70            from multiprocessing import Pool
71            inputs = zip(list_map_get_attr,self.fitter, list_fit_function,
72                         list_handler, list_q, list_curr_thread,list_ftol)
73            result =  Pool(1).map(func=map_apply, 
74                               iterable=inputs)
75            #self.handler.starting_fit()
76            self.complete(result= result,
77                          page_id=self.page_id,
78                          pars = self.pars)
79           
80        except KeyboardInterrupt, msg:
81            # Thread was interrupted, just proceed and re-raise.
82            # Real code should not print, but this is an example...
83            #print "keyboard exception"
84            #Stop on exception during fitting. Todo: need to put
85            #some mssg and reset progress bar.
86            raise
87            #if self.handler is not None:
88            #    self.handler.error(msg=msg)
89        except:
90            raise
91            #if self.handler is not None:
92            #    self.handler.error(msg=str(sys.exc_value))
93           
94       
95   
Note: See TracBrowser for help on using the repository browser.