source: sasview/sansview/perspectives/fitting/fitpage1D.py @ 07a93a1

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 07a93a1 was 07a93a1, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

sansview: fixed problem with switching back and forth between dispersity and no dispersity

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