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