Changeset 2f4b430 in sasview
- Timestamp:
-
Mar 4, 2015 3:39:45 PM
(10 years ago)
- Author:
- Doucet, Mathieu <doucetm@…>
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 74f419d
- Parents:
- 2f732b0
- Message:
-
Take care of white spaces (pylint)
- Location:
- src/sas/perspectives/fitting
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
-
rfa09d62
|
r2f4b430
|
|
1 | | """ |
| 1 | """ |
2 | 2 | Batch panel |
3 | 3 | """ |
… |
… |
|
5 | 5 | import wx.lib.newevent |
6 | 6 | import math |
7 | | from sas.guiframe.events import StatusEvent |
8 | | from sas.guiframe.events import NewPlotEvent |
9 | | |
10 | | (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() |
| 7 | from sas.guiframe.events import StatusEvent |
| 8 | from sas.guiframe.events import NewPlotEvent |
| 9 | |
| 10 | (Chi2UpdateEvent, EVT_CHI2_UPDATE) = wx.lib.newevent.NewEvent() |
11 | 11 | _BOX_WIDTH = 76 |
12 | 12 | _DATA_BOX_WIDTH = 300 |
… |
… |
|
24 | 24 | """ |
25 | 25 | window_name = "BatchFit" |
26 | | window_caption = "BatchFit" |
| 26 | window_caption = "BatchFit" |
27 | 27 | |
28 | 28 | def __init__(self, parent, color=None): |
29 | | """ |
| 29 | """ |
30 | 30 | Initialization of the Panel |
31 | 31 | """ |
32 | 32 | FitPage.__init__(self, parent, color=color) |
33 | | |
| 33 | |
34 | 34 | ## draw sizer |
35 | | |
| 35 | |
36 | 36 | def _fill_data_sizer(self): |
37 | 37 | """ |
… |
… |
|
53 | 53 | text2.SetForegroundColour(wx.RED) |
54 | 54 | sizer_data.Add(text2) |
55 | | |
| 55 | |
56 | 56 | combo = wx.BoxSizer(wx.HORIZONTAL) |
57 | 57 | self.dataSource = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
58 | 58 | wx.EVT_COMBOBOX(self.dataSource, -1, self.on_select_data) |
59 | 59 | self.dataSource.SetMinSize((_DATA_BOX_WIDTH, -1)) |
60 | | |
| 60 | |
61 | 61 | combo.Add(wx.StaticText(self, -1, 'Name : ')) |
62 | | combo.Add((0,5)) |
| 62 | combo.Add((0, 5)) |
63 | 63 | combo.Add(self.dataSource) |
64 | | |
| 64 | |
65 | 65 | sizer_data.Add(combo, 0, wx.ALL, 10) |
66 | 66 | boxsizer1.Add(sizer_data, 0, wx.ALL, 0) |
… |
… |
|
69 | 69 | |
70 | 70 | # COMMENTED OUT TO USE METHODS INHERITED FROM fitpage.py |
71 | | |
| 71 | |
72 | 72 | # def _fill_range_sizer(self): |
73 | 73 | # """ |
… |
… |
|
398 | 398 | # caption=self.window_name) |
399 | 399 | # self._draw_model() |
400 | | |
401 | | |
402 | | |
| 400 | |
| 401 | |
| 402 | |
403 | 403 | class BGTextCtrl(wx.TextCtrl): |
404 | 404 | """ |
405 | 405 | Text control used to display outputs. |
406 | | No editing allowed. The background is |
| 406 | No editing allowed. The background is |
407 | 407 | grayed out. User can't select text. |
408 | 408 | """ |
… |
… |
|
411 | 411 | self.SetEditable(False) |
412 | 412 | self.SetBackgroundColour(self.GetParent().parent.GetBackgroundColour()) |
413 | | |
| 413 | |
414 | 414 | # Bind to mouse event to avoid text highlighting |
415 | 415 | # The event will be skipped once the call-back |
416 | 416 | # is called. |
417 | 417 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
418 | | |
| 418 | |
419 | 419 | def _click(self, event): |
420 | 420 | """ |
421 | 421 | Prevent further handling of the mouse event |
422 | 422 | by not calling Skip(). |
423 | | """ |
| 423 | """ |
424 | 424 | pass |
425 | | |
| 425 | |
-
rb9a5f0e
|
r2f4b430
|
|
2 | 2 | |
3 | 3 | |
4 | | from sas.guiframe.events import StatusEvent |
| 4 | from sas.guiframe.events import StatusEvent |
5 | 5 | import time |
6 | 6 | import wx |
… |
… |
|
13 | 13 | isbetter = False |
14 | 14 | """Record whether results improved since last update""" |
15 | | progress_delta = 60 |
| 15 | progress_delta = 60 |
16 | 16 | """Number of seconds between progress updates""" |
17 | 17 | improvement_delta = 5 |
18 | 18 | """Number of seconds between improvement updates""" |
19 | 19 | def __init__(self, parent, manager=None, |
20 | | quiet=False,progress_delta=60,improvement_delta=5): |
| 20 | quiet=False, progress_delta=60, improvement_delta=5): |
21 | 21 | """ |
22 | 22 | If quiet is true, only print out final summary, not progress and |
23 | 23 | improvements. |
24 | | |
| 24 | |
25 | 25 | :attr parent: the object that handle the messages |
26 | | |
| 26 | |
27 | 27 | """ |
28 | | self.parent= parent |
| 28 | self.parent = parent |
29 | 29 | self.manager = manager |
30 | 30 | self.progress_time = time.time() |
… |
… |
|
38 | 38 | self.update_duration = time.time() |
39 | 39 | self.fit_duration = 0 |
40 | | |
41 | | |
| 40 | |
| 41 | |
42 | 42 | def progress(self, k, n): |
43 | 43 | """ |
… |
… |
|
47 | 47 | |
48 | 48 | t = time.time() |
49 | | p = int((100*k)//n) |
50 | | |
| 49 | p = int((100 * k) // n) |
| 50 | |
51 | 51 | # Show improvements if there are any |
52 | 52 | dt = t - self.improvement_time |
… |
… |
|
56 | 56 | self.isbetter = False |
57 | 57 | self.improvement_time = t |
58 | | |
| 58 | |
59 | 59 | # Update percent complete |
60 | | dp = p-self.progress_percent |
| 60 | dp = p - self.progress_percent |
61 | 61 | if dp < 1: return |
62 | 62 | dt = t - self.progress_time |
… |
… |
|
67 | 67 | self.update_fit() |
68 | 68 | elif 2 < dp <= 5: |
69 | | if p//5 != self.progress_percent//5: |
| 69 | if p // 5 != self.progress_percent // 5: |
70 | 70 | self.progress_percent = p |
71 | 71 | self.progress_time = t |
72 | 72 | else: |
73 | | if p//10 != self.progress_percent//10: |
| 73 | if p // 10 != self.progress_percent // 10: |
74 | 74 | self.progress_percent = p |
75 | 75 | self.progress_time = t |
76 | 76 | self.update_fit() |
77 | | |
| 77 | |
78 | 78 | def improvement(self): |
79 | 79 | """ |
… |
… |
|
82 | 82 | """ |
83 | 83 | self.isbetter = True |
84 | | |
| 84 | |
85 | 85 | def print_result(self): |
86 | 86 | """ |
… |
… |
|
89 | 89 | msg = " \n %s \n" % str(self.result) |
90 | 90 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
91 | | |
| 91 | |
92 | 92 | def error(self, msg): |
93 | 93 | """ |
… |
… |
|
112 | 112 | wx.PostEvent(self.parent, StatusEvent(status=message, |
113 | 113 | info="info", type="stop")) |
114 | | |
| 114 | |
115 | 115 | def finalize(self): |
116 | 116 | """ |
… |
… |
|
126 | 126 | #self.result.print_summary() |
127 | 127 | self.update_fit() |
128 | | |
129 | | |
| 128 | |
| 129 | |
130 | 130 | def update_fit(self, last=False): |
131 | 131 | """ |
132 | 132 | """ |
133 | 133 | t1 = time.time() |
134 | | self.elapsed_time = t1 - self.update_duration |
| 134 | self.elapsed_time = t1 - self.update_duration |
135 | 135 | self.update_duration = t1 |
136 | 136 | self.fit_duration += self.elapsed_time |
… |
… |
|
147 | 147 | d_flag = (hasattr(self.result, "data") and \ |
148 | 148 | self.result.data is not None and \ |
149 | | hasattr(self.result.data, "sas_data") and |
| 149 | hasattr(self.result.data, "sas_data") and |
150 | 150 | self.result.data.sas_data is not None) |
151 | 151 | m_flag = (hasattr(self.result, "model") and \ |
… |
… |
|
156 | 156 | model_name = str(self.result.model.name) |
157 | 157 | if m_flag and d_flag: |
158 | | msg += "Data : %s \n" % (str(data_name))#, |
| 158 | msg += "Data : %s \n" % (str(data_name))#, |
159 | 159 | #str(model_name)) |
160 | | msg += str(self.result) |
| 160 | msg += str(self.result) |
161 | 161 | msg += "\n" |
162 | 162 | else: |
… |
… |
|
164 | 164 | wx.PostEvent(self.parent, StatusEvent(status=msg, info="info", |
165 | 165 | type="progress")) |
166 | | |
| 166 | |
167 | 167 | def starting_fit(self): |
168 | 168 | """ |
169 | 169 | """ |
170 | 170 | wx.PostEvent(self.parent, StatusEvent(status="Starting the Fit...", |
171 | | info="info",type="progress")) |
172 | | |
| 171 | info="info", type="progress")) |
| 172 | |
173 | 173 | def set_result(self, result): |
174 | 174 | """ |
175 | 175 | """ |
176 | 176 | self.result = result |
177 | | |
| 177 | |
178 | 178 | def get_result(self): |
179 | 179 | """ |
180 | 180 | """ |
181 | 181 | return self.result |
182 | | |
183 | | |
| 182 | |
| 183 | |
-
r386ffe1
|
r2f4b430
|
|
9 | 9 | Execute class.function and return result |
10 | 10 | """ |
11 | | return getattr(classInstance,classFunc)(*args) |
| 11 | return getattr(classInstance, classFunc)(*args) |
12 | 12 | |
13 | 13 | def map_apply(arguments): |
… |
… |
|
16 | 16 | class FitThread(CalcThread): |
17 | 17 | """Thread performing the fit """ |
18 | | |
19 | | def __init__(self, |
| 18 | |
| 19 | def __init__(self, |
20 | 20 | fn, |
21 | 21 | page_id, |
… |
… |
|
24 | 24 | batch_inputs=None, |
25 | 25 | pars=None, |
26 | | completefn = None, |
27 | | updatefn = None, |
28 | | yieldtime = 0.03, |
29 | | worktime = 0.03, |
30 | | reset_flag = False): |
| 26 | completefn=None, |
| 27 | updatefn=None, |
| 28 | yieldtime=0.03, |
| 29 | worktime=0.03, |
| 30 | reset_flag=False): |
31 | 31 | CalcThread.__init__(self, |
32 | 32 | completefn, |
… |
… |
|
44 | 44 | #Relative error desired in the sum of squares. |
45 | 45 | self.reset_flag = reset_flag |
46 | | |
| 46 | |
47 | 47 | def isquit(self): |
48 | 48 | """ |
49 | 49 | :raise KeyboardInterrupt: when the thread is interrupted |
50 | | |
| 50 | |
51 | 51 | """ |
52 | 52 | try: |
… |
… |
|
55 | 55 | msg = "Fitting: terminated by the user." |
56 | 56 | raise KeyboardInterrupt, msg |
57 | | |
| 57 | |
58 | 58 | def compute(self): |
59 | 59 | """ |
60 | | Perform a fit |
| 60 | Perform a fit |
61 | 61 | """ |
62 | 62 | msg = "" |
… |
… |
|
64 | 64 | import copy |
65 | 65 | list_handler = [] |
66 | | list_curr_thread = [] |
| 66 | list_curr_thread = [] |
67 | 67 | list_reset_flag = [] |
68 | 68 | list_map_get_attr = [] |
… |
… |
|
78 | 78 | #from multiprocessing import Pool |
79 | 79 | inputs = zip(list_map_get_attr, self.fitter, list_fit_function, |
80 | | list_q, list_q, list_handler,list_curr_thread, |
| 80 | list_q, list_q, list_handler, list_curr_thread, |
81 | 81 | list_reset_flag) |
82 | | result = map(map_apply, inputs) |
83 | | |
| 82 | result = map(map_apply, inputs) |
| 83 | |
84 | 84 | self.complete(result=result, |
85 | 85 | batch_inputs=self.batch_inputs, |
86 | 86 | batch_outputs=self.batch_outputs, |
87 | 87 | page_id=self.page_id, |
88 | | pars = self.pars, |
89 | | elapsed=time.time()-self.starttime) |
90 | | |
| 88 | pars=self.pars, |
| 89 | elapsed=time.time() - self.starttime) |
| 90 | |
91 | 91 | except KeyboardInterrupt, msg: |
92 | 92 | # Thread was interrupted, just proceed and re-raise. |
… |
… |
|
95 | 95 | #Stop on exception during fitting. Todo: need to put |
96 | 96 | #some mssg and reset progress bar. |
97 | | |
| 97 | |
98 | 98 | if self.handler is not None: |
99 | 99 | self.handler.stop(msg=msg) |
… |
… |
|
102 | 102 | if self.handler is not None: |
103 | 103 | self.handler.error(msg=traceback.format_exc()) |
104 | | |
105 | | |
106 | | |
| 104 | |
| 105 | |
| 106 | |
-
r386ffe1
|
r2f4b430
|
|
32 | 32 | FitPanel class contains fields allowing to display results when |
33 | 33 | fitting a model and one data |
34 | | |
| 34 | |
35 | 35 | :note: For Fit to be performed the user should check at least one parameter |
36 | 36 | on fit Panel window. |
… |
… |
|
42 | 42 | """ |
43 | 43 | BasicPage.__init__(self, parent, color=color) |
44 | | |
| 44 | |
45 | 45 | ## draw sizer |
46 | 46 | self._fill_data_sizer() |
… |
… |
|
69 | 69 | self.create_default_data() |
70 | 70 | #self._manager.frame.Bind(wx.EVT_SET_FOCUS, self.on_set_focus) |
71 | | |
| 71 | |
72 | 72 | def enable_fit_button(self): |
73 | 73 | """ |
… |
… |
|
76 | 76 | flag = check_data_validity(self.data) & (self.model is not None) |
77 | 77 | self.btFit.Enable(flag) |
78 | | |
| 78 | |
79 | 79 | def _fill_data_sizer(self): |
80 | 80 | """ |
… |
… |
|
99 | 99 | self.sizer0.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) |
100 | 100 | self.sizer0.Layout() |
101 | | |
| 101 | |
102 | 102 | def enable_datasource(self): |
103 | 103 | """ |
… |
… |
|
108 | 108 | else: |
109 | 109 | self.dataSource.Enable() |
110 | | |
| 110 | |
111 | 111 | def fill_data_combobox(self, data_list): |
112 | 112 | """ |
… |
… |
|
143 | 143 | if len(data_list) == 1: |
144 | 144 | self.dataSource.Disable() |
145 | | |
| 145 | |
146 | 146 | def on_select_data(self, event=None): |
147 | 147 | """ |
… |
… |
|
155 | 155 | data = self.dataSource.GetClientData(pos) |
156 | 156 | self.set_data(data) |
157 | | |
| 157 | |
158 | 158 | def _on_fit_complete(self): |
159 | 159 | """ |
… |
… |
|
162 | 162 | self.fit_started = False |
163 | 163 | self.set_fitbutton() |
164 | | |
| 164 | |
165 | 165 | def _is_2D(self): |
166 | 166 | """ |
167 | 167 | Check if data_name is Data2D |
168 | | |
| 168 | |
169 | 169 | :return: True or False |
170 | | |
| 170 | |
171 | 171 | """ |
172 | 172 | if self.data.__class__.__name__ == "Data2D" or \ |
… |
… |
|
174 | 174 | return True |
175 | 175 | return False |
176 | | |
| 176 | |
177 | 177 | def _on_engine_change(self, name): |
178 | 178 | """ |
… |
… |
|
180 | 180 | and update the panel accordingly |
181 | 181 | """ |
182 | | |
| 182 | |
183 | 183 | self.engine_type = str(name) |
184 | 184 | self.state.engine_type = self.engine_type |
… |
… |
|
189 | 189 | self.Layout() |
190 | 190 | self.Refresh() |
191 | | |
| 191 | |
192 | 192 | def _fill_range_sizer(self): |
193 | 193 | """ |
… |
… |
|
196 | 196 | """ |
197 | 197 | is_2Ddata = False |
198 | | |
| 198 | |
199 | 199 | # Check if data is 2D |
200 | 200 | if self.data.__class__.__name__ == "Data2D" or \ |
201 | 201 | self.enable2D: |
202 | 202 | is_2Ddata = True |
203 | | |
| 203 | |
204 | 204 | title = "Fitting" |
205 | 205 | #smear messages & titles |
… |
… |
|
218 | 218 | smear_message_slit_height_title = "Slit height[1/A]:" |
219 | 219 | smear_message_slit_width_title = "Slit width[1/A]:" |
220 | | |
| 220 | |
221 | 221 | self._get_smear_info() |
222 | | |
| 222 | |
223 | 223 | #Sizers |
224 | 224 | box_description_range = wx.StaticBox(self, -1, str(title)) |
… |
… |
|
233 | 233 | sizer_smearer_box = wx.StaticBoxSizer(smear_set_box, wx.HORIZONTAL) |
234 | 234 | sizer_smearer_box.SetMinSize((_DATA_BOX_WIDTH, 60)) |
235 | | |
| 235 | |
236 | 236 | weighting_set_box = wx.StaticBox(self, -1, \ |
237 | 237 | 'Set Weighting by Selecting dI Source') |
… |
… |
|
268 | 268 | self.dI_idata.Enable(False) |
269 | 269 | weighting_box.Add(sizer_weighting) |
270 | | |
| 270 | |
271 | 271 | sizer_fit = wx.GridSizer(2, 4, 2, 6) |
272 | | |
| 272 | |
273 | 273 | # combobox for smear2d accuracy selection |
274 | 274 | self.smear_accuracy = wx.ComboBox(self, -1, size=(50, -1), |
… |
… |
|
279 | 279 | self.smear_accuracy.SetToolTipString(\ |
280 | 280 | "'Higher' uses more Gaussian points for smearing computation.") |
281 | | |
| 281 | |
282 | 282 | wx.EVT_COMBOBOX(self.smear_accuracy, -1, self._on_select_accuracy) |
283 | 283 | |
… |
… |
|
287 | 287 | self.btFit.Bind(wx.EVT_BUTTON, self._onFit, id=self.btFit.GetId()) |
288 | 288 | self.btFit.SetToolTipString("Start fitting.") |
289 | | |
| 289 | |
290 | 290 | #textcntrl for custom resolution |
291 | 291 | self.smear_pinhole_max = self.ModelTextCtrl(self, -1, |
… |
… |
|
343 | 343 | id=self.slit_smearer.GetId()) |
344 | 344 | self.disable_smearer.SetValue(True) |
345 | | |
| 345 | |
346 | 346 | # add 4 types of smearing to the sizer |
347 | 347 | sizer_smearer.Add(self.disable_smearer, 0, wx.LEFT, 10) |
… |
… |
|
353 | 353 | sizer_smearer.Add(self.slit_smearer) |
354 | 354 | sizer_smearer.Add((10, 10)) |
355 | | |
| 355 | |
356 | 356 | # StaticText for chi2, N(for fitting), Npts + Log/linear spacing |
357 | 357 | self.tcChi = BGTextCtrl(self, -1, "-", size=(75, 20), style=0) |
… |
… |
|
367 | 367 | self.Npts_total.SetToolTipString(\ |
368 | 368 | " Total Npts : total number of data points") |
369 | | |
| 369 | |
370 | 370 | # Update and Draw button |
371 | 371 | self.draw_button = wx.Button(self, wx.NewId(), |
… |
… |
|
374 | 374 | self._onDraw, id=self.draw_button.GetId()) |
375 | 375 | self.draw_button.SetToolTipString("Compute and Draw.") |
376 | | |
377 | | self.points_sizer = wx.BoxSizer(wx.HORIZONTAL) |
| 376 | |
| 377 | self.points_sizer = wx.BoxSizer(wx.HORIZONTAL) |
378 | 378 | self.pointsbox = wx.CheckBox(self, -1, 'Log?', (10, 10)) |
379 | 379 | self.pointsbox.SetValue(False) |
380 | 380 | self.pointsbox.SetToolTipString("Check mark to use log spaced points") |
381 | 381 | wx.EVT_CHECKBOX(self, self.pointsbox.GetId(), self.select_log) |
382 | | |
| 382 | |
383 | 383 | self.points_sizer.Add(wx.StaticText(self, -1, 'Npts ')) |
384 | 384 | self.points_sizer.Add(self.pointsbox) |
… |
… |
|
389 | 389 | #box_description_3.SetToolTipString( \ |
390 | 390 | # " Total Npts : total number of data points") |
391 | | |
| 391 | |
392 | 392 | sizer_fit.Add(box_description_1, 0, 0) |
393 | 393 | sizer_fit.Add(box_description_2, 0, 0) |
… |
… |
|
404 | 404 | smear_message_none, style=wx.ALIGN_LEFT) |
405 | 405 | self.smear_description_dqdata = wx.StaticText(self, |
406 | | -1, smear_message_dqdata, style=wx.ALIGN_LEFT) |
| 406 | - 1, smear_message_dqdata, style=wx.ALIGN_LEFT) |
407 | 407 | self.smear_description_type = wx.StaticText(self, |
408 | | -1, "Type:", style=wx.ALIGN_LEFT) |
| 408 | - 1, "Type:", style=wx.ALIGN_LEFT) |
409 | 409 | self.smear_description_accuracy_type = wx.StaticText(self, -1, |
410 | 410 | "Accuracy:", style=wx.ALIGN_LEFT) |
… |
… |
|
435 | 435 | self.smear_description_slit_width = wx.StaticText(self, -1, |
436 | 436 | smear_message_slit_width_title, style=wx.ALIGN_LEFT) |
437 | | |
| 437 | |
438 | 438 | #arrange sizers |
439 | 439 | self.sizer_set_smearer.Add(sizer_smearer) |
… |
… |
|
468 | 468 | self.sizer_new_smear.Add((20, -1)) |
469 | 469 | self.sizer_new_smear.Add(self.smear_description_2d_y, |
470 | | 0, wx.CENTER, 10 ) |
| 470 | 0, wx.CENTER, 10) |
471 | 471 | self.sizer_new_smear.Add(self.smear_description_pin_max, |
472 | | 0, wx.CENTER, 10 ) |
| 472 | 0, wx.CENTER, 10) |
473 | 473 | self.sizer_new_smear.Add(self.smear_description_slit_width, |
474 | | 0, wx.CENTER, 10 ) |
| 474 | 0, wx.CENTER, 10) |
475 | 475 | |
476 | 476 | self.sizer_new_smear.Add(self.smear_pinhole_max, 0, wx.CENTER, 10) |
477 | 477 | self.sizer_new_smear.Add(self.smear_slit_width, 0, wx.CENTER, 10) |
478 | 478 | self.sizer_new_smear.Add(self.smear_data_right, 0, wx.CENTER, 10) |
479 | | |
| 479 | |
480 | 480 | self.sizer_set_smearer.Add(self.smear_message_new_s, 0, wx.CENTER, 10) |
481 | 481 | self.sizer_set_smearer.Add(self.smear_message_new_p, 0, wx.CENTER, 10) |
482 | 482 | self.sizer_set_smearer.Add((5, 2)) |
483 | 483 | self.sizer_set_smearer.Add(self.sizer_new_smear, 0, wx.CENTER, 10) |
484 | | |
| 484 | |
485 | 485 | # add all to chi2 sizer |
486 | 486 | sizer_smearer_box.Add(self.sizer_set_smearer) |
… |
… |
|
489 | 489 | sizer_chi2.Add(weighting_box) |
490 | 490 | sizer_chi2.Add((-1, 5)) |
491 | | |
| 491 | |
492 | 492 | # hide all smear messages and textctrl |
493 | 493 | self._hide_all_smear_info() |
494 | | |
| 494 | |
495 | 495 | # get smear_selection |
496 | 496 | self.current_smearer = smear_selection(self.data, self.model) |
… |
… |
|
513 | 513 | #2D data? default |
514 | 514 | is_2Ddata = False |
515 | | |
| 515 | |
516 | 516 | #check if it is 2D data |
517 | 517 | if self.data.__class__.__name__ == "Data2D" or self.enable2D: |
518 | 518 | is_2Ddata = True |
519 | | |
| 519 | |
520 | 520 | self.sizer5.Clear(True) |
521 | | |
| 521 | |
522 | 522 | self.qmin = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
523 | 523 | style=wx.TE_PROCESS_ENTER, |
… |
… |
|
530 | 530 | qmin_tip += q_tip |
531 | 531 | self.qmin.SetToolTipString(qmin_tip) |
532 | | |
| 532 | |
533 | 533 | self.qmax = self.ModelTextCtrl(self, -1, size=(_BOX_WIDTH, 20), |
534 | 534 | style=wx.TE_PROCESS_ENTER, |
… |
… |
|
548 | 548 | id = wx.NewId() |
549 | 549 | self.reset_qrange = wx.Button(self, id, 'Reset', size=(77, 20)) |
550 | | |
| 550 | |
551 | 551 | self.reset_qrange.Bind(wx.EVT_BUTTON, self.on_reset_clicked, id=id) |
552 | 552 | self.reset_qrange.SetToolTipString("Reset Q range to the default") |
553 | | |
| 553 | |
554 | 554 | sizer = wx.GridSizer(2, 4, 2, 6) |
555 | 555 | |
… |
… |
|
559 | 559 | self.btEditMask.SetToolTipString("Edit Mask.") |
560 | 560 | self.EditMask_title = wx.StaticText(self, -1, ' Masking(2D)') |
561 | | |
| 561 | |
562 | 562 | sizer.Add(wx.StaticText(self, -1, ' Q range')) |
563 | 563 | sizer.Add(wx.StaticText(self, -1, ' Min[1/A]')) |
… |
… |
|
572 | 572 | boxsizer_range.Add((10, 10)) |
573 | 573 | boxsizer_range.Add(sizer) |
574 | | |
| 574 | |
575 | 575 | boxsizer_range.Add((10, 15)) |
576 | 576 | boxsizer_range.Add(sizer_fit) |
… |
… |
|
586 | 586 | self.sizer5.Layout() |
587 | 587 | |
588 | | |
| 588 | |
589 | 589 | def _set_sizer_dispersion(self): |
590 | 590 | """ |
… |
… |
|
602 | 602 | ## the user didn't select dispersity display |
603 | 603 | return |
604 | | |
| 604 | |
605 | 605 | self._reset_dispersity() |
606 | | |
| 606 | |
607 | 607 | ## fill a sizer with the combobox to select dispersion type |
608 | 608 | model_disp = wx.StaticText(self, -1, 'Function') |
… |
… |
|
632 | 632 | self.sizer4_4.Add(self.text_disp_1, (iy, ix), (1, 1), \ |
633 | 633 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
634 | | |
| 634 | |
635 | 635 | ix += 1 |
636 | 636 | self.text_disp_min = wx.StaticText(self, -1, 'Min') |
… |
… |
|
642 | 642 | self.sizer4_4.Add(self.text_disp_max, (iy, ix), (1, 1), |
643 | 643 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
644 | | |
| 644 | |
645 | 645 | ix += 1 |
646 | 646 | npts = wx.StaticText(self, -1, 'Npts') |
… |
… |
|
660 | 660 | self.sizer4_4.Add(model_disp, (iy, ix), (1, 1), |
661 | 661 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
662 | | |
| 662 | |
663 | 663 | self.text_disp_max.Show(True) |
664 | 664 | self.text_disp_min.Show(True) |
… |
… |
|
680 | 680 | iy += 1 |
681 | 681 | for p in self.model.dispersion[item].keys(): |
682 | | |
| 682 | |
683 | 683 | if p == "width": |
684 | 684 | ix = 0 |
… |
… |
|
713 | 713 | size=(_BOX_WIDTH / 1.3, 20), |
714 | 714 | style=0) |
715 | | |
| 715 | |
716 | 716 | self.sizer4_4.Add(ctl2, (iy, ix), (1, 1), |
717 | 717 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
… |
… |
|
724 | 724 | style=wx.TE_PROCESS_ENTER, |
725 | 725 | text_enter_callback=self._onparamRangeEnter) |
726 | | |
| 726 | |
727 | 727 | self.sizer4_4.Add(ctl3, (iy, ix), (1, 1), |
728 | 728 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
729 | | |
| 729 | |
730 | 730 | ix = 5 |
731 | 731 | ctl4 = self.ModelTextCtrl(self, -1, |
… |
… |
|
733 | 733 | style=wx.TE_PROCESS_ENTER, |
734 | 734 | text_enter_callback=self._onparamRangeEnter) |
735 | | |
| 735 | |
736 | 736 | self.sizer4_4.Add(ctl4, (iy, ix), (1, 1), |
737 | 737 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
… |
… |
|
739 | 739 | ctl3.Show(True) |
740 | 740 | ctl4.Show(True) |
741 | | |
| 741 | |
742 | 742 | elif p == "npts": |
743 | 743 | ix = 6 |
… |
… |
|
746 | 746 | size=(_BOX_WIDTH / 2.2, 20), |
747 | 747 | style=wx.TE_PROCESS_ENTER) |
748 | | |
| 748 | |
749 | 749 | Tctl.SetValue(str(format_number(value))) |
750 | 750 | self.sizer4_4.Add(Tctl, (iy, ix), (1, 1), |
… |
… |
|
758 | 758 | size=(_BOX_WIDTH / 2.2, 20), |
759 | 759 | style=wx.TE_PROCESS_ENTER) |
760 | | |
| 760 | |
761 | 761 | Tct2.SetValue(str(format_number(value))) |
762 | 762 | self.sizer4_4.Add(Tct2, (iy, ix), (1, 1), |
… |
… |
|
777 | 777 | self.fittable_param.append([cb, name1, ctl1, text2, |
778 | 778 | ctl2, ctl3, ctl4, disp_box]) |
779 | | |
| 779 | |
780 | 780 | ix = 0 |
781 | 781 | iy += 1 |
… |
… |
|
794 | 794 | name2 = item + ".npts" |
795 | 795 | name3 = item + ".nsigmas" |
796 | | |
| 796 | |
797 | 797 | if not name1 in self.model.details: |
798 | 798 | self.model.details[name1] = ["", None, None] |
799 | | |
| 799 | |
800 | 800 | iy += 1 |
801 | 801 | for p in self.model.dispersion[item].keys(): |
802 | | |
| 802 | |
803 | 803 | if p == "width": |
804 | 804 | ix = 0 |
… |
… |
|
832 | 832 | poly_text += "It is the STD (ratio*mean)" |
833 | 833 | poly_text += " of the distribution.\n " |
834 | | |
| 834 | |
835 | 835 | values.SetToolTipString(poly_text) |
836 | 836 | first_orient = False |
… |
… |
|
838 | 838 | elif ctl1.IsShown(): |
839 | 839 | ctl1.Hide() |
840 | | |
| 840 | |
841 | 841 | self.sizer4_4.Add(ctl1, (iy, ix), (1, 1), wx.EXPAND) |
842 | 842 | ## text to show error sign |
… |
… |
|
852 | 852 | size=(_BOX_WIDTH / 1.3, 20), |
853 | 853 | style=0) |
854 | | |
| 854 | |
855 | 855 | self.sizer4_4.Add(ctl2, (iy, ix), (1, 1), |
856 | 856 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
… |
… |
|
862 | 862 | text2.Show(True) |
863 | 863 | ctl2.Show(True) |
864 | | |
| 864 | |
865 | 865 | ix = 4 |
866 | 866 | ctl3 = self.ModelTextCtrl(self, -1, |
… |
… |
|
873 | 873 | |
874 | 874 | ctl3.Hide() |
875 | | |
| 875 | |
876 | 876 | ix = 5 |
877 | 877 | ctl4 = self.ModelTextCtrl(self, -1, |
… |
… |
|
882 | 882 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
883 | 883 | ctl4.Hide() |
884 | | |
| 884 | |
885 | 885 | if self.data.__class__.__name__ == "Data2D" or \ |
886 | 886 | self.enable2D: |
887 | 887 | ctl3.Show(True) |
888 | 888 | ctl4.Show(True) |
889 | | |
| 889 | |
890 | 890 | elif p == "npts": |
891 | 891 | ix = 6 |
… |
… |
|
894 | 894 | size=(_BOX_WIDTH / 2.2, 20), |
895 | 895 | style=wx.TE_PROCESS_ENTER) |
896 | | |
| 896 | |
897 | 897 | Tctl.SetValue(str(format_number(value))) |
898 | 898 | if self.data.__class__.__name__ == "Data2D" or \ |
… |
… |
|
914 | 914 | size=(_BOX_WIDTH / 2.2, 20), |
915 | 915 | style=wx.TE_PROCESS_ENTER) |
916 | | |
| 916 | |
917 | 917 | Tct2.SetValue(str(format_number(value))) |
918 | 918 | if self.data.__class__.__name__ == "Data2D" or \ |
… |
… |
|
926 | 926 | self.fixed_param.append([None, name3, Tct2, |
927 | 927 | None, None, None, None, None]) |
928 | | |
| 928 | |
929 | 929 | self.orientation_params_disp.append([None, name3, |
930 | 930 | Tct2, None, None, None, None, None]) |
… |
… |
|
943 | 943 | self.orientation_params_disp.append([cb, name1, ctl1, |
944 | 944 | text2, ctl2, ctl3, ctl4, disp_box]) |
945 | | |
| 945 | |
946 | 946 | if self.data.__class__.__name__ == "Data2D" or \ |
947 | 947 | self.enable2D: |
… |
… |
|
949 | 949 | else: |
950 | 950 | disp_box.Hide() |
951 | | |
| 951 | |
952 | 952 | self.state.disp_cb_dict = copy.deepcopy(self.disp_cb_dict) |
953 | | |
| 953 | |
954 | 954 | self.state.model = self.model.clone() |
955 | 955 | ## save state into |
… |
… |
|
984 | 984 | """ |
985 | 985 | flag = self._update_paramv_on_fit() |
986 | | |
| 986 | |
987 | 987 | wx.CallAfter(self._onparamEnter_helper) |
988 | 988 | if not flag: |
… |
… |
|
990 | 990 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
991 | 991 | return |
992 | | |
| 992 | |
993 | 993 | def _onFit(self, event): |
994 | 994 | """ |
… |
… |
|
1015 | 1015 | StatusEvent(status="Fit: %s" % msg, type="stop")) |
1016 | 1016 | return |
1017 | | |
| 1017 | |
1018 | 1018 | if len(self.param_toFit) <= 0: |
1019 | 1019 | msg = "Select at least one parameter to fit" |
… |
… |
|
1022 | 1022 | StatusEvent(status=msg, type="stop")) |
1023 | 1023 | return |
1024 | | |
| 1024 | |
1025 | 1025 | flag = self._update_paramv_on_fit() |
1026 | | |
| 1026 | |
1027 | 1027 | if self.batch_on and not self._is_2D(): |
1028 | 1028 | if not self._validate_Npts_1D(): |
1029 | 1029 | return |
1030 | | |
| 1030 | |
1031 | 1031 | if not flag: |
1032 | 1032 | msg = "Fitting range or parameters are invalid" |
… |
… |
|
1034 | 1034 | StatusEvent(status=msg, type="stop")) |
1035 | 1035 | return |
1036 | | |
| 1036 | |
1037 | 1037 | self.select_param(event=None) |
1038 | 1038 | |
… |
… |
|
1050 | 1050 | self.fit_started = self._manager.onFit(uid=self.uid) |
1051 | 1051 | wx.CallAfter(self.set_fitbutton) |
1052 | | |
| 1052 | |
1053 | 1053 | def set_fitbutton(self): |
1054 | 1054 | """ |
… |
… |
|
1059 | 1059 | if self.is_mac: |
1060 | 1060 | return |
1061 | | |
| 1061 | |
1062 | 1062 | if self.fit_started: |
1063 | 1063 | label = "Stop" |
… |
… |
|
1070 | 1070 | self.btFit.SetForegroundColour(color) |
1071 | 1071 | self.btFit.Enable(True) |
1072 | | |
| 1072 | |
1073 | 1073 | def get_weight_flag(self): |
1074 | 1074 | """ |
… |
… |
|
1092 | 1092 | break |
1093 | 1093 | return flag |
1094 | | |
| 1094 | |
1095 | 1095 | def _StopFit(self, event=None): |
1096 | 1096 | """ |
… |
… |
|
1102 | 1102 | self._manager._reset_schedule_problem(value=0) |
1103 | 1103 | self._on_fit_complete() |
1104 | | |
| 1104 | |
1105 | 1105 | def rename_model(self): |
1106 | 1106 | """ |
… |
… |
|
1109 | 1109 | if self.model is not None: |
1110 | 1110 | self.model.name = "M" + str(self.index_model) |
1111 | | |
| 1111 | |
1112 | 1112 | def _on_select_model(self, event=None): |
1113 | 1113 | """ |
… |
… |
|
1141 | 1141 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
1142 | 1142 | self.state.slit_smearer = self.slit_smearer.GetValue() |
1143 | | |
| 1143 | |
1144 | 1144 | self.state.structurecombobox = self.structurebox.GetLabel() |
1145 | 1145 | self.state.formfactorcombobox = self.formfactorbox.GetLabel() |
… |
… |
|
1161 | 1161 | self.disable_smearer.SetValue(True) |
1162 | 1162 | self.enable_smearer.SetValue(False) |
1163 | | |
| 1163 | |
1164 | 1164 | # more disables for 2D |
1165 | 1165 | self._set_smear_buttons() |
1166 | | |
| 1166 | |
1167 | 1167 | try: |
1168 | 1168 | # update smearer sizer |
… |
… |
|
1180 | 1180 | ## event to post model to fit to fitting plugins |
1181 | 1181 | (ModelEventbox, EVT_MODEL_BOX) = wx.lib.newevent.NewEvent() |
1182 | | |
| 1182 | |
1183 | 1183 | ## set smearing value whether or not |
1184 | 1184 | # the data contain the smearing info |
… |
… |
|
1190 | 1190 | caption=self.window_caption, |
1191 | 1191 | qmax=float(self.qmax_x)) |
1192 | | |
| 1192 | |
1193 | 1193 | self._manager._on_model_panel(evt=evt) |
1194 | | self.mbox_description.SetLabel("Model [ %s ]"% str(self.model.name)) |
| 1194 | self.mbox_description.SetLabel("Model [ %s ]" % str(self.model.name)) |
1195 | 1195 | self.mbox_description.SetForegroundColour(wx.BLUE) |
1196 | 1196 | self.state.model = self.model.clone() |
… |
… |
|
1225 | 1225 | self.get_paste_params(copy_flag) |
1226 | 1226 | wx.CallAfter(self._onDraw, None) |
1227 | | |
| 1227 | |
1228 | 1228 | else: |
1229 | 1229 | self._draw_model() |
1230 | | |
| 1230 | |
1231 | 1231 | if self.batch_on: |
1232 | 1232 | self.slit_smearer.Enable(False) |
… |
… |
|
1234 | 1234 | self.btEditMask.Disable() |
1235 | 1235 | self.EditMask_title.Disable() |
1236 | | |
| 1236 | |
1237 | 1237 | self.Show(True) |
1238 | 1238 | self.SetupScrolling() |
1239 | | |
| 1239 | |
1240 | 1240 | def _onparamEnter(self, event): |
1241 | 1241 | """ |
… |
… |
|
1282 | 1282 | if flag: |
1283 | 1283 | #self.compute_chisqr(smearer= temp_smearer) |
1284 | | |
| 1284 | |
1285 | 1285 | ## new state posted |
1286 | 1286 | if self.state_change: |
… |
… |
|
1297 | 1297 | msg = "Cannot Plot :Must enter a number!!! " |
1298 | 1298 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
1299 | | |
| 1299 | |
1300 | 1300 | self.save_current_state() |
1301 | 1301 | return |
1302 | | |
| 1302 | |
1303 | 1303 | def _onparamRangeEnter(self, event): |
1304 | 1304 | """ |
… |
… |
|
1323 | 1323 | else: |
1324 | 1324 | tcrtl.SetBackgroundColour(wx.WHITE) |
1325 | | |
| 1325 | |
1326 | 1326 | #self._undo.Enable(True) |
1327 | 1327 | self.save_current_state() |
… |
… |
|
1329 | 1329 | wx.PostEvent(self.parent, event) |
1330 | 1330 | self.state_change = False |
1331 | | |
1332 | | def qrang_set_focus(self, event=None): |
| 1331 | |
| 1332 | def qrang_set_focus(self, event=None): |
1333 | 1333 | """ |
1334 | 1334 | ON Qrange focus |
… |
… |
|
1338 | 1338 | #tcrtl = event.GetEventObject() |
1339 | 1339 | self._validate_qrange(self.qmin, self.qmax) |
1340 | | |
| 1340 | |
1341 | 1341 | def qrange_click(self, event): |
1342 | 1342 | """ |
… |
… |
|
1352 | 1352 | d_group_id = self.data.group_id |
1353 | 1353 | act_ctrl = event.GetEventObject() |
1354 | | wx.PostEvent(self._manager.parent, |
1355 | | PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, |
| 1354 | wx.PostEvent(self._manager.parent, |
| 1355 | PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, |
1356 | 1356 | group_id=d_group_id, leftdown=is_click, |
1357 | 1357 | active=act_ctrl)) |
1358 | | |
| 1358 | |
1359 | 1359 | def on_qrange_text(self, event): |
1360 | 1360 | """ |
… |
… |
|
1368 | 1368 | d_id = self.data.id |
1369 | 1369 | d_group_id = self.data.group_id |
1370 | | wx.PostEvent(self._manager.parent, |
1371 | | PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, |
1372 | | group_id=d_group_id, leftdown=False, |
| 1370 | wx.PostEvent(self._manager.parent, |
| 1371 | PlotQrangeEvent(ctrl=[self.qmin, self.qmax], id=d_id, |
| 1372 | group_id=d_group_id, leftdown=False, |
1373 | 1373 | active=act_ctrl)) |
1374 | 1374 | self._validate_qrange(self.qmin, self.qmax) |
1375 | | |
1376 | | def on_key(self, event): |
| 1375 | |
| 1376 | def on_key(self, event): |
1377 | 1377 | """ |
1378 | 1378 | On Key down |
… |
… |
|
1385 | 1385 | x_data = float(ctrl.GetValue()) |
1386 | 1386 | except: |
1387 | | return |
| 1387 | return |
1388 | 1388 | key = event.GetKeyCode() |
1389 | 1389 | length = len(self.data.x) |
… |
… |
|
1402 | 1402 | ctrl.SetValue(str(self.data.x[indx])) |
1403 | 1403 | self._validate_qrange(self.qmin, self.qmax) |
1404 | | |
| 1404 | |
1405 | 1405 | def _onQrangeEnter(self, event): |
1406 | 1406 | """ |
… |
… |
|
1463 | 1463 | (self.data.x <= self.qmax_x)) |
1464 | 1464 | self.Npts_fit.SetValue(str(len(self.data.x[index_data]))) |
1465 | | |
| 1465 | |
1466 | 1466 | self.npts_x = self.Npts_total.GetValue() |
1467 | 1467 | self.create_default_data() |
… |
… |
|
1471 | 1471 | msg = "Model Error:wrong value entered!!!" |
1472 | 1472 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
1473 | | |
| 1473 | |
1474 | 1474 | self._draw_model() |
1475 | 1475 | self.save_current_state() |
… |
… |
|
1478 | 1478 | self.state_change = False |
1479 | 1479 | return |
1480 | | |
| 1480 | |
1481 | 1481 | def _clear_Err_on_Fit(self): |
1482 | 1482 | """ |
… |
… |
|
1508 | 1508 | if item[4] != None and item[4].IsShown(): |
1509 | 1509 | item[4].Hide() |
1510 | | |
| 1510 | |
1511 | 1511 | if len(self.fittable_param) > 0: |
1512 | 1512 | for item in self.fittable_param: |
… |
… |
|
1528 | 1528 | item[4].Hide() |
1529 | 1529 | return |
1530 | | |
| 1530 | |
1531 | 1531 | def _get_defult_custom_smear(self): |
1532 | 1532 | """ |
… |
… |
|
1542 | 1542 | if self.dx_max == None: |
1543 | 1543 | self.dx_max = SMEAR_SIZE_H |
1544 | | |
| 1544 | |
1545 | 1545 | def _get_smear_info(self): |
1546 | 1546 | """ |
1547 | 1547 | Get the smear info from data. |
1548 | | |
| 1548 | |
1549 | 1549 | :return: self.smear_type, self.dq_l and self.dq_r, |
1550 | 1550 | respectively the type of the smear, dq_min and |
… |
… |
|
1577 | 1577 | self.dq_l = data.dx[0] |
1578 | 1578 | self.dq_r = data.dx[-1] |
1579 | | |
| 1579 | |
1580 | 1580 | # check if it is slit smear and get min max if it is. |
1581 | 1581 | elif data.dxl != None or data.dxw != None: |
… |
… |
|
1586 | 1586 | self.dq_r = data.dxw[0] |
1587 | 1587 | #return self.smear_type,self.dq_l,self.dq_r |
1588 | | |
| 1588 | |
1589 | 1589 | def _show_smear_sizer(self): |
1590 | 1590 | """ |
… |
… |
|
1650 | 1650 | self.smear_description_2d_y.Hide() |
1651 | 1651 | self.smear_description_2d.Hide() |
1652 | | |
| 1652 | |
1653 | 1653 | self.smear_accuracy.Hide() |
1654 | 1654 | self.smear_data_left.Hide() |
… |
… |
|
1664 | 1664 | self.smear_message_new_p.Hide() |
1665 | 1665 | self.smear_message_new_s.Hide() |
1666 | | |
| 1666 | |
1667 | 1667 | def _set_accuracy_list(self): |
1668 | 1668 | """ |
… |
… |
|
1674 | 1674 | for idx in range(len(list)): |
1675 | 1675 | self.smear_accuracy.Append(list[idx], idx) |
1676 | | |
| 1676 | |
1677 | 1677 | def _set_fun_box_list(self, fun_box): |
1678 | 1678 | """ |
… |
… |
|
1695 | 1695 | break |
1696 | 1696 | ind += 1 |
1697 | | |
| 1697 | |
1698 | 1698 | def _on_select_accuracy(self, event): |
1699 | 1699 | """ |
… |
… |
|
1710 | 1710 | if self.current_smearer != None: |
1711 | 1711 | self.current_smearer.set_accuracy(accuracy=\ |
1712 | | self.smear2d_accuracy) |
| 1712 | self.smear2d_accuracy) |
1713 | 1713 | event.Skip() |
1714 | 1714 | |
… |
… |
|
1735 | 1735 | # get ready for new event |
1736 | 1736 | event.Skip() |
1737 | | |
| 1737 | |
1738 | 1738 | def _onMask(self, event): |
1739 | 1739 | """ |
… |
… |
|
1742 | 1742 | from sas.guiframe.local_perspectives.plotting.masking \ |
1743 | 1743 | import MaskPanel as MaskDialog |
1744 | | |
| 1744 | |
1745 | 1745 | self.panel = MaskDialog(base=self, data=self.data, id=wx.NewId()) |
1746 | 1746 | self.panel.ShowModal() |
1747 | | |
| 1747 | |
1748 | 1748 | def _draw_masked_model(self, event): |
1749 | 1749 | """ |
… |
… |
|
1797 | 1797 | """ |
1798 | 1798 | return self.enable2D |
1799 | | |
| 1799 | |
1800 | 1800 | def compute_data_set_range(self, data_list): |
1801 | 1801 | """ |
… |
… |
|
1810 | 1810 | self.npts_data_set += npts |
1811 | 1811 | return self.qmin_data_set, self.qmax_data_set, self.npts_data_set |
1812 | | |
| 1812 | |
1813 | 1813 | def compute_data_range(self, data): |
1814 | 1814 | """ |
… |
… |
|
1826 | 1826 | npts = len(data.x) |
1827 | 1827 | except: |
1828 | | msg = "Unable to find min/max/length of \n data named %s"% \ |
1829 | | data.filename |
| 1828 | msg = "Unable to find min/max/length of \n data named %s" % \ |
| 1829 | data.filename |
1830 | 1830 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg, |
1831 | 1831 | info="error")) |
1832 | 1832 | raise ValueError, msg |
1833 | | |
| 1833 | |
1834 | 1834 | else: |
1835 | 1835 | qmin = 0 |
… |
… |
|
1838 | 1838 | y = max(math.fabs(data.ymin), math.fabs(data.ymax)) |
1839 | 1839 | except: |
1840 | | msg = "Unable to find min/max of \n data named %s"% \ |
1841 | | data.filename |
| 1840 | msg = "Unable to find min/max of \n data named %s" % \ |
| 1841 | data.filename |
1842 | 1842 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg, |
1843 | 1843 | info="error")) |
… |
… |
|
1847 | 1847 | npts = len(data.data) |
1848 | 1848 | return qmin, qmax, npts |
1849 | | |
| 1849 | |
1850 | 1850 | def set_data(self, data): |
1851 | 1851 | """ |
… |
… |
|
1874 | 1874 | self.graph_id = data.group_id |
1875 | 1875 | self.data.group_id = self.graph_id |
1876 | | |
| 1876 | |
1877 | 1877 | if self.data is None: |
1878 | 1878 | data_name = "" |
… |
… |
|
1884 | 1884 | self._set_bookmark_flag(not self.batch_on) |
1885 | 1885 | self._keep.Enable(not self.batch_on) |
1886 | | if self.data.is_data: |
| 1886 | if self.data.is_data: |
1887 | 1887 | self._set_save_flag(True) |
1888 | 1888 | self._set_preview_flag(True) |
… |
… |
|
1922 | 1922 | self.dI_sqrdata.Enable(True) |
1923 | 1923 | self.dI_idata.Enable(True) |
1924 | | |
| 1924 | |
1925 | 1925 | self.formfactorbox.Enable() |
1926 | 1926 | self.structurebox.Enable() |
… |
… |
|
1934 | 1934 | self.btEditMask.Enable() |
1935 | 1935 | self.EditMask_title.Enable() |
1936 | | |
| 1936 | |
1937 | 1937 | self.Npts_total.SetValue(str(npts)) |
1938 | 1938 | #default:number of data points selected to fit |
… |
… |
|
1941 | 1941 | self.Npts_total.SetBackgroundColour(\ |
1942 | 1942 | self.GetParent().GetBackgroundColour()) |
1943 | | |
| 1943 | |
1944 | 1944 | self.Npts_total.Bind(wx.EVT_MOUSE_EVENTS, self._npts_click) |
1945 | 1945 | self.pointsbox.Disable() |
… |
… |
|
1952 | 1952 | if check_data_validity(data): |
1953 | 1953 | self.data_box_description.SetForegroundColour(wx.BLUE) |
1954 | | |
| 1954 | |
1955 | 1955 | if self.batch_on: |
1956 | 1956 | self.slit_smearer.Enable(False) |
… |
… |
|
1988 | 1988 | title=str(self.data.title))) |
1989 | 1989 | self._draw_model() |
1990 | | |
| 1990 | |
1991 | 1991 | def _npts_click(self, event): |
1992 | 1992 | """ |
… |
… |
|
1995 | 1995 | """ |
1996 | 1996 | pass |
1997 | | |
| 1997 | |
1998 | 1998 | def reset_page(self, state, first=False): |
1999 | 1999 | """ |
… |
… |
|
2002 | 2002 | try: |
2003 | 2003 | self.reset_page_helper(state) |
2004 | | |
| 2004 | |
2005 | 2005 | self.select_param(event=None) |
2006 | 2006 | #Save state_fit |
… |
… |
|
2010 | 2010 | msg = "Error: This model state has missing or outdated " |
2011 | 2011 | msg += "information.\n" |
2012 | | msg += "%s"% (sys.exc_value) |
| 2012 | msg += "%s" % (sys.exc_value) |
2013 | 2013 | wx.PostEvent(self._manager.parent, |
2014 | 2014 | StatusEvent(status=msg, info="error")) |
2015 | 2015 | self._lay_out() |
2016 | 2016 | self.Refresh() |
2017 | | |
| 2017 | |
2018 | 2018 | def get_range(self): |
2019 | 2019 | """ |
… |
… |
|
2021 | 2021 | """ |
2022 | 2022 | return float(self.qmin_x), float(self.qmax_x) |
2023 | | |
| 2023 | |
2024 | 2024 | def get_npts2fit(self): |
2025 | 2025 | """ |
2026 | 2026 | return numbers of data points within qrange |
2027 | | |
| 2027 | |
2028 | 2028 | :Note: This is to normalize chisq by Npts of fit |
2029 | | |
| 2029 | |
2030 | 2030 | """ |
2031 | 2031 | if self.data is None: |
… |
… |
|
2052 | 2052 | """ |
2053 | 2053 | self.Npts_fit.SetValue(str(self.get_npts2fit())) |
2054 | | |
| 2054 | |
2055 | 2055 | def get_chi2(self): |
2056 | 2056 | """ |
… |
… |
|
2058 | 2058 | """ |
2059 | 2059 | return self.tcChi.GetValue() |
2060 | | |
| 2060 | |
2061 | 2061 | def onsetValues(self, chisqr, p_name, out, cov): |
2062 | 2062 | """ |
2063 | 2063 | Build the panel from the fit result |
2064 | | |
| 2064 | |
2065 | 2065 | :param chisqr: Value of the goodness of fit metric |
2066 | 2066 | :param p_name: the name of parameters |
2067 | 2067 | :param out: list of parameter with the best value found during fitting |
2068 | 2068 | :param cov: Covariance matrix |
2069 | | |
2070 | | """ |
2071 | | |
| 2069 | |
| 2070 | """ |
| 2071 | |
2072 | 2072 | # make sure stop button to fit button all the time |
2073 | 2073 | self._on_fit_complete() |
2074 | 2074 | if out == None or not numpy.isfinite(chisqr): |
2075 | 2075 | raise ValueError, "Fit error occured..." |
2076 | | |
| 2076 | |
2077 | 2077 | is_modified = False |
2078 | 2078 | has_error = False |
2079 | 2079 | dispersity = '' |
2080 | | |
| 2080 | |
2081 | 2081 | #Hide textctrl boxes of errors. |
2082 | 2082 | self._clear_Err_on_Fit() |
2083 | | |
| 2083 | |
2084 | 2084 | #Check if chi2 is finite |
2085 | 2085 | if chisqr != None and numpy.isfinite(chisqr): |
… |
… |
|
2090 | 2090 | else: |
2091 | 2091 | self.tcChi.SetValue("-") |
2092 | | |
| 2092 | |
2093 | 2093 | #Hide error title |
2094 | 2094 | if self.text2_3.IsShown() and not self.is_mac: |
2095 | 2095 | self.text2_3.Hide() |
2096 | | |
| 2096 | |
2097 | 2097 | try: |
2098 | 2098 | if self.enable_disp.GetValue(): |
… |
… |
|
2103 | 2103 | dispersity = None |
2104 | 2104 | pass |
2105 | | |
| 2105 | |
2106 | 2106 | i = 0 |
2107 | 2107 | #Set the panel when fit result are list |
… |
… |
|
2121 | 2121 | val_out = format_number(out[ind], True) |
2122 | 2122 | item[2].SetValue(val_out) |
2123 | | |
| 2123 | |
2124 | 2124 | if(cov != None and len(cov) == len(out)): |
2125 | 2125 | try: |
… |
… |
|
2133 | 2133 | except: |
2134 | 2134 | pass |
2135 | | |
| 2135 | |
2136 | 2136 | if cov[ind] != None: |
2137 | 2137 | if numpy.isfinite(float(cov[ind])): |
… |
… |
|
2160 | 2160 | ## save current state |
2161 | 2161 | self.save_current_state() |
2162 | | |
| 2162 | |
2163 | 2163 | if not self.is_mac: |
2164 | 2164 | self.Layout() |
… |
… |
|
2167 | 2167 | #plot model ( when drawing, do not update chisqr value again) |
2168 | 2168 | self._draw_model(update_chisqr=False, source='fit') |
2169 | | |
| 2169 | |
2170 | 2170 | def onWeighting(self, event): |
2171 | 2171 | """ |
… |
… |
|
2174 | 2174 | self.weightbt_string = event.GetEventObject().GetLabelText() |
2175 | 2175 | self._set_weight() |
2176 | | |
| 2176 | |
2177 | 2177 | def _set_weight(self, is_2D=None): |
2178 | 2178 | """ |
… |
… |
|
2191 | 2191 | is2d=is_2D, |
2192 | 2192 | fid=None) |
2193 | | |
| 2193 | |
2194 | 2194 | def onPinholeSmear(self, event): |
2195 | 2195 | """ |
2196 | 2196 | Create a custom pinhole smear object that will change the way residuals |
2197 | 2197 | are compute when fitting |
2198 | | |
| 2198 | |
2199 | 2199 | :Note: accuracy is given by strings'High','Med', 'Low' FOR 2d, |
2200 | 2200 | None for 1D |
2201 | | |
| 2201 | |
2202 | 2202 | """ |
2203 | 2203 | if self.model == None: |
… |
… |
|
2232 | 2232 | # hide all silt sizer |
2233 | 2233 | self._hide_all_smear_info() |
2234 | | |
| 2234 | |
2235 | 2235 | # show relevant slit sizers |
2236 | 2236 | self._show_smear_sizer() |
… |
… |
|
2238 | 2238 | self.sizer_set_smearer.Layout() |
2239 | 2239 | self.Layout() |
2240 | | |
| 2240 | |
2241 | 2241 | if event != None: |
2242 | 2242 | event.Skip() |
… |
… |
|
2245 | 2245 | event = PageInfoEvent(page=self) |
2246 | 2246 | wx.PostEvent(self.parent, event) |
2247 | | |
| 2247 | |
2248 | 2248 | def _is_changed_pinhole(self): |
2249 | 2249 | """ |
2250 | 2250 | check if any of pinhole smear is changed |
2251 | | |
| 2251 | |
2252 | 2252 | :return: True or False |
2253 | | |
| 2253 | |
2254 | 2254 | """ |
2255 | 2255 | # get the values |
2256 | 2256 | pin_min = self.smear_pinhole_min.GetValue() |
2257 | 2257 | pin_max = self.smear_pinhole_max.GetValue() |
2258 | | |
| 2258 | |
2259 | 2259 | # Check changes in slit width |
2260 | 2260 | try: |
… |
… |
|
2264 | 2264 | if self.dx_min != dx_min: |
2265 | 2265 | return True |
2266 | | |
| 2266 | |
2267 | 2267 | # Check changes in slit heigth |
2268 | 2268 | try: |
… |
… |
|
2273 | 2273 | return True |
2274 | 2274 | return False |
2275 | | |
| 2275 | |
2276 | 2276 | def _set_pinhole_smear(self): |
2277 | 2277 | """ |
2278 | 2278 | Set custom pinhole smear |
2279 | | |
| 2279 | |
2280 | 2280 | :return: msg |
2281 | | |
| 2281 | |
2282 | 2282 | """ |
2283 | 2283 | # copy data |
… |
… |
|
2295 | 2295 | data.dxw = None |
2296 | 2296 | msg = None |
2297 | | |
| 2297 | |
2298 | 2298 | get_pin_min = self.smear_pinhole_min |
2299 | 2299 | get_pin_max = self.smear_pinhole_max |
… |
… |
|
2349 | 2349 | get_pin_max.SetBackgroundColour("white") |
2350 | 2350 | ## set smearing value whether or not the data contain the smearing info |
2351 | | |
| 2351 | |
2352 | 2352 | self._manager.set_smearer(smearer=self.current_smearer, |
2353 | 2353 | fid=self.data.id, |
… |
… |
|
2357 | 2357 | uid=self.uid) |
2358 | 2358 | return msg |
2359 | | |
| 2359 | |
2360 | 2360 | def update_pinhole_smear(self): |
2361 | 2361 | """ |
2362 | 2362 | called by kill_focus on pinhole TextCntrl |
2363 | 2363 | to update the changes |
2364 | | |
| 2364 | |
2365 | 2365 | :return: False when wrong value was entered |
2366 | | |
| 2366 | |
2367 | 2367 | """ |
2368 | 2368 | # msg default |
… |
… |
|
2377 | 2377 | else: |
2378 | 2378 | return True |
2379 | | |
| 2379 | |
2380 | 2380 | def onSlitSmear(self, event): |
2381 | 2381 | """ |
… |
… |
|
2410 | 2410 | else: |
2411 | 2411 | is_new_slit = True |
2412 | | |
| 2412 | |
2413 | 2413 | # if any value is changed |
2414 | 2414 | if is_new_slit: |
2415 | 2415 | msg = self._set_slit_smear() |
2416 | | |
| 2416 | |
2417 | 2417 | # hide all silt sizer |
2418 | 2418 | self._hide_all_smear_info() |
… |
… |
|
2433 | 2433 | """ |
2434 | 2434 | check if any of slit lengths is changed |
2435 | | |
| 2435 | |
2436 | 2436 | :return: True or False |
2437 | | |
| 2437 | |
2438 | 2438 | """ |
2439 | 2439 | # get the values |
2440 | 2440 | width = self.smear_slit_width.GetValue() |
2441 | 2441 | height = self.smear_slit_height.GetValue() |
2442 | | |
| 2442 | |
2443 | 2443 | # check and change the box bg color if it was pink |
2444 | 2444 | # but it should be white now |
… |
… |
|
2448 | 2448 | if width.lstrip().rstrip() == "": |
2449 | 2449 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
2450 | | |
| 2450 | |
2451 | 2451 | # Check changes in slit width |
2452 | 2452 | if width == "": |
… |
… |
|
2459 | 2459 | if self.dxw != dxw: |
2460 | 2460 | return True |
2461 | | |
| 2461 | |
2462 | 2462 | # Check changes in slit heigth |
2463 | 2463 | if height == "": |
… |
… |
|
2472 | 2472 | |
2473 | 2473 | return False |
2474 | | |
| 2474 | |
2475 | 2475 | def _set_slit_smear(self): |
2476 | 2476 | """ |
2477 | 2477 | Set custom slit smear |
2478 | | |
| 2478 | |
2479 | 2479 | :return: message to inform the user about the validity |
2480 | 2480 | of the values entered for slit smear |
… |
… |
|
2490 | 2490 | data.dxw = None |
2491 | 2491 | msg = None |
2492 | | |
| 2492 | |
2493 | 2493 | try: |
2494 | 2494 | self.dxl = float(self.smear_slit_height.GetValue()) |
… |
… |
|
2515 | 2515 | else: |
2516 | 2516 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
2517 | | |
| 2517 | |
2518 | 2518 | self.current_smearer = smear_selection(data, self.model) |
2519 | 2519 | ## set smearing value whether or not the data contain the smearing info |
… |
… |
|
2525 | 2525 | uid=self.uid) |
2526 | 2526 | return msg |
2527 | | |
| 2527 | |
2528 | 2528 | def update_slit_smear(self): |
2529 | 2529 | """ |
2530 | 2530 | called by kill_focus on pinhole TextCntrl |
2531 | 2531 | to update the changes |
2532 | | |
| 2532 | |
2533 | 2533 | :return: False when wrong value was entered |
2534 | | |
| 2534 | |
2535 | 2535 | """ |
2536 | 2536 | # msg default |
… |
… |
|
2546 | 2546 | else: |
2547 | 2547 | return True |
2548 | | |
| 2548 | |
2549 | 2549 | def onSmear(self, event): |
2550 | 2550 | """ |
… |
… |
|
2572 | 2572 | self._manager.page_finder[self.uid].add_data(data=self.data) |
2573 | 2573 | temp_smearer = self.on_smear_helper() |
2574 | | |
| 2574 | |
2575 | 2575 | self.sizer_set_smearer.Layout() |
2576 | 2576 | self.Layout() |
2577 | 2577 | self._set_weight() |
2578 | | |
| 2578 | |
2579 | 2579 | ## set smearing value whether or not the data contain the smearing info |
2580 | 2580 | wx.CallAfter(self._manager.set_smearer, uid=self.uid, |
… |
… |
|
2585 | 2585 | enable_smearer=not self.disable_smearer.GetValue(), |
2586 | 2586 | draw=True) |
2587 | | |
| 2587 | |
2588 | 2588 | self.state.enable_smearer = self.enable_smearer.GetValue() |
2589 | 2589 | self.state.disable_smearer = self.disable_smearer.GetValue() |
2590 | 2590 | self.state.pinhole_smearer = self.pinhole_smearer.GetValue() |
2591 | 2591 | self.state.slit_smearer = self.slit_smearer.GetValue() |
2592 | | |
| 2592 | |
2593 | 2593 | def on_smear_helper(self, update=False): |
2594 | 2594 | """ |
2595 | 2595 | Help for onSmear |
2596 | | |
| 2596 | |
2597 | 2597 | :param update: force or not to update |
2598 | 2598 | """ |
… |
… |
|
2606 | 2606 | self._hide_all_smear_info() |
2607 | 2607 | data = copy.deepcopy(self.data) |
2608 | | |
| 2608 | |
2609 | 2609 | # make sure once more if it is smearer |
2610 | 2610 | temp_smearer = smear_selection(data, self.model) |
… |
… |
|
2629 | 2629 | self.onSlitSmear(None) |
2630 | 2630 | self._show_smear_sizer() |
2631 | | |
| 2631 | |
2632 | 2632 | return temp_smearer |
2633 | | |
| 2633 | |
2634 | 2634 | def on_complete_chisqr(self, event): |
2635 | 2635 | """ |
… |
… |
|
2648 | 2648 | except: |
2649 | 2649 | pass |
2650 | | |
| 2650 | |
2651 | 2651 | def get_all_checked_params(self): |
2652 | 2652 | """ |
… |
… |
|
2664 | 2664 | self.param_toFit.append(item) |
2665 | 2665 | self.save_current_state_fit() |
2666 | | |
| 2666 | |
2667 | 2667 | event = PageInfoEvent(page=self) |
2668 | 2668 | wx.PostEvent(self.parent, event) |
… |
… |
|
2672 | 2672 | param2fit.append(item[1]) |
2673 | 2673 | self._manager.set_param2fit(self.uid, param2fit) |
2674 | | |
| 2674 | |
2675 | 2675 | def select_all_param(self, event): |
2676 | 2676 | """ |
… |
… |
|
2706 | 2706 | except: |
2707 | 2707 | pass |
2708 | | |
| 2708 | |
2709 | 2709 | else: |
2710 | 2710 | ## for 1D all parameters except orientation |
… |
… |
|
2726 | 2726 | item[0].SetValue(False) |
2727 | 2727 | self.param_toFit = [] |
2728 | | |
| 2728 | |
2729 | 2729 | self.save_current_state_fit() |
2730 | | |
| 2730 | |
2731 | 2731 | if event != None: |
2732 | 2732 | #self._undo.Enable(True) |
… |
… |
|
2739 | 2739 | param2fit.append(item[1]) |
2740 | 2740 | self.parent._manager.set_param2fit(self.uid, param2fit) |
2741 | | |
| 2741 | |
2742 | 2742 | def select_param(self, event): |
2743 | 2743 | """ |
… |
… |
|
2792 | 2792 | else: |
2793 | 2793 | self.cb1.SetValue(False) |
2794 | | |
| 2794 | |
2795 | 2795 | self.save_current_state_fit() |
2796 | 2796 | if event != None: |
… |
… |
|
2798 | 2798 | event = PageInfoEvent(page=self) |
2799 | 2799 | wx.PostEvent(self.parent, event) |
2800 | | |
| 2800 | |
2801 | 2801 | param2fit = [] |
2802 | 2802 | for item in self.param_toFit: |
… |
… |
|
2804 | 2804 | param2fit.append(item[1]) |
2805 | 2805 | self._manager.set_param2fit(self.uid, param2fit) |
2806 | | |
| 2806 | |
2807 | 2807 | def set_model_param_sizer(self, model): |
2808 | 2808 | """ |
2809 | 2809 | Build the panel from the model content |
2810 | | |
| 2810 | |
2811 | 2811 | :param model: the model selected in combo box for fitting purpose |
2812 | | |
| 2812 | |
2813 | 2813 | """ |
2814 | 2814 | self.sizer3.Clear(True) |
… |
… |
|
2820 | 2820 | self.orientation_params = [] |
2821 | 2821 | self.orientation_params_disp = [] |
2822 | | |
| 2822 | |
2823 | 2823 | if model == None: |
2824 | 2824 | self.sizer3.Layout() |
… |
… |
|
2834 | 2834 | ## save the current model |
2835 | 2835 | self.model = model |
2836 | | |
| 2836 | |
2837 | 2837 | keys = self.model.getParamList() |
2838 | | |
| 2838 | |
2839 | 2839 | #list of dispersion parameters |
2840 | 2840 | self.disp_list = self.model.getDispParamList() |
… |
… |
|
2892 | 2892 | |
2893 | 2893 | keys.sort(custom_compare) |
2894 | | |
| 2894 | |
2895 | 2895 | iy = 0 |
2896 | 2896 | ix = 0 |
… |
… |
|
2900 | 2900 | self.cb1.SetToolTipString("To check/uncheck all the boxes below.") |
2901 | 2901 | self.cb1.SetValue(True) |
2902 | | |
| 2902 | |
2903 | 2903 | sizer.Add(self.cb1, (iy, ix), (1, 1), \ |
2904 | 2904 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
… |
… |
|
2928 | 2928 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
2929 | 2929 | self.text2_4.Hide() |
2930 | | |
| 2930 | |
2931 | 2931 | CHECK_STATE = self.cb1.GetValue() |
2932 | 2932 | for item in keys: |
2933 | | |
| 2933 | |
2934 | 2934 | if not item in self.disp_list and not item in \ |
2935 | 2935 | self.model.orientation_params: |
2936 | | |
| 2936 | |
2937 | 2937 | ##prepare a spot to store errors |
2938 | 2938 | if not item in self.model.details: |
2939 | 2939 | self.model.details[item] = ["", None, None] |
2940 | | |
| 2940 | |
2941 | 2941 | iy += 1 |
2942 | 2942 | ix = 0 |
… |
… |
|
2978 | 2978 | #cb.SetValue(True) |
2979 | 2979 | wx.EVT_CHECKBOX(self, cb.GetId(), self.select_param) |
2980 | | |
| 2980 | |
2981 | 2981 | sizer.Add(cb, (iy, ix), (1, 1), |
2982 | 2982 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
… |
… |
|
3017 | 3017 | sizer.Add(ctl3, (iy, ix), (1, 1), |
3018 | 3018 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
3019 | | |
| 3019 | |
3020 | 3020 | ix += 1 |
3021 | 3021 | ctl4 = self.ModelTextCtrl(self, -1, |
… |
… |
|
3028 | 3028 | sizer.Add(ctl4, (iy, ix), (1, 1), |
3029 | 3029 | wx.EXPAND | wx.FIXED_MINSIZE, 0) |
3030 | | |
| 3030 | |
3031 | 3031 | ix += 1 |
3032 | 3032 | # Units |
… |
… |
|
3039 | 3039 | sizer.Add(units, (iy, ix), (1, 1), |
3040 | 3040 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
3041 | | |
| 3041 | |
3042 | 3042 | self.parameters.append([cb, item, ctl1, |
3043 | 3043 | text2, ctl2, ctl3, ctl4, units]) |
3044 | | |
| 3044 | |
3045 | 3045 | iy += 1 |
3046 | 3046 | sizer.Add((10, 10), (iy, ix), (1, 1), |
3047 | 3047 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
3048 | | |
| 3048 | |
3049 | 3049 | # type can be either Guassian or Array |
3050 | 3050 | if len(self.model.dispersion.values()) > 0: |
… |
… |
|
3052 | 3052 | else: |
3053 | 3053 | type = "Gaussian" |
3054 | | |
| 3054 | |
3055 | 3055 | iy += 1 |
3056 | 3056 | ix = 0 |
… |
… |
|
3059 | 3059 | if item in self.model.orientation_params: |
3060 | 3060 | orient_angle = wx.StaticText(self, -1, '[For 2D only]:') |
3061 | | mag_on_button = wx.Button(self, -1, "Magnetic ON" ) |
| 3061 | mag_on_button = wx.Button(self, -1, "Magnetic ON") |
3062 | 3062 | mag_on_button.Bind(wx.EVT_BUTTON, self._on_mag_on) |
3063 | | mag_help_button = wx.Button(self, -1,"Magnetic angles?" ) |
3064 | | mag_help_button.Bind(wx.EVT_BUTTON,self._on_mag_help) |
| 3063 | mag_help_button = wx.Button(self, -1, "Magnetic angles?") |
| 3064 | mag_help_button.Bind(wx.EVT_BUTTON, self._on_mag_help) |
3065 | 3065 | sizer.Add(orient_angle, (iy, ix), (1, 1), |
3066 | 3066 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
3067 | 3067 | iy += 1 |
3068 | | sizer.Add(mag_on_button,(iy, ix ),(1,1), |
3069 | | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
3070 | | sizer.Add(mag_help_button,(iy, ix + 1),(1,1), |
3071 | | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
3072 | | |
| 3068 | sizer.Add(mag_on_button, (iy, ix), (1, 1), |
| 3069 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
| 3070 | sizer.Add(mag_help_button, (iy, ix + 1), (1, 1), |
| 3071 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
| 3072 | |
3073 | 3073 | #handle the magnetic buttons |
3074 | 3074 | if not self._has_magnetic: |
… |
… |
|
3082 | 3082 | if self.magnetic_on: |
3083 | 3083 | mag_on_button.SetLabel("Magnetic OFF") |
3084 | | mag_help_button.Show(True) |
| 3084 | mag_help_button.Show(True) |
3085 | 3085 | else: |
3086 | 3086 | mag_on_button.SetLabel("Magnetic ON") |
3087 | 3087 | mag_help_button.Show(False) |
3088 | | |
| 3088 | |
3089 | 3089 | if not self.data.__class__.__name__ == "Data2D" and \ |
3090 | 3090 | not self.enable2D: |
… |
… |
|
3093 | 3093 | orient_angle.Show(True) |
3094 | 3094 | break |
3095 | | |
| 3095 | |
3096 | 3096 | #For Gaussian only |
3097 | 3097 | if type.lower() != "array": |
… |
… |
|
3104 | 3104 | if not item in self.model.details: |
3105 | 3105 | self.model.details[item] = ["", None, None] |
3106 | | |
| 3106 | |
3107 | 3107 | iy += 1 |
3108 | 3108 | ix = 0 |
… |
… |
|
3119 | 3119 | sizer.Add(cb, (iy, ix), (1, 1), |
3120 | 3120 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
3121 | | |
| 3121 | |
3122 | 3122 | ## add parameter value |
3123 | 3123 | ix += 1 |
… |
… |
|
3148 | 3148 | |
3149 | 3149 | ctl2.Hide() |
3150 | | |
| 3150 | |
3151 | 3151 | ix += 1 |
3152 | 3152 | ctl3 = self.ModelTextCtrl(self, -1, |
… |
… |
|
3154 | 3154 | style=wx.TE_PROCESS_ENTER, |
3155 | 3155 | text_enter_callback=self._onparamRangeEnter) |
3156 | | |
| 3156 | |
3157 | 3157 | sizer.Add(ctl3, (iy, ix), (1, 1), |
3158 | 3158 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
3159 | 3159 | ctl3.Hide() |
3160 | | |
| 3160 | |
3161 | 3161 | ix += 1 |
3162 | 3162 | ctl4 = self.ModelTextCtrl(self, -1, |
… |
… |
|
3166 | 3166 | sizer.Add(ctl4, (iy, ix), (1, 1), |
3167 | 3167 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
3168 | | |
| 3168 | |
3169 | 3169 | ctl4.Hide() |
3170 | | |
| 3170 | |
3171 | 3171 | if self.data.__class__.__name__ == "Data2D" or \ |
3172 | 3172 | self.enable2D: |
… |
… |
|
3176 | 3176 | ctl3.Show(True) |
3177 | 3177 | ctl4.Show(True) |
3178 | | |
| 3178 | |
3179 | 3179 | ix += 1 |
3180 | 3180 | # Units |
… |
… |
|
3191 | 3191 | else: |
3192 | 3192 | units.Hide() |
3193 | | |
| 3193 | |
3194 | 3194 | sizer.Add(units, (iy, ix), (1, 1), |
3195 | 3195 | wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
3196 | | |
| 3196 | |
3197 | 3197 | self.parameters.append([cb, item, ctl1, |
3198 | 3198 | text2, ctl2, ctl3, ctl4, units]) |
3199 | 3199 | self.orientation_params.append([cb, item, ctl1, |
3200 | 3200 | text2, ctl2, ctl3, ctl4, units]) |
3201 | | |
| 3201 | |
3202 | 3202 | iy += 1 |
3203 | 3203 | box_description.SetForegroundColour(wx.BLUE) |
… |
… |
|
3235 | 3235 | wx.PostEvent(self._manager.parent, |
3236 | 3236 | StatusEvent(status=msg, info=infor)) |
3237 | | |
| 3237 | |
3238 | 3238 | def _onModel2D(self, event): |
3239 | 3239 | """ |
… |
… |
|
3243 | 3243 | self.model_view.SetLabel("Show 1D") |
3244 | 3244 | self.enable2D = True |
3245 | | |
| 3245 | |
3246 | 3246 | else: |
3247 | 3247 | self.model_view.SetLabel("Show 2D") |
… |
… |
|
3258 | 3258 | self.SetupScrolling() |
3259 | 3259 | self._draw_model() |
3260 | | |
| 3260 | |
3261 | 3261 | self.state.enable2D = copy.deepcopy(self.enable2D) |
3262 | | |
| 3262 | |
3263 | 3263 | def _set_smear_buttons(self): |
3264 | 3264 | """ |
… |
… |
|
3274 | 3274 | self.slit_smearer.Enable(True) |
3275 | 3275 | self.pinhole_smearer.Enable(True) |
3276 | | |
3277 | | |
| 3276 | |
| 3277 | |
3278 | 3278 | class BGTextCtrl(wx.TextCtrl): |
3279 | 3279 | """ |
… |
… |
|
3286 | 3286 | self.SetEditable(False) |
3287 | 3287 | self.SetBackgroundColour(self.GetParent().parent.GetBackgroundColour()) |
3288 | | |
| 3288 | |
3289 | 3289 | # Bind to mouse event to avoid text highlighting |
3290 | 3290 | # The event will be skipped once the call-back |
3291 | 3291 | # is called. |
3292 | 3292 | self.Bind(wx.EVT_MOUSE_EVENTS, self._click) |
3293 | | |
| 3293 | |
3294 | 3294 | def _click(self, event): |
3295 | 3295 | """ |
-
r386ffe1
|
r2f4b430
|
|
4 | 4 | :note: For Fit to be performed the user should check at least one parameter |
5 | 5 | on fit Panel window. |
6 | | |
| 6 | |
7 | 7 | """ |
8 | 8 | import wx |
… |
… |
|
22 | 22 | """ |
23 | 23 | FitPanel class contains fields allowing to fit models and data |
24 | | |
| 24 | |
25 | 25 | :note: For Fit to be performed the user should check at least one parameter |
26 | 26 | on fit Panel window. |
27 | | |
| 27 | |
28 | 28 | """ |
29 | 29 | ## Internal name for the AUI manager |
… |
… |
|
32 | 32 | window_caption = "Fit Panel " |
33 | 33 | CENTER_PANE = True |
34 | | |
| 34 | |
35 | 35 | def __init__(self, parent, manager=None, *args, **kwargs): |
36 | 36 | """ |
37 | 37 | """ |
38 | 38 | nb.__init__(self, parent, -1, |
39 | | style=wx.aui.AUI_NB_WINDOWLIST_BUTTON| |
40 | | wx.aui.AUI_NB_DEFAULT_STYLE| |
| 39 | style=wx.aui.AUI_NB_WINDOWLIST_BUTTON | |
| 40 | wx.aui.AUI_NB_DEFAULT_STYLE | |
41 | 41 | wx.CLIP_CHILDREN) |
42 | 42 | PanelBase.__init__(self, parent) |
… |
… |
|
51 | 51 | self.model_dictionary = self.menu_mng.get_model_dictionary() |
52 | 52 | self.pageClosedEvent = wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE |
53 | | |
| 53 | |
54 | 54 | self.Bind(self.pageClosedEvent, self.on_close_page) |
55 | 55 | ## save the title of the last page tab added |
… |
… |
|
71 | 71 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, self.on_page_changing) |
72 | 72 | self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSED, self.on_closed) |
73 | | |
| 73 | |
74 | 74 | def on_closed(self, event): |
75 | 75 | """ |
… |
… |
|
78 | 78 | self.add_empty_page() |
79 | 79 | self.enable_close_button() |
80 | | |
| 80 | |
81 | 81 | def save_project(self, doc=None): |
82 | 82 | """ |
… |
… |
|
109 | 109 | info="warning")) |
110 | 110 | return doc |
111 | | |
| 111 | |
112 | 112 | def update_model_list(self): |
113 | 113 | """ |
… |
… |
|
117 | 117 | self.model_list_box = temp |
118 | 118 | return temp |
119 | | |
| 119 | |
120 | 120 | def reset_pmodel_list(self): |
121 | 121 | """ |
… |
… |
|
125 | 125 | self.model_list_box = temp |
126 | 126 | return temp |
127 | | |
| 127 | |
128 | 128 | def get_page_by_id(self, uid): |
129 | 129 | """ |
… |
… |
|
134 | 134 | else: |
135 | 135 | return self.opened_pages[uid] |
136 | | |
| 136 | |
137 | 137 | def on_page_changing(self, event): |
138 | 138 | """ |
… |
… |
|
141 | 141 | """ |
142 | 142 | wx.CallAfter(self.helper_on_page_change) |
143 | | |
| 143 | |
144 | 144 | def helper_on_page_change(self): |
145 | 145 | """ |
… |
… |
|
148 | 148 | if pos != -1: |
149 | 149 | selected_page = self.GetPage(pos) |
150 | | wx.PostEvent(self._manager.parent, |
| 150 | wx.PostEvent(self._manager.parent, |
151 | 151 | PanelOnFocusEvent(panel=selected_page)) |
152 | 152 | self.enable_close_button() |
153 | | |
| 153 | |
154 | 154 | def on_set_focus(self, event): |
155 | 155 | """ |
… |
… |
|
158 | 158 | if pos != -1: |
159 | 159 | selected_page = self.GetPage(pos) |
160 | | wx.PostEvent(self._manager.parent, |
| 160 | wx.PostEvent(self._manager.parent, |
161 | 161 | PanelOnFocusEvent(panel=selected_page)) |
162 | | |
| 162 | |
163 | 163 | def get_data(self): |
164 | 164 | """ |
… |
… |
|
169 | 169 | selected_page = self.GetPage(pos) |
170 | 170 | return selected_page.get_data() |
171 | | |
| 171 | |
172 | 172 | def set_model_state(self, state): |
173 | 173 | """ |
… |
… |
|
178 | 178 | selected_page = self.GetPage(pos) |
179 | 179 | selected_page.set_model_state(state) |
180 | | |
| 180 | |
181 | 181 | def get_state(self): |
182 | 182 | """ |
… |
… |
|
187 | 187 | selected_page = self.GetPage(pos) |
188 | 188 | return selected_page.get_state() |
189 | | |
| 189 | |
190 | 190 | def close_all(self): |
191 | 191 | """ |
192 | 192 | remove all pages, used when a svs file is opened |
193 | 193 | """ |
194 | | |
| 194 | |
195 | 195 | #get number of pages |
196 | 196 | nop = self.GetPageCount() |
… |
… |
|
204 | 204 | self.DeletePage(0) |
205 | 205 | nop = nop - 1 |
206 | | |
| 206 | |
207 | 207 | ## save the title of the last page tab added |
208 | 208 | self.fit_page_name = {} |
209 | 209 | ## list of existing fit page |
210 | 210 | self.opened_pages = {} |
211 | | |
| 211 | |
212 | 212 | def set_state(self, state): |
213 | 213 | """ |
… |
… |
|
238 | 238 | panel.reset_page(state=state) |
239 | 239 | panel.save_current_state() |
240 | | |
| 240 | |
241 | 241 | def clear_panel(self): |
242 | 242 | """ |
243 | 243 | Clear and close all panels, used by guimanager |
244 | 244 | """ |
245 | | |
| 245 | |
246 | 246 | #close all panels only when svs file opened |
247 | 247 | self.close_all() |
248 | 248 | self._manager.mypanels = [] |
249 | | |
| 249 | |
250 | 250 | def on_close_page(self, event=None): |
251 | 251 | """ |
… |
… |
|
260 | 260 | return |
261 | 261 | self._close_helper(selected_page=selected_page) |
262 | | |
| 262 | |
263 | 263 | def close_page_with_data(self, deleted_data): |
264 | 264 | """ |
… |
… |
|
271 | 271 | if hasattr(selected_page, "get_data"): |
272 | 272 | data = selected_page.get_data() |
273 | | |
| 273 | |
274 | 274 | if data is None: |
275 | 275 | #the fitpanel exists and only the initial fit page is open |
… |
… |
|
280 | 280 | self.DeletePage(index) |
281 | 281 | break |
282 | | |
| 282 | |
283 | 283 | def set_manager(self, manager): |
284 | 284 | """ |
285 | 285 | set panel manager |
286 | | |
| 286 | |
287 | 287 | :param manager: instance of plugin fitting |
288 | | |
| 288 | |
289 | 289 | """ |
290 | 290 | self._manager = manager |
… |
… |
|
297 | 297 | """ |
298 | 298 | copy a dictionary of model into its own dictionary |
299 | | |
| 299 | |
300 | 300 | :param m_dict: dictionnary made of model name as key and model class |
301 | 301 | as value |
302 | 302 | """ |
303 | 303 | self.model_list_box = dict |
304 | | |
| 304 | |
305 | 305 | def set_model_dict(self, m_dict): |
306 | 306 | """ |
… |
… |
|
313 | 313 | """ |
314 | 314 | :return: the current page selected |
315 | | |
| 315 | |
316 | 316 | """ |
317 | 317 | return self.GetPage(self.GetSelection()) |
318 | | |
| 318 | |
319 | 319 | def add_sim_page(self, caption="Const & Simul Fit"): |
320 | 320 | """ |
… |
… |
|
325 | 325 | if caption == "Const & Simul Fit": |
326 | 326 | self.sim_page = SimultaneousFitPage(self, page_finder=page_finder, |
327 | | id=-1, batch_on=False) |
| 327 | id= -1, batch_on=False) |
328 | 328 | self.sim_page.window_caption = caption |
329 | 329 | self.sim_page.window_name = caption |
… |
… |
|
343 | 343 | self.enable_close_button() |
344 | 344 | return self.batch_page |
345 | | |
| 345 | |
346 | 346 | def add_empty_page(self): |
347 | 347 | """ |
… |
… |
|
385 | 385 | panel.on_set_focus(None) |
386 | 386 | return panel |
387 | | |
| 387 | |
388 | 388 | def enable_close_button(self): |
389 | 389 | """ |
… |
… |
|
403 | 403 | style |= wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB |
404 | 404 | self.SetWindowStyle(style) |
405 | | |
| 405 | |
406 | 406 | def delete_data(self, data): |
407 | 407 | """ |
… |
… |
|
422 | 422 | if self.GetPageCount() == 0: |
423 | 423 | self._manager.on_add_new_page(event=None) |
424 | | |
| 424 | |
425 | 425 | def set_data_on_batch_mode(self, data_list): |
426 | 426 | """ |
427 | 427 | Add all data to a single tab when the application is on Batch mode. |
428 | | However all data in the set of data must be either 1D or 2D type. |
429 | | This method presents option to select the data type before creating a |
| 428 | However all data in the set of data must be either 1D or 2D type. |
| 429 | This method presents option to select the data type before creating a |
430 | 430 | tab. |
431 | 431 | """ |
… |
… |
|
445 | 445 | #check if there is an empty page to fill up |
446 | 446 | if not check_data_validity(p.get_data()) and p.batch_on: |
447 | | |
| 447 | |
448 | 448 | #make sure data get placed in 1D empty tab if data is 1D |
449 | 449 | #else data get place on 2D tab empty tab |
… |
… |
|
479 | 479 | elif not data_1d_list and data_2d_list: |
480 | 480 | page.fill_data_combobox(data_2d_list) |
481 | | |
| 481 | |
482 | 482 | pos = self.GetPageIndex(page) |
483 | 483 | page.batch_on = self.batch_on |
… |
… |
|
486 | 486 | self.opened_pages[page.uid] = page |
487 | 487 | return page |
488 | | |
| 488 | |
489 | 489 | def set_data(self, data_list): |
490 | 490 | """ |
491 | 491 | Add a fitting page on the notebook contained by fitpanel |
492 | | |
| 492 | |
493 | 493 | :param data: data to fit |
494 | | |
| 494 | |
495 | 495 | :return panel : page just added for further used. |
496 | 496 | is used by fitting module |
497 | | |
| 497 | |
498 | 498 | """ |
499 | 499 | if not data_list: |
… |
… |
|
509 | 509 | data_list = [data] |
510 | 510 | data = data_list[0] |
511 | | |
| 511 | |
512 | 512 | if data is None: |
513 | 513 | return None |
… |
… |
|
535 | 535 | self.SetSelection(pos) |
536 | 536 | return page |
537 | | |
| 537 | |
538 | 538 | def _onGetstate(self, event): |
539 | 539 | """ |
… |
… |
|
543 | 543 | if page.uid in self.fit_page_name: |
544 | 544 | self.fit_page_name[page.uid].appendItem(page.createMemento()) |
545 | | |
| 545 | |
546 | 546 | def _onUndo(self, event): |
547 | 547 | """ |
… |
… |
|
556 | 556 | page._redo.Enable(True) |
557 | 557 | page.reset_page(state) |
558 | | |
| 558 | |
559 | 559 | def _onRedo(self, event): |
560 | 560 | """ |
… |
… |
|
571 | 571 | state = self.fit_page_name[page.uid].getNextItem() |
572 | 572 | page.reset_page(state) |
573 | | |
| 573 | |
574 | 574 | def _close_helper(self, selected_page): |
575 | 575 | """ |
… |
… |
|
606 | 606 | for uid, list in self.opened_pages.iteritems(): |
607 | 607 | #Don't return any panel is the exact same page is created |
608 | | |
| 608 | |
609 | 609 | if flag and selected_page.uid == uid: |
610 | 610 | self._manager.remove_plot(uid, theory=False) |
611 | 611 | break |
612 | 612 | del page_finder[selected_page] |
613 | | |
| 613 | |
614 | 614 | #Delete the name of the page into the list of open page |
615 | 615 | for uid, list in self.opened_pages.iteritems(): |
-
r7a04dbb
|
r2f4b430
|
|
27 | 27 | flag is 0 ingore smear value. |
28 | 28 | """ |
29 | | |
| 29 | |
30 | 30 | def get_smearer(self): |
31 | 31 | """ |
… |
… |
|
35 | 35 | """ |
36 | 36 | """ |
37 | | |
| 37 | |
38 | 38 | def get_name(self): |
39 | 39 | """ |
40 | 40 | """ |
41 | | |
| 41 | |
42 | 42 | def set_model(self, model): |
43 | 43 | """ |
… |
… |
|
46 | 46 | :param name: name created for model |
47 | 47 | """ |
48 | | |
| 48 | |
49 | 49 | def get_model(self): |
50 | 50 | """ |
51 | 51 | :return: saved model |
52 | 52 | """ |
53 | | |
| 53 | |
54 | 54 | def set_residuals(self, residuals): |
55 | 55 | """ |
… |
… |
|
57 | 57 | :param data: data selected |
58 | 58 | """ |
59 | | |
| 59 | |
60 | 60 | def get_residuals(self): |
61 | 61 | """ |
62 | 62 | :return: residuals |
63 | 63 | """ |
64 | | |
| 64 | |
65 | 65 | def set_theory_data(self, data): |
66 | 66 | """ |
… |
… |
|
68 | 68 | :param data: data selected |
69 | 69 | """ |
70 | | |
| 70 | |
71 | 71 | def get_theory_data(self): |
72 | 72 | """ |
73 | 73 | :return: list of data dList |
74 | 74 | """ |
75 | | |
| 75 | |
76 | 76 | def set_fit_data(self, data): |
77 | 77 | """ |
… |
… |
|
81 | 81 | :param data: list of data selected |
82 | 82 | """ |
83 | | |
| 83 | |
84 | 84 | def get_fit_data(self): |
85 | 85 | """ |
86 | 86 | """ |
87 | | |
| 87 | |
88 | 88 | def set_model_param(self, name, value=None): |
89 | 89 | """ |
… |
… |
|
92 | 92 | :param value: value of that parameter |
93 | 93 | """ |
94 | | |
| 94 | |
95 | 95 | def set_param2fit(self, list): |
96 | 96 | """ |
… |
… |
|
98 | 98 | :param list: list of the param names |
99 | 99 | """ |
100 | | |
| 100 | |
101 | 101 | def get_param2fit(self): |
102 | 102 | """ |
103 | 103 | return the list param names to fit |
104 | 104 | """ |
105 | | |
| 105 | |
106 | 106 | def get_model_param(self): |
107 | 107 | """ |
108 | 108 | return list of couple of parameter name and value |
109 | 109 | """ |
110 | | |
| 110 | |
111 | 111 | def schedule_tofit(self, schedule=0): |
112 | 112 | """ |
113 | 113 | set schedule to true to decide if this fit must be performed |
114 | 114 | """ |
115 | | |
| 115 | |
116 | 116 | def get_scheduled(self): |
117 | 117 | """ |
118 | 118 | return true or false if a problem as being schedule for fitting |
119 | 119 | """ |
120 | | |
| 120 | |
121 | 121 | def set_range(self, qmin=None, qmax=None): |
122 | 122 | """ |
123 | 123 | set fitting range |
124 | 124 | """ |
125 | | |
| 125 | |
126 | 126 | def get_range(self): |
127 | 127 | """ |
128 | 128 | :return: fitting range |
129 | 129 | """ |
130 | | |
| 130 | |
131 | 131 | def set_weight(self, flag=None): |
132 | 132 | """ |
133 | 133 | set fitting range |
134 | 134 | """ |
135 | | |
| 135 | |
136 | 136 | def get_weight(self): |
137 | 137 | """ |
138 | 138 | get fitting weight |
139 | 139 | """ |
140 | | |
| 140 | |
141 | 141 | def clear_model_param(self): |
142 | 142 | """ |
143 | 143 | clear constraint info |
144 | 144 | """ |
145 | | |
| 145 | |
146 | 146 | def set_fit_tab_caption(self, caption): |
147 | 147 | """ |
148 | 148 | store the caption of the page associated with object |
149 | 149 | """ |
150 | | |
| 150 | |
151 | 151 | def get_fit_tab_caption(self): |
152 | 152 | """ |
153 | 153 | Return the caption of the page associated with object |
154 | 154 | """ |
155 | | |
| 155 | |
156 | 156 | def set_graph_id(self, id): |
157 | 157 | """ |
158 | | Set graph id (from data_group_id at the time the graph produced) |
159 | | """ |
160 | | |
| 158 | Set graph id (from data_group_id at the time the graph produced) |
| 159 | """ |
| 160 | |
161 | 161 | def get_graph_id(self): |
162 | 162 | """ |
… |
… |
|
173 | 173 | """ |
174 | 174 | |
175 | | |
| 175 | |
176 | 176 | class FitProblemDictionary(FitProblemComponent, dict): |
177 | 177 | """ |
… |
… |
|
198 | 198 | self.batch_inputs = {} |
199 | 199 | self.batch_outputs = {} |
200 | | |
| 200 | |
201 | 201 | def enable_smearing(self, flag=False, fid=None): |
202 | 202 | """ |
… |
… |
|
211 | 211 | if fid in self.iterkeys(): |
212 | 212 | self[fid].enable_smearing(flag) |
213 | | |
| 213 | |
214 | 214 | def set_smearer(self, smearer, fid=None): |
215 | 215 | """ |
… |
… |
|
223 | 223 | if fid in self.iterkeys(): |
224 | 224 | self[fid].set_smearer(smearer) |
225 | | |
| 225 | |
226 | 226 | def get_smearer(self, fid=None): |
227 | 227 | """ |
… |
… |
|
230 | 230 | if fid in self.iterkeys(): |
231 | 231 | return self[fid].get_smearer() |
232 | | |
| 232 | |
233 | 233 | def save_model_name(self, name, fid=None): |
234 | 234 | """ |
… |
… |
|
240 | 240 | if fid in self.iterkeys(): |
241 | 241 | self[fid].save_model_name(name) |
242 | | |
| 242 | |
243 | 243 | def get_name(self, fid=None): |
244 | 244 | """ |
… |
… |
|
252 | 252 | result.append(self[fid].get_name()) |
253 | 253 | return result |
254 | | |
| 254 | |
255 | 255 | def set_model(self, model, fid=None): |
256 | 256 | """ |
… |
… |
|
266 | 266 | if fid in self.iterkeys(): |
267 | 267 | self[fid].set_model(self.model) |
268 | | |
| 268 | |
269 | 269 | def get_model(self, fid): |
270 | 270 | """ |
… |
… |
|
273 | 273 | if fid in self.iterkeys(): |
274 | 274 | return self[fid].get_model() |
275 | | |
| 275 | |
276 | 276 | def set_fit_tab_caption(self, caption): |
277 | 277 | """ |
… |
… |
|
279 | 279 | """ |
280 | 280 | self.fit_tab_caption = caption |
281 | | |
| 281 | |
282 | 282 | def get_fit_tab_caption(self): |
283 | 283 | """ |
… |
… |
|
285 | 285 | """ |
286 | 286 | return self.fit_tab_caption |
287 | | |
| 287 | |
288 | 288 | def set_residuals(self, residuals, fid): |
289 | 289 | """ |
… |
… |
|
293 | 293 | if fid in self.iterkeys(): |
294 | 294 | self[fid].set_residuals(residuals) |
295 | | |
| 295 | |
296 | 296 | def get_residuals(self, fid): |
297 | 297 | """ |
… |
… |
|
300 | 300 | if fid in self.iterkeys(): |
301 | 301 | return self[fid].get_residuals() |
302 | | |
| 302 | |
303 | 303 | def set_theory_data(self, fid, data=None): |
304 | 304 | """ |
… |
… |
|
308 | 308 | if fid in self.iterkeys(): |
309 | 309 | self[fid].set_theory_data(data) |
310 | | |
| 310 | |
311 | 311 | def get_theory_data(self, fid): |
312 | 312 | """ |
… |
… |
|
315 | 315 | if fid in self.iterkeys(): |
316 | 316 | return self[fid].get_theory_data() |
317 | | |
| 317 | |
318 | 318 | def add_data(self, data): |
319 | 319 | """ |
… |
… |
|
325 | 325 | self[data.id] = FitProblem() |
326 | 326 | self[data.id].set_fit_data(data) |
327 | | |
| 327 | |
328 | 328 | def set_fit_data(self, data): |
329 | 329 | """ |
330 | 330 | save a copy of the data select to fit |
331 | 331 | :param data: data selected |
332 | | |
| 332 | |
333 | 333 | """ |
334 | 334 | self.clear() |
… |
… |
|
342 | 342 | self[d.id].set_model(self.model) |
343 | 343 | self[d.id].set_range(self.qmin, self.qmax) |
344 | | |
| 344 | |
345 | 345 | def get_fit_data(self, fid): |
346 | 346 | """ |
… |
… |
|
351 | 351 | if fid in self.iterkeys(): |
352 | 352 | return self[fid].get_fit_data() |
353 | | |
| 353 | |
354 | 354 | def set_model_param(self, name, value=None, fid=None): |
355 | 355 | """ |
… |
… |
|
364 | 364 | if fid in self.iterkeys(): |
365 | 365 | self[fid].set_model_param(name, value) |
366 | | |
| 366 | |
367 | 367 | def get_model_param(self, fid): |
368 | 368 | """ |
… |
… |
|
371 | 371 | if fid in self.iterkeys(): |
372 | 372 | return self[fid].get_model_param() |
373 | | |
| 373 | |
374 | 374 | def set_param2fit(self, list): |
375 | 375 | """ |
… |
… |
|
378 | 378 | """ |
379 | 379 | self.list_param2fit = list |
380 | | |
| 380 | |
381 | 381 | def get_param2fit(self): |
382 | 382 | """ |
… |
… |
|
384 | 384 | """ |
385 | 385 | return self.list_param2fit |
386 | | |
| 386 | |
387 | 387 | def schedule_tofit(self, schedule=0): |
388 | 388 | """ |
… |
… |
|
392 | 392 | for value in self.itervalues(): |
393 | 393 | value.schedule_tofit(schedule) |
394 | | |
| 394 | |
395 | 395 | def get_scheduled(self): |
396 | 396 | """ |
… |
… |
|
398 | 398 | """ |
399 | 399 | return self.scheduled |
400 | | |
| 400 | |
401 | 401 | def set_range(self, qmin=None, qmax=None, fid=None): |
402 | 402 | """ |
… |
… |
|
411 | 411 | if fid in self.iterkeys(): |
412 | 412 | self[fid].value.set_range(self.qmin, self.qmax) |
413 | | |
| 413 | |
414 | 414 | def get_range(self, fid): |
415 | 415 | """ |
… |
… |
|
418 | 418 | if fid in self.iterkeys(): |
419 | 419 | return self[fid].get_range() |
420 | | |
| 420 | |
421 | 421 | def set_weight(self, is2d, flag=None, fid=None): |
422 | 422 | """ |
… |
… |
|
429 | 429 | if fid in self.iterkeys(): |
430 | 430 | self[fid].set_weight(flag=flag, is2d=is2d) |
431 | | |
| 431 | |
432 | 432 | def get_weight(self, fid=None): |
433 | 433 | """ |
… |
… |
|
436 | 436 | if fid in self.iterkeys(): |
437 | 437 | return self[fid].get_weight() |
438 | | |
| 438 | |
439 | 439 | def clear_model_param(self, fid=None): |
440 | 440 | """ |
… |
… |
|
447 | 447 | if fid in self.iterkeys(): |
448 | 448 | self[fid].clear_model_param() |
449 | | |
| 449 | |
450 | 450 | def get_fit_problem(self): |
451 | 451 | """ |
… |
… |
|
453 | 453 | """ |
454 | 454 | return self.itervalues() |
455 | | |
| 455 | |
456 | 456 | def set_result(self, result, fid): |
457 | 457 | """ |
… |
… |
|
459 | 459 | if fid in self.iterkeys(): |
460 | 460 | self[fid].set_result(result) |
461 | | |
| 461 | |
462 | 462 | def set_batch_result(self, batch_inputs, batch_outputs): |
463 | 463 | """ |
… |
… |
|
466 | 466 | self.batch_inputs = batch_inputs |
467 | 467 | self.batch_outputs = batch_outputs |
468 | | |
| 468 | |
469 | 469 | def get_result(self, fid): |
470 | 470 | """ |
… |
… |
|
473 | 473 | if fid in self.iterkeys(): |
474 | 474 | return self[fid].get_result() |
475 | | |
| 475 | |
476 | 476 | def get_batch_result(self): |
477 | 477 | """ |
… |
… |
|
479 | 479 | """ |
480 | 480 | return self.batch_inputs, self.batch_outputs |
481 | | |
| 481 | |
482 | 482 | def set_graph_id(self, id): |
483 | 483 | """ |
484 | | Set graph id (from data_group_id at the time the graph produced) |
| 484 | Set graph id (from data_group_id at the time the graph produced) |
485 | 485 | """ |
486 | 486 | self.graph_id = id |
487 | | |
| 487 | |
488 | 488 | def get_graph_id(self): |
489 | 489 | """ |
… |
… |
|
491 | 491 | """ |
492 | 492 | return self.graph_id |
493 | | |
494 | | |
| 493 | |
| 494 | |
495 | 495 | class FitProblem(FitProblemComponent): |
496 | 496 | """ |
… |
… |
|
527 | 527 | self.weight = None |
528 | 528 | self.result = None |
529 | | |
| 529 | |
530 | 530 | def enable_smearing(self, flag=False): |
531 | 531 | """ |
… |
… |
|
534 | 534 | """ |
535 | 535 | self.smearer_enable = flag |
536 | | |
| 536 | |
537 | 537 | def set_smearer(self, smearer): |
538 | 538 | """ |
539 | 539 | save reference of smear object on fitdata |
540 | | |
| 540 | |
541 | 541 | :param smear: smear object from DataLoader |
542 | | |
| 542 | |
543 | 543 | """ |
544 | 544 | self.smearer_computer_value = smearer |
545 | | |
| 545 | |
546 | 546 | def get_smearer(self): |
547 | 547 | """ |
… |
… |
|
556 | 556 | self.smearer_computed = True |
557 | 557 | return self.smearer_computer_value |
558 | | |
| 558 | |
559 | 559 | def save_model_name(self, name): |
560 | 560 | """ |
561 | 561 | """ |
562 | 562 | self.name_per_page = name |
563 | | |
| 563 | |
564 | 564 | def get_name(self): |
565 | 565 | """ |
566 | 566 | """ |
567 | 567 | return self.name_per_page |
568 | | |
| 568 | |
569 | 569 | def set_model(self, model): |
570 | 570 | """ |
… |
… |
|
577 | 577 | self.model) |
578 | 578 | self.smearer_computed = True |
579 | | |
| 579 | |
580 | 580 | def get_model(self): |
581 | 581 | """ |
… |
… |
|
583 | 583 | """ |
584 | 584 | return self.model |
585 | | |
| 585 | |
586 | 586 | def set_residuals(self, residuals): |
587 | 587 | """ |
… |
… |
|
590 | 590 | """ |
591 | 591 | self.residuals = residuals |
592 | | |
| 592 | |
593 | 593 | def get_residuals(self): |
594 | 594 | """ |
… |
… |
|
596 | 596 | """ |
597 | 597 | return self.residuals |
598 | | |
| 598 | |
599 | 599 | def set_theory_data(self, data): |
600 | 600 | """ |
601 | 601 | save a copy of the data select to fit |
602 | | |
| 602 | |
603 | 603 | :param data: data selected |
604 | | |
| 604 | |
605 | 605 | """ |
606 | 606 | self.theory_data = copy.deepcopy(data) |
607 | | |
| 607 | |
608 | 608 | def get_theory_data(self): |
609 | 609 | """ |
… |
… |
|
627 | 627 | self.smearer_computed = True |
628 | 628 | self.result = None |
629 | | |
| 629 | |
630 | 630 | def get_fit_data(self): |
631 | 631 | """ |
… |
… |
|
633 | 633 | """ |
634 | 634 | return self.fit_data |
635 | | |
| 635 | |
636 | 636 | def get_origin_data(self): |
637 | 637 | """ |
638 | 638 | """ |
639 | 639 | return self.original_data |
640 | | |
| 640 | |
641 | 641 | def set_weight(self, is2d, flag=None): |
642 | 642 | """ |
… |
… |
|
658 | 658 | """ |
659 | 659 | return self.weight |
660 | | |
| 660 | |
661 | 661 | def set_param2fit(self, list): |
662 | 662 | """ |
… |
… |
|
665 | 665 | """ |
666 | 666 | self.list_param2fit = list |
667 | | |
| 667 | |
668 | 668 | def get_param2fit(self): |
669 | 669 | """ |
… |
… |
|
671 | 671 | """ |
672 | 672 | return self.list_param2fit |
673 | | |
| 673 | |
674 | 674 | def set_model_param(self, name, value=None): |
675 | 675 | """ |
… |
… |
|
679 | 679 | """ |
680 | 680 | self.list_param.append([name, value]) |
681 | | |
| 681 | |
682 | 682 | def get_model_param(self): |
683 | 683 | """ |
… |
… |
|
685 | 685 | """ |
686 | 686 | return self.list_param |
687 | | |
| 687 | |
688 | 688 | def schedule_tofit(self, schedule=0): |
689 | 689 | """ |
… |
… |
|
691 | 691 | """ |
692 | 692 | self.schedule = schedule |
693 | | |
| 693 | |
694 | 694 | def get_scheduled(self): |
695 | 695 | """ |
… |
… |
|
697 | 697 | """ |
698 | 698 | return self.schedule |
699 | | |
| 699 | |
700 | 700 | def set_range(self, qmin=None, qmax=None): |
701 | 701 | """ |
… |
… |
|
706 | 706 | self.qmin = qmin |
707 | 707 | self.qmax = qmax |
708 | | |
| 708 | |
709 | 709 | def get_range(self): |
710 | 710 | """ |
711 | 711 | :return: fitting range |
712 | | |
| 712 | |
713 | 713 | """ |
714 | 714 | return self.qmin, self.qmax |
715 | | |
| 715 | |
716 | 716 | def clear_model_param(self): |
717 | 717 | """ |
… |
… |
|
719 | 719 | """ |
720 | 720 | self.list_param = [] |
721 | | |
| 721 | |
722 | 722 | def set_fit_tab_caption(self, caption): |
723 | 723 | """ |
724 | 724 | """ |
725 | 725 | self.fit_tab_caption = str(caption) |
726 | | |
| 726 | |
727 | 727 | def get_fit_tab_caption(self): |
728 | 728 | """ |
729 | 729 | """ |
730 | 730 | return self.fit_tab_caption |
731 | | |
| 731 | |
732 | 732 | def set_graph_id(self, id): |
733 | 733 | """ |
… |
… |
|
735 | 735 | """ |
736 | 736 | self.graph_id = id |
737 | | |
| 737 | |
738 | 738 | def get_graph_id(self): |
739 | 739 | """ |
… |
… |
|
741 | 741 | """ |
742 | 742 | return self.graph_id |
743 | | |
| 743 | |
744 | 744 | def set_result(self, result): |
745 | 745 | """ |
746 | 746 | """ |
747 | 747 | self.result = result |
748 | | |
| 748 | |
749 | 749 | def get_result(self): |
750 | 750 | """ |
-
r39356b5
|
r2f4b430
|
|
25 | 25 | from sas.guiframe.dataFitting import Data1D |
26 | 26 | from sas.guiframe.dataFitting import check_data_validity |
27 | | from sas.guiframe.events import NewPlotEvent |
28 | | from sas.guiframe.events import StatusEvent |
| 27 | from sas.guiframe.events import NewPlotEvent |
| 28 | from sas.guiframe.events import StatusEvent |
29 | 29 | from sas.guiframe.events import EVT_SLICER_PANEL |
30 | 30 | from sas.guiframe.events import EVT_SLICER_PARS_UPDATE |
31 | 31 | from sas.guiframe.gui_style import GUIFRAME_ID |
32 | | from sas.guiframe.plugin_base import PluginBase |
| 32 | from sas.guiframe.plugin_base import PluginBase |
33 | 33 | from sas.guiframe.data_processor import BatchCell |
34 | 34 | from sas.fit.Fitting import Fit |
… |
… |
|
63 | 63 | def __init__(self, standalone=False): |
64 | 64 | PluginBase.__init__(self, name="Fitting", standalone=standalone) |
65 | | |
| 65 | |
66 | 66 | #list of panel to send to guiframe |
67 | 67 | self.mypanels = [] |
… |
… |
|
69 | 69 | self.calc_2D = None |
70 | 70 | self.calc_1D = None |
71 | | |
| 71 | |
72 | 72 | self.color_dict = {} |
73 | | |
| 73 | |
74 | 74 | self.fit_thread_list = {} |
75 | 75 | self.residuals = None |
… |
… |
|
107 | 107 | self.menu1 = None |
108 | 108 | self.new_model_frame = None |
109 | | |
| 109 | |
110 | 110 | self.temp_state = [] |
111 | 111 | self.state_index = 0 |
… |
… |
|
116 | 116 | logging.info("Fitting plug-in started") |
117 | 117 | self.batch_capable = self.get_batch_capable() |
118 | | |
| 118 | |
119 | 119 | def get_batch_capable(self): |
120 | 120 | """ |
… |
… |
|
122 | 122 | """ |
123 | 123 | return True |
124 | | |
| 124 | |
125 | 125 | def create_fit_problem(self, page_id): |
126 | 126 | """ |
… |
… |
|
128 | 128 | """ |
129 | 129 | self.page_finder[page_id] = FitProblemDictionary() |
130 | | |
| 130 | |
131 | 131 | def delete_fit_problem(self, page_id): |
132 | 132 | """ |
… |
… |
|
135 | 135 | if page_id in self.page_finder.iterkeys(): |
136 | 136 | del self.page_finder[page_id] |
137 | | |
| 137 | |
138 | 138 | def add_color(self, color, id): |
139 | 139 | """ |
… |
… |
|
141 | 141 | """ |
142 | 142 | self.color_dict[id] = color |
143 | | |
| 143 | |
144 | 144 | def on_batch_selection(self, flag): |
145 | 145 | """ |
… |
… |
|
149 | 149 | if self.fit_panel is not None: |
150 | 150 | self.fit_panel.batch_on = self.batch_on |
151 | | |
| 151 | |
152 | 152 | def populate_menu(self, owner): |
153 | 153 | """ |
154 | 154 | Create a menu for the Fitting plug-in |
155 | | |
| 155 | |
156 | 156 | :param id: id to create a menu |
157 | 157 | :param owner: owner of menu |
158 | | |
| 158 | |
159 | 159 | :return: list of information to populate the main menu |
160 | | |
| 160 | |
161 | 161 | """ |
162 | 162 | #Menu for fitting |
… |
… |
|
194 | 194 | wx.EVT_MENU(owner, self.id_result_panel, lambda ev: self.result_frame.Show()) |
195 | 195 | self.menu1.AppendSeparator() |
196 | | |
| 196 | |
197 | 197 | self.id_reset_flag = wx.NewId() |
198 | 198 | resetf_help = "BatchFit: If checked, the initial param values will be " |
… |
… |
|
207 | 207 | chain_menu.Check(not self.batch_reset_flag) |
208 | 208 | chain_menu.Enable(self.batch_on) |
209 | | |
| 209 | |
210 | 210 | self.menu1.AppendSeparator() |
211 | 211 | self.edit_model_menu = wx.Menu() |
… |
… |
|
215 | 215 | except: |
216 | 216 | raise |
217 | | |
| 217 | |
218 | 218 | self.id_edit = wx.NewId() |
219 | 219 | editmodel_help = "Edit customized model sample file" |
… |
… |
|
222 | 222 | #create menubar items |
223 | 223 | return [(self.menu1, self.sub_menu)] |
224 | | |
| 224 | |
225 | 225 | def edit_custom_model(self, event): |
226 | 226 | """ |
… |
… |
|
237 | 237 | self.put_icon(frame) |
238 | 238 | frame.Show(True) |
239 | | |
| 239 | |
240 | 240 | def delete_custom_model(self, event): |
241 | 241 | """ |
… |
… |
|
266 | 266 | if item.GetLabel() == label: |
267 | 267 | self.edit_menu.DeleteItem(item) |
268 | | msg = "The custom model, %s, has been deleted."% label |
269 | | wx.PostEvent(self.parent, StatusEvent(status=msg, |
| 268 | msg = "The custom model, %s, has been deleted." % label |
| 269 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
270 | 270 | type='stop', info='info')) |
271 | 271 | break |
272 | 272 | except: |
273 | | msg ='Delete Error: \nCould not delete the file; Check if in use.' |
| 273 | msg = 'Delete Error: \nCould not delete the file; Check if in use.' |
274 | 274 | wx.MessageBox(msg, 'Error') |
275 | | |
| 275 | |
276 | 276 | def make_sum_model(self, event): |
277 | 277 | """ |
… |
… |
|
282 | 282 | model_list = model_manager.get_model_name_list() |
283 | 283 | plug_dir = models.find_plugins_dir() |
284 | | textdial = TextDialog(None, self, -1, 'Easy Sum/Multi(p1, p2) Editor', |
| 284 | textdial = TextDialog(None, self, -1, 'Easy Sum/Multi(p1, p2) Editor', |
285 | 285 | model_list, plug_dir) |
286 | 286 | self.put_icon(textdial) |
287 | 287 | textdial.ShowModal() |
288 | 288 | textdial.Destroy() |
289 | | |
| 289 | |
290 | 290 | def make_new_model(self, event): |
291 | 291 | """ |
… |
… |
|
332 | 332 | except: |
333 | 333 | pass |
334 | | |
335 | | |
| 334 | |
| 335 | |
336 | 336 | def set_edit_menu(self, owner): |
337 | 337 | """ |
… |
… |
|
349 | 349 | e_id = wx.NewId() |
350 | 350 | self.edit_menu = wx.Menu() |
351 | | self.edit_model_menu.AppendMenu(e_id, |
352 | | 'Advanced', self.edit_menu) |
| 351 | self.edit_model_menu.AppendMenu(e_id, |
| 352 | 'Advanced', self.edit_menu) |
353 | 353 | self.set_edit_menu_helper(owner, self.edit_custom_model) |
354 | 354 | |
… |
… |
|
358 | 358 | 'Delete', self.delete_menu) |
359 | 359 | self.set_edit_menu_helper(owner, self.delete_custom_model) |
360 | | |
| 360 | |
361 | 361 | def set_edit_menu_helper(self, owner=None, menu=None): |
362 | 362 | """ |
… |
… |
|
409 | 409 | caption = "Combined Batch" |
410 | 410 | page = self.batch_page |
411 | | |
| 411 | |
412 | 412 | def set_focus_page(page): |
413 | 413 | page.Show(True) |
… |
… |
|
417 | 417 | msg = "%s already opened\n" % str(page.window_caption) |
418 | 418 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
419 | | |
| 419 | |
420 | 420 | if page != None: |
421 | 421 | return set_focus_page(page) |
… |
… |
|
424 | 424 | else: |
425 | 425 | self.batch_page = self.fit_panel.add_sim_page(caption=caption) |
426 | | |
| 426 | |
427 | 427 | def help(self, evt): |
428 | 428 | """ |
… |
… |
|
439 | 439 | pass |
440 | 440 | frame.Show(True) |
441 | | |
| 441 | |
442 | 442 | def get_context_menu(self, plotpanel=None): |
443 | 443 | """ |
444 | 444 | Get the context menu items available for P(r).them allow fitting option |
445 | 445 | for Data2D and Data1D only. |
446 | | |
| 446 | |
447 | 447 | :param graph: the Graph object to which we attach the context menu |
448 | | |
| 448 | |
449 | 449 | :return: a list of menu items with call-back function |
450 | | |
| 450 | |
451 | 451 | :note: if Data1D was generated from Theory1D |
452 | 452 | the fitting option is not allowed |
453 | | |
| 453 | |
454 | 454 | """ |
455 | 455 | self.plot_panel = plotpanel |
456 | 456 | graph = plotpanel.graph |
457 | 457 | fit_option = "Select data for fitting" |
458 | | fit_hint = "Dialog with fitting parameters " |
459 | | |
| 458 | fit_hint = "Dialog with fitting parameters " |
| 459 | |
460 | 460 | if graph.selected_plottable not in plotpanel.plots: |
461 | 461 | return [] |
… |
… |
|
466 | 466 | return [[fit_option, fit_hint, self._onSelect]] |
467 | 467 | else: |
468 | | return [] |
| 468 | return [] |
469 | 469 | return [[fit_option, fit_hint, self._onSelect]] |
470 | 470 | else: |
471 | | |
| 471 | |
472 | 472 | # if is_data is true , this in an actual data loaded |
473 | 473 | #else it is a data created from a theory model |
… |
… |
|
501 | 501 | self.result_panel = ResultPanel(parent=self.result_frame, manager=self) |
502 | 502 | self.perspective.append(self.result_panel.window_name) |
503 | | |
| 503 | |
504 | 504 | #index number to create random model name |
505 | 505 | self.index_model = 0 |
… |
… |
|
517 | 517 | self.mypanels.append(self.result_panel) |
518 | 518 | return self.mypanels |
519 | | |
| 519 | |
520 | 520 | def clear_panel(self): |
521 | 521 | """ |
522 | 522 | """ |
523 | 523 | self.fit_panel.clear_panel() |
524 | | |
| 524 | |
525 | 525 | def delete_data(self, data): |
526 | 526 | """ |
… |
… |
|
528 | 528 | """ |
529 | 529 | self.fit_panel.delete_data(data) |
530 | | |
| 530 | |
531 | 531 | def set_data(self, data_list=None): |
532 | 532 | """ |
… |
… |
|
545 | 545 | selected_data_list = dlg.get_data() |
546 | 546 | dlg.Destroy() |
547 | | |
| 547 | |
548 | 548 | else: |
549 | 549 | selected_data_list = data_list |
… |
… |
|
562 | 562 | msg = "Fitting Set_data: " + str(sys.exc_value) |
563 | 563 | wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) |
564 | | |
| 564 | |
565 | 565 | def set_theory(self, theory_list=None): |
566 | 566 | """ |
… |
… |
|
576 | 576 | wx.PostEvent(self.parent, |
577 | 577 | StatusEvent(status=msg, info="error")) |
578 | | |
| 578 | |
579 | 579 | def set_state(self, state=None, datainfo=None, format=None): |
580 | 580 | """ |
581 | 581 | Call-back method for the fit page state reader. |
582 | 582 | This method is called when a .fitv/.svs file is loaded. |
583 | | |
| 583 | |
584 | 584 | : param state: PageState object |
585 | 585 | : param datainfo: data |
… |
… |
|
596 | 596 | # state file format |
597 | 597 | self.sfile_ext = format |
598 | | |
| 598 | |
599 | 599 | self.on_set_state_helper(event=None) |
600 | 600 | |
… |
… |
|
603 | 603 | Set_state_helper. This actually sets state |
604 | 604 | after plotting data from state file. |
605 | | |
| 605 | |
606 | 606 | : event: FitStateUpdateEvent called |
607 | 607 | by dataloader.plot_data from guiframe |
… |
… |
|
613 | 613 | self.state_index = 0 |
614 | 614 | return |
615 | | |
| 615 | |
616 | 616 | try: |
617 | 617 | # Load fitting state |
… |
… |
|
641 | 641 | caption=caption) |
642 | 642 | self.mypanels.append(page) |
643 | | |
| 643 | |
644 | 644 | # get ready for the next set_state |
645 | 645 | self.state_index += 1 |
… |
… |
|
647 | 647 | #reset state variables to default when all set_state is finished. |
648 | 648 | if len(self.temp_state) == self.state_index: |
649 | | |
| 649 | |
650 | 650 | self.temp_state = [] |
651 | 651 | #self.state_index = 0 |
… |
… |
|
657 | 657 | self.temp_state = [] |
658 | 658 | raise |
659 | | |
| 659 | |
660 | 660 | def set_param2fit(self, uid, param2fit): |
661 | 661 | """ |
… |
… |
|
663 | 663 | """ |
664 | 664 | self.page_finder[uid].set_param2fit(param2fit) |
665 | | |
| 665 | |
666 | 666 | def set_graph_id(self, uid, graph_id): |
667 | 667 | """ |
… |
… |
|
669 | 669 | """ |
670 | 670 | self.page_finder[uid].set_graph_id(graph_id) |
671 | | |
| 671 | |
672 | 672 | def get_graph_id(self, uid): |
673 | 673 | """ |
… |
… |
|
675 | 675 | """ |
676 | 676 | return self.page_finder[uid].get_graph_id() |
677 | | |
| 677 | |
678 | 678 | def save_fit_state(self, filepath, fitstate): |
679 | 679 | """ |
… |
… |
|
693 | 693 | if uid in self.page_finder.keys(): |
694 | 694 | self.page_finder[uid].set_weight(flag=flag, is2d=is2d) |
695 | | |
| 695 | |
696 | 696 | def set_fit_range(self, uid, qmin, qmax, fid=None): |
697 | 697 | """ |
… |
… |
|
706 | 706 | if uid in self.page_finder.keys(): |
707 | 707 | self.page_finder[uid].set_range(qmin=qmin, qmax=qmax, fid=fid) |
708 | | |
| 708 | |
709 | 709 | def schedule_for_fit(self, value=0, uid=None): |
710 | 710 | """ |
… |
… |
|
717 | 717 | if uid in self.page_finder.keys(): |
718 | 718 | self.page_finder[uid].schedule_tofit(value) |
719 | | |
| 719 | |
720 | 720 | def get_page_finder(self): |
721 | 721 | """ |
… |
… |
|
723 | 723 | """ |
724 | 724 | return self.page_finder |
725 | | |
| 725 | |
726 | 726 | def set_page_finder(self, modelname, names, values): |
727 | 727 | """ |
728 | 728 | Used by simfitpage.py to reset a parameter given the string constrainst. |
729 | | |
| 729 | |
730 | 730 | :param modelname: the name ot the model for with the parameter |
731 | 731 | has to reset |
… |
… |
|
741 | 741 | value.set_model_param(names, values) |
742 | 742 | break |
743 | | |
| 743 | |
744 | 744 | def split_string(self, item): |
745 | 745 | """ |
746 | 746 | receive a word containing dot and split it. used to split parameterset |
747 | 747 | name into model name and parameter name example: :: |
748 | | |
| 748 | |
749 | 749 | paramaterset (item) = M1.A |
750 | 750 | Will return model_name = M1 , parameter name = A |
751 | | |
| 751 | |
752 | 752 | """ |
753 | 753 | if item.find(".") >= 0: |
… |
… |
|
760 | 760 | param_name = param_names[1] |
761 | 761 | return model_name, param_name |
762 | | |
| 762 | |
763 | 763 | def on_bumps_options(self, event=None): |
764 | 764 | from bumps.gui.fit_dialog import OpenFitOptions |
… |
… |
|
786 | 786 | panel = self.fit_panel.opened_pages[uid] |
787 | 787 | panel._on_fit_complete() |
788 | | |
| 788 | |
789 | 789 | def set_smearer(self, uid, smearer, fid, qmin=None, qmax=None, draw=True, |
790 | 790 | enable_smearer=False): |
… |
… |
|
792 | 792 | Get a smear object and store it to a fit problem of fid as id. If proper |
793 | 793 | flag is enable , will plot the theory with smearing information. |
794 | | |
| 794 | |
795 | 795 | :param smearer: smear object to allow smearing data of id fid |
796 | 796 | :param enable_smearer: Define whether or not all (data, model) contained |
… |
… |
|
828 | 828 | qmin=qmin, qmax=qmax, weight=weight) |
829 | 829 | self._mac_sleep(0.2) |
830 | | |
| 830 | |
831 | 831 | def _mac_sleep(self, sec=0.2): |
832 | 832 | """ |
… |
… |
|
835 | 835 | if ON_MAC: |
836 | 836 | time.sleep(sec) |
837 | | |
| 837 | |
838 | 838 | def draw_model(self, model, page_id, data=None, smearer=None, |
839 | 839 | enable1D=True, enable2D=False, |
… |
… |
|
845 | 845 | """ |
846 | 846 | Draw model. |
847 | | |
| 847 | |
848 | 848 | :param model: the model to draw |
849 | 849 | :param name: the name of the model to draw |
… |
… |
|
856 | 856 | :param qstep: number of step to divide the x and y-axis |
857 | 857 | :param update_chisqr: update chisqr [bool] |
858 | | |
| 858 | |
859 | 859 | """ |
860 | 860 | #self.weight = weight |
… |
… |
|
889 | 889 | update_chisqr=update_chisqr, |
890 | 890 | source=source) |
891 | | |
| 891 | |
892 | 892 | def onFit(self, uid): |
893 | 893 | """ |
… |
… |
|
934 | 934 | is2d=page._is_2D()) |
935 | 935 | if not page.param_toFit: |
936 | | msg = "No fitting parameters for %s"%page.window_caption |
| 936 | msg = "No fitting parameters for %s" % page.window_caption |
937 | 937 | wx.PostEvent(page.parent.parent, |
938 | 938 | StatusEvent(status=msg, info="error", |
… |
… |
|
979 | 979 | msg = "Fitting is in progress..." |
980 | 980 | wx.PostEvent(self.parent, StatusEvent(status=msg, type="progress")) |
981 | | |
| 981 | |
982 | 982 | #Handler used for fit engine displayed message |
983 | 983 | handler = ConsoleUpdate(parent=self.parent, |
… |
… |
|
1019 | 1019 | msg = "Fitting is in progress..." |
1020 | 1020 | wx.PostEvent(self.parent, StatusEvent(status=msg, type="progress")) |
1021 | | |
| 1021 | |
1022 | 1022 | return True |
1023 | 1023 | |
… |
… |
|
1043 | 1043 | group_id=group_id, |
1044 | 1044 | action='remove')) |
1045 | | |
| 1045 | |
1046 | 1046 | def store_data(self, uid, data_list=None, caption=None): |
1047 | 1047 | """ |
… |
… |
|
1054 | 1054 | if data_list is None: |
1055 | 1055 | data_list = [] |
1056 | | |
| 1056 | |
1057 | 1057 | self.page_finder[uid].set_fit_data(data=data_list) |
1058 | 1058 | if caption is not None: |
1059 | 1059 | self.page_finder[uid].set_fit_tab_caption(caption=caption) |
1060 | | |
| 1060 | |
1061 | 1061 | def on_add_new_page(self, event=None): |
1062 | 1062 | """ |
… |
… |
|
1074 | 1074 | info="warning")) |
1075 | 1075 | except: |
1076 | | msg = "Creating Fit page: %s"%sys.exc_value |
| 1076 | msg = "Creating Fit page: %s" % sys.exc_value |
1077 | 1077 | wx.PostEvent(self.parent, StatusEvent(status=msg, info="error")) |
1078 | | |
| 1078 | |
1079 | 1079 | def add_fit_page(self, data): |
1080 | 1080 | """ |
… |
… |
|
1105 | 1105 | group_id = str(page.uid) + " Model2D" |
1106 | 1106 | data.group_id = theory_data.group_id |
1107 | | wx.PostEvent(self.parent, |
| 1107 | wx.PostEvent(self.parent, |
1108 | 1108 | NewPlotEvent(group_id=group_id, |
1109 | 1109 | action="delete")) |
… |
… |
|
1116 | 1116 | if self.batch_page is not None and self.batch_on: |
1117 | 1117 | self.batch_page.draw_page() |
1118 | | |
| 1118 | |
1119 | 1119 | return page |
1120 | | |
| 1120 | |
1121 | 1121 | def _onEVT_SLICER_PANEL(self, event): |
1122 | 1122 | """ |
… |
… |
|
1124 | 1124 | event.panel_name. this method update slicer panel |
1125 | 1125 | for a given interactor. |
1126 | | |
| 1126 | |
1127 | 1127 | :param event: contains type of slicer , paramaters for updating |
1128 | 1128 | the panel and panel_name to find the slicer 's panel concerned. |
… |
… |
|
1133 | 1133 | if self.parent.panels[item].window_caption.startswith(name): |
1134 | 1134 | self.parent.panels[item].set_slicer(event.type, event.params) |
1135 | | |
| 1135 | |
1136 | 1136 | #self.parent._mgr.Update() |
1137 | | |
| 1137 | |
1138 | 1138 | def _closed_fitpage(self, event): |
1139 | 1139 | """ |
… |
… |
|
1147 | 1147 | event.data.__class__.__name__ == "Data1D": |
1148 | 1148 | self.fit_panel.close_page_with_data(event.data) |
1149 | | |
| 1149 | |
1150 | 1150 | def _reset_schedule_problem(self, value=0, uid=None): |
1151 | 1151 | """ |
… |
… |
|
1160 | 1160 | if uid in self.page_finder.keys(): |
1161 | 1161 | self.page_finder[uid].schedule_tofit(value) |
1162 | | |
| 1162 | |
1163 | 1163 | def _add_problem_to_fit(self, fitproblem, pars, fitter, fit_id): |
1164 | 1164 | """ |
… |
… |
|
1187 | 1187 | qmax=qmax) |
1188 | 1188 | fitter.select_problem_for_fit(id=fit_id, value=1) |
1189 | | |
| 1189 | |
1190 | 1190 | def _onSelect(self, event): |
1191 | 1191 | """ |
… |
… |
|
1198 | 1198 | Plugin.on_perspective(self, event=event) |
1199 | 1199 | self.select_data(panel) |
1200 | | |
| 1200 | |
1201 | 1201 | def select_data(self, panel): |
1202 | 1202 | """ |
… |
… |
|
1212 | 1212 | data = plottable |
1213 | 1213 | self.add_fit_page(data=[data]) |
1214 | | |
| 1214 | |
1215 | 1215 | def update_fit(self, result=None, msg=""): |
1216 | 1216 | """ |
1217 | 1217 | """ |
1218 | 1218 | print "update_fit result", result |
1219 | | |
| 1219 | |
1220 | 1220 | def _batch_fit_complete(self, result, pars, page_id, |
1221 | 1221 | batch_outputs, batch_inputs, elapsed=None): |
… |
… |
|
1231 | 1231 | if uid in self.fit_thread_list.keys(): |
1232 | 1232 | del self.fit_thread_list[uid] |
1233 | | |
| 1233 | |
1234 | 1234 | self._update_fit_button(page_id) |
1235 | 1235 | t1 = time.time() |
… |
… |
|
1239 | 1239 | wx.PostEvent(self.parent, StatusEvent(status=msg, info="info", |
1240 | 1240 | type="stop")) |
1241 | | |
| 1241 | |
1242 | 1242 | if batch_outputs is None: |
1243 | 1243 | batch_outputs = {} |
1244 | | |
| 1244 | |
1245 | 1245 | # format batch_outputs |
1246 | 1246 | batch_outputs["Chi2"] = [] |
… |
… |
|
1278 | 1278 | if data is not None and hasattr(data, "sas_data"): |
1279 | 1279 | data = data.sas_data |
1280 | | |
| 1280 | |
1281 | 1281 | is_data2d = issubclass(data.__class__, Data2D) |
1282 | 1282 | #check consistency of arrays |
… |
… |
|
1327 | 1327 | if res.pvec.__class__ == numpy.float64: |
1328 | 1328 | res.pvec = [res.pvec] |
1329 | | |
| 1329 | |
1330 | 1330 | cell = BatchCell() |
1331 | 1331 | cell.label = res.fitness |
… |
… |
|
1354 | 1354 | if key not in param_list and key not in ["Chi2", "Data"]: |
1355 | 1355 | batch_outputs[key].append(EMPTY) |
1356 | | |
| 1356 | |
1357 | 1357 | self.page_finder[pid].set_batch_result(batch_inputs=batch_inputs, |
1358 | 1358 | batch_outputs=batch_outputs) |
1359 | | |
| 1359 | |
1360 | 1360 | cpage = self.fit_panel.get_page_by_id(pid) |
1361 | 1361 | cpage._on_fit_complete() |
… |
… |
|
1387 | 1387 | batch_outputs=batch_outputs, |
1388 | 1388 | batch_inputs=batch_inputs) |
1389 | | |
| 1389 | |
1390 | 1390 | wx.PostEvent(self.parent, StatusEvent(status=msg, error="info", |
1391 | 1391 | type="stop")) |
… |
… |
|
1397 | 1397 | if key in ["Chi2", "Data"] or shownkeystr.count(key) > 0: |
1398 | 1398 | tbatch_outputs[key] = batch_outputs[key] |
1399 | | |
| 1399 | |
1400 | 1400 | wx.CallAfter(self.parent.on_set_batch_result, tbatch_outputs, |
1401 | 1401 | batch_inputs, self.sub_menu) |
1402 | | |
| 1402 | |
1403 | 1403 | def on_set_batch_result(self, page_id, fid, batch_outputs, batch_inputs): |
1404 | 1404 | """ |
… |
… |
|
1420 | 1420 | cell.label = data.name |
1421 | 1421 | cell.value = index |
1422 | | |
| 1422 | |
1423 | 1423 | if theory_data != None: |
1424 | 1424 | #Suucessful fit |
… |
… |
|
1430 | 1430 | if group_id not in theory_data.list_group_id: |
1431 | 1431 | theory_data.list_group_id.append(group_id) |
1432 | | |
| 1432 | |
1433 | 1433 | try: |
1434 | 1434 | # associate residuals plot |
… |
… |
|
1454 | 1454 | batch_inputs[param] = [] |
1455 | 1455 | batch_inputs[param].append(data.sample.temperature) |
1456 | | |
| 1456 | |
1457 | 1457 | def _fit_completed(self, result, page_id, batch_outputs, |
1458 | 1458 | batch_inputs=None, pars=None, elapsed=None): |
… |
… |
|
1522 | 1522 | info="error", |
1523 | 1523 | type="stop")) |
1524 | | |
| 1524 | |
1525 | 1525 | except: |
1526 | 1526 | msg = "Fit completed but Following" |
… |
… |
|
1528 | 1528 | wx.PostEvent(self.parent, StatusEvent(status=msg, info="warning", |
1529 | 1529 | type="stop")) |
1530 | | |
| 1530 | |
1531 | 1531 | def _update_fit_button(self, page_id): |
1532 | 1532 | """ |
1533 | 1533 | Update Fit button when fit stopped |
1534 | | |
| 1534 | |
1535 | 1535 | : parameter page_id: fitpage where the button is |
1536 | 1536 | """ |
… |
… |
|
1540 | 1540 | page = self.fit_panel.get_page_by_id(uid) |
1541 | 1541 | page._on_fit_complete() |
1542 | | |
| 1542 | |
1543 | 1543 | def _on_show_panel(self, event): |
1544 | 1544 | """ |
1545 | 1545 | """ |
1546 | 1546 | pass |
1547 | | |
| 1547 | |
1548 | 1548 | def on_reset_batch_flag(self, event): |
1549 | 1549 | """ |
… |
… |
|
1561 | 1561 | menu_item.Check(True) |
1562 | 1562 | self.batch_reset_flag = False |
1563 | | |
| 1563 | |
1564 | 1564 | ## post a message to status bar |
1565 | 1565 | msg = "Set Chain Fitting: %s" % str(not self.batch_reset_flag) |
… |
… |
|
1571 | 1571 | """ |
1572 | 1572 | Receive a panel as event and send it to guiframe |
1573 | | |
| 1573 | |
1574 | 1574 | :param event: event containing a panel |
1575 | | |
| 1575 | |
1576 | 1576 | """ |
1577 | 1577 | if event.panel is not None: |
… |
… |
|
1582 | 1582 | event.panel.uid = event_id |
1583 | 1583 | self.mypanels.append(event.panel) |
1584 | | |
| 1584 | |
1585 | 1585 | def _onclearslicer(self, event): |
1586 | 1586 | """ |
… |
… |
|
1590 | 1590 | for panel in self.slicer_panels: |
1591 | 1591 | if panel.window_caption == name: |
1592 | | |
| 1592 | |
1593 | 1593 | for item in self.parent.panels: |
1594 | 1594 | if hasattr(self.parent.panels[item], "uid"): |
… |
… |
|
1598 | 1598 | break |
1599 | 1599 | break |
1600 | | |
| 1600 | |
1601 | 1601 | def _on_model_panel(self, evt): |
1602 | 1602 | """ |
1603 | | react to model selection on any combo box or model menu.plot the model |
1604 | | |
| 1603 | react to model selection on any combo box or model menu.plot the model |
| 1604 | |
1605 | 1605 | :param evt: wx.combobox event |
1606 | | |
| 1606 | |
1607 | 1607 | """ |
1608 | 1608 | model = evt.model |
… |
… |
|
1625 | 1625 | if self.batch_page is not None and self.batch_on: |
1626 | 1626 | self.batch_page.draw_page() |
1627 | | |
| 1627 | |
1628 | 1628 | def _update1D(self, x, output): |
1629 | 1629 | """ |
… |
… |
|
1632 | 1632 | msg = "Plot updating ... " |
1633 | 1633 | wx.PostEvent(self.parent, StatusEvent(status=msg, type="update")) |
1634 | | |
| 1634 | |
1635 | 1635 | def _complete1D(self, x, y, page_id, elapsed, index, model, |
1636 | 1636 | weight=None, fid=None, |
… |
… |
|
1643 | 1643 | try: |
1644 | 1644 | numpy.nan_to_num(y) |
1645 | | |
| 1645 | |
1646 | 1646 | new_plot = Data1D(x=x, y=y) |
1647 | 1647 | new_plot.is_data = False |
… |
… |
|
1661 | 1661 | #the same id |
1662 | 1662 | theory_data = self.page_finder[page_id].get_theory_data(fid=data.id) |
1663 | | |
| 1663 | |
1664 | 1664 | if data.is_data: |
1665 | 1665 | data_name = str(data.name) |
1666 | 1666 | else: |
1667 | 1667 | data_name = str(model.__class__.__name__) |
1668 | | |
1669 | | new_plot.name = model.name + " [" + data_name +"]" |
| 1668 | |
| 1669 | new_plot.name = model.name + " [" + data_name + "]" |
1670 | 1670 | new_plot.xaxis(_xaxis, _xunit) |
1671 | 1671 | new_plot.yaxis(_yaxis, _yunit) |
… |
… |
|
1687 | 1687 | caption = current_pg.window_caption |
1688 | 1688 | self.page_finder[page_id].set_fit_tab_caption(caption=caption) |
1689 | | |
| 1689 | |
1690 | 1690 | self.page_finder[page_id].set_theory_data(data=new_plot, |
1691 | 1691 | fid=data.id) |
… |
… |
|
1711 | 1711 | except: |
1712 | 1712 | raise |
1713 | | |
| 1713 | |
1714 | 1714 | def _update2D(self, output, time=None): |
1715 | 1715 | """ |
… |
… |
|
1719 | 1719 | #updating ... ", type="update")) |
1720 | 1720 | #self.ready_fit() |
1721 | | |
| 1721 | |
1722 | 1722 | def _complete2D(self, image, data, model, page_id, elapsed, index, qmin, |
1723 | 1723 | qmax, fid=None, weight=None, toggle_mode_on=False, state=None, |
… |
… |
|
1746 | 1746 | new_plot.xmax = data.xmax |
1747 | 1747 | title = data.title |
1748 | | |
| 1748 | |
1749 | 1749 | new_plot.is_data = False |
1750 | 1750 | if data.is_data: |
… |
… |
|
1754 | 1754 | |
1755 | 1755 | if len(title) > 1: |
1756 | | new_plot.title = "Model2D for %s "% model.name + data_name |
| 1756 | new_plot.title = "Model2D for %s " % model.name + data_name |
1757 | 1757 | new_plot.name = model.name + " [" + \ |
1758 | 1758 | data_name + "]" |
1759 | 1759 | theory_data = deepcopy(new_plot) |
1760 | | |
| 1760 | |
1761 | 1761 | self.page_finder[page_id].set_theory_data(data=theory_data, |
1762 | 1762 | fid=data.id) |
… |
… |
|
1787 | 1787 | msg = "Computation completed!" |
1788 | 1788 | wx.PostEvent(self.parent, StatusEvent(status=msg, type="stop")) |
1789 | | |
| 1789 | |
1790 | 1790 | def _draw_model2D(self, model, page_id, qmin, |
1791 | 1791 | qmax, |
… |
… |
|
1799 | 1799 | """ |
1800 | 1800 | draw model in 2D |
1801 | | |
| 1801 | |
1802 | 1802 | :param model: instance of the model to draw |
1803 | 1803 | :param description: the description of the model |
… |
… |
|
1806 | 1806 | :param qmax: the maximum value to draw model 2D |
1807 | 1807 | :param qstep: the number of division of Qx and Qy of the model to draw |
1808 | | |
| 1808 | |
1809 | 1809 | """ |
1810 | 1810 | if not enable2D: |
… |
… |
|
1829 | 1829 | qmin=qmin, |
1830 | 1830 | qmax=qmax, |
1831 | | weight=weight, |
| 1831 | weight=weight, |
1832 | 1832 | fid=fid, |
1833 | 1833 | toggle_mode_on=toggle_mode_on, |
… |
… |
|
1848 | 1848 | """ |
1849 | 1849 | Draw model 1D from loaded data1D |
1850 | | |
| 1850 | |
1851 | 1851 | :param data: loaded data |
1852 | 1852 | :param model: the model to plot |
1853 | | |
| 1853 | |
1854 | 1854 | """ |
1855 | 1855 | if not enable1D: |
… |
… |
|
1878 | 1878 | self.calc_1D = Calc1D(data=data, |
1879 | 1879 | model=model, |
1880 | | page_id=page_id, |
| 1880 | page_id=page_id, |
1881 | 1881 | qmin=qmin, |
1882 | 1882 | qmax=qmax, |
… |
… |
|
1895 | 1895 | msg += " %s" % sys.exc_value |
1896 | 1896 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
1897 | | |
| 1897 | |
1898 | 1898 | def _cal_chisqr(self, page_id, data, weight, fid=None, index=None): |
1899 | 1899 | """ |
1900 | | Get handy Chisqr using the output from draw1D and 2D, |
| 1900 | Get handy Chisqr using the output from draw1D and 2D, |
1901 | 1901 | instead of calling expansive CalcChisqr in guithread |
1902 | 1902 | """ |
… |
… |
|
1929 | 1929 | else: |
1930 | 1930 | # 1 d theory from model_thread is only in the range of index |
1931 | | if index == None: |
| 1931 | if index == None: |
1932 | 1932 | index = numpy.ones(len(data_copy.y), dtype=bool) |
1933 | 1933 | if weight != None: |
… |
… |
|
1941 | 1941 | dy[dy == 0] = 1 |
1942 | 1942 | fn = data_copy.y[index] |
1943 | | |
| 1943 | |
1944 | 1944 | theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) |
1945 | 1945 | if theory_data == None: |
… |
… |
|
1947 | 1947 | gn = theory_data.y |
1948 | 1948 | en = dy[index] |
1949 | | |
| 1949 | |
1950 | 1950 | # residual |
1951 | 1951 | try: |
1952 | 1952 | res = (fn - gn) / en |
1953 | 1953 | except ValueError: |
1954 | | print "Unmatch lengths %s, %s, %s"% (len(fn), len(gn), len(en)) |
| 1954 | print "Unmatch lengths %s, %s, %s" % (len(fn), len(gn), len(en)) |
1955 | 1955 | return |
1956 | | |
| 1956 | |
1957 | 1957 | residuals = res[numpy.isfinite(res)] |
1958 | 1958 | # get chisqr only w/finite |
1959 | 1959 | chisqr = numpy.average(residuals * residuals) |
1960 | | |
| 1960 | |
1961 | 1961 | self._plot_residuals(page_id=page_id, data=data_copy, |
1962 | 1962 | fid=fid, |
1963 | 1963 | weight=weight, index=index) |
1964 | | |
| 1964 | |
1965 | 1965 | return chisqr |
1966 | | |
| 1966 | |
1967 | 1967 | def _plot_residuals(self, page_id, weight, fid=None, |
1968 | 1968 | data=None, index=None): |
1969 | 1969 | """ |
1970 | 1970 | Plot the residuals |
1971 | | |
| 1971 | |
1972 | 1972 | :param data: data |
1973 | 1973 | :param index: index array (bool) |
… |
… |
|
2040 | 2040 | theory_name = str(theory_data.name.split()[0]) |
2041 | 2041 | new_plot = residuals |
2042 | | new_plot.name = "Residuals for " + str(theory_name) + "[" +\ |
2043 | | str(data.name) +"]" |
| 2042 | new_plot.name = "Residuals for " + str(theory_name) + "[" + \ |
| 2043 | str(data.name) + "]" |
2044 | 2044 | ## allow to highlight data when plotted |
2045 | 2045 | new_plot.interactive = True |
-
r79492222
|
r2f4b430
|
|
21 | 21 | ScrolledPanel.__init__(self, *args, **kwds) |
22 | 22 | self.SetupScrolling() |
23 | | |
24 | | |
| 23 | |
| 24 | |
25 | 25 | class BatchDataDialog(wx.Dialog): |
26 | 26 | """ |
… |
… |
|
35 | 35 | self.data_2d_selected = None |
36 | 36 | self._do_layout() |
37 | | |
| 37 | |
38 | 38 | def _do_layout(self): |
39 | 39 | """ |
… |
… |
|
43 | 43 | box_description = wx.StaticBox(self, -1, str("Hint")) |
44 | 44 | hint_sizer = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
45 | | selection_sizer = wx.GridBagSizer(5,5) |
| 45 | selection_sizer = wx.GridBagSizer(5, 5) |
46 | 46 | button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
47 | 47 | self.data_1d_selected = wx.RadioButton(self, -1, 'Data1D', |
… |
… |
|
60 | 60 | iy = 0 |
61 | 61 | selection_sizer.Add(self.data_1d_selected, (iy, ix), |
62 | | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
| 62 | (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
63 | 63 | iy += 1 |
64 | 64 | selection_sizer.Add(self.data_2d_selected, (iy, ix), |
65 | | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
| 65 | (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
66 | 66 | #contruction the sizer contaning button |
67 | | button_sizer.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
| 67 | button_sizer.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
68 | 68 | button_sizer.Add(button_cancel, 0, |
69 | | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
| 69 | wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) |
70 | 70 | button_sizer.Add(button_OK, 0, |
71 | | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
72 | | vbox.Add(hint_sizer, 0, wx.EXPAND|wx.ALL, 10) |
73 | | vbox.Add(selection_sizer, 0, wx.TOP|wx.BOTTOM, 10) |
74 | | vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
75 | | vbox.Add(button_sizer, 0, wx.TOP|wx.BOTTOM, 10) |
| 71 | wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) |
| 72 | vbox.Add(hint_sizer, 0, wx.EXPAND | wx.ALL, 10) |
| 73 | vbox.Add(selection_sizer, 0, wx.TOP | wx.BOTTOM, 10) |
| 74 | vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
| 75 | vbox.Add(button_sizer, 0, wx.TOP | wx.BOTTOM, 10) |
76 | 76 | self.SetSizer(vbox) |
77 | 77 | self.Layout() |
78 | | |
| 78 | |
79 | 79 | def get_data(self): |
80 | 80 | """ |
… |
… |
|
97 | 97 | self._max_data = nb_data |
98 | 98 | self._nb_selected_data = nb_data |
99 | | |
| 99 | |
100 | 100 | self.SetSize((WIDTH, HEIGHT)) |
101 | 101 | self.list_of_ctrl = [] |
… |
… |
|
104 | 104 | select_data_text = " %s Data selected.\n" % str(self._nb_selected_data) |
105 | 105 | self._data_text_ctrl = wx.StaticText(self, -1, str(select_data_text)) |
106 | | |
| 106 | |
107 | 107 | self._data_text_ctrl.SetForegroundColour('blue') |
108 | 108 | self._sizer_main = wx.BoxSizer(wx.VERTICAL) |
… |
… |
|
111 | 111 | self._choice_sizer = wx.GridBagSizer(5, 5) |
112 | 112 | self._panel = DialogPanel(self, style=wx.RAISED_BORDER, |
113 | | size=(WIDTH-20, HEIGHT/3)) |
| 113 | size=(WIDTH - 20, HEIGHT / 3)) |
114 | 114 | self.__do_layout(data_list, text=text) |
115 | | |
| 115 | |
116 | 116 | def __do_layout(self, data_list, text=''): |
117 | 117 | """ |
… |
… |
|
141 | 141 | self.list_of_ctrl.append((cb, data_list[i])) |
142 | 142 | self._choice_sizer.Add(cb, (iy, ix), |
143 | | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
| 143 | (1, 1), wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
144 | 144 | iy += 1 |
145 | 145 | self._panel.SetSizer(self._choice_sizer) |
146 | 146 | #add sizer |
147 | | self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
| 147 | self._sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
148 | 148 | button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
149 | 149 | self._sizer_button.Add(button_cancel, 0, |
150 | | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
| 150 | wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) |
151 | 151 | button_OK = wx.Button(self, wx.ID_OK, "Ok") |
152 | 152 | button_OK.SetFocus() |
153 | 153 | self._sizer_button.Add(button_OK, 0, |
154 | | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
| 154 | wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) |
155 | 155 | static_line = wx.StaticLine(self, -1) |
156 | | self._sizer_txt.Add(self._panel, 0, wx.EXPAND|wx.ALL, 10) |
157 | | self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND|wx.ALL, 10) |
158 | | self._sizer_main.Add(self._data_text_ctrl, 0, wx.EXPAND|wx.ALL, 10) |
| 156 | self._sizer_txt.Add(self._panel, 0, wx.EXPAND | wx.ALL, 10) |
| 157 | self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND | wx.ALL, 10) |
| 158 | self._sizer_main.Add(self._data_text_ctrl, 0, wx.EXPAND | wx.ALL, 10) |
159 | 159 | self._sizer_main.Add(static_line, 0, wx.EXPAND, 0) |
160 | | self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10) |
| 160 | self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND | wx.ALL, 10) |
161 | 161 | self.SetSizer(self._sizer_main) |
162 | 162 | self.Layout() |
163 | | |
| 163 | |
164 | 164 | def get_data(self): |
165 | 165 | """ |
… |
… |
|
172 | 172 | temp.append(data) |
173 | 173 | return temp |
174 | | |
| 174 | |
175 | 175 | def _count_selected_data(self, event): |
176 | 176 | """ |
-
r79492222
|
r2f4b430
|
|
13 | 13 | ## Title to appear on top of the window |
14 | 14 | window_caption = "Hint page " |
15 | | |
| 15 | |
16 | 16 | def __init__(self, parent): |
17 | 17 | wx.ScrolledWindow.__init__(self, parent, |
18 | | style = wx.FULL_REPAINT_ON_RESIZE) |
| 18 | style=wx.FULL_REPAINT_ON_RESIZE) |
19 | 19 | PanelBase.__init__(self, parent) |
20 | 20 | msg = "right click on the data when it is highlighted " |
21 | 21 | msg += "the select option to fit for futher options" |
22 | 22 | self.do_layout() |
23 | | |
| 23 | |
24 | 24 | def do_layout(self): |
25 | 25 | """ |
… |
… |
|
27 | 27 | """ |
28 | 28 | name = "Hint" |
29 | | box_description= wx.StaticBox(self, -1, name) |
| 29 | box_description = wx.StaticBox(self, -1, name) |
30 | 30 | boxsizer = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
31 | 31 | msg = " How to link data to the control panel: \n \n" |
… |
… |
|
34 | 34 | msg += " Finally, select 'Select data for fitting' in the pop-up menu. \n" |
35 | 35 | self.hint_txt = wx.StaticText(self, -1, msg, style=wx.ALIGN_LEFT) |
36 | | boxsizer.Add(self.hint_txt, wx.ALL|wx.EXPAND, 20) |
| 36 | boxsizer.Add(self.hint_txt, wx.ALL | wx.EXPAND, 20) |
37 | 37 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
38 | 38 | self.vbox.Add(boxsizer) |
… |
… |
|
42 | 42 | self.SetScrollbars(20, 20, 25, 65) |
43 | 43 | self.Layout() |
44 | | |
| 44 | |
45 | 45 | def createMemento(self): |
46 | 46 | return |
47 | | |
48 | | |
| 47 | |
| 48 | |
49 | 49 | class HelpWindow(wx.Frame): |
50 | 50 | def __init__(self, parent, id, title): |
51 | 51 | wx.Frame.__init__(self, parent, id, title, size=(570, 400)) |
52 | | |
| 52 | |
53 | 53 | self.page = HintFitPage(self) |
54 | 54 | self.Centre() |
-
r79492222
|
r2f4b430
|
|
43 | 43 | self.update_chisqr = update_chisqr |
44 | 44 | self.source = source |
45 | | |
| 45 | |
46 | 46 | def compute(self): |
47 | 47 | """ |
… |
… |
|
59 | 59 | math.fabs(self.data.ymin)), 2) |
60 | 60 | self.qmax = math.sqrt(newx + newy) |
61 | | |
| 61 | |
62 | 62 | if self.data is None: |
63 | 63 | msg = "Compute Calc2D receive data = %s.\n" % str(self.data) |
64 | 64 | raise ValueError, msg |
65 | | |
| 65 | |
66 | 66 | # Define matrix where data will be plotted |
67 | 67 | radius = numpy.sqrt((self.data.qx_data * self.data.qx_data) + \ |
… |
… |
|
73 | 73 | index_model = index_model & self.data.mask |
74 | 74 | index_model = index_model & numpy.isfinite(self.data.data) |
75 | | |
| 75 | |
76 | 76 | if self.smearer is not None: |
77 | 77 | # Set smearer w/ data, model and index. |
… |
… |
|
112 | 112 | update_chisqr=self.update_chisqr, |
113 | 113 | source=self.source) |
114 | | |
| 114 | |
115 | 115 | |
116 | 116 | class Calc1D(CalcThread): |
… |
… |
|
156 | 156 | self.out = None |
157 | 157 | self.index = None |
158 | | |
| 158 | |
159 | 159 | def compute(self): |
160 | 160 | """ |
… |
… |
|
164 | 164 | output = numpy.zeros((len(self.data.x))) |
165 | 165 | index = (self.qmin <= self.data.x) & (self.data.x <= self.qmax) |
166 | | |
| 166 | |
167 | 167 | ##smearer the ouput of the plot |
168 | 168 | if self.smearer is not None: |
… |
… |
|
174 | 174 | else: |
175 | 175 | output[index] = self.model.evalDistribution(self.data.x[index]) |
176 | | |
| 176 | |
177 | 177 | elapsed = time.time() - self.starttime |
178 | | |
| 178 | |
179 | 179 | self.complete(x=self.data.x[index], y=output[index], |
180 | 180 | page_id=self.page_id, |
… |
… |
|
187 | 187 | update_chisqr=self.update_chisqr, |
188 | 188 | source=self.source) |
189 | | |
| 189 | |
190 | 190 | def results(self): |
191 | 191 | """ |
… |
… |
|
196 | 196 | """ |
197 | 197 | Example: :: |
198 | | |
| 198 | |
199 | 199 | class CalcCommandline: |
200 | 200 | def __init__(self, n=20000): |
201 | 201 | #print thread.get_ident() |
202 | 202 | from sas.models.CylinderModel import CylinderModel |
203 | | |
| 203 | |
204 | 204 | model = CylinderModel() |
205 | | |
206 | | |
| 205 | |
| 206 | |
207 | 207 | print model.runXY([0.01, 0.02]) |
208 | | |
| 208 | |
209 | 209 | qmax = 0.01 |
210 | 210 | qstep = 0.0001 |
211 | 211 | self.done = False |
212 | | |
| 212 | |
213 | 213 | x = numpy.arange(-qmax, qmax+qstep*0.01, qstep) |
214 | 214 | y = numpy.arange(-qmax, qmax+qstep*0.01, qstep) |
215 | | |
216 | | |
| 215 | |
| 216 | |
217 | 217 | calc_thread_2D = Calc2D(x, y, None, model.clone(),None, |
218 | 218 | -qmax, qmax,qstep, |
… |
… |
|
220 | 220 | updatefn=self.update , |
221 | 221 | yieldtime=0.0) |
222 | | |
| 222 | |
223 | 223 | calc_thread_2D.queue() |
224 | 224 | calc_thread_2D.ready(2.5) |
225 | | |
| 225 | |
226 | 226 | while not self.done: |
227 | 227 | time.sleep(1) |
228 | | |
| 228 | |
229 | 229 | def update(self,output): |
230 | 230 | print "update" |
231 | | |
| 231 | |
232 | 232 | def complete(self, image, data, model, elapsed, qmin, qmax,index, qstep ): |
233 | 233 | print "complete" |
234 | 234 | self.done = True |
235 | | |
| 235 | |
236 | 236 | if __name__ == "__main__": |
237 | 237 | CalcCommandline() |
-
r6f82ba1
|
r2f4b430
|
|
20 | 20 | from sas.models.BaseComponent import BaseComponent |
21 | 21 | from sas.guiframe.CategoryInstaller import CategoryInstaller |
22 | | |
| 22 | |
23 | 23 | PLUGIN_DIR = 'plugin_models' |
24 | 24 | |
… |
… |
|
40 | 40 | """ |
41 | 41 | Do some checking before model adding plugins in the list |
42 | | |
| 42 | |
43 | 43 | :param model: class model to add into the plugin list |
44 | 44 | :param name:name of the module plugin |
45 | | |
| 45 | |
46 | 46 | :return model: model if valid model or None if not valid |
47 | | |
| 47 | |
48 | 48 | """ |
49 | 49 | #Check if the plugin is of type Model1DPlugin |
… |
… |
|
63 | 63 | log(msg) |
64 | 64 | return None |
65 | | |
| 65 | |
66 | 66 | if hasattr(new_instance, "function"): |
67 | 67 | try: |
… |
… |
|
77 | 77 | return None |
78 | 78 | return model |
79 | | |
80 | | |
| 79 | |
| 80 | |
81 | 81 | def find_plugins_dir(): |
82 | 82 | """ |
… |
… |
|
85 | 85 | """ |
86 | 86 | dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR) |
87 | | |
| 87 | |
88 | 88 | # If the plugin directory doesn't exist, create it |
89 | 89 | if not os.path.isdir(dir): |
90 | 90 | os.makedirs(dir) |
91 | | |
| 91 | |
92 | 92 | # Find paths needed |
93 | 93 | try: |
… |
… |
|
132 | 132 | raise type, value, traceback |
133 | 133 | return 1 |
134 | | |
| 134 | |
135 | 135 | report_problem = ReportProblem() |
136 | 136 | |
… |
… |
|
173 | 173 | if toks[1] == '.py' and not toks[0] == '__init__': |
174 | 174 | name = toks[0] |
175 | | |
| 175 | |
176 | 176 | path = [os.path.abspath(dir)] |
177 | 177 | file = None |
… |
… |
|
194 | 194 | log(msg) |
195 | 195 | finally: |
196 | | |
| 196 | |
197 | 197 | if not file == None: |
198 | 198 | file.close() |
… |
… |
|
213 | 213 | """ |
214 | 214 | self.mydict = {} |
215 | | |
| 215 | |
216 | 216 | def set_list(self, name, mylist): |
217 | 217 | """ |
218 | 218 | :param name: the type of the list |
219 | 219 | :param mylist: the list to add |
220 | | |
| 220 | |
221 | 221 | """ |
222 | 222 | if name not in self.mydict.keys(): |
223 | 223 | self.reset_list(name, mylist) |
224 | | |
| 224 | |
225 | 225 | def reset_list(self, name, mylist): |
226 | 226 | """ |
… |
… |
|
229 | 229 | """ |
230 | 230 | self.mydict[name] = mylist |
231 | | |
| 231 | |
232 | 232 | def get_list(self): |
233 | 233 | """ |
… |
… |
|
235 | 235 | """ |
236 | 236 | return self.mydict |
237 | | |
238 | | |
| 237 | |
| 238 | |
239 | 239 | class ModelManagerBase: |
240 | 240 | """ |
… |
… |
|
262 | 262 | event_owner = None |
263 | 263 | last_time_dir_modified = 0 |
264 | | |
| 264 | |
265 | 265 | def __init__(self): |
266 | 266 | """ |
… |
… |
|
269 | 269 | self.stored_plugins = {} |
270 | 270 | self._getModelList() |
271 | | |
| 271 | |
272 | 272 | def findModels(self): |
273 | 273 | """ |
… |
… |
|
280 | 280 | logging.info("pluging model : %s\n" % str(temp)) |
281 | 281 | return temp |
282 | | |
| 282 | |
283 | 283 | def _getModelList(self): |
284 | 284 | """ |
285 | 285 | List of models we want to make available by default |
286 | 286 | for this application |
287 | | |
| 287 | |
288 | 288 | :return: the next free event ID following the new menu events |
289 | | |
| 289 | |
290 | 290 | """ |
291 | 291 | |
… |
… |
|
702 | 702 | # self.shape_indep_list.append(BEPolyelectrolyte) |
703 | 703 | self.model_name_list.append(BEPolyelectrolyte.__name__) |
704 | | self.form_factor_dict[str(wx.NewId())] = [SphereModel] |
| 704 | self.form_factor_dict[str(wx.NewId())] = [SphereModel] |
705 | 705 | except: |
706 | 706 | pass |
… |
… |
|
1013 | 1013 | #self.shape_indep_list.append(FractalO_Z) |
1014 | 1014 | #self.model_name_list.append(FractalO_Z.__name__) |
1015 | | |
| 1015 | |
1016 | 1016 | #Looking for plugins |
1017 | 1017 | self.stored_plugins = self.findModels() |
… |
… |
|
1019 | 1019 | for name, plug in self.stored_plugins.iteritems(): |
1020 | 1020 | self.model_dictionary[name] = plug |
1021 | | |
| 1021 | |
1022 | 1022 | self._get_multifunc_models() |
1023 | | |
| 1023 | |
1024 | 1024 | return 0 |
1025 | 1025 | |
… |
… |
|
1036 | 1036 | is_modified = True |
1037 | 1037 | self.last_time_dir_modified = temp |
1038 | | |
| 1038 | |
1039 | 1039 | return is_modified |
1040 | | |
| 1040 | |
1041 | 1041 | def update(self): |
1042 | 1042 | """ |
… |
… |
|
1055 | 1055 | else: |
1056 | 1056 | return {} |
1057 | | |
| 1057 | |
1058 | 1058 | def pulgins_reset(self): |
1059 | 1059 | """ |
… |
… |
|
1074 | 1074 | self.model_combobox.reset_list("Customized Models", self.plugins) |
1075 | 1075 | return self.model_combobox.get_list() |
1076 | | |
| 1076 | |
1077 | 1077 | ## I believe the next four methods are for the old form factor GUI |
1078 | 1078 | ## where the dropdown showed a list of categories which then rolled out |
… |
… |
|
1101 | 1101 | ## guiframe reference |
1102 | 1102 | # self.event_owner = event_owner |
1103 | | |
| 1103 | |
1104 | 1104 | # shape_submenu = wx.Menu() |
1105 | 1105 | # shape_indep_submenu = wx.Menu() |
… |
… |
|
1112 | 1112 | # " simple shape"], |
1113 | 1113 | # list1=self.shape_list) |
1114 | | |
| 1114 | |
1115 | 1115 | # self._fill_simple_menu(menuinfo=["Shape-Independent", |
1116 | 1116 | # shape_indep_submenu, |
1117 | 1117 | # "List of shape-independent models"], |
1118 | 1118 | # list1=self.shape_indep_list) |
1119 | | |
| 1119 | |
1120 | 1120 | # self._fill_simple_menu(menuinfo=["Structure Factors", |
1121 | 1121 | # structure_factor, |
1122 | 1122 | # "List of Structure factors models"], |
1123 | 1123 | # list1=self.struct_list) |
1124 | | |
| 1124 | |
1125 | 1125 | # self._fill_plugin_menu(menuinfo=["Customized Models", added_models, |
1126 | 1126 | # "List of additional models"], |
1127 | 1127 | # list1=self.plugins) |
1128 | | |
| 1128 | |
1129 | 1129 | # self._fill_menu(menuinfo=["P(Q)*S(Q)", multip_models, |
1130 | 1130 | # "mulplication of 2 models"], |
… |
… |
|
1132 | 1132 | # list2=self.struct_list) |
1133 | 1133 | # return 0 |
1134 | | |
| 1134 | |
1135 | 1135 | # def _fill_plugin_menu(self, menuinfo, list1): |
1136 | 1136 | # """ |
… |
… |
|
1143 | 1143 | # menuinfo[1].Append(int(id), "Empty", msg) |
1144 | 1144 | # self._fill_simple_menu(menuinfo, list1) |
1145 | | |
| 1145 | |
1146 | 1146 | # def _fill_simple_menu(self, menuinfo, list1): |
1147 | 1147 | # """ |
… |
… |
|
1157 | 1157 | # if len(list1) > 0: |
1158 | 1158 | # self.model_combobox.set_list(menuinfo[0], list1) |
1159 | | |
| 1159 | |
1160 | 1160 | # for item in list1: |
1161 | 1161 | # try: |
… |
… |
|
1217 | 1217 | # id = wx.NewId() |
1218 | 1218 | # self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2]) |
1219 | | |
| 1219 | |
1220 | 1220 | def _on_model(self, evt): |
1221 | 1221 | """ |
1222 | 1222 | React to a model menu event |