1 | """ |
---|
2 | Base Page for fitting |
---|
3 | """ |
---|
4 | import sys |
---|
5 | import os |
---|
6 | import wx |
---|
7 | import numpy |
---|
8 | import time |
---|
9 | import copy |
---|
10 | import math |
---|
11 | import string |
---|
12 | import cPickle as pickle |
---|
13 | #import shutil |
---|
14 | from collections import defaultdict |
---|
15 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
16 | from sans.guiframe.panel_base import PanelBase |
---|
17 | from sans.guiframe.utils import format_number, check_float |
---|
18 | from sans.guiframe.events import PanelOnFocusEvent |
---|
19 | from sans.guiframe.events import StatusEvent |
---|
20 | from sans.guiframe.events import AppendBookmarkEvent |
---|
21 | from sans.guiframe.dataFitting import Data2D |
---|
22 | from sans.guiframe.dataFitting import Data1D |
---|
23 | from sans.guiframe.dataFitting import check_data_validity |
---|
24 | from sans.dataloader.data_info import Detector |
---|
25 | from sans.dataloader.data_info import Source |
---|
26 | from sans.perspectives.fitting.pagestate import PageState |
---|
27 | from sans.guiframe.CategoryInstaller import CategoryInstaller |
---|
28 | |
---|
29 | (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent() |
---|
30 | (PreviousStateEvent, EVT_PREVIOUS_STATE) = wx.lib.newevent.NewEvent() |
---|
31 | (NextStateEvent, EVT_NEXT_STATE) = wx.lib.newevent.NewEvent() |
---|
32 | |
---|
33 | _BOX_WIDTH = 76 |
---|
34 | _QMIN_DEFAULT = 0.0005 |
---|
35 | _QMAX_DEFAULT = 0.5 |
---|
36 | _NPTS_DEFAULT = 50 |
---|
37 | #Control panel width |
---|
38 | if sys.platform.count("win32") > 0: |
---|
39 | PANEL_WIDTH = 450 |
---|
40 | FONT_VARIANT = 0 |
---|
41 | ON_MAC = False |
---|
42 | else: |
---|
43 | PANEL_WIDTH = 500 |
---|
44 | FONT_VARIANT = 1 |
---|
45 | ON_MAC = True |
---|
46 | |
---|
47 | |
---|
48 | class BasicPage(ScrolledPanel, PanelBase): |
---|
49 | """ |
---|
50 | This class provide general structure of fitpanel page |
---|
51 | """ |
---|
52 | ## Internal name for the AUI manager |
---|
53 | window_name = "Fit Page" |
---|
54 | ## Title to appear on top of the window |
---|
55 | window_caption = "Fit Page " |
---|
56 | |
---|
57 | def __init__(self, parent, color='blue', **kwargs): |
---|
58 | """ |
---|
59 | """ |
---|
60 | ScrolledPanel.__init__(self, parent, **kwargs) |
---|
61 | PanelBase.__init__(self, parent) |
---|
62 | self.SetupScrolling() |
---|
63 | #Set window's font size |
---|
64 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
65 | |
---|
66 | self.SetBackgroundColour(color) |
---|
67 | ## parent of the page |
---|
68 | self.parent = parent |
---|
69 | ## manager is the fitting plugin |
---|
70 | ## owner of the page (fitting plugin) |
---|
71 | self.event_owner = None |
---|
72 | ## current model |
---|
73 | self.model = None |
---|
74 | self.m_name = None |
---|
75 | self.index_model = None |
---|
76 | self.panel = None |
---|
77 | ## data |
---|
78 | self.data = None |
---|
79 | #list of available data |
---|
80 | self.data_list = [] |
---|
81 | self.mask = None |
---|
82 | self.uid = wx.NewId() |
---|
83 | self.graph_id = None |
---|
84 | #Q range for data set |
---|
85 | self.qmin_data_set = numpy.inf |
---|
86 | self.qmax_data_set = None |
---|
87 | self.npts_data_set = 0 |
---|
88 | ## Q range |
---|
89 | self.qmin = None |
---|
90 | self.qmax = None |
---|
91 | self.qmax_x = _QMAX_DEFAULT |
---|
92 | self.qmin_x = _QMIN_DEFAULT |
---|
93 | self.npts_x = _NPTS_DEFAULT |
---|
94 | ## total number of point: float |
---|
95 | self.npts = None |
---|
96 | self.num_points = None |
---|
97 | ## default fitengine type |
---|
98 | self.engine_type = 'scipy' |
---|
99 | ## smear default |
---|
100 | self.current_smearer = None |
---|
101 | ## 2D smear accuracy default |
---|
102 | self.smear2d_accuracy = 'Low' |
---|
103 | ## slit smear: |
---|
104 | self.dxl = None |
---|
105 | self.dxw = None |
---|
106 | ## pinhole smear |
---|
107 | self.dx_min = None |
---|
108 | self.dx_max = None |
---|
109 | ##semar attrbs |
---|
110 | self.enable_smearer = None |
---|
111 | self.disable_smearer = None |
---|
112 | self.pinhole_smearer = None |
---|
113 | self.slit_smearer = None |
---|
114 | ##weigth attrbs |
---|
115 | self.dI_noweight = None |
---|
116 | self.dI_didata = None |
---|
117 | self.dI_sqrdata = None |
---|
118 | self.dI_idata = None |
---|
119 | ##other attrbs |
---|
120 | self.dq_l = None |
---|
121 | self.dq_r = None |
---|
122 | self.tcChi = None |
---|
123 | self.disp_box = None |
---|
124 | self.model_disp = None |
---|
125 | self.Npts_fit = None |
---|
126 | self.Npts_total = None |
---|
127 | self.theory_qmin = None |
---|
128 | self.theory_qmax = None |
---|
129 | self.theory_qmin_x = None |
---|
130 | self.theory_qmax_x = None |
---|
131 | self.cb1 = None |
---|
132 | self.btEditMask = None |
---|
133 | self.btFit = None |
---|
134 | self.sld_axes = None |
---|
135 | self.multi_factor = None |
---|
136 | |
---|
137 | self.disp_cb_dict = {} |
---|
138 | |
---|
139 | #self.state = PageState(parent=parent) |
---|
140 | ## dictionary containing list of models |
---|
141 | self.model_list_box = {} |
---|
142 | |
---|
143 | ## Data member to store the dispersion object created |
---|
144 | self._disp_obj_dict = {} |
---|
145 | ## selected parameters to apply dispersion |
---|
146 | self.disp_cb_dict = {} |
---|
147 | ## smearer object |
---|
148 | self.enable2D = False |
---|
149 | self._has_magnetic = False |
---|
150 | self.magnetic_on = False |
---|
151 | self.is_mac = ON_MAC |
---|
152 | self.formfactorbox = None |
---|
153 | self.structurebox = None |
---|
154 | self.categorybox = None |
---|
155 | ##list of model parameters. each item must have same length |
---|
156 | ## each item related to a given parameters |
---|
157 | ##[cb state, name, value, "+/-", error of fit, min, max , units] |
---|
158 | self.parameters = [] |
---|
159 | # non-fittable parameter whose value is astring |
---|
160 | self.str_parameters = [] |
---|
161 | ## list of parameters to fit , must be like self.parameters |
---|
162 | self.param_toFit = [] |
---|
163 | ## list of looking like parameters but with non fittable parameters info |
---|
164 | self.fixed_param = [] |
---|
165 | ## list of looking like parameters but with fittable parameters info |
---|
166 | self.fittable_param = [] |
---|
167 | ##list of dispersion parameters |
---|
168 | self.disp_list = [] |
---|
169 | self.disp_name = "" |
---|
170 | |
---|
171 | ## list of orientation parameters |
---|
172 | self.orientation_params = [] |
---|
173 | self.orientation_params_disp = [] |
---|
174 | if self.model != None: |
---|
175 | self.disp_list = self.model.getDispParamList() |
---|
176 | self.temp_multi_functional = False |
---|
177 | ##enable model 2D draw |
---|
178 | self.enable2D = False |
---|
179 | ## check that the fit range is correct to plot the model again |
---|
180 | self.fitrange = True |
---|
181 | ## Create memento to save the current state |
---|
182 | self.state = PageState(parent=self.parent, |
---|
183 | model=self.model, data=self.data) |
---|
184 | ## flag to determine if state has change |
---|
185 | self.state_change = False |
---|
186 | ## save customized array |
---|
187 | self.values = [] |
---|
188 | self.weights = [] |
---|
189 | ## retrieve saved state |
---|
190 | self.number_saved_state = 0 |
---|
191 | ## dictionary of saved state |
---|
192 | self.saved_states = {} |
---|
193 | ## Create context menu for page |
---|
194 | self.popUpMenu = wx.Menu() |
---|
195 | |
---|
196 | id = wx.NewId() |
---|
197 | self._keep = wx.MenuItem(self.popUpMenu, id, "Add bookmark", |
---|
198 | " Keep the panel status to recall it later") |
---|
199 | self.popUpMenu.AppendItem(self._keep) |
---|
200 | self._keep.Enable(False) |
---|
201 | self._set_bookmark_flag(False) |
---|
202 | self._set_save_flag(False) |
---|
203 | wx.EVT_MENU(self, id, self.on_bookmark) |
---|
204 | self.popUpMenu.AppendSeparator() |
---|
205 | |
---|
206 | ## Default locations |
---|
207 | self._default_save_location = os.getcwd() |
---|
208 | ## save initial state on context menu |
---|
209 | #self.onSave(event=None) |
---|
210 | self.Bind(wx.EVT_CONTEXT_MENU, self.onContextMenu) |
---|
211 | |
---|
212 | # bind key event |
---|
213 | self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down) |
---|
214 | |
---|
215 | ## create the basic structure of the panel with empty sizer |
---|
216 | self.define_page_structure() |
---|
217 | ## drawing Initial dispersion parameters sizer |
---|
218 | self.set_dispers_sizer() |
---|
219 | |
---|
220 | ## layout |
---|
221 | self.set_layout() |
---|
222 | |
---|
223 | def set_index_model(self, index): |
---|
224 | """ |
---|
225 | Index related to this page |
---|
226 | """ |
---|
227 | self.index_model = index |
---|
228 | |
---|
229 | def create_default_data(self): |
---|
230 | """ |
---|
231 | Given the user selection, creates a 1D or 2D data |
---|
232 | Only when the page is on theory mode. |
---|
233 | """ |
---|
234 | if not hasattr(self, "model_view"): |
---|
235 | return |
---|
236 | toggle_mode_on = self.model_view.IsEnabled() |
---|
237 | if toggle_mode_on: |
---|
238 | if self.enable2D and not check_data_validity(self.data): |
---|
239 | self._create_default_2d_data() |
---|
240 | else: |
---|
241 | self._create_default_1d_data() |
---|
242 | if self.model != None: |
---|
243 | if not self.data.is_data: |
---|
244 | self._manager.page_finder[self.uid].set_fit_data(data=\ |
---|
245 | [self.data]) |
---|
246 | self.on_smear_helper(update=True) |
---|
247 | self.state.enable_smearer = self.enable_smearer.GetValue() |
---|
248 | self.state.disable_smearer = self.disable_smearer.GetValue() |
---|
249 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
---|
250 | self.state.slit_smearer = self.slit_smearer.GetValue() |
---|
251 | |
---|
252 | def _create_default_1d_data(self): |
---|
253 | """ |
---|
254 | Create default data for fitting perspective |
---|
255 | Only when the page is on theory mode. |
---|
256 | :warning: This data is never plotted. |
---|
257 | |
---|
258 | """ |
---|
259 | x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, |
---|
260 | num=self.npts_x, endpoint=True) |
---|
261 | self.data = Data1D(x=x) |
---|
262 | self.data.xaxis('\\rm{Q}', "A^{-1}") |
---|
263 | self.data.yaxis('\\rm{Intensity}', "cm^{-1}") |
---|
264 | self.data.is_data = False |
---|
265 | self.data.id = str(self.uid) + " data" |
---|
266 | self.data.group_id = str(self.uid) + " Model1D" |
---|
267 | |
---|
268 | def _create_default_2d_data(self): |
---|
269 | """ |
---|
270 | Create 2D data by default |
---|
271 | Only when the page is on theory mode. |
---|
272 | :warning: This data is never plotted. |
---|
273 | """ |
---|
274 | self.data = Data2D() |
---|
275 | qmax = self.qmax_x / math.sqrt(2) |
---|
276 | self.data.xaxis('\\rm{Q_{x}}', 'A^{-1}') |
---|
277 | self.data.yaxis('\\rm{Q_{y}}', 'A^{-1}') |
---|
278 | self.data.is_data = False |
---|
279 | self.data.id = str(self.uid) + " data" |
---|
280 | self.data.group_id = str(self.uid) + " Model2D" |
---|
281 | ## Default values |
---|
282 | self.data.detector.append(Detector()) |
---|
283 | index = len(self.data.detector) - 1 |
---|
284 | self.data.detector[index].distance = 8000 # mm |
---|
285 | self.data.source.wavelength = 6 # A |
---|
286 | self.data.detector[index].pixel_size.x = 5 # mm |
---|
287 | self.data.detector[index].pixel_size.y = 5 # mm |
---|
288 | self.data.detector[index].beam_center.x = qmax |
---|
289 | self.data.detector[index].beam_center.y = qmax |
---|
290 | ## create x_bins and y_bins of the model 2D |
---|
291 | #pixel_width_x = self.data.detector[index].pixel_size.x |
---|
292 | #pixel_width_y = self.data.detector[index].pixel_size.y |
---|
293 | #center_x = self.data.detector[index].beam_center.x/pixel_width_x |
---|
294 | #center_y = self.data.detector[index].beam_center.y/pixel_width_y |
---|
295 | # theory default: assume the beam |
---|
296 | #center is located at the center of sqr detector |
---|
297 | xmax = qmax |
---|
298 | xmin = -qmax |
---|
299 | ymax = qmax |
---|
300 | ymin = -qmax |
---|
301 | qstep = self.npts_x |
---|
302 | |
---|
303 | x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
---|
304 | y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) |
---|
305 | ## use data info instead |
---|
306 | new_x = numpy.tile(x, (len(y), 1)) |
---|
307 | new_y = numpy.tile(y, (len(x), 1)) |
---|
308 | new_y = new_y.swapaxes(0, 1) |
---|
309 | # all data reuire now in 1d array |
---|
310 | qx_data = new_x.flatten() |
---|
311 | qy_data = new_y.flatten() |
---|
312 | q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) |
---|
313 | # set all True (standing for unmasked) as default |
---|
314 | mask = numpy.ones(len(qx_data), dtype=bool) |
---|
315 | # calculate the range of qx and qy: this way, |
---|
316 | # it is a little more independent |
---|
317 | #x_size = xmax - xmin |
---|
318 | #y_size = ymax - ymin |
---|
319 | # store x and y bin centers in q space |
---|
320 | x_bins = x |
---|
321 | y_bins = y |
---|
322 | # bin size: x- & y-directions |
---|
323 | #xstep = x_size / len(x_bins - 1) |
---|
324 | #ystep = y_size / len(y_bins - 1) |
---|
325 | |
---|
326 | self.data.source = Source() |
---|
327 | self.data.data = numpy.ones(len(mask)) |
---|
328 | self.data.err_data = numpy.ones(len(mask)) |
---|
329 | self.data.qx_data = qx_data |
---|
330 | self.data.qy_data = qy_data |
---|
331 | self.data.q_data = q_data |
---|
332 | self.data.mask = mask |
---|
333 | self.data.x_bins = x_bins |
---|
334 | self.data.y_bins = y_bins |
---|
335 | # max and min taking account of the bin sizes |
---|
336 | self.data.xmin = xmin |
---|
337 | self.data.xmax = xmax |
---|
338 | self.data.ymin = ymin |
---|
339 | self.data.ymax = ymax |
---|
340 | |
---|
341 | def on_set_focus(self, event): |
---|
342 | """ |
---|
343 | On Set Focus, update guimanger and menu |
---|
344 | """ |
---|
345 | if self._manager is not None: |
---|
346 | wx.PostEvent(self._manager.parent, PanelOnFocusEvent(panel=self)) |
---|
347 | self.on_tap_focus() |
---|
348 | |
---|
349 | def on_tap_focus(self): |
---|
350 | """ |
---|
351 | Update menu1 on cliking the page tap |
---|
352 | """ |
---|
353 | if self._manager.menu1 != None: |
---|
354 | chain_menu = self._manager.menu1.FindItemById(\ |
---|
355 | self._manager.id_reset_flag) |
---|
356 | chain_menu.Enable(self.batch_on) |
---|
357 | sim_menu = self._manager.menu1.FindItemById(self._manager.id_simfit) |
---|
358 | flag = self.data.is_data\ |
---|
359 | and (self.model != None) |
---|
360 | sim_menu.Enable(not self.batch_on and flag) |
---|
361 | batch_menu = \ |
---|
362 | self._manager.menu1.FindItemById(self._manager.id_batchfit) |
---|
363 | batch_menu.Enable(self.batch_on and flag) |
---|
364 | |
---|
365 | class ModelTextCtrl(wx.TextCtrl): |
---|
366 | """ |
---|
367 | Text control for model and fit parameters. |
---|
368 | Binds the appropriate events for user interactions. |
---|
369 | Default callback methods can be overwritten on initialization |
---|
370 | |
---|
371 | :param kill_focus_callback: callback method for EVT_KILL_FOCUS event |
---|
372 | :param set_focus_callback: callback method for EVT_SET_FOCUS event |
---|
373 | :param mouse_up_callback: callback method for EVT_LEFT_UP event |
---|
374 | :param text_enter_callback: callback method for EVT_TEXT_ENTER event |
---|
375 | |
---|
376 | """ |
---|
377 | ## Set to True when the mouse is clicked while whole string is selected |
---|
378 | full_selection = False |
---|
379 | ## Call back for EVT_SET_FOCUS events |
---|
380 | _on_set_focus_callback = None |
---|
381 | |
---|
382 | def __init__(self, parent, id=-1, |
---|
383 | value=wx.EmptyString, |
---|
384 | pos=wx.DefaultPosition, |
---|
385 | size=wx.DefaultSize, |
---|
386 | style=0, |
---|
387 | validator=wx.DefaultValidator, |
---|
388 | name=wx.TextCtrlNameStr, |
---|
389 | kill_focus_callback=None, |
---|
390 | set_focus_callback=None, |
---|
391 | mouse_up_callback=None, |
---|
392 | text_enter_callback=None): |
---|
393 | |
---|
394 | wx.TextCtrl.__init__(self, parent, id, value, pos, |
---|
395 | size, style, validator, name) |
---|
396 | |
---|
397 | # Bind appropriate events |
---|
398 | self._on_set_focus_callback = parent.onSetFocus \ |
---|
399 | if set_focus_callback is None else set_focus_callback |
---|
400 | self.Bind(wx.EVT_SET_FOCUS, self._on_set_focus) |
---|
401 | self.Bind(wx.EVT_KILL_FOCUS, self._silent_kill_focus \ |
---|
402 | if kill_focus_callback is None else kill_focus_callback) |
---|
403 | self.Bind(wx.EVT_TEXT_ENTER, parent._onparamEnter \ |
---|
404 | if text_enter_callback is None else text_enter_callback) |
---|
405 | if not ON_MAC: |
---|
406 | self.Bind(wx.EVT_LEFT_UP, self._highlight_text \ |
---|
407 | if mouse_up_callback is None else mouse_up_callback) |
---|
408 | |
---|
409 | def _on_set_focus(self, event): |
---|
410 | """ |
---|
411 | Catch when the text control is set in focus to highlight the whole |
---|
412 | text if necessary |
---|
413 | |
---|
414 | :param event: mouse event |
---|
415 | |
---|
416 | """ |
---|
417 | event.Skip() |
---|
418 | self.full_selection = True |
---|
419 | return self._on_set_focus_callback(event) |
---|
420 | |
---|
421 | def _highlight_text(self, event): |
---|
422 | """ |
---|
423 | Highlight text of a TextCtrl only of no text has be selected |
---|
424 | |
---|
425 | :param event: mouse event |
---|
426 | |
---|
427 | """ |
---|
428 | # Make sure the mouse event is available to other listeners |
---|
429 | event.Skip() |
---|
430 | control = event.GetEventObject() |
---|
431 | if self.full_selection: |
---|
432 | self.full_selection = False |
---|
433 | # Check that we have a TextCtrl |
---|
434 | if issubclass(control.__class__, wx.TextCtrl): |
---|
435 | # Check whether text has been selected, |
---|
436 | # if not, select the whole string |
---|
437 | (start, end) = control.GetSelection() |
---|
438 | if start == end: |
---|
439 | control.SetSelection(-1, -1) |
---|
440 | |
---|
441 | def _silent_kill_focus(self, event): |
---|
442 | """ |
---|
443 | Save the state of the page |
---|
444 | """ |
---|
445 | |
---|
446 | event.Skip() |
---|
447 | #pass |
---|
448 | |
---|
449 | def set_page_info(self, page_info): |
---|
450 | """ |
---|
451 | set some page important information at once |
---|
452 | """ |
---|
453 | ##window_name |
---|
454 | self.window_name = page_info.window_name |
---|
455 | ##window_caption |
---|
456 | self.window_caption = page_info.window_caption |
---|
457 | ## manager is the fitting plugin |
---|
458 | self._manager = page_info.manager |
---|
459 | ## owner of the page (fitting plugin) |
---|
460 | self.event_owner = page_info.event_owner |
---|
461 | ## current model |
---|
462 | self.model = page_info.model |
---|
463 | ## data |
---|
464 | self.data = page_info.data |
---|
465 | ## dictionary containing list of models |
---|
466 | self.model_list_box = page_info.model_list_box |
---|
467 | ## Data member to store the dispersion object created |
---|
468 | self.populate_box(dict=self.model_list_box) |
---|
469 | |
---|
470 | def onContextMenu(self, event): |
---|
471 | """ |
---|
472 | Retrieve the state selected state |
---|
473 | """ |
---|
474 | # Skipping the save state functionality for release 0.9.0 |
---|
475 | #return |
---|
476 | |
---|
477 | pos = event.GetPosition() |
---|
478 | pos = self.ScreenToClient(pos) |
---|
479 | |
---|
480 | self.PopupMenu(self.popUpMenu, pos) |
---|
481 | |
---|
482 | def onUndo(self, event): |
---|
483 | """ |
---|
484 | Cancel the previous action |
---|
485 | """ |
---|
486 | event = PreviousStateEvent(page=self) |
---|
487 | wx.PostEvent(self.parent, event) |
---|
488 | |
---|
489 | def onRedo(self, event): |
---|
490 | """ |
---|
491 | Restore the previous action cancelled |
---|
492 | """ |
---|
493 | event = NextStateEvent(page=self) |
---|
494 | wx.PostEvent(self.parent, event) |
---|
495 | |
---|
496 | def define_page_structure(self): |
---|
497 | """ |
---|
498 | Create empty sizer for a panel |
---|
499 | """ |
---|
500 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
501 | self.sizer0 = wx.BoxSizer(wx.VERTICAL) |
---|
502 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
503 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
504 | self.sizer3 = wx.BoxSizer(wx.VERTICAL) |
---|
505 | self.sizer4 = wx.BoxSizer(wx.VERTICAL) |
---|
506 | self.sizer5 = wx.BoxSizer(wx.VERTICAL) |
---|
507 | self.sizer6 = wx.BoxSizer(wx.VERTICAL) |
---|
508 | |
---|
509 | self.sizer0.SetMinSize((PANEL_WIDTH, -1)) |
---|
510 | self.sizer1.SetMinSize((PANEL_WIDTH, -1)) |
---|
511 | self.sizer2.SetMinSize((PANEL_WIDTH, -1)) |
---|
512 | self.sizer3.SetMinSize((PANEL_WIDTH, -1)) |
---|
513 | self.sizer4.SetMinSize((PANEL_WIDTH, -1)) |
---|
514 | self.sizer5.SetMinSize((PANEL_WIDTH, -1)) |
---|
515 | self.sizer6.SetMinSize((PANEL_WIDTH, -1)) |
---|
516 | |
---|
517 | self.vbox.Add(self.sizer0) |
---|
518 | self.vbox.Add(self.sizer1) |
---|
519 | self.vbox.Add(self.sizer2) |
---|
520 | self.vbox.Add(self.sizer3) |
---|
521 | self.vbox.Add(self.sizer4) |
---|
522 | self.vbox.Add(self.sizer5) |
---|
523 | self.vbox.Add(self.sizer6) |
---|
524 | |
---|
525 | def set_layout(self): |
---|
526 | """ |
---|
527 | layout |
---|
528 | """ |
---|
529 | self.vbox.Layout() |
---|
530 | self.vbox.Fit(self) |
---|
531 | self.SetSizer(self.vbox) |
---|
532 | self.Centre() |
---|
533 | |
---|
534 | def set_owner(self, owner): |
---|
535 | """ |
---|
536 | set owner of fitpage |
---|
537 | |
---|
538 | :param owner: the class responsible of plotting |
---|
539 | |
---|
540 | """ |
---|
541 | self.event_owner = owner |
---|
542 | self.state.event_owner = owner |
---|
543 | |
---|
544 | def get_state(self): |
---|
545 | """ |
---|
546 | """ |
---|
547 | return self.state |
---|
548 | |
---|
549 | def get_data(self): |
---|
550 | """ |
---|
551 | return the current data |
---|
552 | """ |
---|
553 | return self.data |
---|
554 | |
---|
555 | def get_data_list(self): |
---|
556 | """ |
---|
557 | return the current data |
---|
558 | """ |
---|
559 | return self.data_list |
---|
560 | |
---|
561 | def set_manager(self, manager): |
---|
562 | """ |
---|
563 | set panel manager |
---|
564 | |
---|
565 | :param manager: instance of plugin fitting |
---|
566 | |
---|
567 | """ |
---|
568 | self._manager = manager |
---|
569 | self.state.manager = manager |
---|
570 | |
---|
571 | def populate_box(self, dict): |
---|
572 | """ |
---|
573 | Store list of model |
---|
574 | |
---|
575 | :param dict: dictionary containing list of models |
---|
576 | |
---|
577 | """ |
---|
578 | self.model_list_box = dict |
---|
579 | self.state.model_list_box = self.model_list_box |
---|
580 | self.initialize_combox() |
---|
581 | |
---|
582 | def set_model_dictionary(self, model_dict): |
---|
583 | """ |
---|
584 | Store a dictionary linking model name -> model object |
---|
585 | |
---|
586 | :param model_dict: dictionary containing list of models |
---|
587 | """ |
---|
588 | self.model_dict = model_dict |
---|
589 | |
---|
590 | def initialize_combox(self): |
---|
591 | """ |
---|
592 | put default value in the combobox |
---|
593 | """ |
---|
594 | ## fill combox box |
---|
595 | if self.model_list_box is None: |
---|
596 | return |
---|
597 | if len(self.model_list_box) > 0: |
---|
598 | self._populate_box(self.formfactorbox, |
---|
599 | self.model_list_box["Shapes"]) |
---|
600 | |
---|
601 | if len(self.model_list_box) > 0: |
---|
602 | self._populate_box(self.structurebox, |
---|
603 | self.model_list_box["Structure Factors"]) |
---|
604 | self.structurebox.Insert("None", 0, None) |
---|
605 | self.structurebox.SetSelection(0) |
---|
606 | self.structurebox.Hide() |
---|
607 | self.text2.Hide() |
---|
608 | self.structurebox.Disable() |
---|
609 | self.text2.Disable() |
---|
610 | |
---|
611 | if self.model.__class__ in self.model_list_box["P(Q)*S(Q)"]: |
---|
612 | self.structurebox.Show() |
---|
613 | self.text2.Show() |
---|
614 | self.structurebox.Enable() |
---|
615 | self.text2.Enable() |
---|
616 | |
---|
617 | def set_dispers_sizer(self): |
---|
618 | """ |
---|
619 | fill sizer containing dispersity info |
---|
620 | """ |
---|
621 | self.sizer4.Clear(True) |
---|
622 | name = "Polydispersity and Orientational Distribution" |
---|
623 | box_description = wx.StaticBox(self, -1, name) |
---|
624 | box_description.SetForegroundColour(wx.BLUE) |
---|
625 | boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
626 | #---------------------------------------------------- |
---|
627 | self.disable_disp = wx.RadioButton(self, -1, 'Off', (10, 10), |
---|
628 | style=wx.RB_GROUP) |
---|
629 | self.enable_disp = wx.RadioButton(self, -1, 'On', (10, 30)) |
---|
630 | # best size for MAC and PC |
---|
631 | if ON_MAC: |
---|
632 | size_q = (30, 20) |
---|
633 | else: |
---|
634 | size_q = (20, 15) |
---|
635 | self.disp_help_bt = wx.Button(self, wx.NewId(), '?', |
---|
636 | style=wx.BU_EXACTFIT, |
---|
637 | size=size_q) |
---|
638 | self.disp_help_bt.Bind(wx.EVT_BUTTON, |
---|
639 | self.on_pd_help_clicked, id=self.disp_help_bt.GetId()) |
---|
640 | self.disp_help_bt.SetToolTipString("Helps for Polydispersion.") |
---|
641 | |
---|
642 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, |
---|
643 | id=self.disable_disp.GetId()) |
---|
644 | self.Bind(wx.EVT_RADIOBUTTON, self._set_dipers_Param, |
---|
645 | id=self.enable_disp.GetId()) |
---|
646 | #MAC needs SetValue |
---|
647 | self.disable_disp.SetValue(True) |
---|
648 | sizer_dispersion = wx.BoxSizer(wx.HORIZONTAL) |
---|
649 | sizer_dispersion.Add((20, 20)) |
---|
650 | name = "" # Polydispersity and \nOrientational Distribution " |
---|
651 | sizer_dispersion.Add(wx.StaticText(self, -1, name)) |
---|
652 | sizer_dispersion.Add(self.enable_disp) |
---|
653 | sizer_dispersion.Add((20, 20)) |
---|
654 | sizer_dispersion.Add(self.disable_disp) |
---|
655 | sizer_dispersion.Add((25, 20)) |
---|
656 | sizer_dispersion.Add(self.disp_help_bt) |
---|
657 | |
---|
658 | ## fill a sizer for dispersion |
---|
659 | boxsizer1.Add(sizer_dispersion, 0, |
---|
660 | wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, |
---|
661 | border=5) |
---|
662 | self.sizer4_4 = wx.GridBagSizer(6, 5) |
---|
663 | |
---|
664 | boxsizer1.Add(self.sizer4_4) |
---|
665 | #----------------------------------------------------- |
---|
666 | self.sizer4.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) |
---|
667 | self.sizer4_4.Layout() |
---|
668 | self.sizer4.Layout() |
---|
669 | self.Layout() |
---|
670 | |
---|
671 | self.Refresh() |
---|
672 | ## saving the state of enable dispersity button |
---|
673 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
674 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
675 | self.SetupScrolling() |
---|
676 | |
---|
677 | def onResetModel(self, event): |
---|
678 | """ |
---|
679 | Reset model state |
---|
680 | """ |
---|
681 | menu = event.GetEventObject() |
---|
682 | ## post help message for the selected model |
---|
683 | msg = menu.GetHelpString(event.GetId()) |
---|
684 | msg += " reloaded" |
---|
685 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
686 | self.Show(False) |
---|
687 | name = menu.GetLabel(event.GetId()) |
---|
688 | self._on_select_model_helper() |
---|
689 | if self.model != None: |
---|
690 | self.m_name = self.model.name |
---|
691 | if name in self.saved_states.keys(): |
---|
692 | previous_state = self.saved_states[name] |
---|
693 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
694 | |
---|
695 | self.reset_page(previous_state) |
---|
696 | self.state.m_name = self.m_name |
---|
697 | self.Show(True) |
---|
698 | |
---|
699 | def on_preview(self, event): |
---|
700 | """ |
---|
701 | Report the current fit results |
---|
702 | """ |
---|
703 | # Get plot image from plotpanel |
---|
704 | images, canvases = self.get_images() |
---|
705 | # get the report dialog |
---|
706 | self.state.report(images, canvases) |
---|
707 | |
---|
708 | def on_save(self, event): |
---|
709 | """ |
---|
710 | Save the current state into file |
---|
711 | """ |
---|
712 | self.save_current_state() |
---|
713 | new_state = self.state.clone() |
---|
714 | # Ask the user the location of the file to write to. |
---|
715 | path = None |
---|
716 | if self.parent != None: |
---|
717 | self._default_save_location = \ |
---|
718 | self.parent.parent._default_save_location |
---|
719 | dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, |
---|
720 | self.window_caption, "*.fitv", wx.SAVE) |
---|
721 | |
---|
722 | if dlg.ShowModal() == wx.ID_OK: |
---|
723 | path = dlg.GetPath() |
---|
724 | self._default_save_location = os.path.dirname(path) |
---|
725 | self.parent.parent._default_save_location =\ |
---|
726 | self._default_save_location |
---|
727 | else: |
---|
728 | return None |
---|
729 | # MAC always needs the extension for saving |
---|
730 | extens = ".fitv" |
---|
731 | # Make sure the ext included in the file name |
---|
732 | fName = os.path.splitext(path)[0] + extens |
---|
733 | #the manager write the state into file |
---|
734 | self._manager.save_fit_state(filepath=fName, fitstate=new_state) |
---|
735 | return new_state |
---|
736 | |
---|
737 | def on_copy(self, event): |
---|
738 | """ |
---|
739 | Copy Parameter values to the clipboad |
---|
740 | """ |
---|
741 | if event != None: |
---|
742 | event.Skip() |
---|
743 | # It seems MAC needs wxCallAfter |
---|
744 | wx.CallAfter(self.get_copy) |
---|
745 | |
---|
746 | def on_paste(self, event): |
---|
747 | """ |
---|
748 | Paste Parameter values to the panel if possible |
---|
749 | """ |
---|
750 | #if event != None: |
---|
751 | # event.Skip() |
---|
752 | # It seems MAC needs wxCallAfter for the setvalues |
---|
753 | # for multiple textctrl items, otherwise it tends to crash once a while |
---|
754 | wx.CallAfter(self.get_paste) |
---|
755 | # messages depending on the flag |
---|
756 | #self._copy_info(True) |
---|
757 | |
---|
758 | def _copy_info(self, flag): |
---|
759 | """ |
---|
760 | Send event dpemding on flag |
---|
761 | |
---|
762 | : Param flag: flag that distinguish event |
---|
763 | """ |
---|
764 | # messages depending on the flag |
---|
765 | if flag == None: |
---|
766 | msg = " Parameter values are copied to the clipboard..." |
---|
767 | infor = 'warning' |
---|
768 | elif flag: |
---|
769 | msg = " Parameter values are pasted from the clipboad..." |
---|
770 | infor = "warning" |
---|
771 | else: |
---|
772 | msg = "Error was occured " |
---|
773 | msg += ": No valid parameter values to paste from the clipboard..." |
---|
774 | infor = "error" |
---|
775 | wx.PostEvent(self.parent.parent, |
---|
776 | StatusEvent(status=msg, info=infor)) |
---|
777 | raise |
---|
778 | # inform msg to wx |
---|
779 | wx.PostEvent(self.parent.parent, |
---|
780 | StatusEvent(status=msg, info=infor)) |
---|
781 | |
---|
782 | def _get_time_stamp(self): |
---|
783 | """ |
---|
784 | return time and date stings |
---|
785 | """ |
---|
786 | # date and time |
---|
787 | year, month, day, hour, minute, second, _, _, _ = time.localtime() |
---|
788 | current_time = str(hour) + ":" + str(minute) + ":" + str(second) |
---|
789 | current_date = str(month) + "/" + str(day) + "/" + str(year) |
---|
790 | return current_time, current_date |
---|
791 | |
---|
792 | def on_bookmark(self, event): |
---|
793 | """ |
---|
794 | save history of the data and model |
---|
795 | """ |
---|
796 | if self.model == None: |
---|
797 | msg = "Can not bookmark; Please select Data and Model first..." |
---|
798 | wx.MessageBox(msg, 'Info') |
---|
799 | return |
---|
800 | self.save_current_state() |
---|
801 | new_state = self.state.clone() |
---|
802 | ##Add model state on context menu |
---|
803 | self.number_saved_state += 1 |
---|
804 | current_time, current_date = self._get_time_stamp() |
---|
805 | #name= self.model.name+"[%g]"%self.number_saved_state |
---|
806 | name = "Fitting: %g]" % self.number_saved_state |
---|
807 | name += self.model.__class__.__name__ |
---|
808 | name += "bookmarked at %s on %s" % (current_time, current_date) |
---|
809 | self.saved_states[name] = new_state |
---|
810 | |
---|
811 | ## Add item in the context menu |
---|
812 | msg = "Model saved at %s on %s" % (current_time, current_date) |
---|
813 | ## post help message for the selected model |
---|
814 | msg += " Saved! right click on this page to retrieve this model" |
---|
815 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
816 | |
---|
817 | id = wx.NewId() |
---|
818 | self.popUpMenu.Append(id, name, str(msg)) |
---|
819 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
820 | wx.PostEvent(self.parent.parent, |
---|
821 | AppendBookmarkEvent(title=name, |
---|
822 | hint=str(msg), |
---|
823 | handler=self._back_to_bookmark)) |
---|
824 | |
---|
825 | def _back_to_bookmark(self, event): |
---|
826 | """ |
---|
827 | Back to bookmark |
---|
828 | """ |
---|
829 | self._manager.on_perspective(event) |
---|
830 | self.onResetModel(event) |
---|
831 | self._draw_model() |
---|
832 | |
---|
833 | def onSetFocus(self, evt): |
---|
834 | """ |
---|
835 | highlight the current textcrtl and hide the error text control shown |
---|
836 | after fitting |
---|
837 | """ |
---|
838 | return |
---|
839 | |
---|
840 | def read_file(self, path): |
---|
841 | """ |
---|
842 | Read two columns file |
---|
843 | |
---|
844 | :param path: the path to the file to read |
---|
845 | |
---|
846 | """ |
---|
847 | try: |
---|
848 | if path == None: |
---|
849 | wx.PostEvent(self.parent.parent, |
---|
850 | StatusEvent(status= \ |
---|
851 | " Selected Distribution was not loaded: %s" % path)) |
---|
852 | return None, None |
---|
853 | input_f = open(path, 'r') |
---|
854 | buff = input_f.read() |
---|
855 | lines = buff.split('\n') |
---|
856 | input_f.close() |
---|
857 | angles = [] |
---|
858 | weights = [] |
---|
859 | for line in lines: |
---|
860 | toks = line.split() |
---|
861 | try: |
---|
862 | angle = float(toks[0]) |
---|
863 | weight = float(toks[1]) |
---|
864 | angles.append(angle) |
---|
865 | weights.append(weight) |
---|
866 | except: |
---|
867 | # Skip non-data lines |
---|
868 | pass |
---|
869 | return numpy.array(angles), numpy.array(weights) |
---|
870 | except: |
---|
871 | raise |
---|
872 | |
---|
873 | def createMemento(self): |
---|
874 | """ |
---|
875 | return the current state of the page |
---|
876 | """ |
---|
877 | return self.state.clone() |
---|
878 | |
---|
879 | def save_current_state(self): |
---|
880 | """ |
---|
881 | Store current state |
---|
882 | """ |
---|
883 | self.state.engine_type = copy.deepcopy(self.engine_type) |
---|
884 | ## save model option |
---|
885 | if self.model != None: |
---|
886 | self.disp_list = self.model.getDispParamList() |
---|
887 | self.state.disp_list = copy.deepcopy(self.disp_list) |
---|
888 | self.state.model = self.model.clone() |
---|
889 | |
---|
890 | #model combobox: complex code because of mac's silent error |
---|
891 | if self.structurebox != None: |
---|
892 | if self.structurebox.IsShown(): |
---|
893 | self.state.structurecombobox = 'None' |
---|
894 | s_select = self.structurebox.GetSelection() |
---|
895 | if s_select > 0: |
---|
896 | self.state.structurecombobox = self.structurebox.\ |
---|
897 | GetString(s_select) |
---|
898 | if self.formfactorbox != None: |
---|
899 | f_select = self.formfactorbox.GetSelection() |
---|
900 | if f_select > 0: |
---|
901 | self.state.formfactorcombobox = self.formfactorbox.\ |
---|
902 | GetString(f_select) |
---|
903 | if self.categorybox != None: |
---|
904 | cb_select = self.categorybox.GetSelection() |
---|
905 | if cb_select > 0: |
---|
906 | self.state.categorycombobox = self.categorybox.\ |
---|
907 | GetString(cb_select) |
---|
908 | #save radiobutton state for model selection |
---|
909 | #self.state.shape_rbutton = self.shape_rbutton.GetValue() |
---|
910 | #self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() |
---|
911 | #self.state.struct_rbutton = self.struct_rbutton.GetValue() |
---|
912 | #self.state.plugin_rbutton = self.plugin_rbutton.GetValue() |
---|
913 | |
---|
914 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
915 | self.state.values = copy.deepcopy(self.values) |
---|
916 | self.state.weights = copy.deepcopy(self.weights) |
---|
917 | ## save data |
---|
918 | self.state.data = copy.deepcopy(self.data) |
---|
919 | self.state.qmax_x = self.qmax_x |
---|
920 | self.state.qmin_x = self.qmin_x |
---|
921 | self.state.dI_noweight = copy.deepcopy(self.dI_noweight.GetValue()) |
---|
922 | self.state.dI_didata = copy.deepcopy(self.dI_didata.GetValue()) |
---|
923 | self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) |
---|
924 | self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) |
---|
925 | self.state.dq_l = self.dq_l |
---|
926 | self.state.dq_r = self.dq_r |
---|
927 | if hasattr(self, "enable_disp"): |
---|
928 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
929 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
930 | |
---|
931 | self.state.smearer = copy.deepcopy(self.current_smearer) |
---|
932 | if hasattr(self, "enable_smearer"): |
---|
933 | self.state.enable_smearer = \ |
---|
934 | copy.deepcopy(self.enable_smearer.GetValue()) |
---|
935 | self.state.disable_smearer = \ |
---|
936 | copy.deepcopy(self.disable_smearer.GetValue()) |
---|
937 | |
---|
938 | self.state.pinhole_smearer = \ |
---|
939 | copy.deepcopy(self.pinhole_smearer.GetValue()) |
---|
940 | self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) |
---|
941 | |
---|
942 | if len(self._disp_obj_dict) > 0: |
---|
943 | for k, v in self._disp_obj_dict.iteritems(): |
---|
944 | self.state._disp_obj_dict[k] = v |
---|
945 | |
---|
946 | self.state.values = copy.deepcopy(self.values) |
---|
947 | self.state.weights = copy.deepcopy(self.weights) |
---|
948 | ## save plotting range |
---|
949 | self._save_plotting_range() |
---|
950 | |
---|
951 | self.state.orientation_params = [] |
---|
952 | self.state.orientation_params_disp = [] |
---|
953 | self.state.parameters = [] |
---|
954 | self.state.fittable_param = [] |
---|
955 | self.state.fixed_param = [] |
---|
956 | self.state.str_parameters = [] |
---|
957 | |
---|
958 | ## save checkbutton state and txtcrtl values |
---|
959 | self._copy_parameters_state(self.str_parameters, |
---|
960 | self.state.str_parameters) |
---|
961 | self._copy_parameters_state(self.orientation_params, |
---|
962 | self.state.orientation_params) |
---|
963 | self._copy_parameters_state(self.orientation_params_disp, |
---|
964 | self.state.orientation_params_disp) |
---|
965 | |
---|
966 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
967 | self._copy_parameters_state(self.fittable_param, |
---|
968 | self.state.fittable_param) |
---|
969 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
970 | #save chisqr |
---|
971 | self.state.tcChi = self.tcChi.GetValue() |
---|
972 | |
---|
973 | def save_current_state_fit(self): |
---|
974 | """ |
---|
975 | Store current state for fit_page |
---|
976 | """ |
---|
977 | ## save model option |
---|
978 | if self.model != None: |
---|
979 | self.disp_list = self.model.getDispParamList() |
---|
980 | self.state.disp_list = copy.deepcopy(self.disp_list) |
---|
981 | self.state.model = self.model.clone() |
---|
982 | if hasattr(self, "engine_type"): |
---|
983 | self.state.engine_type = copy.deepcopy(self.engine_type) |
---|
984 | |
---|
985 | self.state.enable2D = copy.deepcopy(self.enable2D) |
---|
986 | self.state.values = copy.deepcopy(self.values) |
---|
987 | self.state.weights = copy.deepcopy(self.weights) |
---|
988 | ## save data |
---|
989 | self.state.data = copy.deepcopy(self.data) |
---|
990 | |
---|
991 | if hasattr(self, "enable_disp"): |
---|
992 | self.state.enable_disp = self.enable_disp.GetValue() |
---|
993 | self.state.disable_disp = self.disable_disp.GetValue() |
---|
994 | |
---|
995 | self.state.smearer = copy.deepcopy(self.current_smearer) |
---|
996 | if hasattr(self, "enable_smearer"): |
---|
997 | self.state.enable_smearer = \ |
---|
998 | copy.deepcopy(self.enable_smearer.GetValue()) |
---|
999 | self.state.disable_smearer = \ |
---|
1000 | copy.deepcopy(self.disable_smearer.GetValue()) |
---|
1001 | |
---|
1002 | self.state.pinhole_smearer = \ |
---|
1003 | copy.deepcopy(self.pinhole_smearer.GetValue()) |
---|
1004 | self.state.slit_smearer = copy.deepcopy(self.slit_smearer.GetValue()) |
---|
1005 | self.state.dI_noweight = copy.deepcopy(self.dI_noweight.GetValue()) |
---|
1006 | self.state.dI_didata = copy.deepcopy(self.dI_didata.GetValue()) |
---|
1007 | self.state.dI_sqrdata = copy.deepcopy(self.dI_sqrdata.GetValue()) |
---|
1008 | self.state.dI_idata = copy.deepcopy(self.dI_idata.GetValue()) |
---|
1009 | if hasattr(self, "disp_box") and self.disp_box != None: |
---|
1010 | self.state.disp_box = self.disp_box.GetCurrentSelection() |
---|
1011 | |
---|
1012 | if len(self.disp_cb_dict) > 0: |
---|
1013 | for k, v in self.disp_cb_dict.iteritems(): |
---|
1014 | |
---|
1015 | if v == None: |
---|
1016 | self.state.disp_cb_dict[k] = v |
---|
1017 | else: |
---|
1018 | try: |
---|
1019 | self.state.disp_cb_dict[k] = v.GetValue() |
---|
1020 | except: |
---|
1021 | self.state.disp_cb_dict[k] = None |
---|
1022 | |
---|
1023 | if len(self._disp_obj_dict) > 0: |
---|
1024 | for k, v in self._disp_obj_dict.iteritems(): |
---|
1025 | self.state._disp_obj_dict[k] = v |
---|
1026 | |
---|
1027 | self.state.values = copy.deepcopy(self.values) |
---|
1028 | self.state.weights = copy.deepcopy(self.weights) |
---|
1029 | |
---|
1030 | ## save plotting range |
---|
1031 | self._save_plotting_range() |
---|
1032 | |
---|
1033 | ## save checkbutton state and txtcrtl values |
---|
1034 | self._copy_parameters_state(self.orientation_params, |
---|
1035 | self.state.orientation_params) |
---|
1036 | self._copy_parameters_state(self.orientation_params_disp, |
---|
1037 | self.state.orientation_params_disp) |
---|
1038 | self._copy_parameters_state(self.parameters, self.state.parameters) |
---|
1039 | self._copy_parameters_state(self.fittable_param, |
---|
1040 | self.state.fittable_param) |
---|
1041 | self._copy_parameters_state(self.fixed_param, self.state.fixed_param) |
---|
1042 | |
---|
1043 | def check_invalid_panel(self): |
---|
1044 | """ |
---|
1045 | check if the user can already perform some action with this panel |
---|
1046 | """ |
---|
1047 | if self.data is None: |
---|
1048 | self.disable_smearer.SetValue(True) |
---|
1049 | self.disable_disp.SetValue(True) |
---|
1050 | msg = "Please load Data and select Model to start..." |
---|
1051 | wx.MessageBox(msg, 'Info') |
---|
1052 | return True |
---|
1053 | |
---|
1054 | def set_model_state(self, state): |
---|
1055 | """ |
---|
1056 | reset page given a model state |
---|
1057 | """ |
---|
1058 | self.disp_cb_dict = state.disp_cb_dict |
---|
1059 | self.disp_list = state.disp_list |
---|
1060 | |
---|
1061 | ## set the state of the radio box |
---|
1062 | #self.shape_rbutton.SetValue(state.shape_rbutton) |
---|
1063 | #self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) |
---|
1064 | #self.struct_rbutton.SetValue(state.struct_rbutton) |
---|
1065 | #self.plugin_rbutton.SetValue(state.plugin_rbutton) |
---|
1066 | |
---|
1067 | ## fill model combobox |
---|
1068 | self._show_combox_helper() |
---|
1069 | #select the current model |
---|
1070 | try: |
---|
1071 | # to support older version |
---|
1072 | category_pos = int(state.categorycombobox) |
---|
1073 | except: |
---|
1074 | category_pos = 0 |
---|
1075 | for ind_cat in range(self.categorybox.GetCount()): |
---|
1076 | if self.categorycombobox.GetString(ind_form) == \ |
---|
1077 | state.categorycombobox: |
---|
1078 | category_pos = int(ind_cat) |
---|
1079 | break |
---|
1080 | |
---|
1081 | self.categorybox.Select(category_pos) |
---|
1082 | try: |
---|
1083 | # to support older version |
---|
1084 | formfactor_pos = int(state.formfactorcombobox) |
---|
1085 | except: |
---|
1086 | formfactor_pos = 0 |
---|
1087 | for ind_form in range(self.formfactorbox.GetCount()): |
---|
1088 | if self.formfactorbox.GetString(ind_form) == \ |
---|
1089 | state.formfactorcombobox: |
---|
1090 | formfactor_pos = int(ind_form) |
---|
1091 | break |
---|
1092 | |
---|
1093 | self.formfactorbox.Select(formfactor_pos) |
---|
1094 | |
---|
1095 | try: |
---|
1096 | # to support older version |
---|
1097 | structfactor_pos = int(state.structurecombobox) |
---|
1098 | except: |
---|
1099 | structfactor_pos = 0 |
---|
1100 | for ind_struct in range(self.structurebox.GetCount()): |
---|
1101 | if self.structurebox.GetString(ind_struct) == \ |
---|
1102 | state.structurecombobox: |
---|
1103 | structfactor_pos = int(ind_struct) |
---|
1104 | break |
---|
1105 | |
---|
1106 | self.structurebox.SetSelection(structfactor_pos) |
---|
1107 | |
---|
1108 | if state.multi_factor != None: |
---|
1109 | self.multifactorbox.SetSelection(state.multi_factor) |
---|
1110 | |
---|
1111 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
1112 | self._reset_parameters_state(self.orientation_params_disp, |
---|
1113 | state.orientation_params_disp) |
---|
1114 | self._reset_parameters_state(self.orientation_params, |
---|
1115 | state.orientation_params) |
---|
1116 | self._reset_parameters_state(self.str_parameters, |
---|
1117 | state.str_parameters) |
---|
1118 | self._reset_parameters_state(self.parameters, state.parameters) |
---|
1119 | ## display dispersion info layer |
---|
1120 | self.enable_disp.SetValue(state.enable_disp) |
---|
1121 | self.disable_disp.SetValue(state.disable_disp) |
---|
1122 | |
---|
1123 | if hasattr(self, "disp_box") and self.disp_box != None: |
---|
1124 | self.disp_box.SetSelection(state.disp_box) |
---|
1125 | n = self.disp_box.GetCurrentSelection() |
---|
1126 | dispersity = self.disp_box.GetClientData(n) |
---|
1127 | name = dispersity.__name__ |
---|
1128 | |
---|
1129 | self._set_dipers_Param(event=None) |
---|
1130 | |
---|
1131 | if name == "ArrayDispersion": |
---|
1132 | |
---|
1133 | for item in self.disp_cb_dict.keys(): |
---|
1134 | |
---|
1135 | if hasattr(self.disp_cb_dict[item], "SetValue"): |
---|
1136 | self.disp_cb_dict[item].SetValue(\ |
---|
1137 | state.disp_cb_dict[item]) |
---|
1138 | # Create the dispersion objects |
---|
1139 | from sans.models.dispersion_models import ArrayDispersion |
---|
1140 | disp_model = ArrayDispersion() |
---|
1141 | if hasattr(state, "values") and \ |
---|
1142 | self.disp_cb_dict[item].GetValue() == True: |
---|
1143 | if len(state.values) > 0: |
---|
1144 | self.values = state.values |
---|
1145 | self.weights = state.weights |
---|
1146 | disp_model.set_weights(self.values, |
---|
1147 | state.weights) |
---|
1148 | else: |
---|
1149 | self._reset_dispersity() |
---|
1150 | |
---|
1151 | self._disp_obj_dict[item] = disp_model |
---|
1152 | # Set the new model as the dispersion object |
---|
1153 | #for the selected parameter |
---|
1154 | self.model.set_dispersion(item, disp_model) |
---|
1155 | |
---|
1156 | self.model._persistency_dict[item] = \ |
---|
1157 | [state.values, state.weights] |
---|
1158 | |
---|
1159 | else: |
---|
1160 | keys = self.model.getParamList() |
---|
1161 | for item in keys: |
---|
1162 | if item in self.disp_list and \ |
---|
1163 | not item in self.model.details: |
---|
1164 | self.model.details[item] = ["", None, None] |
---|
1165 | self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
1166 | self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
1167 | ## smearing info restore |
---|
1168 | if hasattr(self, "enable_smearer"): |
---|
1169 | ## set smearing value whether or not the data |
---|
1170 | #contain the smearing info |
---|
1171 | self.enable_smearer.SetValue(state.enable_smearer) |
---|
1172 | self.disable_smearer.SetValue(state.disable_smearer) |
---|
1173 | self.onSmear(event=None) |
---|
1174 | self.pinhole_smearer.SetValue(state.pinhole_smearer) |
---|
1175 | self.slit_smearer.SetValue(state.slit_smearer) |
---|
1176 | |
---|
1177 | self.dI_noweight.SetValue(state.dI_noweight) |
---|
1178 | self.dI_didata.SetValue(state.dI_didata) |
---|
1179 | self.dI_sqrdata.SetValue(state.dI_sqrdata) |
---|
1180 | self.dI_idata.SetValue(state.dI_idata) |
---|
1181 | |
---|
1182 | ## we have two more options for smearing |
---|
1183 | if self.pinhole_smearer.GetValue(): |
---|
1184 | self.onPinholeSmear(event=None) |
---|
1185 | elif self.slit_smearer.GetValue(): |
---|
1186 | self.onSlitSmear(event=None) |
---|
1187 | |
---|
1188 | ## reset state of checkbox,textcrtl and dispersity parameters value |
---|
1189 | self._reset_parameters_state(self.fittable_param, state.fittable_param) |
---|
1190 | self._reset_parameters_state(self.fixed_param, state.fixed_param) |
---|
1191 | |
---|
1192 | ## draw the model with previous parameters value |
---|
1193 | self._onparamEnter_helper() |
---|
1194 | self.select_param(event=None) |
---|
1195 | #Save state_fit |
---|
1196 | self.save_current_state_fit() |
---|
1197 | self._lay_out() |
---|
1198 | self.Refresh() |
---|
1199 | |
---|
1200 | def reset_page_helper(self, state): |
---|
1201 | """ |
---|
1202 | Use page_state and change the state of existing page |
---|
1203 | |
---|
1204 | :precondition: the page is already drawn or created |
---|
1205 | |
---|
1206 | :postcondition: the state of the underlying data change as well as the |
---|
1207 | state of the graphic interface |
---|
1208 | """ |
---|
1209 | if state == None: |
---|
1210 | return |
---|
1211 | # set data, etc. from the state |
---|
1212 | # reset page between theory and fitting from bookmarking |
---|
1213 | #if state.data == None: |
---|
1214 | # data = None |
---|
1215 | #else: |
---|
1216 | data = state.data |
---|
1217 | |
---|
1218 | if data == None: |
---|
1219 | data_min = state.qmin |
---|
1220 | data_max = state.qmax |
---|
1221 | self.qmin_x = data_min |
---|
1222 | self.qmax_x = data_max |
---|
1223 | self.qmin.SetValue(str(data_min)) |
---|
1224 | self.qmax.SetValue(str(data_max)) |
---|
1225 | |
---|
1226 | self.state.data = data |
---|
1227 | self.state.qmin = self.qmin_x |
---|
1228 | self.state.qmax = self.qmax_x |
---|
1229 | else: |
---|
1230 | self.set_data(data) |
---|
1231 | |
---|
1232 | self.enable2D = state.enable2D |
---|
1233 | try: |
---|
1234 | self.magnetic_on = state.magnetic_on |
---|
1235 | except: |
---|
1236 | # Backward compatibility (for older state files) |
---|
1237 | self.magnetic_on = False |
---|
1238 | self.engine_type = state.engine_type |
---|
1239 | |
---|
1240 | self.disp_cb_dict = state.disp_cb_dict |
---|
1241 | self.disp_list = state.disp_list |
---|
1242 | |
---|
1243 | ## set the state of the radio box |
---|
1244 | #self.shape_rbutton.SetValue(state.shape_rbutton) |
---|
1245 | #self.shape_indep_rbutton.SetValue(state.shape_indep_rbutton) |
---|
1246 | #self.struct_rbutton.SetValue(state.struct_rbutton) |
---|
1247 | #self.plugin_rbutton.SetValue(state.plugin_rbutton) |
---|
1248 | |
---|
1249 | ## fill model combobox |
---|
1250 | self._show_combox_helper() |
---|
1251 | #select the current model |
---|
1252 | try: |
---|
1253 | # to support older version |
---|
1254 | category_pos = int(state.categorycombobox) |
---|
1255 | except: |
---|
1256 | category_pos = 0 |
---|
1257 | for ind_cat in range(self.categorybox.GetCount()): |
---|
1258 | if self.categorybox.GetString(ind_cat) == \ |
---|
1259 | state.categorycombobox: |
---|
1260 | category_pos = int(ind_cat) |
---|
1261 | break |
---|
1262 | |
---|
1263 | self.categorybox.Select(category_pos) |
---|
1264 | self._show_combox(None) |
---|
1265 | try: |
---|
1266 | # to support older version |
---|
1267 | formfactor_pos = int(state.formfactorcombobox) |
---|
1268 | except: |
---|
1269 | formfactor_pos = 0 |
---|
1270 | for ind_form in range(self.formfactorbox.GetCount()): |
---|
1271 | if self.formfactorbox.GetString(ind_form) == \ |
---|
1272 | (state.formfactorcombobox): |
---|
1273 | formfactor_pos = int(ind_form) |
---|
1274 | break |
---|
1275 | |
---|
1276 | self.formfactorbox.Select(formfactor_pos) |
---|
1277 | |
---|
1278 | try: |
---|
1279 | # to support older version |
---|
1280 | structfactor_pos = int(state.structurecombobox) |
---|
1281 | except: |
---|
1282 | structfactor_pos = 0 |
---|
1283 | for ind_struct in range(self.structurebox.GetCount()): |
---|
1284 | if self.structurebox.GetString(ind_struct) == \ |
---|
1285 | (state.structurecombobox): |
---|
1286 | structfactor_pos = int(ind_struct) |
---|
1287 | break |
---|
1288 | |
---|
1289 | self.structurebox.SetSelection(structfactor_pos) |
---|
1290 | |
---|
1291 | if state.multi_factor != None: |
---|
1292 | self.multifactorbox.SetSelection(state.multi_factor) |
---|
1293 | |
---|
1294 | #reset the fitting engine type |
---|
1295 | self.engine_type = state.engine_type |
---|
1296 | #draw the pnael according to the new model parameter |
---|
1297 | self._on_select_model(event=None) |
---|
1298 | |
---|
1299 | # take care of 2D button |
---|
1300 | if data == None and self.model_view.IsEnabled(): |
---|
1301 | if self.enable2D: |
---|
1302 | self.model_view.SetLabel("2D Mode") |
---|
1303 | else: |
---|
1304 | self.model_view.SetLabel("1D Mode") |
---|
1305 | # else: |
---|
1306 | |
---|
1307 | if self._manager != None and self.engine_type != None: |
---|
1308 | self._manager._on_change_engine(engine=self.engine_type) |
---|
1309 | ## set the select all check box to the a given state |
---|
1310 | self.cb1.SetValue(state.cb1) |
---|
1311 | |
---|
1312 | ## reset state of checkbox,textcrtl and regular parameters value |
---|
1313 | self._reset_parameters_state(self.orientation_params_disp, |
---|
1314 | state.orientation_params_disp) |
---|
1315 | self._reset_parameters_state(self.orientation_params, |
---|
1316 | state.orientation_params) |
---|
1317 | self._reset_parameters_state(self.str_parameters, |
---|
1318 | state.str_parameters) |
---|
1319 | self._reset_parameters_state(self.parameters, state.parameters) |
---|
1320 | ## display dispersion info layer |
---|
1321 | self.enable_disp.SetValue(state.enable_disp) |
---|
1322 | self.disable_disp.SetValue(state.disable_disp) |
---|
1323 | # If the polydispersion is ON |
---|
1324 | if state.enable_disp: |
---|
1325 | # reset dispersion according the state |
---|
1326 | self._set_dipers_Param(event=None) |
---|
1327 | self._reset_page_disp_helper(state) |
---|
1328 | ##plotting range restore |
---|
1329 | self._reset_plotting_range(state) |
---|
1330 | ## smearing info restore |
---|
1331 | if hasattr(self, "enable_smearer"): |
---|
1332 | ## set smearing value whether or not the data |
---|
1333 | #contain the smearing info |
---|
1334 | self.enable_smearer.SetValue(state.enable_smearer) |
---|
1335 | self.disable_smearer.SetValue(state.disable_smearer) |
---|
1336 | self.onSmear(event=None) |
---|
1337 | self.pinhole_smearer.SetValue(state.pinhole_smearer) |
---|
1338 | self.slit_smearer.SetValue(state.slit_smearer) |
---|
1339 | try: |
---|
1340 | self.dI_noweight.SetValue(state.dI_noweight) |
---|
1341 | self.dI_didata.SetValue(state.dI_didata) |
---|
1342 | self.dI_sqrdata.SetValue(state.dI_sqrdata) |
---|
1343 | self.dI_idata.SetValue(state.dI_idata) |
---|
1344 | except: |
---|
1345 | # to support older state file formats |
---|
1346 | self.dI_noweight.SetValue(False) |
---|
1347 | self.dI_didata.SetValue(True) |
---|
1348 | self.dI_sqrdata.SetValue(False) |
---|
1349 | self.dI_idata.SetValue(False) |
---|
1350 | |
---|
1351 | ## we have two more options for smearing |
---|
1352 | if self.pinhole_smearer.GetValue(): |
---|
1353 | self.onPinholeSmear(event=None) |
---|
1354 | elif self.slit_smearer.GetValue(): |
---|
1355 | self.onSlitSmear(event=None) |
---|
1356 | |
---|
1357 | ## reset state of checkbox,textcrtl and dispersity parameters value |
---|
1358 | self._reset_parameters_state(self.fittable_param, state.fittable_param) |
---|
1359 | self._reset_parameters_state(self.fixed_param, state.fixed_param) |
---|
1360 | |
---|
1361 | ## draw the model with previous parameters value |
---|
1362 | self._onparamEnter_helper() |
---|
1363 | #reset the value of chisqr when not consistent with the value computed |
---|
1364 | self.tcChi.SetValue(str(self.state.tcChi)) |
---|
1365 | ## reset context menu items |
---|
1366 | self._reset_context_menu() |
---|
1367 | |
---|
1368 | ## set the value of the current state to the state given as parameter |
---|
1369 | self.state = state.clone() |
---|
1370 | self.state.m_name = self.m_name |
---|
1371 | |
---|
1372 | def _reset_page_disp_helper(self, state): |
---|
1373 | """ |
---|
1374 | Help to rest page for dispersions |
---|
1375 | """ |
---|
1376 | keys = self.model.getParamList() |
---|
1377 | for item in keys: |
---|
1378 | if item in self.disp_list and \ |
---|
1379 | not item in self.model.details: |
---|
1380 | self.model.details[item] = ["", None, None] |
---|
1381 | #for k,v in self.state.disp_cb_dict.iteritems(): |
---|
1382 | self.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
1383 | self.state.disp_cb_dict = copy.deepcopy(state.disp_cb_dict) |
---|
1384 | self.values = copy.deepcopy(state.values) |
---|
1385 | self.weights = copy.deepcopy(state.weights) |
---|
1386 | |
---|
1387 | for key, disp in state._disp_obj_dict.iteritems(): |
---|
1388 | # From saved file, disp_model can not be sent in model obj. |
---|
1389 | # it will be sent as a string here, then converted to model object. |
---|
1390 | if disp.__class__.__name__ == 'str': |
---|
1391 | disp_model = None |
---|
1392 | com_str = "from sans.models.dispersion_models " |
---|
1393 | com_str += "import %s as disp_func \ndisp_model = disp_func()" |
---|
1394 | exec com_str % disp |
---|
1395 | else: |
---|
1396 | disp_model = disp |
---|
1397 | self._disp_obj_dict[key] = disp_model |
---|
1398 | param_name = key.split('.')[0] |
---|
1399 | # Try to set dispersion only when available |
---|
1400 | # for eg., pass the orient. angles for 1D Cal |
---|
1401 | try: |
---|
1402 | self.model.set_dispersion(param_name, disp_model) |
---|
1403 | self.model._persistency_dict[key] = \ |
---|
1404 | [state.values, state.weights] |
---|
1405 | except: |
---|
1406 | pass |
---|
1407 | selection = self._find_polyfunc_selection(disp_model) |
---|
1408 | for list in self.fittable_param: |
---|
1409 | if list[1] == key and list[7] != None: |
---|
1410 | list[7].SetSelection(selection) |
---|
1411 | # For the array disp_model, set the values and weights |
---|
1412 | if selection == 1: |
---|
1413 | disp_model.set_weights(self.values[key], |
---|
1414 | self.weights[key]) |
---|
1415 | try: |
---|
1416 | # Diables all fittable params for array |
---|
1417 | list[0].SetValue(False) |
---|
1418 | list[0].Disable() |
---|
1419 | list[2].Disable() |
---|
1420 | list[5].Disable() |
---|
1421 | list[6].Disable() |
---|
1422 | except: |
---|
1423 | pass |
---|
1424 | # For array, disable all fixed params |
---|
1425 | if selection == 1: |
---|
1426 | for item in self.fixed_param: |
---|
1427 | if item[1].split(".")[0] == key.split(".")[0]: |
---|
1428 | # try it and pass it for the orientation for 1D |
---|
1429 | try: |
---|
1430 | item[2].Disable() |
---|
1431 | except: |
---|
1432 | pass |
---|
1433 | |
---|
1434 | # Make sure the check box updated when all checked |
---|
1435 | if self.cb1.GetValue(): |
---|
1436 | self.select_all_param(None) |
---|
1437 | |
---|
1438 | def _selectDlg(self): |
---|
1439 | """ |
---|
1440 | open a dialog file to selected the customized dispersity |
---|
1441 | """ |
---|
1442 | if self.parent != None: |
---|
1443 | self._default_save_location = \ |
---|
1444 | self.parent.parent.get_save_location() |
---|
1445 | dlg = wx.FileDialog(self, "Choose a weight file", |
---|
1446 | self._default_save_location, "", |
---|
1447 | "*.*", wx.OPEN) |
---|
1448 | path = None |
---|
1449 | if dlg.ShowModal() == wx.ID_OK: |
---|
1450 | path = dlg.GetPath() |
---|
1451 | dlg.Destroy() |
---|
1452 | return path |
---|
1453 | |
---|
1454 | def _reset_context_menu(self): |
---|
1455 | """ |
---|
1456 | reset the context menu |
---|
1457 | """ |
---|
1458 | for name, _ in self.state.saved_states.iteritems(): |
---|
1459 | self.number_saved_state += 1 |
---|
1460 | ## Add item in the context menu |
---|
1461 | id = wx.NewId() |
---|
1462 | msg = 'Save model and state %g' % self.number_saved_state |
---|
1463 | self.popUpMenu.Append(id, name, msg) |
---|
1464 | wx.EVT_MENU(self, id, self.onResetModel) |
---|
1465 | |
---|
1466 | def _reset_plotting_range(self, state): |
---|
1467 | """ |
---|
1468 | Reset the plotting range to a given state |
---|
1469 | """ |
---|
1470 | self.qmin.SetValue(str(state.qmin)) |
---|
1471 | self.qmax.SetValue(str(state.qmax)) |
---|
1472 | |
---|
1473 | def _save_typeOfmodel(self): |
---|
1474 | """ |
---|
1475 | save radiobutton containing the type model that can be selected |
---|
1476 | """ |
---|
1477 | #self.state.shape_rbutton = self.shape_rbutton.GetValue() |
---|
1478 | #self.state.shape_indep_rbutton = self.shape_indep_rbutton.GetValue() |
---|
1479 | #self.state.struct_rbutton = self.struct_rbutton.GetValue() |
---|
1480 | #self.state.plugin_rbutton = self.plugin_rbutton.GetValue() |
---|
1481 | self.state.structurecombobox = self.structurebox.GetLabel() |
---|
1482 | self.state.formfactorcombobox = self.formfactorbox.GetLabel() |
---|
1483 | self.state.categorycombobox = self.categorybox.GetLabel() |
---|
1484 | |
---|
1485 | ## post state to fit panel |
---|
1486 | event = PageInfoEvent(page=self) |
---|
1487 | wx.PostEvent(self.parent, event) |
---|
1488 | |
---|
1489 | def _save_plotting_range(self): |
---|
1490 | """ |
---|
1491 | save the state of plotting range |
---|
1492 | """ |
---|
1493 | self.state.qmin = self.qmin_x |
---|
1494 | self.state.qmax = self.qmax_x |
---|
1495 | self.state.npts = self.npts_x |
---|
1496 | |
---|
1497 | def _onparamEnter_helper(self): |
---|
1498 | """ |
---|
1499 | check if values entered by the user are changed and valid to replot |
---|
1500 | model |
---|
1501 | """ |
---|
1502 | # Flag to register when a parameter has changed. |
---|
1503 | is_modified = False |
---|
1504 | self.fitrange = True |
---|
1505 | is_2Ddata = False |
---|
1506 | #self._undo.Enable(True) |
---|
1507 | # check if 2d data |
---|
1508 | if self.data.__class__.__name__ == "Data2D": |
---|
1509 | is_2Ddata = True |
---|
1510 | if self.model != None: |
---|
1511 | try: |
---|
1512 | is_modified = self._check_value_enter(self.fittable_param, |
---|
1513 | is_modified) |
---|
1514 | is_modified = self._check_value_enter(self.fixed_param, |
---|
1515 | is_modified) |
---|
1516 | is_modified = self._check_value_enter(self.parameters, |
---|
1517 | is_modified) |
---|
1518 | except: |
---|
1519 | pass |
---|
1520 | |
---|
1521 | # Here we should check whether the boundaries have been modified. |
---|
1522 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
1523 | # set the is_modified flag to True |
---|
1524 | if self._validate_qrange(self.qmin, self.qmax): |
---|
1525 | tempmin = float(self.qmin.GetValue()) |
---|
1526 | if tempmin != self.qmin_x: |
---|
1527 | self.qmin_x = tempmin |
---|
1528 | is_modified = True |
---|
1529 | tempmax = float(self.qmax.GetValue()) |
---|
1530 | if tempmax != self.qmax_x: |
---|
1531 | self.qmax_x = tempmax |
---|
1532 | is_modified = True |
---|
1533 | |
---|
1534 | if is_2Ddata: |
---|
1535 | # set mask |
---|
1536 | is_modified = self._validate_Npts() |
---|
1537 | |
---|
1538 | else: |
---|
1539 | self.fitrange = False |
---|
1540 | |
---|
1541 | if not self.data.is_data: |
---|
1542 | is_modified = True |
---|
1543 | |
---|
1544 | ## if any value is modify draw model with new value |
---|
1545 | if not self.fitrange: |
---|
1546 | #self.btFit.Disable() |
---|
1547 | if is_2Ddata: |
---|
1548 | self.btEditMask.Disable() |
---|
1549 | else: |
---|
1550 | if is_2Ddata and self.data.is_data and not self.batch_on: |
---|
1551 | self.btEditMask.Enable(True) |
---|
1552 | if is_modified and self.fitrange: |
---|
1553 | # Theory case: need to get npts value to draw |
---|
1554 | self.npts_x = float(self.Npts_total.GetValue()) |
---|
1555 | self.create_default_data() |
---|
1556 | self.state_change = True |
---|
1557 | self._draw_model() |
---|
1558 | self.Refresh() |
---|
1559 | return is_modified |
---|
1560 | |
---|
1561 | def _update_paramv_on_fit(self): |
---|
1562 | """ |
---|
1563 | make sure that update param values just before the fitting |
---|
1564 | """ |
---|
1565 | #flag for qmin qmax check values |
---|
1566 | flag = True |
---|
1567 | self.fitrange = True |
---|
1568 | is_modified = False |
---|
1569 | |
---|
1570 | #wx.PostEvent(self._manager.parent, StatusEvent(status=" \ |
---|
1571 | #updating ... ",type="update")) |
---|
1572 | |
---|
1573 | ##So make sure that update param values on_Fit. |
---|
1574 | #self._undo.Enable(True) |
---|
1575 | if self.model != None: |
---|
1576 | if self.Npts_total.GetValue() != self.Npts_fit.GetValue(): |
---|
1577 | if not self.data.is_data: |
---|
1578 | self._manager.page_finder[self.uid].set_fit_data(data=\ |
---|
1579 | [self.data]) |
---|
1580 | ##Check the values |
---|
1581 | self._check_value_enter(self.fittable_param, is_modified) |
---|
1582 | self._check_value_enter(self.fixed_param, is_modified) |
---|
1583 | self._check_value_enter(self.parameters, is_modified) |
---|
1584 | |
---|
1585 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
1586 | # Here we should check whether the boundaries have been modified. |
---|
1587 | # If qmin and qmax have been modified, update qmin and qmax and |
---|
1588 | # set the is_modified flag to True |
---|
1589 | self.fitrange = self._validate_qrange(self.qmin, self.qmax) |
---|
1590 | if self.fitrange: |
---|
1591 | tempmin = float(self.qmin.GetValue()) |
---|
1592 | if tempmin != self.qmin_x: |
---|
1593 | self.qmin_x = tempmin |
---|
1594 | tempmax = float(self.qmax.GetValue()) |
---|
1595 | if tempmax != self.qmax_x: |
---|
1596 | self.qmax_x = tempmax |
---|
1597 | if tempmax == tempmin: |
---|
1598 | flag = False |
---|
1599 | temp_smearer = None |
---|
1600 | if not self.disable_smearer.GetValue(): |
---|
1601 | temp_smearer = self.current_smearer |
---|
1602 | if self.slit_smearer.GetValue(): |
---|
1603 | flag = self.update_slit_smear() |
---|
1604 | elif self.pinhole_smearer.GetValue(): |
---|
1605 | flag = self.update_pinhole_smear() |
---|
1606 | else: |
---|
1607 | self._manager.set_smearer(smearer=temp_smearer, |
---|
1608 | uid=self.uid, |
---|
1609 | fid=self.data.id, |
---|
1610 | qmin=float(self.qmin_x), |
---|
1611 | qmax=float(self.qmax_x), |
---|
1612 | enable_smearer=not self.disable_smearer.GetValue(), |
---|
1613 | draw=False) |
---|
1614 | elif not self._is_2D(): |
---|
1615 | self._manager.set_smearer(smearer=temp_smearer, |
---|
1616 | qmin=float(self.qmin_x), |
---|
1617 | uid=self.uid, |
---|
1618 | fid=self.data.id, |
---|
1619 | qmax=float(self.qmax_x), |
---|
1620 | enable_smearer=not self.disable_smearer.GetValue(), |
---|
1621 | draw=False) |
---|
1622 | if self.data != None: |
---|
1623 | index_data = ((self.qmin_x <= self.data.x) & \ |
---|
1624 | (self.data.x <= self.qmax_x)) |
---|
1625 | val = str(len(self.data.x[index_data == True])) |
---|
1626 | self.Npts_fit.SetValue(val) |
---|
1627 | else: |
---|
1628 | # No data in the panel |
---|
1629 | try: |
---|
1630 | self.npts_x = float(self.Npts_total.GetValue()) |
---|
1631 | except: |
---|
1632 | flag = False |
---|
1633 | return flag |
---|
1634 | flag = True |
---|
1635 | if self._is_2D(): |
---|
1636 | # only 2D case set mask |
---|
1637 | flag = self._validate_Npts() |
---|
1638 | if not flag: |
---|
1639 | return flag |
---|
1640 | else: |
---|
1641 | flag = False |
---|
1642 | else: |
---|
1643 | flag = False |
---|
1644 | |
---|
1645 | #For invalid q range, disable the mask editor and fit button, vs. |
---|
1646 | if not self.fitrange: |
---|
1647 | if self._is_2D(): |
---|
1648 | self.btEditMask.Disable() |
---|
1649 | else: |
---|
1650 | if self._is_2D() and self.data.is_data and not self.batch_on: |
---|
1651 | self.btEditMask.Enable(True) |
---|
1652 | |
---|
1653 | if not flag: |
---|
1654 | msg = "Cannot Plot or Fit :Must select a " |
---|
1655 | msg += " model or Fitting range is not valid!!! " |
---|
1656 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
1657 | |
---|
1658 | try: |
---|
1659 | self.save_current_state() |
---|
1660 | except: |
---|
1661 | pass |
---|
1662 | |
---|
1663 | return flag |
---|
1664 | |
---|
1665 | def _is_modified(self, is_modified): |
---|
1666 | """ |
---|
1667 | return to self._is_modified |
---|
1668 | """ |
---|
1669 | return is_modified |
---|
1670 | |
---|
1671 | def _reset_parameters_state(self, listtorestore, statelist): |
---|
1672 | """ |
---|
1673 | Reset the parameters at the given state |
---|
1674 | """ |
---|
1675 | if len(statelist) == 0 or len(listtorestore) == 0: |
---|
1676 | return |
---|
1677 | if len(statelist) != len(listtorestore): |
---|
1678 | return |
---|
1679 | |
---|
1680 | for j in range(len(listtorestore)): |
---|
1681 | item_page = listtorestore[j] |
---|
1682 | item_page_info = statelist[j] |
---|
1683 | ##change the state of the check box for simple parameters |
---|
1684 | if item_page[0] != None: |
---|
1685 | item_page[0].SetValue(item_page_info[0]) |
---|
1686 | if item_page[2] != None: |
---|
1687 | item_page[2].SetValue(item_page_info[2]) |
---|
1688 | if item_page[2].__class__.__name__ == "ComboBox": |
---|
1689 | if item_page_info[2] in self.model.fun_list: |
---|
1690 | fun_val = self.model.fun_list[item_page_info[2]] |
---|
1691 | self.model.setParam(item_page_info[1], fun_val) |
---|
1692 | if item_page[3] != None: |
---|
1693 | ## show or hide text +/- |
---|
1694 | if item_page_info[2]: |
---|
1695 | item_page[3].Show(True) |
---|
1696 | else: |
---|
1697 | item_page[3].Hide() |
---|
1698 | if item_page[4] != None: |
---|
1699 | ## show of hide the text crtl for fitting error |
---|
1700 | if item_page_info[4][0]: |
---|
1701 | item_page[4].Show(True) |
---|
1702 | item_page[4].SetValue(item_page_info[4][1]) |
---|
1703 | else: |
---|
1704 | item_page[3].Hide() |
---|
1705 | if item_page[5] != None: |
---|
1706 | ## show of hide the text crtl for fitting error |
---|
1707 | item_page[5].Show(item_page_info[5][0]) |
---|
1708 | item_page[5].SetValue(item_page_info[5][1]) |
---|
1709 | |
---|
1710 | if item_page[6] != None: |
---|
1711 | ## show of hide the text crtl for fitting error |
---|
1712 | item_page[6].Show(item_page_info[6][0]) |
---|
1713 | item_page[6].SetValue(item_page_info[6][1]) |
---|
1714 | |
---|
1715 | def _reset_strparam_state(self, listtorestore, statelist): |
---|
1716 | """ |
---|
1717 | Reset the string parameters at the given state |
---|
1718 | """ |
---|
1719 | if len(statelist) == 0: |
---|
1720 | return |
---|
1721 | |
---|
1722 | listtorestore = copy.deepcopy(statelist) |
---|
1723 | |
---|
1724 | for j in range(len(listtorestore)): |
---|
1725 | item_page = listtorestore[j] |
---|
1726 | item_page_info = statelist[j] |
---|
1727 | ##change the state of the check box for simple parameters |
---|
1728 | |
---|
1729 | if item_page[0] != None: |
---|
1730 | item_page[0].SetValue(format_number(item_page_info[0], True)) |
---|
1731 | |
---|
1732 | if item_page[2] != None: |
---|
1733 | param_name = item_page_info[1] |
---|
1734 | value = item_page_info[2] |
---|
1735 | selection = value |
---|
1736 | if value in self.model.fun_list: |
---|
1737 | selection = self.model.fun_list[value] |
---|
1738 | item_page[2].SetValue(selection) |
---|
1739 | self.model.setParam(param_name, selection) |
---|
1740 | |
---|
1741 | def _copy_parameters_state(self, listtocopy, statelist): |
---|
1742 | """ |
---|
1743 | copy the state of button |
---|
1744 | |
---|
1745 | :param listtocopy: the list of check button to copy |
---|
1746 | :param statelist: list of state object to store the current state |
---|
1747 | |
---|
1748 | """ |
---|
1749 | if len(listtocopy) == 0: |
---|
1750 | return |
---|
1751 | |
---|
1752 | for item in listtocopy: |
---|
1753 | |
---|
1754 | checkbox_state = None |
---|
1755 | if item[0] != None: |
---|
1756 | checkbox_state = item[0].GetValue() |
---|
1757 | parameter_name = item[1] |
---|
1758 | parameter_value = None |
---|
1759 | if item[2] != None: |
---|
1760 | parameter_value = item[2].GetValue() |
---|
1761 | static_text = None |
---|
1762 | if item[3] != None: |
---|
1763 | static_text = item[3].IsShown() |
---|
1764 | error_value = None |
---|
1765 | error_state = None |
---|
1766 | if item[4] != None: |
---|
1767 | error_value = item[4].GetValue() |
---|
1768 | error_state = item[4].IsShown() |
---|
1769 | |
---|
1770 | min_value = None |
---|
1771 | min_state = None |
---|
1772 | if item[5] != None: |
---|
1773 | min_value = item[5].GetValue() |
---|
1774 | min_state = item[5].IsShown() |
---|
1775 | |
---|
1776 | max_value = None |
---|
1777 | max_state = None |
---|
1778 | if item[6] != None: |
---|
1779 | max_value = item[6].GetValue() |
---|
1780 | max_state = item[6].IsShown() |
---|
1781 | unit = None |
---|
1782 | if item[7] != None: |
---|
1783 | unit = item[7].GetLabel() |
---|
1784 | |
---|
1785 | statelist.append([checkbox_state, parameter_name, parameter_value, |
---|
1786 | static_text, [error_state, error_value], |
---|
1787 | [min_state, min_value], |
---|
1788 | [max_state, max_value], unit]) |
---|
1789 | |
---|
1790 | def _set_model_sizer_selection(self, model): |
---|
1791 | """ |
---|
1792 | Display the sizer according to the type of the current model |
---|
1793 | """ |
---|
1794 | if model == None: |
---|
1795 | return |
---|
1796 | if hasattr(model, "s_model"): |
---|
1797 | |
---|
1798 | class_name = model.s_model.__class__ |
---|
1799 | name = model.s_model.name |
---|
1800 | flag = (name != "NoStructure") |
---|
1801 | if flag and \ |
---|
1802 | (class_name in self.model_list_box["Structure Factors"]): |
---|
1803 | self.structurebox.Show() |
---|
1804 | self.text2.Show() |
---|
1805 | self.structurebox.Enable() |
---|
1806 | self.text2.Enable() |
---|
1807 | items = self.structurebox.GetItems() |
---|
1808 | self.sizer1.Layout() |
---|
1809 | |
---|
1810 | for i in range(len(items)): |
---|
1811 | if items[i] == str(name): |
---|
1812 | self.structurebox.SetSelection(i) |
---|
1813 | break |
---|
1814 | |
---|
1815 | if hasattr(model, "p_model"): |
---|
1816 | class_name = model.p_model.__class__ |
---|
1817 | name = model.p_model.name |
---|
1818 | self.formfactorbox.Clear() |
---|
1819 | |
---|
1820 | for k, list in self.model_list_box.iteritems(): |
---|
1821 | if k in["P(Q)*S(Q)", "Shapes"] and \ |
---|
1822 | class_name in self.model_list_box["Shapes"]: |
---|
1823 | self.shape_rbutton.SetValue(True) |
---|
1824 | ## fill the form factor list with new model |
---|
1825 | self._populate_box(self.formfactorbox, |
---|
1826 | self.model_list_box["Shapes"]) |
---|
1827 | items = self.formfactorbox.GetItems() |
---|
1828 | ## set comboxbox to the selected item |
---|
1829 | for i in range(len(items)): |
---|
1830 | if items[i] == str(name): |
---|
1831 | self.formfactorbox.SetSelection(i) |
---|
1832 | break |
---|
1833 | return |
---|
1834 | elif k == "Shape-Independent": |
---|
1835 | self.shape_indep_rbutton.SetValue(True) |
---|
1836 | elif k == "Structure Factors": |
---|
1837 | self.struct_rbutton.SetValue(True) |
---|
1838 | elif k == "Multi-Functions": |
---|
1839 | continue |
---|
1840 | else: |
---|
1841 | self.plugin_rbutton.SetValue(True) |
---|
1842 | |
---|
1843 | if class_name in list: |
---|
1844 | ## fill the form factor list with new model |
---|
1845 | self._populate_box(self.formfactorbox, list) |
---|
1846 | items = self.formfactorbox.GetItems() |
---|
1847 | ## set comboxbox to the selected item |
---|
1848 | for i in range(len(items)): |
---|
1849 | if items[i] == str(name): |
---|
1850 | self.formfactorbox.SetSelection(i) |
---|
1851 | break |
---|
1852 | break |
---|
1853 | else: |
---|
1854 | ## Select the model from the menu |
---|
1855 | class_name = model.__class__ |
---|
1856 | name = model.name |
---|
1857 | self.formfactorbox.Clear() |
---|
1858 | items = self.formfactorbox.GetItems() |
---|
1859 | |
---|
1860 | for k, list in self.model_list_box.iteritems(): |
---|
1861 | if k in["P(Q)*S(Q)", "Shapes"] and \ |
---|
1862 | class_name in self.model_list_box["Shapes"]: |
---|
1863 | if class_name in self.model_list_box["P(Q)*S(Q)"]: |
---|
1864 | self.structurebox.Show() |
---|
1865 | self.text2.Show() |
---|
1866 | self.structurebox.Enable() |
---|
1867 | self.structurebox.SetSelection(0) |
---|
1868 | self.text2.Enable() |
---|
1869 | else: |
---|
1870 | self.structurebox.Hide() |
---|
1871 | self.text2.Hide() |
---|
1872 | self.structurebox.Disable() |
---|
1873 | self.structurebox.SetSelection(0) |
---|
1874 | self.text2.Disable() |
---|
1875 | |
---|
1876 | self.shape_rbutton.SetValue(True) |
---|
1877 | ## fill the form factor list with new model |
---|
1878 | self._populate_box(self.formfactorbox, |
---|
1879 | self.model_list_box["Shapes"]) |
---|
1880 | items = self.formfactorbox.GetItems() |
---|
1881 | ## set comboxbox to the selected item |
---|
1882 | for i in range(len(items)): |
---|
1883 | if items[i] == str(name): |
---|
1884 | self.formfactorbox.SetSelection(i) |
---|
1885 | break |
---|
1886 | return |
---|
1887 | elif k == "Shape-Independent": |
---|
1888 | self.shape_indep_rbutton.SetValue(True) |
---|
1889 | elif k == "Structure Factors": |
---|
1890 | self.struct_rbutton.SetValue(True) |
---|
1891 | elif k == "Multi-Functions": |
---|
1892 | continue |
---|
1893 | else: |
---|
1894 | self.plugin_rbutton.SetValue(True) |
---|
1895 | if class_name in list: |
---|
1896 | self.structurebox.SetSelection(0) |
---|
1897 | self.structurebox.Disable() |
---|
1898 | self.text2.Disable() |
---|
1899 | ## fill the form factor list with new model |
---|
1900 | self._populate_box(self.formfactorbox, list) |
---|
1901 | items = self.formfactorbox.GetItems() |
---|
1902 | ## set comboxbox to the selected item |
---|
1903 | for i in range(len(items)): |
---|
1904 | if items[i] == str(name): |
---|
1905 | self.formfactorbox.SetSelection(i) |
---|
1906 | break |
---|
1907 | break |
---|
1908 | |
---|
1909 | def _draw_model(self, update_chisqr=True, source='model'): |
---|
1910 | """ |
---|
1911 | Method to draw or refresh a plotted model. |
---|
1912 | The method will use the data member from the model page |
---|
1913 | to build a call to the fitting perspective manager. |
---|
1914 | |
---|
1915 | :param chisqr: update chisqr value [bool] |
---|
1916 | """ |
---|
1917 | wx.CallAfter(self._draw_model_after, update_chisqr, source) |
---|
1918 | |
---|
1919 | def _draw_model_after(self, update_chisqr=True, source='model'): |
---|
1920 | """ |
---|
1921 | Method to draw or refresh a plotted model. |
---|
1922 | The method will use the data member from the model page |
---|
1923 | to build a call to the fitting perspective manager. |
---|
1924 | |
---|
1925 | :param chisqr: update chisqr value [bool] |
---|
1926 | """ |
---|
1927 | #if self.check_invalid_panel(): |
---|
1928 | # return |
---|
1929 | if self.model != None: |
---|
1930 | temp_smear = None |
---|
1931 | if hasattr(self, "enable_smearer"): |
---|
1932 | if not self.disable_smearer.GetValue(): |
---|
1933 | temp_smear = self.current_smearer |
---|
1934 | # compute weight for the current data |
---|
1935 | from .utils import get_weight |
---|
1936 | flag = self.get_weight_flag() |
---|
1937 | weight = get_weight(data=self.data, is2d=self._is_2D(), flag=flag) |
---|
1938 | toggle_mode_on = self.model_view.IsEnabled() |
---|
1939 | is_2d = self._is_2D() |
---|
1940 | self._manager.draw_model(self.model, |
---|
1941 | data=self.data, |
---|
1942 | smearer=temp_smear, |
---|
1943 | qmin=float(self.qmin_x), |
---|
1944 | qmax=float(self.qmax_x), |
---|
1945 | page_id=self.uid, |
---|
1946 | toggle_mode_on=toggle_mode_on, |
---|
1947 | state=self.state, |
---|
1948 | enable2D=is_2d, |
---|
1949 | update_chisqr=update_chisqr, |
---|
1950 | source='model', |
---|
1951 | weight=weight) |
---|
1952 | |
---|
1953 | def _on_show_sld(self, event=None): |
---|
1954 | """ |
---|
1955 | Plot SLD profile |
---|
1956 | """ |
---|
1957 | # get profile data |
---|
1958 | x, y = self.model.getProfile() |
---|
1959 | |
---|
1960 | from danse.common.plottools import Data1D as pf_data1d |
---|
1961 | #from sans.perspectives.theory.profile_dialog import SLDPanel |
---|
1962 | from sans.guiframe.local_perspectives.plotting.profile_dialog \ |
---|
1963 | import SLDPanel |
---|
1964 | sld_data = pf_data1d(x, y) |
---|
1965 | sld_data.name = 'SLD' |
---|
1966 | sld_data.axes = self.sld_axes |
---|
1967 | self.panel = SLDPanel(self, data=sld_data, axes=self.sld_axes, id=-1) |
---|
1968 | self.panel.ShowModal() |
---|
1969 | |
---|
1970 | def _set_multfactor_combobox(self, multiplicity=10): |
---|
1971 | """ |
---|
1972 | Set comboBox for muitfactor of CoreMultiShellModel |
---|
1973 | :param multiplicit: no. of multi-functionality |
---|
1974 | """ |
---|
1975 | # build content of the combobox |
---|
1976 | for idx in range(0, multiplicity): |
---|
1977 | self.multifactorbox.Append(str(idx), int(idx)) |
---|
1978 | self._hide_multfactor_combobox() |
---|
1979 | |
---|
1980 | def _show_multfactor_combobox(self): |
---|
1981 | """ |
---|
1982 | Show the comboBox of muitfactor of CoreMultiShellModel |
---|
1983 | """ |
---|
1984 | if not self.mutifactor_text.IsShown(): |
---|
1985 | self.mutifactor_text.Show(True) |
---|
1986 | self.mutifactor_text1.Show(True) |
---|
1987 | if not self.multifactorbox.IsShown(): |
---|
1988 | self.multifactorbox.Show(True) |
---|
1989 | |
---|
1990 | def _hide_multfactor_combobox(self): |
---|
1991 | """ |
---|
1992 | Hide the comboBox of muitfactor of CoreMultiShellModel |
---|
1993 | """ |
---|
1994 | if self.mutifactor_text.IsShown(): |
---|
1995 | self.mutifactor_text.Hide() |
---|
1996 | self.mutifactor_text1.Hide() |
---|
1997 | if self.multifactorbox.IsShown(): |
---|
1998 | self.multifactorbox.Hide() |
---|
1999 | |
---|
2000 | def formfactor_combo_init(self): |
---|
2001 | """ |
---|
2002 | First time calls _show_combox_helper |
---|
2003 | """ |
---|
2004 | self._show_combox(None) |
---|
2005 | |
---|
2006 | def _show_combox_helper(self): |
---|
2007 | """ |
---|
2008 | Fill panel's combo box according to the type of model selected |
---|
2009 | """ |
---|
2010 | custom_model = 'Customized Models' |
---|
2011 | mod_cat = self.categorybox.GetStringSelection() |
---|
2012 | self.structurebox.SetSelection(0) |
---|
2013 | self.structurebox.Disable() |
---|
2014 | self.formfactorbox.Clear() |
---|
2015 | if mod_cat == None: |
---|
2016 | return |
---|
2017 | m_list = [] |
---|
2018 | try: |
---|
2019 | if mod_cat == custom_model: |
---|
2020 | for model in self.model_list_box[mod_cat]: |
---|
2021 | str_m = str(model).split(".")[0] |
---|
2022 | #self.model_box.Append(str_m) |
---|
2023 | m_list.append(self.model_dict[str_m]) |
---|
2024 | else: |
---|
2025 | cat_dic = self.master_category_dict[mod_cat] |
---|
2026 | for (model, enabled) in cat_dic: |
---|
2027 | if enabled: |
---|
2028 | m_list.append(self.model_dict[model]) |
---|
2029 | #else: |
---|
2030 | # msg = "This model is disabled by Category Manager." |
---|
2031 | # wx.PostEvent(self.parent.parent, |
---|
2032 | # StatusEvent(status=msg, info="error")) |
---|
2033 | except: |
---|
2034 | msg = "%s\n" % (sys.exc_value) |
---|
2035 | wx.PostEvent(self.parent.parent, |
---|
2036 | StatusEvent(status=msg, info="error")) |
---|
2037 | self._populate_box(self.formfactorbox, m_list) |
---|
2038 | |
---|
2039 | def _on_modify_cat(self, event=None): |
---|
2040 | self._manager.parent.on_category_panel(event) |
---|
2041 | |
---|
2042 | def _show_combox(self, event=None): |
---|
2043 | """ |
---|
2044 | Show combox box associate with type of model selected |
---|
2045 | """ |
---|
2046 | self.Show(False) |
---|
2047 | self._show_combox_helper() |
---|
2048 | self._on_select_model(event=None) |
---|
2049 | self.Show(True) |
---|
2050 | self._save_typeOfmodel() |
---|
2051 | self.sizer4_4.Layout() |
---|
2052 | self.sizer4.Layout() |
---|
2053 | self.Layout() |
---|
2054 | self.Refresh() |
---|
2055 | |
---|
2056 | def _populate_box(self, combobox, list): |
---|
2057 | """ |
---|
2058 | fill combox box with dict item |
---|
2059 | |
---|
2060 | :param list: contains item to fill the combox |
---|
2061 | item must model class |
---|
2062 | """ |
---|
2063 | mlist = [] |
---|
2064 | for models in list: |
---|
2065 | model = models() |
---|
2066 | name = model.__class__.__name__ |
---|
2067 | if models.__name__ != "NoStructure": |
---|
2068 | if hasattr(model, "name"): |
---|
2069 | name = model.name |
---|
2070 | mlist.append((name, models)) |
---|
2071 | |
---|
2072 | # Sort the models |
---|
2073 | mlist_sorted = sorted(mlist) |
---|
2074 | for item in mlist_sorted: |
---|
2075 | combobox.Append(item[0], item[1]) |
---|
2076 | return 0 |
---|
2077 | |
---|
2078 | def _onQrangeEnter(self, event): |
---|
2079 | """ |
---|
2080 | Check validity of value enter in the Q range field |
---|
2081 | |
---|
2082 | """ |
---|
2083 | tcrtl = event.GetEventObject() |
---|
2084 | #Clear msg if previously shown. |
---|
2085 | msg = "" |
---|
2086 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
2087 | # Flag to register when a parameter has changed. |
---|
2088 | #is_modified = False |
---|
2089 | if tcrtl.GetValue().lstrip().rstrip() != "": |
---|
2090 | try: |
---|
2091 | float(tcrtl.GetValue()) |
---|
2092 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
2093 | # If qmin and qmax have been modified, update qmin and qmax |
---|
2094 | if self._validate_qrange(self.qmin, self.qmax): |
---|
2095 | tempmin = float(self.qmin.GetValue()) |
---|
2096 | if tempmin != self.qmin_x: |
---|
2097 | self.qmin_x = tempmin |
---|
2098 | tempmax = float(self.qmax.GetValue()) |
---|
2099 | if tempmax != self.qmax_x: |
---|
2100 | self.qmax_x = tempmax |
---|
2101 | else: |
---|
2102 | tcrtl.SetBackgroundColour("pink") |
---|
2103 | msg = "Model Error:wrong value entered: %s" % sys.exc_value |
---|
2104 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
2105 | return |
---|
2106 | except: |
---|
2107 | tcrtl.SetBackgroundColour("pink") |
---|
2108 | msg = "Model Error:wrong value entered: %s" % sys.exc_value |
---|
2109 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
2110 | return |
---|
2111 | #Check if # of points for theory model are valid(>0). |
---|
2112 | if self.npts != None: |
---|
2113 | if check_float(self.npts): |
---|
2114 | temp_npts = float(self.npts.GetValue()) |
---|
2115 | if temp_npts != self.num_points: |
---|
2116 | self.num_points = temp_npts |
---|
2117 | #is_modified = True |
---|
2118 | else: |
---|
2119 | msg = "Cannot Plot :No npts in that Qrange!!! " |
---|
2120 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
2121 | else: |
---|
2122 | tcrtl.SetBackgroundColour("pink") |
---|
2123 | msg = "Model Error:wrong value entered!!!" |
---|
2124 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
2125 | self.save_current_state() |
---|
2126 | event = PageInfoEvent(page=self) |
---|
2127 | wx.PostEvent(self.parent, event) |
---|
2128 | self.state_change = False |
---|
2129 | #Draw the model for a different range |
---|
2130 | if not self.data.is_data: |
---|
2131 | self.create_default_data() |
---|
2132 | self._draw_model() |
---|
2133 | |
---|
2134 | def _theory_qrange_enter(self, event): |
---|
2135 | """ |
---|
2136 | Check validity of value enter in the Q range field |
---|
2137 | """ |
---|
2138 | |
---|
2139 | tcrtl = event.GetEventObject() |
---|
2140 | #Clear msg if previously shown. |
---|
2141 | msg = "" |
---|
2142 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
2143 | # Flag to register when a parameter has changed. |
---|
2144 | is_modified = False |
---|
2145 | if tcrtl.GetValue().lstrip().rstrip() != "": |
---|
2146 | try: |
---|
2147 | value = float(tcrtl.GetValue()) |
---|
2148 | tcrtl.SetBackgroundColour(wx.WHITE) |
---|
2149 | |
---|
2150 | # If qmin and qmax have been modified, update qmin and qmax |
---|
2151 | if self._validate_qrange(self.theory_qmin, self.theory_qmax): |
---|
2152 | tempmin = float(self.theory_qmin.GetValue()) |
---|
2153 | if tempmin != self.theory_qmin_x: |
---|
2154 | self.theory_qmin_x = tempmin |
---|
2155 | tempmax = float(self.theory_qmax.GetValue()) |
---|
2156 | if tempmax != self.qmax_x: |
---|
2157 | self.theory_qmax_x = tempmax |
---|
2158 | else: |
---|
2159 | tcrtl.SetBackgroundColour("pink") |
---|
2160 | msg = "Model Error:wrong value entered: %s" % sys.exc_value |
---|
2161 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
2162 | return |
---|
2163 | except: |
---|
2164 | tcrtl.SetBackgroundColour("pink") |
---|
2165 | msg = "Model Error:wrong value entered: %s" % sys.exc_value |
---|
2166 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
2167 | return |
---|
2168 | #Check if # of points for theory model are valid(>0). |
---|
2169 | if self.Npts_total.IsEditable(): |
---|
2170 | if check_float(self.Npts_total): |
---|
2171 | temp_npts = float(self.Npts_total.GetValue()) |
---|
2172 | if temp_npts != self.num_points: |
---|
2173 | self.num_points = temp_npts |
---|
2174 | is_modified = True |
---|
2175 | else: |
---|
2176 | msg = "Cannot Plot :No npts in that Qrange!!! " |
---|
2177 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
2178 | else: |
---|
2179 | tcrtl.SetBackgroundColour("pink") |
---|
2180 | msg = "Model Error:wrong value entered!!!" |
---|
2181 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
2182 | self.save_current_state() |
---|
2183 | event = PageInfoEvent(page=self) |
---|
2184 | wx.PostEvent(self.parent, event) |
---|
2185 | self.state_change = False |
---|
2186 | #Draw the model for a different range |
---|
2187 | self.create_default_data() |
---|
2188 | self._draw_model() |
---|
2189 | |
---|
2190 | def _on_select_model_helper(self): |
---|
2191 | """ |
---|
2192 | call back for model selection |
---|
2193 | """ |
---|
2194 | ## reset dictionary containing reference to dispersion |
---|
2195 | self._disp_obj_dict = {} |
---|
2196 | self.disp_cb_dict = {} |
---|
2197 | self.temp_multi_functional = False |
---|
2198 | f_id = self.formfactorbox.GetCurrentSelection() |
---|
2199 | #For MAC |
---|
2200 | form_factor = None |
---|
2201 | if f_id >= 0: |
---|
2202 | form_factor = self.formfactorbox.GetClientData(f_id) |
---|
2203 | |
---|
2204 | if not form_factor in self.model_list_box["multiplication"]: |
---|
2205 | self.structurebox.Hide() |
---|
2206 | self.text2.Hide() |
---|
2207 | self.structurebox.Disable() |
---|
2208 | self.structurebox.SetSelection(0) |
---|
2209 | self.text2.Disable() |
---|
2210 | else: |
---|
2211 | self.structurebox.Show() |
---|
2212 | self.text2.Show() |
---|
2213 | self.structurebox.Enable() |
---|
2214 | self.text2.Enable() |
---|
2215 | |
---|
2216 | if form_factor != None: |
---|
2217 | # set multifactor for Mutifunctional models |
---|
2218 | if form_factor().__class__ in \ |
---|
2219 | self.model_list_box["Multi-Functions"]: |
---|
2220 | m_id = self.multifactorbox.GetCurrentSelection() |
---|
2221 | multiplicity = form_factor().multiplicity_info[0] |
---|
2222 | self.multifactorbox.Clear() |
---|
2223 | self._set_multfactor_combobox(multiplicity) |
---|
2224 | self._show_multfactor_combobox() |
---|
2225 | #ToDo: this info should be called directly from the model |
---|
2226 | text = form_factor().multiplicity_info[1] # 'No. of Shells: ' |
---|
2227 | |
---|
2228 | self.mutifactor_text.SetLabel(text) |
---|
2229 | if m_id > multiplicity - 1: |
---|
2230 | # default value |
---|
2231 | m_id = 1 |
---|
2232 | |
---|
2233 | self.multi_factor = self.multifactorbox.GetClientData(m_id) |
---|
2234 | if self.multi_factor == None: |
---|
2235 | self.multi_factor = 0 |
---|
2236 | form_factor = form_factor(int(self.multi_factor)) |
---|
2237 | self.multifactorbox.SetSelection(m_id) |
---|
2238 | # Check len of the text1 and max_multiplicity |
---|
2239 | text = '' |
---|
2240 | if form_factor.multiplicity_info[0] == \ |
---|
2241 | len(form_factor.multiplicity_info[2]): |
---|
2242 | text = form_factor.multiplicity_info[2][self.multi_factor] |
---|
2243 | self.mutifactor_text1.SetLabel(text) |
---|
2244 | # Check if model has get sld profile. |
---|
2245 | if len(form_factor.multiplicity_info[3]) > 0: |
---|
2246 | self.sld_axes = form_factor.multiplicity_info[3] |
---|
2247 | self.show_sld_button.Show(True) |
---|
2248 | else: |
---|
2249 | self.sld_axes = "" |
---|
2250 | |
---|
2251 | else: |
---|
2252 | self._hide_multfactor_combobox() |
---|
2253 | self.show_sld_button.Hide() |
---|
2254 | form_factor = form_factor() |
---|
2255 | self.multi_factor = None |
---|
2256 | else: |
---|
2257 | self._hide_multfactor_combobox() |
---|
2258 | self.show_sld_button.Hide() |
---|
2259 | self.multi_factor = None |
---|
2260 | |
---|
2261 | s_id = self.structurebox.GetCurrentSelection() |
---|
2262 | struct_factor = self.structurebox.GetClientData(s_id) |
---|
2263 | |
---|
2264 | if struct_factor != None: |
---|
2265 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
2266 | self.model = MultiplicationModel(form_factor, struct_factor()) |
---|
2267 | # multifunctional form factor |
---|
2268 | if len(form_factor.non_fittable) > 0: |
---|
2269 | self.temp_multi_functional = True |
---|
2270 | else: |
---|
2271 | if form_factor != None: |
---|
2272 | self.model = form_factor |
---|
2273 | else: |
---|
2274 | self.model = None |
---|
2275 | return self.model |
---|
2276 | # check if model has magnetic parameters |
---|
2277 | if len(self.model.magnetic_params) > 0: |
---|
2278 | self._has_magnetic = True |
---|
2279 | else: |
---|
2280 | self._has_magnetic = False |
---|
2281 | ## post state to fit panel |
---|
2282 | self.state.parameters = [] |
---|
2283 | self.state.model = self.model |
---|
2284 | self.state.qmin = self.qmin_x |
---|
2285 | self.state.multi_factor = self.multi_factor |
---|
2286 | self.disp_list = self.model.getDispParamList() |
---|
2287 | self.state.disp_list = self.disp_list |
---|
2288 | self.on_set_focus(None) |
---|
2289 | self.Layout() |
---|
2290 | |
---|
2291 | def _validate_qrange(self, qmin_ctrl, qmax_ctrl): |
---|
2292 | """ |
---|
2293 | Verify that the Q range controls have valid values |
---|
2294 | and that Qmin < Qmax. |
---|
2295 | |
---|
2296 | :param qmin_ctrl: text control for Qmin |
---|
2297 | :param qmax_ctrl: text control for Qmax |
---|
2298 | |
---|
2299 | :return: True is the Q range is value, False otherwise |
---|
2300 | |
---|
2301 | """ |
---|
2302 | qmin_validity = check_float(qmin_ctrl) |
---|
2303 | qmax_validity = check_float(qmax_ctrl) |
---|
2304 | if not (qmin_validity and qmax_validity): |
---|
2305 | return False |
---|
2306 | else: |
---|
2307 | qmin = float(qmin_ctrl.GetValue()) |
---|
2308 | qmax = float(qmax_ctrl.GetValue()) |
---|
2309 | if qmin < qmax: |
---|
2310 | #Make sure to set both colours white. |
---|
2311 | qmin_ctrl.SetBackgroundColour(wx.WHITE) |
---|
2312 | qmin_ctrl.Refresh() |
---|
2313 | qmax_ctrl.SetBackgroundColour(wx.WHITE) |
---|
2314 | qmax_ctrl.Refresh() |
---|
2315 | else: |
---|
2316 | qmin_ctrl.SetBackgroundColour("pink") |
---|
2317 | qmin_ctrl.Refresh() |
---|
2318 | qmax_ctrl.SetBackgroundColour("pink") |
---|
2319 | qmax_ctrl.Refresh() |
---|
2320 | msg = "Invalid Q range: Q min must be smaller than Q max" |
---|
2321 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
2322 | return False |
---|
2323 | return True |
---|
2324 | |
---|
2325 | def _validate_Npts(self): |
---|
2326 | """ |
---|
2327 | Validate the number of points for fitting is more than 10 points. |
---|
2328 | If valid, setvalues Npts_fit otherwise post msg. |
---|
2329 | """ |
---|
2330 | #default flag |
---|
2331 | flag = True |
---|
2332 | # Theory |
---|
2333 | if self.data == None and self.enable2D: |
---|
2334 | return flag |
---|
2335 | for data in self.data_list: |
---|
2336 | # q value from qx and qy |
---|
2337 | radius = numpy.sqrt(data.qx_data * data.qx_data + |
---|
2338 | data.qy_data * data.qy_data) |
---|
2339 | #get unmasked index |
---|
2340 | index_data = (float(self.qmin.GetValue()) <= radius) & \ |
---|
2341 | (radius <= float(self.qmax.GetValue())) |
---|
2342 | index_data = (index_data) & (data.mask) |
---|
2343 | index_data = (index_data) & (numpy.isfinite(data.data)) |
---|
2344 | |
---|
2345 | if len(index_data[index_data]) < 10: |
---|
2346 | # change the color pink. |
---|
2347 | self.qmin.SetBackgroundColour("pink") |
---|
2348 | self.qmin.Refresh() |
---|
2349 | self.qmax.SetBackgroundColour("pink") |
---|
2350 | self.qmax.Refresh() |
---|
2351 | msg = "Npts of Data Error :" |
---|
2352 | msg += "No or too little npts of %s." % data.name |
---|
2353 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
2354 | self.fitrange = False |
---|
2355 | flag = False |
---|
2356 | else: |
---|
2357 | self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) |
---|
2358 | self.fitrange = True |
---|
2359 | |
---|
2360 | return flag |
---|
2361 | |
---|
2362 | def _validate_Npts_1D(self): |
---|
2363 | """ |
---|
2364 | Validate the number of points for fitting is more than 5 points. |
---|
2365 | If valid, setvalues Npts_fit otherwise post msg. |
---|
2366 | """ |
---|
2367 | #default flag |
---|
2368 | flag = True |
---|
2369 | # Theory |
---|
2370 | if self.data == None: |
---|
2371 | return flag |
---|
2372 | for data in self.data_list: |
---|
2373 | # q value from qx and qy |
---|
2374 | radius = data.x |
---|
2375 | #get unmasked index |
---|
2376 | index_data = (float(self.qmin.GetValue()) <= radius) & \ |
---|
2377 | (radius <= float(self.qmax.GetValue())) |
---|
2378 | index_data = (index_data) & (numpy.isfinite(data.y)) |
---|
2379 | |
---|
2380 | if len(index_data[index_data]) < 5: |
---|
2381 | # change the color pink. |
---|
2382 | self.qmin.SetBackgroundColour("pink") |
---|
2383 | self.qmin.Refresh() |
---|
2384 | self.qmax.SetBackgroundColour("pink") |
---|
2385 | self.qmax.Refresh() |
---|
2386 | msg = "Npts of Data Error :" |
---|
2387 | msg += "No or too little npts of %s." % data.name |
---|
2388 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
2389 | self.fitrange = False |
---|
2390 | flag = False |
---|
2391 | else: |
---|
2392 | self.Npts_fit.SetValue(str(len(index_data[index_data == True]))) |
---|
2393 | self.fitrange = True |
---|
2394 | |
---|
2395 | return flag |
---|
2396 | |
---|
2397 | def _check_value_enter(self, list, modified): |
---|
2398 | """ |
---|
2399 | :param list: model parameter and panel info |
---|
2400 | :Note: each item of the list should be as follow: |
---|
2401 | item=[check button state, parameter's name, |
---|
2402 | paramater's value, string="+/-", |
---|
2403 | parameter's error of fit, |
---|
2404 | parameter's minimum value, |
---|
2405 | parrameter's maximum value , |
---|
2406 | parameter's units] |
---|
2407 | """ |
---|
2408 | is_modified = modified |
---|
2409 | if len(list) == 0: |
---|
2410 | return is_modified |
---|
2411 | for item in list: |
---|
2412 | #skip angle parameters for 1D |
---|
2413 | if not self.enable2D: |
---|
2414 | if item in self.orientation_params: |
---|
2415 | continue |
---|
2416 | #try: |
---|
2417 | name = str(item[1]) |
---|
2418 | |
---|
2419 | if string.find(name, ".npts") == -1 and \ |
---|
2420 | string.find(name, ".nsigmas") == -1: |
---|
2421 | ## check model parameters range |
---|
2422 | param_min = None |
---|
2423 | param_max = None |
---|
2424 | |
---|
2425 | ## check minimun value |
---|
2426 | if item[5] != None and item[5] != "": |
---|
2427 | if item[5].GetValue().lstrip().rstrip() != "": |
---|
2428 | try: |
---|
2429 | param_min = float(item[5].GetValue()) |
---|
2430 | if not self._validate_qrange(item[5], item[2]): |
---|
2431 | if numpy.isfinite(param_min): |
---|
2432 | item[2].SetValue(format_number(param_min)) |
---|
2433 | |
---|
2434 | item[5].SetBackgroundColour(wx.WHITE) |
---|
2435 | item[2].SetBackgroundColour(wx.WHITE) |
---|
2436 | |
---|
2437 | except: |
---|
2438 | msg = "Wrong Fit parameter range entered " |
---|
2439 | wx.PostEvent(self.parent.parent, |
---|
2440 | StatusEvent(status=msg)) |
---|
2441 | raise ValueError, msg |
---|
2442 | is_modified = True |
---|
2443 | ## check maximum value |
---|
2444 | if item[6] != None and item[6] != "": |
---|
2445 | if item[6].GetValue().lstrip().rstrip() != "": |
---|
2446 | try: |
---|
2447 | param_max = float(item[6].GetValue()) |
---|
2448 | if not self._validate_qrange(item[2], item[6]): |
---|
2449 | if numpy.isfinite(param_max): |
---|
2450 | item[2].SetValue(format_number(param_max)) |
---|
2451 | |
---|
2452 | item[6].SetBackgroundColour(wx.WHITE) |
---|
2453 | item[2].SetBackgroundColour(wx.WHITE) |
---|
2454 | except: |
---|
2455 | msg = "Wrong Fit parameter range entered " |
---|
2456 | wx.PostEvent(self.parent.parent, |
---|
2457 | StatusEvent(status=msg)) |
---|
2458 | raise ValueError, msg |
---|
2459 | is_modified = True |
---|
2460 | |
---|
2461 | if param_min != None and param_max != None: |
---|
2462 | if not self._validate_qrange(item[5], item[6]): |
---|
2463 | msg = "Wrong Fit range entered for parameter " |
---|
2464 | msg += "name %s of model %s " % (name, self.model.name) |
---|
2465 | wx.PostEvent(self.parent.parent, |
---|
2466 | StatusEvent(status=msg)) |
---|
2467 | |
---|
2468 | if name in self.model.details.keys(): |
---|
2469 | self.model.details[name][1:3] = param_min, param_max |
---|
2470 | is_modified = True |
---|
2471 | else: |
---|
2472 | self.model.details[name] = ["", param_min, param_max] |
---|
2473 | is_modified = True |
---|
2474 | try: |
---|
2475 | # Check if the textctr is enabled |
---|
2476 | if item[2].IsEnabled(): |
---|
2477 | value = float(item[2].GetValue()) |
---|
2478 | item[2].SetBackgroundColour("white") |
---|
2479 | # If the value of the parameter has changed, |
---|
2480 | # +update the model and set the is_modified flag |
---|
2481 | if value != self.model.getParam(name) and \ |
---|
2482 | numpy.isfinite(value): |
---|
2483 | self.model.setParam(name, value) |
---|
2484 | except: |
---|
2485 | item[2].SetBackgroundColour("pink") |
---|
2486 | msg = "Wrong Fit parameter value entered " |
---|
2487 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
2488 | |
---|
2489 | return is_modified |
---|
2490 | |
---|
2491 | def _set_dipers_Param(self, event): |
---|
2492 | """ |
---|
2493 | respond to self.enable_disp and self.disable_disp radio box. |
---|
2494 | The dispersity object is reset inside the model into Gaussian. |
---|
2495 | When the user select yes , this method display a combo box for |
---|
2496 | more selection when the user selects No,the combo box disappears. |
---|
2497 | Redraw the model with the default dispersity (Gaussian) |
---|
2498 | """ |
---|
2499 | ## On selction if no model exists. |
---|
2500 | if self.model == None: |
---|
2501 | self.disable_disp.SetValue(True) |
---|
2502 | msg = "Please select a Model first..." |
---|
2503 | wx.MessageBox(msg, 'Info') |
---|
2504 | wx.PostEvent(self._manager.parent, |
---|
2505 | StatusEvent(status="Polydispersion: %s" % msg)) |
---|
2506 | return |
---|
2507 | |
---|
2508 | self._reset_dispersity() |
---|
2509 | |
---|
2510 | if self.model == None: |
---|
2511 | self.model_disp.Hide() |
---|
2512 | self.sizer4_4.Clear(True) |
---|
2513 | return |
---|
2514 | |
---|
2515 | if self.enable_disp.GetValue(): |
---|
2516 | ## layout for model containing no dispersity parameters |
---|
2517 | |
---|
2518 | self.disp_list = self.model.getDispParamList() |
---|
2519 | |
---|
2520 | if len(self.disp_list) == 0 and len(self.disp_cb_dict) == 0: |
---|
2521 | self._layout_sizer_noDipers() |
---|
2522 | else: |
---|
2523 | ## set gaussian sizer |
---|
2524 | self._on_select_Disp(event=None) |
---|
2525 | else: |
---|
2526 | self.sizer4_4.Clear(True) |
---|
2527 | |
---|
2528 | ## post state to fit panel |
---|
2529 | self.save_current_state() |
---|
2530 | if event != None: |
---|
2531 | event = PageInfoEvent(page=self) |
---|
2532 | wx.PostEvent(self.parent, event) |
---|
2533 | #draw the model with the current dispersity |
---|
2534 | self._draw_model() |
---|
2535 | self.sizer4_4.Layout() |
---|
2536 | self.sizer5.Layout() |
---|
2537 | self.Layout() |
---|
2538 | self.Refresh() |
---|
2539 | |
---|
2540 | def _layout_sizer_noDipers(self): |
---|
2541 | """ |
---|
2542 | Draw a sizer with no dispersity info |
---|
2543 | """ |
---|
2544 | ix = 0 |
---|
2545 | iy = 1 |
---|
2546 | self.fittable_param = [] |
---|
2547 | self.fixed_param = [] |
---|
2548 | self.orientation_params_disp = [] |
---|
2549 | |
---|
2550 | self.sizer4_4.Clear(True) |
---|
2551 | text = "No polydispersity available for this model" |
---|
2552 | model_disp = wx.StaticText(self, -1, text) |
---|
2553 | self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), |
---|
2554 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) |
---|
2555 | self.sizer4_4.Layout() |
---|
2556 | self.sizer4.Layout() |
---|
2557 | |
---|
2558 | def _reset_dispersity(self): |
---|
2559 | """ |
---|
2560 | put gaussian dispersity into current model |
---|
2561 | """ |
---|
2562 | if len(self.param_toFit) > 0: |
---|
2563 | for item in self.fittable_param: |
---|
2564 | if item in self.param_toFit: |
---|
2565 | self.param_toFit.remove(item) |
---|
2566 | |
---|
2567 | for item in self.orientation_params_disp: |
---|
2568 | if item in self.param_toFit: |
---|
2569 | self.param_toFit.remove(item) |
---|
2570 | |
---|
2571 | self.fittable_param = [] |
---|
2572 | self.fixed_param = [] |
---|
2573 | self.orientation_params_disp = [] |
---|
2574 | self.values = {} |
---|
2575 | self.weights = {} |
---|
2576 | |
---|
2577 | from sans.models.dispersion_models import GaussianDispersion |
---|
2578 | if len(self.disp_cb_dict) == 0: |
---|
2579 | self.save_current_state() |
---|
2580 | self.sizer4_4.Clear(True) |
---|
2581 | self.Layout() |
---|
2582 | return |
---|
2583 | if (len(self.disp_cb_dict) > 0): |
---|
2584 | for p in self.disp_cb_dict: |
---|
2585 | # The parameter was un-selected. |
---|
2586 | # Go back to Gaussian model (with 0 pts) |
---|
2587 | disp_model = GaussianDispersion() |
---|
2588 | |
---|
2589 | self._disp_obj_dict[p] = disp_model |
---|
2590 | # Set the new model as the dispersion object |
---|
2591 | # for the selected parameter |
---|
2592 | try: |
---|
2593 | self.model.set_dispersion(p, disp_model) |
---|
2594 | except: |
---|
2595 | |
---|
2596 | pass |
---|
2597 | |
---|
2598 | ## save state into |
---|
2599 | self.save_current_state() |
---|
2600 | self.Layout() |
---|
2601 | self.Refresh() |
---|
2602 | |
---|
2603 | def _on_select_Disp(self, event): |
---|
2604 | """ |
---|
2605 | allow selecting different dispersion |
---|
2606 | self.disp_list should change type later .now only gaussian |
---|
2607 | """ |
---|
2608 | self._set_sizer_dispersion() |
---|
2609 | |
---|
2610 | ## Redraw the model |
---|
2611 | self._draw_model() |
---|
2612 | #self._undo.Enable(True) |
---|
2613 | event = PageInfoEvent(page=self) |
---|
2614 | wx.PostEvent(self.parent, event) |
---|
2615 | |
---|
2616 | self.sizer4_4.Layout() |
---|
2617 | self.sizer4.Layout() |
---|
2618 | self.SetupScrolling() |
---|
2619 | |
---|
2620 | def _on_disp_func(self, event=None): |
---|
2621 | """ |
---|
2622 | Select a distribution function for the polydispersion |
---|
2623 | |
---|
2624 | :Param event: ComboBox event |
---|
2625 | """ |
---|
2626 | # get ready for new event |
---|
2627 | if event != None: |
---|
2628 | event.Skip() |
---|
2629 | # Get event object |
---|
2630 | disp_box = event.GetEventObject() |
---|
2631 | |
---|
2632 | # Try to select a Distr. function |
---|
2633 | try: |
---|
2634 | disp_box.SetBackgroundColour("white") |
---|
2635 | selection = disp_box.GetCurrentSelection() |
---|
2636 | param_name = disp_box.Name.split('.')[0] |
---|
2637 | disp_name = disp_box.GetValue() |
---|
2638 | dispersity = disp_box.GetClientData(selection) |
---|
2639 | |
---|
2640 | #disp_model = GaussianDispersion() |
---|
2641 | disp_model = dispersity() |
---|
2642 | # Get param names to reset the values of the param |
---|
2643 | name1 = param_name + ".width" |
---|
2644 | name2 = param_name + ".npts" |
---|
2645 | name3 = param_name + ".nsigmas" |
---|
2646 | # Check Disp. function whether or not it is 'array' |
---|
2647 | if disp_name.lower() == "array": |
---|
2648 | value2 = "" |
---|
2649 | value3 = "" |
---|
2650 | value1 = self._set_array_disp(name=name1, disp=disp_model) |
---|
2651 | else: |
---|
2652 | self._del_array_values(name1) |
---|
2653 | #self._reset_array_disp(param_name) |
---|
2654 | self._disp_obj_dict[name1] = disp_model |
---|
2655 | self.model.set_dispersion(param_name, disp_model) |
---|
2656 | self.state._disp_obj_dict[name1] = disp_model |
---|
2657 | |
---|
2658 | value1 = str(format_number(self.model.getParam(name1), True)) |
---|
2659 | value2 = str(format_number(self.model.getParam(name2))) |
---|
2660 | value3 = str(format_number(self.model.getParam(name3))) |
---|
2661 | # Reset fittable polydispersin parameter value |
---|
2662 | for item in self.fittable_param: |
---|
2663 | if item[1] == name1: |
---|
2664 | item[2].SetValue(value1) |
---|
2665 | item[5].SetValue("") |
---|
2666 | item[6].SetValue("") |
---|
2667 | # Disable for array |
---|
2668 | if disp_name.lower() == "array": |
---|
2669 | item[0].SetValue(False) |
---|
2670 | item[0].Disable() |
---|
2671 | item[2].Disable() |
---|
2672 | item[3].Show(False) |
---|
2673 | item[4].Show(False) |
---|
2674 | item[5].Disable() |
---|
2675 | item[6].Disable() |
---|
2676 | else: |
---|
2677 | item[0].Enable() |
---|
2678 | item[2].Enable() |
---|
2679 | item[5].Enable() |
---|
2680 | item[6].Enable() |
---|
2681 | break |
---|
2682 | # Reset fixed polydispersion params |
---|
2683 | for item in self.fixed_param: |
---|
2684 | if item[1] == name2: |
---|
2685 | item[2].SetValue(value2) |
---|
2686 | # Disable Npts for array |
---|
2687 | if disp_name.lower() == "array": |
---|
2688 | item[2].Disable() |
---|
2689 | else: |
---|
2690 | item[2].Enable() |
---|
2691 | if item[1] == name3: |
---|
2692 | item[2].SetValue(value3) |
---|
2693 | # Disable Nsigs for array |
---|
2694 | if disp_name.lower() == "array": |
---|
2695 | item[2].Disable() |
---|
2696 | else: |
---|
2697 | item[2].Enable() |
---|
2698 | |
---|
2699 | # Make sure the check box updated when all checked |
---|
2700 | if self.cb1.GetValue(): |
---|
2701 | #self.select_all_param(None) |
---|
2702 | self.get_all_checked_params() |
---|
2703 | |
---|
2704 | # update params |
---|
2705 | self._update_paramv_on_fit() |
---|
2706 | # draw |
---|
2707 | self._draw_model() |
---|
2708 | self.Refresh() |
---|
2709 | except: |
---|
2710 | # Error msg |
---|
2711 | msg = "Error occurred:" |
---|
2712 | msg += " Could not select the distribution function..." |
---|
2713 | msg += " Please select another distribution function." |
---|
2714 | disp_box.SetBackgroundColour("pink") |
---|
2715 | # Focus on Fit button so that users can see the pinky box |
---|
2716 | self.btFit.SetFocus() |
---|
2717 | wx.PostEvent(self.parent.parent, |
---|
2718 | StatusEvent(status=msg, info="error")) |
---|
2719 | |
---|
2720 | def _set_array_disp(self, name=None, disp=None): |
---|
2721 | """ |
---|
2722 | Set array dispersion |
---|
2723 | |
---|
2724 | :param name: name of the parameter for the dispersion to be set |
---|
2725 | :param disp: the polydisperion object |
---|
2726 | """ |
---|
2727 | # The user wants this parameter to be averaged. |
---|
2728 | # Pop up the file selection dialog. |
---|
2729 | path = self._selectDlg() |
---|
2730 | # Array data |
---|
2731 | values = [] |
---|
2732 | weights = [] |
---|
2733 | # If nothing was selected, just return |
---|
2734 | if path is None: |
---|
2735 | self.disp_cb_dict[name].SetValue(False) |
---|
2736 | #self.noDisper_rbox.SetValue(True) |
---|
2737 | return |
---|
2738 | self._default_save_location = os.path.dirname(path) |
---|
2739 | if self.parent != None: |
---|
2740 | self.parent.parent._default_save_location =\ |
---|
2741 | self._default_save_location |
---|
2742 | |
---|
2743 | basename = os.path.basename(path) |
---|
2744 | values, weights = self.read_file(path) |
---|
2745 | |
---|
2746 | # If any of the two arrays is empty, notify the user that we won't |
---|
2747 | # proceed |
---|
2748 | if len(self.param_toFit) > 0: |
---|
2749 | if name in self.param_toFit: |
---|
2750 | self.param_toFit.remove(name) |
---|
2751 | |
---|
2752 | # Tell the user that we are about to apply the distribution |
---|
2753 | msg = "Applying loaded %s distribution: %s" % (name, path) |
---|
2754 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
2755 | self._set_array_disp_model(name=name, disp=disp, |
---|
2756 | values=values, weights=weights) |
---|
2757 | return basename |
---|
2758 | |
---|
2759 | def _set_array_disp_model(self, name=None, disp=None, |
---|
2760 | values=[], weights=[]): |
---|
2761 | """ |
---|
2762 | Set array dispersion model |
---|
2763 | |
---|
2764 | :param name: name of the parameter for the dispersion to be set |
---|
2765 | :param disp: the polydisperion object |
---|
2766 | """ |
---|
2767 | disp.set_weights(values, weights) |
---|
2768 | self._disp_obj_dict[name] = disp |
---|
2769 | self.model.set_dispersion(name.split('.')[0], disp) |
---|
2770 | self.state._disp_obj_dict[name] = disp |
---|
2771 | self.values[name] = values |
---|
2772 | self.weights[name] = weights |
---|
2773 | # Store the object to make it persist outside the |
---|
2774 | # scope of this method |
---|
2775 | #TODO: refactor model to clean this up? |
---|
2776 | self.state.values = {} |
---|
2777 | self.state.weights = {} |
---|
2778 | self.state.values = copy.deepcopy(self.values) |
---|
2779 | self.state.weights = copy.deepcopy(self.weights) |
---|
2780 | |
---|
2781 | # Set the new model as the dispersion object for the |
---|
2782 | #selected parameter |
---|
2783 | #self.model.set_dispersion(p, disp_model) |
---|
2784 | # Store a reference to the weights in the model object |
---|
2785 | #so that |
---|
2786 | # it's not lost when we use the model within another thread. |
---|
2787 | self.state.model = self.model.clone() |
---|
2788 | self.model._persistency_dict[name.split('.')[0]] = \ |
---|
2789 | [values, weights] |
---|
2790 | self.state.model._persistency_dict[name.split('.')[0]] = \ |
---|
2791 | [values, weights] |
---|
2792 | |
---|
2793 | def _del_array_values(self, name=None): |
---|
2794 | """ |
---|
2795 | Reset array dispersion |
---|
2796 | |
---|
2797 | :param name: name of the parameter for the dispersion to be set |
---|
2798 | """ |
---|
2799 | # Try to delete values and weight of the names array dic if exists |
---|
2800 | try: |
---|
2801 | del self.values[name] |
---|
2802 | del self.weights[name] |
---|
2803 | # delete all other dic |
---|
2804 | del self.state.values[name] |
---|
2805 | del self.state.weights[name] |
---|
2806 | del self.model._persistency_dict[name.split('.')[0]] |
---|
2807 | del self.state.model._persistency_dict[name.split('.')[0]] |
---|
2808 | except: |
---|
2809 | pass |
---|
2810 | |
---|
2811 | def _lay_out(self): |
---|
2812 | """ |
---|
2813 | returns self.Layout |
---|
2814 | |
---|
2815 | :Note: Mac seems to like this better when self. |
---|
2816 | Layout is called after fitting. |
---|
2817 | """ |
---|
2818 | self._sleep4sec() |
---|
2819 | self.Layout() |
---|
2820 | return |
---|
2821 | |
---|
2822 | def _sleep4sec(self): |
---|
2823 | """ |
---|
2824 | sleep for 1 sec only applied on Mac |
---|
2825 | Note: This 1sec helps for Mac not to crash on self. |
---|
2826 | Layout after self._draw_model |
---|
2827 | """ |
---|
2828 | if ON_MAC == True: |
---|
2829 | time.sleep(1) |
---|
2830 | |
---|
2831 | def _find_polyfunc_selection(self, disp_func=None): |
---|
2832 | """ |
---|
2833 | FInd Comboox selection from disp_func |
---|
2834 | |
---|
2835 | :param disp_function: dispersion distr. function |
---|
2836 | """ |
---|
2837 | # List of the poly_model name in the combobox |
---|
2838 | list = ["RectangleDispersion", "ArrayDispersion", |
---|
2839 | "LogNormalDispersion", "GaussianDispersion", |
---|
2840 | "SchulzDispersion"] |
---|
2841 | |
---|
2842 | # Find the selection |
---|
2843 | try: |
---|
2844 | selection = list.index(disp_func.__class__.__name__) |
---|
2845 | return selection |
---|
2846 | except: |
---|
2847 | return 3 |
---|
2848 | |
---|
2849 | def on_reset_clicked(self, event): |
---|
2850 | """ |
---|
2851 | On 'Reset' button for Q range clicked |
---|
2852 | """ |
---|
2853 | flag = True |
---|
2854 | ##For 3 different cases: Data2D, Data1D, and theory |
---|
2855 | if self.model == None: |
---|
2856 | msg = "Please select a model first..." |
---|
2857 | wx.MessageBox(msg, 'Info') |
---|
2858 | flag = False |
---|
2859 | return |
---|
2860 | |
---|
2861 | elif self.data.__class__.__name__ == "Data2D": |
---|
2862 | data_min = 0 |
---|
2863 | x = max(math.fabs(self.data.xmin), math.fabs(self.data.xmax)) |
---|
2864 | y = max(math.fabs(self.data.ymin), math.fabs(self.data.ymax)) |
---|
2865 | self.qmin_x = data_min |
---|
2866 | self.qmax_x = math.sqrt(x*x + y*y) |
---|
2867 | #self.data.mask = numpy.ones(len(self.data.data),dtype=bool) |
---|
2868 | # check smearing |
---|
2869 | if not self.disable_smearer.GetValue(): |
---|
2870 | ## set smearing value whether or |
---|
2871 | # not the data contain the smearing info |
---|
2872 | if self.pinhole_smearer.GetValue(): |
---|
2873 | flag = self.update_pinhole_smear() |
---|
2874 | else: |
---|
2875 | flag = True |
---|
2876 | |
---|
2877 | elif self.data == None: |
---|
2878 | self.qmin_x = _QMIN_DEFAULT |
---|
2879 | self.qmax_x = _QMAX_DEFAULT |
---|
2880 | self.num_points = _NPTS_DEFAULT |
---|
2881 | self.state.npts = self.num_points |
---|
2882 | |
---|
2883 | elif self.data.__class__.__name__ != "Data2D": |
---|
2884 | self.qmin_x = min(self.data.x) |
---|
2885 | self.qmax_x = max(self.data.x) |
---|
2886 | # check smearing |
---|
2887 | if not self.disable_smearer.GetValue(): |
---|
2888 | ## set smearing value whether or |
---|
2889 | # not the data contain the smearing info |
---|
2890 | if self.slit_smearer.GetValue(): |
---|
2891 | flag = self.update_slit_smear() |
---|
2892 | elif self.pinhole_smearer.GetValue(): |
---|
2893 | flag = self.update_pinhole_smear() |
---|
2894 | else: |
---|
2895 | flag = True |
---|
2896 | else: |
---|
2897 | flag = False |
---|
2898 | |
---|
2899 | if flag == False: |
---|
2900 | msg = "Cannot Plot :Must enter a number!!! " |
---|
2901 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
2902 | else: |
---|
2903 | # set relative text ctrs. |
---|
2904 | self.qmin.SetValue(str(self.qmin_x)) |
---|
2905 | self.qmax.SetValue(str(self.qmax_x)) |
---|
2906 | self.set_npts2fit() |
---|
2907 | # At this point, some button and variables satatus (disabled?) |
---|
2908 | # should be checked such as color that should be reset to |
---|
2909 | # white in case that it was pink. |
---|
2910 | self._onparamEnter_helper() |
---|
2911 | |
---|
2912 | self.save_current_state() |
---|
2913 | self.state.qmin = self.qmin_x |
---|
2914 | self.state.qmax = self.qmax_x |
---|
2915 | |
---|
2916 | #reset the q range values |
---|
2917 | self._reset_plotting_range(self.state) |
---|
2918 | self._draw_model() |
---|
2919 | |
---|
2920 | def get_images(self): |
---|
2921 | """ |
---|
2922 | Get the images of the plots corresponding this panel for report |
---|
2923 | |
---|
2924 | : return graphs: list of figures |
---|
2925 | : Need Move to guiframe |
---|
2926 | """ |
---|
2927 | # set list of graphs |
---|
2928 | graphs = [] |
---|
2929 | canvases = [] |
---|
2930 | res_item = None |
---|
2931 | # call gui_manager |
---|
2932 | gui_manager = self.parent.parent |
---|
2933 | # loops through the panels [dic] |
---|
2934 | for _, item2 in gui_manager.plot_panels.iteritems(): |
---|
2935 | data_title = self.data.group_id |
---|
2936 | # try to get all plots belonging to this control panel |
---|
2937 | try: |
---|
2938 | g_id = item2.group_id |
---|
2939 | if g_id == data_title or \ |
---|
2940 | str(g_id).count("res" + str(self.graph_id)) or \ |
---|
2941 | str(g_id).count(str(self.uid)) > 0: |
---|
2942 | if str(g_id).count("res" + str(self.graph_id)) > 0: |
---|
2943 | res_item = [item2.figure, item2.canvas] |
---|
2944 | else: |
---|
2945 | # append to the list |
---|
2946 | graphs.append(item2.figure) |
---|
2947 | canvases.append(item2.canvas) |
---|
2948 | except: |
---|
2949 | # Not for control panels |
---|
2950 | pass |
---|
2951 | # Make sure the resduals plot goes to the last |
---|
2952 | if res_item != None: |
---|
2953 | graphs.append(res_item[0]) |
---|
2954 | canvases.append(res_item[1]) |
---|
2955 | # return the list of graphs |
---|
2956 | return graphs, canvases |
---|
2957 | |
---|
2958 | def on_model_help_clicked(self, event): |
---|
2959 | """ |
---|
2960 | on 'More details' button |
---|
2961 | """ |
---|
2962 | from sans.perspectives.fitting.help_panel import HelpWindow |
---|
2963 | from sans.models import get_data_path |
---|
2964 | |
---|
2965 | # Get models help model_function path |
---|
2966 | path = get_data_path(media='media') |
---|
2967 | model_path = os.path.join(path, "model_functions.html") |
---|
2968 | if self.model == None: |
---|
2969 | name = 'FuncHelp' |
---|
2970 | else: |
---|
2971 | name = self.formfactorbox.GetValue() |
---|
2972 | frame = HelpWindow(None, -1, pageToOpen=model_path) |
---|
2973 | # If model name exists and model is not a custom model |
---|
2974 | #mod_cat = self.categorybox.GetStringSelection() |
---|
2975 | if frame.rhelp.HasAnchor(name): |
---|
2976 | frame.Show(True) |
---|
2977 | frame.rhelp.ScrollToAnchor(name) |
---|
2978 | else: |
---|
2979 | if self.model != None: |
---|
2980 | frame.Destroy() |
---|
2981 | msg = 'Model description:\n' |
---|
2982 | if str(self.model.description).rstrip().lstrip() == '': |
---|
2983 | msg += "Sorry, no information is available for this model." |
---|
2984 | else: |
---|
2985 | msg += self.model.description + '\n' |
---|
2986 | info = "Info" |
---|
2987 | wx.MessageBox(msg, info) |
---|
2988 | else: |
---|
2989 | frame.Show(True) |
---|
2990 | |
---|
2991 | def _on_mag_help(self, event): |
---|
2992 | """ |
---|
2993 | Magnetic angles help panel |
---|
2994 | """ |
---|
2995 | from sans.perspectives.fitting.help_panel import HelpWindow |
---|
2996 | # Get models help model_function path |
---|
2997 | #import sans.perspectives.fitting as fitmedia |
---|
2998 | from sans.models import get_data_path |
---|
2999 | |
---|
3000 | media = get_data_path(media='media') |
---|
3001 | path = os.path.join(media, "mag_pic.html") |
---|
3002 | name = "Polar/Magnetic Angles" |
---|
3003 | frame = HelpWindow(None, -1, |
---|
3004 | title=' Help: Polarization/Magnetization Angles', |
---|
3005 | pageToOpen=path, size=(865, 450)) |
---|
3006 | try: |
---|
3007 | frame.splitter.DetachWindow(frame.lpanel) |
---|
3008 | # Display only the right side one |
---|
3009 | frame.lpanel.Hide() |
---|
3010 | frame.Show(True) |
---|
3011 | except: |
---|
3012 | frame.Destroy() |
---|
3013 | msg = 'Display Error\n' |
---|
3014 | info = "Info" |
---|
3015 | wx.MessageBox(msg, info) |
---|
3016 | |
---|
3017 | def _on_mag_on(self, event): |
---|
3018 | """ |
---|
3019 | Magnetic Parameters ON/OFF |
---|
3020 | """ |
---|
3021 | button = event.GetEventObject() |
---|
3022 | |
---|
3023 | if button.GetLabel().count('ON') > 0: |
---|
3024 | self.magnetic_on = True |
---|
3025 | button.SetLabel("Magnetic OFF") |
---|
3026 | m_value = 1.0e-06 |
---|
3027 | for key in self.model.magnetic_params: |
---|
3028 | if key.count('M0') > 0: |
---|
3029 | self.model.setParam(key, m_value) |
---|
3030 | m_value += 0.5e-06 |
---|
3031 | else: |
---|
3032 | self.magnetic_on = False |
---|
3033 | button.SetLabel("Magnetic ON") |
---|
3034 | for key in self.model.magnetic_params: |
---|
3035 | if key.count('M0') > 0: |
---|
3036 | #reset mag value to zero fo safety |
---|
3037 | self.model.setParam(key, 0.0) |
---|
3038 | |
---|
3039 | self.Show(False) |
---|
3040 | self.set_model_param_sizer(self.model) |
---|
3041 | #self._set_sizer_dispersion() |
---|
3042 | self.state.magnetic_on = self.magnetic_on |
---|
3043 | self.SetupScrolling() |
---|
3044 | self.Show(True) |
---|
3045 | |
---|
3046 | def on_pd_help_clicked(self, event): |
---|
3047 | """ |
---|
3048 | Button event for PD help |
---|
3049 | """ |
---|
3050 | from help_panel import HelpWindow |
---|
3051 | import sans.models as models |
---|
3052 | |
---|
3053 | # Get models help model_function path |
---|
3054 | path = models.get_data_path(media='media') |
---|
3055 | pd_path = os.path.join(path, "pd_help.html") |
---|
3056 | |
---|
3057 | frame = HelpWindow(None, -1, pageToOpen=pd_path) |
---|
3058 | frame.Show(True) |
---|
3059 | |
---|
3060 | def on_left_down(self, event): |
---|
3061 | """ |
---|
3062 | Get key stroke event |
---|
3063 | """ |
---|
3064 | # Figuring out key combo: Cmd for copy, Alt for paste |
---|
3065 | if event.CmdDown() and event.ShiftDown(): |
---|
3066 | self.get_paste() |
---|
3067 | elif event.CmdDown(): |
---|
3068 | self.get_copy() |
---|
3069 | else: |
---|
3070 | event.Skip() |
---|
3071 | return |
---|
3072 | # make event free |
---|
3073 | event.Skip() |
---|
3074 | |
---|
3075 | def get_copy(self): |
---|
3076 | """ |
---|
3077 | Get copy params to clipboard |
---|
3078 | """ |
---|
3079 | content = self.get_copy_params() |
---|
3080 | flag = self.set_clipboard(content) |
---|
3081 | self._copy_info(flag) |
---|
3082 | return flag |
---|
3083 | |
---|
3084 | def get_copy_params(self): |
---|
3085 | """ |
---|
3086 | Get the string copies of the param names and values in the tap |
---|
3087 | """ |
---|
3088 | content = 'sansview_parameter_values:' |
---|
3089 | # Do it if params exist |
---|
3090 | if self.parameters != []: |
---|
3091 | |
---|
3092 | # go through the parameters |
---|
3093 | strings = self._get_copy_helper(self.parameters, |
---|
3094 | self.orientation_params) |
---|
3095 | content += strings |
---|
3096 | |
---|
3097 | # go through the fittables |
---|
3098 | strings = self._get_copy_helper(self.fittable_param, |
---|
3099 | self.orientation_params_disp) |
---|
3100 | content += strings |
---|
3101 | |
---|
3102 | # go through the fixed params |
---|
3103 | strings = self._get_copy_helper(self.fixed_param, |
---|
3104 | self.orientation_params_disp) |
---|
3105 | content += strings |
---|
3106 | |
---|
3107 | # go through the str params |
---|
3108 | strings = self._get_copy_helper(self.str_parameters, |
---|
3109 | self.orientation_params) |
---|
3110 | content += strings |
---|
3111 | return content |
---|
3112 | else: |
---|
3113 | return False |
---|
3114 | |
---|
3115 | def set_clipboard(self, content=None): |
---|
3116 | """ |
---|
3117 | Put the string to the clipboard |
---|
3118 | """ |
---|
3119 | if not content: |
---|
3120 | return False |
---|
3121 | if wx.TheClipboard.Open(): |
---|
3122 | wx.TheClipboard.SetData(wx.TextDataObject(str(content))) |
---|
3123 | wx.TheClipboard.Close() |
---|
3124 | return True |
---|
3125 | return None |
---|
3126 | |
---|
3127 | def _get_copy_helper(self, param, orient_param): |
---|
3128 | """ |
---|
3129 | Helping get value and name of the params |
---|
3130 | |
---|
3131 | : param param: parameters |
---|
3132 | : param orient_param = oritational params |
---|
3133 | : return content: strings [list] [name,value:....] |
---|
3134 | """ |
---|
3135 | content = '' |
---|
3136 | # go through the str params |
---|
3137 | for item in param: |
---|
3138 | # copy only the params shown |
---|
3139 | if not item[2].IsShown(): |
---|
3140 | continue |
---|
3141 | disfunc = '' |
---|
3142 | try: |
---|
3143 | if item[7].__class__.__name__ == 'ComboBox': |
---|
3144 | disfunc = str(item[7].GetValue()) |
---|
3145 | except: |
---|
3146 | pass |
---|
3147 | |
---|
3148 | # 2D |
---|
3149 | if self.data.__class__.__name__ == "Data2D": |
---|
3150 | try: |
---|
3151 | check = item[0].GetValue() |
---|
3152 | except: |
---|
3153 | check = None |
---|
3154 | name = item[1] |
---|
3155 | value = item[2].GetValue() |
---|
3156 | # 1D |
---|
3157 | else: |
---|
3158 | ## for 1D all parameters except orientation |
---|
3159 | if not item[1] in orient_param: |
---|
3160 | try: |
---|
3161 | check = item[0].GetValue() |
---|
3162 | except: |
---|
3163 | check = None |
---|
3164 | name = item[1] |
---|
3165 | value = item[2].GetValue() |
---|
3166 | |
---|
3167 | # add to the content |
---|
3168 | if disfunc != '': |
---|
3169 | |
---|
3170 | disfunc = ',' + disfunc |
---|
3171 | # Need to support array func for copy/paste |
---|
3172 | try: |
---|
3173 | if disfunc.count('array') > 0: |
---|
3174 | disfunc += ',' |
---|
3175 | for val in self.values[name]: |
---|
3176 | disfunc += ' ' + str(val) |
---|
3177 | disfunc += ',' |
---|
3178 | for weight in self.weights[name]: |
---|
3179 | disfunc += ' ' + str(weight) |
---|
3180 | except: |
---|
3181 | pass |
---|
3182 | content += name + ',' + str(check) + ',' + value + disfunc + ':' |
---|
3183 | |
---|
3184 | return content |
---|
3185 | |
---|
3186 | def get_clipboard(self): |
---|
3187 | """ |
---|
3188 | Get strings in the clipboard |
---|
3189 | """ |
---|
3190 | text = "" |
---|
3191 | # Get text from the clip board |
---|
3192 | if wx.TheClipboard.Open(): |
---|
3193 | if wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)): |
---|
3194 | data = wx.TextDataObject() |
---|
3195 | # get wx dataobject |
---|
3196 | success = wx.TheClipboard.GetData(data) |
---|
3197 | # get text |
---|
3198 | if success: |
---|
3199 | text = data.GetText() |
---|
3200 | else: |
---|
3201 | text = '' |
---|
3202 | # close clipboard |
---|
3203 | wx.TheClipboard.Close() |
---|
3204 | return text |
---|
3205 | |
---|
3206 | def get_paste(self): |
---|
3207 | """ |
---|
3208 | Paste params from the clipboard |
---|
3209 | """ |
---|
3210 | text = self.get_clipboard() |
---|
3211 | flag = self.get_paste_params(text) |
---|
3212 | self._copy_info(flag) |
---|
3213 | return flag |
---|
3214 | |
---|
3215 | def get_paste_params(self, text=''): |
---|
3216 | """ |
---|
3217 | Get the string copies of the param names and values in the tap |
---|
3218 | """ |
---|
3219 | context = {} |
---|
3220 | # put the text into dictionary |
---|
3221 | lines = text.split(':') |
---|
3222 | if lines[0] != 'sansview_parameter_values': |
---|
3223 | self._copy_info(False) |
---|
3224 | return False |
---|
3225 | for line in lines[1:-1]: |
---|
3226 | if len(line) != 0: |
---|
3227 | item = line.split(',') |
---|
3228 | check = item[1] |
---|
3229 | name = item[0] |
---|
3230 | value = item[2] |
---|
3231 | # Transfer the text to content[dictionary] |
---|
3232 | context[name] = [check, value] |
---|
3233 | # ToDo: PlugIn this poly disp function for pasting |
---|
3234 | try: |
---|
3235 | poly_func = item[3] |
---|
3236 | context[name].append(poly_func) |
---|
3237 | try: |
---|
3238 | # take the vals and weights for array |
---|
3239 | array_values = item[4].split(' ') |
---|
3240 | array_weights = item[5].split(' ') |
---|
3241 | val = [float(a_val) for a_val in array_values[1:]] |
---|
3242 | weit = [float(a_weit) for a_weit in array_weights[1:]] |
---|
3243 | |
---|
3244 | context[name].append(val) |
---|
3245 | context[name].append(weit) |
---|
3246 | except: |
---|
3247 | raise |
---|
3248 | except: |
---|
3249 | poly_func = '' |
---|
3250 | context[name].append(poly_func) |
---|
3251 | |
---|
3252 | # Do it if params exist |
---|
3253 | if self.parameters != []: |
---|
3254 | # go through the parameters |
---|
3255 | self._get_paste_helper(self.parameters, |
---|
3256 | self.orientation_params, context) |
---|
3257 | |
---|
3258 | # go through the fittables |
---|
3259 | self._get_paste_helper(self.fittable_param, |
---|
3260 | self.orientation_params_disp, |
---|
3261 | context) |
---|
3262 | |
---|
3263 | # go through the fixed params |
---|
3264 | self._get_paste_helper(self.fixed_param, |
---|
3265 | self.orientation_params_disp, context) |
---|
3266 | |
---|
3267 | # go through the str params |
---|
3268 | self._get_paste_helper(self.str_parameters, |
---|
3269 | self.orientation_params, context) |
---|
3270 | |
---|
3271 | return True |
---|
3272 | return None |
---|
3273 | |
---|
3274 | def _get_paste_helper(self, param, orient_param, content): |
---|
3275 | """ |
---|
3276 | Helping set values of the params |
---|
3277 | |
---|
3278 | : param param: parameters |
---|
3279 | : param orient_param: oritational params |
---|
3280 | : param content: dictionary [ name, value: name1.value1,...] |
---|
3281 | """ |
---|
3282 | # go through the str params |
---|
3283 | for item in param: |
---|
3284 | # 2D |
---|
3285 | if self.data.__class__.__name__ == "Data2D": |
---|
3286 | name = item[1] |
---|
3287 | if name in content.keys(): |
---|
3288 | check = content[name][0] |
---|
3289 | pd = content[name][1] |
---|
3290 | if name.count('.') > 0: |
---|
3291 | try: |
---|
3292 | float(pd) |
---|
3293 | except: |
---|
3294 | #continue |
---|
3295 | if not pd and pd != '': |
---|
3296 | continue |
---|
3297 | item[2].SetValue(str(pd)) |
---|
3298 | if item in self.fixed_param and pd == '': |
---|
3299 | # Only array func has pd == '' case. |
---|
3300 | item[2].Enable(False) |
---|
3301 | if item[2].__class__.__name__ == "ComboBox": |
---|
3302 | if content[name][1] in self.model.fun_list: |
---|
3303 | fun_val = self.model.fun_list[content[name][1]] |
---|
3304 | self.model.setParam(name, fun_val) |
---|
3305 | |
---|
3306 | value = content[name][1:] |
---|
3307 | self._paste_poly_help(item, value) |
---|
3308 | if check == 'True': |
---|
3309 | is_true = True |
---|
3310 | elif check == 'False': |
---|
3311 | is_true = False |
---|
3312 | else: |
---|
3313 | is_true = None |
---|
3314 | if is_true != None: |
---|
3315 | item[0].SetValue(is_true) |
---|
3316 | # 1D |
---|
3317 | else: |
---|
3318 | ## for 1D all parameters except orientation |
---|
3319 | if not item[1] in orient_param: |
---|
3320 | name = item[1] |
---|
3321 | if name in content.keys(): |
---|
3322 | check = content[name][0] |
---|
3323 | # Avoid changing combox content |
---|
3324 | value = content[name][1:] |
---|
3325 | pd = value[0] |
---|
3326 | if name.count('.') > 0: |
---|
3327 | try: |
---|
3328 | pd = float(pd) |
---|
3329 | except: |
---|
3330 | #continue |
---|
3331 | if not pd and pd != '': |
---|
3332 | continue |
---|
3333 | item[2].SetValue(str(pd)) |
---|
3334 | if item in self.fixed_param and pd == '': |
---|
3335 | # Only array func has pd == '' case. |
---|
3336 | item[2].Enable(False) |
---|
3337 | if item[2].__class__.__name__ == "ComboBox": |
---|
3338 | if value[0] in self.model.fun_list: |
---|
3339 | fun_val = self.model.fun_list[value[0]] |
---|
3340 | self.model.setParam(name, fun_val) |
---|
3341 | # save state |
---|
3342 | self._paste_poly_help(item, value) |
---|
3343 | if check == 'True': |
---|
3344 | is_true = True |
---|
3345 | elif check == 'False': |
---|
3346 | is_true = False |
---|
3347 | else: |
---|
3348 | is_true = None |
---|
3349 | if is_true != None: |
---|
3350 | item[0].SetValue(is_true) |
---|
3351 | |
---|
3352 | def _paste_poly_help(self, item, value): |
---|
3353 | """ |
---|
3354 | Helps get paste for poly function |
---|
3355 | |
---|
3356 | :param item: Gui param items |
---|
3357 | :param value: the values for parameter ctrols |
---|
3358 | """ |
---|
3359 | is_array = False |
---|
3360 | if len(value[1]) > 0: |
---|
3361 | # Only for dispersion func.s |
---|
3362 | try: |
---|
3363 | item[7].SetValue(value[1]) |
---|
3364 | selection = item[7].GetCurrentSelection() |
---|
3365 | name = item[7].Name |
---|
3366 | param_name = name.split('.')[0] |
---|
3367 | dispersity = item[7].GetClientData(selection) |
---|
3368 | disp_model = dispersity() |
---|
3369 | # Only for array disp |
---|
3370 | try: |
---|
3371 | pd_vals = numpy.array(value[2]) |
---|
3372 | pd_weights = numpy.array(value[3]) |
---|
3373 | if len(pd_vals) > 0 and len(pd_vals) > 0: |
---|
3374 | if len(pd_vals) == len(pd_weights): |
---|
3375 | self._set_disp_array_cb(item=item) |
---|
3376 | self._set_array_disp_model(name=name, |
---|
3377 | disp=disp_model, |
---|
3378 | values=pd_vals, |
---|
3379 | weights=pd_weights) |
---|
3380 | is_array = True |
---|
3381 | except: |
---|
3382 | pass |
---|
3383 | if not is_array: |
---|
3384 | self._disp_obj_dict[name] = disp_model |
---|
3385 | self.model.set_dispersion(name, |
---|
3386 | disp_model) |
---|
3387 | self.state._disp_obj_dict[name] = \ |
---|
3388 | disp_model |
---|
3389 | self.model.set_dispersion(param_name, disp_model) |
---|
3390 | self.state.values = self.values |
---|
3391 | self.state.weights = self.weights |
---|
3392 | self.model._persistency_dict[param_name] = \ |
---|
3393 | [self.state.values, |
---|
3394 | self.state.weights] |
---|
3395 | |
---|
3396 | except: |
---|
3397 | print "Error in BasePage._paste_poly_help: %s" % sys.exc_value |
---|
3398 | |
---|
3399 | def _set_disp_array_cb(self, item): |
---|
3400 | """ |
---|
3401 | Set cb for array disp |
---|
3402 | """ |
---|
3403 | item[0].SetValue(False) |
---|
3404 | item[0].Enable(False) |
---|
3405 | item[2].Enable(False) |
---|
3406 | item[3].Show(False) |
---|
3407 | item[4].Show(False) |
---|
3408 | item[5].SetValue('') |
---|
3409 | item[5].Enable(False) |
---|
3410 | item[6].SetValue('') |
---|
3411 | item[6].Enable(False) |
---|
3412 | |
---|
3413 | def update_pinhole_smear(self): |
---|
3414 | """ |
---|
3415 | Method to be called by sub-classes |
---|
3416 | Moveit; This method doesn't belong here |
---|
3417 | """ |
---|
3418 | print "BasicPage.update_pinhole_smear was called: skipping" |
---|
3419 | return |
---|
3420 | |
---|
3421 | |
---|
3422 | |
---|
3423 | |
---|
3424 | def _read_category_info(self): |
---|
3425 | """ |
---|
3426 | Reads the categories in from file |
---|
3427 | """ |
---|
3428 | |
---|
3429 | # # ILL mod starts here - July 2012 kieranrcampbell@gmail.com |
---|
3430 | self.master_category_dict = defaultdict(list) |
---|
3431 | self.by_model_dict = defaultdict(list) |
---|
3432 | self.model_enabled_dict = defaultdict(bool) |
---|
3433 | |
---|
3434 | try: |
---|
3435 | categorization_file = CategoryInstaller.get_user_file() |
---|
3436 | if not os.path.isfile(categorization_file): |
---|
3437 | categorization_file = CategoryInstaller.get_default_file() |
---|
3438 | cat_file = open(categorization_file, 'rb') |
---|
3439 | |
---|
3440 | self.master_category_dict = pickle.load(cat_file) |
---|
3441 | self._regenerate_model_dict() |
---|
3442 | cat_file.close() |
---|
3443 | |
---|
3444 | except IOError: |
---|
3445 | raise |
---|
3446 | print 'Problem reading in category file.' |
---|
3447 | print 'We even looked for it, made sure it was there.' |
---|
3448 | print 'An existential crisis if there ever was one.' |
---|
3449 | |
---|
3450 | def _regenerate_model_dict(self): |
---|
3451 | """ |
---|
3452 | regenerates self.by_model_dict which has each model name as the |
---|
3453 | key and the list of categories belonging to that model |
---|
3454 | along with the enabled mapping |
---|
3455 | """ |
---|
3456 | |
---|
3457 | self.by_model_dict = defaultdict(list) |
---|
3458 | for category in self.master_category_dict: |
---|
3459 | for (model, enabled) in self.master_category_dict[category]: |
---|
3460 | self.by_model_dict[model].append(category) |
---|
3461 | self.model_enabled_dict[model] = enabled |
---|
3462 | |
---|
3463 | def _populate_listbox(self): |
---|
3464 | """ |
---|
3465 | fills out the category list box |
---|
3466 | """ |
---|
3467 | uncat_str = 'Customized Models' |
---|
3468 | self._read_category_info() |
---|
3469 | |
---|
3470 | self.categorybox.Clear() |
---|
3471 | cat_list = sorted(self.master_category_dict.keys()) |
---|
3472 | if not uncat_str in cat_list: |
---|
3473 | cat_list.append(uncat_str) |
---|
3474 | |
---|
3475 | for category in cat_list: |
---|
3476 | if category != '': |
---|
3477 | self.categorybox.Append(category) |
---|
3478 | |
---|
3479 | if self.categorybox.GetSelection() == wx.NOT_FOUND: |
---|
3480 | self.categorybox.SetSelection(0) |
---|
3481 | else: |
---|
3482 | self.categorybox.SetSelection( \ |
---|
3483 | self.categorybox.GetSelection()) |
---|
3484 | |
---|
3485 | #self._on_change_cat(None) |
---|
3486 | |
---|
3487 | |
---|
3488 | def _on_change_cat(self, event): |
---|
3489 | """ |
---|
3490 | Callback for category change action |
---|
3491 | """ |
---|
3492 | self.model_name = None |
---|
3493 | category = self.categorybox.GetStringSelection() |
---|
3494 | if category == None: |
---|
3495 | return |
---|
3496 | self.model_box.Clear() |
---|
3497 | |
---|
3498 | if category == 'Customized Models': |
---|
3499 | for model in self.model_list_box[category]: |
---|
3500 | str_m = str(model).split(".")[0] |
---|
3501 | self.model_box.Append(str_m) |
---|
3502 | |
---|
3503 | else: |
---|
3504 | for (model,enabled) in sorted(self.master_category_dict[category], |
---|
3505 | key = lambda name: name[0]): |
---|
3506 | if(enabled): |
---|
3507 | self.model_box.Append(model) |
---|
3508 | |
---|
3509 | |
---|
3510 | |
---|
3511 | |
---|
3512 | def _fill_model_sizer(self, sizer): |
---|
3513 | """ |
---|
3514 | fill sizer containing model info |
---|
3515 | """ |
---|
3516 | ##Add model function Details button in fitpanel. |
---|
3517 | ##The following 3 lines are for Mac. Let JHC know before modifying... |
---|
3518 | title = "Model" |
---|
3519 | self.formfactorbox = None |
---|
3520 | self.multifactorbox = None |
---|
3521 | self.mbox_description = wx.StaticBox(self, -1, str(title)) |
---|
3522 | boxsizer1 = wx.StaticBoxSizer(self.mbox_description, wx.VERTICAL) |
---|
3523 | sizer_cat = wx.BoxSizer(wx.HORIZONTAL) |
---|
3524 | self.mbox_description.SetForegroundColour(wx.RED) |
---|
3525 | id = wx.NewId() |
---|
3526 | self.model_help = wx.Button(self, id, 'Details', size=(80, 23)) |
---|
3527 | self.model_help.Bind(wx.EVT_BUTTON, self.on_model_help_clicked, id=id) |
---|
3528 | self.model_help.SetToolTipString("Model Function Help") |
---|
3529 | id = wx.NewId() |
---|
3530 | self.model_view = wx.Button(self, id, "Show 2D", size=(80, 23)) |
---|
3531 | self.model_view.Bind(wx.EVT_BUTTON, self._onModel2D, id=id) |
---|
3532 | hint = "toggle view of model from 1D to 2D or 2D to 1D" |
---|
3533 | self.model_view.SetToolTipString(hint) |
---|
3534 | |
---|
3535 | cat_set_box = wx.StaticBox(self, -1, 'Category') |
---|
3536 | sizer_cat_box = wx.StaticBoxSizer(cat_set_box, wx.HORIZONTAL) |
---|
3537 | sizer_cat_box.SetMinSize((200, 50)) |
---|
3538 | self.categorybox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
3539 | self.categorybox.SetToolTip( wx.ToolTip("Select a Category/Type") ) |
---|
3540 | self._populate_listbox() |
---|
3541 | wx.EVT_COMBOBOX(self.categorybox, -1, self._show_combox) |
---|
3542 | #self.shape_rbutton = wx.RadioButton(self, -1, 'Shapes', |
---|
3543 | # style=wx.RB_GROUP) |
---|
3544 | #self.shape_indep_rbutton = wx.RadioButton(self, -1, |
---|
3545 | # "Shape-Independent") |
---|
3546 | #self.struct_rbutton = wx.RadioButton(self, -1, "Structure Factor ") |
---|
3547 | #self.plugin_rbutton = wx.RadioButton(self, -1, "Uncategorized") |
---|
3548 | |
---|
3549 | #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
3550 | # id=self.shape_rbutton.GetId()) |
---|
3551 | #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
3552 | # id=self.shape_indep_rbutton.GetId()) |
---|
3553 | #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
3554 | # id=self.struct_rbutton.GetId()) |
---|
3555 | #self.Bind(wx.EVT_RADIOBUTTON, self._show_combox, |
---|
3556 | # id=self.plugin_rbutton.GetId()) |
---|
3557 | #MAC needs SetValue |
---|
3558 | |
---|
3559 | show_cat_button = wx.Button(self, -1, "Modify") |
---|
3560 | cat_tip = "Modify model categories \n" |
---|
3561 | cat_tip += "(also accessible from the menu bar)." |
---|
3562 | show_cat_button.SetToolTip( wx.ToolTip(cat_tip) ) |
---|
3563 | show_cat_button.Bind(wx.EVT_BUTTON, self._on_modify_cat) |
---|
3564 | sizer_cat_box.Add(self.categorybox, 1, wx.RIGHT, 3) |
---|
3565 | sizer_cat_box.Add((10,10)) |
---|
3566 | sizer_cat_box.Add(show_cat_button) |
---|
3567 | #self.shape_rbutton.SetValue(True) |
---|
3568 | |
---|
3569 | sizer_radiobutton = wx.GridSizer(2, 2, 5, 5) |
---|
3570 | |
---|
3571 | #sizer_radiobutton.Add(self.shape_rbutton) |
---|
3572 | #sizer_radiobutton.Add(self.shape_indep_rbutton) |
---|
3573 | sizer_radiobutton.Add((5,5)) |
---|
3574 | sizer_radiobutton.Add(self.model_view, 1, wx.RIGHT, 15) |
---|
3575 | #sizer_radiobutton.Add(self.plugin_rbutton) |
---|
3576 | #sizer_radiobutton.Add(self.struct_rbutton) |
---|
3577 | sizer_radiobutton.Add((5,5)) |
---|
3578 | sizer_radiobutton.Add(self.model_help, 1, wx.RIGHT, 15) |
---|
3579 | sizer_cat.Add(sizer_cat_box, 1, wx.LEFT, 2.5) |
---|
3580 | sizer_cat.Add(sizer_radiobutton) |
---|
3581 | sizer_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
3582 | mutifactor_selection = wx.BoxSizer(wx.HORIZONTAL) |
---|
3583 | |
---|
3584 | self.text1 = wx.StaticText(self, -1, "") |
---|
3585 | self.text2 = wx.StaticText(self, -1, "P(Q)*S(Q)") |
---|
3586 | self.mutifactor_text = wx.StaticText(self, -1, "No. of Shells: ") |
---|
3587 | self.mutifactor_text1 = wx.StaticText(self, -1, "") |
---|
3588 | self.show_sld_button = wx.Button(self, -1, "Show SLD Profile") |
---|
3589 | self.show_sld_button.Bind(wx.EVT_BUTTON, self._on_show_sld) |
---|
3590 | |
---|
3591 | self.formfactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
3592 | self.formfactorbox.SetToolTip( wx.ToolTip("Select a Model") ) |
---|
3593 | if self.model != None: |
---|
3594 | self.formfactorbox.SetValue(self.model.name) |
---|
3595 | self.structurebox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
3596 | self.multifactorbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
3597 | self.initialize_combox() |
---|
3598 | wx.EVT_COMBOBOX(self.formfactorbox, -1, self._on_select_model) |
---|
3599 | |
---|
3600 | wx.EVT_COMBOBOX(self.structurebox, -1, self._on_select_model) |
---|
3601 | wx.EVT_COMBOBOX(self.multifactorbox, -1, self._on_select_model) |
---|
3602 | ## check model type to show sizer |
---|
3603 | if self.model != None: |
---|
3604 | print "_set_model_sizer_selection: disabled." |
---|
3605 | #self._set_model_sizer_selection(self.model) |
---|
3606 | |
---|
3607 | sizer_selection.Add(self.text1) |
---|
3608 | sizer_selection.Add((10, 5)) |
---|
3609 | sizer_selection.Add(self.formfactorbox) |
---|
3610 | sizer_selection.Add((5, 5)) |
---|
3611 | sizer_selection.Add(self.text2) |
---|
3612 | sizer_selection.Add((5, 5)) |
---|
3613 | sizer_selection.Add(self.structurebox) |
---|
3614 | |
---|
3615 | mutifactor_selection.Add((13, 5)) |
---|
3616 | mutifactor_selection.Add(self.mutifactor_text) |
---|
3617 | mutifactor_selection.Add(self.multifactorbox) |
---|
3618 | mutifactor_selection.Add((5, 5)) |
---|
3619 | mutifactor_selection.Add(self.mutifactor_text1) |
---|
3620 | mutifactor_selection.Add((10, 5)) |
---|
3621 | mutifactor_selection.Add(self.show_sld_button) |
---|
3622 | |
---|
3623 | boxsizer1.Add(sizer_cat) |
---|
3624 | boxsizer1.Add((10, 10)) |
---|
3625 | boxsizer1.Add(sizer_selection) |
---|
3626 | boxsizer1.Add((10, 10)) |
---|
3627 | boxsizer1.Add(mutifactor_selection) |
---|
3628 | |
---|
3629 | self._set_multfactor_combobox() |
---|
3630 | self.multifactorbox.SetSelection(1) |
---|
3631 | self.show_sld_button.Hide() |
---|
3632 | sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) |
---|
3633 | sizer.Layout() |
---|
3634 | |
---|
3635 | def on_smear_helper(self, update=False): |
---|
3636 | """ |
---|
3637 | Help for onSmear if implemented |
---|
3638 | |
---|
3639 | :param update: force or not to update |
---|
3640 | """ |
---|
3641 | def reset_page(self, state, first=False): |
---|
3642 | """ |
---|
3643 | reset the state if implemented |
---|
3644 | """ |
---|
3645 | def onSmear(self, event): |
---|
3646 | """ |
---|
3647 | Create a smear object if implemented |
---|
3648 | """ |
---|
3649 | def onPinholeSmear(self, event): |
---|
3650 | """ |
---|
3651 | Create a custom pinhole smear object if implemented |
---|
3652 | """ |
---|
3653 | def onSlitSmear(self, event): |
---|
3654 | """ |
---|
3655 | Create a custom slit smear object if implemented |
---|
3656 | """ |
---|
3657 | def update_slit_smear(self): |
---|
3658 | """ |
---|
3659 | called by kill_focus on pinhole TextCntrl |
---|
3660 | to update the changes if implemented |
---|
3661 | """ |
---|
3662 | def select_param(self, event): |
---|
3663 | """ |
---|
3664 | Select TextCtrl checked if implemented |
---|
3665 | """ |
---|
3666 | def set_data(self, data=None): |
---|
3667 | """ |
---|
3668 | Sets data if implemented |
---|
3669 | """ |
---|
3670 | def _is_2D(self): |
---|
3671 | """ |
---|
3672 | Check if data_name is Data2D if implemented |
---|
3673 | """ |
---|
3674 | def _on_select_model(self, event=None): |
---|
3675 | """ |
---|
3676 | call back for model selection if implemented |
---|
3677 | """ |
---|
3678 | def select_all_param(self, event): |
---|
3679 | """ |
---|
3680 | set to true or false all checkBox if implemented |
---|
3681 | """ |
---|
3682 | def get_weight_flag(self): |
---|
3683 | """ |
---|
3684 | Get flag corresponding to a given weighting dI data if implemented |
---|
3685 | """ |
---|
3686 | def _set_sizer_dispersion(self): |
---|
3687 | """ |
---|
3688 | draw sizer for dispersity if implemented |
---|
3689 | """ |
---|
3690 | def get_all_checked_params(self): |
---|
3691 | """ |
---|
3692 | Found all parameters current check and add them to list of parameters |
---|
3693 | to fit if implemented |
---|
3694 | """ |
---|
3695 | def set_npts2fit(self): |
---|
3696 | """ |
---|
3697 | setValue Npts for fitting if implemented |
---|
3698 | """ |
---|
3699 | def _onModel2D(self, event): |
---|
3700 | """ |
---|
3701 | toggle view of model from 1D to 2D or 2D from 1D if implemented |
---|
3702 | """ |
---|