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
Rev | Line | |
---|
[e9b4cc4] | 1 | |
---|
[66ff250] | 2 | import sys |
---|
[e54d2c32] | 3 | from data_util.calcthread import CalcThread |
---|
[e9b4cc4] | 4 | |
---|
[66ff250] | 5 | |
---|
[e9b4cc4] | 6 | class FitThread(CalcThread): |
---|
[ed2ea6a] | 7 | """Thread performing the fit """ |
---|
[e9b4cc4] | 8 | |
---|
[58e0c83] | 9 | def __init__(self, |
---|
[e54d2c32] | 10 | fn, |
---|
[66ff250] | 11 | page_id, |
---|
[e54d2c32] | 12 | handler, |
---|
| 13 | pars=None, |
---|
[e9b4cc4] | 14 | completefn = None, |
---|
| 15 | updatefn = None, |
---|
| 16 | yieldtime = 0.01, |
---|
[2296316] | 17 | worktime = 0.01, |
---|
| 18 | ftol = None): |
---|
[e9b4cc4] | 19 | CalcThread.__init__(self,completefn, |
---|
| 20 | updatefn, |
---|
| 21 | yieldtime, |
---|
| 22 | worktime) |
---|
[e54d2c32] | 23 | self.handler = handler |
---|
| 24 | self.fitter = fn |
---|
[e9b4cc4] | 25 | self.pars = pars |
---|
[66ff250] | 26 | self.page_id = page_id |
---|
[e9b4cc4] | 27 | self.starttime = 0 |
---|
[e54d2c32] | 28 | self.updatefn = updatefn |
---|
[2296316] | 29 | #Relative error desired in the sum of squares. |
---|
| 30 | self.ftol = ftol |
---|
[e54d2c32] | 31 | |
---|
[e9b4cc4] | 32 | def isquit(self): |
---|
[ed2ea6a] | 33 | """ |
---|
[5062bbf] | 34 | :raise KeyboardInterrupt: when the thread is interrupted |
---|
| 35 | |
---|
[ed2ea6a] | 36 | """ |
---|
[e9b4cc4] | 37 | try: |
---|
| 38 | CalcThread.isquit(self) |
---|
| 39 | except KeyboardInterrupt: |
---|
| 40 | raise KeyboardInterrupt |
---|
[66ff250] | 41 | |
---|
[e9b4cc4] | 42 | def compute(self): |
---|
[ed2ea6a] | 43 | """ |
---|
[5062bbf] | 44 | Perform a fit |
---|
[ed2ea6a] | 45 | """ |
---|
[40953a9] | 46 | msg = "" |
---|
[e9b4cc4] | 47 | try: |
---|
[66ff250] | 48 | #self.handler.starting_fit() |
---|
[ed2ea6a] | 49 | #Result from the fit |
---|
[8da09f4] | 50 | result = self.fitter.fit(handler=self.handler, |
---|
[16865897] | 51 | curr_thread=self, |
---|
| 52 | ftol=self.ftol) |
---|
[e9b4cc4] | 53 | self.complete(result= result, |
---|
[66ff250] | 54 | page_id=self.page_id, |
---|
[6bbeacd4] | 55 | pars = self.pars) |
---|
[785c8233] | 56 | |
---|
[e54d2c32] | 57 | except KeyboardInterrupt, msg: |
---|
[e9b4cc4] | 58 | # Thread was interrupted, just proceed and re-raise. |
---|
| 59 | # Real code should not print, but this is an example... |
---|
[ad6dd4c] | 60 | #print "keyboard exception" |
---|
[a6a7e8a] | 61 | #Stop on exception during fitting. Todo: need to put some mssg and reset progress bar. |
---|
[66ff250] | 62 | raise |
---|
| 63 | #if self.handler is not None: |
---|
| 64 | # self.handler.error(msg=msg) |
---|
| 65 | except: |
---|
| 66 | raise |
---|
| 67 | #if self.handler is not None: |
---|
| 68 | # self.handler.error(msg=str(sys.exc_value)) |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | |
---|
Note: See
TracBrowser
for help on using the repository browser.