- Timestamp:
- Feb 28, 2009 3:41:17 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:
- 6d07882a
- Parents:
- acd91458
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/modelpage.py
rb491d6e r81e4cf7 4 4 import numpy 5 5 import copy 6 6 import math 7 from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion 7 8 8 9 from sans.guicomm.events import StatusEvent … … 34 35 # model on which the fit would be performed 35 36 self.model=model 37 # Data member to store the dispersion object created 38 self._disp_obj_dict = {} 36 39 self.back_up_model= model.clone() 37 40 #list of dispersion paramaters … … 339 342 self.disp_box.SetValue("GaussianModel") 340 343 for k,v in self.polydisp.iteritems(): 341 """342 344 if str(v)=="MyModel": 343 345 self.disp_box.Insert("Select customized Model",id) 344 346 else: 345 self.disp_box.Insert(str(v),id)346 """347 if str(v)!="MyModel":348 347 self.disp_box.Insert(str(v),id) 349 348 … … 585 584 self.sizer5.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 586 585 587 self.parameters.append([cb,ctl1,text2,ctl2])586 self.parameters.append([cb,ctl1,text2,ctl2]) 588 587 589 588 iy+=1 … … 640 639 raise 641 640 642 def _draw_disp_theta(self):643 path = self._selectDlg()644 dispersion=None645 646 for key, value in self.polydisp.iteritems():647 if value =="MyModel":648 disp_ph = key()649 disp_th = key()650 break651 values,weights = self.read_file(path)652 if values ==None and weights==None:653 return654 import math655 disp_ph.set_weights( values, weights)656 disp_th.set_weights( values, weights)657 658 if self.theta_cb !=None:659 angle= self.theta_cb.GetLabelText()660 n=0661 self.disp_list=self.model.getDispParamList()662 if angle.lower().count("theta")>0:663 for param in self.model.getParamList():664 if not param in self.disp_list and param.lower().count("theta")>0:665 self.model.set_dispersion(param, disp_th)666 self.model.dispersion[param]['npts'] = len(values)667 n+=1668 669 if n ==0:670 wx.PostEvent(self.parent.parent, StatusEvent(status=\671 " Model contains no theta distribution"))672 else:673 self._draw_model()674 def _draw_disp_Phi(self):675 path = self._selectDlg()676 dispersion=None677 678 for key, value in self.polydisp.iteritems():679 if value =="MyModel":680 disp_ph = key()681 disp_th = key()682 break683 values,weights = self.read_file(path)684 if values ==None and weights==None:685 return686 import math687 disp_ph.set_weights( values, weights)688 disp_th.set_weights( values, weights)689 690 if self.theta_cb !=None:691 angle= self.theta_cb.GetLabelText()692 n=0693 self.disp_list=self.model.getDispParamList()694 if angle.lower().count("theta")>0:695 for param in self.model.getParamList():696 if not param in self.disp_list and param.lower().count("theta")>0:697 self.model.set_dispersion(param, disp_th)698 self.model.dispersion[param]['npts'] = len(values)699 n+=1700 701 if n ==0:702 wx.PostEvent(self.parent.parent, StatusEvent(status=\703 " Model contains no theta distribution"))704 else:705 self._draw_model()706 707 641 708 642 def select_disp_angle(self, event): 709 if not self.phi_cb.GetValue(): 710 return 711 path = self._selectDlg() 712 dispersion=None 713 714 for key, value in self.polydisp.iteritems(): 715 if value =="MyModel": 716 disp_ph = key() 717 disp_th = key() 718 719 break 720 try: 721 values,weights = self.read_file(path) 722 except: 723 raise 724 725 if values ==None and weights==None: 726 return 727 import math 728 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 729 " Costumized Distribution: %s"% path)) 730 731 disp_ph.set_weights( values, weights) 732 disp_th.set_weights( values, weights) 733 734 735 736 if self.theta_cb !=None: 737 angle= self.phi_cb.GetLabelText() 738 n=0 739 #print "hello1",self.model.runXY([0.01,0.01]) 740 self.disp_list=self.model.getDispParamList() 741 name= "phi" 742 if angle.lower().count(name)>0: 743 for param in self.model.getParamList(): 744 if not param in self.disp_list and param.lower().count(name)>0: 745 self.model.set_dispersion(param, disp_th) 746 #print "para, th",param, disp_th 747 #self.model.dispersion[param]['npts'] = len(values) 748 n+=1 749 #print "model dispers list",self.model.getDispParamList() 750 if n ==0: 751 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 752 " Model contains no %s distribution"%name)) 753 else: 754 #print "hello2",self.model.runXY([0.01,0.01]) 755 #self._draw_model() 756 qmin=self.qmin_x 757 qmax=self.qmax_x 758 qstep= self.num_points 759 x= numpy.linspace(start= -1*qmax, 760 stop= qmax, 761 num= qstep, 762 endpoint=True ) 763 y = numpy.linspace(start= -1*qmax, 764 stop= qmax, 765 num= qstep, 766 endpoint=True ) 767 output= numpy.zeros([len(x),len(y)]) 768 for i_x in range(int(len(x))): 769 for i_y in range(int(len(y))): 770 if (x[i_x]*x[i_x]+y[i_y]*y[i_y]) \ 771 < qmin * qmin: 772 output[i_x] [i_y]=0 773 else: 774 value = self.model.runXY([x[i_x], y[i_y]]) 775 output[i_x] [i_y]=value 776 #print"modelpage", output 777 self.manager.complete( output=output, elapsed=None, model=self.model, qmin=qmin, qmax=qmax,qstep=qstep) 778 #self._draw_model() 643 """ 644 Event for when a user select a parameter to average over. 645 @param event: check box event 646 """ 647 648 649 # Go through the list of dispersion check boxes to identify which one has changed 650 for p in self.disp_cb_dict: 651 # Catch which one of the box was just checked or unchecked. 652 if event.GetEventObject() == self.disp_cb_dict[p]: 653 654 655 if self.disp_cb_dict[p].GetValue() == True: 656 # The user wants this parameter to be averaged. 657 # Pop up the file selection dialog. 658 path = self._selectDlg() 659 660 # If nothing was selected, just return 661 if path is None: 662 self.disp_cb_dict[p].SetValue(False) 663 return 664 665 try: 666 values,weights = self.read_file(path) 667 except: 668 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 669 "Could not read input file")) 670 return 671 672 # If any of the two arrays is empty, notify the user that we won't 673 # proceed 674 if values is None or weights is None: 675 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 676 "The loaded %s distrubtion is corrupted or empty" % p)) 677 return 678 679 # Tell the user that we are about to apply the distribution 680 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 681 "Applying loaded %s distribution: %s" % (p, path))) 682 683 # Create the dispersion objects 684 disp_model = ArrayDispersion() 685 disp_model.set_weights(values, weights) 686 # Store the object to make it persist outside the scope of this method 687 #TODO: refactor model to clean this up? 688 self._disp_obj_dict[p] = disp_model 689 690 # Set the new model as the dispersion object for the selected parameter 691 self.model.set_dispersion(p, disp_model) 692 693 694 # Redraw the model 695 self._draw_model() 696 697 else: 698 # The parameter was un-selected. Go back to Gaussian model (with 0 pts) 699 disp_model = GaussianDispersion() 700 # Store the object to make it persist outside the scope of this method 701 #TODO: refactor model to clean this up? 702 self._disp_obj_dict[p] = disp_model 703 704 # Set the new model as the dispersion object for the selected parameter 705 self.model.set_dispersion(p, disp_model) 706 707 # Redraw the model 708 self._draw_model() 709 return 710 779 711 780 712 … … 797 729 self.sizer8.Add(disp1,( iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 798 730 799 ix+=1 800 self.theta_cb = wx.CheckBox(self, -1,"Theta ", (10, 10)) 801 wx.EVT_CHECKBOX(self, self.theta_cb.GetId(), self.select_disp_angle) 802 self.sizer8.Add(self.theta_cb,(iy, ix),(1,1),\ 803 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 804 ix+=1 805 self.phi_cb = wx.CheckBox(self, -1,"Phi", (10, 10)) 806 wx.EVT_CHECKBOX(self, self.phi_cb.GetId(), self.select_disp_angle) 807 self.sizer8.Add(self.phi_cb,(iy, ix),(1,1),\ 808 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 731 # Look for model parameters to which we can apply an ArrayDispersion model 732 # Add a check box for each parameter. 733 self.disp_cb_dict = {} 734 for p in self.model.dispersion.keys(): 735 ix+=1 736 self.disp_cb_dict[p] = wx.CheckBox(self, -1, p, (10, 10)) 737 738 wx.EVT_CHECKBOX(self, self.disp_cb_dict[p].GetId(), self.select_disp_angle) 739 self.sizer8.Add(self.disp_cb_dict[p], (iy, ix), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 809 740 810 741 ix =0 … … 968 899 name=str(item[0].GetLabelText()) 969 900 value= float(item[1].GetValue()) 970 971 #print "model para", name,value972 901 # If the value of the parameter has changed, 973 902 # update the model and set the is_modified flag 974 903 if value != self.model.getParam(name): 975 #print "went hereee"976 904 self.model.setParam(name,value) 977 905 is_modified = True … … 988 916 name=str(item[0]) 989 917 value= float(item[1].GetValue()) 990 #print "model para", name,value,self.model.getParam(name)991 918 # If the value of the parameter has changed, 992 919 # update the model and set the is_modified flag 993 920 if value != self.model.getParam(name): 994 #print "went hereee"995 921 self.model.setParam(name,value) 996 922 is_modified = True … … 1005 931 name=str(item[0].GetLabelText()) 1006 932 value= float(item[1].GetValue()) 1007 #param_min= item[4].GetValue()1008 #param_max= item[5].GetValue()1009 #print " fittable model para", name,value1010 933 # If the value of the parameter has changed, 1011 934 # update the model and set the is_modified flag 1012 935 if value != self.model.getParam(name): 1013 #print "went here", name,value1014 936 self.model.setParam(name,value) 1015 937 is_modified = True … … 1047 969 [Note to coder: This way future changes will be done in only one place.] 1048 970 """ 1049 #print "_draw_model",self.model1050 971 if name==None: 1051 972 name= self.model.name
Note: See TracChangeset
for help on using the changeset viewer.