source: sasview/sansview/perspectives/fitting/fitpage2D.py @ 44bbf6a

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

panel 2d changed for dispersion display

  • Property mode set to 100644
File size: 24.1 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.image[j][i]- self.model.runXY(\
229                                 [self.data.x_bins[j],self.data.y_bins[i]]))\
230                                    /self.data.err_image[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       
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   
365        self.sizer2.Clear(True)
366        self.parameters = []
367        self.param_toFit=[]
368        self.model = model
369        keys = self.model.getParamList()
370        keys.sort()
371        disp_list=self.model.getDispParamList()
372        disp_list.sort()
373        iy = 1
374        ix = 0
375        self.cb1 = wx.CheckBox(self, -1,'Parameters', (10, 10))
376        wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param)
377        self.sizer2.Add(self.cb1,(iy, ix),(1,1),\
378                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
379        ix +=1
380        self.text2_2 = wx.StaticText(self, -1, 'Values')
381        self.sizer2.Add(self.text2_2,(iy, ix),(1,1),\
382                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
383        ix +=2
384        self.text2_3 = wx.StaticText(self, -1, 'Errors')
385        self.sizer2.Add(self.text2_3,(iy, ix),(1,1),\
386                            wx.EXPAND|wx.ADJUST_MINSIZE, 0)
387        self.text2_3.Hide() 
388        ix +=1
389        self.text2_4 = wx.StaticText(self, -1, 'Units')
390        self.sizer2.Add(self.text2_4,(iy, ix),(1,1),\
391                            wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
392        self.text2_4.Hide()
393        for item in keys:
394            if not item in disp_list:
395                iy += 1
396                ix = 0
397   
398                cb = wx.CheckBox(self, -1, item, (10, 10))
399                cb.SetValue(False)
400                self.sizer2.Add( cb,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
401                wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param)
402               
403                ix += 1
404                value= self.model.getParam(item)
405                ctl1 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
406                ctl1.SetValue(str (format_number(value)))
407                ctl1.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
408                ctl1.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)
409                self.sizer2.Add(ctl1, (iy,ix),(1,1), wx.EXPAND)
410                ix += 1
411                text2=wx.StaticText(self, -1, '+/-')
412                self.sizer2.Add(text2,(iy, ix),(1,1),\
413                                wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
414                text2.Hide() 
415                ix += 1
416                ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
417                self.sizer2.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
418                ctl2.Hide()
419                ix +=1
420                #save data
421                self.parameters.append([cb,ctl1,text2,ctl2])
422                # Units
423                try:
424                    units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT)
425                except:
426                    units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT)
427                 
428                self.sizer2.Add(units, (iy,ix),(1,1),  wx.EXPAND|wx.ADJUST_MINSIZE, 0)
429        iy+=1
430        self.sizer2.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
431        ix= 0
432        iy=1
433        if len(disp_list)>0:
434            disp = wx.StaticText(self, -1, 'Dispersion')
435            self.sizer5.Add(disp,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
436            ix += 1 
437            values = wx.StaticText(self, -1, 'Values')
438            self.sizer5.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
439            #ix += 1
440            #disps = wx.StaticText(self, -1, 'Disp')
441            #self.sizer5.Add(disps,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
442            #ix += 1
443            #npts = wx.StaticText(self, -1, 'npts')
444            #self.sizer5.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
445            iy+=1
446           
447        for item in disp_list:
448            ix = 0
449            cb2 = wx.CheckBox(self, -1, item, (10, 10))
450            cb2.SetValue(False)
451            self.sizer5.Add( cb2,( iy, ix),(1,1),  wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
452            wx.EVT_CHECKBOX(self, cb2.GetId(), self.select_param)
453           
454            ix += 1
455            value= self.model.getParam(item)
456            ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER)
457            ctl2.SetValue(str (format_number(value)))
458            ctl2.Bind(wx.EVT_KILL_FOCUS, self._onparamEnter)
459            ctl2.Bind(wx.EVT_TEXT_ENTER,self._onparamEnter)
460            self.sizer5.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
461            iy += 1
462        #Display units text on panel
463        for item in keys:   
464            if self.model.details[item][0]!='':
465                self.text2_4.Show()
466                break
467            else:
468                self.text2_4.Hide()
469        #Disable or enable fit button
470       
471        if not (len(self.param_toFit ) >0):
472            self.xmin.Disable()
473            self.xmax.Disable()
474            self.ymin.Disable()
475            self.ymax.Disable()
476        else:
477            self.xmin.Enable()
478            self.xmax.Enable()
479            self.ymin.Enable()
480            self.ymax.Enable()
481     
482        self.compute_chisqr()
483        self.vbox.Layout()
484        self.GrandParent.GetSizer().Layout()
485       
486   
487       
488    def _onparamEnter(self,event):
489        """
490            when enter value on panel redraw model according to changed
491        """
492        self.set_model_parameter()
493        self.compute_chisqr()
494     
495    def set_model_parameter(self):
496        """
497            this method redraws the model according to parameters values changes
498            and the reset model according to paramaters changes
499        """
500        if len(self.parameters) !=0 and self.model !=None:
501            for item in self.parameters:
502                try:
503                     name=str(item[0].GetLabelText())
504                     value= float(item[1].GetValue())
505                     self.model.setParam(name,value) 
506                except:
507                     wx.PostEvent(self.parent.GrandParent, StatusEvent(status=\
508                            "Drawing  Error:wrong value entered : %s"% sys.exc_value))
509            self.manager.redraw_model(float(self.xmin.GetValue())\
510                                               ,float(self.xmax.GetValue()))     
511                     
512    def select_all_param(self,event): 
513        """
514             set to true or false all checkBox given the main checkbox value cb1
515        """
516        self.param_toFit=[]
517        if  self.parameters !=[]:
518            if  self.cb1.GetValue()==True:
519                for item in self.parameters:
520                    item[0].SetValue(True)
521                    list= [item[0],item[1],item[2],item[3]]
522                    self.param_toFit.append(list )
523               
524                if not (len(self.param_toFit ) >0):
525                    self.xmin.Disable()
526                    self.xmax.Disable()
527                    self.ymin.Disable()
528                    self.ymax.Disable()
529                else:
530                    self.xmin.Enable()
531                    self.xmax.Enable()
532                    self.ymin.Enable()
533                    self.ymax.Enable()
534            else:
535                for item in self.parameters:
536                    item[0].SetValue(False)
537                self.param_toFit=[]
538             
539                self.xmin.Disable()
540                self.xmax.Disable()
541                self.ymin.Disable()
542                self.ymax.Disable()
543               
544               
545    def select_param(self,event):
546        """
547            Select TextCtrl  checked for fitting purpose and stores them
548            in  self.param_toFit=[] list
549        """
550        self.param_toFit=[]
551        for item in self.parameters:
552            if item[0].GetValue()==True:
553                list= [item[0],item[1],item[2],item[3]]
554                self.param_toFit.append(list ) 
555            else:
556                if item in self.param_toFit:
557                    self.param_toFit.remove(item)
558        if len(self.parameters)==len(self.param_toFit):
559            self.cb1.SetValue(True)
560        else:
561            self.cb1.SetValue(False)
562       
563        if not (len(self.param_toFit ) >0):
564            self.xmin.Disable()
565            self.xmax.Disable()
566            self.ymin.Disable()
567            self.ymax.Disable()
568        else:
569            self.xmin.Enable()
570            self.xmax.Enable()
571            self.ymin.Enable()
572            self.ymax.Enable()
573     
574   
575       
576 
577    def onsetValues(self,chisqr, out,cov):
578        """
579            Build the panel from the fit result
580            @param chisqr:Value of the goodness of fit metric
581            @param out:list of parameter with the best value found during fitting
582            @param cov:Covariance matrix
583       
584        """
585        #print "fitting : onsetvalues out",out
586        self.tcChi.Clear()
587        self.tcChi.SetValue(format_number(chisqr))
588        params = {}
589        is_modified = False
590        has_error = False
591        if out.__class__==numpy.float64:
592            self.param_toFit[0][1].SetValue(format_number(out))
593            self.param_toFit[0][1].Refresh()
594            if cov !=None :
595                self.text2_3.Show()
596                self.param_toFit[0][2].Show()
597                self.param_toFit[0][3].Clear()
598                self.param_toFit[0][3].SetValue(format_number(cov[0]))
599                self.param_toFit[0][3].Show()
600        #out is a list : set parameters and errors in TextCtrl
601        else:
602            i=0
603            #print "fitpage: list param  model",list
604            #for item in self.param_toFit:
605            #    print "fitpage: list display",item[0].GetLabelText()
606            for item in self.param_toFit:
607                if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out):
608                    #item[1].SetValue(format_number(out[i]))
609                    item[1].SetValue(format_number(self.model.getParam(item[0].GetLabelText())))
610                    item[1].Refresh() 
611                if (cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov):
612                    self.text2_3.Show() 
613                    item[2].Show()
614                    item[3].Clear()
615                    item[3].SetValue(format_number(cov[i]))
616                    item[3].Show()   
617                i+=1
618       
619        self.vbox.Layout()
620        self.GrandParent.GetSizer().Layout()
621   
Note: See TracBrowser for help on using the repository browser.