Changeset 00f7ff1 in sasview for src/sas/sasgui/perspectives/fitting
- Timestamp:
- Jun 21, 2017 11:17:18 AM (7 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, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 81b35396
- Parents:
- 2a0f33f
- Location:
- src/sas/sasgui/perspectives/fitting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/basepage.py
r2a0f33f r00f7ff1 157 157 self.disp_cb_dict = {} 158 158 159 # self.state = PageState( parent=parent)159 # self.state = PageState() 160 160 # dictionary containing list of models 161 161 self.model_list_box = {} … … 204 204 self.fitrange = True 205 205 # Create memento to save the current state 206 self.state = PageState(parent=self.parent, 207 model=self.model, data=self.data) 206 self.state = PageState(model=self.model, data=self.data) 208 207 # flag to determine if state has change 209 208 self.state_change = False -
src/sas/sasgui/perspectives/fitting/fitting.py
r2a0f33f r00f7ff1 23 23 import traceback 24 24 25 import bumps.options 26 from bumps.gui.fit_dialog import show_fit_config 27 try: 28 from bumps.gui.fit_dialog import EVT_FITTER_CHANGED 29 except ImportError: 30 # CRUFT: bumps 0.7.5.8 and below 31 EVT_FITTER_CHANGED = None # type: wx.PyCommandEvent 32 25 33 from sas.sascalc.dataloader.loader import Loader 26 34 from sas.sascalc.fit.BumpsFitting import BumpsFit as Fit 27 from sas.sascalc.fit.pagestate import Reader 35 from sas.sascalc.fit.pagestate import Reader, PageState, SimFitPageState 28 36 29 37 from sas.sasgui.guiframe.dataFitting import Data2D … … 37 45 from sas.sasgui.guiframe.plugin_base import PluginBase 38 46 from sas.sasgui.guiframe.data_processor import BatchCell 39 from sas.sasgui.perspectives.fitting.console import ConsoleUpdate 40 from sas.sasgui.perspectives.fitting.fitproblem import FitProblemDictionary 41 from sas.sasgui.perspectives.fitting.fitpanel import FitPanel 42 from sas.sasgui.perspectives.fitting.resultpanel import ResultPanel, PlotResultEvent 43 44 from sas.sasgui.perspectives.fitting.fit_thread import FitThread 45 from sas.sasgui.perspectives.fitting.pagestate import Reader 46 from sas.sasgui.perspectives.fitting.fitpage import Chi2UpdateEvent 47 from sas.sasgui.guiframe.gui_manager import MDIFrame 48 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 49 47 50 from sas.sasgui.perspectives.calculator.model_editor import TextDialog 48 51 from sas.sasgui.perspectives.calculator.model_editor import EditorWindow 49 from sas.sasgui.guiframe.gui_manager import MDIFrame 50 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 51 from sas.sasgui.perspectives.fitting.gpu_options import GpuOptions 52 52 53 from .fitting_widgets import DataDialog 54 from .fit_thread import FitThread 55 from .fitpage import Chi2UpdateEvent 56 from .console import ConsoleUpdate 57 from .fitproblem import FitProblemDictionary 58 from .fitpanel import FitPanel 59 from .model_thread import Calc1D, Calc2D 60 from .resultpanel import ResultPanel, PlotResultEvent 61 from .gpu_options import GpuOptions 53 62 from . import models 54 63 … … 65 74 ON_MAC = True 66 75 67 import bumps.options68 from bumps.gui.fit_dialog import show_fit_config69 try:70 from bumps.gui.fit_dialog import EVT_FITTER_CHANGED71 except ImportError:72 # CRUFT: bumps 0.7.5.8 and below73 EVT_FITTER_CHANGED = None # type: wx.PyCommandEvent74 76 75 77 class Plugin(PluginBase): … … 240 242 Get the python editor panel 241 243 """ 244 from sas.sasgui.perspectives.calculator.pyconsole import PyConsole 245 242 246 event_id = event.GetId() 243 247 label = self.edit_menu.GetLabel(event_id) 244 from sas.sasgui.perspectives.calculator.pyconsole import PyConsole245 248 filename = os.path.join(models.find_plugins_dir(), label) 246 249 frame = PyConsole(parent=self.parent, manager=self, … … 284 287 break 285 288 except Exception: 286 import traceback;traceback.print_exc()289 traceback.print_exc() 287 290 msg = 'Delete Error: \nCould not delete the file; Check if in use.' 288 291 wx.MessageBox(msg, 'Error') … … 558 561 else: 559 562 if len(data_list) > MAX_NBR_DATA: 560 from fitting_widgets import DataDialog561 563 dlg = DataDialog(data_list=data_list, nb_data=MAX_NBR_DATA) 562 564 if dlg.ShowModal() == wx.ID_OK: … … 603 605 : param datainfo: data 604 606 """ 605 from pagestate import PageState606 from simfitpage import SimFitPageState607 607 if isinstance(state, PageState): 608 608 state = state.clone() 609 609 self.temp_state.append(state) 610 610 elif isinstance(state, SimFitPageState): 611 state.load_from_save_state(self) 611 if self.fit_panel.sim_page is None: 612 self.fit_panel.add_sim_page() 613 self.fit_panel.sim_page.load_from_save_state(state) 612 614 else: 613 615 self.temp_state = [] … … 1456 1458 if "Data" not in batch_outputs.keys(): 1457 1459 batch_outputs["Data"] = [] 1458 from sas.sasgui.guiframe.data_processor import BatchCell1459 1460 cell = BatchCell() 1460 1461 cell.label = data.name … … 1565 1566 msg = ("Fit completed but the following error occurred: %s" 1566 1567 % sys.exc_value) 1567 # import traceback;msg = "\n".join((traceback.format_exc(), msg))1568 #msg = "\n".join((traceback.format_exc(), msg)) 1568 1569 evt = StatusEvent(status=msg, info="warning", type="stop") 1569 1570 wx.PostEvent(self.parent, evt) … … 1920 1921 return None 1921 1922 try: 1922 from model_thread import Calc2D1923 1923 ## If a thread is already started, stop it 1924 1924 if (self.calc_2D is not None) and self.calc_2D.isrunning(): … … 1967 1967 return 1968 1968 try: 1969 from model_thread import Calc1D1970 1969 ## If a thread is already started, stop it 1971 1970 if (self.calc_1D is not None) and self.calc_1D.isrunning(): -
src/sas/sasgui/perspectives/fitting/simfitpage.py
r959eb01 r00f7ff1 9 9 from wx.lib.scrolledpanel import ScrolledPanel 10 10 11 from sas.sascalc.fit.pagestate import SimFitPageState 11 12 from sas.sasgui.guiframe.events import StatusEvent, PanelOnFocusEvent 12 13 from sas.sasgui.guiframe.panel_base import PanelBase … … 46 47 47 48 return fittable_param 48 49 49 50 50 class SimultaneousFitPage(ScrolledPanel, PanelBase): … … 143 143 return self.state 144 144 145 def load_from_save_state(self, sim_state): 146 """ 147 Load in a simultaneous/constrained fit from a save state 148 :param fit: Fitpanel object 149 :return: None 150 """ 151 model_map = {} 152 # Process each model and associate old M# with new M# 153 i = 0 154 for model in self.model_list: 155 model_id = self._format_id(model[1].keys()[0]) 156 for saved_model in sim_state.model_list: 157 save_id = saved_model.pop('name') 158 saved_model['name'] = save_id 159 save_id = self._format_id(save_id) 160 if save_id == model_id: 161 model_map[saved_model.pop('fit_page_source')] = \ 162 model[3].name 163 check = bool(saved_model.pop('checked')) 164 self.model_list[i][0].SetValue(check) 165 break 166 i += 1 167 168 self.check_model_name(None) 169 170 if len(sim_state.constraints_list) > 0: 171 self.hide_constraint.SetValue(False) 172 self.show_constraint.SetValue(True) 173 self._display_constraint(None) 174 175 for index, item in enumerate(sim_state.constraints_list): 176 model_cbox = item.pop('model_cbox') 177 if model_cbox != "": 178 constraint_value = item.pop('constraint') 179 param = item.pop('param_cbox') 180 equality = item.pop('egal_txt') 181 for key, value in model_map.iteritems(): 182 model_cbox.replace(key, value) 183 constraint_value.replace(key, value) 184 185 self.constraints_list[index][0].SetValue(model_cbox) 186 self._on_select_model(None) 187 self.constraints_list[index][1].SetValue(param) 188 self.constraints_list[index][2].SetLabel(equality) 189 self.constraints_list[index][3].SetValue(constraint_value) 190 self._on_add_constraint(None) 191 self._manager.sim_page = self 192 193 def _format_id(self, original_id): 194 original_id = original_id.rstrip('1234567890.') 195 new_id_list = original_id.split() 196 new_id = ' '.join(new_id_list) 197 return new_id 198 199 200 145 201 def draw_page(self): 146 202 """ 147 203 Construct the Simultaneous/Constrained fit page. fills the first 148 region (sizer1) with the list of available fit page pairs of data 204 region (sizer1) with the list of available fit page pairs of data 149 205 and models. Then fills sizer2 with the checkbox for adding 150 206 constraints, and finally fills sizer3 with the fit button and … … 1020 1076 cbox.Append(name, value) 1021 1077 cbox.SetStringSelection(selected) 1022 1023 1024 class SimFitPageState:1025 """1026 State of the simultaneous fit page for saving purposes1027 """1028 1029 def __init__(self):1030 # Sim Fit Page Number1031 self.fit_page_no = None1032 # Select all data1033 self.select_all = False1034 # Data sets sent to fit page1035 self.model_list = []1036 # Data sets to be fit1037 self.model_to_fit = []1038 # Number of constraints1039 self.no_constraint = 01040 # Dictionary of constraints1041 self.constraint_dict = {}1042 # List of constraints1043 self.constraints_list = []1044 1045 def load_from_save_state(self, fit):1046 """1047 Load in a simultaneous/constrained fit from a save state1048 :param fit: Fitpanel object1049 :return: None1050 """1051 1052 model_map = {}1053 if fit.fit_panel.sim_page is None:1054 fit.fit_panel.add_sim_page()1055 sim_page = fit.fit_panel.sim_page1056 1057 # Process each model and associate old M# with new M#1058 i = 01059 for model in sim_page.model_list:1060 model_id = self._format_id(model[1].keys()[0])1061 for saved_model in self.model_list:1062 save_id = saved_model.pop('name')1063 saved_model['name'] = save_id1064 save_id = self._format_id(save_id)1065 if save_id == model_id:1066 model_map[saved_model.pop('fit_page_source')] = \1067 model[3].name1068 check = bool(saved_model.pop('checked'))1069 sim_page.model_list[i][0].SetValue(check)1070 break1071 i += 11072 sim_page.check_model_name(None)1073 1074 if len(self.constraints_list) > 0:1075 sim_page.hide_constraint.SetValue(False)1076 sim_page.show_constraint.SetValue(True)1077 sim_page._display_constraint(None)1078 1079 for index, item in enumerate(self.constraints_list):1080 model_cbox = item.pop('model_cbox')1081 if model_cbox != "":1082 constraint_value = item.pop('constraint')1083 param = item.pop('param_cbox')1084 equality = item.pop('egal_txt')1085 for key, value in model_map.iteritems():1086 model_cbox.replace(key, value)1087 constraint_value.replace(key, value)1088 1089 sim_page.constraints_list[index][0].SetValue(model_cbox)1090 sim_page._on_select_model(None)1091 sim_page.constraints_list[index][1].SetValue(param)1092 sim_page.constraints_list[index][2].SetLabel(equality)1093 sim_page.constraints_list[index][3].SetValue(constraint_value)1094 sim_page._on_add_constraint(None)1095 sim_page._manager.sim_page = sim_page1096 1097 def _format_id(self, original_id):1098 original_id = original_id.rstrip('1234567890.')1099 new_id_list = original_id.split()1100 new_id = ' '.join(new_id_list)1101 return new_id
Note: See TracChangeset
for help on using the changeset viewer.