Changeset 240b9966 in sasview for sansview/perspectives/fitting
- Timestamp:
- Jun 10, 2009 4:23:25 PM (16 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:
- 3fe701a
- Parents:
- fe496eeb
- Location:
- sansview/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
rfe496eeb r240b9966 78 78 ## Create memento to save the current state 79 79 self.state= PageState(parent= self.parent,model=self.model, data=self.data) 80 ## flag to determine if state has change 81 self.state_change= False 80 82 ## save customized array 81 83 self.values=[] … … 403 405 self.state.model = self.model.clone() 404 406 #if not hasattr(self.model, "_persistency_dict"): 405 self.model._persistency_dict = {}406 self.state.model._persistency_dict= copy.deepcopy(self.model._persistency_dict)407 #self.model._persistency_dict = {} 408 #self.state.model._persistency_dict= copy.deepcopy(self.model._persistency_dict) 407 409 408 410 new_state = self.state.clone() … … 515 517 self.state.weights = copy.deepcopy( self.weights) 516 518 ## save data 517 self.state. save_data(self.data)519 self.state.data= copy.deepcopy(self.data) 518 520 519 521 try: … … 570 572 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 571 573 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 572 573 ## post state to fit panel 574 #event = PageInfoEvent(page = self) 575 #wx.PostEvent(self.parent, event) 576 577 578 def reset_page_helper(self, state, forward=False): 574 575 576 def reset_page_helper(self, state): 579 577 """ 580 578 Use page_state and change the state of existing page … … 590 588 self.smearer= state.smearer 591 589 self.enable2D= state.enable2D 592 590 ## set the state of the radio box 591 self.shape_rbutton.SetValue(state.shape_rbutton ) 592 self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) 593 self.struct_rbutton.SetValue(state.struct_rbutton ) 594 self.plugin_rbutton.SetValue(state.plugin_rbutton) 593 595 ##draw sizer containing model parameters value for the current model 594 596 self._set_model_sizer_selection( self.model ) 595 597 self.set_model_param_sizer(self.model) 598 599 ## reset value of combox box 600 self.structurebox.SetSelection(state.structurecombobox ) 601 self.formfactorbox.SetSelection(state.formfactorcombobox) 596 602 ## enable the view 2d button if this is a modelpage type 597 603 if hasattr(self,"model_view"): … … 617 623 if hasattr(self, "disp_box"): 618 624 self.disp_box.SetSelection(state.disp_box) 619 n = self.disp_box.GetCurrentSelection() 620 dispersity= self.disp_box.GetClientData(n) 621 622 self._set_dipers_Param(event=None) 623 name= dispersity.__name__ 624 if name == "GaussianDispersion": 625 self.disp_cb_dict = {} 625 626 self.disp_cb_dict = {} 627 for k,v in self.state.disp_cb_dict.iteritems(): 626 628 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 627 628 self._disp_obj_dict={} 629 for k , v in state._disp_obj_dict.iteritems(): 630 self._disp_obj_dict[k]=v 631 632 if name=="ArrayDispersion": 633 self.model_disp.Show(True) 634 self.disp_box.Show(True) 635 self._set_sizer_arraydispersion() 629 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 636 630 637 for k,v in state.disp_cb_dict.iteritems(): 638 self.disp_cb_dict[k].SetValue(v) 639 640 if self.disp_cb_dict[k].GetValue(): 641 # Create the dispersion objects 642 from sans.models.dispersion_models import ArrayDispersion 643 disp_model = ArrayDispersion() 644 645 disp_model.set_weights(state.values, state.weights) 646 647 # Store the object to make it persist outside the scope of this method 648 #TODO: refactor model to clean this up? 649 self._disp_obj_dict[k] = disp_model 650 651 self.values=[] 652 self.weights = [] 653 self.values= state.values 654 self.weights = state.weights 655 656 # Set the new model as the dispersion object for the selected parameter 657 #if not hasattr(self.model, "_persistency_dict"): 658 self.model._persistency_dict = {} 659 self.model._persistency_dict[k] = [state.values, state.weights] 660 self.model.set_dispersion(k, disp_model) 661 631 self._disp_obj_dict={} 632 for k , v in self.state._disp_obj_dict.iteritems(): 633 self._disp_obj_dict[k]=v 634 635 self._set_dipers_Param(event=None) 662 636 ##plotting range restore 663 637 self._reset_plotting_range(state) … … 677 651 self._reset_parameters_state(self.fixed_param,state.fixed_param) 678 652 679 653 680 654 ## draw the model with previous parameters value 681 655 self._onparamEnter_helper() 682 656 683 657 ## reset context menu items 684 658 self._reset_context_menu() 659 685 660 ## set the value of the current state to the state given as parameter 686 661 self.state = state.clone() 687 ## post state to fit panel 688 #event = PageInfoEvent(page = self) 689 #wx.PostEvent(self.parent, event) 662 663 690 664 691 665 def _selectDlg(self): … … 724 698 self.npts.SetValue(str(state.npts)) 725 699 700 def _save_typeOfmodel(self): 701 """ 702 save radiobutton containing the type model that can be selected 703 """ 704 self.state.shape_rbutton = self.shape_rbutton.GetValue() 705 self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() 706 self.state.struct_rbutton = self.struct_rbutton.GetValue() 707 self.state.plugin_rbutton = self.plugin_rbutton.GetValue() 708 ## post state to fit panel 709 event = PageInfoEvent(page = self) 710 wx.PostEvent(self.parent, event) 711 self._undo.Enable(True) 726 712 727 713 def _save_plotting_range(self ): … … 780 766 ## if any value is modify draw model with new value 781 767 if is_modified: 782 768 self.state_change= True 783 769 self._draw_model() 784 770 self.save_current_state() … … 871 857 max_value = item[6].GetValue() 872 858 max_state = item[6].IsShown() 859 unit=None 860 if item[7]!=None: 861 unit = item[7].GetLabel() 873 862 874 863 statelist.append([checkbox_state, parameter_name, parameter_value, 875 864 static_text ,[error_state,error_value], 876 [min_state,min_value],[max_state , max_value], None])865 [min_state,min_value],[max_state , max_value],unit]) 877 866 878 867 … … 982 971 break 983 972 break 973 ## save state and post 974 984 975 985 976 … … 1132 1123 self._populate_box( self.formfactorbox, 1133 1124 self.model_list_box["Customized Models"]) 1134 1125 self._save_typeOfmodel() 1135 1126 self._on_select_model(event=None) 1136 1127 self.sizer4_4.Layout() … … 1192 1183 self.disp_list =self.model.getDispParamList() 1193 1184 self.state.disp_list = self.disp_list 1194 1185 self.state.structurecombobox =self.structurebox.GetCurrentSelection() 1186 self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() 1195 1187 self.sizer4_4.Layout() 1196 1188 self.sizer4.Layout() … … 1290 1282 self.disp_box.Hide() 1291 1283 self.sizer4_4.Clear(True) 1292 ## post state to fit panel1293 self.save_current_state()1284 ## save the state of the dispersity 1285 #self.save_current_state() 1294 1286 return 1295 1287 … … 1309 1301 self.disp_box.SetSelection(0) 1310 1302 self.sizer4_4.Clear(True) 1311 #self._reset_dispersity() 1312 1313 ## post state to fit panel 1303 1304 ## post state to fit panel 1314 1305 self.save_current_state() 1306 if event !=None: 1307 event = PageInfoEvent(page = self) 1308 wx.PostEvent(self.parent, event) 1309 1315 1310 self.sizer4_4.Layout() 1316 1311 self.sizer4.Layout() … … 1382 1377 1383 1378 self._draw_model() 1384 1379 ## save state into 1380 self.save_current_state() 1385 1381 self.sizer4_4.Layout() 1386 1382 self.sizer4.Layout() … … 1407 1403 1408 1404 self.state.disp_box= n 1409 ## post state to fit panel1410 #event = PageInfoEvent(page = self)1411 #wx.PostEvent(self.parent, event)1412 1405 1413 1406 self.sizer4_4.Layout() … … 1457 1450 self.sizer4.Layout() 1458 1451 self.SetScrollbars(20,20,200,100) 1459 1452 ## save state into 1453 self._copy_parameters_state(self.orientation_params_disp, 1454 self.state.orientation_params_disp) 1455 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 1456 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1457 1460 1458 1461 1459 def _set_range_sizer(self, title, object1=None,object=None): -
sansview/perspectives/fitting/fitpage.py
r330573d r240b9966 453 453 self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 454 454 self.state.model = self.model.clone() 455 ## save state into 456 self._copy_parameters_state(self.orientation_params_disp, 457 self.state.orientation_params_disp) 458 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 459 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 455 460 456 461 wx.PostEvent(self.parent, StatusEvent(status=\ … … 542 547 wx.PostEvent(self.event_owner, evt) 543 548 self.btFit.SetFocus() 549 self.state.enable_disp = self.enable_disp.GetValue() 550 self.state.disable_disp = self.disable_disp.GetValue() 544 551 ## post state to fit panel 545 552 event = PageInfoEvent(page = self) … … 573 580 ##Calculate chi2 574 581 self.compute_chisqr(smearer= temp_smearer) 582 ## new state posted 583 if self.state_change: 584 event = PageInfoEvent(page = self) 585 wx.PostEvent(self.parent, event) 586 self.state_change= False 575 587 576 588 … … 580 592 """ 581 593 tcrtl= event.GetEventObject() 582 ## save current state 583 self.save_current_state() 584 585 event = PageInfoEvent(page = self) 586 wx.PostEvent(self.parent, event) 587 594 588 595 if check_float(tcrtl): 589 596 self._onparamEnter_helper() … … 592 599 temp_smearer= self.smearer 593 600 self.compute_chisqr(smearer= temp_smearer) 601 ## new state posted 602 if self.state_change: 603 event = PageInfoEvent(page = self) 604 wx.PostEvent(self.parent, event) 605 self.state_change= False 594 606 else: 595 607 msg= "Cannot Plot :Must enter a number!!! " … … 610 622 self.Layout() 611 623 612 def reset_page(self, state ):624 def reset_page(self, state,first=False): 613 625 """ 614 626 reset the state 615 627 """ 628 if first: 629 self._undo.Enable(False) 630 616 631 self.reset_page_helper(state) 617 632 evt = ModelEventbox(model=self.model) … … 1108 1123 ##[cb state, name, value, "+/-", error of fit, min, max , units] 1109 1124 self.parameters.append([cb,item, ctl1, 1110 text2,ctl2, ctl3, ctl4, None])1125 text2,ctl2, ctl3, ctl4,units]) 1111 1126 1112 1127 iy+=1 … … 1206 1221 ##[cb state, name, value, "+/-", error of fit, min, max , units] 1207 1222 self.parameters.append([cb,item, ctl1, 1208 text2,ctl2, ctl3, ctl4, None])1223 text2,ctl2, ctl3, ctl4,units]) 1209 1224 self.orientation_params.append([cb,item, ctl1, 1210 text2,ctl2, ctl3, ctl4, None])1225 text2,ctl2, ctl3, ctl4,units]) 1211 1226 1212 1227 iy+=1 … … 1220 1235 else: 1221 1236 self.text2_4.Hide() 1222 1237 1238 self._copy_parameters_state(self.orientation_params, 1239 self.state.orientation_params) 1240 self._copy_parameters_state(self.orientation_params_disp, 1241 self.state.orientation_params_disp) 1242 self._copy_parameters_state(self.parameters, self.state.parameters) 1243 self._copy_parameters_state(self.fittable_param, self.state.fittable_param) 1244 self._copy_parameters_state(self.fixed_param, self.state.fixed_param) 1245 1223 1246 boxsizer1.Add(sizer) 1224 1225 1247 self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) 1226 1248 self.sizer3.Layout() -
sansview/perspectives/fitting/fitpanel.py
rfe496eeb r240b9966 311 311 else: 312 312 self.fit_page_name[name]=ListOfState() 313 313 314 #self.fit_page_name[name].appendItem(panel.createMemento()) 314 315 #GetPage(self, page_idx) … … 355 356 else: 356 357 self.model_page.select_model(model) 357 self.fit_page_name[page_title].insert(0,self.model_page.createMemento()) 358 self.fit_page_name[name]=ListOfState() 359 #self.fit_page_name[page_title].insert(0,self.model_page.createMemento()) 358 360 359 361 … … 397 399 self.fit_page_name[page.window_name].appendItem(page.createMemento()) 398 400 401 print " current added state: ",len(self.fit_page_name[page.window_name]) 402 399 403 def _onUndo(self, event ): 400 404 """ … … 456 460 panel.reset_page(memento) 457 461 else: 458 self.fit_page_name[page_title]=[] 462 self.fit_page_name[page_title]=ListOfState() 463 #self.fit_page_name[page_title]=[] 459 464 self.fit_page_name[page_title].insert(0,panel.createMemento()) 460 465 -
sansview/perspectives/fitting/pagestate.py
r0aeabc6 r240b9966 64 64 ## save the state of the context menu 65 65 self.saved_states={} 66 ## save current valueof combobox66 ## save selection of combobox 67 67 self.formfactorcombobox = "" 68 68 self.structurecombobox = "" 69 ## radio box to select type of model 70 self.shape_rbutton = False 71 self.shape_indep_rbutton = False 72 self.struct_rbutton = False 73 self.plugin_rbutton = False 69 74 ## the indice of the current selection 70 75 self.disp_box = 0 … … 74 79 self.qmax= 0.1 75 80 self.npts = None 81 self.name="" 76 82 ## enable smearering state 77 83 self.enable_smearer = False … … 86 92 ## store value of chisqr 87 93 self.tcChi= None 88 89 90 def save_data(self, data): 91 """ 92 Save data 93 """ 94 self.data = copy.deepcopy(data) 95 96 94 97 95 def clone(self): 98 96 model=None … … 103 101 obj.data = copy.deepcopy(self.data) 104 102 obj.model_list_box = copy.deepcopy(self.model_list_box) 105 103 104 obj.formfactorcombobox= self.formfactorcombobox 105 obj.structurecombobox =self.structurecombobox 106 107 obj.shape_rbutton = self.shape_rbutton 108 obj.shape_indep_rbutton = self.shape_indep_rbutton 109 obj.struct_rbutton = self.struct_rbutton 110 obj.plugin_rbutton = self.plugin_rbutton 111 106 112 obj.manager = self.manager 107 113 obj.event_owner = self.event_owner … … 143 149 return obj 144 150 145 146 class PageMemento(object): 147 """ 148 Store the state of a fitpage or model page of fitpanel 149 """ 150 def __init__(self, state): 151 """ Initialization""" 152 self.state = state 153 154 def setState(self,state): 155 """ 156 set current state 157 @param state: new state 158 """ 159 self.state = state 160 161 def getState(self): 162 """ 163 @return state 164 """ 165 return self.state 151 152 def old__repr__(self): 153 """ output string for printing""" 154 rep = "\n\nState name: %s\n"%self.name 155 rep +="data : %s\n"% str(self.data) 156 rep += "Plotting Range: min: %s, max: %s, steps: %s\n"%(str(self.qmin), 157 str(self.qmax),str(self.npts)) 158 rep +="model : %s\n\n"% str(self.model) 159 rep +="number parameters(self.parameters): %s\n"%len(self.parameters) 160 for item in self.parameters: 161 rep += "parameter name: %s \n"%str(item[1]) 162 rep += "value: %s\n"%str(item[2]) 163 rep += "selected: %s\n"%str(item[0]) 164 rep += "error displayed : %s \n"%str(item[4][0]) 165 rep += "error value:%s \n"%str(item[4][1]) 166 rep += "minimum displayed : %s \n"%str(item[5][0]) 167 rep += "minimum value : %s \n"%str(item[5][1]) 168 rep += "maximum displayed : %s \n"%str(item[6][0]) 169 rep += "maximum value : %s \n"%str(item[6][1]) 170 rep += "parameter unit: %s\n\n"%str(item[7]) 171 rep +="number orientation parameters" 172 rep +="(self.orientation_params): %s\n"%len(self.orientation_params) 173 for item in self.orientation_params: 174 rep += "parameter name: %s \n"%str(item[1]) 175 rep += "value: %s\n"%str(item[2]) 176 rep += "selected: %s\n"%str(item[0]) 177 rep += "error displayed : %s \n"%str(item[4][0]) 178 rep += "error value:%s \n"%str(item[4][1]) 179 rep += "minimum displayed : %s \n"%str(item[5][0]) 180 rep += "minimum value : %s \n"%str(item[5][1]) 181 rep += "maximum displayed : %s \n"%str(item[6][0]) 182 rep += "maximum value : %s \n"%str(item[6][1]) 183 rep += "parameter unit: %s\n\n"%str(item[7]) 184 rep +="number dispersity parameters" 185 rep +="(self.orientation_params_disp): %s\n"%len(self.orientation_params_disp) 186 for item in self.orientation_params_disp: 187 rep += "parameter name: %s \n"%str(item[1]) 188 rep += "value: %s\n"%str(item[2]) 189 rep += "selected: %s\n"%str(item[0]) 190 rep += "error displayed : %s \n"%str(item[4][0]) 191 rep += "error value:%s \n"%str(item[4][1]) 192 rep += "minimum displayed : %s \n"%str(item[5][0]) 193 rep += "minimum value : %s \n"%str(item[5][1]) 194 rep += "maximum displayed : %s \n"%str(item[6][0]) 195 rep += "maximum value : %s \n"%str(item[6][1]) 196 rep += "parameter unit: %s\n\n"%str(item[7]) 197 198 return rep 199 200 166 201 167 202 168 169
Note: See TracChangeset
for help on using the changeset viewer.