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