- Timestamp:
- Mar 11, 2011 4:39:00 PM (14 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:
- ee2b492
- Parents:
- 14cd91b1
- Location:
- sansview/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
rb2d9826 re88ebfd 946 946 return True 947 947 948 948 def set_model_state(self, state): 949 """ 950 reset page given a model state 951 """ 952 self.disp_cb_dict = state.disp_cb_dict 953 self.disp_list = state.disp_list 954 955 ## set the state of the radio box 956 self.shape_rbutton.SetValue(state.shape_rbutton ) 957 self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) 958 self.struct_rbutton.SetValue(state.struct_rbutton) 959 self.plugin_rbutton.SetValue(state.plugin_rbutton) 960 961 ## fill model combobox 962 self._show_combox_helper() 963 #select the current model 964 self.formfactorbox.Select(int(state.formfactorcombobox)) 965 self.structurebox.SetSelection(state.structurecombobox ) 966 if state.multi_factor != None: 967 self.multifactorbox.SetSelection(state.multi_factor) 968 969 ## reset state of checkbox,textcrtl and regular parameters value 970 self._reset_parameters_state(self.orientation_params_disp, 971 state.orientation_params_disp) 972 self._reset_parameters_state(self.orientation_params, 973 state.orientation_params) 974 self._reset_parameters_state(self.str_parameters, 975 state.str_parameters) 976 self._reset_parameters_state(self.parameters,state.parameters) 977 ## display dispersion info layer 978 self.enable_disp.SetValue(state.enable_disp) 979 self.disable_disp.SetValue(state.disable_disp) 980 981 if hasattr(self, "disp_box"): 982 983 self.disp_box.SetSelection(state.disp_box) 984 n= self.disp_box.GetCurrentSelection() 985 dispersity= self.disp_box.GetClientData(n) 986 name = dispersity.__name__ 987 988 self._set_dipers_Param(event=None) 989 990 if name == "ArrayDispersion": 991 992 for item in self.disp_cb_dict.keys(): 993 994 if hasattr(self.disp_cb_dict[item], "SetValue") : 995 self.disp_cb_dict[item].SetValue(\ 996 state.disp_cb_dict[item]) 997 # Create the dispersion objects 998 from sans.models.dispersion_models import ArrayDispersion 999 disp_model = ArrayDispersion() 1000 if hasattr(state,"values")and\ 1001 self.disp_cb_dict[item].GetValue() == True: 1002 if len(state.values)>0: 1003 self.values=state.values 1004 self.weights=state.weights 1005 disp_model.set_weights(self.values, 1006 state.weights) 1007 else: 1008 self._reset_dispersity() 1009 1010 self._disp_obj_dict[item] = disp_model 1011 # Set the new model as the dispersion object 1012 #for the selected parameter 1013 self.model.set_dispersion(item, disp_model) 1014 1015 self.model._persistency_dict[item] = \ 1016 [state.values, state.weights] 1017 1018 else: 1019 keys = self.model.getParamList() 1020 for item in keys: 1021 if item in self.disp_list and \ 1022 not self.model.details.has_key(item): 1023 self.model.details[item] = ["", None, None] 1024 for k,v in self.state.disp_cb_dict.iteritems(): 1025 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1026 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 1027 ## smearing info restore 1028 if hasattr(self, "enable_smearer"): 1029 ## set smearing value whether or not the data 1030 #contain the smearing info 1031 self.enable_smearer.SetValue(state.enable_smearer) 1032 self.disable_smearer.SetValue(state.disable_smearer) 1033 self.onSmear(event=None) 1034 self.pinhole_smearer.SetValue(state.pinhole_smearer) 1035 self.slit_smearer.SetValue(state.slit_smearer) 1036 ## we have two more options for smearing 1037 if self.pinhole_smearer.GetValue(): self.onPinholeSmear(event=None) 1038 elif self.slit_smearer.GetValue(): self.onSlitSmear(event=None) 1039 1040 ## reset state of checkbox,textcrtl and dispersity parameters value 1041 self._reset_parameters_state(self.fittable_param,state.fittable_param) 1042 self._reset_parameters_state(self.fixed_param,state.fixed_param) 1043 1044 ## draw the model with previous parameters value 1045 self._onparamEnter_helper() 1046 self.select_param(event=None) 1047 #Save state_fit 1048 self.save_current_state_fit() 1049 self._lay_out() 1050 self.Refresh() 1051 949 1052 def reset_page_helper(self, state): 950 1053 """ -
sansview/perspectives/fitting/fitpanel.py
rb2d9826 re88ebfd 101 101 return selected_page.get_data() 102 102 103 def set_model_state(state): 104 """ 105 receive a state to reset the model in the current page 106 """ 107 pos = self.GetSelection() 108 if pos != -1: 109 selected_page = self.GetPage(pos) 110 selected_page.set_model_state(state) 111 103 112 def get_state(self): 104 113 """ -
sansview/perspectives/fitting/fitproblem.py
r6bbeacd4 re88ebfd 1 import copy 1 2 2 3 class FitProblem: … … 32 33 copy fitproblem 33 34 """ 34 import copy35 35 36 obj = FitProblem() 36 37 model= None … … 110 111 111 112 """ 112 self.theory_data = data 113 114 113 self.theory_data = copy.deepcopy(data) 114 115 115 def get_theory_data(self): 116 116 """ -
sansview/perspectives/fitting/fitting.py
rb2d9826 re88ebfd 17 17 import logging 18 18 import numpy 19 #import math20 19 import string 21 20 import time 22 #import thread23 21 from copy import deepcopy 24 25 22 import models 26 23 import fitpage … … 36 33 from sans.guiframe.gui_style import GUIFRAME_ID 37 34 from sans.guiframe.plugin_base import PluginBase 38 39 35 40 36 from .console import ConsoleUpdate … … 256 252 return True 257 253 258 def set_data(self, data_list=None , theory_list=None):254 def set_data(self, data_list=None): 259 255 """ 260 256 receive a list of data to fit … … 270 266 else: 271 267 selected_data_list = data_list 272 for data in selected_data_list: 273 self.add_fit_page(data=data) 274 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 275 title=str(data.title))) 268 try: 269 for data in selected_data_list: 270 self.add_fit_page(data=data) 271 wx.PostEvent(self.parent, NewPlotEvent(plot=data, 272 title=str(data.title))) 273 except: 274 msg = "Fitting Set_data: " + str(sys.exc_value) 275 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 276 277 def set_theory(self, theory_list=None): 278 """ 279 """ 280 #set the model state for a given theory_state: 281 for item in theory_list: 282 try: 283 _, theory_state = item 284 self.fit_panel.set_model_state(theory_state) 285 except: 286 msg = "Fitting: cannot deal with the theory received" 287 logging.error("set_theory " + msg + "\n" + str(sys.exc_value)) 288 wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) 276 289 277 290 def set_state(self, state=None, datainfo=None, format=None): … … 593 606 if theory: 594 607 id = data.id 595 group_id = data.group_id [len(data.group_id)-1]608 group_id = data.group_id 596 609 wx.PostEvent(self.parent, NewPlotEvent(id=id, 597 610 group_id=group_id, … … 643 656 #append Data1D to the panel containing its theory 644 657 #if theory already plotted 645 646 658 if page.id in self.page_finder: 647 659 theory_data = self.page_finder[page.id].get_theory_data() 648 649 660 if issubclass(data.__class__, Data2D): 650 data.group_id .append(wx.NewId())661 data.group_id = wx.NewId() 651 662 if theory_data is not None: 652 663 group_id = str(page.id) + " Model1D" 653 if group_id in theory_data.group_id:654 theory_data.group_id.remove(group_id)655 664 wx.PostEvent(self.parent, 656 665 NewPlotEvent(group_id=group_id, … … 660 669 if theory_data is not None: 661 670 group_id = str(page.id) + " Model2D" 662 if group_id in theory_data.group_id: 663 theory_data.group_id.remove(group_id) 664 data_group_id = theory_data.group_id[len(theory_data.group_id)-1] 665 if data_group_id not in data.group_id: 666 data.group_id.append(data_group_id) 671 data.group_id = theory_data.group_id 667 672 wx.PostEvent(self.parent, 668 673 NewPlotEvent(group_id=group_id, 669 674 action="delete")) 670 self.parent.update_data(prev_data=theory_data, new_data=data) 675 self.parent.update_data(prev_data=theory_data, new_data=data) 676 671 677 self.store_data(id=page.id, data=data, caption=page.window_name) 672 678 if self.sim_page is not None: … … 725 731 if name !="Model": 726 732 data= fitproblem.get_fit_data() 727 page = self.fit_panel.add_fit_page(data= data,reset=True)733 page = self.fit_panel.add_fit_page(data=data, reset=True) 728 734 if fitproblem != None: 729 735 self.page_finder[id] = fitproblem … … 1103 1109 theory.ymin = ymin 1104 1110 theory.ymax = ymax 1105 group_id = str(id) + " Model2D" 1106 if group_id not in theory.group_id: 1107 theory.group_id.append(group_id) 1111 theory.group_id = str(id) + " Model2D" 1108 1112 theory.id = str(id) + " Model2D" 1109 1113 1110 1111 1114 def _complete1D(self, x,y, id, elapsed,index,model, 1112 1115 toggle_mode_on=False,state=None, data=None): … … 1126 1129 theory_data = self.page_finder[id].get_theory_data() 1127 1130 if theory_data is not None: 1128 group_id = theory_data.group_id[len(theory_data.group_id)-1] 1129 if group_id not in data.group_id: 1130 data.group_id.append(group_id) 1131 data.group_id = theory_data.group_id 1131 1132 #data is plotted before the theory, then take its group_id 1132 1133 #assign to the new theory 1133 group_id = data.group_id[len(data.group_id)-1] 1134 if group_id not in new_plot.group_id: 1135 new_plot.group_id.append(group_id) 1134 new_plot.group_id = data.group_id 1136 1135 1137 1136 else: … … 1140 1139 new_plot.title = "Analytical model 1D " 1141 1140 #find a group id to plot theory without data 1142 group_id = str(id) + " Model1D" 1143 if group_id not in new_plot.group_id: 1144 new_plot.group_id.append(group_id) 1141 new_plot.group_id = str(id) + " Model1D" 1145 1142 new_plot.is_data = False 1146 1143 new_plot.id = str(id) + " Model1D" … … 1161 1158 NewPlotEvent(group_id=str(id) + " Model2D", 1162 1159 action="Hide")) 1163 1160 1164 1161 self.page_finder[id].set_theory_data(new_plot) 1162 theory_data = self.page_finder[id].get_theory_data() 1165 1163 if data is None: 1166 theory_data = self.page_finder[id].get_theory_data() 1164 name = "Data generates by Fitting " 1165 theory_data.name = name 1167 1166 self.parent.add_data_helper({theory_data.id:theory_data}) 1168 1167 data_id = theory_data.id … … 1170 1169 data_id = data.id 1171 1170 1172 self.parent.append_theory(data_id=data_id, 1173 theory=new_plot, state=state) 1171 self.parent.update_theory(data_id=data_id, 1172 theory=theory_data, 1173 state=state) 1174 1174 current_pg = self.fit_panel.get_page_by_id(id) 1175 1175 title = new_plot.title … … 1218 1218 else: 1219 1219 new_plot.id = str(id) + " Model2D" 1220 group_id = str(id) + " Model2D" 1221 if group_id not in new_plot.group_id: 1222 new_plot.group_id.append(group_id) 1223 1220 new_plot.group_id = str(id) + " Model2D" 1224 1221 new_plot.x_bins = data.x_bins 1225 1222 new_plot.y_bins = data.y_bins … … 1247 1244 NewPlotEvent(group_id=str(id) + " Model1D", 1248 1245 action="Hide")) 1249 self.page_finder[id].set_theory_data(theory_data) 1250 1246 1247 self.page_finder[id].set_theory_data(new_plot) 1248 theory_data = self.page_finder[id].get_theory_data() 1251 1249 if data is None: 1252 theory_data = self.page_finder[id].get_theory_data() 1250 name = "Data generates by Fitting " 1251 theory_data.name = name 1253 1252 self.parent.add_data_helper({theory_data.id:theory_data}) 1254 1253 data_id = theory_data.id 1255 1254 else: 1256 1255 data_id = data.id 1257 1258 self.parent.append_theory(data_id=data_id,1259 theory=new_plot, state=state)1256 self.parent.update_theory(data_id=data_id, 1257 theory=theory_data, 1258 state=state) 1260 1259 current_pg = self.fit_panel.get_page_by_id(id) 1261 1260 title = new_plot.title
Note: See TracChangeset
for help on using the changeset viewer.