Changeset 077809c in sasview
- Timestamp:
- Jul 13, 2009 11:26:32 AM (15 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:
- 342d9197
- Parents:
- 70bf68c
- Location:
- sansview/perspectives/fitting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage.py
r3b9e023 r077809c 552 552 self.state.structurecombobox = self.structurebox.GetCurrentSelection() 553 553 self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() 554 #print "_on_select_model",self.state.structurecombobox,self.state.formfactorcombobox554 555 555 556 556 if event !=None: … … 586 586 temp_smearer= self.smearer 587 587 ##Calculate chi2 588 588 589 self.compute_chisqr(smearer= temp_smearer) 589 590 ## new state posted … … 606 607 if self.enable_smearer.GetValue(): 607 608 temp_smearer= self.smearer 609 608 610 self.compute_chisqr(smearer= temp_smearer) 609 611 ## new state posted … … 793 795 """ 794 796 try: 797 if output ==None: 798 output= "-" 795 799 self.tcChi.SetLabel(str(output)) 796 800 … … 825 829 self.calc_Chisqr.stop() 826 830 827 self.calc_Chisqr= CalcChisqr1D( x= self.data.x, 828 y= self.data.y, 829 dy= self.data.dy, 831 self.calc_Chisqr= CalcChisqr1D( data1d= self.data, 830 832 model= self.model, 831 833 smearer=smearer, … … 864 866 self.calc_Chisqr.stop() 865 867 866 self.calc_Chisqr= CalcChisqr2D( x_bins= self.data.x_bins, 867 y_bins= self.data.y_bins, 868 data= self.data.data, 869 err_data = self.data.err_data, 868 self.calc_Chisqr= CalcChisqr2D( data2d= self.data, 870 869 model= self.model, 871 870 qmin= self.qmin_x, … … 877 876 878 877 except: 879 raise ValueError," Could not compute Chisqr for %s Model 2D: "%self.model.name 880 878 raise 881 879 882 880 … … 897 895 return 898 896 except: 899 wx.PostEvent(self.parent. GrandParent, StatusEvent(status=\897 wx.PostEvent(self.parent.parent, StatusEvent(status=\ 900 898 "Chisqr Error: %s"% sys.exc_value)) 901 899 return -
sansview/perspectives/fitting/gui_thread.py
re733619 r077809c 9 9 10 10 from data_util.calcthread import CalcThread 11 from sans.fit.AbstractFitEngine import FitData2D, FitData1D, SansAssembly 12 11 13 12 14 class CalcChisqr1D(CalcThread): … … 14 16 Compute chisqr 15 17 """ 16 def __init__(self, x, y,dy, model,18 def __init__(self, data1d, model, 17 19 smearer=None, 18 20 qmin=None, … … 27 29 yieldtime, 28 30 worktime) 29 self.smearer =smearer 30 self.y = numpy.array(y) 31 self.x = numpy.array(x) 32 self.dy= copy.deepcopy(dy) 31 32 if model ==None or data1d ==None: 33 raise ValueError, "Need data and model to compute chisqr" 34 35 if data1d.__class__.__name__ !="Data1D": 36 msg= str(data1d.__class__.__name__) 37 raise ValueError, "need Data1D to compute chisqr. Current class %s"%msg 38 39 self.fitdata= FitData1D(data1d, smearer=smearer) 40 self.fitdata.setFitRange(qmin=qmin,qmax=qmax) 33 41 self.model = model 34 self.qmin = qmin 35 self.qmax = qmax 36 self.smearer = smearer 42 37 43 self.starttime = 0 38 44 … … 53 59 self.starttime = time.time() 54 60 55 x,y = [numpy.asarray(v) for v in (self.x,self.y)]56 if self.dy==None or self.dy==[]:57 self.dy= numpy.zeros(len(self.y))58 self.dy[self.dy==0]=159 60 if self.qmin==0.0 and not numpy.isfinite(self.y[self.qmin]):61 self.qmin = min(self.x[sel.x!=0])62 elif self.qmin==None:63 self.qmin= min(self.x)64 65 if self.qmax==None:66 self.qmax= max(self.x)67 68 fx = numpy.zeros(len(self.x))69 70 61 output= None 71 62 res=[] 72 try: 73 74 for i_x in range(len(self.x)): 75 76 # Check whether we need to bail out 77 self.isquit() 78 79 fx[i_x]=self.model.run(self.x[i_x]) 80 81 if self.smearer!=None: 82 fx= self.smearer(fx) 83 84 for i_y in range(len(fx)): 85 # Check whether we need to bail out 86 self.isquit() 87 88 temp=(self.y[i_y] - fx[i_y])/self.dy[i_y] 89 res.append(temp*temp) 90 #sum of residuals 63 try: 64 res = self.fitdata.residuals(self.model.run) 91 65 sum=0 92 66 for item in res: … … 94 68 self.isquit() 95 69 if numpy.isfinite(item): 96 sum +=item 97 output = sum/ len(res) 70 sum +=item*item 71 if len(res)>0: 72 output = sum/ len(res) 73 98 74 elapsed = time.time()-self.starttime 99 75 self.complete(output= output, elapsed=elapsed) … … 103 79 # Real code should not print, but this is an example... 104 80 raise 105 except: 81 except: 106 82 raise 107 83 … … 111 87 """ 112 88 113 def __init__(self, x_bins, y_bins,data,err_data, model,89 def __init__(self,data2d, model, 114 90 qmin, 115 91 qmax, … … 123 99 yieldtime, 124 100 worktime) 125 126 self.y_bins = y_bins 127 self.x_bins = x_bins 128 self.data= data 129 self.err_data= copy.deepcopy(err_data) 101 102 if model ==None or data2d ==None: 103 raise ValueError, "Need data and model to compute chisqr" 104 105 if data2d.__class__.__name__ !="Data2D": 106 msg= str(data2d.__class__.__name__) 107 raise ValueError, "need Data2D to compute chisqr. Current class %s"%msg 108 109 self.fitdata = FitData2D(data2d) 110 self.fitdata.setFitRange(qmin=qmin,qmax=qmax) 111 130 112 self.model = model 131 self.qmin = qmin132 self.qmax = qmax133 113 134 114 self.starttime = 0 … … 149 129 """ 150 130 self.starttime = time.time() 151 if self.model ==None: 152 return 153 if self.data==None: 154 return 155 if self.err_data==None or self.err_data==[]: 156 self.err_data= numpy.zeros(len(self.x_bins),len(self.y_bins)) 157 158 self.err_data[self.err_data==0]=1 159 131 160 132 output= None 161 133 res=[] 162 134 try: 163 164 for i in range(len(self.x_bins)): 165 # Check whether we need to bail out 166 self.isquit() 167 for j in range(len(self.y_bins)): 168 #Check the range containing data between self.qmin_x and self.qmax_x 169 value = math.pow(self.x_bins[i],2)+ math.pow(self.y_bins[j],2) 170 if value >= math.pow(self.qmin,2) and value <= math.pow(self.qmax,2): 171 172 temp = [self.x_bins[i],self.y_bins[j]] 173 error= self.err_data[j][i] 174 chisqrji = (self.data[j][i]- self.model.runXY(temp ))/error 175 #Vector containing residuals 176 res.append( math.pow(chisqrji,2) ) 177 135 res = self.fitdata.residuals(self.model.run) 178 136 sum=0 179 137 for item in res: … … 181 139 self.isquit() 182 140 if numpy.isfinite(item): 183 sum +=item 184 output = sum/ len(res) 141 sum +=item*item 142 if len(res)>0: 143 output = sum/ len(res) 144 185 145 elapsed = time.time()-self.starttime 186 146 self.complete(output= output, elapsed=elapsed) … … 190 150 # Real code should not print, but this is an example... 191 151 raise 152 except: 153 raise
Note: See TracChangeset
for help on using the changeset viewer.