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