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