Changeset 9687d58 in sasview for src/sas/sasgui/perspectives/fitting/fitting.py
- Timestamp:
- Apr 10, 2017 4:01:46 AM (8 years ago)
- Branches:
- 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
- Children:
- 6c8fb2c
- Parents:
- 9208346 (diff), c6f3aec (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/fitting.py
r811bec1 r9687d58 45 45 from sas.sasgui.guiframe.gui_manager import MDIFrame 46 46 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 47 from sas.sasgui.perspectives.fitting.gpu_options import GpuOptions 47 48 48 49 from . import models … … 193 194 self.bumps_options_menu.Enable(True) 194 195 196 self.id_gpu_options_panel = wx.NewId() 197 self.menu1.Append(self.id_gpu_options_panel, "OpenCL Options", "Choose OpenCL driver or turn it off") 198 wx.EVT_MENU(owner, self.id_gpu_options_panel, self.on_gpu_options) 199 195 200 self.id_result_panel = wx.NewId() 196 201 self.menu1.Append(self.id_result_panel, "Fit Results", "Show fit results panel") … … 221 226 self.id_edit = wx.NewId() 222 227 editmodel_help = "Edit customized model sample file" 223 self.menu1.AppendMenu(self.id_edit, " Edit Custom Model",228 self.menu1.AppendMenu(self.id_edit, "Plugin Model Operations", 224 229 self.edit_model_menu, editmodel_help) 225 230 #create menubar items … … 236 241 frame = PyConsole(parent=self.parent, manager=self, 237 242 panel=self.fit_panel, 238 title='Advanced CustomModel Editor',243 title='Advanced Plugin Model Editor', 239 244 filename=filename) 240 245 self.put_icon(frame) … … 302 307 event_id = event.GetId() 303 308 dir_path = models.find_plugins_dir() 304 title = "New CustomModel Function"309 title = "New Plugin Model Function" 305 310 self.new_model_frame = EditorWindow(parent=self, base=self, 306 311 path=dir_path, title=title) … … 313 318 """ 314 319 event_id = event.GetId() 315 self.update_custom_combo() 320 self.update_custom_combo() 316 321 317 322 def update_custom_combo(self): … … 319 324 Update custom model list in the fitpage combo box 320 325 """ 321 custom_model = ' CustomizedModels'326 custom_model = 'Plugin Models' 322 327 try: 323 328 # Update edit menus … … 342 347 page.formfactorbox.SetLabel(current_val) 343 348 except: 344 pass 345 349 logging.error("update_custom_combo: %s", sys.exc_value) 346 350 347 351 def set_edit_menu(self, owner): … … 351 355 wx_id = wx.NewId() 352 356 #new_model_menu = wx.Menu() 353 self.edit_model_menu.Append(wx_id, 'New ',357 self.edit_model_menu.Append(wx_id, 'New Plugin Model', 354 358 'Add a new model function') 355 359 wx.EVT_MENU(owner, wx_id, self.make_new_model) … … 363 367 self.edit_menu = wx.Menu() 364 368 self.edit_model_menu.AppendMenu(e_id, 365 'Advanced ', self.edit_menu)369 'Advanced Plugin Editor', self.edit_menu) 366 370 self.set_edit_menu_helper(owner, self.edit_custom_model) 367 371 … … 369 373 self.delete_menu = wx.Menu() 370 374 self.edit_model_menu.AppendMenu(d_id, 371 'Delete ', self.delete_menu)375 'Delete Plugin Models', self.delete_menu) 372 376 self.set_edit_menu_helper(owner, self.delete_custom_model) 373 377 374 378 wx_id = wx.NewId() 375 self.edit_model_menu.Append(wx_id, 'Load Models',379 self.edit_model_menu.Append(wx_id, 'Load Plugin Models', 376 380 '(Re)Load all models present in user plugin_models folder') 377 381 wx.EVT_MENU(owner, wx_id, self.load_plugin_models) 378 382 379 383 def set_edit_menu_helper(self, owner=None, menu=None): 380 384 """ … … 594 598 : param datainfo: data 595 599 """ 596 #state = self.state_reader.get_state() 597 if state != None: 600 from pagestate import PageState 601 from simfitpage import SimFitPageState 602 if isinstance(state, PageState): 598 603 state = state.clone() 599 # store fitting state in temp_state600 604 self.temp_state.append(state) 605 elif isinstance(state, SimFitPageState): 606 state.load_from_save_state(self) 601 607 else: 602 608 self.temp_state = [] … … 801 807 self.result_frame.Raise() 802 808 809 def on_gpu_options(self, event=None): 810 """ 811 Make the Fit Results panel visible. 812 """ 813 dialog = GpuOptions(None, wx.ID_ANY, "") 814 dialog.Show() 815 803 816 def stop_fit(self, uid): 804 817 """ … … 863 876 enable1D=enable1D, enable2D=enable2D, 864 877 qmin=qmin, qmax=qmax, weight=weight) 865 self._mac_sleep(0.2)866 878 867 879 def _mac_sleep(self, sec=0.2): … … 1520 1532 for uid in page_id: 1521 1533 res = result[index] 1534 fit_msg = res.mesg 1522 1535 if res.fitness is None or \ 1523 1536 not numpy.isfinite(res.fitness) or \ 1524 1537 numpy.any(res.pvec == None) or \ 1525 1538 not numpy.all(numpy.isfinite(res.pvec)): 1526 msg = "Fitting did not converge!!!" 1527 evt = StatusEvent(status=msg, info="warning", type="stop") 1528 wx.PostEvent(self.parent, evt) 1539 fit_msg += "\nFitting did not converge!!!" 1529 1540 wx.CallAfter(self._update_fit_button, page_id) 1530 1541 else: … … 1549 1560 wx.CallAfter(cpage._on_fit_complete) 1550 1561 except KeyboardInterrupt: 1551 msg = "Singular point: Fitting Stoped." 1552 evt = StatusEvent(status=msg, info="info", type="stop") 1553 wx.PostEvent(self.parent, evt) 1562 fit_msg += "\nSingular point: Fitting stopped." 1554 1563 except: 1555 msg = "Singular point: Fitting Error occurred." 1556 evt = StatusEvent(status=msg, info="error", type="stop") 1557 wx.PostEvent(self.parent, evt) 1564 fit_msg += "\nSingular point: Fitting error occurred." 1565 if fit_msg: 1566 evt = StatusEvent(status=fit_msg, info="warning", type="stop") 1567 wx.PostEvent(self.parent, evt) 1558 1568 1559 1569 except: … … 1666 1676 wx.PostEvent(self.parent, StatusEvent(status=msg, type="update")) 1667 1677 1678 def create_theory_1D(self, x, y, page_id, model, data, state, 1679 data_description, data_id, dy=None): 1680 """ 1681 Create a theory object associate with an existing Data1D 1682 and add it to the data manager. 1683 @param x: x-values of the data 1684 @param y: y_values of the data 1685 @param page_id: fit page ID 1686 @param model: model used for fitting 1687 @param data: Data1D object to create the theory for 1688 @param state: model state 1689 @param data_description: title to use in the data manager 1690 @param data_id: unique data ID 1691 """ 1692 new_plot = Data1D(x=x, y=y) 1693 if dy is None: 1694 new_plot.is_data = False 1695 new_plot.dy = numpy.zeros(len(y)) 1696 # If this is a theory curve, pick the proper symbol to make it a curve 1697 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 1698 else: 1699 new_plot.is_data = True 1700 new_plot.dy = dy 1701 new_plot.interactive = True 1702 new_plot.dx = None 1703 new_plot.dxl = None 1704 new_plot.dxw = None 1705 _yaxis, _yunit = data.get_yaxis() 1706 _xaxis, _xunit = data.get_xaxis() 1707 new_plot.title = data.name 1708 new_plot.group_id = data.group_id 1709 if new_plot.group_id == None: 1710 new_plot.group_id = data.group_id 1711 new_plot.id = data_id 1712 # Find if this theory was already plotted and replace that plot given 1713 # the same id 1714 self.page_finder[page_id].get_theory_data(fid=data.id) 1715 1716 if data.is_data: 1717 data_name = str(data.name) 1718 else: 1719 data_name = str(model.__class__.__name__) 1720 1721 new_plot.name = data_description + " [" + data_name + "]" 1722 new_plot.xaxis(_xaxis, _xunit) 1723 new_plot.yaxis(_yaxis, _yunit) 1724 self.page_finder[page_id].set_theory_data(data=new_plot, 1725 fid=data.id) 1726 self.parent.update_theory(data_id=data.id, theory=new_plot, 1727 state=state) 1728 return new_plot 1729 1668 1730 def _complete1D(self, x, y, page_id, elapsed, index, model, 1669 1731 weight=None, fid=None, 1670 1732 toggle_mode_on=False, state=None, 1671 1733 data=None, update_chisqr=True, 1672 source='model', plot_result=True): 1673 """ 1674 Complete plotting 1D data 1734 source='model', plot_result=True, 1735 unsmeared_model=None, unsmeared_data=None, 1736 unsmeared_error=None, sq_model=None, pq_model=None): 1737 """ 1738 Complete plotting 1D data 1739 @param unsmeared_model: fit model, without smearing 1740 @param unsmeared_data: data, rescaled to unsmeared model 1741 @param unsmeared_error: data error, rescaled to unsmeared model 1675 1742 """ 1676 1743 try: 1677 1744 numpy.nan_to_num(y) 1678 1679 new_plot = Data1D(x=x, y=y) 1680 new_plot.is_data = False 1681 new_plot.dy = numpy.zeros(len(y)) 1682 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 1683 _yaxis, _yunit = data.get_yaxis() 1684 _xaxis, _xunit = data.get_xaxis() 1685 new_plot.title = data.name 1686 1687 new_plot.group_id = data.group_id 1688 if new_plot.group_id == None: 1689 new_plot.group_id = data.group_id 1690 new_plot.id = str(page_id) + " " + data.name 1691 #if new_plot.id in self.color_dict: 1692 # new_plot.custom_color = self.color_dict[new_plot.id] 1693 #find if this theory was already plotted and replace that plot given 1694 #the same id 1695 self.page_finder[page_id].get_theory_data(fid=data.id) 1696 1697 if data.is_data: 1698 data_name = str(data.name) 1699 else: 1700 data_name = str(model.__class__.__name__) 1701 1702 new_plot.name = model.name + " [" + data_name + "]" 1703 new_plot.xaxis(_xaxis, _xunit) 1704 new_plot.yaxis(_yaxis, _yunit) 1705 self.page_finder[page_id].set_theory_data(data=new_plot, 1706 fid=data.id) 1707 self.parent.update_theory(data_id=data.id, theory=new_plot, 1708 state=state) 1745 new_plot = self.create_theory_1D(x, y, page_id, model, data, state, 1746 data_description=model.name, 1747 data_id=str(page_id) + " " + data.name) 1748 if unsmeared_model is not None: 1749 self.create_theory_1D(x, unsmeared_model, page_id, model, data, state, 1750 data_description=model.name + " unsmeared", 1751 data_id=str(page_id) + " " + data.name + " unsmeared") 1752 1753 if unsmeared_data is not None and unsmeared_error is not None: 1754 self.create_theory_1D(x, unsmeared_data, page_id, model, data, state, 1755 data_description="Data unsmeared", 1756 data_id="Data " + data.name + " unsmeared", 1757 dy=unsmeared_error) 1758 1759 if sq_model is not None and pq_model is not None: 1760 self.create_theory_1D(x, sq_model, page_id, model, data, state, 1761 data_description=model.name + " S(q)", 1762 data_id=str(page_id) + " " + data.name + " S(q)") 1763 self.create_theory_1D(x, pq_model, page_id, model, data, state, 1764 data_description=model.name + " P(q)", 1765 data_id=str(page_id) + " " + data.name + " P(q)") 1766 1767 1709 1768 current_pg = self.fit_panel.get_page_by_id(page_id) 1710 1769 title = new_plot.title … … 1916 1975 ## May need rethinking 1917 1976 ## 1918 ## -PDB August 12, 2014 1977 ## -PDB August 12, 2014 1919 1978 while self.calc_1D.isrunning(): 1920 1979 time.sleep(0.1)
Note: See TracChangeset
for help on using the changeset viewer.