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