source: sasview/sansview/perspectives/fitting/fitpage2D.py @ 0550752

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 0550752 was 57668f8, checked in by Gervaise Alina <gervyh@…>, 16 years ago

working on sector averaging

  • Property mode set to 100644
File size: 24.0 KB
Line 
1import sys
2import wx
3import wx.lib
4import numpy,math
5import copy
6
7from sans.guicomm.events import StatusEvent   
8(ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent()
9_BOX_WIDTH = 80
10
11def format_number(value, high=False):
12    """
13        Return a float in a standardized, human-readable formatted string
14    """
15    try: 
16        value = float(value)
17    except:
18        print "returning 0"
19        return "0"
20   
21    if high:
22        return "%-6.4g" % value
23    else:
24        return "%-5.3g" % value
25
26   
27class FitPage2D(wx.Panel):
28    """
29        FitPanel class contains fields allowing to display results when
30        fitting  a model and one data
31        @note: For Fit to be performed the user should check at least one parameter
32        on fit Panel window.
33 
34    """
35    ## Internal name for the AUI manager
36    window_name = "Fit page"
37    ## Title to appear on top of the window
38    window_caption = "Fit Page"
39   
40   
41    def __init__(self, parent,data, *args, **kwargs):
42        wx.Panel.__init__(self, parent, *args, **kwargs)
43        """
44            Initialization of the Panel
45        """
46        self.manager = None
47        self.parent  = parent
48        self.event_owner=None
49        #panel interface
50        self.vbox  = wx.BoxSizer(wx.VERTICAL)
51        self.sizer5 = wx.GridBagSizer(5,5)
52        self.sizer4 = wx.GridBagSizer(5,5)
53        self.sizer3 = wx.GridBagSizer(5,5)
54        self.sizer2 = wx.GridBagSizer(5,5)
55        self.sizer1 = wx.GridBagSizer(5,5)
56        #self.DataSource      = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
57        #self.DataSource.SetToolTipString("name of data to fit")
58        #self.DataSource.SetValue(str(data.name))
59        #self.DataSource.Disable()
60        self.DataSource  =wx.StaticText(self, -1,str(data.name))
61        self.modelbox = wx.ComboBox(self, -1)
62        id = wx.NewId()
63        self.btFit =wx.Button(self,id,'Fit')
64        self.btFit.Bind(wx.EVT_BUTTON, self.onFit,id=id)
65        self.btFit.SetToolTipString("Perform fit.")
66        self.static_line_1 = wx.StaticLine(self, -1)
67       
68        self.vbox.Add(self.sizer3)
69        self.vbox.Add(self.sizer2)
70        self.vbox.Add(self.static_line_1, 0, wx.EXPAND, 0)
71        self.vbox.Add(self.sizer5)
72        self.vbox.Add(self.sizer4)
73        self.vbox.Add(self.sizer1)
74       
75        id = wx.NewId()
76        self.btClose =wx.Button(self,id,'Close')
77        self.btClose.Bind(wx.EVT_BUTTON, self.onClose,id=id)
78        self.btClose.SetToolTipString("Close page.")
79        ix = 0
80        iy = 1
81        self.sizer3.Add(wx.StaticText(self, -1, 'Data Source'),(iy,ix),\
82                 (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
83        ix += 1
84        self.sizer3.Add(self.DataSource,(iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
85        ix += 1
86        self.sizer3.Add((20,20),(iy,ix),(1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE,0)
87        ix = 0
88        iy += 1
89        self.sizer3.Add(wx.StaticText(self,-1,'Model'),(iy,ix),(1,1)\
90                  , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
91        ix += 1
92        self.sizer3.Add(self.modelbox,(iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
93       
94        ix = 0
95        iy = 1
96        #set maximum range for x in linear scale
97        self.text4_3 = wx.StaticText(self, -1, 'Maximum Data\n Range (Linear)', style=wx.ALIGN_LEFT)
98        self.sizer4.Add(self.text4_3,(iy,ix),(1,1),\
99                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
100        ix += 1
101        self.text4_1 = wx.StaticText(self, -1, 'Min')
102        self.sizer4.Add(self.text4_1,(iy, ix),(1,1),\
103                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
104        #self.text4_1.Hide()
105        ix += 2
106        self.text4_2 = wx.StaticText(self, -1, 'Max')
107        self.sizer4.Add(self.text4_2,(iy, ix),(1,1),\
108                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
109        #self.text4_2.Hide()
110       
111        #self.text4_3.Hide()
112        ix = 0
113        iy += 1
114        self.text4_4 = wx.StaticText(self, -1, 'x range')
115        self.sizer4.Add(self.text4_4,(iy, ix),(1,1),\
116                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
117        ix += 1
118        self.xmin    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
119        self.xmin.SetValue(format_number(data.xmin))
120        self.xmin.SetToolTipString("Minimun value of x in linear scale.")
121        self.sizer4.Add(self.xmin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
122        self.xmin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
123        self.xmin.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)
124       
125        ix += 2
126        self.xmax    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
127        self.xmax.SetValue(format_number(data.xmax))
128        self.xmax.SetToolTipString("Maximum value of x in linear scale.")
129        self.sizer4.Add(self.xmax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
130        self.xmax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
131        self.xmax.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)
132       
133        iy +=1
134        ix = 0
135        self.text4_5 = wx.StaticText(self, -1, 'y range')
136        self.sizer4.Add(self.text4_5,(iy, ix),(1,1),\
137                            wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
138        ix += 1
139        self.ymin    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
140        self.ymin.SetValue(format_number(data.ymin))
141        self.ymin.SetToolTipString("Minimun value of y in linear scale.")
142        self.sizer4.Add(self.ymin,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
143        self.ymin.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
144        self.ymin.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)
145       
146        ix += 2
147        self.ymax    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
148        self.ymax.SetValue(format_number(data.ymax))
149        self.ymax.SetToolTipString("Maximum value of y in linear scale.")
150        self.sizer4.Add(self.ymax,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
151        self.ymax.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter)
152        self.ymax.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter)
153       
154        #Set chisqr  result into TextCtrl
155        ix = 0
156        iy = 1
157        self.text1_1 = wx.StaticText(self, -1, 'Chi2/dof', style=wx.ALIGN_LEFT)
158        self.sizer1.Add(self.text1_1,(iy,ix),(1,1),\
159                   wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
160        ix += 1
161        self.tcChi    = wx.TextCtrl(self, -1,size=(_BOX_WIDTH,20))
162        self.tcChi.SetToolTipString("Chi^2 over degrees of freedom.")
163        self.sizer1.Add(self.tcChi,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
164        ix +=2
165        self.sizer1.Add(self.btFit,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
166        ix+= 1
167        self.sizer1.Add( self.btClose,(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
168        ix= 1
169        iy+=1
170        self.sizer1.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)
171        # contains link between  model ,all its parameters, and panel organization
172        self.parameters=[]
173        #contains link between a model and selected parameters to fit
174        self.param_toFit=[]
175        # model on which the fit would be performed
176        self.model=None
177        # preview selected model name
178       
179       
180        #dictionary of model name and model class
181        self.model_list_box={}
182       
183        self.data = data
184        self.vbox.Layout()
185        self.vbox.Fit(self) 
186        self.SetSizer(self.vbox)
187        self.Centre()
188       
189       
190    def set_owner(self,owner):
191        """
192            set owner of fitpage
193            @param owner: the class responsible of plotting
194        """
195        self.event_owner=owner   
196   
197 
198    def set_manager(self, manager):
199        """
200             set panel manager
201             @param manager: instance of plugin fitting
202        """
203        self.manager = manager
204 
205       
206    def onClose(self,event):
207        """ close the page associated with this panel"""
208        self.GrandParent.onClose()
209       
210       
211    def compute_chisqr(self):
212        """ @param fn: function that return model value
213            @return residuals
214        """
215        flag=self.checkFitRange()
216        res=[]
217        if flag== True:
218            try:
219                xmin = float(self.xmin.GetValue())
220                xmax = float(self.xmax.GetValue())
221                ymin = float(self.ymin.GetValue())
222                ymax = float(self.ymax.GetValue())
223               
224                for i in range(len(self.data.y_bins)):
225                    if self.data.y_bins[i]>= ymin and self.data.y_bins[i]<= ymax:
226                        for j in range(len(self.data.x_bins)):
227                            if self.data.x_bins[j]>= xmin and self.data.x_bins[j]<= xmax:
228                                res.append( (self.data.data[j][i]- self.model.runXY(\
229                                 [self.data.x_bins[j],self.data.y_bins[i]]))\
230                                    /self.data.err_data[j][i] )
231                sum=0
232               
233                for item in res:
234                    if numpy.isfinite(item):
235                        sum +=item
236                self.tcChi.SetValue(format_number(math.fabs(sum)))
237            except:
238                wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
239                            "Chisqr cannot be compute: %s"% sys.exc_value))
240           
241           
242    def onFit(self,event):
243        """ signal for fitting"""
244        flag=self.checkFitRange()
245        self.set_manager(self.manager)
246     
247        qmin=float(self.xmin.GetValue())
248        qmax =float( self.xmax.GetValue())
249        if len(self.param_toFit) >0 and flag==True:
250            self.manager.schedule_for_fit( value=1,fitproblem =None) 
251            self.manager._on_single_fit(qmin=qmin,qmax=qmax)
252        else:
253            wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
254                            "Select at least on parameter to fit "))
255    def populate_box(self, dict):
256        """
257            Populate each combox box of each page
258            @param page: the page to populate
259        """
260        id=0
261        self.model_list_box=dict
262        list_name=[]
263        for item in  self.model_list_box.itervalues():
264            name = item.__name__
265            if hasattr(item, "name"):
266                name = item.name
267            list_name.append(name)
268        list_name.sort()   
269        for name in list_name:
270            self.modelbox.Insert(name,int(id))
271            id+=1
272        wx.EVT_COMBOBOX(self.modelbox,-1, self._on_select_model) 
273        return 0
274   
275   
276    def _on_select_model(self,event):
277        """
278            react when a model is selected from page's combo box
279            post an event to its owner to draw an appropriate theory
280        """
281        self.btFit.SetFocus()
282        for item in self.model_list_box.itervalues():
283            name = item.__name__
284            if hasattr(item, "name"):
285                name = item.name
286            #print "fitpage: _on_select_model model name",name ,event.GetString()
287            if name ==event.GetString():
288                try:
289                    evt = ModelEventbox(model=item(),name=name)
290                    wx.PostEvent(self.event_owner, evt)
291                except:
292                    raise #ValueError,"model.name is not equal to model class name"
293                break
294   
295    def _onTextEnter(self,event):
296        """
297            set a flag to determine if the fitting range entered by the user is valid
298        """
299     
300        try:
301            flag=self.checkFitRange()
302            if flag==True and self.model!=None:
303                print"fit page",self.xmin.GetValue(),self.xmax.GetValue()
304                self.manager.redraw_model(float(self.xmin.GetValue())\
305                                               ,float(self.xmax.GetValue()))
306        except:
307
308            wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
309                            "Drawing  Error:wrong value entered %s"% sys.exc_value))
310       
311    def checkFitRange(self):
312        """
313            Check the validity of fitting range
314            @note: xmin should always be less than xmax or else each control box
315            background is colored in pink.
316        """
317       
318        flag = True
319        valueMin = self.xmin.GetValue()
320        valueMax = self.xmax.GetValue()
321        # Check for possible values entered
322        print "fitpage: checkfitrange:",valueMin,valueMax
323        try:
324            if (float(valueMax)> float(valueMin)):
325                self.xmax.SetBackgroundColour(wx.WHITE)
326                self.xmin.SetBackgroundColour(wx.WHITE)
327            else:
328                flag = False
329                self.xmin.SetBackgroundColour("pink")
330                self.xmax.SetBackgroundColour("pink")     
331        except:
332            flag = False
333            self.xmin.SetBackgroundColour("pink")
334            self.xmax.SetBackgroundColour("pink")
335           
336        self.xmin.Refresh()
337        self.xmax.Refresh()
338        return flag
339   
340 
341    def get_model_box(self): 
342        """ return reference to combox box self.model"""
343        return self.modelbox
344
345   
346    def get_param_list(self):
347        """
348            @return self.param_toFit: list containing  references to TextCtrl
349            checked.Theses TextCtrl will allow reference to parameters to fit.
350            @raise: if return an empty list of parameter fit will nnote work
351            properly so raise ValueError,"missing parameter to fit"
352        """
353        if self.param_toFit !=[]:
354            return self.param_toFit
355        else:
356            raise ValueError,"missing parameter to fit"
357       
358       
359    def set_panel(self,model):
360        """
361            Build the panel from the model content
362            @param model: the model selected in combo box for fitting purpose
363        """
364        self.sizer2.Clear(True)
365        self.sizer5.Clear(True)
366        self.parameters = []
367        self.param_toFit=[]
368        self.model = model
369        keys = self.model.getParamList()
370        #print "fitpage1D : dispersion list",self.model.getDispParamList()
371        keys.sort()
372        disp_list=self.model.getDispParamList()
373        ip=0
374        iq=1
375        if len(disp_list)>0:
376            disp = wx.StaticText(self, -1, 'Dispersion')
377            self.sizer5.Add(disp,( iq, ip),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
378            ip += 1 
379            values = wx.StaticText(self, -1, 'Values')
380            self.sizer5.Add(values,( iq, ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
381           
382        disp_list.sort()
383        iy = 1
384        ix = 0
385        self.cb1 = wx.CheckBox(self, -1,'Parameters', (10, 10))
386        wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param)
387        self.sizer2.Add(self.cb1,(iy, ix),(1,1),\
388                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
389        ix +=1
390        self.text2_2 = wx.StaticText(self, -1, 'Values')
391        self.sizer2.Add(self.text2_2,(iy, ix),(1,1),\
392                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
393        ix +=2
394        self.text2_3 = wx.StaticText(self, -1, 'Errors')
395        self.sizer2.Add(self.text2_3,(iy, ix),(1,1),\
396                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
397        self.text2_3.Hide() 
398        ix +=1
399        self.text2_4 = wx.StaticText(self, -1, 'Units')
400        self.sizer2.Add(self.text2_4,(iy, ix),(1,1),\
401                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
402        self.text2_4.Hide()
403       
404        for item in keys:
405            if not item in disp_list:
406                iy += 1
407                ix = 0
408   
409                cb = wx.CheckBox(self, -1, item, (10, 10))
410                cb.SetValue(False)
411                self.sizer2.Add( cb,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
412                wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param)
413               
414                ix += 1
415                value= self.model.getParam(item)
416                ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
417                ctl1.SetValue(str (format_number(value)))
418                ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
419                ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)
420                self.sizer2.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)
421                ix += 1
422                text2=wx.StaticText(self, -1, '+/-')
423                self.sizer2.Add(text2,(iy, ix),(1,1),\
424                                wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
425                text2.Hide() 
426                ix += 1
427                ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
428                self.sizer2.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
429                ctl2.Hide()
430                ix +=1
431                # Units
432                try:
433                    units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT)
434                except:
435                    units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT)
436                self.sizer2.Add(units, (iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
437            else:
438                ip = 0
439                iq += 1
440                cb = wx.CheckBox(self, -1, item, (10, 10))
441                cb.SetValue(False)
442                self.sizer5.Add( cb,( iq, ip),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
443                wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param)
444               
445                ip += 1
446                value= self.model.getParam(item)
447                ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
448                ctl1.SetValue(str (format_number(value)))
449                ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
450                ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)
451                self.sizer5.Add(ctl1, (iq,ip),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
452               
453            #save data
454            self.parameters.append([cb,ctl1,text2,ctl2])
455               
456        iy+=1
457        self.sizer2.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
458       
459        #Display units text on panel
460        for item in keys:   
461            if self.model.details[item][0]!='':
462                self.text2_4.Show()
463                break
464            else:
465                self.text2_4.Hide()
466        #Disable or enable fit button
467       
468        if not (len(self.param_toFit ) >0):
469            self.xmin.Disable()
470            self.xmax.Disable()
471            self.ymin.Disable()
472            self.ymax.Disable()
473        else:
474            self.xmin.Enable()
475            self.xmax.Enable()
476            self.ymin.Enable()
477            self.ymax.Enable()
478     
479        self.compute_chisqr()
480        self.vbox.Layout()
481        self.GrandParent.GetSizer().Layout()
482       
483   
484       
485    def _onparamEnter(self,event):
486        """
487            when enter value on panel redraw model according to changed
488        """
489        self.set_model_parameter()
490        self.compute_chisqr()
491     
492    def set_model_parameter(self):
493        """
494            this method redraws the model according to parameters values changes
495            and the reset model according to paramaters changes
496        """
497        if len(self.parameters) !=0 and self.model !=None:
498            for item in self.parameters:
499                try:
500                     name=str(item[0].GetLabelText())
501                     value= float(item[1].GetValue())
502                     self.model.setParam(name,value) 
503                except:
504                     wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
505                            "Drawing  Error:wrong value entered : %s"% sys.exc_value))
506            self.manager.redraw_model(float(self.xmin.GetValue())\
507                                               ,float(self.xmax.GetValue()))     
508                     
509    def select_all_param(self,event): 
510        """
511             set to true or false all checkBox given the main checkbox value cb1
512        """
513        self.param_toFit=[]
514        if  self.parameters !=[]:
515            if  self.cb1.GetValue()==True:
516                for item in self.parameters:
517                    item[0].SetValue(True)
518                    list= [item[0],item[1],item[2],item[3]]
519                    self.param_toFit.append(list )
520               
521                if not (len(self.param_toFit ) >0):
522                    self.xmin.Disable()
523                    self.xmax.Disable()
524                    self.ymin.Disable()
525                    self.ymax.Disable()
526                else:
527                    self.xmin.Enable()
528                    self.xmax.Enable()
529                    self.ymin.Enable()
530                    self.ymax.Enable()
531            else:
532                for item in self.parameters:
533                    item[0].SetValue(False)
534                self.param_toFit=[]
535             
536                self.xmin.Disable()
537                self.xmax.Disable()
538                self.ymin.Disable()
539                self.ymax.Disable()
540               
541               
542    def select_param(self,event):
543        """
544            Select TextCtrl  checked for fitting purpose and stores them
545            in  self.param_toFit=[] list
546        """
547        self.param_toFit=[]
548        for item in self.parameters:
549            if item[0].GetValue()==True:
550                list= [item[0],item[1],item[2],item[3]]
551                self.param_toFit.append(list ) 
552            else:
553                if item in self.param_toFit:
554                    self.param_toFit.remove(item)
555        if len(self.parameters)==len(self.param_toFit):
556            self.cb1.SetValue(True)
557        else:
558            self.cb1.SetValue(False)
559       
560        if not (len(self.param_toFit ) >0):
561            self.xmin.Disable()
562            self.xmax.Disable()
563            self.ymin.Disable()
564            self.ymax.Disable()
565        else:
566            self.xmin.Enable()
567            self.xmax.Enable()
568            self.ymin.Enable()
569            self.ymax.Enable()
570     
571   
572       
573 
574    def onsetValues(self,chisqr, out,cov):
575        """
576            Build the panel from the fit result
577            @param chisqr:Value of the goodness of fit metric
578            @param out:list of parameter with the best value found during fitting
579            @param cov:Covariance matrix
580       
581        """
582        #print "fitting : onsetvalues out",out
583        self.tcChi.Clear()
584        self.tcChi.SetValue(format_number(chisqr))
585        params = {}
586        is_modified = False
587        has_error = False
588        if out.__class__==numpy.float64:
589            self.param_toFit[0][1].SetValue(format_number(out))
590            self.param_toFit[0][1].Refresh()
591            if cov !=None :
592                self.text2_3.Show()
593                self.param_toFit[0][2].Show()
594                self.param_toFit[0][3].Clear()
595                self.param_toFit[0][3].SetValue(format_number(cov[0]))
596                self.param_toFit[0][3].Show()
597        #out is a list : set parameters and errors in TextCtrl
598        else:
599            i=0
600            #print "fitpage: list param  model",list
601            #for item in self.param_toFit:
602            #    print "fitpage: list display",item[0].GetLabelText()
603            for item in self.param_toFit:
604                if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out):
605                    #item[1].SetValue(format_number(out[i]))
606                    item[1].SetValue(format_number(self.model.getParam(item[0].GetLabelText())))
607                    item[1].Refresh() 
608                if (cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov):
609                    self.text2_3.Show() 
610                    item[2].Show()
611                    item[3].Clear()
612                    item[3].SetValue(format_number(cov[i]))
613                    item[3].Show()   
614                i+=1
615       
616        self.vbox.Layout()
617        self.GrandParent.GetSizer().Layout()
618   
Note: See TracBrowser for help on using the repository browser.