Changeset 6f73a08 in sasview for sansview/perspectives
- Timestamp:
- Oct 9, 2008 2:41:05 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:
- 126a761
- Parents:
- 385d464
- Location:
- sansview/perspectives/fitting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage.py
r948add7 r6f73a08 140 140 # flag to check if the user has selected a new model in the combox box 141 141 self.model_hasChanged=False 142 #flag to check if the user has selected a new data 143 self.data_hasChanged=False 142 144 143 #dictionary of model name and model class 145 144 self.model_list_box={} 146 # Data1D to make a deep comparison between 2 Data1D for checking data 147 #change 148 from sans.guitools.plottables import Data1D 149 self.prevData = Data1D(x=[], y=[],dx=None, dy=None) 150 self.prevData.name= None 145 # comparison between 2 group_id for checking data changes 146 self.prev_group_id= None 151 147 152 148 self.data=None … … 191 187 self.GrandParent.GetSizer().Layout() 192 188 193 194 def copy_data(self,dataset): 195 """ 196 copy a select data in the panel to compared with the previous selected data 197 @param dataset: the data selected 198 @note : everything a data is selected, the panel check is it is different 199 from the previous selected data 200 """ 201 try: 202 if dataset !=None: 203 self.prevData.x= copy.deepcopy(dataset.x) 204 self.prevData.y= copy.deepcopy(dataset.y) 205 self.prevData.name=dataset.name 206 if dataset.dy==None: 207 self.prevData.dy= copy.deepcopy(dataset.dy) 208 except: 209 raise ValueError, " copy_data: cannot copy data" 210 189 211 190 212 191 def onClose(self,event): … … 224 203 qmin = float(self.xmin.GetValue()) 225 204 qmax = float(self.xmax.GetValue()) 226 x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 227 if qmin==None and qmax==None: 228 fx =numpy.asarray([self.model.run(v) for v in x]) 229 res=(y - fx)/dy 230 else: 231 idx = (x>= qmin) & (x <=qmax) 232 fx = numpy.asarray([self.model.run(item)for item in x[idx ]]) 233 res= (y[idx] - fx)/dy[idx] 205 #x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 206 #if qmin==None and qmax==None: 207 # fx =numpy.asarray([self.model.run(v) for v in x]) 208 # res=(y - fx)/dy 209 #else: 210 # idx = (x>= qmin) & (x <=qmax) 211 # fx = numpy.asarray([self.model.run(item)for item in x[idx ]]) 212 # res= (y[idx] - fx)/dy[idx] 213 self.data.setFitRange(qmin,qmax) 214 res=self.data.residuals(self.model.runXY) 234 215 sum=0 235 216 for item in res: … … 304 285 flag=self.checkFitRange() 305 286 if flag==True and self.model!=None: 306 self.manager.redraw_model(float(self.xmin.GetValue())\ 287 print"fit page",self.xmin.GetValue(),self.xmax.GetValue() 288 self.manager.redraw_model(float(self.xmin.GetValue())\ 307 289 ,float(self.xmax.GetValue())) 308 309 290 except: 291 310 292 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 311 293 "Drawing Error:wrong value entered %s"% sys.exc_value)) … … 322 304 valueMax = self.xmax.GetValue() 323 305 # Check for possible values entered 324 306 print "fitpage: checkfitrange:",valueMin,valueMax 325 307 try: 326 308 if (float(valueMax)> float(valueMin)): … … 340 322 return flag 341 323 342 def check_data_change(self,dataset): 343 """ 344 check if data selected has changed and set flag self.data_hasChanged 345 has true is changed or false is unchanged 346 @param dataset: data selected 347 """ 348 self.data_hasChanged=False 349 if self.prevData.__class__ !=dataset.__class__: 350 self.data_hasChanged=True 351 352 elif self.prevData.name != dataset.name: 353 self.data_hasChanged=True 354 355 elif len(self.prevData.x) != len(self.prevData.y): 356 self.data_hasChanged=True 357 358 else: 359 for i in range(len(dataset.x)): 360 if self.prevData.x[i] !=dataset.x[i]: 361 self.data_hasChanged=True 362 break 363 364 if self.prevData.y[i] !=dataset.y[i]: 365 self.data_hasChanged=True 366 break 367 368 if dataset.dy !=None: 369 if self.prevData.dy[i] !=dataset.dy[i]: 370 self.data_hasChanged=True 371 break 372 324 373 325 374 326 def set_data_name(self,dataset): … … 379 331 for xmin and xmax range sizer 380 332 """ 381 self.check_data_change(dataset)382 if self. data_hasChanged==True:333 334 if self.prev_group_id !=dataset.data.group_id: 383 335 self._DataNameEnter() 384 self.data =dataset385 self. copy_data(dataset)336 self.data = dataset 337 self.prev_group_id=dataset.data.group_id 386 338 #Displaying Data information 387 self.DataSource.SetValue(str(dataset. name))388 self._xaxis,self._xunit=dataset. get_xaxis()339 self.DataSource.SetValue(str(dataset.data.name)) 340 self._xaxis,self._xunit=dataset.data.get_xaxis() 389 341 self.text4_3.SetLabel(self._xaxis+"["+self._xunit+"]") 390 342 self.text4_1.Show() 391 343 self.text4_2.Show() 392 344 self.text4_3.Show() 393 394 self.xmin.SetValue(format_number(min(dataset.x))) 395 self.xmin.Show() 396 397 self.xmax.SetValue(format_number(max(dataset.x))) 398 self.xmax.Show() 399 345 if not dataset.data.__class__.__name__=='Data2D': 346 self.xmin.SetValue(format_number(min(dataset.data.x))) 347 self.xmin.Show() 348 self.xmax.SetValue(format_number(max(dataset.data.x))) 349 self.xmax.Show() 350 else: 351 self.xmin.SetValue(format_number(numpy.min(dataset.data.image))) 352 self.xmin.Show() 353 self.xmax.SetValue(format_number(numpy.max(dataset.data.image))) 354 self.xmax.Show() 400 355 if ((len(self.param_toFit ) >0) and self.DataSource.GetValue()and \ 401 356 self.modelbox.GetValue() and (self.model_hasChanged ==False)): -
sansview/perspectives/fitting/fitting.py
r57f3320 r6f73a08 4 4 5 5 from copy import deepcopy 6 from sans.guitools.plottables import Data1D, Theory1D 7 from sans.guitools.PlotPanel import PlotPanel 6 #from sans.guitools.plottables import Data1D, Theory1D 7 #from sans.guitools.PlotPanel import PlotPanel 8 from danse.common.plottools.plottables import Data1D, Theory1D, Data2D 9 from danse.common.plottools.PlotPanel import PlotPanel 8 10 from sans.guicomm.events import NewPlotEvent, StatusEvent 9 from sans.fit.AbstractFitEngine import Model,Data 11 from sans.fit.AbstractFitEngine import Model,Data,FitData1D,FitData2D 10 12 from fitproblem import FitProblem 11 13 from fitpanel import FitPanel … … 82 84 self.graph=graph 83 85 for item in graph.plottables: 84 if item.name==graph.selected_plottable and item.__class__.__name__ is not "Theory1D": 85 return [["Select Data", "Dialog with fitting parameters ", self._onSelect]] 86 if item.__class__.__name__ is "Data2D": 87 return [["Fit Data2D", "Dialog with fitting parameters ", self._onSelect]] 88 else: 89 if item.name==graph.selected_plottable and item.__class__.__name__ is not "Theory1D": 90 return [["Select Data", "Dialog with fitting parameters ", self._onSelect]] 86 91 return [] 87 92 … … 138 143 self.panel = event.GetEventObject() 139 144 for item in self.panel.graph.plottables: 140 if item.name == self.panel.graph.selected_plottable :145 if item.name == self.panel.graph.selected_plottable or item.__class__.__name__ is "Data2D": 141 146 #find a name for the page created for notebook 142 147 try: … … 147 152 page = self.fit_panel.add_fit_page(name) 148 153 # add data associated to the page created 149 page.set_data_name(item) 150 #create a fitproblem storing all link to data,model,page creation 151 self.page_finder[page]= FitProblem() 152 #data_for_park= Data(sans_data=item) 153 #datap = PlottableData(data=data_for_park,data1d=item) 154 #self.page_finder[page].add_data(datap) 155 self.page_finder[page].add_data(item) 154 if item.__class__.__name__=='Data1D': 155 new_item=FitData1D(item) 156 else: 157 new_item=FitData2D(item) 158 if page !=None: 159 page.set_data_name(new_item) 160 #create a fitproblem storing all link to data,model,page creation 161 self.page_finder[page]= FitProblem() 162 #data_for_park= Data(sans_data=item) 163 #datap = PlottableData(data=data_for_park,data1d=item) 164 #self.page_finder[page].add_data(datap) 165 self.page_finder[page].add_data(new_item) 156 166 except: 157 #raise158 wx.PostEvent(self.parent, StatusEvent(status=" Fitting error:\159 data already Selected "))167 raise 168 wx.PostEvent(self.parent, StatusEvent(status="Creating Fit page: %s"\ 169 %sys.exc_value)) 160 170 def schedule_for_fit(self,value=0,fitproblem =None): 161 171 """ … … 224 234 for page, value in self.page_finder.iteritems(): 225 235 if page==cpage : 226 data = value.get_data()236 #fitdata = value.get_data() 227 237 list = value.get_model() 228 238 model= list[0] … … 258 268 for page, value in self.page_finder.iteritems(): 259 269 if value.get_scheduled()==1: 260 data = value.get_data()270 #fitdata = value.get_data() 261 271 list = value.get_model() 262 272 model= list[0] … … 305 315 for page, value in self.page_finder.iteritems(): 306 316 if value.get_scheduled() ==1 : 307 data = value.get_data()317 fitdata = value.get_data() 308 318 list=value.get_model() 309 319 model=list[0] … … 319 329 #Do the single fit 320 330 self.fitter.set_model(Model(model), self.id, pars) 321 self.fitter.set_data( Data(sans_data=data),self.id,qmin,qmax)331 self.fitter.set_data(fitdata,self.id,qmin,qmax) 322 332 self.fitter.select_problem_for_fit(Uid=self.id,value=value.get_scheduled()) 323 333 page_fitted=page … … 336 346 self._single_fit_completed(result,pars,page_fitted,qmin,qmax) 337 347 except: 348 raise 338 349 wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value)) 339 350 return … … 360 371 try: 361 372 if value.get_scheduled()==1: 362 data = value.get_data()373 fitdata = value.get_data() 363 374 list = value.get_model() 364 375 model= list[0] … … 389 400 390 401 self.fitter.set_model(new_model, self.id, pars) 391 self.fitter.set_data( Data(sans_data=data),self.id,qmin,qmax)402 self.fitter.set_data(fitdata,self.id,qmin,qmax) 392 403 self.fitter.select_problem_for_fit(Uid=self.id,value=value.get_scheduled()) 393 404 self.id += 1 … … 433 444 current_pg.set_panel(model) 434 445 try: 435 data=self.page_finder[current_pg].get_data()436 M_name="M"+str(self.index_model)+"= "+name+"("+ data.group_id+")"446 fitdata=self.page_finder[current_pg].get_data() 447 M_name="M"+str(self.index_model)+"= "+name+"("+fitdata.data.group_id+")" 437 448 except: 438 449 raise … … 468 479 if page==currpage : 469 480 break 470 data=self.page_finder[page].get_data()481 fitdata=self.page_finder[page].get_data() 471 482 list=self.page_finder[page].get_model() 472 483 model=list[0] 473 if data!=None: 484 data=fitdata.data 485 486 if data!=None and data.__class__.__name__ != 'Data2D': 474 487 theory = Theory1D(x=[], y=[]) 475 488 theory.name = "Model" … … 498 511 tempx = data.x[i] 499 512 tempy = model.run(tempx) 500 501 513 theory.x.append(tempx) 502 514 theory.y.append(tempy) … … 509 521 theory.x.append(tempx) 510 522 theory.y.append(tempy) 511 wx.PostEvent(self.parent, NewPlotEvent(plot=theory, title="Analytical model"))523 512 524 except: 513 525 wx.PostEvent(self.parent, StatusEvent(status="fitting \ 514 526 skipping point x %g %s" %(qmax, sys.exc_value))) 515 516 527 else: 528 theory=Data2D(data.image, data.err_image) 529 theory.x_bins= data.x_bins 530 theory.y_bins= data.y_bins 531 tempy=[] 532 for i in range(len(data.x_bins)): 533 theory.image= model.runXY([data.x_bins[i],data.y_bins[i]]) 534 #print "fitting : plot_helper:", theory.image 535 #print data.image 536 #theory.image=model.runXY(data.image) 537 theory.image=model.run(data.image) 538 print "fitting : plot_helper:",theory.image 539 theory.zmin= data.zmin 540 theory.zmax= data.zmax 541 theory.xmin= data.xmin 542 theory.xmax= data.xmax 543 theory.ymin= data.ymin 544 theory.ymax= data.ymax 545 546 wx.PostEvent(self.parent, NewPlotEvent(plot=theory, title="Analytical model")) 547 548 517 549 def _on_model_menu(self, evt): 518 550 """
Note: See TracChangeset
for help on using the changeset viewer.