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 | from DataLoader.data_info import Data1D |
---|
12 | from sans.guiframe.events import StatusEvent |
---|
13 | from sans.guiframe.utils import format_number,check_float |
---|
14 | |
---|
15 | (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() |
---|
16 | _BOX_WIDTH = 76 |
---|
17 | _DATA_BOX_WIDTH = 300 |
---|
18 | SMEAR_SIZE_L = 0.00 |
---|
19 | SMEAR_SIZE_H = 0.00 |
---|
20 | |
---|
21 | import basepage |
---|
22 | from basepage import BasicPage |
---|
23 | from basepage import PageInfoEvent |
---|
24 | from sans.models.qsmearing import smear_selection |
---|
25 | |
---|
26 | |
---|
27 | class FitPage(BasicPage): |
---|
28 | """ |
---|
29 | FitPanel class contains fields allowing to display results when |
---|
30 | fitting a model and one data |
---|
31 | |
---|
32 | :note: For Fit to be performed the user should check at least one parameter |
---|
33 | on fit Panel window. |
---|
34 | """ |
---|
35 | |
---|
36 | def __init__(self,parent, color='rand'): |
---|
37 | """ |
---|
38 | Initialization of the Panel |
---|
39 | """ |
---|
40 | BasicPage.__init__(self, parent, color=color) |
---|
41 | |
---|
42 | ## draw sizer |
---|
43 | self._fill_datainfo_sizer() |
---|
44 | self.is_2D = None |
---|
45 | # get smear info from data |
---|
46 | self._get_smear_info() |
---|
47 | self._fill_model_sizer( self.sizer1) |
---|
48 | self._get_defult_custom_smear() |
---|
49 | self._fill_range_sizer() |
---|
50 | self._set_smear(self.data) |
---|
51 | self.Bind(EVT_CHI2_UPDATE, self.on_complete_chisqr) |
---|
52 | # bind key event |
---|
53 | self.Bind(wx.EVT_RIGHT_DOWN, self.on_right_down) |
---|
54 | self._set_bookmark_flag(False) |
---|
55 | self._set_save_flag(False) |
---|
56 | self._set_preview_flag(False) |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | def _on_fit_complete(self): |
---|
61 | """ |
---|
62 | When fit is complete ,reset the fit button label. |
---|
63 | """ |
---|
64 | self.btFit.SetLabel("Fit") |
---|
65 | self.bind_fit_button() |
---|
66 | |
---|
67 | def _is_2D(self): |
---|
68 | """ |
---|
69 | Check if data_name is Data2D |
---|
70 | |
---|
71 | :return: True or False |
---|
72 | |
---|
73 | """ |
---|
74 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
75 | self.enable2D: |
---|
76 | return True |
---|
77 | return False |
---|
78 | |
---|
79 | def _on_engine_change(self, name): |
---|
80 | """ |
---|
81 | get the current name of the fit engine type |
---|
82 | and update the panel accordingly |
---|
83 | """ |
---|
84 | |
---|
85 | self.engine_type = str(name) |
---|
86 | self.state.engine_type = self.engine_type |
---|
87 | if len(self.parameters) == 0: |
---|
88 | self.Layout() |
---|
89 | return |
---|
90 | self.Layout() |
---|
91 | self.Refresh() |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | def _fill_range_sizer(self): |
---|
96 | """ |
---|
97 | Fill the sizer containing the plotting range |
---|
98 | add access to npts |
---|
99 | """ |
---|
100 | is_2Ddata = False |
---|
101 | |
---|
102 | # Check if data is 2D |
---|
103 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
104 | self.enable2D: |
---|
105 | is_2Ddata = True |
---|
106 | |
---|
107 | title = "Fitting" |
---|
108 | #smear messages & titles |
---|
109 | smear_message_none = "No smearing is selected..." |
---|
110 | smear_message_dqdata = "The dQ data is being used for smearing..." |
---|
111 | smear_message_2d = "Higher accuracy is very time-expensive. Use it with care..." |
---|
112 | smear_message_new_ssmear = "Please enter only the value of interest to customize smearing..." |
---|
113 | smear_message_new_psmear = "Please enter both; the dQ will be generated by interpolation..." |
---|
114 | smear_message_2d_x_title = "<dQp>[1/A]:" |
---|
115 | smear_message_2d_y_title = "<dQs>[1/A]:" |
---|
116 | smear_message_pinhole_min_title = "dQ_low[1/A]:" |
---|
117 | smear_message_pinhole_max_title = "dQ_high[1/A]:" |
---|
118 | smear_message_slit_height_title = "Slit height[1/A]:" |
---|
119 | smear_message_slit_width_title = "Slit width[1/A]:" |
---|
120 | |
---|
121 | self._get_smear_info() |
---|
122 | |
---|
123 | #Sizers |
---|
124 | box_description_range = wx.StaticBox(self, -1,str(title)) |
---|
125 | boxsizer_range = wx.StaticBoxSizer(box_description_range, wx.VERTICAL) |
---|
126 | self.sizer_set_smearer = wx.BoxSizer(wx.VERTICAL) |
---|
127 | sizer_smearer = wx.BoxSizer(wx.HORIZONTAL) |
---|
128 | self.sizer_new_smear= wx.BoxSizer(wx.HORIZONTAL) |
---|
129 | self.sizer_set_masking = wx.BoxSizer(wx.HORIZONTAL) |
---|
130 | sizer_chi2 = wx.BoxSizer(wx.VERTICAL) |
---|
131 | smear_set_box= wx.StaticBox(self, -1,'Set Instrumental Smearing') |
---|
132 | sizer_smearer_box = wx.StaticBoxSizer(smear_set_box, wx.HORIZONTAL) |
---|
133 | sizer_smearer_box.SetMinSize((_DATA_BOX_WIDTH,85)) |
---|
134 | sizer_fit = wx.GridSizer(2, 4, 2, 6) |
---|
135 | |
---|
136 | # combobox for smear2d accuracy selection |
---|
137 | self.smear_accuracy = wx.ComboBox(self, -1,size=(50,-1),style=wx.CB_READONLY) |
---|
138 | self._set_accuracy_list() |
---|
139 | self.smear_accuracy.SetValue(self.smear2d_accuracy) |
---|
140 | self.smear_accuracy.SetSelection(0) |
---|
141 | self.smear_accuracy.SetToolTipString("'Higher' uses more Gaussian points for smearing computation.") |
---|
142 | |
---|
143 | wx.EVT_COMBOBOX(self.smear_accuracy,-1, self._on_select_accuracy) |
---|
144 | |
---|
145 | #Fit button |
---|
146 | self.btFit = wx.Button(self,wx.NewId(),'Fit', size=(88,25)) |
---|
147 | self.default_bt_colour = self.btFit.GetDefaultAttributes() |
---|
148 | self.btFit.Bind(wx.EVT_BUTTON, self._onFit,id= self.btFit.GetId()) |
---|
149 | self.btFit.SetToolTipString("Start fitting.") |
---|
150 | |
---|
151 | #textcntrl for custom resolution |
---|
152 | self.smear_pinhole_max = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
153 | text_enter_callback = self.onPinholeSmear) |
---|
154 | self.smear_pinhole_min = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
155 | text_enter_callback = self.onPinholeSmear) |
---|
156 | self.smear_slit_height= self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
157 | text_enter_callback = self.onSlitSmear) |
---|
158 | self.smear_slit_width = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH-25,20),style=wx.TE_PROCESS_ENTER, |
---|
159 | text_enter_callback = self.onSlitSmear) |
---|
160 | |
---|
161 | ## smear |
---|
162 | self.smear_data_left= BGTextCtrl(self, -1, size=(_BOX_WIDTH-25,20), style=0) |
---|
163 | self.smear_data_left.SetValue(str(self.dq_l)) |
---|
164 | self.smear_data_right = BGTextCtrl(self, -1, size=(_BOX_WIDTH-25,20), style=0) |
---|
165 | self.smear_data_right.SetValue(str(self.dq_r)) |
---|
166 | |
---|
167 | #set default values for smear |
---|
168 | self.smear_pinhole_max.SetValue(str(self.dx_max)) |
---|
169 | self.smear_pinhole_min.SetValue(str(self.dx_min)) |
---|
170 | self.smear_slit_height.SetValue(str(self.dxl)) |
---|
171 | self.smear_slit_width.SetValue(str(self.dxw)) |
---|
172 | |
---|
173 | #Filling the sizer containing instruments smearing info. |
---|
174 | self.disable_smearer = wx.RadioButton(self, -1, 'None', style=wx.RB_GROUP) |
---|
175 | self.enable_smearer = wx.RadioButton(self, -1, 'Use dQ Data') |
---|
176 | #self.enable_smearer.SetToolTipString("Click to use the loaded dQ data for smearing.") |
---|
177 | self.pinhole_smearer = wx.RadioButton(self, -1, 'Custom Pinhole Smear') |
---|
178 | #self.pinhole_smearer.SetToolTipString("Click to input custom resolution for pinhole smearing.") |
---|
179 | self.slit_smearer = wx.RadioButton(self, -1, 'Custom Slit Smear') |
---|
180 | #self.slit_smearer.SetToolTipString("Click to input custom resolution for slit smearing.") |
---|
181 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.disable_smearer.GetId()) |
---|
182 | self.Bind(wx.EVT_RADIOBUTTON, self.onSmear, id=self.enable_smearer.GetId()) |
---|
183 | self.Bind(wx.EVT_RADIOBUTTON, self.onPinholeSmear, id=self.pinhole_smearer.GetId()) |
---|
184 | self.Bind(wx.EVT_RADIOBUTTON, self.onSlitSmear, id=self.slit_smearer.GetId()) |
---|
185 | self.disable_smearer.SetValue(True) |
---|
186 | |
---|
187 | # add 4 types of smearing to the sizer |
---|
188 | sizer_smearer.Add( self.disable_smearer,0, wx.LEFT, 10) |
---|
189 | sizer_smearer.Add((10,10)) |
---|
190 | sizer_smearer.Add( self.enable_smearer) |
---|
191 | sizer_smearer.Add((10,10)) |
---|
192 | sizer_smearer.Add( self.pinhole_smearer ) |
---|
193 | sizer_smearer.Add((10,10)) |
---|
194 | sizer_smearer.Add( self.slit_smearer ) |
---|
195 | sizer_smearer.Add((10,10)) |
---|
196 | |
---|
197 | # StaticText for chi2, N(for fitting), Npts |
---|
198 | self.tcChi = BGTextCtrl(self, -1, "-", size=(75,20), style=0) |
---|
199 | self.tcChi.SetToolTipString("Chi2/Npts(Fit)") |
---|
200 | self.Npts_fit = BGTextCtrl(self, -1, "-", size=(75,20), style=0) |
---|
201 | self.Npts_fit.SetToolTipString(\ |
---|
202 | " Npts : number of points selected for fitting") |
---|
203 | self.Npts_total = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
204 | style=wx.TE_PROCESS_ENTER, |
---|
205 | text_enter_callback=self._onQrangeEnter) |
---|
206 | self.Npts_total.SetValue(format_number(self.npts_x)) |
---|
207 | self.Npts_total.SetToolTipString(\ |
---|
208 | " Total Npts : total number of data points") |
---|
209 | |
---|
210 | # Update and Draw button |
---|
211 | self.draw_button = wx.Button(self,wx.NewId(),'Compute', size=(88,24)) |
---|
212 | self.draw_button.Bind(wx.EVT_BUTTON, \ |
---|
213 | self._onDraw,id= self.draw_button.GetId()) |
---|
214 | self.draw_button.SetToolTipString("Compute and Draw.") |
---|
215 | |
---|
216 | box_description_1= wx.StaticText(self, -1,' Chi2/Npts') |
---|
217 | box_description_2= wx.StaticText(self, -1,'Npts(Fit)') |
---|
218 | box_description_3= wx.StaticText(self, -1,'Total Npts') |
---|
219 | box_description_3.SetToolTipString( \ |
---|
220 | " Total Npts : total number of data points") |
---|
221 | #box_description_4= wx.StaticText(self, -1,' ') |
---|
222 | |
---|
223 | |
---|
224 | sizer_fit.Add(box_description_1,0,0) |
---|
225 | sizer_fit.Add(box_description_2,0,0) |
---|
226 | sizer_fit.Add(box_description_3,0,0) |
---|
227 | sizer_fit.Add(self.draw_button,0,0) |
---|
228 | sizer_fit.Add(self.tcChi,0,0) |
---|
229 | sizer_fit.Add(self.Npts_fit ,0,0) |
---|
230 | sizer_fit.Add(self.Npts_total,0,0) |
---|
231 | sizer_fit.Add(self.btFit,0,0) |
---|
232 | |
---|
233 | # StaticText for smear |
---|
234 | #self.tcChi = wx.StaticText(self, -1, "-", style=wx.ALIGN_LEFT) |
---|
235 | self.smear_description_none = wx.StaticText(self, -1, smear_message_none , style=wx.ALIGN_LEFT) |
---|
236 | self.smear_description_dqdata = wx.StaticText(self, -1, smear_message_dqdata , style=wx.ALIGN_LEFT) |
---|
237 | self.smear_description_type = wx.StaticText(self, -1, "Type:" , style=wx.ALIGN_LEFT) |
---|
238 | self.smear_description_accuracy_type = wx.StaticText(self, -1, "Accuracy:" , style=wx.ALIGN_LEFT) |
---|
239 | self.smear_description_smear_type = BGTextCtrl(self, -1, size=(57,20), style=0) |
---|
240 | self.smear_description_smear_type.SetValue(str(self.dq_l)) |
---|
241 | self.SetBackgroundColour(self.GetParent().GetBackgroundColour()) |
---|
242 | self.smear_description_2d = wx.StaticText(self, -1, smear_message_2d , style=wx.ALIGN_LEFT) |
---|
243 | self.smear_message_new_s = wx.StaticText(self, -1, smear_message_new_ssmear , style=wx.ALIGN_LEFT) |
---|
244 | self.smear_message_new_p = wx.StaticText(self, -1, smear_message_new_psmear , style=wx.ALIGN_LEFT) |
---|
245 | self.smear_description_2d_x = wx.StaticText(self, -1, smear_message_2d_x_title , style=wx.ALIGN_LEFT) |
---|
246 | self.smear_description_2d_x.SetToolTipString(" dQp(parallel) in q_r direction.") |
---|
247 | self.smear_description_2d_y = wx.StaticText(self, -1, smear_message_2d_y_title , style=wx.ALIGN_LEFT) |
---|
248 | self.smear_description_2d_y.SetToolTipString(" dQs(perpendicular) in q_phi direction.") |
---|
249 | self.smear_description_pin_min = wx.StaticText(self, -1, smear_message_pinhole_min_title , style=wx.ALIGN_LEFT) |
---|
250 | self.smear_description_pin_max = wx.StaticText(self, -1, smear_message_pinhole_max_title , style=wx.ALIGN_LEFT) |
---|
251 | self.smear_description_slit_height = wx.StaticText(self, -1, smear_message_slit_height_title , style=wx.ALIGN_LEFT) |
---|
252 | self.smear_description_slit_width = wx.StaticText(self, -1, smear_message_slit_width_title , style=wx.ALIGN_LEFT) |
---|
253 | |
---|
254 | #arrange sizers |
---|
255 | #boxsizer1.Add( self.tcChi ) |
---|
256 | self.sizer_set_smearer.Add(sizer_smearer ) |
---|
257 | self.sizer_set_smearer.Add((10,10)) |
---|
258 | self.sizer_set_smearer.Add( self.smear_description_none,0, wx.CENTER, 10 ) |
---|
259 | self.sizer_set_smearer.Add( self.smear_description_dqdata,0, wx.CENTER, 10 ) |
---|
260 | self.sizer_set_smearer.Add( self.smear_description_2d,0, wx.CENTER, 10 ) |
---|
261 | self.sizer_new_smear.Add( self.smear_description_type,0, wx.CENTER, 10 ) |
---|
262 | self.sizer_new_smear.Add( self.smear_description_accuracy_type,0, wx.CENTER, 10 ) |
---|
263 | self.sizer_new_smear.Add( self.smear_accuracy ) |
---|
264 | self.sizer_new_smear.Add( self.smear_description_smear_type,0, wx.CENTER, 10 ) |
---|
265 | self.sizer_new_smear.Add((15,-1)) |
---|
266 | self.sizer_new_smear.Add( self.smear_description_2d_x,0, wx.CENTER, 10 ) |
---|
267 | self.sizer_new_smear.Add( self.smear_description_pin_min,0, wx.CENTER, 10 ) |
---|
268 | self.sizer_new_smear.Add( self.smear_description_slit_height,0, wx.CENTER, 10 ) |
---|
269 | |
---|
270 | self.sizer_new_smear.Add( self.smear_pinhole_min,0, wx.CENTER, 10 ) |
---|
271 | self.sizer_new_smear.Add( self.smear_slit_height,0, wx.CENTER, 10 ) |
---|
272 | self.sizer_new_smear.Add( self.smear_data_left,0, wx.CENTER, 10 ) |
---|
273 | self.sizer_new_smear.Add((20,-1)) |
---|
274 | self.sizer_new_smear.Add( self.smear_description_2d_y,0, wx.CENTER, 10 ) |
---|
275 | self.sizer_new_smear.Add( self.smear_description_pin_max,0, wx.CENTER, 10 ) |
---|
276 | self.sizer_new_smear.Add( self.smear_description_slit_width,0, wx.CENTER, 10 ) |
---|
277 | |
---|
278 | self.sizer_new_smear.Add( self.smear_pinhole_max,0, wx.CENTER, 10 ) |
---|
279 | self.sizer_new_smear.Add( self.smear_slit_width,0, wx.CENTER, 10 ) |
---|
280 | self.sizer_new_smear.Add( self.smear_data_right,0, wx.CENTER, 10 ) |
---|
281 | |
---|
282 | self.sizer_set_smearer.Add( self.smear_message_new_s,0, wx.CENTER, 10) |
---|
283 | self.sizer_set_smearer.Add( self.smear_message_new_p,0, wx.CENTER, 10) |
---|
284 | self.sizer_set_smearer.Add((5,2)) |
---|
285 | self.sizer_set_smearer.Add( self.sizer_new_smear,0, wx.CENTER, 10 ) |
---|
286 | |
---|
287 | # add all to chi2 sizer |
---|
288 | sizer_smearer_box.Add(self.sizer_set_smearer) |
---|
289 | sizer_chi2.Add(sizer_smearer_box) |
---|
290 | sizer_chi2.Add((-1,5)) |
---|
291 | |
---|
292 | # hide all smear messages and textctrl |
---|
293 | self._hide_all_smear_info() |
---|
294 | |
---|
295 | # get smear_selection |
---|
296 | self.current_smearer= smear_selection( self.data, self.model ) |
---|
297 | |
---|
298 | # Show only the relevant smear messages, etc |
---|
299 | if self.current_smearer == None: |
---|
300 | if not is_2Ddata: |
---|
301 | self.smear_description_none.Show(True) |
---|
302 | self.enable_smearer.Disable() |
---|
303 | else: |
---|
304 | self.smear_description_none.Show(True) |
---|
305 | #self.smear_description_2d.Show(True) |
---|
306 | #self.pinhole_smearer.Disable() |
---|
307 | self.slit_smearer.Disable() |
---|
308 | #self.enable_smearer.Disable() |
---|
309 | if self.data == None: |
---|
310 | self.slit_smearer.Disable() |
---|
311 | self.pinhole_smearer.Disable() |
---|
312 | self.enable_smearer.Disable() |
---|
313 | else: self._show_smear_sizer() |
---|
314 | boxsizer_range.Add(self.sizer_set_masking) |
---|
315 | #2D data? default |
---|
316 | is_2Ddata = False |
---|
317 | |
---|
318 | #check if it is 2D data |
---|
319 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
320 | self.enable2D: |
---|
321 | is_2Ddata = True |
---|
322 | |
---|
323 | self.sizer5.Clear(True) |
---|
324 | |
---|
325 | self.qmin = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), |
---|
326 | style=wx.TE_PROCESS_ENTER, |
---|
327 | text_enter_callback = self._onQrangeEnter) |
---|
328 | self.qmin.SetValue(str(self.qmin_x)) |
---|
329 | self.qmin.SetToolTipString("Minimun value of Q in linear scale.") |
---|
330 | |
---|
331 | self.qmax = self.ModelTextCtrl(self, -1,size=(_BOX_WIDTH,20), |
---|
332 | style=wx.TE_PROCESS_ENTER, |
---|
333 | text_enter_callback=self._onQrangeEnter) |
---|
334 | self.qmax.SetValue(str(self.qmax_x)) |
---|
335 | self.qmax.SetToolTipString("Maximum value of Q in linear scale.") |
---|
336 | """ |
---|
337 | self.theory_npts_tcrtl = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
338 | style=wx.TE_PROCESS_ENTER, |
---|
339 | text_enter_callback=self._onQrangeEnter) |
---|
340 | self.theory_npts_tcrtl.SetValue(format_number(self.npts_x)) |
---|
341 | self.theory_npts_tcrtl.SetToolTipString("Number of point to plot.") |
---|
342 | """ |
---|
343 | id = wx.NewId() |
---|
344 | self.reset_qrange =wx.Button(self,id,'Reset',size=(77,20)) |
---|
345 | |
---|
346 | self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked,id=id) |
---|
347 | self.reset_qrange.SetToolTipString("Reset Q range to the default values") |
---|
348 | |
---|
349 | sizer_horizontal=wx.BoxSizer(wx.HORIZONTAL) |
---|
350 | sizer= wx.GridSizer(2, 4, 2, 6) |
---|
351 | |
---|
352 | self.btEditMask = wx.Button(self,wx.NewId(),'Editor', size=(88,23)) |
---|
353 | self.btEditMask.Bind(wx.EVT_BUTTON, self._onMask,id= self.btEditMask.GetId()) |
---|
354 | self.btEditMask.SetToolTipString("Edit Mask.") |
---|
355 | self.EditMask_title = wx.StaticText(self, -1, ' Masking(2D)') |
---|
356 | |
---|
357 | sizer.Add(wx.StaticText(self, -1, 'Q range')) |
---|
358 | sizer.Add(wx.StaticText(self, -1, ' Min[1/A]')) |
---|
359 | sizer.Add(wx.StaticText(self, -1, ' Max[1/A]')) |
---|
360 | sizer.Add(self.EditMask_title) |
---|
361 | #sizer.Add(wx.StaticText(self, -1, '')) |
---|
362 | sizer.Add(self.reset_qrange) |
---|
363 | sizer.Add(self.qmin) |
---|
364 | sizer.Add(self.qmax) |
---|
365 | #sizer.Add(self.theory_npts_tcrtl) |
---|
366 | sizer.Add(self.btEditMask) |
---|
367 | boxsizer_range.Add(sizer_chi2) |
---|
368 | boxsizer_range.Add((10,10)) |
---|
369 | boxsizer_range.Add(sizer) |
---|
370 | |
---|
371 | boxsizer_range.Add((10,15)) |
---|
372 | boxsizer_range.Add(sizer_fit) |
---|
373 | if is_2Ddata: |
---|
374 | self.btEditMask.Enable() |
---|
375 | self.EditMask_title.Enable() |
---|
376 | else: |
---|
377 | self.btEditMask.Disable() |
---|
378 | self.EditMask_title.Disable() |
---|
379 | ## save state |
---|
380 | self.save_current_state() |
---|
381 | self.sizer5.Add(boxsizer_range,0, wx.EXPAND | wx.ALL, 10) |
---|
382 | self.sizer5.Layout() |
---|
383 | |
---|
384 | def _fill_datainfo_sizer(self): |
---|
385 | """ |
---|
386 | fill sizer 0 with data info |
---|
387 | """ |
---|
388 | ## no loaded data , don't fill the sizer |
---|
389 | if self.data is None: |
---|
390 | data_min = "" |
---|
391 | data_max = "" |
---|
392 | data_name = "" |
---|
393 | else: |
---|
394 | data_name = self.data.name |
---|
395 | #set maximum range for x in linear scale |
---|
396 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
397 | # Minimum value of data |
---|
398 | data_min = min(self.data.x) |
---|
399 | # Maximum value of data |
---|
400 | data_max = max(self.data.x) |
---|
401 | else: |
---|
402 | ## Minimum value of data |
---|
403 | data_min = 0 |
---|
404 | x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
405 | y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
406 | ## Maximum value of data |
---|
407 | data_max = math.sqrt(x*x + y*y) |
---|
408 | ## set q range to plot |
---|
409 | self.qmin_x = data_min |
---|
410 | self.qmax_x = data_max |
---|
411 | box_description= wx.StaticBox(self, -1, 'Data') |
---|
412 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
413 | #---------------------------------------------------------- |
---|
414 | sizer_data = wx.BoxSizer(wx.HORIZONTAL) |
---|
415 | #Filling the sizer containing data related fields |
---|
416 | #self.dataSource = wx.StaticText(self, -1,str(self.data.name)) |
---|
417 | self.dataSource = BGTextCtrl(self, -1) |
---|
418 | self.dataSource.SetValue(str(data_name)) |
---|
419 | #self.dataSource.SetEditable(False) |
---|
420 | self.dataSource.SetMinSize((_DATA_BOX_WIDTH, -1)) |
---|
421 | sizer_data.Add(wx.StaticText(self, -1, 'Source Name : ')) |
---|
422 | sizer_data.Add(self.dataSource ) |
---|
423 | sizer_data.Add( (0,5) ) |
---|
424 | |
---|
425 | #---------sizer 2 draw-------------------------------- |
---|
426 | text4_3 = wx.StaticText(self, -1, 'Total Q Range (1/A)', |
---|
427 | style=wx.ALIGN_LEFT) |
---|
428 | sizer_range = wx.BoxSizer(wx.HORIZONTAL) |
---|
429 | sizer_range.Add( text4_3 ,0, wx.RIGHT, 10) |
---|
430 | self.minimum_q = BGTextCtrl(self, -1, size=(_BOX_WIDTH,20)) |
---|
431 | self.minimum_q.SetValue(str(data_min)) |
---|
432 | self.maximum_q = BGTextCtrl(self, -1,size=(_BOX_WIDTH,20)) |
---|
433 | self.maximum_q.SetValue(str(data_max)) |
---|
434 | sizer_range.Add(wx.StaticText(self, -1, "Min: "),0, wx.LEFT, 10) |
---|
435 | sizer_range.Add(self.minimum_q,0, wx.LEFT, 10) |
---|
436 | sizer_range.Add(wx.StaticText(self, -1, "Max: "),0, wx.LEFT, 10) |
---|
437 | sizer_range.Add(self.maximum_q,0, wx.LEFT, 10) |
---|
438 | boxsizer1.Add(sizer_data,0, wx.ALL, 10) |
---|
439 | boxsizer1.Add(sizer_range, 0 , wx.LEFT, 10) |
---|
440 | #------------------------------------------------------------ |
---|
441 | self.sizer0.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
442 | self.sizer0.Layout() |
---|
443 | |
---|
444 | def _fill_model_sizer(self, sizer): |
---|
445 | """ |
---|
446 | fill sizer containing model info |
---|
447 | """ |
---|
448 | ##Add model function Details button in fitpanel. |
---|
449 | ##The following 3 lines are for Mac. Let JHC know before modifying... |
---|
450 | title = "Model" |
---|
451 | box_description= wx.StaticBox(self, -1,str(title)) |
---|
452 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
453 | |
---|
454 | id = wx.NewId() |
---|
455 | self.model_help =wx.Button(self,id,'Details', size=(80,23)) |
---|
456 | self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked,id=id) |
---|
457 | self.model_help.SetToolTipString("Model Function Help") |
---|
458 | id = wx.NewId() |
---|
459 | self.model_view = wx.Button(self, id,"Switch to 2D", size=(80, 23)) |
---|
460 | self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) |
---|
461 | hint = "toggle view of model from 1D to 2D or 2D from 1D" |
---|
462 | self.model_view.SetToolTipString(hint) |
---|
463 | |
---|
464 | self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', style=wx.RB_GROUP) |
---|
465 | self.shape_indep_rbutton = wx.RadioButton(self, -1, "Shape-Independent") |
---|
466 | self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
467 | self.plugin_rbutton = wx.RadioButton(self, -1, "Customized Models") |
---|
468 | |
---|
469 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
470 | id= self.shape_rbutton.GetId()) |
---|
471 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
472 | id= self.shape_indep_rbutton.GetId()) |
---|
473 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
474 | id= self.struct_rbutton.GetId()) |
---|
475 | self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
476 | id= self.plugin_rbutton.GetId()) |
---|
477 | #MAC needs SetValue |
---|
478 | self.shape_rbutton.SetValue(True) |
---|
479 | |
---|
480 | sizer_radiobutton = wx.GridSizer(2, 3, 5, 5) |
---|
481 | sizer_radiobutton.Add(self.shape_rbutton) |
---|
482 | sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
483 | #sizer_radiobutton.Add((5, 5)) |
---|
484 | sizer_radiobutton.Add(self.model_view,1, wx.LEFT, 20) |
---|
485 | sizer_radiobutton.Add(self.plugin_rbutton) |
---|
486 | sizer_radiobutton.Add(self.struct_rbutton) |
---|
487 | #sizer_radiobutton.Add((5, 5)) |
---|
488 | sizer_radiobutton.Add(self.model_help,1, wx.LEFT, 20) |
---|
489 | |
---|
490 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
491 | mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
492 | |
---|
493 | self.text1 = wx.StaticText(self,-1,"" ) |
---|
494 | self.text2 = wx.StaticText(self,-1,"P(Q)*S(Q)" ) |
---|
495 | self.mutifactor_text = wx.StaticText( self,-1,"No. of Shells: ") |
---|
496 | self.mutifactor_text1 = wx.StaticText( self,-1,"" ) |
---|
497 | self.show_sld_button = wx.Button( self,-1,"Show SLD Profile" ) |
---|
498 | self.show_sld_button.Bind(wx.EVT_BUTTON,self._on_show_sld) |
---|
499 | |
---|
500 | self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) |
---|
501 | if self.model!= None: |
---|
502 | self.formfactorbox.SetValue(self.model.name) |
---|
503 | self.structurebox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
504 | self.multifactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
505 | self.initialize_combox() |
---|
506 | wx.EVT_COMBOBOX(self.formfactorbox, -1, self._on_select_model) |
---|
507 | |
---|
508 | wx.EVT_COMBOBOX(self.structurebox, -1, self._on_select_model) |
---|
509 | wx.EVT_COMBOBOX(self.multifactorbox, -1, self._on_select_model) |
---|
510 | ## check model type to show sizer |
---|
511 | if self.model !=None: |
---|
512 | self._set_model_sizer_selection(self.model) |
---|
513 | |
---|
514 | sizer_selection.Add(self.text1) |
---|
515 | sizer_selection.Add((5, 5)) |
---|
516 | sizer_selection.Add(self.formfactorbox) |
---|
517 | sizer_selection.Add((5, 5)) |
---|
518 | sizer_selection.Add(self.text2) |
---|
519 | sizer_selection.Add((5, 5)) |
---|
520 | sizer_selection.Add(self.structurebox) |
---|
521 | |
---|
522 | mutifactor_selection.Add((10,5)) |
---|
523 | mutifactor_selection.Add(self.mutifactor_text) |
---|
524 | mutifactor_selection.Add(self.multifactorbox) |
---|
525 | mutifactor_selection.Add((5, 5)) |
---|
526 | mutifactor_selection.Add(self.mutifactor_text1) |
---|
527 | mutifactor_selection.Add((10, 5)) |
---|
528 | mutifactor_selection.Add(self.show_sld_button) |
---|
529 | |
---|
530 | |
---|
531 | boxsizer1.Add(sizer_radiobutton) |
---|
532 | boxsizer1.Add((10, 10)) |
---|
533 | boxsizer1.Add(sizer_selection) |
---|
534 | boxsizer1.Add((10, 10)) |
---|
535 | boxsizer1.Add(mutifactor_selection) |
---|
536 | |
---|
537 | self._set_multfactor_combobox() |
---|
538 | self.multifactorbox.SetSelection(1) |
---|
539 | self.show_sld_button.Hide() |
---|
540 | sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
541 | sizer.Layout() |
---|
542 | |
---|
543 | def _set_sizer_dispersion(self): |
---|
544 | """ |
---|
545 | draw sizer with gaussian dispersity parameters |
---|
546 | """ |
---|
547 | self.fittable_param=[] |
---|
548 | self.fixed_param=[] |
---|
549 | self.orientation_params_disp=[] |
---|
550 | |
---|
551 | self.sizer4_4.Clear(True) |
---|
552 | if self.model==None: |
---|
553 | ##no model is selected |
---|
554 | return |
---|
555 | if not self.enable_disp.GetValue(): |
---|
556 | ## the user didn't select dispersity display |
---|
557 | return |
---|
558 | |
---|
559 | self._reset_dispersity() |
---|
560 | |
---|
561 | ## fill a sizer with the combobox to select dispersion type |
---|
562 | #sizer_select_dispers = wx.BoxSizer(wx.HORIZONTAL) |
---|
563 | model_disp = wx.StaticText(self, -1, 'Function') |
---|
564 | |
---|
565 | import sans.models.dispersion_models |
---|
566 | self.polydisp= sans.models.dispersion_models.models |
---|
567 | |
---|
568 | ix = 0 |
---|
569 | iy = 0 |
---|
570 | disp = wx.StaticText(self, -1, ' ') |
---|
571 | self.sizer4_4.Add(disp,( iy, ix),(1,1), |
---|
572 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
573 | ix += 1 |
---|
574 | values = wx.StaticText(self, -1, 'PD[ratio]') |
---|
575 | polytext = "Polydispersity (= STD/mean); " |
---|
576 | polytext += "the standard deviation over the mean value." |
---|
577 | values.SetToolTipString(polytext) |
---|
578 | |
---|
579 | self.sizer4_4.Add(values,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
580 | 0) |
---|
581 | ix +=2 |
---|
582 | self.text_disp_1 = wx.StaticText(self, -1, '') |
---|
583 | self.sizer4_4.Add( self.text_disp_1,(iy, ix),(1,1),\ |
---|
584 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
585 | |
---|
586 | |
---|
587 | ix +=1 |
---|
588 | self.text_disp_min = wx.StaticText(self, -1, 'Min') |
---|
589 | self.sizer4_4.Add(self.text_disp_min,(iy, ix),(1,1),\ |
---|
590 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
591 | |
---|
592 | ix +=1 |
---|
593 | self.text_disp_max = wx.StaticText(self, -1, 'Max') |
---|
594 | self.sizer4_4.Add(self.text_disp_max,(iy, ix),(1,1),\ |
---|
595 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
596 | |
---|
597 | ix += 1 |
---|
598 | npts = wx.StaticText(self, -1, 'Npts') |
---|
599 | npts.SetToolTipString("Number of sampling points for the numerical\n\ |
---|
600 | integration over the distribution function.") |
---|
601 | self.sizer4_4.Add(npts,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
602 | ix += 1 |
---|
603 | nsigmas = wx.StaticText(self, -1, 'Nsigs') |
---|
604 | nsigmas.SetToolTipString(" Number of sigmas between which the range\n\ |
---|
605 | of the distribution function will be used for weighting. \n\ |
---|
606 | The value '3' covers 99.5% for Gaussian distribution \n\ |
---|
607 | function. Note: Not recommended to change this value.") |
---|
608 | self.sizer4_4.Add(nsigmas,( iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
609 | 0) |
---|
610 | ix +=1 |
---|
611 | self.sizer4_4.Add(model_disp,(iy, ix),(1,1),\ |
---|
612 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
613 | |
---|
614 | if self.engine_type=="park": |
---|
615 | self.text_disp_max.Show(True) |
---|
616 | self.text_disp_min.Show(True) |
---|
617 | |
---|
618 | for item in self.model.dispersion.keys(): |
---|
619 | if not item in self.model.orientation_params: |
---|
620 | if not self.disp_cb_dict.has_key(item): |
---|
621 | self.disp_cb_dict[item]= None |
---|
622 | name0="Distribution of " + item |
---|
623 | name1=item+".width" |
---|
624 | name2=item+".npts" |
---|
625 | name3=item+".nsigmas" |
---|
626 | if not self.model.details.has_key(name1): |
---|
627 | self.model.details [name1] = ["",None,None] |
---|
628 | |
---|
629 | iy += 1 |
---|
630 | for p in self.model.dispersion[item].keys(): |
---|
631 | |
---|
632 | if p=="width": |
---|
633 | ix = 0 |
---|
634 | cb = wx.CheckBox(self, -1, name0, (10, 10)) |
---|
635 | cb.SetToolTipString("Check mark to fit") |
---|
636 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
637 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
638 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
639 | 5) |
---|
640 | ix = 1 |
---|
641 | value= self.model.getParam(name1) |
---|
642 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20) |
---|
643 | ,style=wx.TE_PROCESS_ENTER) |
---|
644 | ctl1.SetLabel('PD[ratio]') |
---|
645 | poly_text = "Polydispersity (STD/mean) of %s\n" % item |
---|
646 | poly_text += "STD: the standard deviation" |
---|
647 | poly_text += " from the mean value." |
---|
648 | ctl1.SetToolTipString(poly_text) |
---|
649 | ctl1.SetValue(str (format_number(value, True))) |
---|
650 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
651 | ## text to show error sign |
---|
652 | ix = 2 |
---|
653 | text2=wx.StaticText(self, -1, '+/-') |
---|
654 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
655 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
656 | text2.Hide() |
---|
657 | |
---|
658 | ix = 3 |
---|
659 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20), |
---|
660 | style=0) |
---|
661 | |
---|
662 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), |
---|
663 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
664 | |
---|
665 | ctl2.Hide() |
---|
666 | |
---|
667 | ix = 4 |
---|
668 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2, |
---|
669 | 20), style=wx.TE_PROCESS_ENTER, |
---|
670 | text_enter_callback = self._onparamRangeEnter) |
---|
671 | |
---|
672 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), |
---|
673 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
674 | |
---|
675 | |
---|
676 | ix = 5 |
---|
677 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/2, |
---|
678 | 20), style=wx.TE_PROCESS_ENTER, |
---|
679 | text_enter_callback = self._onparamRangeEnter) |
---|
680 | |
---|
681 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), |
---|
682 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
683 | |
---|
684 | |
---|
685 | if self.engine_type=="park": |
---|
686 | ctl3.Show(True) |
---|
687 | ctl4.Show(True) |
---|
688 | |
---|
689 | elif p=="npts": |
---|
690 | ix = 6 |
---|
691 | value= self.model.getParam(name2) |
---|
692 | Tctl = self.ModelTextCtrl(self, -1, |
---|
693 | size=(_BOX_WIDTH/2.2,20), |
---|
694 | style=wx.TE_PROCESS_ENTER) |
---|
695 | |
---|
696 | Tctl.SetValue(str (format_number(value))) |
---|
697 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
698 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
699 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
700 | None, None,None]) |
---|
701 | elif p=="nsigmas": |
---|
702 | ix = 7 |
---|
703 | value= self.model.getParam(name3) |
---|
704 | Tct2 = self.ModelTextCtrl(self, -1, |
---|
705 | size=(_BOX_WIDTH/2.2,20), |
---|
706 | style=wx.TE_PROCESS_ENTER) |
---|
707 | |
---|
708 | Tct2.SetValue(str (format_number(value))) |
---|
709 | self.sizer4_4.Add(Tct2, (iy,ix),(1,1), |
---|
710 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
711 | #ix +=1 |
---|
712 | #self.sizer4_4.Add((20,20), (iy,ix),(1,1), |
---|
713 | # wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
714 | |
---|
715 | self.fixed_param.append([None, name3, Tct2, |
---|
716 | None, None, None, |
---|
717 | None, None]) |
---|
718 | |
---|
719 | |
---|
720 | ix = 8 |
---|
721 | disp_box = wx.ComboBox(self, -1,size=(65,-1), |
---|
722 | style=wx.CB_READONLY, name = '%s'% name1) |
---|
723 | for key, value in self.polydisp.iteritems(): |
---|
724 | name_disp = str(key) |
---|
725 | disp_box.Append(name_disp,value) |
---|
726 | disp_box.SetStringSelection("gaussian") |
---|
727 | wx.EVT_COMBOBOX(disp_box,-1, self._on_disp_func) |
---|
728 | self.sizer4_4.Add(disp_box,(iy,ix),(1,1), wx.EXPAND) |
---|
729 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
730 | ctl2, ctl3, ctl4, disp_box]) |
---|
731 | |
---|
732 | ix =0 |
---|
733 | iy +=1 |
---|
734 | self.sizer4_4.Add((20,20),(iy,ix),(1,1), |
---|
735 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
736 | first_orient = True |
---|
737 | for item in self.model.dispersion.keys(): |
---|
738 | if item in self.model.orientation_params: |
---|
739 | if not self.disp_cb_dict.has_key(item): |
---|
740 | self.disp_cb_dict[item]= None |
---|
741 | name0="Distribution of " + item |
---|
742 | name1=item+".width" |
---|
743 | name2=item+".npts" |
---|
744 | name3=item+".nsigmas" |
---|
745 | |
---|
746 | if not self.model.details.has_key(name1): |
---|
747 | self.model.details [name1] = ["",None,None] |
---|
748 | |
---|
749 | |
---|
750 | iy += 1 |
---|
751 | for p in self.model.dispersion[item].keys(): |
---|
752 | |
---|
753 | if p=="width": |
---|
754 | ix = 0 |
---|
755 | cb = wx.CheckBox(self, -1, name0, (10, 10)) |
---|
756 | cb.SetToolTipString("Check mark to fit") |
---|
757 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
758 | self.sizer4_4.Add( cb,( iy, ix),(1,1), |
---|
759 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, |
---|
760 | 5) |
---|
761 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
762 | self.enable2D: |
---|
763 | cb.Show(True) |
---|
764 | elif cb.IsShown(): |
---|
765 | cb.Hide() |
---|
766 | ix = 1 |
---|
767 | value= self.model.getParam(name1) |
---|
768 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.3, |
---|
769 | 20),style=wx.TE_PROCESS_ENTER) |
---|
770 | poly_tip = "Absolute Sigma for %s." % item |
---|
771 | ctl1.SetToolTipString(poly_tip) |
---|
772 | ctl1.SetValue(str (format_number(value, True))) |
---|
773 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
774 | self.enable2D: |
---|
775 | if first_orient: |
---|
776 | values.SetLabel('PD[ratio], Sig[deg]') |
---|
777 | poly_text = "PD(polydispersity for lengths):\n" |
---|
778 | poly_text += "It should be a value between" |
---|
779 | poly_text += "0 and 1\n" |
---|
780 | poly_text += "Sigma for angles: \n" |
---|
781 | poly_text += "It is the STD (ratio*mean)" |
---|
782 | poly_text += " of the distribution.\n " |
---|
783 | |
---|
784 | values.SetToolTipString(poly_text) |
---|
785 | first_orient = False |
---|
786 | ctl1.Show(True) |
---|
787 | elif ctl1.IsShown(): |
---|
788 | ctl1.Hide() |
---|
789 | |
---|
790 | self.sizer4_4.Add(ctl1, (iy,ix),(1,1),wx.EXPAND) |
---|
791 | ## text to show error sign |
---|
792 | ix = 2 |
---|
793 | text2=wx.StaticText(self, -1, '+/-') |
---|
794 | self.sizer4_4.Add(text2,(iy, ix),(1,1), |
---|
795 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
796 | text2.Hide() |
---|
797 | |
---|
798 | ix = 3 |
---|
799 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.3,20), |
---|
800 | style=0) |
---|
801 | |
---|
802 | self.sizer4_4.Add(ctl2, (iy,ix),(1,1), |
---|
803 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
804 | ctl2.Hide() |
---|
805 | |
---|
806 | ix = 4 |
---|
807 | ctl3 = self.ModelTextCtrl(self, -1, |
---|
808 | size=(_BOX_WIDTH/2,20), |
---|
809 | style=wx.TE_PROCESS_ENTER, |
---|
810 | text_enter_callback = self._onparamRangeEnter) |
---|
811 | |
---|
812 | self.sizer4_4.Add(ctl3, (iy,ix),(1,1), |
---|
813 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
814 | |
---|
815 | ctl3.Hide() |
---|
816 | |
---|
817 | ix = 5 |
---|
818 | ctl4 = self.ModelTextCtrl(self, -1, |
---|
819 | size=(_BOX_WIDTH/2,20), style=wx.TE_PROCESS_ENTER, |
---|
820 | text_enter_callback = self._onparamRangeEnter) |
---|
821 | self.sizer4_4.Add(ctl4, (iy,ix),(1,1), |
---|
822 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
823 | ctl4.Hide() |
---|
824 | |
---|
825 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
826 | self.enable2D: |
---|
827 | ctl3.Show(True) |
---|
828 | ctl4.Show(True) |
---|
829 | |
---|
830 | elif p=="npts": |
---|
831 | ix = 6 |
---|
832 | value= self.model.getParam(name2) |
---|
833 | Tctl = self.ModelTextCtrl(self, -1, |
---|
834 | size=(_BOX_WIDTH/2.2, 20), |
---|
835 | style=wx.TE_PROCESS_ENTER) |
---|
836 | |
---|
837 | Tctl.SetValue(str (format_number(value))) |
---|
838 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
839 | self.enable2D: |
---|
840 | Tctl.Show(True) |
---|
841 | else: |
---|
842 | Tctl.Hide() |
---|
843 | self.sizer4_4.Add(Tctl, (iy,ix),(1,1), |
---|
844 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
845 | self.fixed_param.append([None,name2, Tctl,None,None, |
---|
846 | None, None,None]) |
---|
847 | self.orientation_params_disp.append([None,name2, |
---|
848 | Tctl,None,None, |
---|
849 | None, None,None]) |
---|
850 | elif p=="nsigmas": |
---|
851 | ix = 7 |
---|
852 | value= self.model.getParam(name3) |
---|
853 | Tct2 = self.ModelTextCtrl(self, -1, |
---|
854 | size=(_BOX_WIDTH/2.2,20), |
---|
855 | style=wx.TE_PROCESS_ENTER) |
---|
856 | |
---|
857 | Tct2.SetValue(str (format_number(value))) |
---|
858 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
859 | self.enable2D: |
---|
860 | Tct2.Show(True) |
---|
861 | else: |
---|
862 | Tct2.Hide() |
---|
863 | self.sizer4_4.Add(Tct2, (iy,ix),(1,1), |
---|
864 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
865 | |
---|
866 | |
---|
867 | self.fixed_param.append([None,name3, Tct2 |
---|
868 | ,None,None, None, None,None]) |
---|
869 | |
---|
870 | self.orientation_params_disp.append([None,name3, |
---|
871 | Tct2 ,None,None, None, None,None]) |
---|
872 | |
---|
873 | |
---|
874 | ix = 8 |
---|
875 | disp_box = wx.ComboBox(self, -1,size=(65,-1), |
---|
876 | style=wx.CB_READONLY, name = '%s'% name1) |
---|
877 | for key, value in self.polydisp.iteritems(): |
---|
878 | name_disp = str(key) |
---|
879 | disp_box.Append(name_disp,value) |
---|
880 | disp_box.SetStringSelection("gaussian") |
---|
881 | wx.EVT_COMBOBOX(disp_box,-1, self._on_disp_func) |
---|
882 | self.sizer4_4.Add(disp_box,(iy,ix),(1,1), wx.EXPAND) |
---|
883 | self.fittable_param.append([cb,name1,ctl1,text2, |
---|
884 | ctl2, ctl3, ctl4, disp_box]) |
---|
885 | self.orientation_params_disp.append([cb,name1,ctl1, |
---|
886 | text2, ctl2, ctl3, ctl4, disp_box]) |
---|
887 | |
---|
888 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
889 | self.enable2D: |
---|
890 | disp_box.Show(True) |
---|
891 | else: |
---|
892 | disp_box.Hide() |
---|
893 | |
---|
894 | |
---|
895 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
---|
896 | |
---|
897 | self.state.model = self.model.clone() |
---|
898 | ## save state into |
---|
899 | self.state.cb1 = self.cb1.GetValue() |
---|
900 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
901 | self._copy_parameters_state(self.orientation_params_disp, |
---|
902 | self.state.orientation_params_disp) |
---|
903 | self._copy_parameters_state(self.fittable_param, |
---|
904 | self.state.fittable_param) |
---|
905 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
906 | |
---|
907 | |
---|
908 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
909 | " Selected Distribution: Gaussian")) |
---|
910 | #Fill the list of fittable parameters |
---|
911 | self.select_all_param(event=None) |
---|
912 | |
---|
913 | self.Layout() |
---|
914 | |
---|
915 | |
---|
916 | def _onDraw(self, event): |
---|
917 | """ |
---|
918 | Update and Draw the model |
---|
919 | """ |
---|
920 | if self.model ==None: |
---|
921 | msg="Please select a Model first..." |
---|
922 | wx.MessageBox(msg, 'Info') |
---|
923 | |
---|
924 | return |
---|
925 | flag = self._update_paramv_on_fit() |
---|
926 | self._onparamEnter_helper() |
---|
927 | if not flag: |
---|
928 | msg= "The parameters are invalid" |
---|
929 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) |
---|
930 | return |
---|
931 | |
---|
932 | |
---|
933 | def _onFit(self, event): |
---|
934 | """ |
---|
935 | Allow to fit |
---|
936 | """ |
---|
937 | if self.data is None: |
---|
938 | msg = "Please get Data first..." |
---|
939 | wx.MessageBox(msg, 'Info') |
---|
940 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
941 | "Fit: %s" % msg)) |
---|
942 | return |
---|
943 | if self.model is None: |
---|
944 | msg = "Please select a Model first..." |
---|
945 | wx.MessageBox(msg, 'Info') |
---|
946 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
947 | "Fit: %s"%msg, type="stop")) |
---|
948 | return |
---|
949 | |
---|
950 | if len(self.param_toFit) <= 0: |
---|
951 | msg= "Select at least one parameter to fit" |
---|
952 | wx.MessageBox(msg, 'Info') |
---|
953 | wx.PostEvent(self._manager.parent, StatusEvent(status= msg, |
---|
954 | type="stop" )) |
---|
955 | return |
---|
956 | |
---|
957 | flag = self._update_paramv_on_fit() |
---|
958 | |
---|
959 | if not flag: |
---|
960 | msg= "Fitting range or parameters are invalid" |
---|
961 | wx.PostEvent(self.parent.parent, StatusEvent(status= msg, |
---|
962 | type="stop")) |
---|
963 | return |
---|
964 | |
---|
965 | self.select_param(event =None) |
---|
966 | |
---|
967 | #Clear errors if exist from previous fitting |
---|
968 | #self._clear_Err_on_Fit() |
---|
969 | |
---|
970 | # Remove or do not allow fitting on the Q=0 point, especially |
---|
971 | # when y(q=0)=None at x[0]. |
---|
972 | self.qmin_x = float(self.qmin.GetValue()) |
---|
973 | self.qmax_x = float( self.qmax.GetValue()) |
---|
974 | self._manager._reset_schedule_problem(value=0) |
---|
975 | self._manager.schedule_for_fit(uid=self.uid,value=1, fitproblem =None) |
---|
976 | self._manager.set_fit_range(uid=self.uid,qmin= self.qmin_x, |
---|
977 | qmax= self.qmax_x) |
---|
978 | |
---|
979 | #single fit |
---|
980 | self._manager.onFit() |
---|
981 | self.btFit.SetLabel("Stop") |
---|
982 | self.bind_fit_button() |
---|
983 | |
---|
984 | def bind_fit_button(self): |
---|
985 | """ |
---|
986 | bind the fit button to either fit handler or stop fit handler |
---|
987 | """ |
---|
988 | self.btFit.Unbind(event=wx.EVT_BUTTON, id= self.btFit.GetId()) |
---|
989 | if self.btFit.GetLabel().lower() == "stop": |
---|
990 | self.btFit.SetForegroundColour('red') |
---|
991 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._StopFit, |
---|
992 | id=self.btFit.GetId()) |
---|
993 | elif self.btFit.GetLabel().lower() == "fit": |
---|
994 | self.btFit.SetDefault() |
---|
995 | self.btFit.SetForegroundColour('black') |
---|
996 | #self.btFit.SetBackgroundColour(self.default_bt_colour) |
---|
997 | self.btFit.Bind(event=wx.EVT_BUTTON, handler=self._onFit, |
---|
998 | id=self.btFit.GetId()) |
---|
999 | else: |
---|
1000 | msg = "FitPage: fit button has unknown label" |
---|
1001 | raise ValuerError, msg |
---|
1002 | self._manager._reset_schedule_problem(value=0) |
---|
1003 | |
---|
1004 | |
---|
1005 | def _StopFit(self, event): |
---|
1006 | """ |
---|
1007 | Stop fit |
---|
1008 | """ |
---|
1009 | #if self.engine_type=="scipy": |
---|
1010 | self._manager.stop_fit(self.uid) |
---|
1011 | self._manager._reset_schedule_problem(value=0) |
---|
1012 | self._on_fit_complete() |
---|
1013 | |
---|
1014 | def _on_select_model(self, event=None): |
---|
1015 | """ |
---|
1016 | call back for model selection |
---|
1017 | """ |
---|
1018 | |
---|
1019 | |
---|
1020 | self._on_select_model_helper() |
---|
1021 | self.set_model_param_sizer(self.model) |
---|
1022 | if self.model is None: |
---|
1023 | self._set_bookmark_flag(False) |
---|
1024 | self._keep.Enable(False) |
---|
1025 | self._set_save_flag(False) |
---|
1026 | self.enable_disp.SetValue(False) |
---|
1027 | self.disable_disp.SetValue(True) |
---|
1028 | try: |
---|
1029 | self.set_dispers_sizer() |
---|
1030 | except: |
---|
1031 | pass |
---|
1032 | self.btFit.SetFocus() |
---|
1033 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
1034 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
1035 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
1036 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
1037 | |
---|
1038 | self.state.structurecombobox = self.structurebox.GetCurrentSelection() |
---|
1039 | self.state.formfactorcombobox = self.formfactorbox.GetCurrentSelection() |
---|
1040 | |
---|
1041 | if self.model != None: |
---|
1042 | if self.data != None: |
---|
1043 | self._set_bookmark_flag(True) |
---|
1044 | self._keep.Enable(True) |
---|
1045 | #self._set_save_flag(True) |
---|
1046 | # Reset smearer, model and data |
---|
1047 | self._set_smear(self.data) |
---|
1048 | try: |
---|
1049 | # update smearer sizer |
---|
1050 | self.onSmear(None) |
---|
1051 | temp_smear = None |
---|
1052 | if self.enable_smearer.GetValue(): |
---|
1053 | # Set the smearer environments |
---|
1054 | temp_smear = self.smearer |
---|
1055 | except: |
---|
1056 | raise |
---|
1057 | ## error occured on chisqr computation |
---|
1058 | #pass |
---|
1059 | ## event to post model to fit to fitting plugins |
---|
1060 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
---|
1061 | |
---|
1062 | ## set smearing value whether or not |
---|
1063 | # the data contain the smearing info |
---|
1064 | evt = ModelEventbox(model=self.model, |
---|
1065 | smearer=temp_smear, |
---|
1066 | qmin=float(self.qmin_x), |
---|
1067 | uid=self.uid, |
---|
1068 | qmax=float(self.qmax_x)) |
---|
1069 | |
---|
1070 | self._manager._on_model_panel(evt=evt) |
---|
1071 | self.state.model = self.model.clone() |
---|
1072 | self.state.model.name = self.model.name |
---|
1073 | if event is not None: |
---|
1074 | #self._draw_model() |
---|
1075 | self._onDraw(event=None) |
---|
1076 | if event != None: |
---|
1077 | ## post state to fit panel |
---|
1078 | new_event = PageInfoEvent(page = self) |
---|
1079 | wx.PostEvent(self.parent, new_event) |
---|
1080 | #update list of plugins if new plugin is available |
---|
1081 | if self.plugin_rbutton.GetValue(): |
---|
1082 | temp = self.parent.update_model_list() |
---|
1083 | if temp: |
---|
1084 | self.model_list_box = temp |
---|
1085 | current_val = self.formfactorbox.GetValue() |
---|
1086 | pos = self.formfactorbox.GetSelection() |
---|
1087 | self._show_combox_helper() |
---|
1088 | self.formfactorbox.SetSelection(pos) |
---|
1089 | self.formfactorbox.SetValue(current_val) |
---|
1090 | self.SetupScrolling() |
---|
1091 | |
---|
1092 | |
---|
1093 | def _onparamEnter(self,event): |
---|
1094 | """ |
---|
1095 | when enter value on panel redraw model according to changed |
---|
1096 | """ |
---|
1097 | if self.model ==None: |
---|
1098 | msg="Please select a Model first..." |
---|
1099 | wx.MessageBox(msg, 'Info') |
---|
1100 | #wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
1101 | # "Parameters: %s"%msg)) |
---|
1102 | return |
---|
1103 | |
---|
1104 | #default flag |
---|
1105 | flag = False |
---|
1106 | self.fitrange = True |
---|
1107 | #get event object |
---|
1108 | tcrtl = event.GetEventObject() |
---|
1109 | |
---|
1110 | #wx.PostEvent(self._manager.parent, StatusEvent(status=" \ |
---|
1111 | # updating ... ",type="update")) |
---|
1112 | #Clear msg if previously shown. |
---|
1113 | msg= "" |
---|
1114 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1115 | |
---|
1116 | if check_float(tcrtl): |
---|
1117 | flag = self._onparamEnter_helper() |
---|
1118 | self.set_npts2fit() |
---|
1119 | if self.fitrange: |
---|
1120 | temp_smearer = None |
---|
1121 | if not self.disable_smearer.GetValue(): |
---|
1122 | temp_smearer= self.current_smearer |
---|
1123 | ## set smearing value whether or not |
---|
1124 | # the data contain the smearing info |
---|
1125 | if self.slit_smearer.GetValue(): |
---|
1126 | flag1 = self.update_slit_smear() |
---|
1127 | flag = flag or flag1 |
---|
1128 | elif self.pinhole_smearer.GetValue(): |
---|
1129 | flag1 = self.update_pinhole_smear() |
---|
1130 | flag = flag or flag1 |
---|
1131 | elif self.data.__class__.__name__ != "Data2D" and \ |
---|
1132 | not self.enable2D: |
---|
1133 | self._manager.set_smearer(smearer=temp_smearer, |
---|
1134 | enable2D=self.enable2D, |
---|
1135 | uid=self.uid, |
---|
1136 | qmin= float(self.qmin_x), |
---|
1137 | qmax= float(self.qmax_x), |
---|
1138 | draw=True) |
---|
1139 | if flag: |
---|
1140 | #self.compute_chisqr(smearer= temp_smearer) |
---|
1141 | |
---|
1142 | ## new state posted |
---|
1143 | if self.state_change: |
---|
1144 | #self._undo.Enable(True) |
---|
1145 | event = PageInfoEvent(page = self) |
---|
1146 | wx.PostEvent(self.parent, event) |
---|
1147 | self.state_change= False |
---|
1148 | else: |
---|
1149 | # invalid fit range: do nothing here: |
---|
1150 | # msg already displayed in validate |
---|
1151 | return |
---|
1152 | else: |
---|
1153 | self.save_current_state() |
---|
1154 | msg= "Cannot Plot :Must enter a number!!! " |
---|
1155 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1156 | |
---|
1157 | self.save_current_state() |
---|
1158 | return |
---|
1159 | |
---|
1160 | def _onparamRangeEnter(self, event): |
---|
1161 | """ |
---|
1162 | Check validity of value enter in the parameters range field |
---|
1163 | """ |
---|
1164 | #if self.check_invalid_panel(): |
---|
1165 | # return |
---|
1166 | tcrtl= event.GetEventObject() |
---|
1167 | #Clear msg if previously shown. |
---|
1168 | msg= "" |
---|
1169 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1170 | # Flag to register when a parameter has changed. |
---|
1171 | is_modified = False |
---|
1172 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
1173 | try: |
---|
1174 | value = float(tcrtl.GetValue()) |
---|
1175 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
1176 | self._check_value_enter(self.fittable_param ,is_modified) |
---|
1177 | self._check_value_enter(self.parameters ,is_modified) |
---|
1178 | except: |
---|
1179 | tcrtl.SetBackgroundColour("pink") |
---|
1180 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
1181 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1182 | return |
---|
1183 | else: |
---|
1184 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
1185 | |
---|
1186 | #self._undo.Enable(True) |
---|
1187 | self.save_current_state() |
---|
1188 | event = PageInfoEvent(page = self) |
---|
1189 | wx.PostEvent(self.parent, event) |
---|
1190 | self.state_change= False |
---|
1191 | |
---|
1192 | |
---|
1193 | def _onQrangeEnter(self, event): |
---|
1194 | """ |
---|
1195 | Check validity of value enter in the Q range field |
---|
1196 | """ |
---|
1197 | #if self.check_invalid_panel(): |
---|
1198 | # return |
---|
1199 | tcrtl= event.GetEventObject() |
---|
1200 | #Clear msg if previously shown. |
---|
1201 | msg= "" |
---|
1202 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1203 | # Flag to register when a parameter has changed. |
---|
1204 | is_modified = False |
---|
1205 | if tcrtl.GetValue().lstrip().rstrip()!="": |
---|
1206 | try: |
---|
1207 | value = float(tcrtl.GetValue()) |
---|
1208 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
1209 | |
---|
1210 | # If qmin and qmax have been modified, update qmin and qmax |
---|
1211 | if self._validate_qrange( self.qmin, self.qmax): |
---|
1212 | tempmin = float(self.qmin.GetValue()) |
---|
1213 | if tempmin != self.qmin_x: |
---|
1214 | self.qmin_x = tempmin |
---|
1215 | tempmax = float(self.qmax.GetValue()) |
---|
1216 | if tempmax != self.qmax_x: |
---|
1217 | self.qmax_x = tempmax |
---|
1218 | else: |
---|
1219 | tcrtl.SetBackgroundColour("pink") |
---|
1220 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
1221 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1222 | return |
---|
1223 | |
---|
1224 | except: |
---|
1225 | tcrtl.SetBackgroundColour("pink") |
---|
1226 | msg= "Model Error:wrong value entered : %s"% sys.exc_value |
---|
1227 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1228 | return |
---|
1229 | #Check if # of points for theory model are valid(>0). |
---|
1230 | # check for 2d |
---|
1231 | if self.data is not None: |
---|
1232 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
1233 | self.enable2D: |
---|
1234 | # set mask |
---|
1235 | radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + |
---|
1236 | self.data.qy_data*self.data.qy_data ) |
---|
1237 | index_data = ((self.qmin_x <= radius)& \ |
---|
1238 | (radius<= self.qmax_x)) |
---|
1239 | index_data = (index_data)&(self.data.mask) |
---|
1240 | index_data = (index_data)&(numpy.isfinite(self.data.data)) |
---|
1241 | if len(index_data[index_data]) < 10: |
---|
1242 | msg = "Cannot Plot :No or too little npts in" |
---|
1243 | msg += " that data range!!! " |
---|
1244 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1245 | return |
---|
1246 | else: |
---|
1247 | self.data.mask = index_data |
---|
1248 | #self.Npts_fit.SetValue(str(len(self.data.mask))) |
---|
1249 | self.set_npts2fit() |
---|
1250 | else: |
---|
1251 | index_data = ((self.qmin_x <= self.data.x)& \ |
---|
1252 | (self.data.x <= self.qmax_x)) |
---|
1253 | self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) |
---|
1254 | else: |
---|
1255 | self.npts_x = self.Npts_total.GetValue() |
---|
1256 | self._save_plotting_range() |
---|
1257 | |
---|
1258 | else: |
---|
1259 | tcrtl.SetBackgroundColour("pink") |
---|
1260 | msg= "Model Error:wrong value entered!!!" |
---|
1261 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1262 | |
---|
1263 | self._draw_model() |
---|
1264 | ##update chi2 |
---|
1265 | #self.compute_chisqr(smearer= temp_smearer) |
---|
1266 | #self._undo.Enable(True) |
---|
1267 | self.save_current_state() |
---|
1268 | event = PageInfoEvent(page = self) |
---|
1269 | wx.PostEvent(self.parent, event) |
---|
1270 | self.state_change= False |
---|
1271 | return |
---|
1272 | |
---|
1273 | def _clear_Err_on_Fit(self): |
---|
1274 | """ |
---|
1275 | hide the error text control shown |
---|
1276 | after fitting |
---|
1277 | """ |
---|
1278 | |
---|
1279 | if hasattr(self,"text2_3"): |
---|
1280 | self.text2_3.Hide() |
---|
1281 | |
---|
1282 | if len(self.parameters)>0: |
---|
1283 | for item in self.parameters: |
---|
1284 | #Skip t ifhe angle parameters if 1D data |
---|
1285 | if self.data.__class__.__name__ != "Data2D" and \ |
---|
1286 | not self.enable2D: |
---|
1287 | if item in self.orientation_params: |
---|
1288 | continue |
---|
1289 | if item in self.param_toFit: |
---|
1290 | continue |
---|
1291 | ## hide statictext +/- |
---|
1292 | if item[3]!=None and item[3].IsShown(): |
---|
1293 | item[3].Hide() |
---|
1294 | ## hide textcrtl for error after fit |
---|
1295 | if item[4]!=None and item[4].IsShown(): |
---|
1296 | item[4].Hide() |
---|
1297 | |
---|
1298 | if len(self.fittable_param)>0: |
---|
1299 | for item in self.fittable_param: |
---|
1300 | #Skip t ifhe angle parameters if 1D data |
---|
1301 | if self.data.__class__.__name__ != "Data2D" and \ |
---|
1302 | not self.enable2D: |
---|
1303 | if item in self.orientation_params: |
---|
1304 | continue |
---|
1305 | if item in self.param_toFit: |
---|
1306 | continue |
---|
1307 | ## hide statictext +/- |
---|
1308 | if item[3]!=None and item[3].IsShown(): |
---|
1309 | item[3].Hide() |
---|
1310 | ## hide textcrtl for error after fit |
---|
1311 | if item[4]!=None and item[4].IsShown(): |
---|
1312 | item[4].Hide() |
---|
1313 | return |
---|
1314 | |
---|
1315 | def _get_defult_custom_smear(self): |
---|
1316 | """ |
---|
1317 | Get the defult values for custum smearing. |
---|
1318 | """ |
---|
1319 | # get the default values |
---|
1320 | if self.dxl == None: self.dxl = 0.0 |
---|
1321 | if self.dxw == None: self.dxw = "" |
---|
1322 | if self.dx_min == None: self.dx_min = SMEAR_SIZE_L |
---|
1323 | if self.dx_max == None: self.dx_max = SMEAR_SIZE_H |
---|
1324 | |
---|
1325 | def _get_smear_info(self): |
---|
1326 | """ |
---|
1327 | Get the smear info from data. |
---|
1328 | |
---|
1329 | :return: self.smear_type, self.dq_l and self.dq_r, |
---|
1330 | respectively the type of the smear, dq_min and |
---|
1331 | dq_max for pinhole smear data |
---|
1332 | while dxl and dxw for slit smear |
---|
1333 | |
---|
1334 | """ |
---|
1335 | |
---|
1336 | # default |
---|
1337 | self.smear_type = None |
---|
1338 | self.dq_l = None |
---|
1339 | self.dq_r = None |
---|
1340 | data = self.data |
---|
1341 | if self.data is None: |
---|
1342 | return |
---|
1343 | elif self.data.__class__.__name__ == "Data2D" or \ |
---|
1344 | self.enable2D: |
---|
1345 | if data.dqx_data == None or data.dqy_data ==None: |
---|
1346 | return |
---|
1347 | elif self.smearer != None and (data.dqx_data.any()!=0) and \ |
---|
1348 | (data.dqx_data.any()!=0): |
---|
1349 | self.smear_type = "Pinhole2d" |
---|
1350 | self.dq_l = format_number(numpy.average(data.dqx_data)) |
---|
1351 | self.dq_r = format_number(numpy.average(data.dqy_data)) |
---|
1352 | return |
---|
1353 | else: |
---|
1354 | return |
---|
1355 | # check if it is pinhole smear and get min max if it is. |
---|
1356 | if data.dx != None and all(data.dx !=0): |
---|
1357 | self.smear_type = "Pinhole" |
---|
1358 | self.dq_l = data.dx[0] |
---|
1359 | self.dq_r = data.dx[-1] |
---|
1360 | |
---|
1361 | # check if it is slit smear and get min max if it is. |
---|
1362 | elif data.dxl != None or data.dxw != None: |
---|
1363 | self.smear_type = "Slit" |
---|
1364 | if data.dxl != None and all(data.dxl !=0): |
---|
1365 | self.dq_l = data.dxl[0] |
---|
1366 | if data.dxw != None and all(data.dxw !=0): |
---|
1367 | self.dq_r = data.dxw[0] |
---|
1368 | #return self.smear_type,self.dq_l,self.dq_r |
---|
1369 | |
---|
1370 | def _show_smear_sizer(self): |
---|
1371 | """ |
---|
1372 | Show only the sizers depending on smear selection |
---|
1373 | """ |
---|
1374 | # smear disabled |
---|
1375 | if self.disable_smearer.GetValue(): |
---|
1376 | self.smear_description_none.Show(True) |
---|
1377 | # 2Dsmear |
---|
1378 | elif self._is_2D(): |
---|
1379 | self.smear_description_accuracy_type.Show(True) |
---|
1380 | self.smear_accuracy.Show(True) |
---|
1381 | self.smear_description_accuracy_type.Show(True) |
---|
1382 | self.smear_description_2d.Show(True) |
---|
1383 | self.smear_description_2d_x.Show(True) |
---|
1384 | self.smear_description_2d_y.Show(True) |
---|
1385 | if self.pinhole_smearer.GetValue(): |
---|
1386 | self.smear_pinhole_min.Show(True) |
---|
1387 | self.smear_pinhole_max.Show(True) |
---|
1388 | # smear from data |
---|
1389 | elif self.enable_smearer.GetValue(): |
---|
1390 | |
---|
1391 | self.smear_description_dqdata.Show(True) |
---|
1392 | if self.smear_type != None: |
---|
1393 | self.smear_description_smear_type.Show(True) |
---|
1394 | if self.smear_type == 'Slit': |
---|
1395 | self.smear_description_slit_height.Show(True) |
---|
1396 | self.smear_description_slit_width.Show(True) |
---|
1397 | elif self.smear_type == 'Pinhole': |
---|
1398 | self.smear_description_pin_min.Show(True) |
---|
1399 | self.smear_description_pin_max.Show(True) |
---|
1400 | self.smear_description_smear_type.Show(True) |
---|
1401 | self.smear_description_type.Show(True) |
---|
1402 | self.smear_data_left.Show(True) |
---|
1403 | self.smear_data_right.Show(True) |
---|
1404 | # custom pinhole smear |
---|
1405 | elif self.pinhole_smearer.GetValue(): |
---|
1406 | if self.smear_type == 'Pinhole': |
---|
1407 | self.smear_message_new_p.Show(True) |
---|
1408 | self.smear_description_pin_min.Show(True) |
---|
1409 | self.smear_description_pin_max.Show(True) |
---|
1410 | |
---|
1411 | self.smear_pinhole_min.Show(True) |
---|
1412 | self.smear_pinhole_max.Show(True) |
---|
1413 | # custom slit smear |
---|
1414 | elif self.slit_smearer.GetValue(): |
---|
1415 | self.smear_message_new_s.Show(True) |
---|
1416 | self.smear_description_slit_height.Show(True) |
---|
1417 | self.smear_slit_height.Show(True) |
---|
1418 | self.smear_description_slit_width.Show(True) |
---|
1419 | self.smear_slit_width.Show(True) |
---|
1420 | |
---|
1421 | def _hide_all_smear_info(self): |
---|
1422 | """ |
---|
1423 | Hide all smearing messages in the set_smearer sizer |
---|
1424 | """ |
---|
1425 | self.smear_description_none.Hide() |
---|
1426 | self.smear_description_dqdata.Hide() |
---|
1427 | self.smear_description_type.Hide() |
---|
1428 | self.smear_description_smear_type.Hide() |
---|
1429 | self.smear_description_accuracy_type.Hide() |
---|
1430 | self.smear_description_2d_x.Hide() |
---|
1431 | self.smear_description_2d_y.Hide() |
---|
1432 | self.smear_description_2d.Hide() |
---|
1433 | |
---|
1434 | self.smear_accuracy.Hide() |
---|
1435 | self.smear_data_left.Hide() |
---|
1436 | self.smear_data_right.Hide() |
---|
1437 | self.smear_description_pin_min.Hide() |
---|
1438 | self.smear_pinhole_min.Hide() |
---|
1439 | self.smear_description_pin_max.Hide() |
---|
1440 | self.smear_pinhole_max.Hide() |
---|
1441 | self.smear_description_slit_height.Hide() |
---|
1442 | self.smear_slit_height.Hide() |
---|
1443 | self.smear_description_slit_width.Hide() |
---|
1444 | self.smear_slit_width.Hide() |
---|
1445 | self.smear_message_new_p.Hide() |
---|
1446 | self.smear_message_new_s.Hide() |
---|
1447 | |
---|
1448 | def _set_accuracy_list(self): |
---|
1449 | """ |
---|
1450 | Set the list of an accuracy in 2D custum smear: Xhigh, High, Med, or Low |
---|
1451 | """ |
---|
1452 | # list of accuracy choices |
---|
1453 | list = ['Low','Med','High','Xhigh'] |
---|
1454 | for idx in range(len(list)): |
---|
1455 | self.smear_accuracy.Append(list[idx],idx) |
---|
1456 | |
---|
1457 | def _set_fun_box_list(self,fun_box): |
---|
1458 | """ |
---|
1459 | Set the list of func for multifunctional models |
---|
1460 | """ |
---|
1461 | # Check if it is multi_functional model |
---|
1462 | if self.model.__class__ not in self.model_list_box["Multi-Functions"]: |
---|
1463 | return None |
---|
1464 | # Get the func name list |
---|
1465 | list = self.model.fun_list |
---|
1466 | if len(list) == 0: |
---|
1467 | return None |
---|
1468 | # build function (combo)box |
---|
1469 | ind = 0 |
---|
1470 | while(ind < len(list)): |
---|
1471 | for key, val in list.iteritems(): |
---|
1472 | if (val == ind): |
---|
1473 | fun_box.Append(key,val) |
---|
1474 | break |
---|
1475 | ind += 1 |
---|
1476 | |
---|
1477 | def _on_select_accuracy(self,event): |
---|
1478 | """ |
---|
1479 | Select an accuracy in 2D custom smear: Xhigh, High, Med, or Low |
---|
1480 | """ |
---|
1481 | #event.Skip() |
---|
1482 | # Check if the accuracy is same as before |
---|
1483 | #self.smear2d_accuracy = event.GetEventObject().GetValue() |
---|
1484 | self.smear2d_accuracy = self.smear_accuracy.GetValue() |
---|
1485 | if self.pinhole_smearer.GetValue(): |
---|
1486 | self.onPinholeSmear(event=None) |
---|
1487 | else: |
---|
1488 | self.onSmear(event=None) |
---|
1489 | if self.current_smearer != None: |
---|
1490 | self.current_smearer.set_accuracy(accuracy = |
---|
1491 | self.smear2d_accuracy) |
---|
1492 | event.Skip() |
---|
1493 | |
---|
1494 | def _on_fun_box(self,event): |
---|
1495 | """ |
---|
1496 | Select an func: Erf,Rparabola,LParabola |
---|
1497 | """ |
---|
1498 | fun_val = None |
---|
1499 | fun_box = event.GetEventObject() |
---|
1500 | name = fun_box.Name |
---|
1501 | value = fun_box.GetValue() |
---|
1502 | if self.model.fun_list.has_key(value): |
---|
1503 | fun_val = self.model.fun_list[value] |
---|
1504 | |
---|
1505 | self.model.setParam(name,fun_val) |
---|
1506 | # save state |
---|
1507 | self._copy_parameters_state(self.str_parameters, |
---|
1508 | self.state.str_parameters) |
---|
1509 | # update params |
---|
1510 | self._update_paramv_on_fit() |
---|
1511 | # draw |
---|
1512 | self._draw_model() |
---|
1513 | self.Refresh() |
---|
1514 | # get ready for new event |
---|
1515 | event.Skip() |
---|
1516 | |
---|
1517 | def _onMask(self, event): |
---|
1518 | """ |
---|
1519 | Build a panel to allow to edit Mask |
---|
1520 | """ |
---|
1521 | |
---|
1522 | from sans.guiframe.local_perspectives.plotting.masking \ |
---|
1523 | import MaskPanel as MaskDialog |
---|
1524 | |
---|
1525 | self.panel = MaskDialog(self, data=self.data,id =-1 ) |
---|
1526 | self.panel.Bind(wx.EVT_CLOSE, self._draw_masked_model) |
---|
1527 | self.panel.ShowModal() |
---|
1528 | #wx.PostEvent(self.parent, event) |
---|
1529 | |
---|
1530 | def _draw_masked_model(self,event): |
---|
1531 | """ |
---|
1532 | Draw model image w/mask |
---|
1533 | """ |
---|
1534 | event.Skip() |
---|
1535 | |
---|
1536 | is_valid_qrange = self._update_paramv_on_fit() |
---|
1537 | |
---|
1538 | if is_valid_qrange: |
---|
1539 | # try re draw the model plot if it exists |
---|
1540 | self._draw_model() |
---|
1541 | self.panel.Destroy() # frame |
---|
1542 | self.set_npts2fit() |
---|
1543 | elif self.model == None: |
---|
1544 | self.panel.Destroy() |
---|
1545 | self.set_npts2fit() |
---|
1546 | msg= "No model is found on updating MASK in the model plot... " |
---|
1547 | wx.PostEvent(self.parent.parent, StatusEvent(status = msg )) |
---|
1548 | else: |
---|
1549 | msg = ' Please consider your Q range, too.' |
---|
1550 | self.panel.ShowMessage(msg) |
---|
1551 | |
---|
1552 | def _set_smear(self, data): |
---|
1553 | """ |
---|
1554 | """ |
---|
1555 | if data is None: |
---|
1556 | return |
---|
1557 | self.smearer = smear_selection(data, self.model) |
---|
1558 | self.disable_smearer.SetValue(True) |
---|
1559 | if self.smearer == None: |
---|
1560 | self.enable_smearer.Disable() |
---|
1561 | else: |
---|
1562 | self.enable_smearer.Enable() |
---|
1563 | |
---|
1564 | def get_view_mode(self): |
---|
1565 | """ |
---|
1566 | return True if the panel allow 2D or False if 1D |
---|
1567 | """ |
---|
1568 | return self.enable2D |
---|
1569 | |
---|
1570 | def set_data(self, data): |
---|
1571 | """ |
---|
1572 | reset the current data |
---|
1573 | """ |
---|
1574 | flag = False |
---|
1575 | if self.data is None and data is not None: |
---|
1576 | self.window_name = str(data.name) |
---|
1577 | ## Title to appear on top of the window |
---|
1578 | self.window_caption = str(data.name) |
---|
1579 | flag = True |
---|
1580 | self.data = data |
---|
1581 | if self.data is None: |
---|
1582 | data_min = "" |
---|
1583 | data_max = "" |
---|
1584 | data_name = "" |
---|
1585 | self._set_bookmark_flag(False) |
---|
1586 | self._keep.Enable(False) |
---|
1587 | self._set_save_flag(False) |
---|
1588 | else: |
---|
1589 | if self.model != None: |
---|
1590 | self._set_bookmark_flag(True) |
---|
1591 | self._keep.Enable(True) |
---|
1592 | self._set_save_flag(True) |
---|
1593 | self._set_preview_flag(True) |
---|
1594 | |
---|
1595 | self._set_smear(data) |
---|
1596 | # more disables for 2D |
---|
1597 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
1598 | self.enable2D: |
---|
1599 | self.slit_smearer.Disable() |
---|
1600 | self.pinhole_smearer.Enable(True) |
---|
1601 | self.default_mask = copy.deepcopy(self.data.mask) |
---|
1602 | else: |
---|
1603 | self.slit_smearer.Enable(True) |
---|
1604 | self.pinhole_smearer.Enable(True) |
---|
1605 | |
---|
1606 | self.formfactorbox.Enable() |
---|
1607 | self.structurebox.Enable() |
---|
1608 | data_name = self.data.name |
---|
1609 | #set maximum range for x in linear scale |
---|
1610 | if not hasattr(self.data,"data"): #Display only for 1D data fit |
---|
1611 | # Minimum value of data |
---|
1612 | data_min = min(self.data.x) |
---|
1613 | # Maximum value of data |
---|
1614 | data_max = max(self.data.x) |
---|
1615 | #number of total data points |
---|
1616 | self.Npts_total.SetValue(str(len(self.data.x))) |
---|
1617 | #default:number of data points selected to fit |
---|
1618 | self.Npts_fit.SetValue(str(len(self.data.x))) |
---|
1619 | self.btEditMask.Disable() |
---|
1620 | self.EditMask_title.Disable() |
---|
1621 | else: |
---|
1622 | |
---|
1623 | ## Minimum value of data |
---|
1624 | data_min = 0 |
---|
1625 | x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
1626 | y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
1627 | ## Maximum value of data |
---|
1628 | data_max = math.sqrt(x*x + y*y) |
---|
1629 | #number of total data points |
---|
1630 | self.Npts_total.SetValue(str(len(self.data.data))) |
---|
1631 | #default:number of data points selected to fit |
---|
1632 | self.Npts_fit.SetValue(str(len(self.data.data))) |
---|
1633 | self.btEditMask.Enable() |
---|
1634 | self.EditMask_title.Enable() |
---|
1635 | self.Npts_total.SetEditable(False) |
---|
1636 | self.Npts_total.SetBackgroundColour(\ |
---|
1637 | self.GetParent().GetBackgroundColour()) |
---|
1638 | |
---|
1639 | self.Npts_total.Bind(wx.EVT_MOUSE_EVENTS, self._npts_click) |
---|
1640 | #self.Npts_total.Disable() |
---|
1641 | self.dataSource.SetValue(data_name) |
---|
1642 | self.qmin_x = data_min |
---|
1643 | self.qmax_x = data_max |
---|
1644 | self.minimum_q.SetValue(str(data_min)) |
---|
1645 | self.maximum_q.SetValue(str(data_max)) |
---|
1646 | self.qmin.SetValue(str(data_min)) |
---|
1647 | self.qmax.SetValue(str(data_max)) |
---|
1648 | self.qmin.SetBackgroundColour("white") |
---|
1649 | self.qmax.SetBackgroundColour("white") |
---|
1650 | self.state.data = data |
---|
1651 | self.state.qmin = self.qmin_x |
---|
1652 | self.state.qmax = self.qmax_x |
---|
1653 | |
---|
1654 | #update model plot with new data information |
---|
1655 | if flag: |
---|
1656 | #set model view button |
---|
1657 | if self.data.__class__.__name__ == "Data2D": |
---|
1658 | self.enable2D = True |
---|
1659 | self.model_view.SetLabel("2D Mode") |
---|
1660 | else: |
---|
1661 | self.enable2D = False |
---|
1662 | self.model_view.SetLabel("1D Mode") |
---|
1663 | |
---|
1664 | self.model_view.Disable() |
---|
1665 | self._draw_model() |
---|
1666 | |
---|
1667 | def _npts_click(self, event): |
---|
1668 | """ |
---|
1669 | Prevent further handling of the mouse event on Npts_total |
---|
1670 | by not calling Skip(). |
---|
1671 | """ |
---|
1672 | pass |
---|
1673 | |
---|
1674 | def reset_page(self, state,first=False): |
---|
1675 | """ |
---|
1676 | reset the state |
---|
1677 | """ |
---|
1678 | self.reset_page_helper(state) |
---|
1679 | #import sans.guiframe.gui_manager |
---|
1680 | #evt = ModelEventbox(model=state.model) |
---|
1681 | #wx.PostEvent(self.event_owner, evt) |
---|
1682 | |
---|
1683 | if self.engine_type != None: |
---|
1684 | self._manager._on_change_engine(engine=self.engine_type) |
---|
1685 | |
---|
1686 | self.select_param(event = None) |
---|
1687 | #Save state_fit |
---|
1688 | self.save_current_state_fit() |
---|
1689 | self._lay_out() |
---|
1690 | self.Refresh() |
---|
1691 | |
---|
1692 | def get_range(self): |
---|
1693 | """ |
---|
1694 | return the fitting range |
---|
1695 | """ |
---|
1696 | return float(self.qmin_x) , float(self.qmax_x) |
---|
1697 | |
---|
1698 | def get_npts2fit(self): |
---|
1699 | """ |
---|
1700 | return numbers of data points within qrange |
---|
1701 | |
---|
1702 | :Note: This is for Park where chi2 is not normalized by Npts of fit |
---|
1703 | |
---|
1704 | """ |
---|
1705 | if self.data is None: |
---|
1706 | return |
---|
1707 | npts2fit = 0 |
---|
1708 | qmin,qmax = self.get_range() |
---|
1709 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
1710 | self.enable2D: |
---|
1711 | radius= numpy.sqrt( self.data.qx_data*self.data.qx_data + |
---|
1712 | self.data.qy_data*self.data.qy_data ) |
---|
1713 | index_data = (self.qmin_x <= radius)&(radius<= self.qmax_x) |
---|
1714 | index_data= (index_data)&(self.data.mask) |
---|
1715 | index_data = (index_data)&(numpy.isfinite(self.data.data)) |
---|
1716 | npts2fit = len(self.data.data[index_data]) |
---|
1717 | else: |
---|
1718 | for qx in self.data.x: |
---|
1719 | if qx >= qmin and qx <= qmax: |
---|
1720 | npts2fit += 1 |
---|
1721 | return npts2fit |
---|
1722 | |
---|
1723 | def set_npts2fit(self): |
---|
1724 | """ |
---|
1725 | setValue Npts for fitting |
---|
1726 | """ |
---|
1727 | self.Npts_fit.SetValue(str(self.get_npts2fit())) |
---|
1728 | |
---|
1729 | def get_chi2(self): |
---|
1730 | """ |
---|
1731 | return the current chi2 |
---|
1732 | """ |
---|
1733 | return self.tcChi.GetValue() |
---|
1734 | |
---|
1735 | def get_param_list(self): |
---|
1736 | """ |
---|
1737 | :return self.param_toFit: list containing references to TextCtrl |
---|
1738 | checked.Theses TextCtrl will allow reference to parameters to fit. |
---|
1739 | |
---|
1740 | :raise: if return an empty list of parameter fit will nnote work |
---|
1741 | properly so raise ValueError,"missing parameter to fit" |
---|
1742 | """ |
---|
1743 | if self.param_toFit !=[]: |
---|
1744 | return self.param_toFit |
---|
1745 | else: |
---|
1746 | msg = "missing parameters to fit" |
---|
1747 | wx.MessageBox(msg, 'warning') |
---|
1748 | return False |
---|
1749 | #raise ValueError,"missing parameters to fit" |
---|
1750 | |
---|
1751 | def onsetValues(self, chisqr, p_name, out, cov): |
---|
1752 | """ |
---|
1753 | Build the panel from the fit result |
---|
1754 | |
---|
1755 | :param chisqr: Value of the goodness of fit metric |
---|
1756 | :param p_name: the name of parameters |
---|
1757 | :param out: list of parameter with the best value found during fitting |
---|
1758 | :param cov: Covariance matrix |
---|
1759 | |
---|
1760 | """ |
---|
1761 | if out == None or not numpy.isfinite(chisqr): |
---|
1762 | raise ValueError,"Fit error occured..." |
---|
1763 | |
---|
1764 | is_modified = False |
---|
1765 | has_error = False |
---|
1766 | |
---|
1767 | #Hide textctrl boxes of errors. |
---|
1768 | self._clear_Err_on_Fit() |
---|
1769 | |
---|
1770 | #Check if chi2 is finite |
---|
1771 | if chisqr != None and numpy.isfinite(chisqr): |
---|
1772 | #format chi2 |
---|
1773 | if self.engine_type == "park": |
---|
1774 | npt_fit = float(self.get_npts2fit()) |
---|
1775 | if npt_fit > 0: |
---|
1776 | chisqr =chisqr/npt_fit |
---|
1777 | chi2 = format_number(chisqr, True) |
---|
1778 | self.tcChi.SetValue(chi2) |
---|
1779 | self.tcChi.Refresh() |
---|
1780 | else: |
---|
1781 | self.tcChi.SetValue("-") |
---|
1782 | |
---|
1783 | #Hide error title |
---|
1784 | if self.text2_3.IsShown(): |
---|
1785 | self.text2_3.Hide() |
---|
1786 | |
---|
1787 | try: |
---|
1788 | if self.enable_disp.GetValue(): |
---|
1789 | if hasattr(self,"text_disp_1" ): |
---|
1790 | if self.text_disp_1 != None: |
---|
1791 | self.text_disp_1.Hide() |
---|
1792 | except: |
---|
1793 | dispersty = None |
---|
1794 | pass |
---|
1795 | #set the panel when fit result are float not list |
---|
1796 | if out.__class__== numpy.float64: |
---|
1797 | self.param_toFit[0][2].SetValue(format_number(out, True)) |
---|
1798 | |
---|
1799 | if self.param_toFit[0][4].IsShown: |
---|
1800 | self.param_toFit[0][4].Hide() |
---|
1801 | if cov !=None : |
---|
1802 | self.text2_3.Show(True) |
---|
1803 | try: |
---|
1804 | if self.enable_disp.GetValue(): |
---|
1805 | if hasattr(self,"text_disp_1" ): |
---|
1806 | if self.text_disp_1 !=None: |
---|
1807 | self.text_disp_1.Show(True) |
---|
1808 | except: |
---|
1809 | pass |
---|
1810 | |
---|
1811 | if cov[0]==None or not numpy.isfinite(cov[0]): |
---|
1812 | if self.param_toFit[0][3].IsShown: |
---|
1813 | self.param_toFit[0][3].Hide() |
---|
1814 | else: |
---|
1815 | self.param_toFit[0][3].Show(True) |
---|
1816 | self.param_toFit[0][4].Show(True) |
---|
1817 | self.param_toFit[0][4].SetValue(format_number(cov[0], True)) |
---|
1818 | has_error = True |
---|
1819 | else: |
---|
1820 | |
---|
1821 | i = 0 |
---|
1822 | #Set the panel when fit result are list |
---|
1823 | for item in self.param_toFit: |
---|
1824 | if len(item)>5 and item != None: |
---|
1825 | ## reset error value to initial state |
---|
1826 | item[3].Hide() |
---|
1827 | item[4].Hide() |
---|
1828 | |
---|
1829 | for ind in range(len(out)): |
---|
1830 | |
---|
1831 | if item[1] == p_name[ind]: |
---|
1832 | break |
---|
1833 | if len(out)<=len(self.param_toFit) and out[ind] !=None: |
---|
1834 | val_out = format_number(out[ind], True) |
---|
1835 | item[2].SetValue(val_out) |
---|
1836 | |
---|
1837 | if(cov !=None): |
---|
1838 | |
---|
1839 | try: |
---|
1840 | if dispersity !=None: |
---|
1841 | if self.enable_disp.GetValue(): |
---|
1842 | if hasattr(self,"text_disp_1" ): |
---|
1843 | if self.text_disp_1!=None: |
---|
1844 | if not self.text_disp_1.IsShown(): |
---|
1845 | self.text_disp_1.Show(True) |
---|
1846 | except: |
---|
1847 | pass |
---|
1848 | |
---|
1849 | if cov[ind]!=None : |
---|
1850 | if numpy.isfinite(float(cov[ind])): |
---|
1851 | val_err = format_number(cov[ind], True) |
---|
1852 | item[3].Show(True) |
---|
1853 | item[4].Show(True) |
---|
1854 | item[4].SetValue(val_err) |
---|
1855 | |
---|
1856 | has_error = True |
---|
1857 | i += 1 |
---|
1858 | #Show error title when any errors displayed |
---|
1859 | if has_error: |
---|
1860 | if not self.text2_3.IsShown(): |
---|
1861 | self.text2_3.Show(True) |
---|
1862 | |
---|
1863 | ## save current state |
---|
1864 | self.save_current_state() |
---|
1865 | #plot model ( when drawing, do not update chisqr value again) |
---|
1866 | self._draw_model(update_chisqr=False) |
---|
1867 | self._lay_out() |
---|
1868 | self.Refresh() |
---|
1869 | #PostStatusEvent |
---|
1870 | msg = "Fit completed! " |
---|
1871 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
1872 | |
---|
1873 | def onPinholeSmear(self, event): |
---|
1874 | """ |
---|
1875 | Create a custom pinhole smear object that will change the way residuals |
---|
1876 | are compute when fitting |
---|
1877 | |
---|
1878 | :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, |
---|
1879 | None for 1D |
---|
1880 | |
---|
1881 | """ |
---|
1882 | |
---|
1883 | #if self.check_invalid_panel(): |
---|
1884 | # return |
---|
1885 | if self.model ==None: |
---|
1886 | self.disable_smearer.SetValue(True) |
---|
1887 | msg="Please select a Model first..." |
---|
1888 | wx.MessageBox(msg, 'Info') |
---|
1889 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
1890 | "Smear: %s"%msg)) |
---|
1891 | return |
---|
1892 | |
---|
1893 | # Need update param values |
---|
1894 | self._update_paramv_on_fit() |
---|
1895 | |
---|
1896 | # msg default |
---|
1897 | msg = None |
---|
1898 | if event != None: |
---|
1899 | tcrtl= event.GetEventObject() |
---|
1900 | # event case of radio button |
---|
1901 | if tcrtl.GetValue()== True: |
---|
1902 | self.dx_min = 0.0 |
---|
1903 | self.dx_max = 0.0 |
---|
1904 | is_new_pinhole = True |
---|
1905 | else: |
---|
1906 | is_new_pinhole = self._is_changed_pinhole() |
---|
1907 | else: |
---|
1908 | is_new_pinhole = True |
---|
1909 | # if any value is changed |
---|
1910 | if is_new_pinhole: |
---|
1911 | msg = self._set_pinhole_smear() |
---|
1912 | # hide all silt sizer |
---|
1913 | self._hide_all_smear_info() |
---|
1914 | |
---|
1915 | ##Calculate chi2 |
---|
1916 | temp_smearer = self.current_smearer |
---|
1917 | #self.compute_chisqr(smearer= temp_smearer) |
---|
1918 | |
---|
1919 | # show relevant slit sizers |
---|
1920 | self._show_smear_sizer() |
---|
1921 | |
---|
1922 | self.sizer_set_smearer.Layout() |
---|
1923 | self.Layout() |
---|
1924 | |
---|
1925 | if event != None: |
---|
1926 | event.Skip() |
---|
1927 | #self._undo.Enable(True) |
---|
1928 | self.save_current_state() |
---|
1929 | event = PageInfoEvent(page = self) |
---|
1930 | wx.PostEvent(self.parent, event) |
---|
1931 | |
---|
1932 | def _is_changed_pinhole(self): |
---|
1933 | """ |
---|
1934 | check if any of pinhole smear is changed |
---|
1935 | |
---|
1936 | :return: True or False |
---|
1937 | |
---|
1938 | """ |
---|
1939 | # get the values |
---|
1940 | pin_min = self.smear_pinhole_min.GetValue() |
---|
1941 | pin_max = self.smear_pinhole_max.GetValue() |
---|
1942 | |
---|
1943 | # Check changes in slit width |
---|
1944 | try: |
---|
1945 | dx_min = float(pin_min) |
---|
1946 | except: |
---|
1947 | return True |
---|
1948 | if self.dx_min != dx_min: |
---|
1949 | return True |
---|
1950 | |
---|
1951 | # Check changes in slit heigth |
---|
1952 | try: |
---|
1953 | dx_max = float(pin_max) |
---|
1954 | except: |
---|
1955 | return True |
---|
1956 | if self.dx_max != dx_max: |
---|
1957 | return True |
---|
1958 | return False |
---|
1959 | |
---|
1960 | def _set_pinhole_smear(self): |
---|
1961 | """ |
---|
1962 | Set custom pinhole smear |
---|
1963 | |
---|
1964 | :return: msg |
---|
1965 | |
---|
1966 | """ |
---|
1967 | # copy data |
---|
1968 | data = copy.deepcopy(self.data) |
---|
1969 | if self._is_2D(): |
---|
1970 | self.smear_type = 'Pinhole2d' |
---|
1971 | len_data = len(data.data) |
---|
1972 | data.dqx_data = numpy.zeros(len_data) |
---|
1973 | data.dqy_data = numpy.zeros(len_data) |
---|
1974 | else: |
---|
1975 | self.smear_type = 'Pinhole' |
---|
1976 | len_data = len(data.x) |
---|
1977 | data.dx = numpy.zeros(len_data) |
---|
1978 | data.dxl = None |
---|
1979 | data.dxw = None |
---|
1980 | msg = None |
---|
1981 | |
---|
1982 | get_pin_min = self.smear_pinhole_min |
---|
1983 | get_pin_max = self.smear_pinhole_max |
---|
1984 | |
---|
1985 | if not check_float(get_pin_min): |
---|
1986 | get_pin_min.SetBackgroundColour("pink") |
---|
1987 | msg= "Model Error:wrong value entered!!!" |
---|
1988 | elif not check_float(get_pin_max ): |
---|
1989 | get_pin_max.SetBackgroundColour("pink") |
---|
1990 | msg= "Model Error:wrong value entered!!!" |
---|
1991 | else: |
---|
1992 | if len_data < 2: len_data = 2 |
---|
1993 | self.dx_min = float(get_pin_min.GetValue()) |
---|
1994 | self.dx_max = float(get_pin_max.GetValue()) |
---|
1995 | if self.dx_min < 0: |
---|
1996 | get_pin_min.SetBackgroundColour("pink") |
---|
1997 | msg= "Model Error:This value can not be negative!!!" |
---|
1998 | elif self.dx_max <0: |
---|
1999 | get_pin_max.SetBackgroundColour("pink") |
---|
2000 | msg= "Model Error:This value can not be negative!!!" |
---|
2001 | elif self.dx_min != None and self.dx_max != None: |
---|
2002 | if self._is_2D(): |
---|
2003 | data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
2004 | data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
2005 | elif self.dx_min == self.dx_max: |
---|
2006 | data.dx[data.dx==0] = self.dx_min |
---|
2007 | else: |
---|
2008 | step = (self.dx_max - self.dx_min)/(len_data-1) |
---|
2009 | data.dx = numpy.arange(self.dx_min,self.dx_max+step/1.1, |
---|
2010 | step) |
---|
2011 | elif self.dx_min != None: |
---|
2012 | if self._is_2D(): data.dqx_data[data.dqx_data==0] = self.dx_min |
---|
2013 | else: data.dx[data.dx==0] = self.dx_min |
---|
2014 | elif self.dx_max != None: |
---|
2015 | if self._is_2D(): data.dqy_data[data.dqy_data==0] = self.dx_max |
---|
2016 | else: data.dx[data.dx==0] = self.dx_max |
---|
2017 | self.current_smearer = smear_selection(data, self.model) |
---|
2018 | # 2D need to set accuracy |
---|
2019 | if self._is_2D(): |
---|
2020 | self.current_smearer.set_accuracy(accuracy = \ |
---|
2021 | self.smear2d_accuracy) |
---|
2022 | |
---|
2023 | if msg != None: |
---|
2024 | wx.PostEvent(self._manager.parent, StatusEvent(status = msg )) |
---|
2025 | else: |
---|
2026 | get_pin_min.SetBackgroundColour("white") |
---|
2027 | get_pin_max.SetBackgroundColour("white") |
---|
2028 | ## set smearing value whether or not the data contain the smearing info |
---|
2029 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
2030 | enable2D=self.enable2D, |
---|
2031 | qmin=float(self.qmin_x), |
---|
2032 | qmax= float(self.qmax_x), |
---|
2033 | uid=self.uid) |
---|
2034 | return msg |
---|
2035 | |
---|
2036 | def update_pinhole_smear(self): |
---|
2037 | """ |
---|
2038 | called by kill_focus on pinhole TextCntrl |
---|
2039 | to update the changes |
---|
2040 | |
---|
2041 | :return: False when wrong value was entered |
---|
2042 | |
---|
2043 | """ |
---|
2044 | # msg default |
---|
2045 | msg = None |
---|
2046 | # check if any value is changed |
---|
2047 | if self._is_changed_pinhole(): |
---|
2048 | msg = self._set_pinhole_smear() |
---|
2049 | #self._undo.Enable(True) |
---|
2050 | self.save_current_state() |
---|
2051 | |
---|
2052 | if msg != None: |
---|
2053 | return False |
---|
2054 | else: |
---|
2055 | return True |
---|
2056 | |
---|
2057 | def onSlitSmear(self, event): |
---|
2058 | """ |
---|
2059 | Create a custom slit smear object that will change the way residuals |
---|
2060 | are compute when fitting |
---|
2061 | """ |
---|
2062 | |
---|
2063 | #if self.check_invalid_panel(): |
---|
2064 | # return |
---|
2065 | |
---|
2066 | if self.model ==None: |
---|
2067 | self.disable_smearer.SetValue(True) |
---|
2068 | |
---|
2069 | msg="Please select a Model first..." |
---|
2070 | wx.MessageBox(msg, 'Info') |
---|
2071 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
2072 | "Smear: %s"%msg)) |
---|
2073 | return |
---|
2074 | |
---|
2075 | # Need update param values |
---|
2076 | self._update_paramv_on_fit() |
---|
2077 | |
---|
2078 | # msg default |
---|
2079 | msg = None |
---|
2080 | # for event given |
---|
2081 | if event != None: |
---|
2082 | tcrtl= event.GetEventObject() |
---|
2083 | # event case of radio button |
---|
2084 | if tcrtl.GetValue(): |
---|
2085 | self.dxl = 0.0 |
---|
2086 | self.dxw = 0.0 |
---|
2087 | is_new_slit = True |
---|
2088 | else: |
---|
2089 | is_new_slit = self._is_changed_slit() |
---|
2090 | else: |
---|
2091 | is_new_slit = True |
---|
2092 | |
---|
2093 | # if any value is changed |
---|
2094 | if is_new_slit: |
---|
2095 | msg = self._set_slit_smear() |
---|
2096 | |
---|
2097 | # hide all silt sizer |
---|
2098 | self._hide_all_smear_info() |
---|
2099 | ##Calculate chi2 |
---|
2100 | #self.compute_chisqr(smearer= self.current_smearer) |
---|
2101 | # show relevant slit sizers |
---|
2102 | self._show_smear_sizer() |
---|
2103 | self.sizer_set_smearer.Layout() |
---|
2104 | self.Layout() |
---|
2105 | |
---|
2106 | if event != None: |
---|
2107 | event.Skip() |
---|
2108 | #self._undo.Enable(True) |
---|
2109 | self.save_current_state() |
---|
2110 | event = PageInfoEvent(page = self) |
---|
2111 | wx.PostEvent(self.parent, event) |
---|
2112 | if msg != None: |
---|
2113 | wx.PostEvent(self._manager.parent, StatusEvent(status = msg)) |
---|
2114 | |
---|
2115 | def _is_changed_slit(self): |
---|
2116 | """ |
---|
2117 | check if any of slit lengths is changed |
---|
2118 | |
---|
2119 | :return: True or False |
---|
2120 | |
---|
2121 | """ |
---|
2122 | # get the values |
---|
2123 | width = self.smear_slit_width.GetValue() |
---|
2124 | height = self.smear_slit_height.GetValue() |
---|
2125 | |
---|
2126 | # check and change the box bg color if it was pink |
---|
2127 | # but it should be white now |
---|
2128 | # because this is the case that _set_slit_smear() will not handle |
---|
2129 | if height.lstrip().rstrip()=="": |
---|
2130 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
2131 | if width.lstrip().rstrip()=="": |
---|
2132 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
2133 | |
---|
2134 | # Check changes in slit width |
---|
2135 | if width == "": |
---|
2136 | dxw = 0.0 |
---|
2137 | else: |
---|
2138 | try: |
---|
2139 | dxw = float(width) |
---|
2140 | except: |
---|
2141 | return True |
---|
2142 | if self.dxw != dxw: |
---|
2143 | return True |
---|
2144 | |
---|
2145 | # Check changes in slit heigth |
---|
2146 | if height == "": |
---|
2147 | dxl = 0.0 |
---|
2148 | else: |
---|
2149 | try: |
---|
2150 | dxl = float(height) |
---|
2151 | except: |
---|
2152 | return True |
---|
2153 | if self.dxl != dxl: |
---|
2154 | return True |
---|
2155 | |
---|
2156 | return False |
---|
2157 | |
---|
2158 | def _set_slit_smear(self): |
---|
2159 | """ |
---|
2160 | Set custom slit smear |
---|
2161 | |
---|
2162 | :return: message to inform the user about the validity |
---|
2163 | of the values entered for slit smear |
---|
2164 | """ |
---|
2165 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
2166 | self.enable2D: |
---|
2167 | return |
---|
2168 | temp_smearer = None |
---|
2169 | # make sure once more if it is smearer |
---|
2170 | data = copy.deepcopy(self.data) |
---|
2171 | data_len = len(data.x) |
---|
2172 | data.dx = None |
---|
2173 | data.dxl = None |
---|
2174 | data.dxw = None |
---|
2175 | msg = None |
---|
2176 | |
---|
2177 | try: |
---|
2178 | self.dxl = float(self.smear_slit_height.GetValue()) |
---|
2179 | data.dxl = self.dxl* numpy.ones(data_len) |
---|
2180 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
2181 | except: |
---|
2182 | data.dxl = numpy.zeros(data_len) |
---|
2183 | if self.smear_slit_height.GetValue().lstrip().rstrip()!="": |
---|
2184 | self.smear_slit_height.SetBackgroundColour("pink") |
---|
2185 | msg = "Wrong value entered... " |
---|
2186 | else: |
---|
2187 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
---|
2188 | try: |
---|
2189 | self.dxw = float(self.smear_slit_width.GetValue()) |
---|
2190 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
2191 | data.dxw = self.dxw* numpy.ones(data_len) |
---|
2192 | except: |
---|
2193 | data.dxw = numpy.zeros(data_len) |
---|
2194 | if self.smear_slit_width.GetValue().lstrip().rstrip()!="": |
---|
2195 | self.smear_slit_width.SetBackgroundColour("pink") |
---|
2196 | msg = "Wrong Fit value entered... " |
---|
2197 | else: |
---|
2198 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
---|
2199 | |
---|
2200 | self.current_smearer = smear_selection(data, self.model) |
---|
2201 | #temp_smearer = self.current_smearer |
---|
2202 | ## set smearing value whether or not the data contain the smearing info |
---|
2203 | self._manager.set_smearer(smearer=self.current_smearer, |
---|
2204 | enable2D=self.enable2D, |
---|
2205 | qmin=float(self.qmin_x), |
---|
2206 | qmax= float(self.qmax_x), |
---|
2207 | uid=self.uid) |
---|
2208 | return msg |
---|
2209 | |
---|
2210 | def update_slit_smear(self): |
---|
2211 | """ |
---|
2212 | called by kill_focus on pinhole TextCntrl |
---|
2213 | to update the changes |
---|
2214 | |
---|
2215 | :return: False when wrong value was entered |
---|
2216 | |
---|
2217 | """ |
---|
2218 | # msg default |
---|
2219 | msg = None |
---|
2220 | # check if any value is changed |
---|
2221 | if self._is_changed_slit(): |
---|
2222 | msg = self._set_slit_smear() |
---|
2223 | #self._undo.Enable(True) |
---|
2224 | self.save_current_state() |
---|
2225 | |
---|
2226 | if msg != None: |
---|
2227 | return False |
---|
2228 | else: |
---|
2229 | return True |
---|
2230 | |
---|
2231 | def onSmear(self, event): |
---|
2232 | """ |
---|
2233 | Create a smear object that will change the way residuals |
---|
2234 | are compute when fitting |
---|
2235 | """ |
---|
2236 | if event != None: |
---|
2237 | event.Skip() |
---|
2238 | if self.data is None: |
---|
2239 | return |
---|
2240 | |
---|
2241 | if self.model == None: |
---|
2242 | self.disable_smearer.SetValue(True) |
---|
2243 | msg="Please select a Model first..." |
---|
2244 | wx.MessageBox(msg, 'Info') |
---|
2245 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
2246 | "Smear: %s"%msg)) |
---|
2247 | return |
---|
2248 | |
---|
2249 | # Need update param values |
---|
2250 | self._update_paramv_on_fit() |
---|
2251 | |
---|
2252 | temp_smearer = None |
---|
2253 | self._get_smear_info() |
---|
2254 | |
---|
2255 | #renew smear sizer |
---|
2256 | if self.smear_type != None: |
---|
2257 | self.smear_description_smear_type.SetValue(str(self.smear_type)) |
---|
2258 | self.smear_data_left.SetValue(str(self.dq_l)) |
---|
2259 | self.smear_data_right.SetValue(str(self.dq_r)) |
---|
2260 | |
---|
2261 | self._hide_all_smear_info() |
---|
2262 | |
---|
2263 | data = copy.deepcopy(self.data) |
---|
2264 | # make sure once more if it is smearer |
---|
2265 | self.current_smearer = smear_selection(data, self.model) |
---|
2266 | |
---|
2267 | if self.enable_smearer.GetValue(): |
---|
2268 | if hasattr(self.data,"dxl"): |
---|
2269 | |
---|
2270 | msg= ": Resolution smearing parameters" |
---|
2271 | if hasattr(self.data,"dxw"): |
---|
2272 | msg= ": Slit smearing parameters" |
---|
2273 | if self.smearer ==None: |
---|
2274 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
2275 | "Data contains no smearing information")) |
---|
2276 | else: |
---|
2277 | wx.PostEvent(self._manager.parent, StatusEvent(status=\ |
---|
2278 | "Data contains smearing information")) |
---|
2279 | |
---|
2280 | #self.smear_description_dqdata.Show(True) |
---|
2281 | self.smear_data_left.Show(True) |
---|
2282 | self.smear_data_right.Show(True) |
---|
2283 | temp_smearer= self.current_smearer |
---|
2284 | elif self.disable_smearer.GetValue(): |
---|
2285 | self.smear_description_none.Show(True) |
---|
2286 | |
---|
2287 | self._show_smear_sizer() |
---|
2288 | |
---|
2289 | self.sizer_set_smearer.Layout() |
---|
2290 | self.Layout() |
---|
2291 | ## set smearing value whether or not the data contain the smearing info |
---|
2292 | self._manager.set_smearer(uid=self.uid, smearer=temp_smearer, |
---|
2293 | enable2D=self.enable2D, |
---|
2294 | qmin= float(self.qmin_x), |
---|
2295 | qmax= float(self.qmax_x), draw=True) |
---|
2296 | |
---|
2297 | self.state.enable_smearer= self.enable_smearer.GetValue() |
---|
2298 | self.state.disable_smearer=self.disable_smearer.GetValue() |
---|
2299 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
2300 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
2301 | |
---|
2302 | def on_complete_chisqr(self, event): |
---|
2303 | """ |
---|
2304 | print result chisqr |
---|
2305 | |
---|
2306 | :event: activated by fitting/ complete after draw |
---|
2307 | |
---|
2308 | """ |
---|
2309 | try: |
---|
2310 | if event == None: |
---|
2311 | output= "-" |
---|
2312 | elif not numpy.isfinite(event.output): |
---|
2313 | output= "-" |
---|
2314 | else: |
---|
2315 | output = event.output |
---|
2316 | self.tcChi.SetValue(str(format_number(output, True))) |
---|
2317 | |
---|
2318 | self.state.tcChi = self.tcChi.GetValue() |
---|
2319 | except: |
---|
2320 | pass |
---|
2321 | |
---|
2322 | |
---|
2323 | def select_all_param(self,event): |
---|
2324 | """ |
---|
2325 | set to true or false all checkBox given the main checkbox value cb1 |
---|
2326 | """ |
---|
2327 | self.param_toFit=[] |
---|
2328 | if self.parameters !=[]: |
---|
2329 | if self.cb1.GetValue(): |
---|
2330 | for item in self.parameters: |
---|
2331 | ## for data2D select all to fit |
---|
2332 | if self.data.__class__.__name__== "Data2D" or \ |
---|
2333 | self.enable2D: |
---|
2334 | item[0].SetValue(True) |
---|
2335 | self.param_toFit.append(item ) |
---|
2336 | else: |
---|
2337 | ## for 1D all parameters except orientation |
---|
2338 | if not item in self.orientation_params: |
---|
2339 | item[0].SetValue(True) |
---|
2340 | self.param_toFit.append(item ) |
---|
2341 | #if len(self.fittable_param)>0: |
---|
2342 | for item in self.fittable_param: |
---|
2343 | if self.data.__class__.__name__== "Data2D" or \ |
---|
2344 | self.enable2D: |
---|
2345 | item[0].SetValue(True) |
---|
2346 | self.param_toFit.append(item ) |
---|
2347 | try: |
---|
2348 | if len(self.values[item[1]]) > 0: |
---|
2349 | item[0].SetValue(False) |
---|
2350 | except: |
---|
2351 | pass |
---|
2352 | |
---|
2353 | else: |
---|
2354 | ## for 1D all parameters except orientation |
---|
2355 | if not item in self.orientation_params_disp: |
---|
2356 | item[0].SetValue(True) |
---|
2357 | self.param_toFit.append(item ) |
---|
2358 | try: |
---|
2359 | if len(self.values[item[1]]) > 0: |
---|
2360 | item[0].SetValue(False) |
---|
2361 | except: |
---|
2362 | pass |
---|
2363 | |
---|
2364 | else: |
---|
2365 | for item in self.parameters: |
---|
2366 | item[0].SetValue(False) |
---|
2367 | for item in self.fittable_param: |
---|
2368 | item[0].SetValue(False) |
---|
2369 | self.param_toFit=[] |
---|
2370 | |
---|
2371 | self.save_current_state_fit() |
---|
2372 | |
---|
2373 | if event !=None: |
---|
2374 | #self._undo.Enable(True) |
---|
2375 | ## post state to fit panel |
---|
2376 | event = PageInfoEvent(page = self) |
---|
2377 | wx.PostEvent(self.parent, event) |
---|
2378 | |
---|
2379 | def select_param(self,event): |
---|
2380 | """ |
---|
2381 | Select TextCtrl checked for fitting purpose and stores them |
---|
2382 | in self.param_toFit=[] list |
---|
2383 | """ |
---|
2384 | self.param_toFit=[] |
---|
2385 | for item in self.parameters: |
---|
2386 | #Skip t ifhe angle parameters if 1D data |
---|
2387 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
2388 | not self.enable2D: |
---|
2389 | if item in self.orientation_params: |
---|
2390 | continue |
---|
2391 | #Select parameters to fit for list of primary parameters |
---|
2392 | if item[0].GetValue(): |
---|
2393 | if not (item in self.param_toFit): |
---|
2394 | self.param_toFit.append(item ) |
---|
2395 | else: |
---|
2396 | #remove parameters from the fitting list |
---|
2397 | if item in self.param_toFit: |
---|
2398 | self.param_toFit.remove(item) |
---|
2399 | |
---|
2400 | #Select parameters to fit for list of fittable parameters |
---|
2401 | # with dispersion |
---|
2402 | for item in self.fittable_param: |
---|
2403 | #Skip t ifhe angle parameters if 1D data |
---|
2404 | if self.data.__class__.__name__ != "Data2D" and\ |
---|
2405 | not self.enable2D: |
---|
2406 | if item in self.orientation_params: |
---|
2407 | continue |
---|
2408 | if item[0].GetValue(): |
---|
2409 | if not (item in self.param_toFit): |
---|
2410 | self.param_toFit.append(item) |
---|
2411 | else: |
---|
2412 | #remove parameters from the fitting list |
---|
2413 | if item in self.param_toFit: |
---|
2414 | self.param_toFit.remove(item) |
---|
2415 | |
---|
2416 | #Calculate num. of angle parameters |
---|
2417 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
2418 | self.enable2D: |
---|
2419 | len_orient_para = 0 |
---|
2420 | else: |
---|
2421 | len_orient_para = len(self.orientation_params) #assume even len |
---|
2422 | #Total num. of angle parameters |
---|
2423 | if len(self.fittable_param) > 0: |
---|
2424 | len_orient_para *= 2 |
---|
2425 | #Set the value of checkbox that selected every checkbox or not |
---|
2426 | if len(self.parameters)+len(self.fittable_param)-len_orient_para ==\ |
---|
2427 | len(self.param_toFit): |
---|
2428 | self.cb1.SetValue(True) |
---|
2429 | else: |
---|
2430 | self.cb1.SetValue(False) |
---|
2431 | self.save_current_state_fit() |
---|
2432 | if event !=None: |
---|
2433 | #self._undo.Enable(True) |
---|
2434 | ## post state to fit panel |
---|
2435 | event = PageInfoEvent(page = self) |
---|
2436 | wx.PostEvent(self.parent, event) |
---|
2437 | |
---|
2438 | def set_model_param_sizer(self, model): |
---|
2439 | """ |
---|
2440 | Build the panel from the model content |
---|
2441 | |
---|
2442 | :param model: the model selected in combo box for fitting purpose |
---|
2443 | |
---|
2444 | """ |
---|
2445 | self.sizer3.Clear(True) |
---|
2446 | self.parameters = [] |
---|
2447 | self.str_parameters = [] |
---|
2448 | self.param_toFit=[] |
---|
2449 | self.fittable_param=[] |
---|
2450 | self.fixed_param=[] |
---|
2451 | self.orientation_params=[] |
---|
2452 | self.orientation_params_disp=[] |
---|
2453 | |
---|
2454 | if model ==None: |
---|
2455 | self.sizer3.Layout() |
---|
2456 | self.SetupScrolling() |
---|
2457 | return |
---|
2458 | ## the panel is drawn using the current value of the fit engine |
---|
2459 | if self.engine_type==None and self._manager !=None: |
---|
2460 | self.engine_type= self._manager._return_engine_type() |
---|
2461 | |
---|
2462 | box_description= wx.StaticBox(self, -1,str("Model Parameters")) |
---|
2463 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
2464 | sizer = wx.GridBagSizer(5,5) |
---|
2465 | ## save the current model |
---|
2466 | self.model = model |
---|
2467 | |
---|
2468 | keys = self.model.getParamList() |
---|
2469 | #list of dispersion paramaters |
---|
2470 | self.disp_list=self.model.getDispParamList() |
---|
2471 | |
---|
2472 | def custom_compare(a,b): |
---|
2473 | """ |
---|
2474 | Custom compare to order, first by alphabets then second by number. |
---|
2475 | """ |
---|
2476 | # number at the last digit |
---|
2477 | a_last = a[len(a)-1] |
---|
2478 | b_last = b[len(b)-1] |
---|
2479 | # default |
---|
2480 | num_a = None |
---|
2481 | num_b = None |
---|
2482 | # split the names |
---|
2483 | a2 = a.lower().split('_') |
---|
2484 | b2 = b.lower().split('_') |
---|
2485 | # check length of a2, b2 |
---|
2486 | len_a2 = len(a2) |
---|
2487 | len_b2 = len(b2) |
---|
2488 | # check if it contains a int number(<10) |
---|
2489 | try: |
---|
2490 | num_a = int(a_last) |
---|
2491 | except: pass |
---|
2492 | try: |
---|
2493 | num_b = int(b_last) |
---|
2494 | except: pass |
---|
2495 | # Put 'scale' near the top; happens |
---|
2496 | # when numbered param name exists |
---|
2497 | if a == 'scale': |
---|
2498 | return -1 |
---|
2499 | # both have a number |
---|
2500 | if num_a != None and num_b != None: |
---|
2501 | if num_a > num_b: return -1 |
---|
2502 | # same number |
---|
2503 | elif num_a == num_b: |
---|
2504 | # different last names |
---|
2505 | if a2[len_a2-1] != b2[len_b2-1] and num_a != 0: |
---|
2506 | return -cmp(a2[len_a2-1], b2[len_b2-1]) |
---|
2507 | else: |
---|
2508 | return cmp(a, b) |
---|
2509 | else: return 1 |
---|
2510 | # one of them has a number |
---|
2511 | elif num_a != None: return 1 |
---|
2512 | elif num_b != None: return -1 |
---|
2513 | # no numbers |
---|
2514 | else: return cmp(a.lower(), b.lower()) |
---|
2515 | |
---|
2516 | |
---|
2517 | keys.sort(custom_compare) |
---|
2518 | |
---|
2519 | iy = 0 |
---|
2520 | ix = 0 |
---|
2521 | select_text = "Select All" |
---|
2522 | self.cb1 = wx.CheckBox(self, -1,str(select_text), (10, 10)) |
---|
2523 | wx.EVT_CHECKBOX(self, self.cb1.GetId(), self.select_all_param) |
---|
2524 | self.cb1.SetToolTipString("To check/uncheck all the boxes below.") |
---|
2525 | self.cb1.SetValue(True) |
---|
2526 | |
---|
2527 | sizer.Add(self.cb1,(iy, ix),(1,1),\ |
---|
2528 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
2529 | ix +=1 |
---|
2530 | self.text2_2 = wx.StaticText(self, -1, 'Values') |
---|
2531 | sizer.Add(self.text2_2,(iy, ix),(1,1),\ |
---|
2532 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2533 | ix +=2 |
---|
2534 | self.text2_3 = wx.StaticText(self, -1, 'Errors') |
---|
2535 | sizer.Add(self.text2_3,(iy, ix),(1,1),\ |
---|
2536 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2537 | self.text2_3.Hide() |
---|
2538 | ix +=1 |
---|
2539 | self.text2_min = wx.StaticText(self, -1, 'Min') |
---|
2540 | sizer.Add(self.text2_min,(iy, ix),(1,1),\ |
---|
2541 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2542 | #self.text2_min.Hide() |
---|
2543 | ix +=1 |
---|
2544 | self.text2_max = wx.StaticText(self, -1, 'Max') |
---|
2545 | sizer.Add(self.text2_max,(iy, ix),(1,1),\ |
---|
2546 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2547 | #self.text2_max.Hide() |
---|
2548 | ix += 1 |
---|
2549 | self.text2_4 = wx.StaticText(self, -1, '[Units]') |
---|
2550 | sizer.Add(self.text2_4,(iy, ix),(1,1),\ |
---|
2551 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2552 | self.text2_4.Hide() |
---|
2553 | |
---|
2554 | for item in keys: |
---|
2555 | if not item in self.disp_list and not item in \ |
---|
2556 | self.model.orientation_params: |
---|
2557 | |
---|
2558 | ##prepare a spot to store errors |
---|
2559 | if not self.model.details.has_key(item): |
---|
2560 | self.model.details [item] = ["",None,None] |
---|
2561 | |
---|
2562 | iy += 1 |
---|
2563 | ix = 0 |
---|
2564 | if self.model.__class__ in \ |
---|
2565 | self.model_list_box["Multi-Functions"] \ |
---|
2566 | and item in self.model.non_fittable: |
---|
2567 | non_fittable_name = wx.StaticText(self, -1, item ) |
---|
2568 | sizer.Add(non_fittable_name,(iy, ix),(1,1),\ |
---|
2569 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 21) |
---|
2570 | ## add parameter value |
---|
2571 | ix += 1 |
---|
2572 | value= self.model.getParam(item) |
---|
2573 | if len(self.model.fun_list) > 0: |
---|
2574 | num = item.split('_')[1][5:7] |
---|
2575 | fun_box = wx.ComboBox(self, -1,size=(100,-1), |
---|
2576 | style=wx.CB_READONLY, name = '%s'% item) |
---|
2577 | self._set_fun_box_list(fun_box) |
---|
2578 | fun_box.SetSelection(0) |
---|
2579 | #self.fun_box.SetToolTipString("A function |
---|
2580 | # describing the interface") |
---|
2581 | wx.EVT_COMBOBOX(fun_box,-1, self._on_fun_box) |
---|
2582 | else: |
---|
2583 | fun_box = self.ModelTextCtrl(self, -1, |
---|
2584 | size=(_BOX_WIDTH,20), |
---|
2585 | style=wx.TE_PROCESS_ENTER, name ='%s'% item) |
---|
2586 | fun_box.SetToolTipString("Hit 'Enter' after typing.") |
---|
2587 | fun_box.SetValue(format_number(value, True)) |
---|
2588 | sizer.Add(fun_box, (iy,ix),(1,1), wx.EXPAND) |
---|
2589 | self.str_parameters.append([None,item, fun_box, |
---|
2590 | None, None, None, |
---|
2591 | None, None]) |
---|
2592 | |
---|
2593 | |
---|
2594 | else: |
---|
2595 | ## add parameters name with checkbox for selecting to fit |
---|
2596 | cb = wx.CheckBox(self, -1, item ) |
---|
2597 | cb.SetToolTipString(" Check mark to fit.") |
---|
2598 | #cb.SetValue(True) |
---|
2599 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
2600 | |
---|
2601 | sizer.Add( cb,( iy, ix),(1,1), |
---|
2602 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
2603 | |
---|
2604 | ## add parameter value |
---|
2605 | ix += 1 |
---|
2606 | value= self.model.getParam(item) |
---|
2607 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
2608 | style=wx.TE_PROCESS_ENTER) |
---|
2609 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
2610 | ctl1.SetValue(format_number(value, True)) |
---|
2611 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
2612 | ## text to show error sign |
---|
2613 | ix += 1 |
---|
2614 | text2=wx.StaticText(self, -1, '+/-') |
---|
2615 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
2616 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2617 | text2.Hide() |
---|
2618 | ix += 1 |
---|
2619 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.2,20), style=0) |
---|
2620 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
2621 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2622 | ctl2.Hide() |
---|
2623 | |
---|
2624 | ix += 1 |
---|
2625 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.9,20), |
---|
2626 | style=wx.TE_PROCESS_ENTER, |
---|
2627 | text_enter_callback = self._onparamRangeEnter) |
---|
2628 | |
---|
2629 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
2630 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2631 | |
---|
2632 | ix += 1 |
---|
2633 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.9,20), |
---|
2634 | style=wx.TE_PROCESS_ENTER, |
---|
2635 | text_enter_callback = self._onparamRangeEnter) |
---|
2636 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
2637 | wx.EXPAND|wx.FIXED_MINSIZE, 0) |
---|
2638 | |
---|
2639 | ix +=1 |
---|
2640 | # Units |
---|
2641 | if self.model.details.has_key(item): |
---|
2642 | units = wx.StaticText(self, -1, |
---|
2643 | self.model.details[item][0], style=wx.ALIGN_LEFT) |
---|
2644 | else: |
---|
2645 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
2646 | sizer.Add(units, (iy,ix),(1,1), |
---|
2647 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2648 | |
---|
2649 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
2650 | self.parameters.append([cb,item, ctl1, |
---|
2651 | text2,ctl2, ctl3, ctl4,units]) |
---|
2652 | |
---|
2653 | iy+=1 |
---|
2654 | sizer.Add((10,10),(iy,ix),(1,1), |
---|
2655 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
2656 | |
---|
2657 | # type can be either Guassian or Array |
---|
2658 | if len(self.model.dispersion.values())>0: |
---|
2659 | type= self.model.dispersion.values()[0]["type"] |
---|
2660 | else: |
---|
2661 | type = "Gaussian" |
---|
2662 | |
---|
2663 | iy += 1 |
---|
2664 | ix = 0 |
---|
2665 | #Add tile for orientational angle |
---|
2666 | for item in keys: |
---|
2667 | if item in self.model.orientation_params: |
---|
2668 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
---|
2669 | sizer.Add(orient_angle,(iy, ix),(1,1), |
---|
2670 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
2671 | if not self.data.__class__.__name__ == "Data2D" and \ |
---|
2672 | not self.enable2D: |
---|
2673 | orient_angle.Hide() |
---|
2674 | else: |
---|
2675 | orient_angle.Show(True) |
---|
2676 | break |
---|
2677 | |
---|
2678 | #For Gaussian only |
---|
2679 | if type.lower() != "array": |
---|
2680 | for item in self.model.orientation_params: |
---|
2681 | if not item in self.disp_list: |
---|
2682 | ##prepare a spot to store min max |
---|
2683 | if not self.model.details.has_key(item): |
---|
2684 | self.model.details [item] = ["",None,None] |
---|
2685 | |
---|
2686 | iy += 1 |
---|
2687 | ix = 0 |
---|
2688 | ## add parameters name with checkbox for selecting to fit |
---|
2689 | cb = wx.CheckBox(self, -1, item ) |
---|
2690 | cb.SetValue(False) |
---|
2691 | cb.SetToolTipString("Check mark to fit") |
---|
2692 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
---|
2693 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
2694 | self.enable2D: |
---|
2695 | cb.Show(True) |
---|
2696 | else: |
---|
2697 | cb.Hide() |
---|
2698 | sizer.Add( cb,( iy, ix),(1,1), |
---|
2699 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
2700 | |
---|
2701 | ## add parameter value |
---|
2702 | ix += 1 |
---|
2703 | value= self.model.getParam(item) |
---|
2704 | ctl1 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH,20), |
---|
2705 | style=wx.TE_PROCESS_ENTER) |
---|
2706 | ctl1.SetToolTipString("Hit 'Enter' after typing.") |
---|
2707 | ctl1.SetValue(format_number(value, True)) |
---|
2708 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
2709 | self.enable2D: |
---|
2710 | ctl1.Show(True) |
---|
2711 | else: |
---|
2712 | ctl1.Hide() |
---|
2713 | sizer.Add(ctl1, (iy,ix),(1,1), wx.EXPAND) |
---|
2714 | ## text to show error sign |
---|
2715 | ix += 1 |
---|
2716 | text2=wx.StaticText(self, -1, '+/-') |
---|
2717 | sizer.Add(text2,(iy, ix),(1,1),\ |
---|
2718 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2719 | text2.Hide() |
---|
2720 | ix += 1 |
---|
2721 | ctl2 = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/1.2,20), style=0) |
---|
2722 | sizer.Add(ctl2, (iy,ix),(1,1), |
---|
2723 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2724 | ctl2.Hide() |
---|
2725 | |
---|
2726 | |
---|
2727 | ix += 1 |
---|
2728 | ctl3 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.8,20), |
---|
2729 | style=wx.TE_PROCESS_ENTER, |
---|
2730 | text_enter_callback = self._onparamRangeEnter) |
---|
2731 | |
---|
2732 | sizer.Add(ctl3, (iy,ix),(1,1), |
---|
2733 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2734 | ctl3.Hide() |
---|
2735 | |
---|
2736 | ix += 1 |
---|
2737 | ctl4 = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH/1.8,20), |
---|
2738 | style=wx.TE_PROCESS_ENTER, |
---|
2739 | text_enter_callback = self._onparamRangeEnter) |
---|
2740 | sizer.Add(ctl4, (iy,ix),(1,1), |
---|
2741 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2742 | |
---|
2743 | ctl4.Hide() |
---|
2744 | |
---|
2745 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
2746 | self.enable2D: |
---|
2747 | ctl3.Show(True) |
---|
2748 | ctl4.Show(True) |
---|
2749 | |
---|
2750 | ix +=1 |
---|
2751 | # Units |
---|
2752 | if self.model.details.has_key(item): |
---|
2753 | units = wx.StaticText(self, -1, |
---|
2754 | self.model.details[item][0], |
---|
2755 | style=wx.ALIGN_LEFT) |
---|
2756 | else: |
---|
2757 | units = wx.StaticText(self, -1, "", style=wx.ALIGN_LEFT) |
---|
2758 | if self.data.__class__.__name__ == "Data2D" or \ |
---|
2759 | self.enable2D: |
---|
2760 | units.Show(True) |
---|
2761 | |
---|
2762 | else: |
---|
2763 | units.Hide() |
---|
2764 | |
---|
2765 | sizer.Add(units, (iy,ix),(1,1), |
---|
2766 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
2767 | |
---|
2768 | ##[cb state, name, value, "+/-", error of fit,min,max,units] |
---|
2769 | self.parameters.append([cb,item, ctl1, |
---|
2770 | text2,ctl2, ctl3, ctl4,units]) |
---|
2771 | self.orientation_params.append([cb,item, ctl1, |
---|
2772 | text2,ctl2, ctl3, ctl4,units]) |
---|
2773 | |
---|
2774 | iy+=1 |
---|
2775 | |
---|
2776 | #Display units text on panel |
---|
2777 | for item in keys: |
---|
2778 | if self.model.details.has_key(item): |
---|
2779 | self.text2_4.Show() |
---|
2780 | #Fill the list of fittable parameters |
---|
2781 | self.select_all_param(event=None) |
---|
2782 | |
---|
2783 | self.save_current_state_fit() |
---|
2784 | boxsizer1.Add(sizer) |
---|
2785 | self.sizer3.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
2786 | self.sizer3.Layout() |
---|
2787 | self.Layout() |
---|
2788 | self.Refresh() |
---|
2789 | |
---|
2790 | def on_right_down(self, event): |
---|
2791 | """ |
---|
2792 | Get key stroke event |
---|
2793 | """ |
---|
2794 | if self.data == None: |
---|
2795 | return |
---|
2796 | # Figuring out key combo: Cmd for copy, Alt for paste |
---|
2797 | if event.AltDown() and event.ShiftDown(): |
---|
2798 | self._show_ftol_dialog() |
---|
2799 | flag = True |
---|
2800 | elif event.AltDown() or event.ShiftDown(): |
---|
2801 | flag = False |
---|
2802 | else: |
---|
2803 | return |
---|
2804 | # make event free |
---|
2805 | event.Skip() |
---|
2806 | # messages depending on the flag |
---|
2807 | if not flag: |
---|
2808 | msg = " Could not open ftol dialog;" |
---|
2809 | msg += " Check if the Scipy fit engine is selected in the menubar." |
---|
2810 | infor = 'warning' |
---|
2811 | # inform msg to wx |
---|
2812 | wx.PostEvent( self.parent.parent, |
---|
2813 | StatusEvent(status= msg, info=infor)) |
---|
2814 | |
---|
2815 | |
---|
2816 | def _show_ftol_dialog(self): |
---|
2817 | """ |
---|
2818 | Dialog to select ftol for Scipy |
---|
2819 | """ |
---|
2820 | from ftol_dialog import ChangeFtol |
---|
2821 | panel = ChangeFtol(self) |
---|
2822 | panel.ShowModal() |
---|
2823 | |
---|
2824 | def _onModel2D(self, event): |
---|
2825 | """ |
---|
2826 | toggle view of model from 1D to 2D or 2D from 1D |
---|
2827 | """ |
---|
2828 | if self.model_view.GetLabelText() == "Switch to 2D": |
---|
2829 | self.model_view.SetLabel("Switch to 1D") |
---|
2830 | self.enable2D = True |
---|
2831 | |
---|
2832 | else: |
---|
2833 | self.model_view.SetLabel("Switch to 2D") |
---|
2834 | self.enable2D = False |
---|
2835 | |
---|
2836 | self.set_model_param_sizer(self.model) |
---|
2837 | self._set_sizer_dispersion() |
---|
2838 | self._draw_model() |
---|
2839 | |
---|
2840 | |
---|
2841 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
2842 | |
---|
2843 | class BGTextCtrl(wx.TextCtrl): |
---|
2844 | """ |
---|
2845 | Text control used to display outputs. |
---|
2846 | No editing allowed. The background is |
---|
2847 | grayed out. User can't select text. |
---|
2848 | """ |
---|
2849 | def __init__(self, *args, **kwds): |
---|
2850 | wx.TextCtrl.__init__(self, *args, **kwds) |
---|
2851 | self.SetEditable(False) |
---|
2852 | self.SetBackgroundColour(self.GetParent().parent.GetBackgroundColour()) |
---|
2853 | |
---|
2854 | # Bind to mouse event to avoid text highlighting |
---|
2855 | # The event will be skipped once the call-back |
---|
2856 | # is called. |
---|
2857 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
---|
2858 | |
---|
2859 | def _click(self, event): |
---|
2860 | """ |
---|
2861 | Prevent further handling of the mouse event |
---|
2862 | by not calling Skip(). |
---|
2863 | """ |
---|
2864 | pass |
---|
2865 | |
---|