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