- Timestamp:
- Jul 19, 2011 5:35:27 PM (13 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 24adb89
- Parents:
- d771c72
- Location:
- sansview/perspectives/fitting
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
r70468a5 rcc31608 64 64 ## data 65 65 self.data = None 66 #list of available data 67 self.data_list = [] 66 68 self.mask = None 67 69 self.uid = None … … 364 366 """ 365 367 return self.state 368 366 369 def get_data(self): 367 370 """ … … 369 372 """ 370 373 return self.data 374 375 def get_data_list(self): 376 """ 377 return the current data 378 """ 379 return self.data_list 371 380 372 381 def set_manager(self, manager): -
sansview/perspectives/fitting/fit_thread.py
r40953a9 rcc31608 3 3 from data_util.calcthread import CalcThread 4 4 5 def 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 12 def map_apply(arguments): 13 return apply(arguments[0], arguments[1:]) 5 14 6 15 class FitThread(CalcThread): … … 45 54 """ 46 55 msg = "" 47 try: 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, list_handler, list_q, list_curr_thread,list_ftol) 72 print inputs 73 result = Pool(1).map(func=map_apply, 74 iterable=inputs) 48 75 #self.handler.starting_fit() 49 76 #Result from the fit 50 result = self.fitter.fit(handler=self.handler, 51 curr_thread=self, 52 ftol=self.ftol) 77 """ 78 result = self.fitter.fit(handler=self.handler, 79 curr_thread=self, 80 ftol=self.ftol) 81 """ 82 print "fithread result", result 53 83 self.complete(result= result, 54 84 page_id=self.page_id, -
sansview/perspectives/fitting/fitpage.py
r515bf4f rcc31608 10 10 from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion 11 11 from DataLoader.data_info import Data1D 12 from sans.guiframe.events import StatusEvent 12 from sans.guiframe.events import StatusEvent 13 from sans.guiframe.events import NewPlotEvent 13 14 from sans.guiframe.utils import format_number,check_float 14 15 … … 41 42 42 43 ## draw sizer 43 self._fill_data info_sizer()44 self._fill_data_sizer() 44 45 self.is_2D = None 45 46 self.fit_started = False … … 59 60 self._set_paste_flag(False) 60 61 self.btFit.SetFocus() 61 62 self.fill_data_combobox(data_list=self.data_list) 63 64 65 def _fill_data_sizer(self): 66 """ 67 fill sizer 0 with data info 68 """ 69 box_description= wx.StaticBox(self, -1, 'I(q) Data Source') 70 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 71 #---------------------------------------------------------- 72 sizer_data = wx.BoxSizer(wx.HORIZONTAL) 73 self.dataSource = wx.ComboBox(self, -1, style=wx.CB_READONLY) 74 wx.EVT_COMBOBOX(self.dataSource, -1, self.on_select_data) 75 self.dataSource.SetMinSize((_DATA_BOX_WIDTH, -1)) 76 sizer_data.Add(wx.StaticText(self, -1, 'Name : ')) 77 sizer_data.Add(self.dataSource) 78 sizer_data.Add( (0,5) ) 79 boxsizer1.Add(sizer_data,0, wx.ALL, 10) 80 self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) 81 self.sizer0.Layout() 82 83 def enable_datasource(self): 84 """ 85 Enable or disable data source control depending on existing data 86 """ 87 if not self.data_list: 88 self.dataSource.Disable() 89 else: 90 self.dataSource.Enable() 91 92 def fill_data_combobox(self, data_list): 93 """ 94 Get a list of data and fill the corresponding combobox 95 """ 96 self.dataSource.Clear() 97 self.data_list = data_list 98 self.enable_datasource() 99 for data in self.data_list: 100 if data is not None: 101 self.dataSource.Append(str(data.name), clientData=data) 102 self.dataSource.SetSelection(0) 103 self.on_select_data(event=None) 104 105 def on_select_data(self, event=None): 106 """ 107 """ 108 if event is None and self.dataSource.GetCount() > 0: 109 data = self.dataSource.GetClientData(0) 110 self.set_data(data) 111 elif self.dataSource.GetCount() > 0: 112 pos = self.dataSource.GetSelection() 113 data = self.dataSource.GetClientData(pos) 114 self.set_data(data) 115 116 62 117 63 118 def _on_fit_complete(self): … … 293 348 sizer_chi2.Add(sizer_smearer_box) 294 349 sizer_chi2.Add((-1,5)) 295 350 296 351 # hide all smear messages and textctrl 297 352 self._hide_all_smear_info() … … 386 441 self.sizer5.Layout() 387 442 388 def _fill_datainfo_sizer(self):389 """390 fill sizer 0 with data info391 """392 ## no loaded data , don't fill the sizer393 if self.data is None:394 data_min = ""395 data_max = ""396 data_name = " None"397 else:398 data_name = self.data.name399 #set maximum range for x in linear scale400 if not hasattr(self.data,"data"): #Display only for 1D data fit401 # Minimum value of data402 data_min = min(self.data.x)403 # Maximum value of data404 data_max = max(self.data.x)405 else:406 ## Minimum value of data407 data_min = 0408 x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax))409 y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax))410 ## Maximum value of data411 data_max = math.sqrt(x*x + y*y)412 ## set q range to plot413 self.qmin_x = data_min414 self.qmax_x = data_max415 box_description= wx.StaticBox(self, -1, 'I(q) Data Source')416 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)417 #----------------------------------------------------------418 sizer_data = wx.BoxSizer(wx.HORIZONTAL)419 #Filling the sizer containing data related fields420 #self.dataSource = wx.StaticText(self, -1,str(self.data.name))421 self.dataSource = BGTextCtrl(self, -1)422 self.dataSource.SetValue(str(data_name))423 #self.dataSource.SetEditable(False)424 self.dataSource.SetMinSize((_DATA_BOX_WIDTH, -1))425 sizer_data.Add(wx.StaticText(self, -1, 'Name : '))426 sizer_data.Add(self.dataSource )427 sizer_data.Add( (0,5) )428 """429 #---------sizer 2 draw--------------------------------430 text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)',431 style=wx.ALIGN_LEFT)432 sizer_range = wx.BoxSizer(wx.HORIZONTAL)433 sizer_range.Add( text4_3 ,0, wx.RIGHT, 10)434 self.minimum_q = BGTextCtrl(self, -1, size=(_BOX_WIDTH,20))435 self.minimum_q.SetValue(str(data_min))436 self.maximum_q = BGTextCtrl(self, -1,size=(_BOX_WIDTH,20))437 self.maximum_q.SetValue(str(data_max))438 sizer_range.Add(wx.StaticText(self, -1, "Min: "),0, wx.LEFT, 10)439 sizer_range.Add(self.minimum_q,0, wx.LEFT, 10)440 sizer_range.Add(wx.StaticText(self, -1, "Max: "),0, wx.LEFT, 10)441 sizer_range.Add(self.maximum_q,0, wx.LEFT, 10)442 """443 boxsizer1.Add(sizer_data,0, wx.ALL, 10)444 #boxsizer1.Add(sizer_range, 0 , wx.LEFT, 10)445 #------------------------------------------------------------446 447 self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10)448 self.sizer0.Layout()449 443 450 444 def _fill_model_sizer(self, sizer): … … 1636 1630 reset the current data 1637 1631 """ 1632 id = None 1633 group_id = None 1638 1634 flag = False 1639 1635 if self.data is None and data is not None: 1640 self.window_name = str(data.name)1641 ## Title to appear on top of the window1642 self.window_caption = str(data.name)1643 1636 flag = True 1637 if data is not None: 1638 id = data.id 1639 group_id = data.group_id 1640 if self.data is not None: 1641 flag = (data.id != self.data.id) 1644 1642 self.data = data 1645 1643 if self.data is None: … … 1727 1725 1728 1726 self.model_view.Disable() 1727 1728 #replace data plot on combo box selection 1729 #by removing the previous selected data 1730 wx.PostEvent(self._manager.parent, NewPlotEvent(action="remove", 1731 group_id=group_id, id=id)) 1732 #plot the current selected data 1733 wx.PostEvent(self._manager.parent, NewPlotEvent(plot=self.data, 1734 title=str(self.data.title))) 1735 self._manager.store_data(uid=self.uid, data=data, 1736 data_list=self.data_list, 1737 caption=self.window_name) 1729 1738 self._draw_model() 1730 1739 -
sansview/perspectives/fitting/fitpanel.py
r00ea2a7 rcc31608 54 54 ## list of existing fit page 55 55 self.opened_pages = {} 56 #index of fit page 57 self.fit_page_index = 0 58 #index of batch page 59 self.batch_page_index = 0 56 60 #page of simultaneous fit 57 61 self.sim_page = None … … 309 313 add an empty page 310 314 """ 311 from fitpage import FitPage 312 panel = FitPage(parent=self) 315 if self.batch_on: 316 from batchfitpage import BatchFitPage 317 panel = BatchFitPage(parent=self) 318 #Increment index of batch page 319 self.batch_page_index += 1 320 index = self.batch_page_index 321 else: 322 from fitpage import FitPage 323 panel = FitPage(parent=self) 324 #Increment index of fit page 325 self.fit_page_index += 1 326 index = self.fit_page_index 313 327 panel.uid = wx.NewId() 314 328 panel.populate_box(dict=self.model_list_box) 315 329 panel.set_manager(self._manager) 316 index = self.GetPageCount() 317 #caption = str(panel.window_name) + " " + str(self._manager.index_model) 318 caption = str(panel.window_name) + " " + str(index) 330 caption = str(panel.window_caption) + " " + str(index) 319 331 self.AddPage(panel, caption, select=True) 320 332 self.opened_pages[panel.uid] = panel … … 360 372 self._manager.on_add_new_page(event=None) 361 373 362 def set_data(self, data ):374 def set_data(self, data_list): 363 375 """ 364 376 Add a fitting page on the notebook contained by fitpanel … … 369 381 370 382 """ 371 if data is None:383 if not data_list: 372 384 return None 385 386 if self.batch_on: 387 page = self.add_empty_page() 388 print "batch on fitpanel", page.__class__.__name__, page.window_caption 389 pos = self.GetPageIndex(page) 390 page.fill_data_combobox(data_list) 391 self.opened_pages[page.uid] = page 392 return page 393 else: 394 data = None 395 data = data_list[0] 396 if data is None: 397 return None 373 398 for page in self.opened_pages.values(): 374 399 #check if the selected data existing in the fitpanel 375 400 pos = self.GetPageIndex(page) 376 401 if page.get_data() is None: 402 #make sure data get placed in 1D empty tab if data is 1D 403 #else data get place on 2D tab empty tab 377 404 enable2D = page.get_view_mode() 378 405 if (data.__class__.__name__ == "Data2D" and enable2D)\ 379 406 or (data.__class__.__name__ == "Data1D" and not enable2D): 380 page.set_data(data) 407 #page.set_data(data) 408 page.fill_data_combobox(data_list) 381 409 self.SetPageText(pos, str(data.name)) 382 410 self.SetSelection(pos) 383 411 return page 384 # Todo: Need to set different window name when has same data385 # Todo: to catch page with same data even if it is not on the top.386 """387 elif page.get_data().id == data.id:388 msg = "Data already existing in the fitting panel"389 wx.PostEvent(self._manager.parent,390 StatusEvent(status=msg, info='warning'))391 self.SetSelection(pos)392 return page393 """412 # Todo: Need to set different window name when has same data 413 # Todo: to catch page with same data even if it is not on the top. 414 """ 415 elif page.get_data().id == data.id: 416 msg = "Data already existing in the fitting panel" 417 wx.PostEvent(self._manager.parent, 418 StatusEvent(status=msg, info='warning')) 419 self.SetSelection(pos) 420 return page 421 """ 394 422 page = self.add_empty_page() 395 423 pos = self.GetPageIndex(page) 396 page.set_data(data) 424 page.fill_data_combobox(data_list) 425 #page.set_data(data) 397 426 self.SetPageText(pos, str(data.name)) 398 427 self.opened_pages[page.uid] = page … … 447 476 self._manager.sim_page=None 448 477 return 449 478 if selected_page.__class__.__name__ == "FitPage": 479 self.fit_page_index -= 1 480 else: 481 self.batch_page_index -= 1 450 482 ## closing other pages 451 483 state = selected_page.createMemento() -
sansview/perspectives/fitting/fitproblem.py
rba1f0b2 rcc31608 13 13 ## data used for fitting 14 14 self.fit_data = None 15 #list of data in case of batch mode 16 self.data_list = [] 17 #dictionary of data id and location to corresponding fitproblem 18 self.fitproblem_pointers = {} 15 19 self.theory_data = None 16 20 ## the current model … … 28 32 self.qmin = None 29 33 self.qmax = None 34 self.result = [] 30 35 31 36 # 1D or 2D … … 143 148 return self.fit_data 144 149 150 def set_fit_data_list(self, data_list): 151 """ 152 save a copy of a list of data 153 154 :param data_list: list of data 155 156 """ 157 self.data_list = data_list 158 159 def get_fit_data_list(self): 160 """ 161 """ 162 return self.data_list 163 145 164 def set_model_param(self,name,value=None): 146 165 """ … … 205 224 """ 206 225 return self.enable2D 226 227 def get_pointer_to_fitproblem(self): 228 """ 229 return dictionary of id of fitproblem 230 """ 231 return self.fitproblem_pointers 232 233 def set_pointer_to_fitproblem(self, data_id, page_id): 234 """ 235 """ 236 self.fitproblem_pointers[data_id] = page_id 237 238 def set_result(self, result): 239 """ 240 set a list of result 241 """ 242 self.result = result 243 244 def get_result(self): 245 """ 246 get result 247 """ 248 return self.result 249 207 250 -
sansview/perspectives/fitting/fitting.py
r0145a25 rcc31608 34 34 from sans.guiframe.plugin_base import PluginBase 35 35 36 #from .console import ConsoleUpdate36 from .console import ConsoleUpdate 37 37 from .fitproblem import FitProblem 38 38 from .fitpanel import FitPanel 39 #from .fit_thread import FitThread39 from .fit_thread import FitThread 40 40 from .pagestate import Reader 41 41 from .fitpage import Chi2UpdateEvent … … 108 108 logging.info("Fitting plug-in started") 109 109 110 def on_batch_selection(self, flag): 111 """ 112 switch the the notebook of batch mode or not 113 """ 114 self.batch_on = flag 115 if self.batch_on: 116 if self.fit_panel is not None: 117 self.fit_panel.batch_on = flag 118 110 119 def populate_menu(self, owner): 111 120 """ … … 275 284 data_list = [] 276 285 selected_data_list = [] 277 if len(data_list) > MAX_NBR_DATA : 278 from fitting_widgets import DataDialog 279 dlg = DataDialog(data_list=data_list, nb_data=MAX_NBR_DATA) 280 if dlg.ShowModal() == wx.ID_OK: 281 selected_data_list = dlg.get_data() 282 dlg.Destroy() 283 286 if self.batch_on: 287 page = self.add_fit_page(data=data_list) 284 288 else: 285 selected_data_list = data_list 286 try: 287 for data in selected_data_list: 288 page = self.add_fit_page(data=data) 289 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 290 title=str(data.title))) 291 except: 292 msg = "Fitting Set_data: " + str(sys.exc_value) 293 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 289 if len(data_list) > MAX_NBR_DATA: 290 from fitting_widgets import DataDialog 291 dlg = DataDialog(data_list=data_list, nb_data=MAX_NBR_DATA) 292 if dlg.ShowModal() == wx.ID_OK: 293 selected_data_list = dlg.get_data() 294 dlg.Destroy() 295 296 else: 297 selected_data_list = data_list 298 try: 299 for data in selected_data_list: 300 page = self.add_fit_page(data=[data]) 301 except: 302 msg = "Fitting Set_data: " + str(sys.exc_value) 303 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 294 304 295 305 def set_top_panel(self): … … 371 381 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 372 382 title=data.title)) 373 page = self.add_fit_page( data)383 page = self.add_fit_page([data]) 374 384 caption = page.window_name 375 self.store_data(page=page.uid, data=data, caption=caption) 385 self.store_data(uid=page.uid, data=page.get_data(), 386 data_list=page.get_data_list(), 387 caption=page.window_name) 376 388 self.mypanels.append(page) 377 389 … … 602 614 """ 603 615 perform fit 604 605 : param type: uid for single fit, None for simultaneous fit 606 """ 607 from sans.fit.Fitting import Fit 608 from .fit_thread import FitThread 609 from .console import ConsoleUpdate 616 """ 610 617 ## count the number of fitproblem schedule to fit 611 #if uid == None or self._fit_engine == "park":612 618 fitproblem_count = 0 613 619 for value in self.page_finder.values(): … … 616 622 617 623 ## if simultaneous fit change automatically the engine to park 618 # scipy can not handle two thread running at the same time 619 if fitproblem_count > 1 or len(self.fit_thread_list)>0: 624 if fitproblem_count > 1: 620 625 self._on_change_engine(engine='park') 621 626 622 627 self.fitproblem_count = fitproblem_count 623 628 629 from sans.fit.Fitting import Fit 624 630 fitter = Fit(self._fit_engine) 631 625 632 if self._fit_engine == "park": 626 633 engineType = "Simultaneous Fit" … … 628 635 engineType = "Single Fit" 629 636 637 fitter_list = [] 630 638 fproblemId = 0 631 639 self.current_pg = None … … 655 663 self._fit_helper(value=value, pars=pars, 656 664 fitter=fitter, 665 fitter_list=fitter_list, 657 666 fitproblem_id=fproblemId, 658 667 title=engineType) … … 679 688 self._mac_sleep(0.2) 680 689 ## perform single fit 681 682 690 if fitproblem_count == 1: 691 print "fitter_list", fitter_list 683 692 calc_fit = FitThread(handler = handler, 684 fn=fitter ,693 fn=fitter_list, 685 694 pars=pars, 686 695 page_id=list_page_id, … … 691 700 ## Perform more than 1 fit at the time 692 701 calc_fit = FitThread(handler=handler, 693 fn=fitter ,702 fn=fitter_list, 694 703 page_id=list_page_id, 695 704 updatefn=handler.update_fit, 696 705 completefn=self._simul_fit_completed, 697 706 ftol=self.ftol) 698 699 707 self.fit_thread_list[current_page_id] = calc_fit 700 self._mac_sleep(0.2)701 702 #self.ready_fit(calc_fit=calc_fit)703 708 calc_fit.queue() 704 709 msg = "Fitting is in progress..." 710 wx.PostEvent( self.parent, StatusEvent(status=msg, type="progress" )) 711 712 self.ready_fit(calc_fit=calc_fit) 713 705 714 def ready_fit(self, calc_fit): 706 715 """ … … 730 739 action='remove')) 731 740 732 def store_data(self, uid, data=None, caption=None):741 def store_data(self, uid, data=None, data_list=None, caption=None): 733 742 """ 734 743 Helper to save page reference into the plug-in … … 737 746 738 747 """ 748 if data_list is None: 749 data_list = [] 739 750 #create a fitproblem storing all link to data,model,page creation 740 751 if not uid in self.page_finder.keys(): 741 752 self.page_finder[uid] = FitProblem() 742 753 self.page_finder[uid].set_fit_data(data) 754 self.page_finder[uid].set_fit_data_list(data_list) 743 755 self.page_finder[uid].set_fit_tab_caption(caption) 744 756 … … 778 790 if page.uid in self.page_finder: 779 791 theory_data = self.page_finder[page.uid].get_theory_data() 792 data = page.get_data() 780 793 if issubclass(data.__class__, Data2D): 781 794 data.group_id = wx.NewId() … … 795 808 self.parent.update_data(prev_data=theory_data, new_data=data) 796 809 797 self.store_data(uid=page.uid, data=data, caption=page.window_name) 810 self.store_data(uid=page.uid, data=page.get_data(), 811 data_list=page.get_data_list(), 812 caption=page.window_name) 798 813 if self.sim_page is not None: 799 814 self.sim_page.draw_page() … … 875 890 self.page_finder[uid].schedule_tofit(value) 876 891 877 def _fit_helper(self, pars, value, fitproblem_id,fitter, title="Single Fit " ): 878 """ 879 helper for fitting 880 """ 881 metadata = value.get_fit_data() 892 def _fit_setter(self, data, value, fitter, fit_id, pars): 893 """ 894 """ 882 895 model = value.get_model() 883 896 smearer = value.get_smearer() 884 897 qmin, qmax = value.get_range() 885 self.fit_id = fitproblem_id 898 #Extra list of parameters and their constraints 899 listOfConstraint = [] 900 901 param = value.get_model_param() 902 if len(param) > 0: 903 for item in param: 904 ## check if constraint 905 if item[0] != None and item[1] != None: 906 listOfConstraint.append((item[0],item[1])) 907 908 #Do the single fit 909 fitter.set_model(deepcopy(model), fit_id, 910 pars, constraints=listOfConstraint) 911 912 fitter.set_data(data=data, id=fit_id, 913 smearer=smearer, qmin=qmin, qmax=qmax) 914 915 fitter.select_problem_for_fit(id=fit_id, value=1) 916 value.clear_model_param() 917 918 919 def _fit_helper(self, pars, value, fitproblem_id, fitter_list, 920 fitter=None, title="Single Fit " ): 921 """ 922 helper for fitting 923 """ 924 from sans.fit.Fitting import Fit 925 self.fit_id = 0 926 data_list = value.get_fit_data_list() 927 pointer_to_fitproblem = value.get_pointer_to_fitproblem() 886 928 #Create list of parameters for fitting used 887 929 templist = [] 888 889 try: 890 #Extra list of parameters and their constraints 891 listOfConstraint = [] 892 893 param = value.get_model_param() 894 if len(param) > 0: 895 for item in param: 896 ## check if constraint 897 if item[0] != None and item[1] != None: 898 listOfConstraint.append((item[0],item[1])) 899 900 #Do the single fit 901 fitter.set_model(model, self.fit_id, 902 pars, constraints=listOfConstraint) 903 904 fitter.set_data(data=metadata, id=self.fit_id, 905 smearer=smearer, qmin=qmin, qmax=qmax) 906 907 fitter.select_problem_for_fit(id=self.fit_id, 908 value=value.get_scheduled()) 909 value.clear_model_param() 910 except: 911 raise 912 #msg = title + " error: %s" % sys.exc_value 913 #wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 914 930 for single_data in data_list: 931 fitter = Fit(self._fit_engine) 932 try: 933 if single_data.id in pointer_to_fitproblem: 934 new_value = self.page_finder[pointer_to_fitproblem[single_data.id]] 935 self._fit_setter(data=single_data, value=new_value, 936 fitter=fitter, 937 pars=pars, 938 fit_id=self.fit_id) 939 else: 940 self._fit_setter(data=single_data, value=value, 941 fitter=fitter, 942 pars=pars, 943 fit_id=self.fit_id) 944 except: 945 raise 946 #msg = title + " error: %s" % sys.exc_value 947 #wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) 948 fitter_list.append(fitter) 949 self.fit_id += 1 950 915 951 def _onSelect(self,event): 916 952 """ … … 925 961 if plottable == self.panel.plots[data_id]: 926 962 data = plottable 927 self.add_fit_page(data= data)963 self.add_fit_page(data=[data]) 928 964 return 929 965 else: 930 966 data = plottable 931 self.add_fit_page(data= data)967 self.add_fit_page(data=[data]) 932 968 self.set_top_panel() 933 969 … … 936 972 """ 937 973 print "update_fit result", result 974 975 def _batch_single_fit_complete_helper(self,result, pars, page_id, elapsed=None): 976 """ 977 Fit result are display in batch mode 978 """ 979 self._update_fit_button(page_id) 980 msg = "Single Fitting complete " 981 wx.PostEvent(self.parent, StatusEvent(status=msg, info="info", 982 type="stop")) 983 if self.batch_on: 984 batch_result = {"Chi2":[]} 985 for index in range(len(pars)): 986 batch_result[pars[index]] = [] 987 batch_result["error on %s" % pars[index]] = [] 988 for res in result: 989 batch_result["Chi2"].append(res.fitness) 990 for index in range(len(pars)): 991 batch_result[pars[index]].append(res.pvec[index]) 992 batch_result["error on %s" % pars[index]].append(res.stderr[index]) 993 994 pid = page_id[0] 995 self.page_finder[pid].set_result(result=batch_result) 996 self.parent.on_set_batch_result(data=batch_result, name=self.sub_menu) 997 938 998 939 999 def _single_fit_completed(self, result, pars, page_id, elapsed=None): … … 950 1010 self._mac_sleep(0.2) 951 1011 if page_id[0] in self.fit_thread_list.keys(): 952 del self.fit_thread_list[page_id[0]] 953 try: 954 if result == None: 1012 del self.fit_thread_list[page_id[0]] 1013 if self.batch_on: 1014 wx.CallAfter(self._batch_single_fit_complete_helper, result, pars, page_id, elapsed=None) 1015 return 1016 else: 1017 try: 1018 result = result[0] 1019 if result == None: 1020 self._update_fit_button(page_id) 1021 msg= "Single Fitting did not converge!!!" 1022 wx.PostEvent(self.parent, 1023 StatusEvent(status=msg, 1024 info="warning", 1025 type="stop")) 1026 return 1027 if not numpy.isfinite(result.fitness) or \ 1028 numpy.any(result.pvec == None) or \ 1029 not numpy.all(numpy.isfinite(result.pvec)): 1030 msg = "Single Fitting did not converge!!!" 1031 wx.PostEvent(self.parent, 1032 StatusEvent(status=msg, 1033 info="warning", 1034 type="stop")) 1035 self._update_fit_button(page_id) 1036 return 1037 1038 for uid in page_id: 1039 value = self.page_finder[uid] 1040 model = value.get_model() 1041 page_id = uid 1042 1043 param_name = [] 1044 for name in pars: 1045 param_name.append(name) 1046 1047 cpage = self.fit_panel.get_page_by_id(uid) 1048 # Make sure we got all results (CallAfter is important to MAC) 1049 wx.CallAfter(cpage.onsetValues, result.fitness, 1050 param_name, result.pvec, result.stderr) 1051 cpage._on_fit_complete() 1052 if result.stderr == None: 1053 msg = "Fit Abort: " 1054 else: 1055 msg = "Fitting: " 1056 msg += "Completed!!!" 1057 wx.PostEvent(self.parent, StatusEvent(status=msg)) 1058 return 1059 except ValueError: 955 1060 self._update_fit_button(page_id) 956 msg= "Single Fitting did not converge!!!" 957 wx.PostEvent(self.parent, 958 StatusEvent(status=msg, 959 info="warning", 960 type="stop")) 1061 msg = "Single Fitting did not converge!!!" 1062 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 1063 type="stop")) 1064 return 1065 except: 1066 self._update_fit_button(page_id) 1067 msg = "Single Fit completed but Following" 1068 msg += " error occurred:%s" % sys.exc_value 1069 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 1070 type="stop")) 1071 raise 961 1072 return 962 if not numpy.isfinite(result.fitness) or \ 963 numpy.any(result.pvec == None) or \ 964 not numpy.all(numpy.isfinite(result.pvec)): 965 msg = "Single Fitting did not converge!!!" 966 wx.PostEvent(self.parent, 967 StatusEvent(status=msg, 968 info="warning", 969 type="stop")) 970 self._update_fit_button(page_id) 971 return 972 973 for uid in page_id: 974 value = self.page_finder[uid] 975 model = value.get_model() 976 page_id = uid 977 978 param_name = [] 979 for name in pars: 980 param_name.append(name) 981 982 cpage = self.fit_panel.get_page_by_id(uid) 983 # Make sure we got all results (CallAfter is important to MAC) 984 wx.CallAfter(cpage.onsetValues, result.fitness, 985 param_name, result.pvec, result.stderr) 986 cpage._on_fit_complete() 987 if result.stderr == None: 988 msg = "Fit Abort: " 989 else: 990 msg = "Fitting: " 991 msg += "Completed!!!" 992 wx.PostEvent(self.parent, StatusEvent(status=msg)) 993 return 994 except ValueError: 995 self._update_fit_button(page_id) 996 msg = "Single Fitting did not converge!!!" 997 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 998 type="stop")) 999 return 1000 except: 1001 self._update_fit_button(page_id) 1002 msg = "Single Fit completed but Following" 1003 msg += " error occurred:%s" % sys.exc_value 1004 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", 1005 type="stop")) 1006 raise 1007 return 1008 1073 1009 1074 def _simul_fit_completed(self, result, page_id,pars=None, elapsed=None): 1010 1075 """
Note: See TracChangeset
for help on using the changeset viewer.