Changeset 386ffe1 in sasview for src/sas/perspectives/fitting/fitting.py
- Timestamp:
- Feb 20, 2015 5:02:38 AM (10 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:
- cda1cf8
- Parents:
- 018582f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/perspectives/fitting/fitting.py
rfd5ac0d r386ffe1 45 45 from sas.guiframe.gui_manager import MDIFrame 46 46 47 # TODO: remove globals from interface to bumps options!48 # Default bumps to use the levenberg-marquardt optimizer49 import bumps.fitters50 bumps.fitters.FIT_DEFAULT = 'lm'51 52 47 MAX_NBR_DATA = 4 53 SAS_F_TOL = 5e-0554 48 55 49 (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() … … 93 87 self._fit_engine = 'bumps' 94 88 self._gui_engine = None 95 ## Relative error desired in the sum of squares (float); scipy only 96 self.ftol = SAS_F_TOL 89 ## Relative error desired in the sum of squares (float) 97 90 self.batch_reset_flag = True 98 91 #List of selected data … … 112 105 self.state_reader = None 113 106 self._extensions = '.fitv' 114 self.scipy_id = wx.NewId()115 self.park_id = wx.NewId()116 self.bumps_id = wx.NewId()117 107 self.menu1 = None 118 108 self.new_model_frame = None … … 191 181 self.batch_menu.Enable(False) 192 182 self.menu1.AppendSeparator() 193 #Set park engine 194 scipy_help = "Scipy Engine: Perform Simple fit. More in Help window...." 195 self.menu1.AppendCheckItem(self.scipy_id, "Simple FitEngine [LeastSq]", 196 scipy_help) 197 wx.EVT_MENU(owner, self.scipy_id, self._onset_engine_scipy) 198 199 park_help = "Park Engine: Perform Complex fit. More in Help window...." 200 self.menu1.AppendCheckItem(self.park_id, "Complex FitEngine [ParkMC]", 201 park_help) 202 wx.EVT_MENU(owner, self.park_id, self._onset_engine_park) 203 204 bumps_help = "Bumps: fitting and uncertainty analysis. More in Help window...." 205 self.menu1.AppendCheckItem(self.bumps_id, "Bumps fit", 206 bumps_help) 207 wx.EVT_MENU(owner, self.bumps_id, self._onset_engine_bumps) 208 209 self.menu1.FindItemById(self.scipy_id).Check(self._fit_engine=="scipy") 210 self.menu1.FindItemById(self.park_id).Check(self._fit_engine=="park") 211 self.menu1.FindItemById(self.bumps_id).Check(self._fit_engine=="bumps") 183 212 184 self.menu1.AppendSeparator() 213 self.id_tol = wx.NewId()214 ftol_help = "Change the current FTolerance (=%s) " % str(self.ftol)215 ftol_help += "of Simple FitEngine..."216 self.menu1.Append(self.id_tol, "Change FTolerance",217 ftol_help)218 wx.EVT_MENU(owner, self.id_tol, self.show_ftol_dialog)219 220 185 self.id_bumps_options = wx.NewId() 221 bopts_help = " Bumps fitting options"222 self.menu1.Append(self.id_bumps_options, ' Bumps&Options', bopts_help)186 bopts_help = "Fitting options" 187 self.menu1.Append(self.id_bumps_options, 'Fit &Options', bopts_help) 223 188 wx.EVT_MENU(owner, self.id_bumps_options, self.on_bumps_options) 224 189 self.bumps_options_menu = self.menu1.FindItemById(self.id_bumps_options) … … 776 741 :param value: can be a string in this case. 777 742 :param names: the paramter name 778 779 :note: expecting park used for fit.780 781 743 """ 782 744 sim_page_id = self.sim_page.uid … … 808 770 return model_name, param_name 809 771 810 def set_ftol(self, ftol=None):811 """812 Set ftol: Relative error desired in the sum of chi squares.813 """814 # check if it is flaot815 try:816 f_tol = float(ftol)817 except:818 # default819 f_tol = SAS_F_TOL820 821 self.ftol = f_tol822 # update ftol menu help strings823 ftol_help = "Change the current FTolerance (=%s) " % str(self.ftol)824 ftol_help += "of Simple FitEngine..."825 if self.menu1 != None:826 self.menu1.SetHelpString(self.id_tol, ftol_help)827 828 def show_ftol_dialog(self, event=None):829 """830 Dialog to select ftol for Scipy831 """832 from ftol_dialog import ChangeFtol833 dialog = ChangeFtol(self.parent, self)834 result = dialog.ShowModal()835 if result == wx.ID_OK:836 value = dialog.get_ftol()837 if value is not None:838 self.set_ftol(value)839 msg = "The ftol (LeastSq) is set to %s." % value840 else:841 msg = "Error in the selection... No change in ftol."842 # post event for info843 wx.PostEvent(self.parent,844 StatusEvent(status=msg, info='warning'))845 dialog.Destroy()846 847 772 def on_bumps_options(self, event=None): 848 773 from bumps.gui.fit_dialog import OpenFitOptions … … 983 908 if uid is None: raise RuntimeError("no page to fit") # Should never happen 984 909 985 # Remember the user selected fit engine before the fit. Simultaneous986 # fitting may change the selected engine, so it needs to be restored987 # when the fit is complete.988 self._gui_engine = self._fit_engine989 990 910 sim_page_uid = getattr(self.sim_page, 'uid', None) 991 911 batch_page_uid = getattr(self.batch_page, 'uid', None) … … 997 917 else: 998 918 fit_type = 'single' 999 1000 # if constrained fit, don't use scipy leastsq directly1001 if fit_type == 'simultaneous':1002 if self._fit_engine not in ("park","bumps"):1003 self._on_change_engine(engine='bumps')1004 1005 919 1006 920 fitter_list = [] … … 1075 989 wx.PostEvent(self.parent, StatusEvent(status=msg, type="progress")) 1076 990 1077 #Handler used for parkengine displayed message991 #Handler used for fit engine displayed message 1078 992 handler = ConsoleUpdate(parent=self.parent, 1079 993 manager=self, … … 1098 1012 page_id=list_page_id, 1099 1013 completefn=self._batch_fit_complete, 1100 ftol=self.ftol,1101 1014 reset_flag=self.batch_reset_flag) 1102 1015 else: … … 1108 1021 page_id=list_page_id, 1109 1022 updatefn=handler.update_fit, 1110 completefn=self._fit_completed, 1111 ftol=self.ftol) 1023 completefn=self._fit_completed) 1112 1024 #self.fit_thread_list[current_page_id] = calc_fit 1113 1025 self.fit_thread_list[uid] = calc_fit … … 1568 1480 type="stop")) 1569 1481 wx.PostEvent(self.result_panel, PlotResultEvent(result=result)) 1570 # reset fit_engine if changed by simul_fit1571 if self._fit_engine != self._gui_engine:1572 self._on_change_engine(self._gui_engine)1573 1482 self._update_fit_button(page_id) 1574 1483 result = result[0] … … 1667 1576 StatusEvent(status=msg)) 1668 1577 1669 def _onset_engine_park(self, event): 1670 """ 1671 set engine to park 1672 """ 1673 self._on_change_engine('park') 1674 1675 def _onset_engine_scipy(self, event): 1676 """ 1677 set engine to scipy 1678 """ 1679 self._on_change_engine('scipy') 1680 1681 def _onset_engine_bumps(self, event): 1682 """ 1683 set engine to bumps 1684 """ 1685 self._on_change_engine('bumps') 1686 1578 1687 1579 def _on_slicer_event(self, event): 1688 1580 """ … … 1705 1597 """ 1706 1598 name = event.GetEventObject().frame.GetTitle() 1707 print "name", name1708 1599 for panel in self.slicer_panels: 1709 1600 if panel.window_caption == name: … … 1717 1608 break 1718 1609 1719 def _on_change_engine(self, engine='park'):1720 """1721 Allow to select the type of engine to perform fit1722 1723 :param engine: the key work of the engine1724 1725 """1726 ## saving fit engine name1727 self._fit_engine = engine1728 ## change menu item state1729 if engine == "park":1730 self.menu1.FindItemById(self.park_id).Check(True)1731 self.menu1.FindItemById(self.scipy_id).Check(False)1732 self.menu1.FindItemById(self.bumps_id).Check(False)1733 elif engine == "scipy":1734 self.menu1.FindItemById(self.park_id).Check(False)1735 self.menu1.FindItemById(self.scipy_id).Check(True)1736 self.menu1.FindItemById(self.bumps_id).Check(False)1737 else:1738 self.menu1.FindItemById(self.park_id).Check(False)1739 self.menu1.FindItemById(self.scipy_id).Check(False)1740 self.menu1.FindItemById(self.bumps_id).Check(True)1741 ## post a message to status bar1742 msg = "Engine set to: %s" % self._fit_engine1743 wx.PostEvent(self.parent,1744 StatusEvent(status=msg))1745 ## send the current engine type to fitpanel1746 self.fit_panel._on_engine_change(name=self._fit_engine)1747 1748 1610 def _on_model_panel(self, evt): 1749 1611 """
Note: See TracChangeset
for help on using the changeset viewer.