Changeset 71f0373 in sasview
- Timestamp:
- May 15, 2009 6:30:16 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:
- 138c139
- Parents:
- 111acd2
- Location:
- sansview/perspectives/fitting
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/basepage.py
rdad49a0 r71f0373 75 75 76 76 self.state= PageState(parent= self.parent,model=self.model, data=self.data) 77 77 ## save customized array 78 self.values=[] 79 self.weights=[] 78 80 ## retrieve saved state 79 81 self.number_saved_state= 0 … … 195 197 self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), style=wx.RB_GROUP) 196 198 self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) 197 ## saving the state of enable dispersity button 198 self.state.enable_disp= self.enable_disp.GetValue() 199 199 200 200 201 self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, id=self.disable_disp.GetId()) … … 251 252 self.SetScrollbars(20,20,200,100) 252 253 self.Refresh() 253 254 ## saving the state of enable dispersity button 255 self.state.enable_disp= self.enable_disp.GetValue() 256 self.state.disable_disp= self.disable_disp.GetValue() 257 254 258 255 259 def select_disp_angle(self, event): … … 258 262 @param event: check box event 259 263 """ 264 self.values=[] 265 self.weights=[] 260 266 # Go through the list of dispersion check boxes to identify which one has changed 261 267 for p in self.disp_cb_dict: … … 263 269 if event.GetEventObject() == self.disp_cb_dict[p]: 264 270 265 self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue()271 266 272 if self.disp_cb_dict[p].GetValue() == True: 267 273 # The user wants this parameter to be averaged. … … 278 284 pass 279 285 try: 280 values,weights = self.read_file(path)286 self.values,self.weights = self.read_file(path) 281 287 except: 282 288 msg="Could not read input file" … … 286 292 # If any of the two arrays is empty, notify the user that we won't 287 293 # proceed 288 if values is None or weights is None: 294 if self.values is None or self.weights is None or \ 295 self.values ==[] or self.weights ==[]: 289 296 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 290 297 "The loaded %s distrubtion is corrupted or empty" % p)) … … 298 305 from sans.models.dispersion_models import ArrayDispersion 299 306 disp_model = ArrayDispersion() 300 disp_model.set_weights(values, weights) 307 disp_model.set_weights(self.values, self.weights) 308 301 309 # Store the object to make it persist outside the scope of this method 302 310 #TODO: refactor model to clean this up? … … 305 313 self.state.values=[] 306 314 self.state.weights=[] 307 self.state.values = values308 self.state.weights = weights315 self.state.values = self.values 316 self.state.weights = self.weights 309 317 # Set the new model as the dispersion object for the selected parameter 310 318 self.model.set_dispersion(p, disp_model) … … 312 320 # it's not lost when we use the model within another thread. 313 321 #TODO: total hack - fix this 322 self.state.model= self.model.clone() 314 323 if not hasattr(self.model, "_persistency_dict"): 315 324 self.model._persistency_dict = {} 316 self.model._persistency_dict[p] = [values, weights] 325 self.model._persistency_dict[p] = [self.values, self.weights] 326 self.state.model._persistency_dict[p] = [self.values, self.weights] 317 327 else: 318 328 # The parameter was un-selected. Go back to Gaussian model (with 0 pts) … … 320 330 321 331 ## Redraw the model 332 print "select angle => draw" 322 333 self._draw_model() 323 334 ## post state to fit panel 335 336 self.state.disp_cb_dict[p]= self.disp_cb_dict[p].GetValue() 324 337 event = PageInfoEvent(page = self) 325 338 wx.PostEvent(self.parent, event) … … 346 359 save history of the data and model 347 360 """ 348 # Skipping the save state functionality for release 0.9.0 349 return 350 361 351 362 if self.model==None: 352 363 return … … 357 368 358 369 self.state.model = self.model.clone() 370 if not hasattr(self.model, "_persistency_dict"): 371 self.model._persistency_dict = {} 372 self.state.model._persistency_dict= copy.deepcopy(self.model._persistency_dict) 373 359 374 new_state = self.state.clone() 360 375 new_state.enable2D = copy.deepcopy(self.enable2D) … … 377 392 self.slicerpop.Append(id,name,str(msg)) 378 393 wx.EVT_MENU(self, id, self.onResetModel) 394 379 395 380 396 def onSetFocus(self, evt): … … 447 463 return the current state of the page 448 464 """ 465 449 466 return self.state.clone() 450 467 … … 455 472 """ 456 473 if self.model!= None: 474 self.disp_list= self.model.getDispParamList() 475 self.state.disp_list= copy.deepcopy(self.disp_list) 457 476 self.state.model = self.model.clone() 458 477 self.state.save_data(self.data) 459 478 self.state.disp_list = self.disp_list 460 479 self.state.enable2D = copy.deepcopy(self.enable2D) 480 self.state.values= copy.deepcopy(self.values) 481 self.state.weights = copy.deepcopy( self.weights) 461 482 try: 462 483 n = self.disp_box.GetCurrentSelection() … … 493 514 for k , v in self._disp_obj_dict.iteritems(): 494 515 self.state._disp_obj_dict[k]= v 495 516 self.state.values = copy.deepcopy(self.values) 517 self.state.weights = copy.deepcopy(self.weights) 496 518 self._save_plotting_range() 497 519 … … 519 541 """ 520 542 Use page_state and change the state of existing page 521 """ 522 self.state = state.clone() 543 @precondition: the page is already drawn or created 544 @postcondition: the state of the underlying data change as well as the 545 state of the graphic interface 546 """ 547 ## set the value of the current state to the state given as parameter 548 self.state = state.clone() 549 523 550 self.model= self.state.model 524 551 self.data = self.state.data 525 552 self.smearer= self.state.smearer 526 self. state.enable_smearer=state.enable_smearer527 528 ## model parameter values restore553 self.enable2D= state.enable2D 554 555 ##draw sizer containing model parameters value for the current model 529 556 self._set_model_sizer_selection( self.model ) 530 557 self.set_model_param_sizer(self.model) 531 532 self.enable2D= state.enable2D 533 self.state.enable2D= state.enable2D 534 558 ## enable the view 2d button if this is a modelpage type 535 559 if hasattr(self,"model_view"): 536 560 if not self.enable2D: … … 538 562 else: 539 563 self.model_view.Disable() 540 564 ## set the select all check box to the a given state 541 565 if hasattr(self, "cb1"): 542 self.cb1.SetValue(self.state.cb1) 566 self.cb1.SetValue(state.cb1) 567 ## reset state of checkbox,textcrtl and regular parameters value 568 self._reset_parameters_state(self.orientation_params_disp, 569 state.orientation_params_disp) 570 self._reset_parameters_state(self.orientation_params, 571 state.orientation_params) 572 self._reset_parameters_state(self.parameters,state.parameters) 573 543 574 ## display dispersion info layer 544 575 self.enable_disp.SetValue(self.state.enable_disp) 545 576 self.disable_disp.SetValue(self.state.disable_disp) 577 546 578 if hasattr(self, "disp_box"): 547 579 self.disp_box.SetSelection(self.state.disp_box) 548 549 self._set_dipers_Param(event=None)550 551 580 n = self.disp_box.GetCurrentSelection() 552 581 dispersity= self.disp_box.GetClientData(n) 582 583 self._set_dipers_Param(event=None) 553 584 name= dispersity.__name__ 554 585 if name == "GaussianDispersion": … … 556 587 self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 557 588 self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) 558 589 559 590 self._disp_obj_dict={} 560 591 for k , v in self.state._disp_obj_dict.iteritems(): 561 592 self._disp_obj_dict[k]=v 562 593 563 594 if name=="ArrayDispersion": 564 595 self.model_disp.Show(True) 596 self.disp_box.Show(True) 597 self._set_sizer_arraydispersion() 598 565 599 for k,v in state.disp_cb_dict.iteritems(): 566 600 self.disp_cb_dict[k].SetValue(v) 601 self.state.disp_cb_dict[k]=v 602 if self.disp_cb_dict[k].GetValue(): 603 # Create the dispersion objects 604 from sans.models.dispersion_models import ArrayDispersion 605 disp_model = ArrayDispersion() 606 607 disp_model.set_weights(state.values, state.weights) 608 609 # Store the object to make it persist outside the scope of this method 610 #TODO: refactor model to clean this up? 611 self._disp_obj_dict[k] = disp_model 612 self.state._disp_obj_dict [k]= disp_model 613 self.state.values=[] 614 self.state.weights=[] 615 self.state.values = self.values 616 self.state.weights = self.weights 617 self.values=[] 618 self.weights = [] 619 self.values= state.values 620 self.weights = state.weights 567 621 568 self._disp_obj_dict={} 569 for k , v in state._disp_obj_dict.iteritems(): 570 # Create the dispersion objects 571 from sans.models.dispersion_models import ArrayDispersion 572 disp_model = ArrayDispersion() 573 self.state.values = copy.deepcopy(state.values) 574 self.state.weights = copy.deepcopy(state.weights) 575 576 disp_model.set_weights(self.state.values, self.state.weights) 577 578 self._disp_obj_dict[k] = disp_model 579 self.state._disp_obj_dict[k]= disp_model 580 self.state.values=[] 581 self.state.weights=[] 582 583 if not hasattr(self.model, "_persistency_dict"): 584 self.model._persistency_dict = {} 585 self.model._persistency_dict[k] = [self.state.values, self.state.weights] 586 # Set the new model as the dispersion object for the selected parameter 587 self.model.set_dispersion(k, disp_model) 588 622 # Set the new model as the dispersion object for the selected parameter 623 if not hasattr(self.model, "_persistency_dict"): 624 self.model._persistency_dict = {} 625 self.model._persistency_dict[k] = [state.values, state.weights] 626 self.model.set_dispersion(k, disp_model) 627 589 628 ##plotting range restore 590 629 self._reset_plotting_range() … … 592 631 if hasattr(self,"enable_smearer"): 593 632 ## set smearing value whether or not the data contain the smearing info 594 self.enable_smearer.SetValue(s tate.enable_smearer)595 self.disable_smearer.SetValue(s tate.disable_smearer)633 self.enable_smearer.SetValue(self.state.enable_smearer) 634 self.disable_smearer.SetValue(self.state.disable_smearer) 596 635 self.compute_chisqr(smearer= self.smearer) 597 636 598 ## reset state of checkbox,textcrtl and parameters value 599 self._reset_parameters_state(self.orientation_params_disp, 600 state.orientation_params_disp) 601 self._reset_parameters_state(self.orientation_params, 602 state.orientation_params) 603 self._reset_parameters_state(self.parameters,state.parameters) 637 ## reset state of checkbox,textcrtl and dispersity parameters value 604 638 self._reset_parameters_state(self.fittable_param,state.fittable_param) 605 639 self._reset_parameters_state(self.fixed_param,state.fixed_param) 640 641 606 642 ## draw the model with previous parameters value 607 643 self._onparamEnter_helper() 644 608 645 ## reset context menu items 609 646 self._reset_context_menu() 610 611 647 648 612 649 613 650 def _selectDlg(self): … … 636 673 wx.EVT_MENU(self, id, self.onResetModel) 637 674 675 638 676 def _reset_plotting_range(self): 639 677 """ … … 668 706 """ 669 707 if self.model !=None: 708 670 709 ## save current state 671 710 self.save_current_state() 711 672 712 # Flag to register when a parameter has changed. 673 713 is_modified = False … … 703 743 ## if any value is modify draw model with new value 704 744 if is_modified: 745 print "is_modified--->",is_modified 705 746 self._draw_model() 706 747 self.save_current_state() … … 919 960 if self.enable_smearer.GetValue(): 920 961 temp_smear= self.smearer 962 print "self.model.dispersion",self.model.dispersion 921 963 self.manager.draw_model(self.model, data=self.data, 922 964 smearer= temp_smear, … … 924 966 qstep= float(self.num_points), 925 967 enable2D=self.enable2D) 968 926 969 927 970 def _set_model_sizer(self, sizer, title="", object=None): … … 970 1013 wx.EVT_COMBOBOX(self.structurebox,-1, self._on_select_model) 971 1014 972 973 1015 974 1016 ## fill combox box 975 1017 if len(self.model_list_box)>0: … … 1074 1116 name = model.name 1075 1117 combobox.Append(name,models) 1076 #try: 1077 1078 #combobox.SetSelection(0) 1079 1080 #except: 1081 #pass 1082 1118 1083 1119 return 0 1084 1120 … … 1116 1152 ## post state to fit panel 1117 1153 self.state.model =self.model 1154 self.disp_list =self.model.getDispParamList() 1155 self.state.disp_list = self.disp_list 1156 1118 1157 ## post state to fit panel 1119 1158 event = PageInfoEvent(page = self) … … 1185 1224 item[4].Hide() 1186 1225 1187 1188 1226 value= float(item[2].GetValue()) 1189 1227 … … 1211 1249 self.disp_box.Hide() 1212 1250 self.sizer4_4.Clear(True) 1213 self._reset_dispersity()1214 1251 ## post state to fit panel 1215 1252 self.save_current_state() … … 1220 1257 self.disp_box.Show(True) 1221 1258 ## layout for model containing no dispersity parameters 1259 self.disp_list= self.model.getDispParamList() 1222 1260 if len(self.disp_list)==0: 1223 1261 self._layout_sizer_noDipers() … … 1228 1266 self.model_disp.Hide() 1229 1267 self.disp_box.Hide() 1268 self.disp_box.SetSelection(0) 1230 1269 self.sizer4_4.Clear(True) 1231 self._reset_dispersity() 1232 1233 1270 #self._reset_dispersity() 1271 1234 1272 ## post state to fit panel 1235 1273 self.save_current_state() 1236 1274 self.sizer4_4.Layout() 1275 self.sizer4.Layout() 1276 self.Layout() 1277 self.Refresh() 1278 self.SetScrollbars(20,20,200,100) 1237 1279 1238 1280 … … 1273 1315 self.fixed_param=[] 1274 1316 self.orientation_params_disp=[] 1275 1317 self.values=[] 1318 self.weights=[] 1319 1320 1276 1321 from sans.models.dispersion_models import GaussianDispersion 1277 1322 if len(self.disp_cb_dict)==0: … … 1284 1329 return 1285 1330 1331 1286 1332 for p in self.disp_cb_dict: 1287 1333 # The parameter was un-selected. Go back to Gaussian model (with 0 pts) … … 1293 1339 self.model.set_dispersion(p, disp_model) 1294 1340 # Redraw the model 1341 print "reset dispersity=> draw" 1295 1342 self._draw_model() 1296 1343 … … 1315 1362 self._set_sizer_gaussian() 1316 1363 1317 if name=="ArrayDispersion":1364 if name == "ArrayDispersion": 1318 1365 self._set_sizer_arraydispersion() 1319 1366 … … 1343 1390 if item in self.param_toFit: 1344 1391 self.param_toFit.remove(item) 1392 1345 1393 self.fittable_param=[] 1346 1394 self.fixed_param=[] … … 1368 1416 self.sizer4.Layout() 1369 1417 self.SetScrollbars(20,20,200,100) 1370 1418 1371 1419 1372 1420 def _set_range_sizer(self, title, object1=None,object=None): … … 1379 1427 #-------------------------------------------------------------- 1380 1428 self.qmin = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 1381 #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.)1382 #self.qmin.SetValue(format_number(self.qmin_x))1383 1429 self.qmin.SetValue(str(self.qmin_x)) 1384 1430 self.qmin.SetToolTipString("Minimun value of Q in linear scale.") … … 1388 1434 1389 1435 self.qmax = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20)) 1390 #For qmin and qmax, do not use format_number.(If do, qmin and max could be different from what is in the data.)1391 #self.qmax.SetValue(format_number(self.qmax_x))1392 1436 self.qmax.SetValue(str(self.qmax_x)) 1393 1437 self.qmax.SetToolTipString("Maximum value of Q in linear scale.") -
sansview/perspectives/fitting/fitpage.py
r848a2ef r71f0373 452 452 ,None,None, None, None,None]) 453 453 454 self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 454 self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 455 self.state.model = self.model.clone() 456 455 457 wx.PostEvent(self.parent, StatusEvent(status=\ 456 458 " Selected Distribution: Gaussian")) … … 460 462 self.sizer4_4.Layout() 461 463 self.sizer4.Layout() 464 self.Layout() 462 465 self.SetScrollbars(20,20,200,100) 466 self.Refresh() 463 467 464 468 -
sansview/perspectives/fitting/fitpanel.py
rdf4c3ad r71f0373 339 339 340 340 memento= self.fit_page_name[page_title][0] 341 341 342 panel.reset_page(memento) 342 343 else: 343 344 self.fit_page_name[page_title]=[] 344 345 self.fit_page_name[page_title].insert(0,panel.createMemento()) 345 346 # We just created a model page, we are ready to plot the model 347 #self.manager.draw_model(model, model.name) 348 #FOR PLUGIN for some reason model.name is = BASEcomponent 349 self.manager.draw_model(model, qmin=qmin, qmax=qmax) 346 ## We just created a model page, we are ready to plot the model 347 self.manager.draw_model(model, qmin=qmin, qmax=qmax) 350 348 351 349 -
sansview/perspectives/fitting/modelpage.py
rdad49a0 r71f0373 284 284 285 285 msg = " Selected Distribution: Gaussian" 286 wx.PostEvent(self.parent.parent, StatusEvent( status= msg )) 286 wx.PostEvent(self.parent.parent, StatusEvent( status= msg )) 287 self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) 287 288 ix =0 288 289 iy +=1 … … 334 335 """ 335 336 self.model = model 337 if self.model !=None: 338 self.disp_list= self.model.getDispParamList() 336 339 self.set_model_param_sizer(self.model) 337 340 ## keep the sizer view consistent with the model menu selecting … … 562 565 else: 563 566 self.text2_4.Hide() 564 self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict)567 565 568 boxsizer1.Add(sizer) 566 569 self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) -
sansview/perspectives/fitting/pagestate.py
rdad49a0 r71f0373 25 25 if not hasattr(self.model, "_persistency_dict"): 26 26 self.model._persistency_dict = {} 27 self.model._persistency_dict = copy.deepcopy(model._persistency_dict) 27 28 #fit page manager 28 29 self.manager = None … … 50 51 #list of dispersion paramaters 51 52 self.disp_list =[] 53 if self.model !=None: 54 self.disp_list = self.model.getDispParamList() 52 55 self._disp_obj_dict={} 53 56 self.disp_cb_dict={} … … 98 101 obj.data = copy.deepcopy(self.data) 99 102 obj.model_list_box = copy.deepcopy(self.model_list_box) 103 100 104 obj.manager = self.manager 101 105 obj.event_owner = self.event_owner 106 obj.disp_list = copy.deepcopy(self.disp_list) 102 107 103 108 obj.enable2D = copy.deepcopy(self.enable2D) … … 110 115 obj.enable_disp = copy.deepcopy(self.enable_disp) 111 116 obj.disable_disp = copy.deepcopy(self.disable_disp) 112 if len(self.model._persistency_dict)>0:117 if self.model !=None and len(self.model._persistency_dict)>0: 113 118 for k, v in self.model._persistency_dict.iteritems(): 114 119 obj.model._persistency_dict[k] = copy.deepcopy(v) … … 137 142 return obj 138 143 144 139 145 class PageMemento(object): 140 146 """
Note: See TracChangeset
for help on using the changeset viewer.