1 | |
---|
2 | |
---|
3 | import sys |
---|
4 | import wx |
---|
5 | import wx.lib.newevent |
---|
6 | import numpy |
---|
7 | import copy |
---|
8 | import math |
---|
9 | from sans.models.dispersion_models import ArrayDispersion, GaussianDispersion |
---|
10 | |
---|
11 | from sans.guicomm.events import StatusEvent |
---|
12 | from sans.guiframe.utils import format_number,check_float |
---|
13 | |
---|
14 | ## event to post model to fit to fitting plugins |
---|
15 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
16 | |
---|
17 | ## event to know the selected fit engine |
---|
18 | (FitterTypeEvent, EVT_FITTER_TYPE) = wx.lib.newevent.NewEvent() |
---|
19 | (FitStopEvent, EVT_FIT_STOP) = wx.lib.newevent.NewEvent() |
---|
20 | _BOX_WIDTH = 76 |
---|
21 | |
---|
22 | import basepage |
---|
23 | from basepage import BasicPage |
---|
24 | from basepage import PageInfoEvent |
---|
25 | from DataLoader.qsmearing import smear_selection |
---|
26 | |
---|
27 | class FitPage(BasicPage): |
---|
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 | def __init__(self,parent, page_info): |
---|
36 | BasicPage.__init__(self, parent, page_info) |
---|
37 | """ |
---|
38 | Initialization of the Panel |
---|
39 | """ |
---|
40 | ## fit page does not content npts txtcrtl |
---|
41 | self.npts=None |
---|
42 | ## thread for compute Chisqr |
---|
43 | self.calc_Chisqr=None |
---|
44 | ## default fitengine type |
---|
45 | self.engine_type = None |
---|
46 | #self.smearer = None |
---|
47 | ## draw sizer |
---|
48 | self._fill_datainfo_sizer() |
---|
49 | |
---|
50 | self._fill_model_sizer( self.sizer1) |
---|
51 | |
---|
52 | self._fill_range_sizer() |
---|
53 | #self._on_select_model(event=None) |
---|
54 | if self.data !=None: |
---|
55 | self.smearer = smear_selection( self.data ) |
---|
56 | if self.smearer ==None: |
---|
57 | self.enable_smearer.Disable() |
---|
58 | self.disable_smearer.Disable() |
---|
59 | |
---|
60 | ## to update the panel according to the fit engine type selected |
---|
61 | self.Bind(EVT_FITTER_TYPE,self._on_engine_change) |
---|
62 | self.Bind(EVT_FIT_STOP,self._on_fit_complete) |
---|
63 | |
---|
64 | def _on_fit_complete(self, event): |
---|
65 | """ |
---|
66 | When fit is complete ,reset the fit button label. |
---|
67 | """ |
---|
68 | #self.btFit.SetLabel("Fit") |
---|
69 | #self.btFit.Unbind(event=wx.EVT_BUTTON, id=self.btFit.GetId()) |
---|
70 | #self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit,id=self.btFit.GetId()) |
---|
71 | pass |
---|
72 | |
---|
73 | |
---|
74 | def _on_engine_change(self, event): |
---|
75 | """ |
---|
76 | get an event containing the current name of the fit engine type |
---|
77 | @param event: FitterTypeEvent containing the name of the current engine |
---|
78 | """ |
---|
79 | self.engine_type = event.type |
---|
80 | |
---|
81 | if len(self.parameters)==0: |
---|
82 | return |
---|
83 | if event.type =="park": |
---|
84 | self.btFit.SetLabel("Fit") |
---|
85 | |
---|
86 | for item in self.parameters: |
---|
87 | if event.type =="scipy" : |
---|
88 | item[5].SetValue("") |
---|
89 | item[5].Hide() |
---|
90 | item[6].SetValue("") |
---|
91 | item[6].Hide() |
---|
92 | self.text2_min.Hide() |
---|
93 | self.text2_max.Hide() |
---|
94 | else: |
---|
95 | item[5].Show(True) |
---|
96 | item[6].Show(True) |
---|
97 | self.text2_min.Show(True) |
---|
98 | self.text2_max.Show(True) |
---|
99 | for item in self.fittable_param: |
---|
100 | if item[5]!=None and item[6]!=None and not item in self.orientation_params_disp: |
---|
101 | if event.type =="scipy" and not item in self.orientation_params: |
---|
102 | item[5].SetValue("") |
---|
103 | item[5].Hide() |
---|
104 | item[6].SetValue("") |
---|
105 | item[6].Hide() |
---|
106 | self.text2_min.Hide() |
---|
107 | self.text2_max.Hide() |
---|
108 | self.text_disp_min.Hide() |
---|
109 | self.text_disp_max.Hide() |
---|
110 | else: |
---|
111 | item[5].Show(True) |
---|
112 | item[6].Show(True) |
---|
113 | self.text2_min.Show(True) |
---|
114 | self.text2_max.Show(True) |
---|
115 | self.text_disp_min.Show(True) |
---|
116 | self.text_disp_max.Show(True) |
---|
117 | |
---|
118 | for item in self.orientation_params: |
---|
119 | if item[5]!=None and item[6]!=None: |
---|
120 | if event.type =="scipy" or self.data.__class__.__name__ !="Data2D": |
---|
121 | item[5].SetValue("") |
---|
122 | item[5].Hide() |
---|
123 | item[6].SetValue("") |
---|
124 | item[6].Hide() |
---|
125 | else: |
---|
126 | item[5].Show(True) |
---|
127 | item[6].Show(True) |
---|
128 | |
---|
129 | for item in self.orientation_params_disp: |
---|
130 | if item[5]!=None and item[6]!=None: |
---|
131 | if event.type =="scipy" or self.data.__class__.__name__ !="Data2D": |
---|
132 | item[5].SetValue("") |
---|
133 | item[5].Hide() |
---|
134 | item[6].SetValue("") |
---|
135 | item[6].Hide() |
---|
136 | else: |
---|
137 | item[5].Show(True) |
---|
138 | item[6].Show(True) |
---|
139 | |
---|
140 | self.sizer3.Layout() |
---|
141 | self.SetScrollbars(20,20,25,65) |
---|
142 | |
---|
143 | |
---|
144 | def _fill_range_sizer(self): |
---|
145 | """ |
---|
146 | Fill the sizer containing the plotting range |
---|
147 | add access to npts |
---|
148 | """ |
---|
149 | title = "Fitting" |
---|
150 | box_description_range = wx.StaticBox(self, -1,str(title)) |
---|
151 | boxsizer_range = wx.StaticBoxSizer(box_description_range, wx.VERTICAL) |
---|
152 | |
---|
153 | sizer_fit = wx.GridSizer(1, 1,0, 0) |
---|
154 | |
---|
155 | self.btFit = wx.Button(self,wx.NewId(),'Fit', size=(80,23)) |
---|
156 | self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId()) |
---|
157 | self.btFit.SetToolTipString("Perform fit.") |
---|
158 | |
---|
159 | |
---|
160 | sizer_fit.Add((5,5),1, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
161 | sizer_fit.Add(self.btFit,0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 35) |
---|
162 | sizer_fit.Layout() |
---|
163 | sizer_smearer = wx.BoxSizer(wx.HORIZONTAL) |
---|
164 | #Filling the sizer containing instruments smearing info. |
---|
165 | self.disable_smearer = wx.RadioButton(self, -1, 'No', style=wx.RB_GROUP) |
---|
166 | self.enable_smearer = wx.RadioButton(self, -1, 'Yes') |
---|
167 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId()) |
---|
168 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId()) |
---|
169 | self.disable_smearer.SetValue(True) |
---|
170 | |
---|
171 | sizer_smearer.Add(wx.StaticText(self,-1,'Instrument Smearing? ')) |
---|
172 | sizer_smearer.Add((10, 10)) |
---|
173 | sizer_smearer.Add( self.enable_smearer ) |
---|
174 | sizer_smearer.Add((10,10)) |
---|
175 | sizer_smearer.Add( self.disable_smearer ) |
---|
176 | #Display Chi^2/dof |
---|
177 | sizer_smearer.Add((78,10)) |
---|
178 | box_description= wx.StaticBox(self, -1,'Chi2/dof') |
---|
179 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
180 | boxsizer1.SetMinSize((80,-1)) |
---|
181 | temp_smearer = None |
---|
182 | if self.enable_smearer.GetValue(): |
---|
183 | temp_smearer= self.smearer |
---|
184 | |
---|
185 | self.tcChi = wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT) |
---|
186 | |
---|
187 | boxsizer1.Add( self.tcChi ) |
---|
188 | sizer_smearer.Add( boxsizer1 ) |
---|
189 | |
---|
190 | #Set sizer for Fitting section |
---|
191 | self._set_range_sizer( title=title,box_sizer=boxsizer_range, object1=sizer_smearer, object= sizer_fit) |
---|
192 | |
---|
193 | |
---|
194 | def _fill_datainfo_sizer(self): |
---|
195 | """ |
---|
196 | fill sizer 0 with data info |
---|
197 | """ |
---|
198 | self.sizer0.Clear(True) |
---|
199 | ## no loaded data , don't fill the sizer |
---|
200 | if self.data== None: |
---|
201 | self.sizer0.Layout() |
---|
202 | return |
---|
203 | |
---|
204 | box_description= wx.StaticBox(self, -1, 'Data') |
---|
205 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
206 | #---------------------------------------------------------- |
---|
207 | sizer_data = wx.GridSizer(3, 3,5, 5) |
---|
208 | #Filling the sizer containing data related fields |
---|
209 | DataSource =wx.StaticText(self, -1,str(self.data.name)) |
---|
210 | |
---|
211 | sizer_data.Add(wx.StaticText(self, -1, 'Source Name : ')) |
---|
212 | sizer_data.Add(DataSource ) |
---|
213 | sizer_data.Add( (0,5) ) |
---|
214 | |
---|
215 | #---------sizer 2 draw-------------------------------- |
---|
216 | #set maximum range for x in linear scale |
---|
217 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
218 | # Minimum value of data |
---|
219 | data_min = min(self.data.x) |
---|
220 | # Maximum value of data |
---|
221 | data_max = max(self.data.x) |
---|
222 | text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)', |
---|
223 | style=wx.ALIGN_LEFT) |
---|
224 | sizer_data.Add( text4_3 ) |
---|
225 | sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%str(data_min))) |
---|
226 | sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%str(data_max))) |
---|
227 | |
---|
228 | else: |
---|
229 | ## Minimum value of data |
---|
230 | data_min= 0 |
---|
231 | x= max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
232 | y= max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
233 | ## Maximum value of data |
---|
234 | data_max = math.sqrt(x*x + y*y) |
---|
235 | |
---|
236 | #For qmin and qmax, do not use format_number |
---|
237 | #.(If do, qmin and max could be different from what is in the data.) |
---|
238 | text4_3 = wx.StaticText(self, -1, "Total Q Range (1/A)", |
---|
239 | style=wx.ALIGN_LEFT) |
---|
240 | sizer_data.Add( text4_3 ) |
---|
241 | sizer_data.Add(wx.StaticText(self, -1, "Min : %s"%str(data_min))) |
---|
242 | sizer_data.Add(wx.StaticText(self, -1, "Max : %s"%str(data_max))) |
---|
243 | ## set q range to plot |
---|
244 | self.qmin_x= data_min |
---|
245 | self.qmax_x= data_max |
---|
246 | |
---|
247 | boxsizer1.Add(sizer_data) |
---|
248 | #------------------------------------------------------------ |
---|
249 | self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
250 | self.sizer0.Layout() |
---|
251 | |
---|
252 | def _fill_model_sizer(self, sizer): |
---|
253 | """ |
---|
254 | fill sizer containing model info |
---|
255 | """ |
---|
256 | ##Add model function Details button in fitpanel. |
---|
257 | ##The following 3 lines are for Mac. Let JHC know before modifying... |
---|
258 | title = "Model" |
---|
259 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
260 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
261 | |
---|
262 | id = wx.NewId() |
---|
263 | self.model_help =wx.Button(self,id,'Details', size=(80,23)) |
---|
264 | self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked,id=id) |
---|
265 | self.model_help.SetToolTipString("Model Function Help") |
---|
266 | |
---|
267 | ## class base method to add view 2d button |
---|
268 | self._set_model_sizer(sizer=sizer, box_sizer=boxsizer1, title="Model",object=self.model_help ) |
---|
269 | |
---|
270 | |
---|
271 | #def _set_sizer_gaussian(self): |
---|
272 | def _set_sizer_dispersion(self, dispersity): |
---|
273 | """ |
---|
274 | draw sizer with gaussian dispersity parameters |
---|
275 | """ |
---|
276 | self.fittable_param=[] |
---|
277 | self.fixed_param=[] |
---|
278 | self.orientation_params_disp=[] |
---|
279 | |
---|
280 | self.sizer4_4.Clear(True) |
---|
281 | if self.model==None: |
---|
282 | ##no model is selected |
---|
283 | return |
---|
284 | if not self.enable_disp.GetValue(): |
---|
285 | ## the user didn't select dispersity display |
---|
286 | return |
---|
287 | |
---|
288 | self._reset_dispersity() |
---|
289 | # Create the dispersion objects |
---|
290 | for item in self.model.dispersion.keys(): |
---|
291 | #disp_model = GaussianDispersion() |
---|
292 | disp_model = dispersity() |
---|
293 | self._disp_obj_dict[item] = disp_model |
---|
294 | self.model.set_dispersion(item, disp_model) |
---|
295 | self.state._disp_obj_dict[item]= disp_model |
---|
296 | |
---|
297 | ix=0 |
---|
298 | iy=1 |
---|
299 | disp = wx.StaticText(self, -1, 'Names') |
---|
300 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
301 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
302 | ix += 1 |
---|
303 | values = wx.StaticText(self, -1, 'Sigmas (STD)') |
---|
304 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
305 | ix +=2 |
---|
306 | self.text_disp_1 = wx.StaticText(self, -1, '') |
---|
307 | self.sizer4_4.Add( self.text_disp_1,(iy, ix),(1,1),\ |
---|
308 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
309 | self.text_disp_1.Hide() |
---|
310 | |
---|
311 | |
---|
312 | ix +=1 |
---|
313 | self.text_disp_min = wx.StaticText(self, -1, 'Min') |
---|
314 | self.sizer4_4.Add(self.text_disp_min,(iy, ix),(1,1),\ |
---|
315 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
316 | self.text_disp_min.Hide() |
---|
317 | ix +=1 |
---|
318 | self.text_disp_max = wx.StaticText(self, -1, 'Max') |
---|
319 | self.sizer4_4.Add(self.text_disp_max,(iy, ix),(1,1),\ |
---|
320 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
321 | self.text_disp_max.Hide() |
---|
322 | |
---|
323 | |
---|
324 | |
---|
325 | |
---|
326 | |
---|
327 | |
---|
328 | ix += 1 |
---|
329 | npts = wx.StaticText(self, -1, 'Npts') |
---|
330 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
331 | ix += 1 |
---|
332 | nsigmas = wx.StaticText(self, -1, 'Nsigmas') |
---|
333 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
334 | |
---|
335 | if self.engine_type=="park": |
---|
336 | self.text_disp_max.Show(True) |
---|
337 | self.text_disp_min.Show(True) |
---|
338 | |
---|
339 | for item in self.model.dispersion.keys(): |
---|
340 | if not item in self.model.orientation_params: |
---|
341 | self.disp_cb_dict[item]= None |
---|
342 | name1=item+".width" |
---|
343 | name2=item+".npts" |
---|
344 | name3=item+".nsigmas" |
---|
345 | iy += 1 |
---|
346 | for p in self.model.dispersion[item].keys(): |
---|
347 | |
---|
348 | if p=="width": |
---|
349 | ix = 0 |
---|
350 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
351 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
352 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
353 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
354 | ix = 1 |
---|
355 | value= self.model.getParam(name1) |
---|
356 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
357 | style=wx.TE_PROCESS_ENTER) |
---|
358 | ctl1.SetValue(str (format_number(value))) |
---|
359 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
360 | ## text to show error sign |
---|
361 | ix = 2 |
---|
362 | text2=wx.StaticText(self, -1, '+/-') |
---|
363 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
364 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
365 | text2.Hide() |
---|
366 | ## txtcrtl to add error from fit |
---|
367 | ix = 3 |
---|
368 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
369 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
370 | ctl2.Hide() |
---|
371 | |
---|
372 | #Prepare add min and max in model.details.(Maybe Not correct way) |
---|
373 | if not self.model.details.has_key(name1): |
---|
374 | self.model.details [name1] = ["",None, None] |
---|
375 | param_min, param_max= self.model.details[name1][1:] |
---|
376 | ix = 4 |
---|
377 | ctl3 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
378 | kill_focus_callback = self._on_paramRangeEnter, |
---|
379 | set_focus_callback = self._on_paramRangeEnter) |
---|
380 | if param_min ==None: |
---|
381 | ctl3.SetValue("") |
---|
382 | else: |
---|
383 | ctl3.SetValue(str(param_min)) |
---|
384 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
385 | ctl3.Hide() |
---|
386 | |
---|
387 | ix = 5 |
---|
388 | ctl4 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
389 | kill_focus_callback = self._on_paramRangeEnter, |
---|
390 | set_focus_callback = self._on_paramRangeEnter) |
---|
391 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
392 | if param_max==None: |
---|
393 | ctl4.SetValue("") |
---|
394 | else: |
---|
395 | ctl4.SetValue(str(param_max)) |
---|
396 | ctl4.Hide() |
---|
397 | |
---|
398 | if self.engine_type=="park": |
---|
399 | ctl3.Show(True) |
---|
400 | ctl4.Show(True) |
---|
401 | |
---|
402 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
403 | ctl2, ctl3, ctl4,None]) |
---|
404 | #self.parameters.append([cb,name1, ctl1,text2,ctl2, ctl3, ctl4,None]) |
---|
405 | #self.orientation_params.append([cb,name1, ctl1,text2,ctl2, ctl3, ctl4,None]) |
---|
406 | |
---|
407 | |
---|
408 | elif p=="npts": |
---|
409 | ix = 6 |
---|
410 | value= self.model.getParam(name2) |
---|
411 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
412 | style=wx.TE_PROCESS_ENTER) |
---|
413 | |
---|
414 | Tctl.SetValue(str (format_number(value))) |
---|
415 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
416 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
417 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
418 | None, None,None]) |
---|
419 | elif p=="nsigmas": |
---|
420 | ix = 7 |
---|
421 | value= self.model.getParam(name3) |
---|
422 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
423 | style=wx.TE_PROCESS_ENTER) |
---|
424 | Tctl.SetValue(str (format_number(value))) |
---|
425 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
426 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
427 | ix +=1 |
---|
428 | self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
429 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
430 | |
---|
431 | self.fixed_param.append([None,name3, Tctl |
---|
432 | ,None,None,None, None,None]) |
---|
433 | |
---|
434 | ix =0 |
---|
435 | iy +=1 |
---|
436 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
437 | for item in self.model.dispersion.keys(): |
---|
438 | if item in self.model.orientation_params: |
---|
439 | self.disp_cb_dict[item]= None |
---|
440 | name1=item+".width" |
---|
441 | name2=item+".npts" |
---|
442 | name3=item+".nsigmas" |
---|
443 | iy += 1 |
---|
444 | for p in self.model.dispersion[item].keys(): |
---|
445 | |
---|
446 | if p=="width": |
---|
447 | ix = 0 |
---|
448 | cb = wx.CheckBox(self, -1, name1, (10, 10)) |
---|
449 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
450 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
451 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
452 | if self.data.__class__.__name__ =="Data2D": |
---|
453 | cb.Show(True) |
---|
454 | else: |
---|
455 | cb.Hide() |
---|
456 | ix = 1 |
---|
457 | value= self.model.getParam(name1) |
---|
458 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
459 | style=wx.TE_PROCESS_ENTER) |
---|
460 | ctl1.SetValue(str (format_number(value))) |
---|
461 | if self.data.__class__.__name__ =="Data2D": |
---|
462 | ctl1.Show(True) |
---|
463 | else: |
---|
464 | ctl1.Hide() |
---|
465 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
466 | ## text to show error sign |
---|
467 | ix = 2 |
---|
468 | text2=wx.StaticText(self, -1, '+/-') |
---|
469 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
470 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
471 | text2.Hide() |
---|
472 | ## txtcrtl to add error from fit |
---|
473 | ix = 3 |
---|
474 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
475 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
476 | ctl2.Hide() |
---|
477 | if self.data.__class__.__name__ =="Data2D": |
---|
478 | ctl2.Enable() |
---|
479 | else: |
---|
480 | ctl2.Disable() |
---|
481 | |
---|
482 | |
---|
483 | if not self.model.details.has_key(name1): |
---|
484 | self.model.details [name1] = ["",None, None] |
---|
485 | |
---|
486 | param_min, param_max= self.model.details[name1][1:] |
---|
487 | ix = 4 |
---|
488 | ctl3 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
489 | kill_focus_callback = self._onparamRangeEnter, |
---|
490 | set_focus_callback = self._onparamRangeEnter) |
---|
491 | if param_min ==None: |
---|
492 | ctl3.SetValue("") |
---|
493 | else: |
---|
494 | ctl3.SetValue(str(param_min)) |
---|
495 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
496 | ctl3.Hide() |
---|
497 | if self.data.__class__.__name__ =="Data2D": |
---|
498 | ctl3.Enable() |
---|
499 | else: |
---|
500 | ctl3.Disable() |
---|
501 | |
---|
502 | ix = 5 |
---|
503 | ctl4 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
504 | kill_focus_callback = self._onparamRangeEnter, |
---|
505 | set_focus_callback = self._onparamRangeEnter) |
---|
506 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
507 | if param_max==None: |
---|
508 | ctl4.SetValue("") |
---|
509 | else: |
---|
510 | ctl4.SetValue(str(param_max)) |
---|
511 | ctl4.Hide() |
---|
512 | if self.data.__class__.__name__ =="Data2D": |
---|
513 | ctl4.Enable() |
---|
514 | else: |
---|
515 | ctl4.Disable() |
---|
516 | |
---|
517 | if self.engine_type=="park" and self.data.__class__.__name__ =="Data2D": |
---|
518 | ctl3.Show(True) |
---|
519 | ctl4.Show(True) |
---|
520 | |
---|
521 | |
---|
522 | |
---|
523 | |
---|
524 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
525 | ctl2, ctl3, ctl4,None]) |
---|
526 | #self.parameters.append([cb,name1, ctl1,text2,ctl2, ctl3, ctl4,None]) |
---|
527 | #self.orientation_params.append([cb,name1,ctl1,text2, ctl2, ctl3, ctl4,None]) |
---|
528 | self.orientation_params_disp.append([cb,name1,ctl1,text2, |
---|
529 | ctl2, ctl3, ctl4,None]) |
---|
530 | elif p=="npts": |
---|
531 | ix = 6 |
---|
532 | value= self.model.getParam(name2) |
---|
533 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
534 | style=wx.TE_PROCESS_ENTER) |
---|
535 | |
---|
536 | Tctl.SetValue(str (format_number(value))) |
---|
537 | if self.data.__class__.__name__ =="Data2D": |
---|
538 | Tctl.Show(True) |
---|
539 | else: |
---|
540 | Tctl.Hide() |
---|
541 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
542 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
543 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
544 | None, None,None]) |
---|
545 | self.orientation_params_disp.append([None,name2, Tctl,None,None, |
---|
546 | None, None,None]) |
---|
547 | elif p=="nsigmas": |
---|
548 | ix = 7 |
---|
549 | value= self.model.getParam(name3) |
---|
550 | Tctl = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), |
---|
551 | style=wx.TE_PROCESS_ENTER) |
---|
552 | Tctl.SetValue(str (format_number(value))) |
---|
553 | if self.data.__class__.__name__ =="Data2D": |
---|
554 | Tctl.Show(True) |
---|
555 | else: |
---|
556 | Tctl.Hide() |
---|
557 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
558 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
559 | ix +=1 |
---|
560 | #self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
561 | #wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
562 | self.fixed_param.append([None,name3, Tctl |
---|
563 | ,None,None, None, None,None]) |
---|
564 | |
---|
565 | self.orientation_params_disp.append([None,name3, Tctl |
---|
566 | ,None,None, None, None,None]) |
---|
567 | |
---|
568 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
569 | self.state.model = self.model.clone() |
---|
570 | ## save state into |
---|
571 | self.state.cb1 = self.cb1.GetValue() |
---|
572 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
573 | self._copy_parameters_state(self.orientation_params_disp, |
---|
574 | self.state.orientation_params_disp) |
---|
575 | self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
576 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
577 | |
---|
578 | |
---|
579 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
580 | " Selected Distribution: Gaussian")) |
---|
581 | ix =0 |
---|
582 | iy +=1 |
---|
583 | #self.sizer4_4.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
584 | self.sizer4_4.Layout() |
---|
585 | self.sizer4.Layout() |
---|
586 | self.Layout() |
---|
587 | self.SetScrollbars(20,20,25,65) |
---|
588 | self.Refresh() |
---|
589 | |
---|
590 | |
---|
591 | def _onFit(self, event): |
---|
592 | """ |
---|
593 | Allow to fit |
---|
594 | """ |
---|
595 | from sans.guiframe.utils import check_value |
---|
596 | flag = check_value( self.qmin, self.qmax) |
---|
597 | |
---|
598 | if not flag: |
---|
599 | msg= "Fitting range invalid" |
---|
600 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
601 | return |
---|
602 | |
---|
603 | if len(self.param_toFit) <= 0: |
---|
604 | msg= "Select at least one parameter to fit" |
---|
605 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
606 | return |
---|
607 | |
---|
608 | # Remove or do not allow fitting on the Q=0 point, especially when y(q=0)=None at x[0]. |
---|
609 | #ToDo: Fix this. |
---|
610 | self.qmin_x = float(self.qmin.GetValue()) |
---|
611 | self.qmax_x =float( self.qmax.GetValue()) |
---|
612 | self.manager._reset_schedule_problem( value=0) |
---|
613 | self.manager.schedule_for_fit( value=1,page=self,fitproblem =None) |
---|
614 | self.manager.set_fit_range(page= self,qmin= self.qmin_x, qmax= self.qmax_x) |
---|
615 | |
---|
616 | #single fit |
---|
617 | self.manager.onFit() |
---|
618 | ## allow stopping the fit |
---|
619 | #if self.engine_type=="scipy": |
---|
620 | # self.btFit.SetLabel("Stop") |
---|
621 | # self.btFit.Unbind(event=wx.EVT_BUTTON, id= self.btFit.GetId()) |
---|
622 | # self.btFit.Bind(event= wx.EVT_BUTTON, handler=self._StopFit, id=self.btFit.GetId()) |
---|
623 | #else: |
---|
624 | # self.btFit.SetLabel("Fit") |
---|
625 | # self.btFit.Bind(event= wx.EVT_BUTTON, handler=self._onFit, id=self.btFit.GetId()) |
---|
626 | self.btFit.SetFocus() |
---|
627 | self.sizer5.Layout() |
---|
628 | #self.SetScrollbars(20,20,55,40) |
---|
629 | |
---|
630 | def _StopFit(self, event): |
---|
631 | """ |
---|
632 | Stop fit |
---|
633 | """ |
---|
634 | self.btFit.SetLabel("Fit") |
---|
635 | if self.engine_type=="scipy": |
---|
636 | self.manager.stop_fit() |
---|
637 | self.btFit.Unbind(event=wx.EVT_BUTTON, id=self.btFit.GetId()) |
---|
638 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit,id=self.btFit.GetId()) |
---|
639 | |
---|
640 | |
---|
641 | self.btFit.SetFocus() |
---|
642 | self.sizer5.Layout() |
---|
643 | self.SetScrollbars(20,20,55,40) |
---|
644 | |
---|
645 | def _on_select_model(self, event): |
---|
646 | """ |
---|
647 | call back for model selection |
---|
648 | """ |
---|
649 | self._on_select_model_helper() |
---|
650 | self.set_model_param_sizer(self.model) |
---|
651 | |
---|
652 | self.enable_disp.SetValue(False) |
---|
653 | self.disable_disp.SetValue(True) |
---|
654 | try: |
---|
655 | self.set_dispers_sizer() |
---|
656 | except: |
---|
657 | pass |
---|
658 | if self.model !=None: |
---|
659 | try: |
---|
660 | temp_smear= None |
---|
661 | if self.enable_smearer.GetValue(): |
---|
662 | temp_smear= self.smearer |
---|
663 | self.compute_chisqr(temp_smear) |
---|
664 | except: |
---|
665 | ## error occured on chisqr computation |
---|
666 | pass |
---|
667 | ## set smearing value whether or not the data contain the smearing info |
---|
668 | self.manager.set_smearer(smearer=temp_smear, qmin= float(self.qmin_x), |
---|
669 | qmax= float(self.qmax_x)) |
---|
670 | evt = ModelEventbox(model=self.model) |
---|
671 | wx.PostEvent(self.event_owner, evt) |
---|
672 | |
---|
673 | self.btFit.SetFocus() |
---|
674 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
675 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
676 | |
---|
677 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
678 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
679 | |
---|
680 | |
---|
681 | if event !=None: |
---|
682 | #self._undo.Enable(True) |
---|
683 | ## post state to fit panel |
---|
684 | event = PageInfoEvent(page = self) |
---|
685 | wx.PostEvent(self.parent, event) |
---|
686 | |
---|
687 | |
---|
688 | def _onparamRangeEnter(self, event): |
---|
689 | """ |
---|
690 | Check validity of value enter in the parameters range field |
---|
691 | """ |
---|
692 | tcrtl= event.GetEventObject() |
---|
693 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
694 | try: |
---|
695 | value = float(tcrtl.GetValue()) |
---|
696 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
697 | tcrtl.Refresh() |
---|
698 | except: |
---|
699 | tcrtl.SetBackgroundColour("pink") |
---|
700 | tcrtl.Refresh() |
---|
701 | return |
---|
702 | else: |
---|
703 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
704 | tcrtl.Refresh() |
---|
705 | self._onparamEnter_helper() |
---|
706 | |
---|
707 | ##compute chisqr for range change |
---|
708 | temp_smearer = None |
---|
709 | if self.enable_smearer.GetValue(): |
---|
710 | msg="" |
---|
711 | temp_smearer= self.smearer |
---|
712 | ##Calculate chi2 |
---|
713 | |
---|
714 | self.compute_chisqr(smearer= temp_smearer) |
---|
715 | ## new state posted |
---|
716 | if self.state_change: |
---|
717 | #self._undo.Enable(True) |
---|
718 | event = PageInfoEvent(page = self) |
---|
719 | wx.PostEvent(self.parent, event) |
---|
720 | self.state_change= False |
---|
721 | |
---|
722 | |
---|
723 | def _onparamEnter(self,event): |
---|
724 | """ |
---|
725 | when enter value on panel redraw model according to changed |
---|
726 | """ |
---|
727 | tcrtl= event.GetEventObject() |
---|
728 | |
---|
729 | if check_float(tcrtl): |
---|
730 | self._onparamEnter_helper() |
---|
731 | temp_smearer = None |
---|
732 | if self.enable_smearer.GetValue(): |
---|
733 | temp_smearer= self.smearer |
---|
734 | |
---|
735 | self.compute_chisqr(smearer= temp_smearer) |
---|
736 | ## new state posted |
---|
737 | if self.state_change: |
---|
738 | #self._undo.Enable(True) |
---|
739 | event = PageInfoEvent(page = self) |
---|
740 | wx.PostEvent(self.parent, event) |
---|
741 | self.state_change= False |
---|
742 | else: |
---|
743 | msg= "Cannot Plot :Must enter a number!!! " |
---|
744 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
745 | return |
---|
746 | |
---|
747 | ### Same as _onparamRangeEnter but smear and chi^2 calculations are removed |
---|
748 | ### and _onparamEnter_helper is not used, which causing mess sizer display |
---|
749 | def _on_paramRangeEnter(self, event): |
---|
750 | """ |
---|
751 | Check validity of value enter in the parameters range field |
---|
752 | """ |
---|
753 | tcrtl= event.GetEventObject() |
---|
754 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
755 | try: |
---|
756 | value = float(tcrtl.GetValue()) |
---|
757 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
758 | tcrtl.Refresh() |
---|
759 | except: |
---|
760 | tcrtl.SetBackgroundColour("pink") |
---|
761 | tcrtl.Refresh() |
---|
762 | return |
---|
763 | else: |
---|
764 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
765 | tcrtl.Refresh() |
---|
766 | self._onparamEnter_helper() |
---|
767 | |
---|
768 | ## new state posted |
---|
769 | if self.state_change: |
---|
770 | #self._undo.Enable(True) |
---|
771 | event = PageInfoEvent(page = self) |
---|
772 | wx.PostEvent(self.parent, event) |
---|
773 | self.state_change= False |
---|
774 | |
---|
775 | |
---|
776 | |
---|
777 | def set_data(self, data ): |
---|
778 | """ |
---|
779 | reset the current data |
---|
780 | """ |
---|
781 | if data ==None: |
---|
782 | return |
---|
783 | self.data =data |
---|
784 | self.state.data= data |
---|
785 | self._fill_datainfo_sizer() |
---|
786 | self.SetScrollbars(20,20,25,65) |
---|
787 | self.Layout() |
---|
788 | |
---|
789 | def reset_page(self, state,first=False): |
---|
790 | """ |
---|
791 | reset the state |
---|
792 | """ |
---|
793 | #if first: |
---|
794 | # self._undo.Enable(False) |
---|
795 | |
---|
796 | self.reset_page_helper(state) |
---|
797 | evt = ModelEventbox(model=state.model) |
---|
798 | wx.PostEvent(self.event_owner, evt) |
---|
799 | |
---|
800 | |
---|
801 | def get_range(self): |
---|
802 | """ |
---|
803 | return the fitting range |
---|
804 | """ |
---|
805 | return float(self.qmin_x) , float(self.qmax_x) |
---|
806 | |
---|
807 | def get_param_list(self): |
---|
808 | """ |
---|
809 | @return self.param_toFit: list containing references to TextCtrl |
---|
810 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
811 | @raise: if return an empty list of parameter fit will nnote work |
---|
812 | properly so raise ValueError,"missing parameter to fit" |
---|
813 | """ |
---|
814 | if self.param_toFit !=[]: |
---|
815 | return self.param_toFit |
---|
816 | else: |
---|
817 | raise ValueError,"missing parameter to fit" |
---|
818 | |
---|
819 | def onsetValues(self,chisqr, out,cov): |
---|
820 | """ |
---|
821 | Build the panel from the fit result |
---|
822 | @param chisqr:Value of the goodness of fit metric |
---|
823 | @param out:list of parameter with the best value found during fitting |
---|
824 | @param cov:Covariance matrix |
---|
825 | |
---|
826 | """ |
---|
827 | self.tcChi.SetLabel(format_number(chisqr)) |
---|
828 | params = {} |
---|
829 | is_modified = False |
---|
830 | has_error = False |
---|
831 | self.text2_3.Hide() |
---|
832 | try: |
---|
833 | n = self.disp_box.GetCurrentSelection() |
---|
834 | dispersity= self.disp_box.GetClientData(n) |
---|
835 | name= dispersity.__name__ |
---|
836 | if name == "GaussianDispersion": |
---|
837 | if hasattr(self,"text_disp_1" ): |
---|
838 | if self.text_disp_1 !=None: |
---|
839 | self.text_disp_1.Hide() |
---|
840 | except: |
---|
841 | pass |
---|
842 | #set the panel when fit result are float not list |
---|
843 | if out.__class__==numpy.float64: |
---|
844 | self.param_toFit[0][2].SetValue(format_number(out)) |
---|
845 | self.param_toFit[0][2].Refresh() |
---|
846 | |
---|
847 | self.param_toFit[0][4].Clear() |
---|
848 | self.param_toFit[0][4].Hide() |
---|
849 | if cov !=None : |
---|
850 | self.text2_3.Show(True) |
---|
851 | try: |
---|
852 | name= dispersity.__name__ |
---|
853 | if name == "GaussianDispersion": |
---|
854 | if hasattr(self,"text_disp_1" ): |
---|
855 | if self.text_disp_1 !=None: |
---|
856 | self.text_disp_1.Show(True) |
---|
857 | except: |
---|
858 | pass |
---|
859 | if cov[0]==None or not numpy.isfinite(cov[0]): |
---|
860 | self.param_toFit[0][3].Hide() |
---|
861 | self.param_toFit[0][4].Clear() |
---|
862 | self.param_toFit[0][4].Hide() |
---|
863 | self.param_toFit[0][4].Refresh() |
---|
864 | else: |
---|
865 | self.param_toFit[0][3].Show(True) |
---|
866 | self.param_toFit[0][4].Clear() |
---|
867 | self.param_toFit[0][4].SetValue(format_number(cov[0])) |
---|
868 | self.param_toFit[0][4].Show(True) |
---|
869 | self.param_toFit[0][4].Refresh() |
---|
870 | else: |
---|
871 | i=0 |
---|
872 | j=0 |
---|
873 | #Set the panel when fit result are list |
---|
874 | for item in self.param_toFit: |
---|
875 | ## reset error value to initial state |
---|
876 | item[4].Clear() |
---|
877 | item[4].Hide() |
---|
878 | item[4].Refresh() |
---|
879 | if( out != None ) and len(out)<=len(self.param_toFit)and i < len(out): |
---|
880 | item[2].SetValue(format_number(self.model.getParam(item[1]))) |
---|
881 | item[2].Refresh() |
---|
882 | if(cov !=None)and len(cov)<=len(self.param_toFit)and i < len(cov): |
---|
883 | self.text2_3.Show(True) |
---|
884 | try: |
---|
885 | name= dispersity.__name__ |
---|
886 | if name == "GaussianDispersion": |
---|
887 | if hasattr(self,"text_disp_1" ): |
---|
888 | if self.text_disp_1!=None: |
---|
889 | self.text_disp_1.Show(True) |
---|
890 | except: |
---|
891 | pass |
---|
892 | item[3].Show(True) |
---|
893 | item[4].Clear() |
---|
894 | for j in range(len(out)): |
---|
895 | if out[j]==self.model.getParam(item[1]): |
---|
896 | break |
---|
897 | ## unable to compare cov[j]==numpy.nan so switch to None |
---|
898 | if cov[j]==None or not numpy.isfinite(cov[j]): |
---|
899 | item[3].Hide() |
---|
900 | item[4].Refresh() |
---|
901 | item[4].Clear() |
---|
902 | item[4].Hide() |
---|
903 | else: |
---|
904 | item[4].SetValue(format_number(cov[j])) |
---|
905 | item[4].Refresh() |
---|
906 | item[4].Show(True) |
---|
907 | i+=1 |
---|
908 | |
---|
909 | self.sizer3.Layout() |
---|
910 | self.sizer4.Layout() |
---|
911 | self.Layout() |
---|
912 | self.Refresh() |
---|
913 | self.SetScrollbars(20,20,25,65) |
---|
914 | |
---|
915 | |
---|
916 | def onSmear(self, event): |
---|
917 | """ |
---|
918 | Create a smear object that will change the way residuals |
---|
919 | are compute when fitting |
---|
920 | """ |
---|
921 | if self.model ==None: |
---|
922 | msg="Need model and data to smear plot" |
---|
923 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
924 | "Smear: %s"%msg)) |
---|
925 | return |
---|
926 | temp_smearer = None |
---|
927 | if self.enable_smearer.GetValue(): |
---|
928 | temp_smearer= self.smearer |
---|
929 | if hasattr(self.data,"dxl"): |
---|
930 | msg= ": Resolution smearing parameters" |
---|
931 | if hasattr(self.data,"dxw"): |
---|
932 | msg= ": Slit smearing parameters" |
---|
933 | if self.smearer ==None: |
---|
934 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
935 | "Data contains no smearing information")) |
---|
936 | else: |
---|
937 | wx.PostEvent(self.manager.parent, StatusEvent(status=\ |
---|
938 | "Data contains smearing information %s"%msg)) |
---|
939 | |
---|
940 | ## set smearing value whether or not the data contain the smearing info |
---|
941 | self.manager.set_smearer(smearer=temp_smearer, qmin= float(self.qmin_x), |
---|
942 | qmax= float(self.qmax_x)) |
---|
943 | ##Calculate chi2 |
---|
944 | self.compute_chisqr(smearer= temp_smearer) |
---|
945 | |
---|
946 | self.state.enable_smearer= self.enable_smearer.GetValue() |
---|
947 | self.state.disable_smearer=self.disable_smearer.GetValue() |
---|
948 | |
---|
949 | def complete_chisqr(self, output, elapsed=None): |
---|
950 | """ |
---|
951 | print result chisqr |
---|
952 | """ |
---|
953 | try: |
---|
954 | if output ==None: |
---|
955 | output= "-" |
---|
956 | self.tcChi.SetLabel(str(format_number(output))) |
---|
957 | |
---|
958 | self.sizer5.Layout() |
---|
959 | self.Layout() |
---|
960 | self.Refresh |
---|
961 | ## post state to fit panel |
---|
962 | self.state.tcChi =output |
---|
963 | |
---|
964 | except: |
---|
965 | pass |
---|
966 | |
---|
967 | |
---|
968 | def compute_chisqr1D(self, smearer=None): |
---|
969 | """ |
---|
970 | Compute chisqr for 1D |
---|
971 | """ |
---|
972 | from sans.guiframe.utils import check_value |
---|
973 | flag = check_value( self.qmin, self.qmax) |
---|
974 | |
---|
975 | if not flag: |
---|
976 | return |
---|
977 | |
---|
978 | try: |
---|
979 | self.qmin_x = float(self.qmin.GetValue()) |
---|
980 | self.qmax_x = float(self.qmax.GetValue()) |
---|
981 | ##return residuals within self.qmin_x and self.qmax_x |
---|
982 | from gui_thread import CalcChisqr1D |
---|
983 | ## If a thread is already started, stop it |
---|
984 | if self.calc_Chisqr!= None and self.calc_Chisqr.isrunning(): |
---|
985 | self.calc_Chisqr.stop() |
---|
986 | |
---|
987 | self.calc_Chisqr= CalcChisqr1D( data1d= self.data, |
---|
988 | model= self.model, |
---|
989 | smearer=smearer, |
---|
990 | qmin=self.qmin_x, |
---|
991 | qmax=self.qmax_x, |
---|
992 | completefn = self.complete_chisqr, |
---|
993 | updatefn = None) |
---|
994 | |
---|
995 | self.calc_Chisqr.queue() |
---|
996 | |
---|
997 | except: |
---|
998 | raise ValueError," Could not compute Chisqr for %s Model 2D: "%self.model.name |
---|
999 | |
---|
1000 | |
---|
1001 | |
---|
1002 | |
---|
1003 | |
---|
1004 | def compute_chisqr2D(self): |
---|
1005 | """ |
---|
1006 | compute chi square given a model and data 2D and set the value |
---|
1007 | to the tcChi txtcrl |
---|
1008 | """ |
---|
1009 | from sans.guiframe.utils import check_value |
---|
1010 | flag = check_value( self.qmin, self.qmax) |
---|
1011 | if not flag: |
---|
1012 | return |
---|
1013 | |
---|
1014 | try: |
---|
1015 | self.qmin_x = float(self.qmin.GetValue()) |
---|
1016 | self.qmax_x = float(self.qmax.GetValue()) |
---|
1017 | |
---|
1018 | ##return residuals within self.qmin_x and self.qmax_x |
---|
1019 | from gui_thread import CalcChisqr2D |
---|
1020 | ## If a thread is already started, stop it |
---|
1021 | if self.calc_Chisqr!= None and self.calc_Chisqr.isrunning(): |
---|
1022 | self.calc_Chisqr.stop() |
---|
1023 | |
---|
1024 | self.calc_Chisqr= CalcChisqr2D( data2d= self.data, |
---|
1025 | model= self.model, |
---|
1026 | qmin= self.qmin_x, |
---|
1027 | qmax = self.qmax_x, |
---|
1028 | completefn = self.complete_chisqr, |
---|
1029 | updatefn = None) |
---|
1030 | |
---|
1031 | self.calc_Chisqr.queue() |
---|
1032 | |
---|
1033 | except: |
---|
1034 | raise |
---|
1035 | |
---|
1036 | |
---|
1037 | def compute_chisqr(self , smearer=None): |
---|
1038 | """ |
---|
1039 | compute chi square given a model and data 1D and set the value |
---|
1040 | to the tcChi txtcrl |
---|
1041 | """ |
---|
1042 | from sans.guiframe.utils import check_value |
---|
1043 | flag = check_value( self.qmin, self.qmax) |
---|
1044 | if flag== True: |
---|
1045 | try: |
---|
1046 | if hasattr(self.data,"data"): |
---|
1047 | self.compute_chisqr2D() |
---|
1048 | return |
---|
1049 | else: |
---|
1050 | self.compute_chisqr1D(smearer=smearer) |
---|
1051 | return |
---|
1052 | except: |
---|
1053 | wx.PostEvent(self.parent.parent, StatusEvent(status=\ |
---|
1054 | "Chisqr Error: %s"% sys.exc_value)) |
---|
1055 | return |
---|
1056 | |
---|
1057 | |
---|
1058 | def select_all_param(self,event): |
---|
1059 | """ |
---|
1060 | set to true or false all checkBox given the main checkbox value cb1 |
---|
1061 | """ |
---|
1062 | |
---|
1063 | self.param_toFit=[] |
---|
1064 | if self.parameters !=[]: |
---|
1065 | if self.cb1.GetValue(): |
---|
1066 | for item in self.parameters: |
---|
1067 | ## for data2D select all to fit |
---|
1068 | if self.data.__class__.__name__=="Data2D": |
---|
1069 | item[0].SetValue(True) |
---|
1070 | self.param_toFit.append(item ) |
---|
1071 | else: |
---|
1072 | ## for 1D all parameters except orientation |
---|
1073 | if not item in self.orientation_params: |
---|
1074 | item[0].SetValue(True) |
---|
1075 | self.param_toFit.append(item ) |
---|
1076 | if len(self.fittable_param)>0: |
---|
1077 | for item in self.fittable_param: |
---|
1078 | if self.data.__class__.__name__=="Data2D": |
---|
1079 | item[0].SetValue(True) |
---|
1080 | self.param_toFit.append(item ) |
---|
1081 | else: |
---|
1082 | ## for 1D all parameters except orientation |
---|
1083 | if not item in self.orientation_params_disp: |
---|
1084 | item[0].SetValue(True) |
---|
1085 | self.param_toFit.append(item ) |
---|
1086 | else: |
---|
1087 | for item in self.parameters: |
---|
1088 | item[0].SetValue(False) |
---|
1089 | for item in self.fittable_param: |
---|
1090 | item[0].SetValue(False) |
---|
1091 | self.param_toFit=[] |
---|
1092 | |
---|
1093 | #self._copy_parameters_state(self.orientation_params, |
---|
1094 | # self.state.orientation_params) |
---|
1095 | #self._copy_parameters_state(self.orientation_params_disp, |
---|
1096 | # self.state.orientation_params_disp) |
---|
1097 | #self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
1098 | #self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
1099 | #self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
1100 | |
---|
1101 | self.save_current_state_fit() |
---|
1102 | if event !=None: |
---|
1103 | #self._undo.Enable(True) |
---|
1104 | ## post state to fit panel |
---|
1105 | event = PageInfoEvent(page = self) |
---|
1106 | wx.PostEvent(self.parent, event) |
---|
1107 | |
---|
1108 | |
---|
1109 | |
---|
1110 | def select_param(self,event): |
---|
1111 | """ |
---|
1112 | Select TextCtrl checked for fitting purpose and stores them |
---|
1113 | in self.param_toFit=[] list |
---|
1114 | """ |
---|
1115 | self.param_toFit=[] |
---|
1116 | for item in self.parameters: |
---|
1117 | #Select parameters to fit for list of primary parameters |
---|
1118 | if item[0].GetValue(): |
---|
1119 | if not (item in self.param_toFit): |
---|
1120 | self.param_toFit.append(item ) |
---|
1121 | else: |
---|
1122 | #remove parameters from the fitting list |
---|
1123 | if item in self.param_toFit: |
---|
1124 | self.param_toFit.remove(item) |
---|
1125 | #Select parameters to fit for list of fittable parameters with dispersion |
---|
1126 | for item in self.fittable_param: |
---|
1127 | if item[0].GetValue(): |
---|
1128 | if not (item in self.param_toFit): |
---|
1129 | self.param_toFit.append(item) |
---|
1130 | else: |
---|
1131 | #remove parameters from the fitting list |
---|
1132 | if item in self.param_toFit: |
---|
1133 | self.param_toFit.remove(item) |
---|
1134 | #Set the value of checkbox that selected every checkbox or not |
---|
1135 | if len(self.parameters)+len(self.fittable_param) ==len(self.param_toFit): |
---|
1136 | self.cb1.SetValue(True) |
---|
1137 | else: |
---|
1138 | self.cb1.SetValue(False) |
---|
1139 | ## save current state of the page |
---|
1140 | #self.state.cb1 = self.cb1.GetValue() |
---|
1141 | #self._copy_parameters_state(self.orientation_params, |
---|
1142 | # self.state.orientation_params) |
---|
1143 | #self._copy_parameters_state(self.orientation_params_disp, |
---|
1144 | # self.state.orientation_params_disp) |
---|
1145 | #self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
1146 | #self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
1147 | #self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
1148 | |
---|
1149 | self.save_current_state_fit() |
---|
1150 | if event !=None: |
---|
1151 | #self._undo.Enable(True) |
---|
1152 | ## post state to fit panel |
---|
1153 | event = PageInfoEvent(page = self) |
---|
1154 | wx.PostEvent(self.parent, event) |
---|
1155 | |
---|
1156 | |
---|
1157 | |
---|
1158 | def set_model_param_sizer(self, model): |
---|
1159 | """ |
---|
1160 | Build the panel from the model content |
---|
1161 | @param model: the model selected in combo box for fitting purpose |
---|
1162 | """ |
---|
1163 | self.sizer3.Clear(True) |
---|
1164 | self.parameters = [] |
---|
1165 | self.param_toFit=[] |
---|
1166 | self.fittable_param=[] |
---|
1167 | self.fixed_param=[] |
---|
1168 | self.orientation_params=[] |
---|
1169 | self.orientation_params_disp=[] |
---|
1170 | |
---|
1171 | if model ==None: |
---|
1172 | self.sizer3.Layout() |
---|
1173 | self.SetScrollbars(20,20,25,65) |
---|
1174 | return |
---|
1175 | ## the panel is drawn using the current value of the fit engine |
---|
1176 | if self.engine_type==None and self.manager !=None: |
---|
1177 | self.engine_type= self.manager._return_engine_type() |
---|
1178 | |
---|
1179 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
1180 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
1181 | sizer = wx.GridBagSizer(5,5) |
---|
1182 | ## save the current model |
---|
1183 | self.model = model |
---|
1184 | |
---|
1185 | keys = self.model.getParamList() |
---|
1186 | #list of dispersion paramaters |
---|
1187 | self.disp_list=self.model.getDispParamList() |
---|
1188 | |
---|
1189 | keys.sort() |
---|
1190 | |
---|
1191 | iy = 0 |
---|
1192 | ix = 0 |
---|
1193 | self.cb1 = wx.CheckBox(self, -1,"Select all", (10, 10)) |
---|
1194 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
1195 | self.cb1.SetValue(False) |
---|
1196 | |
---|
1197 | sizer.Add(self.cb1,(iy, ix),(1,1),\ |
---|
1198 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
1199 | ix +=1 |
---|
1200 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
1201 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
1202 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1203 | ix +=2 |
---|
1204 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
1205 | sizer.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
1206 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1207 | self.text2_3.Hide() |
---|
1208 | ix +=1 |
---|
1209 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
1210 | sizer.Add(self.text2_min,(iy, ix),(1,1),\ |
---|
1211 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1212 | self.text2_min.Hide() |
---|
1213 | ix +=1 |
---|
1214 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
1215 | sizer.Add(self.text2_max,(iy, ix),(1,1),\ |
---|
1216 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1217 | self.text2_max.Hide() |
---|
1218 | ix += 1 |
---|
1219 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
1220 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
1221 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1222 | self.text2_4.Hide() |
---|
1223 | if self.engine_type=="park": |
---|
1224 | self.text2_max.Show(True) |
---|
1225 | self.text2_min.Show(True) |
---|
1226 | |
---|
1227 | for item in keys: |
---|
1228 | if not item in self.disp_list and not item in self.model.orientation_params: |
---|
1229 | |
---|
1230 | iy += 1 |
---|
1231 | ix = 0 |
---|
1232 | ## add parameters name with checkbox for selecting to fit |
---|
1233 | cb = wx.CheckBox(self, -1, item ) |
---|
1234 | cb.SetValue(False) |
---|
1235 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
1236 | sizer.Add( cb,( iy, ix),(1,1), |
---|
1237 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
1238 | |
---|
1239 | ## add parameter value |
---|
1240 | ix += 1 |
---|
1241 | value= self.model.getParam(item) |
---|
1242 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
1243 | style=wx.TE_PROCESS_ENTER) |
---|
1244 | |
---|
1245 | ctl1.SetValue(format_number(value)) |
---|
1246 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
1247 | ## text to show error sign |
---|
1248 | ix += 1 |
---|
1249 | text2=wx.StaticText(self, -1, '+/-') |
---|
1250 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
1251 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1252 | text2.Hide() |
---|
1253 | ## txtcrtl to add error from fit |
---|
1254 | ix += 1 |
---|
1255 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
1256 | sizer.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1257 | ctl2.Hide() |
---|
1258 | |
---|
1259 | param_min, param_max= self.model.details[item][1:] |
---|
1260 | ix += 1 |
---|
1261 | ctl3 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
1262 | kill_focus_callback = self._on_paramRangeEnter, |
---|
1263 | set_focus_callback = self._on_paramRangeEnter) |
---|
1264 | if param_min ==None: |
---|
1265 | ctl3.SetValue("") |
---|
1266 | else: |
---|
1267 | ctl3.SetValue(str(param_min)) |
---|
1268 | sizer.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1269 | ctl3.Hide() |
---|
1270 | |
---|
1271 | ix += 1 |
---|
1272 | ctl4 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
1273 | kill_focus_callback = self._on_paramRangeEnter, |
---|
1274 | set_focus_callback = self._on_paramRangeEnter) |
---|
1275 | sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1276 | if param_max==None: |
---|
1277 | ctl4.SetValue("") |
---|
1278 | else: |
---|
1279 | ctl4.SetValue(str(param_max)) |
---|
1280 | ctl4.Hide() |
---|
1281 | |
---|
1282 | if self.engine_type=="park": |
---|
1283 | ctl3.Show(True) |
---|
1284 | ctl4.Show(True) |
---|
1285 | ix +=1 |
---|
1286 | # Units |
---|
1287 | try: |
---|
1288 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
1289 | except: |
---|
1290 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
1291 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1292 | |
---|
1293 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
1294 | self.parameters.append([cb,item, ctl1, |
---|
1295 | text2,ctl2, ctl3, ctl4,units]) |
---|
1296 | |
---|
1297 | iy+=1 |
---|
1298 | sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1299 | |
---|
1300 | # type can be either Guassian or Array |
---|
1301 | if len(self.model.dispersion.values())>0: |
---|
1302 | type= self.model.dispersion.values()[0]["type"] |
---|
1303 | else: |
---|
1304 | type = "Gaussian" |
---|
1305 | |
---|
1306 | iy += 1 |
---|
1307 | ix = 0 |
---|
1308 | #Add tile for orientational angle |
---|
1309 | for item in keys: |
---|
1310 | if item in self.model.orientation_params: |
---|
1311 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
1312 | sizer.Add(orient_angle,(iy, ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1313 | if not self.data.__class__.__name__ =="Data2D": |
---|
1314 | orient_angle.Hide() |
---|
1315 | else: |
---|
1316 | orient_angle.Show(True) |
---|
1317 | break |
---|
1318 | |
---|
1319 | #For Gaussian only |
---|
1320 | if type.lower() != "array": |
---|
1321 | for item in self.model.orientation_params: |
---|
1322 | if not item in self.disp_list: |
---|
1323 | iy += 1 |
---|
1324 | ix = 0 |
---|
1325 | ## add parameters name with checkbox for selecting to fit |
---|
1326 | cb = wx.CheckBox(self, -1, item ) |
---|
1327 | cb.SetValue(False) |
---|
1328 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
1329 | if self.data.__class__.__name__ =="Data2D": |
---|
1330 | cb.Show(True) |
---|
1331 | #cb.Enable() |
---|
1332 | else: |
---|
1333 | cb.Hide() |
---|
1334 | #cb.Disable() |
---|
1335 | sizer.Add( cb,( iy, ix),(1,1), |
---|
1336 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
1337 | |
---|
1338 | ## add parameter value |
---|
1339 | ix += 1 |
---|
1340 | value= self.model.getParam(item) |
---|
1341 | ctl1 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
1342 | style=wx.TE_PROCESS_ENTER) |
---|
1343 | |
---|
1344 | ctl1.SetValue(format_number(value)) |
---|
1345 | if self.data.__class__.__name__ =="Data2D": |
---|
1346 | ctl1.Show(True) |
---|
1347 | #ctl1.Enable() |
---|
1348 | else: |
---|
1349 | ctl1.Hide() |
---|
1350 | #ctl1.Disable() |
---|
1351 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
1352 | ## text to show error sign |
---|
1353 | ix += 1 |
---|
1354 | text2=wx.StaticText(self, -1, '+/-') |
---|
1355 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
1356 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1357 | text2.Hide() |
---|
1358 | ## txtcrtl to add error from fit |
---|
1359 | ix += 1 |
---|
1360 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,20), style=wx.TE_PROCESS_ENTER) |
---|
1361 | sizer.Add(ctl2, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1362 | ctl2.Hide() |
---|
1363 | if self.data.__class__.__name__ =="Data2D": |
---|
1364 | ctl1.Show(True) |
---|
1365 | #ctl1.Enable() |
---|
1366 | else: |
---|
1367 | ctl1.Hide() |
---|
1368 | #ctl1.Disable() |
---|
1369 | param_min, param_max= self.model.details[item][1:] |
---|
1370 | ix += 1 |
---|
1371 | ctl3 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
1372 | kill_focus_callback = self._onparamRangeEnter, |
---|
1373 | set_focus_callback = self._onparamRangeEnter) |
---|
1374 | if param_min ==None: |
---|
1375 | ctl3.SetValue("") |
---|
1376 | else: |
---|
1377 | ctl3.SetValue(str(param_min)) |
---|
1378 | sizer.Add(ctl3, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1379 | ctl3.Hide() |
---|
1380 | if self.data.__class__.__name__ =="Data2D": |
---|
1381 | ctl3.Show(True) |
---|
1382 | #ctl3.Enable() |
---|
1383 | else: |
---|
1384 | ctl3.Hide() |
---|
1385 | #ctl3.Disable() |
---|
1386 | ix += 1 |
---|
1387 | ctl4 = BasicPage.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
1388 | kill_focus_callback = self._onparamRangeEnter, |
---|
1389 | set_focus_callback = self._onparamRangeEnter) |
---|
1390 | sizer.Add(ctl4, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1391 | if param_max ==None: |
---|
1392 | ctl4.SetValue("") |
---|
1393 | else: |
---|
1394 | ctl4.SetValue(str(param_max)) |
---|
1395 | ctl4.Hide() |
---|
1396 | if self.data.__class__.__name__ =="Data2D": |
---|
1397 | ctl4.Show(True) |
---|
1398 | #ctl4.Enable() |
---|
1399 | else: |
---|
1400 | ctl4.Hide() |
---|
1401 | #ctl4.Disable() |
---|
1402 | if self.engine_type !="park" or self.data.__class__.__name__ !="Data2D": |
---|
1403 | ctl3.Hide() |
---|
1404 | ctl4.Hide() |
---|
1405 | else: |
---|
1406 | ctl3.Show(True) |
---|
1407 | ctl4.Show(True) |
---|
1408 | |
---|
1409 | ix +=1 |
---|
1410 | # Units |
---|
1411 | try: |
---|
1412 | units = wx.StaticText(self, -1, self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
1413 | except: |
---|
1414 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
1415 | if self.data.__class__.__name__ =="Data2D": |
---|
1416 | units.Show(True) |
---|
1417 | #units.Enable() |
---|
1418 | else: |
---|
1419 | units.Hide() |
---|
1420 | #units.Disable() |
---|
1421 | sizer.Add(units, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1422 | |
---|
1423 | |
---|
1424 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
1425 | self.parameters.append([cb,item, ctl1, |
---|
1426 | text2,ctl2, ctl3, ctl4,units]) |
---|
1427 | self.orientation_params.append([cb,item, ctl1, |
---|
1428 | text2,ctl2, ctl3, ctl4,units]) |
---|
1429 | |
---|
1430 | iy+=1 |
---|
1431 | #sizer.Add((10,10),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1432 | |
---|
1433 | #Display units text on panel |
---|
1434 | for item in keys: |
---|
1435 | if self.model.details[item][0]!='': |
---|
1436 | self.text2_4.Show() |
---|
1437 | break |
---|
1438 | else: |
---|
1439 | self.text2_4.Hide() |
---|
1440 | #self.state.cb1 = self.cb1.GetValue() |
---|
1441 | #self._copy_parameters_state(self.orientation_params, |
---|
1442 | # self.state.orientation_params) |
---|
1443 | #self._copy_parameters_state(self.orientation_params_disp, |
---|
1444 | # self.state.orientation_params_disp) |
---|
1445 | #self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
1446 | #self._copy_parameters_state(self.fittable_param, self.state.fittable_param) |
---|
1447 | #self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
1448 | self.save_current_state_fit() |
---|
1449 | boxsizer1.Add(sizer) |
---|
1450 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
1451 | self.sizer3.Layout() |
---|
1452 | self.Layout() |
---|
1453 | self.Refresh() |
---|
1454 | self.SetScrollbars(20,20,25,65) |
---|
1455 | |
---|
1456 | |
---|
1457 | |
---|
1458 | class HelpWindow(wx.Frame): |
---|
1459 | def __init__(self, parent, id, title): |
---|
1460 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
---|
1461 | |
---|
1462 | from sans.models.CylinderModel import CylinderModel |
---|
1463 | model = CylinderModel() |
---|
1464 | |
---|
1465 | from danse.common.plottools.plottables import Data1D |
---|
1466 | data= Data1D(x=[1,2], y=[3,4], dy=[0.1, 0,1]) |
---|
1467 | |
---|
1468 | from fitpanel import PageInfo |
---|
1469 | myinfo = PageInfo(self, model, data=data ) |
---|
1470 | |
---|
1471 | ## add data |
---|
1472 | |
---|
1473 | from models import ModelList |
---|
1474 | mylist= ModelList() |
---|
1475 | |
---|
1476 | from sans.models.SphereModel import SphereModel |
---|
1477 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
1478 | from sans.models.DebyeModel import DebyeModel |
---|
1479 | from sans.models.LineModel import LineModel |
---|
1480 | name= "shapes" |
---|
1481 | list1= [SphereModel] |
---|
1482 | mylist.set_list( name, list1) |
---|
1483 | |
---|
1484 | name= "Shape-independent" |
---|
1485 | list1= [DebyeModel] |
---|
1486 | mylist.set_list( name, list1) |
---|
1487 | |
---|
1488 | name= "Structure Factors" |
---|
1489 | list1= [SquareWellStructure] |
---|
1490 | mylist.set_list( name, list1) |
---|
1491 | |
---|
1492 | name= "Added models" |
---|
1493 | list1= [LineModel] |
---|
1494 | mylist.set_list( name, list1) |
---|
1495 | |
---|
1496 | myinfo.model_list_box = mylist.get_list() |
---|
1497 | |
---|
1498 | self.page = FitPage(self, myinfo) |
---|
1499 | |
---|
1500 | |
---|
1501 | |
---|
1502 | self.Centre() |
---|
1503 | self.Show(True) |
---|
1504 | |
---|
1505 | |
---|
1506 | |
---|
1507 | if __name__=="__main__": |
---|
1508 | app = wx.App() |
---|
1509 | HelpWindow(None, -1, 'HelpWindow') |
---|
1510 | app.MainLoop() |
---|
1511 | |
---|