Changeset 442895f in sasview
- Timestamp:
- Sep 23, 2008 3:25:52 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:
- 6aa47df
- Parents:
- e71440c
- Location:
- sansview/perspectives/fitting
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
sansview/perspectives/fitting/fitpage.py
r55fd102 r442895f 2 2 import wx 3 3 import wx.lib 4 import numpy 4 import numpy,math 5 5 import copy 6 6 … … 65 65 self.vbox.Add(self.sizer1) 66 66 67 id = wx.NewId() 68 self.btClose =wx.Button(self,id,'Close') 69 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id) 70 self.btClose.SetToolTipString("Close page.") 67 71 ix = 0 68 72 iy = 1 … … 123 127 ix +=2 124 128 self.sizer1.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 125 129 iy+= 1 130 ix = 3 131 self.sizer1.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) 126 132 # contains link between model ,all its parameters, and panel organization 127 133 self.parameters=[] … … 193 199 from the previous selected data 194 200 """ 195 196 201 try: 197 202 if dataset !=None: … … 205 210 206 211 212 def onClose(self,event): 213 self.GrandParent.onClose() 214 215 216 def compute_chisqr(self): 217 """ @param fn: function that return model value 218 @return residuals 219 """ 220 flag=self.checkFitRange() 221 if flag== True: 222 qmin = float(self.xmin.GetValue()) 223 qmax = float(self.xmax.GetValue()) 224 x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)] 225 if qmin==None and qmax==None: 226 fx =numpy.asarray([self.model.run(v) for v in x]) 227 res=(y - fx)/dy 228 else: 229 idx = (x>= qmin) & (x <=qmax) 230 fx = numpy.asarray([self.model.run(item)for item in x[idx ]]) 231 res= (y[idx] - fx)/dy[idx] 232 233 sum=0 234 for item in res: 235 sum +=item 236 self.tcChi.SetValue(format_number(math.fabs(sum))) 237 238 207 239 def onFit(self,event): 208 240 """ signal for fitting""" … … 214 246 qmax =float( self.xmax.GetValue()) 215 247 if len(self.param_toFit) >0 and flag==True: 216 #self.manager._on_single_fit(model=self.model,qmin=qmin,qmax=qmax)217 248 self.manager._on_single_fit(qmin=qmin,qmax=qmax) 218 249 else: … … 264 295 set a flag to determine if the fitting range entered by the user is valid 265 296 """ 297 266 298 try: 267 299 flag=self.checkFitRange() … … 269 301 self.manager.redraw_model(float(self.xmin.GetValue())\ 270 302 ,float(self.xmax.GetValue())) 303 271 304 except: 272 305 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ … … 489 522 self.xmin.Disable() 490 523 self.xmax.Disable() 491 524 self.compute_chisqr() 492 525 self.vbox.Layout() 493 526 self.GrandParent.GetSizer().Layout() … … 500 533 """ 501 534 self.set_model_parameter() 502 535 self.compute_chisqr() 536 503 537 def set_model_parameter(self): 538 """ 539 this method redraws the model according to parameters values changes 540 and the reset model according to paramaters changes 541 """ 504 542 if len(self.parameters) !=0 and self.model !=None: 505 543 for item in self.parameters: … … 514 552 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 515 553 "Drawing Error:wrong value entered : %s"% sys.exc_value)) 554 555 516 556 def select_all_param(self,event): 517 557 """ … … 603 643 for item in self.param_toFit: 604 644 if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out): 605 item[1].SetValue(format_number(out[i])) 645 #item[1].SetValue(format_number(out[i])) 646 item[1].SetValue(format_number(self.model.getParam(item[0].GetLabelText()))) 606 647 item[1].Refresh() 607 648 if (cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov): -
sansview/perspectives/fitting/fitpanel.py
r4fc6dbf r442895f 37 37 self.nb.AddPage(self.sim_page,"Simultaneous Fit") 38 38 39 id = wx.NewId()40 self.btClose =wx.Button(self,id,'Close')41 self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id)42 self.btClose.SetToolTipString("Close page.")43 44 sizer_button = wx.BoxSizer(wx.HORIZONTAL)45 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)46 sizer_button.Add(self.btClose, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)47 self.sizer.Add(sizer_button,1, wx.EXPAND)48 39 #dictionary of miodel {model class name, model class} 49 40 self.model_list_box={} … … 145 136 return self.nb.GetPage(self.nb.GetSelection()) 146 137 147 def onClose(self ,event):138 def onClose(self): 148 139 """ 149 140 close the current page except the simpage. remove each check box link to the model 150 141 selected on that page. remove its reference into page_finder (fitting module) 151 142 """ 143 152 144 sim_page = self.nb.GetPage(0) 153 145 selected_page = self.nb.GetPage(self.nb.GetSelection()) -
sansview/perspectives/fitting/fitting.py
r55fd102 r442895f 14 14 import fitpage 15 15 import park 16 class PlottableDatas(Data,Data1D): 17 """ class plottable data: class allowing to plot Data type on panel""" 18 19 def __init__(self,data=None,data1d=None): 20 Data.__init__(self,sans_data=data1d) 21 Data1D.__init__(self,x=data1d.x,y = data1d.y,dx = data1d.dx,dy = data1d.dy) 22 #self.x = data1d.x 23 #self.y = data1d.y 24 #self.dx = data1d.dx 25 #self.dy = data1d.dy 26 #self.data=data 27 self.group_id = data1d.group_id 28 #x_name, x_units = data1d.get_xaxis() 29 #y_name, y_units = data1d.get_yaxis() 30 #self.xaxis( x_name, x_units) 31 #self.yaxis( y_name, y_units ) 32 #self.qmin = data.qmin 33 #self.qmax = data.qmax 34 16 35 17 36 class PlottableData(Data,Data1D): 18 37 """ class plottable data: class allowing to plot Data type on panel""" 19 def __init__(self,data,data1d): 38 39 def __init__(self,data=None,data1d=None): 40 #Data.__init__(self,*args) 41 #Data1D.__init__(self,**kw) 20 42 self.x = data1d.x 21 43 self.y = data1d.y 22 44 self.dx = data1d.dx 23 45 self.dy = data1d.dy 24 46 self.data=data 25 47 self.group_id = data1d.group_id 26 48 x_name, x_units = data1d.get_xaxis() … … 30 52 self.qmin = data.qmin 31 53 self.qmax = data.qmax 54 def residuals(self, fn): 55 return self.data.residuals(fn) 32 56 33 57 class Plugin: … … 68 92 wx.EVT_MENU(owner, id1, self.on_perspective) 69 93 id3 = wx.NewId() 70 self.menu1.Append (id3,'&scipy \ park','toggle engine to park or scipy')94 self.menu1.AppendCheckItem(id3, "park") 71 95 wx.EVT_MENU(owner, id3, self._onset_engine) 72 96 … … 166 190 #create a fitproblem storing all link to data,model,page creation 167 191 self.page_finder[page]= FitProblem() 168 data_for_park= Data(sans_data=item) 169 datap=PlottableData(data=data_for_park,data1d=item) 170 self.page_finder[page].add_data(datap) 192 #data_for_park= Data(sans_data=item) 193 #datap = PlottableData(data=data_for_park,data1d=item) 194 #self.page_finder[page].add_data(datap) 195 self.page_finder[page].add_data(item) 171 196 except: 197 #raise 172 198 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: \ 173 199 data already Selected ")) … … 230 256 break 231 257 i = 0 258 # print "fitting: single fit pars ", pars 232 259 for name in pars: 233 260 if result.pvec.__class__==numpy.float64: … … 235 262 else: 236 263 model.setParam(name,result.pvec[i]) 264 # print "fitting: single fit", name, result.pvec[i] 237 265 i += 1 266 # print "fitting result : chisqr",result.fitness 267 # print "fitting result : pvec",result.pvec 268 # print "fitting result : stderr",result.stderr 269 238 270 current_pg.onsetValues(result.fitness, result.pvec,result.stderr) 239 271 self.plot_helper(currpage=current_pg,qmin=qmin,qmax=qmax) 240 272 except: 273 raise 241 274 wx.PostEvent(self.parent, StatusEvent(status="Fitting error: %s" % sys.exc_value)) 242 275 … … 319 352 try: 320 353 self.fitter.set_model(Model(model), self.id, pars) 321 self.fitter.set_data(data,self.id,qmin,qmax) 354 #print "fitting: data .x",data.x 355 #print "fitting: data .y",data.y 356 #print "fitting: data .dy",data.dy 357 self.fitter.set_data(Data(sans_data=data),self.id,qmin,qmax) 322 358 323 359 result=self.fitter.fit() … … 325 361 326 362 except: 363 raise 327 364 wx.PostEvent(self.parent, StatusEvent(status="Single Fit error: %s" % sys.exc_value)) 328 365 return … … 364 401 return 365 402 self.fitter.set_model(Model(model), self.id, pars) 366 self.fitter.set_data( data,self.id,qmin,qmax)403 self.fitter.set_data(Data(sans_data=data),self.id,qmin,qmax) 367 404 368 405 self.id += 1 … … 415 452 model.name="M"+str(self.index_model) 416 453 self.index_model += 1 417 #self.page_finder[current_pg].set_theory("Fitness")454 418 455 self.page_finder[current_pg].set_model(model,M_name) 419 456 self.plot_helper(currpage= current_pg,qmin= None,qmax= None) … … 448 485 if data!=None: 449 486 theory = Theory1D(x=[], y=[]) 450 theory.name = model.name487 theory.name = "Model" 451 488 theory.group_id = data.group_id 452 489 … … 455 492 theory.xaxis(x_name, x_units) 456 493 theory.yaxis(y_name, y_units) 457 494 #print"fitting : redraw data.x",data.x 495 #print"fitting : redraw data.y",data.y 496 #print"fitting : redraw data.dy",data.dy 458 497 if qmin == None : 459 498 qmin = min(data.x) … … 489 528 skipping point x %g %s" %(qmax, sys.exc_value))) 490 529 try: 491 from sans.guicomm.events import NewPlotEvent 530 #print "fitting redraw for plot thoery .x",theory.x 531 #print "fitting redraw for plot thoery .y",theory.y 532 #print "fitting redraw for plot thoery .dy",theory.dy 533 #rom sans.guicomm.events import NewPlotEvent 492 534 wx.PostEvent(self.parent, NewPlotEvent(plot=theory, title="Analytical model")) 493 535 except: 536 raise 494 537 print "SimView.complete1D: could not import sans.guicomm.events" 495 538 … … 520 563 521 564 new_plot = Theory1D(x, y) 522 new_plot.name = model.name565 new_plot.name = "Model" 523 566 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 524 567 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") -
sansview/perspectives/fitting/modelpage.py
r55fd102 r442895f 268 268 self.manager.draw_model(self.model) 269 269 except: 270 270 271 wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\ 271 " Drawing Error:wrong value entered : %s"% sys.exc_value))272 "Model Drawing Error:wrong value entered : %s"% sys.exc_value)) 272 273 273 274 -
sansview/perspectives/fitting/models.py
r3b19ac9 r442895f 1 1 import wx 2 2 import imp 3 import os,sys 3 import os,sys,math 4 4 import os.path 5 5 … … 76 76 self.model_list = {} 77 77 self.model_list_box = {} 78 78 79 model_info="shape-based models" 80 81 from sans.models.SphereModel import SphereModel 82 self.model_list[str(wx.NewId())] = ModelInfo(SphereModel , model_info) 83 79 84 from sans.models.CylinderModel import CylinderModel 80 85 self.model_list[str(wx.NewId())] = ModelInfo(CylinderModel , model_info) 81 86 82 from sans.models.SphereModel import SphereModel 83 self.model_list[str(wx.NewId())] = ModelInfo(SphereModel , model_info) 84 87 from sans.models.CoreShellModel import CoreShellModel 88 self.model_list[str(wx.NewId())] = ModelInfo(CoreShellModel , model_info) 89 90 from sans.models.CoreShellCylinderModel import CoreShellCylinderModel 91 self.model_list[str(wx.NewId())] = ModelInfo(CoreShellCylinderModel , model_info) 92 93 from sans.models.EllipticalCylinderModel import EllipticalCylinderModel 94 self.model_list[str(wx.NewId())] = ModelInfo(EllipticalCylinderModel , model_info) 95 96 from sans.models.EllipsoidModel import EllipsoidModel 97 self.model_list[str(wx.NewId())] = ModelInfo(EllipsoidModel , model_info) 98 85 99 from sans.guitools.LineModel import LineModel 86 100 self.model_list[str(wx.NewId())] = ModelInfo(LineModel , model_info) 101 102 87 103 model_info="shape-independent models" 88 from sans.models.Lorentzian import Lorentzian 89 self.indep_model.append( ModelInfo(Lorentzian , model_info) ) 104 105 from sans.models.BEPolyelectrolyte import BEPolyelectrolyte 106 self.indep_model.append( ModelInfo( BEPolyelectrolyte , model_info) ) 107 108 from sans.models.DABModel import DABModel 109 self.indep_model.append( ModelInfo(DABModel , model_info+ 110 "\n Evaluates F(x) = scale/( 1 + (x*L)^2 )^(2) +bkd") ) 111 112 from sans.models.DebyeModel import DebyeModel 113 self.indep_model.append( ModelInfo(DebyeModel , model_info+ 114 "\n Evaluates F(x) = 2( exp(-x)+x -1 )/x**2") ) 115 116 from sans.models.FractalModel import FractalModel 117 class FractalAbsModel(FractalModel): 118 def _Fractal(self, x): 119 return FractalModel._Fractal(self, math.fabs(x)) 120 self.indep_model.append( ModelInfo(FractalAbsModel , model_info) ) 121 122 from sans.models.LorentzModel import LorentzModel 123 self.indep_model.append( ModelInfo(LorentzModel , model_info+ 124 "\n Evaluates F(x)= scale/( 1 + (x*L)^2 ) + bkd ") ) 125 126 from sans.models.PowerLawModel import PowerLawModel 127 class PowerLawAbsModel(PowerLawModel): 128 def _PowerLaw(self, x): 129 try: 130 return PowerLawModel._PowerLaw(self, math.fabs(x)) 131 except: 132 print sys.exc_value 133 self.indep_model.append( ModelInfo(PowerLawAbsModel , model_info+ 134 "\n Evaluates abs(F(x)) \n with F(x) = scale* (x)^(m) + bkd ") ) 135 136 137 from sans.models.TeubnerStreyModel import TeubnerStreyModel 138 self.indep_model.append( ModelInfo(TeubnerStreyModel , model_info) ) 139 140 141 142 143 144 90 145 91 146 #Looking for plugins -
sansview/perspectives/fitting/simfitpage.py
r55fd102 r442895f 39 39 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 40 40 wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_model_name) 41 42 ix = 0 43 iy = 1 41 44 42 text=wx.StaticText(self, -1, 'Constraint') 45 43 self.sizer2.Add(text,0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 46 ix = 0 47 iy += 1 44 48 45 self.ctl2 = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE) 49 46 self.ctl2.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) 50 47 self.ctl2.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter) 51 48 self.sizer2.Add(self.ctl2, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 52 ix +=249 53 50 self.sizer2.Add(self.btFit, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 54 51 self.params=[] … … 56 53 self.model_toFit=[] 57 54 self.page_finder={} 58 iy +=1 55 56 59 57 #self.sizer2.Add((20,20),(iy, ix)) 60 self.sizer2.Add((20,20), 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)58 #self.sizer2.Add((20,20), 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 61 59 self.vbox.Layout() 62 60 self.vbox.Fit(self) … … 117 115 for page, value in page_finder.iteritems(): 118 116 try: 119 list =value.get_model()120 model =list[0]121 modelname =list[1]117 list = value.get_model() 118 model = list[0] 119 modelname = list[1] 122 120 cb = wx.CheckBox(self, -1, modelname, (10, 10)) 123 121 cb.SetValue(False) … … 131 129 #(value.get_data().group_id,sys.exc_value))) 132 130 pass 131 iy +=1 132 self.sizer1.Add((20,20),( iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 133 133 self.sizer1.Layout() 134 134 self.vbox.Layout()
Note: See TracChangeset
for help on using the changeset viewer.