1 | """ |
---|
2 | Generic Scattering panel. |
---|
3 | This module relies on guiframe manager. |
---|
4 | """ |
---|
5 | |
---|
6 | import wx |
---|
7 | import sys |
---|
8 | import os |
---|
9 | import numpy |
---|
10 | #import math |
---|
11 | import wx.aui as aui |
---|
12 | #import wx.lib.agw.aui as aui |
---|
13 | import logging |
---|
14 | import time |
---|
15 | |
---|
16 | import matplotlib |
---|
17 | matplotlib.interactive(False) |
---|
18 | #Use the WxAgg back end. The Wx one takes too long to render |
---|
19 | matplotlib.use('WXAgg') |
---|
20 | |
---|
21 | #from sas.guiframe.gui_manager import MDIFrame |
---|
22 | from sas.data_util.calcthread import CalcThread |
---|
23 | from sas.guiframe.local_perspectives.plotting.SimplePlot import PlotFrame |
---|
24 | from sas.guiframe.dataFitting import Data2D |
---|
25 | from sas.guiframe.dataFitting import Data1D |
---|
26 | from sas.dataloader.data_info import Detector |
---|
27 | from sas.dataloader.data_info import Source |
---|
28 | from sas.guiframe.panel_base import PanelBase |
---|
29 | from sas.guiframe.utils import format_number |
---|
30 | from sas.guiframe.events import StatusEvent |
---|
31 | from sas.calculator import sas_gen |
---|
32 | from sas.perspectives.calculator.calculator_widgets import OutputTextCtrl |
---|
33 | from sas.perspectives.calculator.calculator_widgets import InputTextCtrl |
---|
34 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
35 | from sas.perspectives.calculator.load_thread import GenReader |
---|
36 | from sas.plottools.arrow3d import Arrow3D |
---|
37 | from sas.perspectives.calculator import calculator_widgets as widget |
---|
38 | from sas.guiframe.events import NewPlotEvent |
---|
39 | from sas.guiframe.documentation_window import DocumentationWindow |
---|
40 | |
---|
41 | _BOX_WIDTH = 76 |
---|
42 | #Slit length panel size |
---|
43 | if sys.platform.count("win32") > 0: |
---|
44 | PANEL_TOP = 0 |
---|
45 | PANEL_WIDTH = 570 |
---|
46 | PANEL_HEIGHT = 370 |
---|
47 | FONT_VARIANT = 0 |
---|
48 | else: |
---|
49 | PANEL_TOP = 60 |
---|
50 | PANEL_WIDTH = 620 |
---|
51 | PANEL_HEIGHT = 370 |
---|
52 | FONT_VARIANT = 1 |
---|
53 | _QMAX_DEFAULT = 0.3 |
---|
54 | _NPTS_DEFAULT = 50 |
---|
55 | _Q1D_MIN = 0.001 |
---|
56 | |
---|
57 | def add_icon(parent, frame): |
---|
58 | """ |
---|
59 | Add icon in the frame |
---|
60 | """ |
---|
61 | if parent != None: |
---|
62 | if hasattr(frame, "IsIconized"): |
---|
63 | if not frame.IsIconized(): |
---|
64 | try: |
---|
65 | icon = parent.GetIcon() |
---|
66 | frame.SetIcon(icon) |
---|
67 | except: |
---|
68 | pass |
---|
69 | |
---|
70 | def _set_error(panel, item, show_msg=False): |
---|
71 | """ |
---|
72 | Set_error dialog |
---|
73 | """ |
---|
74 | if item != None: |
---|
75 | item.SetBackgroundColour("pink") |
---|
76 | item.Refresh() |
---|
77 | if show_msg: |
---|
78 | msg = "Error: wrong (or out of range) value entered." |
---|
79 | if panel.parent.parent != None: |
---|
80 | wx.PostEvent(panel.parent.parent, |
---|
81 | StatusEvent(status=msg, info='Error')) |
---|
82 | panel.SetFocus() |
---|
83 | return False |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | class CalcGen(CalcThread): |
---|
88 | """ |
---|
89 | Computation |
---|
90 | """ |
---|
91 | def __init__(self, |
---|
92 | id= -1, |
---|
93 | input=None, |
---|
94 | completefn=None, |
---|
95 | updatefn=None, |
---|
96 | #elapsed = 0, |
---|
97 | yieldtime=0.01, |
---|
98 | worktime=0.01): |
---|
99 | """ |
---|
100 | """ |
---|
101 | CalcThread.__init__(self, completefn, |
---|
102 | updatefn, |
---|
103 | yieldtime, |
---|
104 | worktime) |
---|
105 | self.starttime = 0 |
---|
106 | self.id = id |
---|
107 | self.input = input |
---|
108 | self.update_fn = updatefn |
---|
109 | |
---|
110 | def compute(self): |
---|
111 | """ |
---|
112 | excuting computation |
---|
113 | """ |
---|
114 | #elapsed = time.time() - self.starttime |
---|
115 | self.starttime = time.time() |
---|
116 | self.complete(input=self.input, update=self.update_fn) |
---|
117 | |
---|
118 | class SasGenPanel(ScrolledPanel, PanelBase): |
---|
119 | """ |
---|
120 | Provides the sas gen calculator GUI. |
---|
121 | """ |
---|
122 | ## Internal nickname for the window, used by the AUI manager |
---|
123 | window_name = "Generic SAS Calculator" |
---|
124 | ## Name to appear on the window title bar |
---|
125 | window_caption = "Generic SAS " |
---|
126 | |
---|
127 | def __init__(self, parent, *args, **kwds): |
---|
128 | ScrolledPanel.__init__(self, parent, style=wx.RAISED_BORDER, |
---|
129 | *args, **kwds) |
---|
130 | #kwds['style'] = wx.SUNKEN_BORDER |
---|
131 | PanelBase.__init__(self) |
---|
132 | #Font size |
---|
133 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
134 | self.SetupScrolling() |
---|
135 | #thread to read data |
---|
136 | self.reader = None |
---|
137 | self.ext = None |
---|
138 | self.id = 'GenSAS' |
---|
139 | self.file_name = '' |
---|
140 | self.time_text = None |
---|
141 | self.orient_combo = None |
---|
142 | self.omfreader = sas_gen.OMFReader() |
---|
143 | self.sldreader = sas_gen.SLDReader() |
---|
144 | self.pdbreader = sas_gen.PDBReader() |
---|
145 | self.model = sas_gen.GenSAS() |
---|
146 | self.param_dic = self.model.params |
---|
147 | self.parameters = [] |
---|
148 | self.data = None |
---|
149 | self.scale2d = None |
---|
150 | self.is_avg = False |
---|
151 | self.plot_frame = None |
---|
152 | self.qmax_x = _QMAX_DEFAULT |
---|
153 | self.npts_x = _NPTS_DEFAULT |
---|
154 | self.sld_data = None |
---|
155 | self.graph_num = 1 |
---|
156 | self.default_shape = 'rectangular' |
---|
157 | # Object that receive status event |
---|
158 | self.parent = parent |
---|
159 | self._do_layout() |
---|
160 | self._create_default_sld_data() |
---|
161 | self._create_default_2d_data() |
---|
162 | wx.CallAfter(self._set_sld_data_helper) |
---|
163 | |
---|
164 | def _define_structure(self): |
---|
165 | """ |
---|
166 | Define the main sizers building to build this application. |
---|
167 | """ |
---|
168 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
169 | self.box_source = wx.StaticBox(self, -1, str("SLD Data File")) |
---|
170 | self.box_parameters = wx.StaticBox(self, -1, str("Input Parameters")) |
---|
171 | self.box_qrange = wx.StaticBox(self, -1, str("Q Range")) |
---|
172 | self.boxsizer_source = wx.StaticBoxSizer(self.box_source, |
---|
173 | wx.VERTICAL) |
---|
174 | self.boxsizer_parameters = wx.StaticBoxSizer(self.box_parameters, |
---|
175 | wx.VERTICAL) |
---|
176 | self.boxsizer_qrange = wx.StaticBoxSizer(self.box_qrange, |
---|
177 | wx.VERTICAL) |
---|
178 | self.data_name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
179 | self.param_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
180 | self.shape_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
181 | self.hint_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
182 | self.qrange_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
183 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
184 | |
---|
185 | def _layout_data_name(self): |
---|
186 | """ |
---|
187 | Fill the sizer containing data's name |
---|
188 | """ |
---|
189 | data_name_txt = wx.StaticText(self, -1, 'Data: ') |
---|
190 | self.data_name_tcl = OutputTextCtrl(self, -1, |
---|
191 | size=(_BOX_WIDTH * 4, -1)) |
---|
192 | data_hint = "Loaded data" |
---|
193 | self.data_name_tcl.SetToolTipString(data_hint) |
---|
194 | #control that triggers importing data |
---|
195 | id = wx.NewId() |
---|
196 | self.browse_button = wx.Button(self, id, "Load") |
---|
197 | hint_on_browse = "Click to load data into this panel." |
---|
198 | self.browse_button.SetToolTipString(hint_on_browse) |
---|
199 | self.Bind(wx.EVT_BUTTON, self.on_load_data, id=id) |
---|
200 | self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT, 15), |
---|
201 | (self.data_name_tcl, 0, wx.LEFT, 10), |
---|
202 | (self.browse_button, 0, wx.LEFT, 10)]) |
---|
203 | def _layout_param_size(self): |
---|
204 | """ |
---|
205 | Fill the sizer containing slit size information |
---|
206 | """ |
---|
207 | self.parameters = [] |
---|
208 | sizer = wx.GridBagSizer(3, 6) |
---|
209 | model = self.model |
---|
210 | details = self.model.details |
---|
211 | params = self.model.params |
---|
212 | ix = 0 |
---|
213 | iy = 0 |
---|
214 | param_title = wx.StaticText(self, -1, 'Parameter') |
---|
215 | sizer.Add(param_title, (iy, ix), (1, 1), \ |
---|
216 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
217 | ix += 1 |
---|
218 | value_title = wx.StaticText(self, -1, 'Value') |
---|
219 | sizer.Add(value_title, (iy, ix), (1, 1), \ |
---|
220 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
221 | ix += 1 |
---|
222 | unit_title = wx.StaticText(self, -1, 'Unit') |
---|
223 | sizer.Add(unit_title, (iy, ix), (1, 1), \ |
---|
224 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
225 | key_list = params.keys() |
---|
226 | key_list.sort() |
---|
227 | for param in key_list: |
---|
228 | iy += 1 |
---|
229 | ix = 0 |
---|
230 | p_name = wx.StaticText(self, -1, param) |
---|
231 | sizer.Add(p_name, (iy, ix), (1, 1), \ |
---|
232 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
233 | ## add parameter value |
---|
234 | ix += 1 |
---|
235 | value = model.getParam(param) |
---|
236 | ctl = InputTextCtrl(self, -1, size=(_BOX_WIDTH * 2, 20), |
---|
237 | style=wx.TE_PROCESS_ENTER) |
---|
238 | #ctl.SetToolTipString(\ |
---|
239 | # "Hit 'Enter' after typing to update the plot.") |
---|
240 | ctl.SetValue(format_number(value, True)) |
---|
241 | sizer.Add(ctl, (iy, ix), (1, 1), wx.EXPAND) |
---|
242 | ## add unit |
---|
243 | ix += 1 |
---|
244 | unit = wx.StaticText(self, -1, details[param][0]) |
---|
245 | sizer.Add(unit, (iy, ix), (1, 1), \ |
---|
246 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
247 | self.parameters.append([p_name, ctl, unit]) |
---|
248 | |
---|
249 | self.param_sizer.Add(sizer, 0, wx.LEFT, 10) |
---|
250 | |
---|
251 | def _layout_hint(self): |
---|
252 | """ |
---|
253 | Fill the sizer containing hint |
---|
254 | """ |
---|
255 | hint_msg = "We support omf, sld or pdb data files only." |
---|
256 | hint_msg += " " |
---|
257 | if FONT_VARIANT < 1: |
---|
258 | hint_msg += "Very " |
---|
259 | hint_msg += "SLOW drawing -->" |
---|
260 | hint_txt = wx.StaticText(self, -1, hint_msg) |
---|
261 | |
---|
262 | id = wx.NewId() |
---|
263 | self.draw_button = wx.Button(self, id, "Arrow Draw") |
---|
264 | hint_on_draw = "Draw with arrows. Caution: it is a very slow drawing." |
---|
265 | self.draw_button.SetToolTipString(hint_on_draw) |
---|
266 | self.draw_button.Bind(wx.EVT_BUTTON, self.sld_draw, id=id) |
---|
267 | |
---|
268 | self.draw_button.Enable(False) |
---|
269 | self.hint_sizer.AddMany([(hint_txt, 0, wx.LEFT, 15), |
---|
270 | (self.draw_button, 0, wx.LEFT, 7)]) |
---|
271 | |
---|
272 | def _layout_shape(self): |
---|
273 | """ |
---|
274 | Fill the shape sizer |
---|
275 | """ |
---|
276 | label_txt = wx.StaticText(self, -1, "Shape:") |
---|
277 | self.shape_combo = self._fill_shape_combo() |
---|
278 | self.shape_sizer.AddMany([(label_txt, 0, wx.LEFT, 15), |
---|
279 | (self.shape_combo, 0, wx.LEFT, 5)]) |
---|
280 | |
---|
281 | def _fill_shape_combo(self): |
---|
282 | """ |
---|
283 | Fill up the shape combo box |
---|
284 | """ |
---|
285 | shape_combo = wx.ComboBox(self, -1, size=(150, -1), |
---|
286 | style=wx.CB_READONLY) |
---|
287 | shape_combo.Append('Rectangular') |
---|
288 | shape_combo.Append('Ellipsoid') |
---|
289 | shape_combo.Bind(wx.EVT_COMBOBOX, self._on_shape_select) |
---|
290 | shape_combo.SetSelection(0) |
---|
291 | return shape_combo |
---|
292 | |
---|
293 | def _on_shape_select(self, event): |
---|
294 | """ |
---|
295 | On selecting a shape |
---|
296 | """ |
---|
297 | event.Skip() |
---|
298 | label = event.GetEventObject().GetValue().lower() |
---|
299 | self.default_shape = label |
---|
300 | self.parent.set_omfpanel_default_shap(self.default_shape) |
---|
301 | self.parent.set_omfpanel_npts() |
---|
302 | |
---|
303 | def _fill_orient_combo(self): |
---|
304 | """ |
---|
305 | Fill up the orientation combo box: used only for atomic structure |
---|
306 | """ |
---|
307 | orient_combo = wx.ComboBox(self, -1, size=(150, -1), |
---|
308 | style=wx.CB_READONLY) |
---|
309 | orient_combo.Append('Fixed orientation') |
---|
310 | orient_combo.Append('Debye full avg.') |
---|
311 | #orient_combo.Append('Debye sph. sym.') |
---|
312 | |
---|
313 | orient_combo.Bind(wx.EVT_COMBOBOX, self._on_orient_select) |
---|
314 | orient_combo.SetSelection(0) |
---|
315 | return orient_combo |
---|
316 | |
---|
317 | def _on_orient_select(self, event): |
---|
318 | """ |
---|
319 | On selecting a orientation |
---|
320 | """ |
---|
321 | event.Skip() |
---|
322 | cb = event.GetEventObject() |
---|
323 | if cb.GetCurrentSelection() == 2: |
---|
324 | self.is_avg = None |
---|
325 | else: |
---|
326 | is_avg = cb.GetCurrentSelection() == 1 |
---|
327 | self.is_avg = is_avg |
---|
328 | self.model.set_is_avg(self.is_avg) |
---|
329 | self.set_est_time() |
---|
330 | |
---|
331 | def _layout_qrange(self): |
---|
332 | """ |
---|
333 | Fill the sizer containing qrange |
---|
334 | """ |
---|
335 | sizer = wx.GridBagSizer(2, 3) |
---|
336 | ix = 0 |
---|
337 | iy = 0 |
---|
338 | #key_list.sort() |
---|
339 | name = wx.StaticText(self, -1, 'No. of Qx (Qy) bins: ') |
---|
340 | sizer.Add(name, (iy, ix), (1, 1), \ |
---|
341 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
342 | ## add parameter value |
---|
343 | ix += 1 |
---|
344 | self.npt_ctl = InputTextCtrl(self, -1, size=(_BOX_WIDTH * 1.5, 20), |
---|
345 | style=wx.TE_PROCESS_ENTER) |
---|
346 | self.npt_ctl.Bind(wx.EVT_TEXT, self._onparamEnter) |
---|
347 | self.npt_ctl.SetValue(format_number(self.npts_x, True)) |
---|
348 | sizer.Add(self.npt_ctl, (iy, ix), (1, 1), wx.EXPAND) |
---|
349 | ## add unit |
---|
350 | ix += 1 |
---|
351 | unit = wx.StaticText(self, -1, '') |
---|
352 | sizer.Add(unit, (iy, ix), (1, 1), \ |
---|
353 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
354 | iy += 1 |
---|
355 | ix = 0 |
---|
356 | name = wx.StaticText(self, -1, 'Qx (Qy) Max: ') |
---|
357 | sizer.Add(name, (iy, ix), (1, 1), \ |
---|
358 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
359 | ## add parameter value |
---|
360 | ix += 1 |
---|
361 | self.qmax_ctl = InputTextCtrl(self, -1, size=(_BOX_WIDTH * 1.5, 20), |
---|
362 | style=wx.TE_PROCESS_ENTER) |
---|
363 | self.qmax_ctl.Bind(wx.EVT_TEXT, self._onparamEnter) |
---|
364 | self.qmax_ctl.SetValue(format_number(self.qmax_x, True)) |
---|
365 | sizer.Add(self.qmax_ctl, (iy, ix), (1, 1), wx.EXPAND) |
---|
366 | ## add unit |
---|
367 | ix += 1 |
---|
368 | unit = wx.StaticText(self, -1, '[1/A]') |
---|
369 | sizer.Add(unit, (iy, ix), (1, 1), \ |
---|
370 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
371 | self.qrange_sizer.Add(sizer, 0, wx.LEFT, 10) |
---|
372 | |
---|
373 | def _layout_button(self): |
---|
374 | """ |
---|
375 | Do the layout for the button widgets |
---|
376 | """ |
---|
377 | self.est_time = '*Estimated Computation time :\n %s' |
---|
378 | self.time_text = wx.StaticText(self, -1, self.est_time % str('2 sec')) |
---|
379 | self.orient_combo = self._fill_orient_combo() |
---|
380 | self.orient_combo.Show(False) |
---|
381 | |
---|
382 | self.bt_compute = wx.Button(self, wx.NewId(), 'Compute') |
---|
383 | self.bt_compute.Bind(wx.EVT_BUTTON, self.on_compute) |
---|
384 | self.bt_compute.SetToolTipString("Compute 2D Scattering Pattern.") |
---|
385 | |
---|
386 | self.bt_help = wx.Button(self, wx.NewId(), 'HELP') |
---|
387 | self.bt_help.Bind(wx.EVT_BUTTON, self.on_help) |
---|
388 | self.bt_help.SetToolTipString("Help on Scatter Calculator") |
---|
389 | |
---|
390 | self.bt_close = wx.Button(self, wx.ID_CANCEL, 'Close') |
---|
391 | self.bt_close.Bind(wx.EVT_BUTTON, self.on_panel_close) |
---|
392 | self.bt_close.SetToolTipString("Close this window") |
---|
393 | |
---|
394 | self.button_sizer.AddMany([(self.time_text , 0, wx.LEFT, 20), |
---|
395 | (self.orient_combo , 0, wx.LEFT, 20), |
---|
396 | (self.bt_compute, 0, wx.LEFT, 20), |
---|
397 | (self.bt_help, 0, wx.LEFT, 20), |
---|
398 | (self.bt_close, 0, wx.LEFT, 5)]) |
---|
399 | |
---|
400 | def estimate_ctime(self): |
---|
401 | """ |
---|
402 | Calculation time estimation |
---|
403 | """ |
---|
404 | # magic equation: not very accurate |
---|
405 | factor = 1 |
---|
406 | n_qbins = float(self.npt_ctl.GetValue()) |
---|
407 | n_qbins *= n_qbins |
---|
408 | n_pixs = float(self.parent.get_npix()) |
---|
409 | if self.is_avg: |
---|
410 | factor = 6 |
---|
411 | n_pixs *= (n_pixs / 200) |
---|
412 | x_in = n_qbins * n_pixs / 100000 |
---|
413 | etime = factor + 0.085973 * x_in |
---|
414 | return int(etime) |
---|
415 | |
---|
416 | def set_est_time(self): |
---|
417 | """ |
---|
418 | Set text for est. computation time |
---|
419 | """ |
---|
420 | unit = 'sec' |
---|
421 | if self.time_text != None: |
---|
422 | self.time_text.SetForegroundColour('black') |
---|
423 | etime = self.estimate_ctime() |
---|
424 | if etime > 60: |
---|
425 | etime /= 60 |
---|
426 | unit = 'min' |
---|
427 | self.time_text.SetForegroundColour('red') |
---|
428 | time_str = str(etime) + ' ' + unit |
---|
429 | self.time_text.SetLabel(self.est_time % time_str) |
---|
430 | |
---|
431 | def _do_layout(self): |
---|
432 | """ |
---|
433 | Draw window content |
---|
434 | """ |
---|
435 | self._define_structure() |
---|
436 | self._layout_data_name() |
---|
437 | self._layout_param_size() |
---|
438 | self._layout_qrange() |
---|
439 | self._layout_hint() |
---|
440 | self._layout_shape() |
---|
441 | self._layout_button() |
---|
442 | self.boxsizer_source.AddMany([(self.data_name_sizer, 0, |
---|
443 | wx.EXPAND | wx.TOP | wx.BOTTOM, 5), |
---|
444 | (self.hint_sizer, 0, |
---|
445 | wx.EXPAND | wx.TOP | wx.BOTTOM, 5), |
---|
446 | (self.shape_sizer, 0, |
---|
447 | wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) |
---|
448 | self.boxsizer_parameters.AddMany([(self.param_sizer, 0, |
---|
449 | wx.EXPAND | wx.TOP | wx.BOTTOM, 5), ]) |
---|
450 | self.boxsizer_qrange.AddMany([(self.qrange_sizer, 0, |
---|
451 | wx.EXPAND | wx.TOP | wx.BOTTOM, 5), ]) |
---|
452 | self.main_sizer.AddMany([(self.boxsizer_source, 0, |
---|
453 | wx.EXPAND | wx.ALL, 10), |
---|
454 | (self.boxsizer_parameters, 0, |
---|
455 | wx.EXPAND | wx.ALL, 10), |
---|
456 | (self.boxsizer_qrange, 0, |
---|
457 | wx.EXPAND | wx.ALL, 10), |
---|
458 | (self.button_sizer, 0, |
---|
459 | wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) |
---|
460 | self.SetSizer(self.main_sizer) |
---|
461 | self.SetAutoLayout(True) |
---|
462 | |
---|
463 | def _create_default_sld_data(self): |
---|
464 | """ |
---|
465 | Making default sld-data |
---|
466 | """ |
---|
467 | sld_n_default = 6.97e-06 |
---|
468 | omfdata = sas_gen.OMFData() |
---|
469 | omf2sld = sas_gen.OMF2SLD() |
---|
470 | omf2sld.set_data(omfdata, self.default_shape) |
---|
471 | self.sld_data = omf2sld.output |
---|
472 | self.sld_data.is_data = False |
---|
473 | self.sld_data.filename = "Default SLD Profile" |
---|
474 | self.sld_data.set_sldn(sld_n_default) |
---|
475 | self.data_name_tcl.SetValue(self.sld_data.filename) |
---|
476 | |
---|
477 | def choose_data_file(self, location=None): |
---|
478 | """ |
---|
479 | Choosing a dtata file |
---|
480 | """ |
---|
481 | path = None |
---|
482 | filename = '' |
---|
483 | if location == None: |
---|
484 | location = os.getcwd() |
---|
485 | |
---|
486 | exts = "*" + self.omfreader.ext[0] |
---|
487 | exts += ", *" + self.sldreader.ext[0] |
---|
488 | exts += ", *" + self.pdbreader.ext[0] |
---|
489 | all_type = "All GEN files (%s, %s) | %s" % (exts.upper(), exts.lower(), |
---|
490 | exts.lower().replace(',', ';')) |
---|
491 | wildcard = [all_type] |
---|
492 | omf_type = self.omfreader.type |
---|
493 | sld_type = self.sldreader.type |
---|
494 | pdb_type = self.pdbreader.type |
---|
495 | |
---|
496 | for type in sld_type: |
---|
497 | wildcard.append(type) |
---|
498 | for type in omf_type: |
---|
499 | wildcard.append(type) |
---|
500 | for type in pdb_type: |
---|
501 | wildcard.append(type) |
---|
502 | wildcard = '|'.join(wildcard) |
---|
503 | dlg = wx.FileDialog(self, "Choose a file", location, |
---|
504 | "", wildcard, wx.OPEN) |
---|
505 | if dlg.ShowModal() == wx.ID_OK: |
---|
506 | path = dlg.GetPath() |
---|
507 | filename = os.path.basename(path) |
---|
508 | dlg.Destroy() |
---|
509 | return path |
---|
510 | |
---|
511 | def on_load_data(self, event): |
---|
512 | """ |
---|
513 | Open a file dialog to allow the user to select a given file. |
---|
514 | The user is only allow to load file with extension .omf, .txt, .sld. |
---|
515 | Display the slit size corresponding to the loaded data. |
---|
516 | """ |
---|
517 | location = self.parent.get_path() |
---|
518 | path = self.choose_data_file(location=location) |
---|
519 | if path is None: |
---|
520 | return |
---|
521 | |
---|
522 | self.shape_sizer.ShowItems(False) |
---|
523 | self.default_shape = 'rectangular' |
---|
524 | self.parent.set_omfpanel_default_shap(self.default_shape) |
---|
525 | |
---|
526 | self.parent.set_file_location(os.path.dirname(path)) |
---|
527 | try: |
---|
528 | #Load data |
---|
529 | self.ext = os.path.splitext(path)[-1] |
---|
530 | if self.ext in self.omfreader.ext: |
---|
531 | loader = self.omfreader |
---|
532 | elif self.ext in self.sldreader.ext: |
---|
533 | loader = self.sldreader |
---|
534 | elif self.ext in self.pdbreader.ext: |
---|
535 | loader = self.pdbreader |
---|
536 | else: |
---|
537 | loader = None |
---|
538 | if self.reader is not None and self.reader.isrunning(): |
---|
539 | self.reader.stop() |
---|
540 | self.browse_button.Enable(False) |
---|
541 | self.browse_button.SetLabel("Loading...") |
---|
542 | if self.parent.parent is not None: |
---|
543 | wx.PostEvent(self.parent.parent, |
---|
544 | StatusEvent(status="Loading...", |
---|
545 | type="progress")) |
---|
546 | self.reader = GenReader(path=path, loader=loader, |
---|
547 | completefn=self.complete_loading, |
---|
548 | updatefn=self.load_update) |
---|
549 | self.reader.queue() |
---|
550 | #self.load_update() |
---|
551 | except: |
---|
552 | self.ext = None |
---|
553 | if self.parent.parent is None: |
---|
554 | return |
---|
555 | msg = "Generic SAS Calculator: %s" % (sys.exc_value) |
---|
556 | wx.PostEvent(self.parent.parent, |
---|
557 | StatusEvent(status=msg, type='stop')) |
---|
558 | self.SetFocus() |
---|
559 | return |
---|
560 | |
---|
561 | def load_update(self): |
---|
562 | """ |
---|
563 | print update on the status bar |
---|
564 | """ |
---|
565 | if self.parent.parent is None: |
---|
566 | return |
---|
567 | if self.reader.isrunning(): |
---|
568 | type = "progress" |
---|
569 | else: |
---|
570 | type = "stop" |
---|
571 | wx.PostEvent(self.parent.parent, StatusEvent(status="", |
---|
572 | type=type)) |
---|
573 | |
---|
574 | def complete_loading(self, data=None, filename=''): |
---|
575 | """ |
---|
576 | Complete the loading |
---|
577 | """ |
---|
578 | #compute the slit size |
---|
579 | self.browse_button.Enable(True) |
---|
580 | self.browse_button.SetLabel('Load') |
---|
581 | try: |
---|
582 | is_pdbdata = False |
---|
583 | filename = data.filename |
---|
584 | self.data_name_tcl.SetValue(str(filename)) |
---|
585 | self.file_name = filename.split('.')[0] |
---|
586 | self.orient_combo.SetSelection(0) |
---|
587 | self.is_avg = False |
---|
588 | if self.ext in self.omfreader.ext: |
---|
589 | gen = sas_gen.OMF2SLD() |
---|
590 | gen.set_data(data) |
---|
591 | #omf_data = data |
---|
592 | self.sld_data = gen.get_magsld() |
---|
593 | elif self.ext in self.sldreader.ext: |
---|
594 | self.sld_data = data |
---|
595 | elif self.ext in self.pdbreader.ext: |
---|
596 | self.sld_data = data |
---|
597 | is_pdbdata = True |
---|
598 | #omf_data = None |
---|
599 | else: |
---|
600 | raise |
---|
601 | self.orient_combo.Show(is_pdbdata) |
---|
602 | self.button_sizer.Layout() |
---|
603 | self._set_sld_data_helper(True) |
---|
604 | except: |
---|
605 | if self.parent.parent is None: |
---|
606 | raise |
---|
607 | msg = "Loading Error: This file format is not supported " |
---|
608 | msg += "for GenSAS." |
---|
609 | wx.PostEvent(self.parent.parent, |
---|
610 | StatusEvent(status=msg, type='stop', info='Error')) |
---|
611 | self.SetFocus() |
---|
612 | return |
---|
613 | if self.parent.parent is None: |
---|
614 | return |
---|
615 | |
---|
616 | msg = "Load Complete" |
---|
617 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg, type='stop')) |
---|
618 | self.SetFocus() |
---|
619 | |
---|
620 | def _set_sld_data_helper(self, is_draw=False): |
---|
621 | """ |
---|
622 | Set sld data helper |
---|
623 | """ |
---|
624 | #is_avg = self.orient_combo.GetCurrentSelection() == 1 |
---|
625 | self.model.set_is_avg(self.is_avg) |
---|
626 | self.model.set_sld_data(self.sld_data) |
---|
627 | |
---|
628 | self.draw_button.Enable(self.sld_data != None) |
---|
629 | wx.CallAfter(self.parent.set_sld_data, self.sld_data) |
---|
630 | self._update_model_params() |
---|
631 | if is_draw: |
---|
632 | wx.CallAfter(self.sld_draw, None, False) |
---|
633 | |
---|
634 | def _update_model_params(self): |
---|
635 | """ |
---|
636 | Update the model parameter values |
---|
637 | """ |
---|
638 | for list in self.parameters: |
---|
639 | param_name = list[0].GetLabelText() |
---|
640 | val = str(self.model.params[param_name]) |
---|
641 | list[1].SetValue(val) |
---|
642 | |
---|
643 | def set_volume_ctl_val(self, val): |
---|
644 | """ |
---|
645 | Set volume txtctrl value |
---|
646 | """ |
---|
647 | for list in self.parameters: |
---|
648 | param_name = list[0].GetLabelText() |
---|
649 | if param_name.lower() == 'total_volume': |
---|
650 | list[1].SetValue(val) |
---|
651 | list[1].Refresh() |
---|
652 | break |
---|
653 | |
---|
654 | def _onparamEnter(self, event): |
---|
655 | """ |
---|
656 | On param enter |
---|
657 | """ |
---|
658 | try: |
---|
659 | item = event.GetEventObject() |
---|
660 | self._check_value() |
---|
661 | item.Refresh() |
---|
662 | except: |
---|
663 | pass |
---|
664 | |
---|
665 | def sld_draw(self, event=None, has_arrow=True): |
---|
666 | """ |
---|
667 | Draw 3D sld profile |
---|
668 | """ |
---|
669 | flag = self.parent.check_omfpanel_inputs() |
---|
670 | if not flag: |
---|
671 | infor = 'Error' |
---|
672 | msg = 'Error: Wrong inputs in the SLD info panel.' |
---|
673 | # inform msg to wx |
---|
674 | wx.PostEvent(self.parent.parent, |
---|
675 | StatusEvent(status=msg, info=infor)) |
---|
676 | self.SetFocus() |
---|
677 | return |
---|
678 | |
---|
679 | self.sld_data = self.parent.get_sld_from_omf() |
---|
680 | output = self.sld_data |
---|
681 | #frame_size = wx.Size(470, 470) |
---|
682 | self.plot_frame = PlotFrame(self, -1, 'testView') |
---|
683 | frame = self.plot_frame |
---|
684 | frame.Show(False) |
---|
685 | add_icon(self.parent, frame) |
---|
686 | panel = frame.plotpanel |
---|
687 | try: |
---|
688 | # mpl >= 1.0.0 |
---|
689 | ax = panel.figure.gca(projection='3d') |
---|
690 | except: |
---|
691 | # mpl < 1.0.0 |
---|
692 | try: |
---|
693 | from mpl_toolkits.mplot3d import Axes3D |
---|
694 | ax = Axes3D(panel.figure) |
---|
695 | except: |
---|
696 | logging.error("PlotPanel could not import Axes3D") |
---|
697 | raise |
---|
698 | panel.dimension = 3 |
---|
699 | graph_title = self._sld_plot_helper(ax, output, has_arrow) |
---|
700 | # Use y, z axes (in mpl 3d) as z, y axes |
---|
701 | # that consistent with our SAS detector coords. |
---|
702 | ax.set_xlabel('x ($\A%s$)' % output.pos_unit) |
---|
703 | ax.set_ylabel('z ($\A%s$)' % output.pos_unit) |
---|
704 | ax.set_zlabel('y ($\A%s$)' % output.pos_unit) |
---|
705 | panel.subplot.figure.subplots_adjust(left=0.05, right=0.95, |
---|
706 | bottom=0.05, top=0.96) |
---|
707 | if output.pix_type == 'atom': |
---|
708 | ax.legend(loc='upper left', prop={'size':10}) |
---|
709 | num_graph = str(self.graph_num) |
---|
710 | frame.SetTitle('Graph %s: %s' % (num_graph, graph_title)) |
---|
711 | wx.CallAfter(frame.Show, True) |
---|
712 | self.graph_num += 1 |
---|
713 | |
---|
714 | def _sld_plot_helper(self, ax, output, has_arrow=False): |
---|
715 | """ |
---|
716 | Actual plot definition happens here |
---|
717 | :Param ax: axis3d |
---|
718 | :Param output: sld_data [MagSLD] |
---|
719 | :Param has_arrow: whether or not draws M vector [bool] |
---|
720 | """ |
---|
721 | # Set the locals |
---|
722 | color_dic = {'H':'blue', 'D':'purple', 'N': 'orange', |
---|
723 | 'O':'red', 'C':'green', 'P':'cyan', 'Other':'k'} |
---|
724 | marker = ',' |
---|
725 | m_size = 2 |
---|
726 | graph_title = self.file_name |
---|
727 | graph_title += " 3D SLD Profile " |
---|
728 | pos_x = output.pos_x |
---|
729 | pos_y = output.pos_y |
---|
730 | pos_z = output.pos_z |
---|
731 | sld_mx = output.sld_mx |
---|
732 | sld_my = output.sld_my |
---|
733 | sld_mz = output.sld_mz |
---|
734 | pix_symbol = output.pix_symbol |
---|
735 | if output.pix_type == 'atom': |
---|
736 | marker = 'o' |
---|
737 | m_size = 3.5 |
---|
738 | sld_tot = (numpy.fabs(sld_mx) + numpy.fabs(sld_my) + \ |
---|
739 | numpy.fabs(sld_mz) + numpy.fabs(output.sld_n)) |
---|
740 | is_nonzero = sld_tot > 0.0 |
---|
741 | is_zero = sld_tot == 0.0 |
---|
742 | # I. Plot null points |
---|
743 | if is_zero.any(): |
---|
744 | ax.plot(pos_x[is_zero], pos_z[is_zero], pos_y[is_zero], marker, |
---|
745 | c="y", alpha=0.5, markeredgecolor='y', markersize=m_size) |
---|
746 | pos_x = pos_x[is_nonzero] |
---|
747 | pos_y = pos_y[is_nonzero] |
---|
748 | pos_z = pos_z[is_nonzero] |
---|
749 | sld_mx = sld_mx[is_nonzero] |
---|
750 | sld_my = sld_my[is_nonzero] |
---|
751 | sld_mz = sld_mz[is_nonzero] |
---|
752 | pix_symbol = output.pix_symbol[is_nonzero] |
---|
753 | # II. Plot selective points in color |
---|
754 | other_color = numpy.ones(len(pix_symbol), dtype='bool') |
---|
755 | for key in color_dic.keys(): |
---|
756 | chosen_color = pix_symbol == key |
---|
757 | if numpy.any(chosen_color): |
---|
758 | other_color = other_color & (chosen_color != True) |
---|
759 | color = color_dic[key] |
---|
760 | ax.plot(pos_x[chosen_color], pos_z[chosen_color], |
---|
761 | pos_y[chosen_color], marker, c=color, alpha=0.5, |
---|
762 | markeredgecolor=color, markersize=m_size, label=key) |
---|
763 | # III. Plot All others |
---|
764 | if numpy.any(other_color): |
---|
765 | a_name = '' |
---|
766 | if output.pix_type == 'atom': |
---|
767 | # Get atom names not in the list |
---|
768 | a_names = [symb for symb in pix_symbol \ |
---|
769 | if symb not in color_dic.keys()] |
---|
770 | a_name = a_names[0] |
---|
771 | for name in a_names: |
---|
772 | new_name = ", " + name |
---|
773 | if a_name.count(name) == 0: |
---|
774 | a_name += new_name |
---|
775 | # plot in black |
---|
776 | ax.plot(pos_x[other_color], pos_z[other_color], pos_y[other_color], |
---|
777 | marker, c="k", alpha=0.5, markeredgecolor="k", |
---|
778 | markersize=m_size, label=a_name) |
---|
779 | # IV. Draws atomic bond with grey lines if any |
---|
780 | if output.has_conect: |
---|
781 | for ind in range(len(output.line_x)): |
---|
782 | ax.plot(output.line_x[ind], output.line_z[ind], |
---|
783 | output.line_y[ind], '-', lw=0.6, c="grey", alpha=0.3) |
---|
784 | # V. Draws magnetic vectors |
---|
785 | if has_arrow and len(pos_x) > 0: |
---|
786 | graph_title += " - Magnetic Vector as Arrow -" |
---|
787 | panel = self.plot_frame.plotpanel |
---|
788 | def _draw_arrow(input=None, update=None): |
---|
789 | """ |
---|
790 | draw magnetic vectors w/arrow |
---|
791 | """ |
---|
792 | max_mx = max(numpy.fabs(sld_mx)) |
---|
793 | max_my = max(numpy.fabs(sld_my)) |
---|
794 | max_mz = max(numpy.fabs(sld_mz)) |
---|
795 | max_m = max(max_mx, max_my, max_mz) |
---|
796 | try: |
---|
797 | max_step = max(output.xstepsize, output.ystepsize, |
---|
798 | output.zstepsize) |
---|
799 | except: |
---|
800 | max_step = 0 |
---|
801 | if max_step <= 0: |
---|
802 | max_step = 5 |
---|
803 | try: |
---|
804 | if max_m != 0: |
---|
805 | unit_x2 = sld_mx / max_m |
---|
806 | unit_y2 = sld_my / max_m |
---|
807 | unit_z2 = sld_mz / max_m |
---|
808 | # 0.8 is for avoiding the color becomes white=(1,1,1)) |
---|
809 | color_x = numpy.fabs(unit_x2 * 0.8) |
---|
810 | color_y = numpy.fabs(unit_y2 * 0.8) |
---|
811 | color_z = numpy.fabs(unit_z2 * 0.8) |
---|
812 | x2 = pos_x + unit_x2 * max_step |
---|
813 | y2 = pos_y + unit_y2 * max_step |
---|
814 | z2 = pos_z + unit_z2 * max_step |
---|
815 | x_arrow = numpy.column_stack((pos_x, x2)) |
---|
816 | y_arrow = numpy.column_stack((pos_y, y2)) |
---|
817 | z_arrow = numpy.column_stack((pos_z, z2)) |
---|
818 | colors = numpy.column_stack((color_x, color_y, color_z)) |
---|
819 | arrows = Arrow3D(panel, x_arrow, z_arrow, y_arrow, |
---|
820 | colors, mutation_scale=10, lw=1, |
---|
821 | arrowstyle="->", alpha=0.5) |
---|
822 | ax.add_artist(arrows) |
---|
823 | except: |
---|
824 | pass |
---|
825 | msg = "Arrow Drawing completed.\n" |
---|
826 | status_type = 'stop' |
---|
827 | self._status_info(msg, status_type) |
---|
828 | msg = "Arrow Drawing is in progress..." |
---|
829 | status_type = 'progress' |
---|
830 | self._status_info(msg, status_type) |
---|
831 | draw_out = CalcGen(input=ax, |
---|
832 | completefn=_draw_arrow, updatefn=self._update) |
---|
833 | draw_out.queue() |
---|
834 | return graph_title |
---|
835 | |
---|
836 | def set_input_params(self): |
---|
837 | """ |
---|
838 | Set model parameters |
---|
839 | """ |
---|
840 | for list in self.parameters: |
---|
841 | param_name = list[0].GetLabelText() |
---|
842 | param_value = float(list[1].GetValue()) |
---|
843 | self.model.setParam(param_name, param_value) |
---|
844 | |
---|
845 | def on_compute(self, event): |
---|
846 | """ |
---|
847 | Compute I(qx, qy) |
---|
848 | """ |
---|
849 | flag = self.parent.check_omfpanel_inputs() |
---|
850 | if not flag and self.parent.parent != None: |
---|
851 | infor = 'Error' |
---|
852 | msg = 'Error: Wrong inputs in the SLD info panel.' |
---|
853 | # inform msg to wx |
---|
854 | wx.PostEvent(self.parent.parent, |
---|
855 | StatusEvent(status=msg, info=infor)) |
---|
856 | self.SetFocus() |
---|
857 | return |
---|
858 | self.sld_data = self.parent.get_sld_from_omf() |
---|
859 | if self.sld_data == None: |
---|
860 | if self.parent.parent != None: |
---|
861 | infor = 'Error' |
---|
862 | msg = 'Error: No data has been selected.' |
---|
863 | # inform msg to wx |
---|
864 | wx.PostEvent(self.parent.parent, |
---|
865 | StatusEvent(status=msg, info=infor)) |
---|
866 | self.SetFocus() |
---|
867 | return |
---|
868 | flag = self._check_value() |
---|
869 | if not flag: |
---|
870 | _set_error(self, None, True) |
---|
871 | return |
---|
872 | try: |
---|
873 | self.model.set_sld_data(self.sld_data) |
---|
874 | self.set_input_params() |
---|
875 | if self.is_avg or self.is_avg == None: |
---|
876 | self._create_default_1d_data() |
---|
877 | i_out = numpy.zeros(len(self.data.y)) |
---|
878 | inputs = [self.data.x, [], i_out] |
---|
879 | else: |
---|
880 | self._create_default_2d_data() |
---|
881 | i_out = numpy.zeros(len(self.data.data)) |
---|
882 | inputs = [self.data.qx_data, self.data.qy_data, i_out] |
---|
883 | |
---|
884 | msg = "Computation is in progress..." |
---|
885 | status_type = 'progress' |
---|
886 | self._status_info(msg, status_type) |
---|
887 | cal_out = CalcGen(input=inputs, |
---|
888 | completefn=self.complete, |
---|
889 | updatefn=self._update) |
---|
890 | cal_out.queue() |
---|
891 | |
---|
892 | except: |
---|
893 | msg = "%s." % sys.exc_value |
---|
894 | status_type = 'stop' |
---|
895 | self._status_info(msg, status_type) |
---|
896 | wx.PostEvent(self.parent.parent, |
---|
897 | StatusEvent(status=msg, info='Error')) |
---|
898 | self.SetFocus() |
---|
899 | |
---|
900 | def on_help(self, event): |
---|
901 | """ |
---|
902 | Bring up the General scattering Calculator Documentation whenever |
---|
903 | the HELP button is clicked. |
---|
904 | |
---|
905 | Calls DocumentationWindow with the path of the location within the |
---|
906 | documentation tree (after /doc/ ....". Note that when using old |
---|
907 | versions of Wx (before 2.9) and thus not the release version of |
---|
908 | installers, the help comes up at the top level of the file as |
---|
909 | webbrowser does not pass anything past the # to the browser when it is |
---|
910 | running "file:///...." |
---|
911 | |
---|
912 | :param evt: Triggers on clicking the help button |
---|
913 | """ |
---|
914 | |
---|
915 | _TreeLocation = "user/perspectives/calculator/sas_calculator_help.html" |
---|
916 | _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", |
---|
917 | "General Scattering Calculator Help") |
---|
918 | |
---|
919 | def _check_value(self): |
---|
920 | """ |
---|
921 | Check input values if float |
---|
922 | """ |
---|
923 | flag = True |
---|
924 | self.npt_ctl.SetBackgroundColour("white") |
---|
925 | self.qmax_ctl.SetBackgroundColour("white") |
---|
926 | try: |
---|
927 | npt_val = float(self.npt_ctl.GetValue()) |
---|
928 | if npt_val < 2 or npt_val > 1000: |
---|
929 | raise |
---|
930 | self.npt_ctl.SetValue(str(int(npt_val))) |
---|
931 | self.set_est_time() |
---|
932 | except: |
---|
933 | flag = _set_error(self, self.npt_ctl) |
---|
934 | try: |
---|
935 | qmax_val = float(self.qmax_ctl.GetValue()) |
---|
936 | if qmax_val <= 0 or qmax_val > 1000: |
---|
937 | raise |
---|
938 | except: |
---|
939 | flag = _set_error(self, self.qmax_ctl) |
---|
940 | for list in self.parameters: |
---|
941 | list[1].SetBackgroundColour("white") |
---|
942 | param_name = list[0].GetLabelText() |
---|
943 | try: |
---|
944 | param_val = float(list[1].GetValue()) |
---|
945 | if param_name.count('frac') > 0: |
---|
946 | if param_val < 0 or param_val > 1: |
---|
947 | raise |
---|
948 | except: |
---|
949 | flag = _set_error(self, list[1]) |
---|
950 | return flag |
---|
951 | |
---|
952 | def _status_info(self, msg='', type="update"): |
---|
953 | """ |
---|
954 | Status msg |
---|
955 | """ |
---|
956 | if type == "stop": |
---|
957 | label = "Compute" |
---|
958 | able = True |
---|
959 | else: |
---|
960 | label = "Wait..." |
---|
961 | able = False |
---|
962 | self.bt_compute.Enable(able) |
---|
963 | self.bt_compute.SetLabel(label) |
---|
964 | self.bt_compute.SetToolTipString(label) |
---|
965 | if self.parent.parent != None: |
---|
966 | wx.PostEvent(self.parent.parent, |
---|
967 | StatusEvent(status=msg, type=type)) |
---|
968 | |
---|
969 | def _update(self, time=None): |
---|
970 | """ |
---|
971 | Update the progress bar |
---|
972 | """ |
---|
973 | if self.parent.parent == None: |
---|
974 | return |
---|
975 | type = "progress" |
---|
976 | msg = "Please wait. Computing... (Note: Window may look frozen.)" |
---|
977 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg, |
---|
978 | type=type)) |
---|
979 | |
---|
980 | def complete(self, input, update=None): |
---|
981 | """ |
---|
982 | Gen compute complete function |
---|
983 | :Param input: input list [qx_data, qy_data, i_out] |
---|
984 | """ |
---|
985 | out = numpy.empty(0) |
---|
986 | #s = time.time() |
---|
987 | for ind in range(len(input[0])): |
---|
988 | if self.is_avg: |
---|
989 | if ind % 1 == 0 and update != None: |
---|
990 | update() |
---|
991 | time.sleep(0.1) |
---|
992 | inputi = [input[0][ind:ind + 1], [], input[2][ind:ind + 1]] |
---|
993 | outi = self.model.run(inputi) |
---|
994 | out = numpy.append(out, outi) |
---|
995 | else: |
---|
996 | if ind % 50 == 0 and update != None: |
---|
997 | update() |
---|
998 | time.sleep(0.001) |
---|
999 | inputi = [input[0][ind:ind + 1], input[1][ind:ind + 1], |
---|
1000 | input[2][ind:ind + 1]] |
---|
1001 | outi = self.model.runXY(inputi) |
---|
1002 | out = numpy.append(out, outi) |
---|
1003 | #print time.time() - s |
---|
1004 | if self.is_avg or self.is_avg == None: |
---|
1005 | self._draw1D(out) |
---|
1006 | else: |
---|
1007 | #out = self.model.runXY(input) |
---|
1008 | self._draw2D(out) |
---|
1009 | |
---|
1010 | msg = "Gen computation completed.\n" |
---|
1011 | status_type = 'stop' |
---|
1012 | self._status_info(msg, status_type) |
---|
1013 | |
---|
1014 | def _create_default_2d_data(self): |
---|
1015 | """ |
---|
1016 | Create 2D data by default |
---|
1017 | Only when the page is on theory mode. |
---|
1018 | :warning: This data is never plotted. |
---|
1019 | """ |
---|
1020 | self.qmax_x = float(self.qmax_ctl.GetValue()) |
---|
1021 | self.npts_x = int(float(self.npt_ctl.GetValue())) |
---|
1022 | self.data = Data2D() |
---|
1023 | qmax = self.qmax_x #/ numpy.sqrt(2) |
---|
1024 | self.data.xaxis('\\rm{Q_{x}}', '\AA^{-1}') |
---|
1025 | self.data.yaxis('\\rm{Q_{y}}', '\AA^{-1}') |
---|
1026 | self.data.is_data = False |
---|
1027 | self.data.id = str(self.uid) + " GenData" |
---|
1028 | self.data.group_id = str(self.uid) + " Model2D" |
---|
1029 | ## Default values |
---|
1030 | self.data.detector.append(Detector()) |
---|
1031 | index = len(self.data.detector) - 1 |
---|
1032 | self.data.detector[index].distance = 8000 # mm |
---|
1033 | self.data.source.wavelength = 6 # A |
---|
1034 | self.data.detector[index].pixel_size.x = 5 # mm |
---|
1035 | self.data.detector[index].pixel_size.y = 5 # mm |
---|
1036 | self.data.detector[index].beam_center.x = qmax |
---|
1037 | self.data.detector[index].beam_center.y = qmax |
---|
1038 | xmax = qmax |
---|
1039 | xmin = -qmax |
---|
1040 | ymax = qmax |
---|
1041 | ymin = -qmax |
---|
1042 | qstep = self.npts_x |
---|
1043 | |
---|
1044 | x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
---|
1045 | y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) |
---|
1046 | ## use data info instead |
---|
1047 | new_x = numpy.tile(x, (len(y), 1)) |
---|
1048 | new_y = numpy.tile(y, (len(x), 1)) |
---|
1049 | new_y = new_y.swapaxes(0, 1) |
---|
1050 | # all data reuire now in 1d array |
---|
1051 | qx_data = new_x.flatten() |
---|
1052 | qy_data = new_y.flatten() |
---|
1053 | q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) |
---|
1054 | # set all True (standing for unmasked) as default |
---|
1055 | mask = numpy.ones(len(qx_data), dtype=bool) |
---|
1056 | # store x and y bin centers in q space |
---|
1057 | x_bins = x |
---|
1058 | y_bins = y |
---|
1059 | self.data.source = Source() |
---|
1060 | self.data.data = numpy.ones(len(mask)) |
---|
1061 | self.data.err_data = numpy.ones(len(mask)) |
---|
1062 | self.data.qx_data = qx_data |
---|
1063 | self.data.qy_data = qy_data |
---|
1064 | self.data.q_data = q_data |
---|
1065 | self.data.mask = mask |
---|
1066 | self.data.x_bins = x_bins |
---|
1067 | self.data.y_bins = y_bins |
---|
1068 | # max and min taking account of the bin sizes |
---|
1069 | self.data.xmin = xmin |
---|
1070 | self.data.xmax = xmax |
---|
1071 | self.data.ymin = ymin |
---|
1072 | self.data.ymax = ymax |
---|
1073 | |
---|
1074 | def _create_default_1d_data(self): |
---|
1075 | """ |
---|
1076 | Create 2D data by default |
---|
1077 | Only when the page is on theory mode. |
---|
1078 | :warning: This data is never plotted. |
---|
1079 | residuals.x = data_copy.x[index] |
---|
1080 | residuals.dy = numpy.ones(len(residuals.y)) |
---|
1081 | residuals.dx = None |
---|
1082 | residuals.dxl = None |
---|
1083 | residuals.dxw = None |
---|
1084 | """ |
---|
1085 | self.qmax_x = float(self.qmax_ctl.GetValue()) |
---|
1086 | self.npts_x = int(float(self.npt_ctl.GetValue())) |
---|
1087 | qmax = self.qmax_x #/ numpy.sqrt(2) |
---|
1088 | ## Default values |
---|
1089 | xmax = qmax |
---|
1090 | xmin = qmax * _Q1D_MIN |
---|
1091 | qstep = self.npts_x |
---|
1092 | x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
---|
1093 | # store x and y bin centers in q space |
---|
1094 | #self.data.source = Source() |
---|
1095 | y = numpy.ones(len(x)) |
---|
1096 | dy = numpy.zeros(len(x)) |
---|
1097 | dx = numpy.zeros(len(x)) |
---|
1098 | self.data = Data1D(x=x, y=y) |
---|
1099 | self.data.dx = dx |
---|
1100 | self.data.dy = dy |
---|
1101 | |
---|
1102 | def _draw1D(self, y_out): |
---|
1103 | """ |
---|
1104 | Complete get the result of modelthread and create model 2D |
---|
1105 | that can be plot. |
---|
1106 | """ |
---|
1107 | page_id = self.id |
---|
1108 | data = self.data |
---|
1109 | |
---|
1110 | model = self.model |
---|
1111 | state = None |
---|
1112 | |
---|
1113 | new_plot = Data1D(x=data.x, y=y_out) |
---|
1114 | new_plot.dx = data.dx |
---|
1115 | new_plot.dy = data.dy |
---|
1116 | new_plot.xaxis('\\rm{Q_{x}}', '\AA^{-1}') |
---|
1117 | new_plot.yaxis('\\rm{Intensity}', 'cm^{-1}') |
---|
1118 | new_plot.is_data = False |
---|
1119 | new_plot.id = str(self.uid) + " GenData1D" |
---|
1120 | new_plot.group_id = str(self.uid) + " Model1D" |
---|
1121 | new_plot.name = model.name + '1d' |
---|
1122 | new_plot.title = "Generic model1D " |
---|
1123 | new_plot.id = str(page_id) + ': ' + self.file_name \ |
---|
1124 | + ' #%s' % str(self.graph_num) + "_1D" |
---|
1125 | new_plot.group_id = str(page_id) + " Model1D" + \ |
---|
1126 | ' #%s' % str(self.graph_num) + "_1D" |
---|
1127 | new_plot.is_data = False |
---|
1128 | |
---|
1129 | title = new_plot.title |
---|
1130 | _yaxis, _yunit = new_plot.get_yaxis() |
---|
1131 | _xaxis, _xunit = new_plot.get_xaxis() |
---|
1132 | new_plot.xaxis(str(_xaxis), str(_xunit)) |
---|
1133 | new_plot.yaxis(str(_yaxis), str(_yunit)) |
---|
1134 | |
---|
1135 | if new_plot.is_data: |
---|
1136 | data_name = str(new_plot.name) |
---|
1137 | else: |
---|
1138 | data_name = str(model.__class__.__name__) + '1d' |
---|
1139 | |
---|
1140 | if len(title) > 1: |
---|
1141 | new_plot.title = "Gen Theory for %s " % model.name + data_name |
---|
1142 | new_plot.name = new_plot.id |
---|
1143 | new_plot.label = new_plot.id |
---|
1144 | #theory_data = deepcopy(new_plot) |
---|
1145 | if self.parent.parent != None: |
---|
1146 | self.parent.parent.update_theory(data_id=new_plot.id, |
---|
1147 | theory=new_plot, |
---|
1148 | state=state) |
---|
1149 | title = new_plot.title |
---|
1150 | num_graph = str(self.graph_num) |
---|
1151 | wx.CallAfter(self.parent.draw_graph, new_plot, |
---|
1152 | title="GEN Graph %s: " % num_graph + new_plot.id) |
---|
1153 | self.graph_num += 1 |
---|
1154 | |
---|
1155 | def _draw2D(self, image): |
---|
1156 | """ |
---|
1157 | Complete get the result of modelthread and create model 2D |
---|
1158 | that can be plot. |
---|
1159 | """ |
---|
1160 | page_id = self.id |
---|
1161 | data = self.data |
---|
1162 | |
---|
1163 | model = self.model |
---|
1164 | qmin = 0.0 |
---|
1165 | state = None |
---|
1166 | |
---|
1167 | numpy.nan_to_num(image) |
---|
1168 | new_plot = Data2D(image=image, err_image=data.err_data) |
---|
1169 | new_plot.name = model.name + '2d' |
---|
1170 | new_plot.title = "Generic model 2D " |
---|
1171 | new_plot.id = str(page_id) + ': ' + self.file_name \ |
---|
1172 | + ' #%s' % str(self.graph_num) + "_2D" |
---|
1173 | new_plot.group_id = str(page_id) + " Model2D" \ |
---|
1174 | + ' #%s' % str(self.graph_num) + "_2D" |
---|
1175 | new_plot.detector = data.detector |
---|
1176 | new_plot.source = data.source |
---|
1177 | new_plot.is_data = False |
---|
1178 | new_plot.qx_data = data.qx_data |
---|
1179 | new_plot.qy_data = data.qy_data |
---|
1180 | new_plot.q_data = data.q_data |
---|
1181 | new_plot.mask = data.mask |
---|
1182 | ## plot boundaries |
---|
1183 | new_plot.ymin = data.ymin |
---|
1184 | new_plot.ymax = data.ymax |
---|
1185 | new_plot.xmin = data.xmin |
---|
1186 | new_plot.xmax = data.xmax |
---|
1187 | title = data.title |
---|
1188 | _yaxis, _yunit = data.get_yaxis() |
---|
1189 | _xaxis, _xunit = data.get_xaxis() |
---|
1190 | new_plot.xaxis(str(_xaxis), str(_xunit)) |
---|
1191 | new_plot.yaxis(str(_yaxis), str(_yunit)) |
---|
1192 | |
---|
1193 | new_plot.is_data = False |
---|
1194 | if data.is_data: |
---|
1195 | data_name = str(data.name) |
---|
1196 | else: |
---|
1197 | data_name = str(model.__class__.__name__) + '2d' |
---|
1198 | |
---|
1199 | if len(title) > 1: |
---|
1200 | new_plot.title = "Gen Theory for %s " % model.name + data_name |
---|
1201 | new_plot.name = new_plot.id |
---|
1202 | new_plot.label = new_plot.id |
---|
1203 | #theory_data = deepcopy(new_plot) |
---|
1204 | if self.parent.parent != None: |
---|
1205 | self.parent.parent.update_theory(data_id=data.id, |
---|
1206 | theory=new_plot, |
---|
1207 | state=state) |
---|
1208 | title = new_plot.title |
---|
1209 | num_graph = str(self.graph_num) |
---|
1210 | wx.CallAfter(self.parent.draw_graph, new_plot, |
---|
1211 | title="GEN Graph %s: " % num_graph + new_plot.id) |
---|
1212 | self.graph_num += 1 |
---|
1213 | |
---|
1214 | def set_scale2d(self, scale): |
---|
1215 | """ |
---|
1216 | Set SLD plot scale |
---|
1217 | """ |
---|
1218 | self.scale2d = None |
---|
1219 | |
---|
1220 | def on_panel_close(self, event): |
---|
1221 | """ |
---|
1222 | close the window containing this panel |
---|
1223 | """ |
---|
1224 | self.parent.Close() |
---|
1225 | |
---|
1226 | class OmfPanel(ScrolledPanel, PanelBase): |
---|
1227 | """ |
---|
1228 | Provides the sas gen calculator GUI. |
---|
1229 | """ |
---|
1230 | ## Internal nickname for the window, used by the AUI manager |
---|
1231 | window_name = "SLD Pixel Info" |
---|
1232 | ## Name to appear on the window title bar |
---|
1233 | window_caption = "SLD Pixel Info " |
---|
1234 | |
---|
1235 | def __init__(self, parent, *args, **kwds): |
---|
1236 | ScrolledPanel.__init__(self, parent, style=wx.RAISED_BORDER, |
---|
1237 | *args, **kwds) |
---|
1238 | PanelBase.__init__(self) |
---|
1239 | #Font size |
---|
1240 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
1241 | self.SetupScrolling() |
---|
1242 | # Object that receive status event |
---|
1243 | self.parent = parent |
---|
1244 | self.sld_data = sas_gen.MagSLD([0], [0], [0]) |
---|
1245 | self.sld_ctl = None |
---|
1246 | self.default_shape = 'rectangular' |
---|
1247 | self._do_layout() |
---|
1248 | |
---|
1249 | def set_slddata(self, slddata): |
---|
1250 | """ |
---|
1251 | Set sld data related items |
---|
1252 | """ |
---|
1253 | self.sld_data = slddata |
---|
1254 | self._set_slddata_ctr_val(slddata) |
---|
1255 | # Make sure that self._set_slddata_ctr_val() is finished |
---|
1256 | wx.CallAfter(self._set_omfdata_ctr, slddata) |
---|
1257 | |
---|
1258 | def get_sld_val(self): |
---|
1259 | """ |
---|
1260 | Set sld_n of slddata on sld input |
---|
1261 | """ |
---|
1262 | sld_sets = {} |
---|
1263 | if not self.sld_data.is_data: |
---|
1264 | self._get_other_val() |
---|
1265 | for list in self.slds: |
---|
1266 | if list[1].IsEnabled(): |
---|
1267 | list[1].SetBackgroundColour("white") |
---|
1268 | list[1].Refresh() |
---|
1269 | try: |
---|
1270 | val = float(list[1].GetValue()) |
---|
1271 | sld_sets[list[0]] = val |
---|
1272 | except: |
---|
1273 | flag = _set_error(self, list[1]) |
---|
1274 | if not flag: |
---|
1275 | return self.sld_data |
---|
1276 | else: |
---|
1277 | sld_sets[list[0]] = None |
---|
1278 | for key in sld_sets.keys(): |
---|
1279 | key_low = key.lower() |
---|
1280 | if key_low.count('mx') > 0: |
---|
1281 | if sld_sets[key] == None: |
---|
1282 | sld_sets[key] = self.sld_data.sld_mx |
---|
1283 | mx = sld_sets[key] |
---|
1284 | elif key_low.count('my') > 0: |
---|
1285 | if sld_sets[key] == None: |
---|
1286 | sld_sets[key] = self.sld_data.sld_my |
---|
1287 | my = sld_sets[key] |
---|
1288 | elif key_low.count('mz') > 0: |
---|
1289 | if sld_sets[key] == None: |
---|
1290 | sld_sets[key] = self.sld_data.sld_mz |
---|
1291 | mz = sld_sets[key] |
---|
1292 | else: |
---|
1293 | if sld_sets[key] != None: |
---|
1294 | self.sld_data.set_sldn(sld_sets[key]) |
---|
1295 | self.sld_data.set_sldms(mx, my, mz) |
---|
1296 | self._set_slddata_ctr_val(self.sld_data) |
---|
1297 | |
---|
1298 | return self.sld_data |
---|
1299 | |
---|
1300 | def get_pix_volumes(self): |
---|
1301 | """ |
---|
1302 | Get the pixel volume |
---|
1303 | """ |
---|
1304 | vol = self.sld_data.vol_pix |
---|
1305 | |
---|
1306 | return vol |
---|
1307 | |
---|
1308 | def _get_other_val(self): |
---|
1309 | """ |
---|
1310 | """ |
---|
1311 | omfdata = sas_gen.OMFData() |
---|
1312 | sets = {} |
---|
1313 | try: |
---|
1314 | for lst in self.stepsize: |
---|
1315 | if lst[1].IsEnabled(): |
---|
1316 | val = float(lst[1].GetValue()) |
---|
1317 | sets[lst[0]] = val |
---|
1318 | else: |
---|
1319 | sets[lst[0]] = None |
---|
1320 | return |
---|
1321 | for lst in self.nodes: |
---|
1322 | if lst[1].IsEnabled(): |
---|
1323 | val = float(lst[1].GetValue()) |
---|
1324 | sets[lst[0]] = val |
---|
1325 | else: |
---|
1326 | sets[lst[0]] = None |
---|
1327 | return |
---|
1328 | |
---|
1329 | for key in sets.keys(): |
---|
1330 | setattr(omfdata, key, sets[key]) |
---|
1331 | |
---|
1332 | omf2sld = sas_gen.OMF2SLD() |
---|
1333 | omf2sld.set_data(omfdata, self.default_shape) |
---|
1334 | self.sld_data = omf2sld.output |
---|
1335 | self.sld_data.is_data = False |
---|
1336 | self.sld_data.filename = "Default SLD Profile" |
---|
1337 | except: |
---|
1338 | msg = "OMF Panel: %s" % sys.exc_value |
---|
1339 | infor = 'Error' |
---|
1340 | #logging.error(msg) |
---|
1341 | if self.parent.parent != None: |
---|
1342 | # inform msg to wx |
---|
1343 | wx.PostEvent(self.parent.parent, |
---|
1344 | StatusEvent(status=msg, info=infor)) |
---|
1345 | self.SetFocus() |
---|
1346 | |
---|
1347 | def _set_slddata_ctr_val(self, slddata): |
---|
1348 | """ |
---|
1349 | Set slddata crl |
---|
1350 | """ |
---|
1351 | try: |
---|
1352 | val = str(len(slddata.sld_n)) |
---|
1353 | except: |
---|
1354 | val = 'Unknown' |
---|
1355 | self.npix_ctl.SetValue(val) |
---|
1356 | |
---|
1357 | def _set_omfdata_ctr(self, omfdata): |
---|
1358 | """ |
---|
1359 | Set the textctr box values |
---|
1360 | """ |
---|
1361 | |
---|
1362 | if omfdata == None: |
---|
1363 | self._set_none_text() |
---|
1364 | return |
---|
1365 | nodes_list = self._get_nodes_key_list(omfdata) |
---|
1366 | step_list = self._get_step_key_list(omfdata) |
---|
1367 | for ctr_list in self.nodes: |
---|
1368 | for key in nodes_list.keys(): |
---|
1369 | if ctr_list[0] == key: |
---|
1370 | ctr_list[1].SetValue(format_number(nodes_list[key], True)) |
---|
1371 | ctr_list[1].Enable(not omfdata.is_data) |
---|
1372 | break |
---|
1373 | for ctr_list in self.stepsize: |
---|
1374 | for key in step_list.keys(): |
---|
1375 | if ctr_list[0] == key: |
---|
1376 | ctr_list[1].SetValue(format_number(step_list[key], True)) |
---|
1377 | ctr_list[1].Enable(not omfdata.is_data) |
---|
1378 | break |
---|
1379 | |
---|
1380 | def _set_none_text(self): |
---|
1381 | """ |
---|
1382 | Set Unknown in textctrls |
---|
1383 | """ |
---|
1384 | val = 'Unknown' |
---|
1385 | for ctr_list in self.nodes: |
---|
1386 | ctr_list[1].SetValue(val) |
---|
1387 | for ctr_list in self.stepsize: |
---|
1388 | ctr_list[1].SetValue(val) |
---|
1389 | |
---|
1390 | def _define_structure(self): |
---|
1391 | """ |
---|
1392 | Define the main sizers building to build this application. |
---|
1393 | """ |
---|
1394 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
1395 | |
---|
1396 | self.npixels_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1397 | self.box_sld = wx.StaticBox(self, -1, |
---|
1398 | str("Mean SLD")) |
---|
1399 | self.box_node = wx.StaticBox(self, -1, str("Nodes")) |
---|
1400 | self.boxsizer_sld = wx.StaticBoxSizer(self.box_sld, wx.VERTICAL) |
---|
1401 | self.box_stepsize = wx.StaticBox(self, -1, str("Step Size")) |
---|
1402 | self.boxsizer_node = wx.StaticBoxSizer(self.box_node, wx.VERTICAL) |
---|
1403 | self.boxsizer_stepsize = wx.StaticBoxSizer(self.box_stepsize, |
---|
1404 | wx.VERTICAL) |
---|
1405 | self.sld_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1406 | self.node_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1407 | self.step_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1408 | self.hint_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1409 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
1410 | |
---|
1411 | def _layout_npix(self): |
---|
1412 | """ |
---|
1413 | Build No of pixels sizer |
---|
1414 | """ |
---|
1415 | num_pix_text = wx.StaticText(self, -1, "No. of Pixels: ") |
---|
1416 | self.npix_ctl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
1417 | style=wx.TE_PROCESS_ENTER) |
---|
1418 | self._set_slddata_ctr_val(self.sld_data) |
---|
1419 | self._set_omfdata_ctr(self.sld_data) |
---|
1420 | self.npixels_sizer.AddMany([(num_pix_text, 0, |
---|
1421 | wx.EXPAND | wx.LEFT | wx.TOP, 5), |
---|
1422 | (self.npix_ctl, 0, |
---|
1423 | wx.EXPAND | wx.TOP, 5)]) |
---|
1424 | |
---|
1425 | def _layout_slds(self): |
---|
1426 | """ |
---|
1427 | Build nuclear sld sizer |
---|
1428 | """ |
---|
1429 | self.slds = [] |
---|
1430 | omfdata = self.sld_data |
---|
1431 | if omfdata == None: |
---|
1432 | raise |
---|
1433 | sld_key_list = self._get_slds_key_list(omfdata) |
---|
1434 | # Dic is not sorted |
---|
1435 | key_list = [key for key in sld_key_list.keys()] |
---|
1436 | # Sort here |
---|
1437 | key_list.sort() |
---|
1438 | is_data = self.sld_data.is_data |
---|
1439 | sizer = wx.GridBagSizer(2, 3) |
---|
1440 | ix = 0 |
---|
1441 | iy = -1 |
---|
1442 | for key in key_list: |
---|
1443 | value = sld_key_list[key] |
---|
1444 | iy += 1 |
---|
1445 | ix = 0 |
---|
1446 | name = wx.StaticText(self, -1, key) |
---|
1447 | sizer.Add(name, (iy, ix), (1, 1), \ |
---|
1448 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
1449 | ## add parameter value |
---|
1450 | ix += 1 |
---|
1451 | ctl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
1452 | style=wx.TE_PROCESS_ENTER) |
---|
1453 | ctl.SetValue(format_number(value, True)) |
---|
1454 | ctl.Enable(not is_data) |
---|
1455 | sizer.Add(ctl, (iy, ix), (1, 1), wx.EXPAND) |
---|
1456 | ## add unit |
---|
1457 | ix += 1 |
---|
1458 | s_unit = '[' + omfdata.sld_unit + ']' |
---|
1459 | unit = wx.StaticText(self, -1, s_unit) |
---|
1460 | sizer.Add(unit, (iy, ix), (1, 1), \ |
---|
1461 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
1462 | self.slds.append([key, ctl, unit]) |
---|
1463 | self.sld_sizer.Add(sizer, 0, wx.LEFT, 10) |
---|
1464 | |
---|
1465 | def _layout_nodes(self): |
---|
1466 | """ |
---|
1467 | Fill the sizer containing data's name |
---|
1468 | """ |
---|
1469 | self.nodes = [] |
---|
1470 | omfdata = self.sld_data |
---|
1471 | if omfdata == None: |
---|
1472 | raise |
---|
1473 | key_list = self._get_nodes_key_list(omfdata) |
---|
1474 | is_data = self.sld_data.is_data |
---|
1475 | sizer = wx.GridBagSizer(2, 3) |
---|
1476 | ix = 0 |
---|
1477 | iy = -1 |
---|
1478 | for key, value in key_list.iteritems(): |
---|
1479 | iy += 1 |
---|
1480 | ix = 0 |
---|
1481 | name = wx.StaticText(self, -1, key) |
---|
1482 | sizer.Add(name, (iy, ix), (1, 1), \ |
---|
1483 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
1484 | ## add parameter value |
---|
1485 | ix += 1 |
---|
1486 | ctl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
1487 | style=wx.TE_PROCESS_ENTER) |
---|
1488 | ctl.Bind(wx.EVT_TEXT, self._onparamEnter) |
---|
1489 | ctl.SetValue(format_number(value, True)) |
---|
1490 | ctl.Enable(not is_data) |
---|
1491 | sizer.Add(ctl, (iy, ix), (1, 1), wx.EXPAND) |
---|
1492 | ## add unit |
---|
1493 | ix += 1 |
---|
1494 | unit = wx.StaticText(self, -1, '') |
---|
1495 | sizer.Add(unit, (iy, ix), (1, 1), \ |
---|
1496 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
1497 | self.nodes.append([key, ctl, unit]) |
---|
1498 | self.node_sizer.Add(sizer, 0, wx.LEFT, 10) |
---|
1499 | |
---|
1500 | def _layout_stepsize(self): |
---|
1501 | """ |
---|
1502 | Fill the sizer containing slit size information |
---|
1503 | """ |
---|
1504 | self.stepsize = [] |
---|
1505 | omfdata = self.sld_data |
---|
1506 | if omfdata == None: |
---|
1507 | raise |
---|
1508 | key_list = self._get_step_key_list(omfdata) |
---|
1509 | is_data = self.sld_data.is_data |
---|
1510 | sizer = wx.GridBagSizer(2, 3) |
---|
1511 | ix = 0 |
---|
1512 | iy = -1 |
---|
1513 | #key_list.sort() |
---|
1514 | for key, value in key_list.iteritems(): |
---|
1515 | iy += 1 |
---|
1516 | ix = 0 |
---|
1517 | name = wx.StaticText(self, -1, key) |
---|
1518 | sizer.Add(name, (iy, ix), (1, 1), \ |
---|
1519 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
1520 | ## add parameter value |
---|
1521 | ix += 1 |
---|
1522 | ctl = InputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
---|
1523 | style=wx.TE_PROCESS_ENTER) |
---|
1524 | ctl.Bind(wx.EVT_TEXT, self._onstepsize) |
---|
1525 | ctl.SetValue(format_number(value, True)) |
---|
1526 | ctl.Enable(not is_data) |
---|
1527 | sizer.Add(ctl, (iy, ix), (1, 1), wx.EXPAND) |
---|
1528 | ## add unit |
---|
1529 | ix += 1 |
---|
1530 | p_unit = '[' + omfdata.pos_unit + ']' |
---|
1531 | unit = wx.StaticText(self, -1, p_unit) |
---|
1532 | sizer.Add(unit, (iy, ix), (1, 1), \ |
---|
1533 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
1534 | self.stepsize.append([key, ctl, unit]) |
---|
1535 | self.step_sizer.Add(sizer, 0, wx.LEFT, 10) |
---|
1536 | |
---|
1537 | def _layout_hint(self): |
---|
1538 | """ |
---|
1539 | Fill the sizer containing hint |
---|
1540 | """ |
---|
1541 | hint_msg = "Load an omf or 3d sld profile data file." |
---|
1542 | self.hint_txt = wx.StaticText(self, -1, hint_msg) |
---|
1543 | self.hint_sizer.AddMany([(self.hint_txt, 0, wx.LEFT, 15)]) |
---|
1544 | |
---|
1545 | def _layout_button(self): |
---|
1546 | """ |
---|
1547 | Do the layout for the button widgets |
---|
1548 | """ |
---|
1549 | self.bt_draw = wx.Button(self, wx.NewId(), 'Draw Points') |
---|
1550 | self.bt_draw.Bind(wx.EVT_BUTTON, self.on_sld_draw) |
---|
1551 | self.bt_draw.SetToolTipString("Draw a scatter plot for sld profile.") |
---|
1552 | self.bt_save = wx.Button(self, wx.NewId(), 'Save SLD Data') |
---|
1553 | self.bt_save.Bind(wx.EVT_BUTTON, self.on_save) |
---|
1554 | self.bt_save.Enable(False) |
---|
1555 | self.bt_save.SetToolTipString("Save SLD data.") |
---|
1556 | self.button_sizer.AddMany([(self.bt_draw, 0, wx.LEFT, 10), |
---|
1557 | (self.bt_save, 0, wx.LEFT, 10)]) |
---|
1558 | |
---|
1559 | def _do_layout(self): |
---|
1560 | """ |
---|
1561 | Draw omf panel content, used to define sld s. |
---|
1562 | |
---|
1563 | """ |
---|
1564 | self._define_structure() |
---|
1565 | self._layout_nodes() |
---|
1566 | self._layout_stepsize() |
---|
1567 | self._layout_npix() |
---|
1568 | self._layout_slds() |
---|
1569 | #self._layout_hint() |
---|
1570 | self._layout_button() |
---|
1571 | self.boxsizer_node.AddMany([(self.node_sizer, 0, |
---|
1572 | wx.EXPAND | wx.TOP, 5), |
---|
1573 | (self.hint_sizer, 0, |
---|
1574 | wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) |
---|
1575 | self.boxsizer_stepsize.AddMany([(self.step_sizer, 0, |
---|
1576 | wx.EXPAND | wx.TOP | wx.BOTTOM, 5), ]) |
---|
1577 | self.boxsizer_sld.AddMany([(self.sld_sizer, 0, |
---|
1578 | wx.EXPAND | wx.BOTTOM, 5), ]) |
---|
1579 | self.main_sizer.AddMany([(self.npixels_sizer, 0, wx.EXPAND | wx.ALL, 10), |
---|
1580 | (self.boxsizer_sld, 0, wx.EXPAND | wx.ALL, 10), |
---|
1581 | (self.boxsizer_node, 0, wx.EXPAND | wx.ALL, 10), |
---|
1582 | (self.boxsizer_stepsize, 0, wx.EXPAND | wx.ALL, 10), |
---|
1583 | (self.button_sizer, 0, wx.EXPAND | wx.TOP | wx.BOTTOM, 5)]) |
---|
1584 | self.SetSizer(self.main_sizer) |
---|
1585 | self.SetAutoLayout(True) |
---|
1586 | |
---|
1587 | def _get_nodes_key_list(self, data): |
---|
1588 | """ |
---|
1589 | Return nodes key list |
---|
1590 | |
---|
1591 | :Param data: OMFData |
---|
1592 | """ |
---|
1593 | key_list = {'xnodes' : data.xnodes, |
---|
1594 | 'ynodes' : data.ynodes, |
---|
1595 | 'znodes' : data.znodes} |
---|
1596 | return key_list |
---|
1597 | |
---|
1598 | def _get_slds_key_list(self, data): |
---|
1599 | """ |
---|
1600 | Return nodes key list |
---|
1601 | |
---|
1602 | :Param data: OMFData |
---|
1603 | """ |
---|
1604 | key_list = {'Nucl.' : data.sld_n, |
---|
1605 | 'Mx' : data.sld_mx, |
---|
1606 | 'My' : data.sld_my, |
---|
1607 | 'Mz' : data.sld_mz} |
---|
1608 | return key_list |
---|
1609 | |
---|
1610 | def _get_step_key_list(self, data): |
---|
1611 | """ |
---|
1612 | Return step key list |
---|
1613 | |
---|
1614 | :Param data: OMFData |
---|
1615 | """ |
---|
1616 | key_list = {'xstepsize' : data.xstepsize, |
---|
1617 | 'ystepsize' : data.ystepsize, |
---|
1618 | 'zstepsize' : data.zstepsize} |
---|
1619 | return key_list |
---|
1620 | |
---|
1621 | def set_sld_ctr(self, sld_data): |
---|
1622 | """ |
---|
1623 | Set sld textctrls |
---|
1624 | """ |
---|
1625 | if sld_data == None: |
---|
1626 | for ctr_list in self.slds: |
---|
1627 | ctr_list[1].Enable(False) |
---|
1628 | #break |
---|
1629 | return |
---|
1630 | |
---|
1631 | self.sld_data = sld_data |
---|
1632 | sld_list = self._get_slds_key_list(sld_data) |
---|
1633 | for ctr_list in self.slds: |
---|
1634 | for key in sld_list.keys(): |
---|
1635 | if ctr_list[0] == key: |
---|
1636 | min_val = numpy.min(sld_list[key]) |
---|
1637 | max_val = numpy.max(sld_list[key]) |
---|
1638 | mean_val = numpy.mean(sld_list[key]) |
---|
1639 | enable = (min_val == max_val) and \ |
---|
1640 | sld_data.pix_type == 'pixel' |
---|
1641 | ctr_list[1].SetValue(format_number(mean_val, True)) |
---|
1642 | ctr_list[1].Enable(enable) |
---|
1643 | #ctr_list[2].SetLabel("[" + sld_data.sld_unit + "]") |
---|
1644 | break |
---|
1645 | |
---|
1646 | def on_sld_draw(self, event): |
---|
1647 | """ |
---|
1648 | Draw sld profile as scattered plot |
---|
1649 | """ |
---|
1650 | self.parent.sld_draw() |
---|
1651 | |
---|
1652 | def on_save(self, event): |
---|
1653 | """ |
---|
1654 | Close the window containing this panel |
---|
1655 | """ |
---|
1656 | flag = True |
---|
1657 | flag = self.check_inputs() |
---|
1658 | if not flag: |
---|
1659 | return |
---|
1660 | self.sld_data = self.get_sld_val() |
---|
1661 | self.parent.set_main_panel_sld_data(self.sld_data) |
---|
1662 | |
---|
1663 | reader = sas_gen.SLDReader() |
---|
1664 | extension = '*.sld' |
---|
1665 | path = None |
---|
1666 | data = None |
---|
1667 | location = self.parent.get_path() |
---|
1668 | dlg = wx.FileDialog(self, "Save sld file", |
---|
1669 | location, "sld_file", |
---|
1670 | extension, |
---|
1671 | wx.SAVE) |
---|
1672 | if dlg.ShowModal() == wx.ID_OK: |
---|
1673 | path = dlg.GetPath() |
---|
1674 | self.parent.set_file_location(os.path.dirname(path)) |
---|
1675 | else: |
---|
1676 | return None |
---|
1677 | dlg.Destroy() |
---|
1678 | try: |
---|
1679 | if path is None: |
---|
1680 | return |
---|
1681 | |
---|
1682 | data = self.parent.get_sld_data() |
---|
1683 | fName = os.path.splitext(path)[0] + '.' + extension.split('.')[-1] |
---|
1684 | if data != None: |
---|
1685 | try: |
---|
1686 | reader.write(fName, data) |
---|
1687 | except: |
---|
1688 | raise |
---|
1689 | else: |
---|
1690 | msg = "%s cannot write %s\n" % ('Generic Scattering', str(path)) |
---|
1691 | infor = 'Error' |
---|
1692 | #logging.error(msg) |
---|
1693 | if self.parent.parent != None: |
---|
1694 | # inform msg to wx |
---|
1695 | wx.PostEvent(self.parent.parent, |
---|
1696 | StatusEvent(status=msg, info=infor)) |
---|
1697 | self.SetFocus() |
---|
1698 | return |
---|
1699 | except: |
---|
1700 | msg = "Error occurred while saving. " |
---|
1701 | infor = 'Error' |
---|
1702 | if self.parent.parent != None: |
---|
1703 | # inform msg to wx |
---|
1704 | wx.PostEvent(self.parent.parent, |
---|
1705 | StatusEvent(status=msg, info=infor)) |
---|
1706 | self.SetFocus() |
---|
1707 | |
---|
1708 | def _onparamEnter(self, event): |
---|
1709 | """ |
---|
1710 | """ |
---|
1711 | flag = True |
---|
1712 | if event != None: |
---|
1713 | event.Skip() |
---|
1714 | ctl = event.GetEventObject() |
---|
1715 | ctl.SetBackgroundColour("white") |
---|
1716 | #_set_error(self, ctl) |
---|
1717 | try: |
---|
1718 | float(ctl.GetValue()) |
---|
1719 | except: |
---|
1720 | flag = _set_error(self, ctl) |
---|
1721 | if flag: |
---|
1722 | npts = 1 |
---|
1723 | for item in self.nodes: |
---|
1724 | n_val = float(item[1].GetValue()) |
---|
1725 | if n_val <= 0: |
---|
1726 | item[1].SetBackgroundColour("pink") |
---|
1727 | npts = -1 |
---|
1728 | break |
---|
1729 | if numpy.isfinite(n_val): |
---|
1730 | npts *= int(n_val) |
---|
1731 | if npts > 0: |
---|
1732 | nop = self.set_npts_from_slddata() |
---|
1733 | if nop == None: |
---|
1734 | nop = npts |
---|
1735 | self.display_npts(nop) |
---|
1736 | |
---|
1737 | ctl.Refresh() |
---|
1738 | return flag |
---|
1739 | |
---|
1740 | def _set_volume_ctr_val(self, npts): |
---|
1741 | """ |
---|
1742 | Set total volume |
---|
1743 | """ |
---|
1744 | total_volume = npts * self.sld_data.vol_pix[0] |
---|
1745 | self.parent.set_volume_ctr_val(total_volume) |
---|
1746 | |
---|
1747 | def _onstepsize(self, event): |
---|
1748 | """ |
---|
1749 | On stepsize event |
---|
1750 | """ |
---|
1751 | flag = True |
---|
1752 | if event != None: |
---|
1753 | event.Skip() |
---|
1754 | ctl = event.GetEventObject() |
---|
1755 | ctl.SetBackgroundColour("white") |
---|
1756 | |
---|
1757 | if flag and not self.sld_data.is_data:#ctl.IsEnabled(): |
---|
1758 | s_size = 1.0 |
---|
1759 | try: |
---|
1760 | for item in self.stepsize: |
---|
1761 | s_val = float(item[1].GetValue()) |
---|
1762 | if s_val <= 0: |
---|
1763 | item[1].SetBackgroundColour("pink") |
---|
1764 | ctl.Refresh() |
---|
1765 | return |
---|
1766 | if numpy.isfinite(s_val): |
---|
1767 | s_size *= s_val |
---|
1768 | self.sld_data.set_pixel_volumes(s_size) |
---|
1769 | if ctl.IsEnabled(): |
---|
1770 | total_volume = sum(self.sld_data.vol_pix) |
---|
1771 | self.parent.set_volume_ctr_val(total_volume) |
---|
1772 | except: |
---|
1773 | pass |
---|
1774 | ctl.Refresh() |
---|
1775 | |
---|
1776 | |
---|
1777 | def set_npts_from_slddata(self): |
---|
1778 | """ |
---|
1779 | Set total n. of points form the sld data |
---|
1780 | """ |
---|
1781 | try: |
---|
1782 | sld_data = self.parent.get_sld_from_omf() |
---|
1783 | #nop = (nop * numpy.pi) / 6 |
---|
1784 | nop = len(sld_data.sld_n) |
---|
1785 | except: |
---|
1786 | nop = None |
---|
1787 | return nop |
---|
1788 | |
---|
1789 | def display_npts(self, nop): |
---|
1790 | """ |
---|
1791 | Displays Npts ctrl |
---|
1792 | """ |
---|
1793 | try: |
---|
1794 | self.npix_ctl.SetValue(str(nop)) |
---|
1795 | self.npix_ctl.Refresh() |
---|
1796 | self.parent.set_etime() |
---|
1797 | wx.CallAfter(self._set_volume_ctr_val, nop) |
---|
1798 | except: |
---|
1799 | # On Init |
---|
1800 | pass |
---|
1801 | |
---|
1802 | def check_inputs(self): |
---|
1803 | """ |
---|
1804 | check if the inputs are valid |
---|
1805 | """ |
---|
1806 | flag = self._check_input_helper(self.slds) |
---|
1807 | if flag: |
---|
1808 | flag = self._check_input_helper(self.nodes) |
---|
1809 | if flag: |
---|
1810 | flag = self._check_input_helper(self.stepsize) |
---|
1811 | return flag |
---|
1812 | |
---|
1813 | def _check_input_helper(self, list): |
---|
1814 | """ |
---|
1815 | Check list values |
---|
1816 | """ |
---|
1817 | flag = True |
---|
1818 | for item in list: |
---|
1819 | item[1].SetBackgroundColour("white") |
---|
1820 | item[1].Refresh() |
---|
1821 | try: |
---|
1822 | float(item[1].GetValue()) |
---|
1823 | except: |
---|
1824 | flag = _set_error(self, item[1]) |
---|
1825 | break |
---|
1826 | return flag |
---|
1827 | |
---|
1828 | class SasGenWindow(widget.CHILD_FRAME): |
---|
1829 | """ |
---|
1830 | GEN SAS main window |
---|
1831 | """ |
---|
1832 | def __init__(self, parent=None, manager=None, title="Generic Scattering Calculator", |
---|
1833 | size=(PANEL_WIDTH * 1.4, PANEL_HEIGHT * 1.65), *args, **kwds): |
---|
1834 | """ |
---|
1835 | Init |
---|
1836 | """ |
---|
1837 | kwds['size'] = size |
---|
1838 | kwds['title'] = title |
---|
1839 | widget.CHILD_FRAME.__init__(self, parent, *args, **kwds) |
---|
1840 | self.parent = parent |
---|
1841 | self.base = manager |
---|
1842 | self.omfpanel = OmfPanel(parent=self) |
---|
1843 | self.panel = SasGenPanel(parent=self) |
---|
1844 | self.data = None |
---|
1845 | self.omfdata = sas_gen.OMFData() |
---|
1846 | self.sld_data = None |
---|
1847 | self._default_save_location = os.getcwd() |
---|
1848 | |
---|
1849 | self._mgr = aui.AuiManager(self) |
---|
1850 | self._mgr.SetDockSizeConstraint(0.5, 0.5) |
---|
1851 | self._plot_title = '' |
---|
1852 | self.scale2d = 'log_{10}' |
---|
1853 | self.Bind(wx.EVT_CLOSE, self.on_close) |
---|
1854 | |
---|
1855 | |
---|
1856 | self.build_panels() |
---|
1857 | self.SetPosition((wx.LEFT, PANEL_TOP)) |
---|
1858 | self.Show(True) |
---|
1859 | |
---|
1860 | def build_panels(self): |
---|
1861 | """ |
---|
1862 | """ |
---|
1863 | |
---|
1864 | self.set_sld_data(self.sld_data) |
---|
1865 | self._mgr.AddPane(self.panel, aui.AuiPaneInfo(). |
---|
1866 | Name(self.panel.window_name). |
---|
1867 | CenterPane(). |
---|
1868 | # This is where we set the size of |
---|
1869 | # the application window |
---|
1870 | BestSize(wx.Size(PANEL_WIDTH, |
---|
1871 | PANEL_HEIGHT)). |
---|
1872 | Show()) |
---|
1873 | self._mgr.AddPane(self.omfpanel, aui.AuiPaneInfo(). |
---|
1874 | Name(self.omfpanel.window_name). |
---|
1875 | Caption(self.omfpanel.window_caption). |
---|
1876 | CloseButton(False). |
---|
1877 | Right(). |
---|
1878 | Floatable(False). |
---|
1879 | BestSize(wx.Size(PANEL_WIDTH / 2.5, PANEL_HEIGHT)). |
---|
1880 | Show()) |
---|
1881 | self._mgr.Update() |
---|
1882 | |
---|
1883 | def get_sld_data(self): |
---|
1884 | """ |
---|
1885 | Return slddata |
---|
1886 | """ |
---|
1887 | return self.sld_data |
---|
1888 | |
---|
1889 | def get_sld_from_omf(self): |
---|
1890 | """ |
---|
1891 | """ |
---|
1892 | self.sld_data = self.omfpanel.get_sld_val() |
---|
1893 | return self.sld_data |
---|
1894 | |
---|
1895 | def set_sld_n(self, sld): |
---|
1896 | """ |
---|
1897 | """ |
---|
1898 | self.panel.sld_data = sld |
---|
1899 | self.panel.model.set_sld_data(sld) |
---|
1900 | |
---|
1901 | def set_sld_data(self, data): |
---|
1902 | """ |
---|
1903 | Set omfdata |
---|
1904 | """ |
---|
1905 | if data == None: |
---|
1906 | return |
---|
1907 | self.sld_data = data |
---|
1908 | enable = (not data == None) |
---|
1909 | self._set_omfpanel_sld_data(self.sld_data) |
---|
1910 | self.omfpanel.bt_save.Enable(enable) |
---|
1911 | self.set_etime() |
---|
1912 | |
---|
1913 | def set_omfpanel_npts(self): |
---|
1914 | """ |
---|
1915 | Set Npts in omf panel |
---|
1916 | """ |
---|
1917 | nop = self.omfpanel.set_npts_from_slddata() |
---|
1918 | self.omfpanel.display_npts(nop) |
---|
1919 | |
---|
1920 | def _set_omfpanel_sld_data(self, data): |
---|
1921 | """ |
---|
1922 | Set sld_data in omf panel |
---|
1923 | """ |
---|
1924 | self.omfpanel.set_slddata(data) |
---|
1925 | self.omfpanel.set_sld_ctr(data) |
---|
1926 | |
---|
1927 | def check_omfpanel_inputs(self): |
---|
1928 | """ |
---|
1929 | Check OMF panel inputs |
---|
1930 | """ |
---|
1931 | return self.omfpanel.check_inputs() |
---|
1932 | |
---|
1933 | def set_main_panel_sld_data(self, sld_data): |
---|
1934 | """ |
---|
1935 | """ |
---|
1936 | self.sld_data = sld_data |
---|
1937 | |
---|
1938 | def set_file_location(self, path): |
---|
1939 | """ |
---|
1940 | File location |
---|
1941 | """ |
---|
1942 | self._default_save_location = path |
---|
1943 | |
---|
1944 | def get_path(self): |
---|
1945 | """ |
---|
1946 | File location |
---|
1947 | """ |
---|
1948 | return self._default_save_location |
---|
1949 | |
---|
1950 | def draw_graph(self, plot, title=''): |
---|
1951 | """ |
---|
1952 | """ |
---|
1953 | try: |
---|
1954 | wx.PostEvent(self.parent, NewPlotEvent(plot=plot, title=title)) |
---|
1955 | except: |
---|
1956 | # standalone |
---|
1957 | frame = PlotFrame(self, -1, 'testView', self.scale2d) |
---|
1958 | #add_icon(self.parent, frame) |
---|
1959 | frame.add_plot(plot) |
---|
1960 | frame.SetTitle(title) |
---|
1961 | frame.Show(True) |
---|
1962 | frame.SetFocus() |
---|
1963 | |
---|
1964 | def set_schedule_full_draw(self, panel=None, func='del'): |
---|
1965 | """ |
---|
1966 | Send full draw to gui frame |
---|
1967 | """ |
---|
1968 | if self.parent != None: |
---|
1969 | self.parent.set_schedule_full_draw(panel, func) |
---|
1970 | |
---|
1971 | def get_npix(self): |
---|
1972 | """ |
---|
1973 | Get no. of pixels from omf panel |
---|
1974 | """ |
---|
1975 | n_pix = self.omfpanel.npix_ctl.GetValue() |
---|
1976 | return n_pix |
---|
1977 | |
---|
1978 | def get_pix_volumes(self): |
---|
1979 | """ |
---|
1980 | Get a pixel volume |
---|
1981 | """ |
---|
1982 | vol = self.omfpanel.get_pix_volumes() |
---|
1983 | return vol |
---|
1984 | |
---|
1985 | def set_volume_ctr_val(self, val): |
---|
1986 | """ |
---|
1987 | Set volume txtctl value |
---|
1988 | """ |
---|
1989 | try: |
---|
1990 | self.panel.set_volume_ctl_val(str(val)) |
---|
1991 | except: |
---|
1992 | print "self.panel is not initialized yet" |
---|
1993 | |
---|
1994 | def set_omfpanel_default_shap(self, shape): |
---|
1995 | """ |
---|
1996 | Set default_shape in omfpanel |
---|
1997 | """ |
---|
1998 | self.omfpanel.default_shape = shape |
---|
1999 | |
---|
2000 | def set_etime(self): |
---|
2001 | """ |
---|
2002 | Sets est. computation time on panel |
---|
2003 | """ |
---|
2004 | self.panel.set_est_time() |
---|
2005 | |
---|
2006 | def get_sld_data_from_omf(self): |
---|
2007 | """ |
---|
2008 | """ |
---|
2009 | data = self.omfpanel.get_sld_val() |
---|
2010 | return data |
---|
2011 | |
---|
2012 | def set_scale2d(self, scale): |
---|
2013 | """ |
---|
2014 | """ |
---|
2015 | self.scale2d = scale |
---|
2016 | |
---|
2017 | def on_panel_close(self, event): |
---|
2018 | """ |
---|
2019 | """ |
---|
2020 | #Not implemented |
---|
2021 | |
---|
2022 | def on_open_file(self, event): |
---|
2023 | """ |
---|
2024 | On Open |
---|
2025 | """ |
---|
2026 | self.panel.on_load_data(event) |
---|
2027 | |
---|
2028 | def sld_draw(self): |
---|
2029 | """ |
---|
2030 | sld draw |
---|
2031 | """ |
---|
2032 | self.panel.sld_draw(event=None, has_arrow=False) |
---|
2033 | |
---|
2034 | def on_save_file(self, event): |
---|
2035 | """ |
---|
2036 | On Close |
---|
2037 | """ |
---|
2038 | self.omfpanel.on_save(event) |
---|
2039 | |
---|
2040 | def on_close(self, event): |
---|
2041 | """ |
---|
2042 | Close |
---|
2043 | """ |
---|
2044 | if self.base != None: |
---|
2045 | self.base.gen_frame = None |
---|
2046 | self.Destroy() |
---|
2047 | |
---|
2048 | if __name__ == "__main__": |
---|
2049 | app = wx.PySimpleApp() |
---|
2050 | widget.CHILD_FRAME = wx.Frame |
---|
2051 | SGframe = SasGenWindow() |
---|
2052 | SGframe.Show(True) |
---|
2053 | app.MainLoop() |
---|