source: sasview/sansview/perspectives/fitting/fitpage1D.py @ 1fbb343

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 1fbb343 was 1fbb343, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

sansview: change data member to circumvent a problem with a badly written inheritence

  • Property mode set to 100644
File size: 24.7 KB
Line 
1import sys
2import wx
3import wx.lib
4import numpy,math
5import copy
6
7from sans.guicomm.events import StatusEvent
8from sans.guiframe.utils import format_number
9from modelpage import ModelPage 
10from modelpage import format_number
11(ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()
12_BOX_WIDTH = 80
13
14
15#TODO: FitPage1D inherits from ModelPage but doesn't call its __init__ method!
16#TODO: refactor this class to have an __init__ that deals with data only, then calls a UI builder method.
17
18class FitPage1D(ModelPage):
19    """
20        FitPanel class contains fields allowing to display results when
21        fitting  a model and one data
22        @note: For Fit to be performed the user should check at least one parameter
23        on fit Panel window.
24    """
25    ## Internal name for the AUI manager
26    window_name = "Fit page"
27    ## Title to appear on top of the window
28    window_caption = "Fit Page"
29   
30    name=None
31   
32    def __init__(self, parent,data, *args, **kwargs):
33        wx.ScrolledWindow.__init__(self, parent, *args, **kwargs)
34       
35        """
36            Initialization of the Panel
37        """
38        #Data used for fitting
39        self.data = data
40        # flag to allow data2D plot
41        self.enable2D=False
42        #fit page manager
43        self.manager = None
44        #Store the parent of this panel parent
45        # For this application fitpanel is the parent
46        self.parent  = parent
47        # Event_owner is the owner of model event
48        self.event_owner = None
49        #panel interface
50        self.vbox  = wx.BoxSizer(wx.VERTICAL)
51   
52        self.sizer9 = wx.GridBagSizer(5,5)
53        self.sizer8 = wx.GridBagSizer(5,5)
54        self.sizer7 = wx.GridBagSizer(5,5)
55        self.sizer6 = wx.GridBagSizer(5,5)
56        self.sizer5 = wx.GridBagSizer(5,5)
57        self.sizer4 = wx.GridBagSizer(5,5)
58        self.sizer3 = wx.GridBagSizer(5,5)
59        self.sizer2 = wx.GridBagSizer(5,5)
60        self.sizer1 = wx.GridBagSizer(5,5)
61        # Add layer
62        #data info layer
63        self.vbox.Add(self.sizer1)
64        #data range
65        self.vbox.Add(self.sizer2)
66        #instrument smearing selection layer
67        self.vbox.Add(self.sizer3)
68        #model selection
69        self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
70        self.vbox.Add(self.sizer4)
71        #model paramaters layer
72        self.vbox.Add(self.sizer5)
73        #polydispersion selected
74        self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
75        self.vbox.Add(self.sizer6)
76        #combox box for type of dispersion
77        self.vbox.Add(self.sizer7)
78        #dispersion parameters layer
79        self.vbox.Add(self.sizer8)
80        #fit info layer
81        self.vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0)
82        self.vbox.Add(self.sizer9)
83        #---------sizer 1 draw--------------------------------
84        #Filling the sizer containing data related fields
85        self.DataSource  =wx.StaticText(self, -1,str(data.name))
86        ix = 0
87        iy = 1
88        self.sizer1.Add(wx.StaticText(self, -1, 'Data Source Name : '),(iy,ix),\
89                 (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
90        ix += 1
91        self.sizer1.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
92       
93        #---------sizer 2 draw--------------------------------
94        #set maximum range for x in linear scale
95        if not hasattr(self.data,"data"): #Display only for 1D data fit
96            ix = 0
97            iy = 1
98            # Minimum value of data   
99            self.data_min    = wx.StaticText(self, -1,str(format_number(numpy.min(data.x))))
100            # Maximum value of data 
101            self.data_max    =  wx.StaticText(self, -1,str(format_number(numpy.max(data.x))))   
102            self.text4_3 = wx.StaticText(self, -1, 'Maximum Data Range(Linear)', style=wx.ALIGN_LEFT)
103            self.sizer2.Add(self.text4_3,(iy,ix),(1,1),\
104                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
105            ix += 2
106            self.sizer2.Add(wx.StaticText(self, -1, 'Min :'),(iy, ix),(1,1),\
107                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
108            ix += 1
109            self.sizer2.Add(self.data_min,(iy, ix),(1,1),\
110                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
111            ix += 1
112            self.sizer2.Add(wx.StaticText(self, -1, 'Max : '),(iy, ix),(1,1),\
113                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
114            ix += 1
115            self.sizer2.Add(self.data_max,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
116       
117        #----sizer 3 draw--------------------------------
118        #Filling the sizer containing instruments smearing info.
119        self.disable_smearer = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
120        self.enable_smearer = wx.RadioButton(self, -1, 'Yes', (10, 30))
121        self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId())
122        self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId())
123        ix = 0
124        iy = 1
125        self.sizer3.Add(wx.StaticText(self,-1,'Instrument Smearing'),(iy,ix),(1,1)\
126                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
127        ix += 1
128        self.sizer3.Add(self.enable_smearer,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
129        ix += 1
130        self.sizer3.Add(self.disable_smearer,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
131        ix =0
132        iy+=1
133        self.sizer3.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
134           
135        #------------------ sizer 4  draw------------------------   
136        # This sizer contains model list and chisqr value
137        #filling sizer4
138        self.modelbox = wx.ComboBox(self, -1)
139        self.tcChi    =  wx.StaticText(self, -1, str(0), style=wx.ALIGN_LEFT)
140        self.tcChi.Hide()
141        self.text1_1 = wx.StaticText(self, -1, 'Chi2/dof', style=wx.ALIGN_LEFT)
142        self.text1_1.Hide()
143        ix = 0
144        iy = 1
145        self.sizer4.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\
146                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
147        ix += 1
148        self.sizer4.Add(self.modelbox,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
149        ix += 1
150        self.sizer4.Add(self.text1_1,(iy,ix),(1,1),\
151                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
152        ix += 1
153        self.sizer4.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
154        #----------sizer6-------------------------------------------------
155        #Sizer containing info on polydispersity
156        self.disable_disp = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP)
157        self.enable_disp = wx.RadioButton(self, -1, 'Yes', (10, 30))
158        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.disable_disp.GetId())
159        self.Bind(wx.EVT_RADIOBUTTON, self.Set_DipersParam, id=self.enable_disp.GetId())
160        ix= 0
161        iy=1
162        self.sizer6.Add(wx.StaticText(self,-1,'Polydispersity: '),(iy,ix),(1,1)\
163                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
164        ix += 1
165        self.sizer6.Add(self.enable_disp ,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
166        ix += 1
167        self.sizer6.Add(self.disable_disp ,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
168        ix =0
169        iy+=1
170        self.sizer6.Add((20,20),(iy,ix),(1,1),wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
171        #---------sizer 9 draw----------------------------------------
172       
173       
174        id = wx.NewId()
175        self.btFit =wx.Button(self,id,'Fit')
176        self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id=id)
177        self.btFit.SetToolTipString("Perform fit.")
178        ## Q range
179        # Reversed to the codes; Need to think  carefully about consistency in q between 2D plot and fitting
180        if not hasattr(self.data,"data"):
181            self.qmin_x= numpy.min(self.data.x)
182            self.qmax_x= numpy.max(self.data.x)
183            self.num_points= len(self.data.x)
184        else:
185            # Reversed to the codes; Need to think  carefully about consistency in q between 2D plot and fitting
186            radius1= math.sqrt(math.pow(self.data.xmin, 2)+ math.pow(self.data.ymin, 2))
187            radius2= math.sqrt(math.pow(self.data.xmax, 2)+ math.pow(self.data.ymin, 2))
188            radius3= math.sqrt(math.pow(self.data.xmin, 2)+ math.pow(self.data.ymax, 2))
189            radius4= math.sqrt(math.pow(self.data.xmax, 2)+ math.pow(self.data.ymax, 2))
190           
191            self.qmin_x= 0
192            self.qmax_x= math.sqrt(math.pow(max(math.fabs(self.data.xmax),math.fabs(self.data.xmin)),2)
193                            +math.pow(max(math.fabs(self.data.ymax),math.fabs(self.data.ymin)),2))#self.data.xmax           
194       
195        self.num_points= 100
196        # The minimum fitting range
197        self.qmin    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
198        self.qmin.SetValue(str(format_number(self.qmin_x)))
199        self.qmin.SetToolTipString("Minimun value of x in linear scale.")
200        self.qmin.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
201        self.qmin.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
202        self.qmin.Enable()
203        #The maximum fitting range
204        self.qmax    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
205        self.qmax.SetValue(str(format_number(self.qmax_x)))
206        self.qmax.SetToolTipString("Maximum value of x in linear scale.")
207        self.qmax.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
208        self.qmax.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
209        self.qmax.Enable()
210        #The number of points to plots
211        self.npts    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
212        self.npts.SetValue(format_number(self.num_points))
213        self.npts.SetToolTipString("Number of point to plot.")
214        self.npts.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
215        self.npts.Bind(wx.EVT_TEXT_ENTER, self._onparamEnter)
216        self.npts.Disable()
217        self.npts.Hide()
218        ix = 0
219        iy = 1 
220        self.sizer9.Add(wx.StaticText(self, -1, 'Fitting Range'),(iy, ix),(1,1),\
221                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
222        ix += 1 
223        self.sizer9.Add(wx.StaticText(self, -1, 'Min'),(iy, ix),(1,1),\
224                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
225        ix += 1
226        self.sizer9.Add(wx.StaticText(self, -1, 'Max'),(iy, ix),(1,1),\
227                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
228        ix = 0
229        iy += 1
230        self.sizer9.Add(wx.StaticText(self, -1, 'Q range'),(iy, ix),(1,1),\
231                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
232        ix += 1
233        self.sizer9.Add(self.qmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
234        ix += 1
235        self.sizer9.Add(self.qmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
236        ix += 1
237        self.sizer9.Add(self.npts,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
238       
239        ix += 1
240        self.sizer9.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
241       
242        ix =0
243        iy+=1 
244        self.sizer9.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
245       
246        # Contains link between  model ,all its parameters, and panel organization
247        self.parameters=[]
248        # Contains list of parameters that cannot be fitted and reference to
249        #panel objects
250        self.fixed_param=[]
251        # Contains list of parameters with dispersity and reference to
252        #panel objects
253        self.fittable_param=[]
254        #list of dispersion paramaters
255        self.disp_list=[]
256        #contains link between a model and selected parameters to fit
257        self.param_toFit=[]
258        # model on which the fit would be performed
259        self.model=None
260       
261        self.back_up_model= None
262        #dictionary of model name and model class
263        self.model_list_box={}   
264                     
265        if self.model == None:
266            self.qmin.Disable()
267            self.qmax.Disable() 
268        else:
269            self.qmin.Enable()
270            self.qmax.Enable() 
271
272   
273        self.vbox.Layout()
274        self.vbox.Fit(self) 
275        self.SetSizer(self.vbox)
276        self.SetScrollbars(20,20,55,40)
277       
278        self.Centre()
279        self.Layout()
280        self.GrandParent.GetSizer().Layout()
281   
282    def compute_chisqr2D(self):
283        """
284            compute chi square given a model and data 2D and set the value
285            to the tcChi txtcrl
286        """
287        flag=self.checkFitRange()
288        res=[]
289        if flag== True:
290            try:
291                self.qmin_x = float(self.qmin.GetValue())
292                self.qmax_x = float(self.qmax.GetValue())
293                for i in range(len(self.data.x_bins)):
294                    for j in range(len(self.data.y_bins)):
295                        #Check the range containing data between self.qmin_x and self.qmax_x
296                        if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)>=math.pow(self.qmin_x,2):
297                            if math.pow(self.data.x_bins[i],2)+math.pow(self.data.y_bins[j],2)<=math.pow(self.qmax_x,2):
298                                chisqrji=(self.data.data[j][i]- self.model.runXY(\
299                                                                                    [self.data.y_bins[j],self.data.x_bins[i]]))\
300                                                                                    /self.data.err_data[j][i]
301                                #Vector containing residuals
302                                res.append( math.pow(chisqrji,2) )
303                # compute sum of residual
304                sum=0
305                for item in res:
306                    if numpy.isfinite(item):
307                        sum +=item
308                self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
309            except:
310                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
311                            "Chisqr cannot be compute: %s"% sys.exc_value))
312                return
313   
314       
315    def compute_chisqr(self):
316        """
317            compute chi square given a model and data 1D and set the value
318            to the tcChi txtcrl
319        """
320        flag=self.checkFitRange()
321        if flag== True:
322            try:
323                if hasattr(self.data,"data"):
324                    self.compute_chisqr2D()
325                    return
326                else:
327                    self.qmin_x = float(self.qmin.GetValue())
328                    self.qmax_x = float(self.qmax.GetValue())
329                    # return residuals within self.qmin_x and self.qmax_x
330                    x,y,dy = [numpy.asarray(v) for v in (self.data.x,self.data.y,self.data.dy)]
331                    if self.qmin_x==None and self.qmax_x==None: 
332                        fx =numpy.asarray([self.model.run(v) for v in x])
333                        temp=(y - fx)/dy
334                        res= temp*temp
335                    else:
336                        idx = (x>= self.qmin_x) & (x <=self.qmax_x)
337                        fx = numpy.asarray([self.model.run(item)for item in x[idx ]])
338                        temp=(y[idx] - fx)/dy[idx]
339                        res= temp*temp
340                    #sum of residuals
341                    sum=0
342                    for item in res:
343                        if numpy.isfinite(item):
344                            sum +=item
345                    self.tcChi.SetLabel(format_number(math.fabs(sum/ len(res))))
346            except:
347                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
348                            "Chisqr cannot be compute: %s"% sys.exc_value))
349                return 
350           
351    def _on_select_model(self,event):
352        """
353            react when a model is selected from page's combo box
354            post an event to its owner to draw an appropriate theory
355        """
356        self.btFit.SetFocus()
357        self.disable_disp.SetValue(True)
358        self.sizer8.Clear(True)
359        self.sizer7.Clear(True)       
360        self.vbox.Layout()
361        self.SetScrollbars(20,20,55,40)
362        self.Layout()
363        self.parent.GetSizer().Layout()
364
365        for item in self.model_list_box.itervalues():
366            name = item.__name__
367            if hasattr(item, "name"):
368                name = item.name
369           
370            if name == None:
371                self.qmin.Disable()
372                self.qmax.Disable() 
373            else:
374                self.qmin.Enable()
375                self.qmax.Enable() 
376           
377            if name ==event.GetString():
378                try:
379                    self.model=item()
380                    self.back_up_model= self.model.clone()
381                    evt = ModelEventbox(model=self.model,name=name)
382                    wx.PostEvent(self.event_owner, evt)
383                    self.text1_1.Show()
384                    self.compute_chisqr()
385                    self.tcChi.Show()
386                except:
387                    raise #ValueError,"model.name is not equal to model class name"
388                break 
389           
390                 
391    def onFit(self,event):
392        """ signal for fitting"""
393         
394        flag=self.checkFitRange()
395        self.set_manager(self.manager)
396     
397        self.qmin_x=float(self.qmin.GetValue())
398        self.qmax_x =float( self.qmax.GetValue())
399        if len(self.param_toFit) >0 and flag==True:
400            self.manager.schedule_for_fit( value=1,fitproblem =None) 
401            if hasattr(self.data, "data"):
402                #single fit for Data2D
403                self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x,
404                                            ymin=self.data.ymin, ymax=self.data.ymax,
405                                            xmin=self.data.xmin,xmax=self.data.xmax)
406            else:
407                #single fit for Data1D
408                self.manager._on_single_fit(qmin=self.qmin_x,qmax=self.qmax_x)
409               
410            self.vbox.Layout()
411            self.SetScrollbars(20,20,55,40)
412            self.Layout()
413            self.parent.GetSizer().Layout()
414        else:
415            wx.PostEvent(self.parent.parent, StatusEvent(status=\
416                            "Select at least one parameter to fit "))
417 
418   
419    def _onTextEnter(self,event):
420        """
421            set a flag to determine if the fitting range entered by the user is valid
422        """
423     
424        try:
425            flag=self.checkFitRange()
426            if flag==True and self.model!=None:
427                self.manager.redraw_model(float(self.xmin.GetValue())\
428                                               ,float(self.xmax.GetValue()))
429        except:
430
431            wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
432                            "Drawing  Error:wrong value entered %s"% sys.exc_value))
433       
434   
435   
436    def get_param_list(self):
437        """
438            @return self.param_toFit: list containing  references to TextCtrl
439            checked.Theses TextCtrl will allow reference to parameters to fit.
440            @raise: if return an empty list of parameter fit will nnote work
441            properly so raise ValueError,"missing parameter to fit"
442        """
443        if self.param_toFit !=[]:
444            return self.param_toFit
445        else:
446            raise ValueError,"missing parameter to fit"
447       
448   
449    def _onparamEnter(self,event):
450        """
451            when enter value on panel redraw model according to changed
452        """
453        self.set_model()
454        try:
455            self.compute_chisqr()
456        except:
457            pass
458       
459    def set_model(self): 
460        """
461            Hide panel object related to the previous fit and set
462            values entered by the used inside the model
463        """
464        if len(self.parameters) !=0 and self.model !=None:
465            # Flag to register when a parameter has changed.
466            for item in self.parameters:
467                try:
468                    self.text2_3.Hide()
469                    item[2].Hide()
470                    item[3].Clear()
471                    item[3].Hide()
472                except:
473                    pass
474        self.set_model_parameter()
475       
476   
477    def select_all_param(self,event): 
478        """
479             set to true or false all checkBox given the main checkbox value cb1
480        """
481        self.select_all_param_helper()
482               
483               
484    def select_param(self,event):
485        """
486            Select TextCtrl  checked for fitting purpose and stores them
487            in  self.param_toFit=[] list
488        """
489        self.param_toFit=[]
490        for item in self.parameters:
491            #Select parameters to fit for list of primary parameters
492            if item[0].GetValue()==True:
493                list= [item[0],item[1],item[2],item[3]]
494                if not (list  in self.param_toFit):
495                    self.param_toFit.append(list ) 
496            else:
497                #remove parameters from the fitting list
498                if item in self.param_toFit:
499                    self.param_toFit.remove(item)
500        #Select parameters to fit for list of fittable parameters with dispersion         
501        for item in self.fittable_param:
502            if item[0].GetValue()==True:
503                list= [item[0],item[1],item[2],item[3]]
504                if not (list  in self.param_toFit):
505                    self.param_toFit.append(list ) 
506            else:
507                #remove parameters from the fitting list
508                if item in self.param_toFit:
509                    self.param_toFit.remove(item)           
510        #Set the value of checkbox that selected every checkbox or not           
511        if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit):
512            self.cb1.SetValue(True)
513        else:
514            self.cb1.SetValue(False)
515       
516       
517    def onsetValues(self,chisqr, out,cov):
518        """
519            Build the panel from the fit result
520            @param chisqr:Value of the goodness of fit metric
521            @param out:list of parameter with the best value found during fitting
522            @param cov:Covariance matrix
523       
524        """
525        self.tcChi.SetLabel(format_number(chisqr))
526        params = {}
527        is_modified = False
528        has_error = False
529        #set the panel when fit result are float not list
530        if out.__class__==numpy.float64:
531            self.param_toFit[0][1].SetValue(format_number(out))
532            self.param_toFit[0][1].Refresh()
533            if cov !=None :
534                self.text2_3.Show()
535                self.param_toFit[0][2].Show()
536                self.param_toFit[0][3].Clear()
537                self.param_toFit[0][3].SetValue(format_number(cov[0]))
538                self.param_toFit[0][3].Show()
539        else:
540            i=0
541            j=0
542            #Set the panel when fit result are list
543            for item in self.param_toFit:
544                if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out):
545                    item[1].SetValue(format_number(self.model.getParam(item[0].GetLabelText())))
546                    item[1].Refresh()
547                if(cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov):
548                    self.text2_3.Show() 
549                    item[2].Show()
550                    item[3].Clear()
551                    for j in range(len(out)):
552                        if out[j]==self.model.getParam(item[0].GetLabelText()):
553                            break
554                    item[3].SetValue(format_number(cov[j]))
555                    item[3].Show()   
556                i+=1
557       
558        self.vbox.Layout()
559        self.SetScrollbars(20,20,55,40)
560        self.Layout()
561        self.GrandParent.GetSizer().Layout()
562       
563       
564    def onSmear(self, event):
565        """
566            Create a smear object that will change the way residuals
567            are compute when fitting
568        """
569        smear =None
570        msg=""
571        if self.enable_smearer.GetValue():
572            from DataLoader.qsmearing import smear_selection
573            smear =smear_selection( self.data )
574            if hasattr(self.data,"dxl"):
575                msg= ": Resolution smearing parameters"
576            if hasattr(self.data,"dxw"):
577                msg= ": Slit smearing parameters"
578            if smear ==None:
579                wx.PostEvent(self.manager.parent, StatusEvent(status=\
580                            "Data contains no smearing information"))
581            else:
582                wx.PostEvent(self.manager.parent, StatusEvent(status=\
583                            "Data contains smearing information %s"%msg))
584        self.manager.set_smearer(smear)   
585           
586             
587       
588       
Note: See TracBrowser for help on using the repository browser.