[c23f303] | 1 | import wx |
---|
| 2 | import sys |
---|
| 3 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
[3901e7c] | 4 | from sas.sasgui.guiframe.events import PlotQrangeEvent |
---|
| 5 | from sas.sasgui.guiframe.events import StatusEvent |
---|
[c23f303] | 6 | from sas.sasgui.guiframe.panel_base import PanelBase |
---|
[3901e7c] | 7 | from sas.sasgui.guiframe.utils import check_float |
---|
[3b8efec] | 8 | from sas.sasgui.guiframe.dataFitting import Data1D |
---|
[7858575] | 9 | from sas.sasgui.perspectives.invariant.invariant_widgets import OutputTextCtrl |
---|
[9f7dde3] | 10 | from sas.sasgui.perspectives.invariant.invariant_widgets import InvTextCtrl |
---|
[3901e7c] | 11 | from sas.sasgui.perspectives.fitting.basepage import ModelTextCtrl |
---|
[e02d8f6] | 12 | from sas.sasgui.perspectives.corfunc.corfunc_state import CorfuncState |
---|
[3b8efec] | 13 | import sas.sasgui.perspectives.corfunc.corfunc |
---|
| 14 | from sas.sascalc.corfunc.corfunc_calculator import CorfuncCalculator |
---|
[c23f303] | 15 | |
---|
[033c14c] | 16 | OUTPUT_STRINGS = { |
---|
| 17 | 'max': "Long Period (A): ", |
---|
| 18 | 'Lc': "Average Hard Block Thickness (A): ", |
---|
| 19 | 'dtr': "Average Interface Thickness (A): ", |
---|
| 20 | 'd0': "Average Core Thickness: ", |
---|
| 21 | 'A': "PolyDispersity: ", |
---|
| 22 | 'Lc/max': "Filling Fraction: " |
---|
| 23 | } |
---|
| 24 | |
---|
[c23f303] | 25 | if sys.platform.count("win32") > 0: |
---|
[7858575] | 26 | _STATICBOX_WIDTH = 350 |
---|
| 27 | PANEL_WIDTH = 400 |
---|
[c23f303] | 28 | PANEL_HEIGHT = 700 |
---|
| 29 | FONT_VARIANT = 0 |
---|
| 30 | else: |
---|
[7858575] | 31 | _STATICBOX_WIDTH = 390 |
---|
| 32 | PANEL_WIDTH = 430 |
---|
[c23f303] | 33 | PANEL_HEIGHT = 700 |
---|
| 34 | FONT_VARIANT = 1 |
---|
| 35 | |
---|
| 36 | class CorfuncPanel(ScrolledPanel,PanelBase): |
---|
| 37 | window_name = "Correlation Function" |
---|
| 38 | window_caption = "Correlation Function" |
---|
| 39 | CENTER_PANE = True |
---|
| 40 | |
---|
| 41 | def __init__(self, parent, data=None, manager=None, *args, **kwds): |
---|
| 42 | kwds["size"] = (PANEL_WIDTH, PANEL_HEIGHT) |
---|
| 43 | kwds["style"] = wx.FULL_REPAINT_ON_RESIZE |
---|
| 44 | ScrolledPanel.__init__(self, parent=parent, *args, **kwds) |
---|
| 45 | PanelBase.__init__(self, parent) |
---|
| 46 | self.SetupScrolling() |
---|
| 47 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 48 | self._manager = manager |
---|
[911dbe4] | 49 | # The data with no correction for background values |
---|
| 50 | self._data = data # The data to be analysed (corrected fr background) |
---|
[3b8efec] | 51 | self._extrapolated_data = None # The extrapolated data set |
---|
[033c14c] | 52 | self._transformed_data = None # Fourier trans. of the extrapolated data |
---|
[911dbe4] | 53 | self._calculator = CorfuncCalculator() |
---|
[3ec4b8f] | 54 | self._data_name_box = None # Text box to show name of file |
---|
[b564ea2] | 55 | self._background_input = None |
---|
[3901e7c] | 56 | self._qmin_input = None |
---|
| 57 | self._qmax1_input = None |
---|
| 58 | self._qmax2_input = None |
---|
[911dbe4] | 59 | self._transform_btn = None |
---|
[033c14c] | 60 | self._extract_btn = None |
---|
[e02d8f6] | 61 | self.qmin = 0 |
---|
| 62 | self.qmax = (0, 0) |
---|
[b564ea2] | 63 | self.background = 0 |
---|
[033c14c] | 64 | # Dictionary for saving refs to text boxes used to display output data |
---|
| 65 | self._output_boxes = None |
---|
[c23f303] | 66 | self.state = None |
---|
| 67 | self._do_layout() |
---|
[54a0989] | 68 | self._disable_inputs() |
---|
[e02d8f6] | 69 | self.set_state() |
---|
[b564ea2] | 70 | self._qmin_input.Bind(wx.EVT_TEXT, self._on_enter_input) |
---|
| 71 | self._qmax1_input.Bind(wx.EVT_TEXT, self._on_enter_input) |
---|
| 72 | self._qmax2_input.Bind(wx.EVT_TEXT, self._on_enter_input) |
---|
[688d029] | 73 | self._qmin_input.Bind(wx.EVT_MOUSE_EVENTS, self._on_click_qrange) |
---|
| 74 | self._qmax1_input.Bind(wx.EVT_MOUSE_EVENTS, self._on_click_qrange) |
---|
| 75 | self._qmax2_input.Bind(wx.EVT_MOUSE_EVENTS, self._on_click_qrange) |
---|
[3b8efec] | 76 | self._background_input.Bind(wx.EVT_TEXT, self._on_enter_input) |
---|
[c23f303] | 77 | |
---|
| 78 | def set_state(self, state=None, data=None): |
---|
[9c90cf3] | 79 | """ |
---|
| 80 | Set the state of the panel. If no state is provided, the panel will |
---|
| 81 | be set to the default state. |
---|
| 82 | |
---|
| 83 | :param state: A CorfuncState object |
---|
| 84 | :param data: A Data1D object |
---|
| 85 | """ |
---|
[e02d8f6] | 86 | if state is None: |
---|
| 87 | self.state = CorfuncState() |
---|
| 88 | else: |
---|
| 89 | self.state = state |
---|
| 90 | if data is not None: |
---|
| 91 | self.state.data = data |
---|
[3b8efec] | 92 | self.set_data(data, set_qrange=False) |
---|
[e02d8f6] | 93 | if self.state.qmin is not None: |
---|
| 94 | self.set_qmin(self.state.qmin) |
---|
| 95 | if self.state.qmax is not None and self.state.qmax != (None, None): |
---|
| 96 | self.set_qmax(tuple(self.state.qmax)) |
---|
[b564ea2] | 97 | if self.state.background is not None: |
---|
| 98 | self.set_background(self.state.background) |
---|
[e02d8f6] | 99 | |
---|
| 100 | def get_state(self): |
---|
| 101 | """ |
---|
| 102 | Return the state of the panel |
---|
| 103 | """ |
---|
| 104 | state = CorfuncState() |
---|
| 105 | state.set_saved_state('qmin_tcl', self.qmin) |
---|
| 106 | state.set_saved_state('qmax1_tcl', self.qmax[0]) |
---|
| 107 | state.set_saved_state('qmax2_tcl', self.qmax[1]) |
---|
[b564ea2] | 108 | state.set_saved_state('background_tcl', self.background) |
---|
[e02d8f6] | 109 | if self._data is not None: |
---|
| 110 | state.file = self._data.title |
---|
| 111 | state.data = self._data |
---|
| 112 | self.state = state |
---|
| 113 | |
---|
| 114 | return self.state |
---|
[c23f303] | 115 | |
---|
[3901e7c] | 116 | def onSetFocus(self, evt): |
---|
| 117 | if evt is not None: |
---|
| 118 | evt.Skip() |
---|
[b564ea2] | 119 | self._validate_inputs() |
---|
[3901e7c] | 120 | |
---|
[e02d8f6] | 121 | def set_data(self, data=None, set_qrange=True): |
---|
[7858575] | 122 | """ |
---|
| 123 | Update the GUI to reflect new data that has been loaded in |
---|
| 124 | |
---|
| 125 | :param data: The data that has been loaded |
---|
| 126 | """ |
---|
[e02d8f6] | 127 | if data is None: |
---|
| 128 | return |
---|
[54a0989] | 129 | self._enable_inputs() |
---|
| 130 | self._transform_btn.Disable() |
---|
[033c14c] | 131 | self._extract_btn.Disable() |
---|
[e02d8f6] | 132 | self._data_name_box.SetValue(str(data.title)) |
---|
[3901e7c] | 133 | self._data = data |
---|
[911dbe4] | 134 | self._calculator.set_data(data) |
---|
[7858575] | 135 | if self._manager is not None: |
---|
[3b8efec] | 136 | from sas.sasgui.perspectives.corfunc.corfunc import IQ_DATA_LABEL |
---|
[911dbe4] | 137 | self._manager.show_data(self._data, IQ_DATA_LABEL, reset=True) |
---|
[e02d8f6] | 138 | if set_qrange: |
---|
| 139 | lower = data.x[-1]*0.05 |
---|
| 140 | upper1 = data.x[-1] - lower*5 |
---|
| 141 | upper2 = data.x[-1] |
---|
| 142 | self.set_qmin(lower) |
---|
| 143 | self.set_qmax((upper1, upper2)) |
---|
[911dbe4] | 144 | self.set_background(self._calculator.compute_background(self.qmax)) |
---|
[e02d8f6] | 145 | |
---|
| 146 | def get_data(self): |
---|
| 147 | return self._data |
---|
| 148 | |
---|
[3b8efec] | 149 | def compute_extrapolation(self, event=None): |
---|
[6970e51] | 150 | """ |
---|
| 151 | Compute and plot the extrapolated data. |
---|
| 152 | Called when Extrapolate button is pressed. |
---|
| 153 | """ |
---|
[3b8efec] | 154 | if not self._validate_inputs: |
---|
| 155 | msg = "Invalid Q range entered." |
---|
| 156 | wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) |
---|
| 157 | return |
---|
[911dbe4] | 158 | self._calculator.set_data(self._data) |
---|
| 159 | self._calculator.lowerq = self.qmin |
---|
| 160 | self._calculator.upperq = self.qmax |
---|
[275b448] | 161 | self._calculator.background = self.background |
---|
[cdd1c3b] | 162 | try: |
---|
| 163 | self._extrapolated_data = self._calculator.compute_extrapolation() |
---|
| 164 | except: |
---|
| 165 | msg = "Error extrapolating data." |
---|
| 166 | wx.MessageBox(msg, 'error') |
---|
| 167 | wx.PostEvent(self._manager.parent, |
---|
| 168 | StatusEvent(status=msg, info="Error")) |
---|
| 169 | self._transform_btn.Disable() |
---|
| 170 | return |
---|
[3b8efec] | 171 | # TODO: Find way to set xlim and ylim so full range of data can be |
---|
| 172 | # plotted |
---|
| 173 | maxq = self._data.x.max() |
---|
| 174 | mask = self._extrapolated_data.x <= maxq |
---|
| 175 | numpts = len(self._extrapolated_data.x[mask]) + 250 |
---|
| 176 | plot_x = self._extrapolated_data.x[0:numpts] |
---|
| 177 | plot_y = self._extrapolated_data.y[0:numpts] |
---|
| 178 | to_plot = Data1D(plot_x, plot_y) |
---|
| 179 | from sas.sasgui.perspectives.corfunc.corfunc import\ |
---|
| 180 | IQ_EXTRAPOLATED_DATA_LABEL |
---|
| 181 | self._manager.show_data(to_plot, IQ_EXTRAPOLATED_DATA_LABEL) |
---|
[911dbe4] | 182 | self._transform_btn.Enable() |
---|
| 183 | |
---|
| 184 | def compute_transform(self, event=None): |
---|
[6970e51] | 185 | """ |
---|
| 186 | Compute and plot the transformed data. |
---|
| 187 | Called when Transform button is pressed. |
---|
| 188 | """ |
---|
[cdd1c3b] | 189 | try: |
---|
| 190 | transformed_data = self._calculator.compute_transform( |
---|
| 191 | self._extrapolated_data, self.background) |
---|
| 192 | except: |
---|
| 193 | transformed_data = None |
---|
| 194 | if transformed_data is None: |
---|
| 195 | msg = "Error calculating Transform." |
---|
| 196 | wx.MessageBox(msg, 'error') |
---|
| 197 | wx.PostEvent(self._manager.parent, |
---|
| 198 | StatusEvent(status=msg, info="Error")) |
---|
| 199 | self._extract_btn.Disable() |
---|
| 200 | return |
---|
[033c14c] | 201 | self._transformed_data = transformed_data |
---|
[911dbe4] | 202 | from sas.sasgui.perspectives.corfunc.corfunc import TRANSFORM_LABEL |
---|
| 203 | import numpy as np |
---|
| 204 | plot_x = transformed_data.x[np.where(transformed_data.x <= 200)] |
---|
| 205 | plot_y = transformed_data.y[np.where(transformed_data.x <= 200)] |
---|
| 206 | self._manager.show_data(Data1D(plot_x, plot_y), TRANSFORM_LABEL) |
---|
[033c14c] | 207 | self._extract_btn.Enable() |
---|
| 208 | |
---|
| 209 | def extract_parameters(self, event=None): |
---|
| 210 | try: |
---|
| 211 | params = self._calculator.extract_parameters(self._transformed_data) |
---|
| 212 | except: |
---|
| 213 | params = None |
---|
| 214 | if params is None: |
---|
| 215 | msg = "Error extracting parameters." |
---|
[cdd1c3b] | 216 | wx.MessageBox(msg, 'error') |
---|
[033c14c] | 217 | wx.PostEvent(self._manager.parent, |
---|
[cdd1c3b] | 218 | StatusEvent(status=msg, info="Error")) |
---|
[033c14c] | 219 | return |
---|
| 220 | for key in OUTPUT_STRINGS.keys(): |
---|
| 221 | value = params[key] |
---|
| 222 | self._output_boxes[key].SetValue(value) |
---|
| 223 | |
---|
[3b8efec] | 224 | |
---|
| 225 | |
---|
[e02d8f6] | 226 | def save_project(self, doc=None): |
---|
| 227 | """ |
---|
| 228 | Return an XML node containing the state of the panel |
---|
[9c90cf3] | 229 | |
---|
| 230 | :param doc: Am xml node to attach the project state to (optional) |
---|
[e02d8f6] | 231 | """ |
---|
| 232 | data = self._data |
---|
| 233 | state = self.get_state() |
---|
| 234 | if data is not None: |
---|
| 235 | new_doc, sasentry = self._manager.state_reader._to_xml_doc(data) |
---|
| 236 | new_doc = state.toXML(doc=new_doc, entry_node=sasentry) |
---|
| 237 | if new_doc is not None: |
---|
| 238 | if doc is not None and hasattr(doc, "firstChild"): |
---|
| 239 | child = new_doc.getElementsByTagName("SASentry") |
---|
| 240 | for item in child: |
---|
| 241 | doc.firstChild.appendChild(item) |
---|
| 242 | else: |
---|
| 243 | doc = new_doc |
---|
| 244 | return doc |
---|
[3901e7c] | 245 | |
---|
[9c90cf3] | 246 | def set_qmin(self, qmin): |
---|
| 247 | self.qmin = qmin |
---|
| 248 | self._qmin_input.SetValue(str(qmin)) |
---|
| 249 | |
---|
| 250 | def set_qmax(self, qmax): |
---|
| 251 | self.qmax = qmax |
---|
| 252 | self._qmax1_input.SetValue(str(qmax[0])) |
---|
| 253 | self._qmax2_input.SetValue(str(qmax[1])) |
---|
| 254 | |
---|
[b564ea2] | 255 | def set_background(self, bg): |
---|
| 256 | self.background = bg |
---|
| 257 | self._background_input.SetValue(str(bg)) |
---|
[dc72638] | 258 | self._calculator.background = bg |
---|
[7858575] | 259 | |
---|
[911dbe4] | 260 | def _compute_background(self, event=None): |
---|
| 261 | self.set_background(self._calculator.compute_background(self.qmax)) |
---|
[b564ea2] | 262 | |
---|
| 263 | def _on_enter_input(self, event=None): |
---|
[3901e7c] | 264 | """ |
---|
| 265 | Read values from input boxes and save to memory. |
---|
| 266 | """ |
---|
[e02d8f6] | 267 | if event is not None: event.Skip() |
---|
[b564ea2] | 268 | if not self._validate_inputs(): |
---|
[3901e7c] | 269 | return |
---|
[b564ea2] | 270 | self.qmin = float(self._qmin_input.GetValue()) |
---|
[3901e7c] | 271 | new_qmax1 = float(self._qmax1_input.GetValue()) |
---|
| 272 | new_qmax2 = float(self._qmax2_input.GetValue()) |
---|
| 273 | self.qmax = (new_qmax1, new_qmax2) |
---|
[b564ea2] | 274 | self.background = float(self._background_input.GetValue()) |
---|
[688d029] | 275 | self._calculator.background = self.background |
---|
[3b8efec] | 276 | from sas.sasgui.perspectives.corfunc.corfunc import GROUP_ID_IQ_DATA,\ |
---|
| 277 | IQ_DATA_LABEL |
---|
[e02d8f6] | 278 | if event is not None: |
---|
[688d029] | 279 | active_ctrl = event.GetEventObject() |
---|
| 280 | if active_ctrl == self._background_input: |
---|
[911dbe4] | 281 | from sas.sasgui.perspectives.corfunc.corfunc\ |
---|
| 282 | import IQ_DATA_LABEL |
---|
[688d029] | 283 | self._manager.show_data(self._data, IQ_DATA_LABEL, reset=False) |
---|
| 284 | wx.PostEvent(self._manager.parent, PlotQrangeEvent( |
---|
| 285 | ctrl=[self._qmin_input, self._qmax1_input, self._qmax2_input], |
---|
[5a54aa4] | 286 | active=active_ctrl, id=IQ_DATA_LABEL, is_corfunc=True, |
---|
[688d029] | 287 | group_id=GROUP_ID_IQ_DATA, leftdown=False)) |
---|
| 288 | |
---|
| 289 | def _on_click_qrange(self, event=None): |
---|
| 290 | if event is None: |
---|
| 291 | return |
---|
| 292 | event.Skip() |
---|
| 293 | if not self._validate_inputs(): return |
---|
| 294 | is_click = event.LeftDown() |
---|
| 295 | if is_click: |
---|
| 296 | from sas.sasgui.perspectives.corfunc.corfunc import GROUP_ID_IQ_DATA,\ |
---|
| 297 | IQ_DATA_LABEL |
---|
[e02d8f6] | 298 | wx.PostEvent(self._manager.parent, PlotQrangeEvent( |
---|
| 299 | ctrl=[self._qmin_input, self._qmax1_input, self._qmax2_input], |
---|
[77e9ac6] | 300 | active=event.GetEventObject(), id=IQ_DATA_LABEL, |
---|
[688d029] | 301 | group_id=GROUP_ID_IQ_DATA, leftdown=is_click)) |
---|
[3901e7c] | 302 | |
---|
[b564ea2] | 303 | def _validate_inputs(self): |
---|
[3901e7c] | 304 | """ |
---|
| 305 | Check that the values for qmin and qmax in the input boxes are valid |
---|
| 306 | """ |
---|
| 307 | if self._data is None: |
---|
| 308 | return False |
---|
| 309 | qmin_valid = check_float(self._qmin_input) |
---|
| 310 | qmax1_valid = check_float(self._qmax1_input) |
---|
| 311 | qmax2_valid = check_float(self._qmax2_input) |
---|
| 312 | qmax_valid = qmax1_valid and qmax2_valid |
---|
[b564ea2] | 313 | background_valid = check_float(self._background_input) |
---|
[3901e7c] | 314 | msg = "" |
---|
[b564ea2] | 315 | if (qmin_valid and qmax_valid and background_valid): |
---|
| 316 | qmin = float(self._qmin_input.GetValue()) |
---|
| 317 | qmax1 = float(self._qmax1_input.GetValue()) |
---|
| 318 | qmax2 = float(self._qmax2_input.GetValue()) |
---|
| 319 | background = float(self._background_input.GetValue()) |
---|
| 320 | if not qmin > self._data.x.min(): |
---|
| 321 | msg = "qmin must be greater than the lowest q value" |
---|
| 322 | qmin_valid = False |
---|
| 323 | elif qmax2 < qmax1: |
---|
| 324 | msg = "qmax1 must be less than qmax2" |
---|
| 325 | qmax_valid = False |
---|
| 326 | elif qmin > qmax1: |
---|
| 327 | msg = "qmin must be less than qmax" |
---|
| 328 | qmin_valid = False |
---|
[033c14c] | 329 | elif background > self._data.y.max(): |
---|
| 330 | msg = "background must be less than highest I" |
---|
[b564ea2] | 331 | background_valid = False |
---|
| 332 | if not qmin_valid: |
---|
| 333 | self._qmin_input.SetBackgroundColour('pink') |
---|
| 334 | if not qmax_valid: |
---|
| 335 | self._qmax1_input.SetBackgroundColour('pink') |
---|
| 336 | self._qmax2_input.SetBackgroundColour('pink') |
---|
| 337 | if not background_valid: |
---|
| 338 | self._background_input.SetBackgroundColour('pink') |
---|
| 339 | if msg != "": |
---|
| 340 | wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) |
---|
| 341 | if (qmin_valid and qmax_valid and background_valid): |
---|
[3901e7c] | 342 | self._qmin_input.SetBackgroundColour(wx.WHITE) |
---|
| 343 | self._qmax1_input.SetBackgroundColour(wx.WHITE) |
---|
| 344 | self._qmax2_input.SetBackgroundColour(wx.WHITE) |
---|
[b564ea2] | 345 | self._background_input.SetBackgroundColour(wx.WHITE) |
---|
[3901e7c] | 346 | self._qmin_input.Refresh() |
---|
| 347 | self._qmax1_input.Refresh() |
---|
| 348 | self._qmax2_input.Refresh() |
---|
[f2bbabf] | 349 | self._background_input.Refresh() |
---|
[b564ea2] | 350 | return (qmin_valid and qmax_valid and background_valid) |
---|
[7858575] | 351 | |
---|
[c23f303] | 352 | def _do_layout(self): |
---|
| 353 | """ |
---|
| 354 | Draw the window content |
---|
| 355 | """ |
---|
[7858575] | 356 | vbox = wx.GridBagSizer(0,0) |
---|
| 357 | |
---|
| 358 | # I(q) data box |
---|
[9f7dde3] | 359 | databox = wx.StaticBox(self, -1, "I(Q) Data Source") |
---|
| 360 | databox_sizer = wx.StaticBoxSizer(databox, wx.VERTICAL) |
---|
[7858575] | 361 | |
---|
[9f7dde3] | 362 | file_sizer = wx.GridBagSizer(5, 5) |
---|
[7858575] | 363 | |
---|
| 364 | file_name_label = wx.StaticText(self, -1, "Name:") |
---|
[9f7dde3] | 365 | file_sizer.Add(file_name_label, (0, 0), (1, 1), |
---|
[7858575] | 366 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
| 367 | |
---|
[9f7dde3] | 368 | self._data_name_box = OutputTextCtrl(self, -1, |
---|
| 369 | size=(300,20)) |
---|
| 370 | file_sizer.Add(self._data_name_box, (0, 1), (1, 1), |
---|
| 371 | wx.CENTER | wx.ADJUST_MINSIZE, 15) |
---|
| 372 | |
---|
| 373 | file_sizer.AddSpacer((1, 25), pos=(0,2)) |
---|
| 374 | databox_sizer.Add(file_sizer, wx.TOP, 15) |
---|
| 375 | |
---|
| 376 | vbox.Add(databox_sizer, (0, 0), (1, 1), |
---|
| 377 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE | wx.TOP, 15) |
---|
| 378 | |
---|
| 379 | |
---|
| 380 | # Parameters |
---|
| 381 | qbox = wx.StaticBox(self, -1, "Parameters") |
---|
| 382 | qbox_sizer = wx.StaticBoxSizer(qbox, wx.VERTICAL) |
---|
| 383 | qbox_sizer.SetMinSize((_STATICBOX_WIDTH, 75)) |
---|
| 384 | |
---|
| 385 | q_sizer = wx.GridBagSizer(5, 5) |
---|
| 386 | |
---|
| 387 | # Explanation |
---|
| 388 | explanation_txt = ("Corfunc will use all values in the lower range for" |
---|
| 389 | " Guinier back extrapolation, and all values in the upper range " |
---|
| 390 | "for Porod forward extrapolation.") |
---|
| 391 | explanation_label = wx.StaticText(self, -1, explanation_txt, |
---|
| 392 | size=(_STATICBOX_WIDTH, 60)) |
---|
| 393 | |
---|
| 394 | q_sizer.Add(explanation_label, (0,0), (1,4), wx.LEFT | wx.EXPAND, 5) |
---|
| 395 | |
---|
| 396 | qrange_label = wx.StaticText(self, -1, "Q Range:", size=(50,20)) |
---|
[7a219e3e] | 397 | q_sizer.Add(qrange_label, (1,0), (1,1), wx.LEFT | wx.EXPAND, 5) |
---|
[9f7dde3] | 398 | |
---|
| 399 | # Lower Q Range |
---|
| 400 | qmin_label = wx.StaticText(self, -1, "Lower:", size=(50,20)) |
---|
| 401 | qmin_dash_label = wx.StaticText(self, -1, "-", size=(10,20), |
---|
| 402 | style=wx.ALIGN_CENTER_HORIZONTAL) |
---|
| 403 | |
---|
| 404 | qmin_lower = OutputTextCtrl(self, -1, size=(50, 20), value="0.0") |
---|
[3901e7c] | 405 | self._qmin_input = ModelTextCtrl(self, -1, size=(50, 20), |
---|
| 406 | style=wx.TE_PROCESS_ENTER, name='qmin_input', |
---|
[b564ea2] | 407 | text_enter_callback=self._on_enter_input) |
---|
[3901e7c] | 408 | self._qmin_input.SetToolTipString(("Values with q < qmin will be used " |
---|
| 409 | "for Guinier back extrapolation")) |
---|
[9f7dde3] | 410 | |
---|
[7a219e3e] | 411 | q_sizer.Add(qmin_label, (2, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 412 | q_sizer.Add(qmin_lower, (2, 1), (1, 1), wx.LEFT, 5) |
---|
| 413 | q_sizer.Add(qmin_dash_label, (2, 2), (1, 1), wx.CENTER | wx.EXPAND, 5) |
---|
| 414 | q_sizer.Add(self._qmin_input, (2, 3), (1, 1), wx.LEFT, 5) |
---|
[9f7dde3] | 415 | |
---|
| 416 | # Upper Q range |
---|
| 417 | qmax_tooltip = ("Values with qmax1 < q < qmax2 will be used for Porod" |
---|
| 418 | " forward extrapolation") |
---|
| 419 | |
---|
| 420 | qmax_label = wx.StaticText(self, -1, "Upper:", size=(50,20)) |
---|
| 421 | qmax_dash_label = wx.StaticText(self, -1, "-", size=(10,20), |
---|
| 422 | style=wx.ALIGN_CENTER_HORIZONTAL) |
---|
| 423 | |
---|
[3901e7c] | 424 | self._qmax1_input = ModelTextCtrl(self, -1, size=(50, 20), |
---|
| 425 | style=wx.TE_PROCESS_ENTER, name="qmax1_input", |
---|
[b564ea2] | 426 | text_enter_callback=self._on_enter_input) |
---|
[3901e7c] | 427 | self._qmax1_input.SetToolTipString(qmax_tooltip) |
---|
| 428 | self._qmax2_input = ModelTextCtrl(self, -1, size=(50, 20), |
---|
| 429 | style=wx.TE_PROCESS_ENTER, name="qmax2_input", |
---|
[b564ea2] | 430 | text_enter_callback=self._on_enter_input) |
---|
[3901e7c] | 431 | self._qmax2_input.SetToolTipString(qmax_tooltip) |
---|
[9f7dde3] | 432 | |
---|
[7a219e3e] | 433 | q_sizer.Add(qmax_label, (3, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 434 | q_sizer.Add(self._qmax1_input, (3, 1), (1, 1), wx.LEFT, 5) |
---|
| 435 | q_sizer.Add(qmax_dash_label, (3, 2), (1, 1), wx.CENTER | wx.EXPAND, 5) |
---|
| 436 | q_sizer.Add(self._qmax2_input, (3,3), (1, 1), wx.LEFT, 5) |
---|
| 437 | |
---|
| 438 | background_label = wx.StaticText(self, -1, "Background:", size=(80,20)) |
---|
| 439 | q_sizer.Add(background_label, (4,0), (1,1), wx.LEFT | wx.EXPAND, 5) |
---|
| 440 | |
---|
| 441 | self._background_input = ModelTextCtrl(self, -1, size=(50,20), |
---|
| 442 | style=wx.TE_PROCESS_ENTER, name='background_input', |
---|
| 443 | text_enter_callback=self._on_enter_input) |
---|
| 444 | self._background_input.SetToolTipString(("A background value to " |
---|
| 445 | "subtract from all intensity values")) |
---|
| 446 | q_sizer.Add(self._background_input, (4,1), (1,1), |
---|
| 447 | wx.RIGHT, 5) |
---|
| 448 | |
---|
| 449 | background_button = wx.Button(self, wx.NewId(), "Calculate", |
---|
| 450 | size=(75, 20)) |
---|
| 451 | background_button.Bind(wx.EVT_BUTTON, self._compute_background) |
---|
| 452 | q_sizer.Add(background_button, (4, 2), (1, 1), wx.RIGHT, 5) |
---|
[9f7dde3] | 453 | |
---|
| 454 | qbox_sizer.Add(q_sizer, wx.TOP, 0) |
---|
| 455 | |
---|
| 456 | vbox.Add(qbox_sizer, (1, 0), (1, 1), |
---|
| 457 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
| 458 | |
---|
| 459 | # Output data |
---|
| 460 | outputbox = wx.StaticBox(self, -1, "Output Measuments") |
---|
| 461 | outputbox_sizer = wx.StaticBoxSizer(outputbox, wx.VERTICAL) |
---|
| 462 | |
---|
| 463 | output_sizer = wx.GridBagSizer(5, 5) |
---|
| 464 | |
---|
[033c14c] | 465 | self._output_boxes = dict() |
---|
| 466 | i = 0 |
---|
| 467 | for key, value in OUTPUT_STRINGS.iteritems(): |
---|
[3ec4b8f] | 468 | # Create a label and a text box for each poperty |
---|
[033c14c] | 469 | label = wx.StaticText(self, -1, value) |
---|
| 470 | output_box = OutputTextCtrl(self, wx.NewId(), |
---|
[9f7dde3] | 471 | value="-", style=wx.ALIGN_CENTER_HORIZONTAL) |
---|
[3ec4b8f] | 472 | # Save the ID of each of the text boxes for accessing after the |
---|
| 473 | # output data has been calculated |
---|
[033c14c] | 474 | self._output_boxes[key] = output_box |
---|
[9f7dde3] | 475 | output_sizer.Add(label, (i, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
| 476 | output_sizer.Add(output_box, (i, 2), (1, 1), |
---|
| 477 | wx.RIGHT | wx.EXPAND, 15) |
---|
[033c14c] | 478 | i += 1 |
---|
[9f7dde3] | 479 | |
---|
| 480 | outputbox_sizer.Add(output_sizer, wx.TOP, 0) |
---|
| 481 | |
---|
| 482 | vbox.Add(outputbox_sizer, (2, 0), (1, 1), |
---|
| 483 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
| 484 | |
---|
[3ec4b8f] | 485 | # Controls |
---|
[9f7dde3] | 486 | controlbox = wx.StaticBox(self, -1, "Controls") |
---|
| 487 | controlbox_sizer = wx.StaticBoxSizer(controlbox, wx.VERTICAL) |
---|
| 488 | |
---|
| 489 | controls_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
| 490 | |
---|
| 491 | extrapolate_btn = wx.Button(self, wx.NewId(), "Extrapolate") |
---|
[911dbe4] | 492 | self._transform_btn = wx.Button(self, wx.NewId(), "Transform") |
---|
[033c14c] | 493 | self._extract_btn = wx.Button(self, wx.NewId(), "Compute Measuments") |
---|
[911dbe4] | 494 | |
---|
| 495 | self._transform_btn.Disable() |
---|
[033c14c] | 496 | self._extract_btn.Disable() |
---|
[9f7dde3] | 497 | |
---|
[3b8efec] | 498 | extrapolate_btn.Bind(wx.EVT_BUTTON, self.compute_extrapolation) |
---|
[911dbe4] | 499 | self._transform_btn.Bind(wx.EVT_BUTTON, self.compute_transform) |
---|
[033c14c] | 500 | self._extract_btn.Bind(wx.EVT_BUTTON, self.extract_parameters) |
---|
[3b8efec] | 501 | |
---|
[9f7dde3] | 502 | controls_sizer.Add(extrapolate_btn, wx.CENTER | wx.EXPAND) |
---|
[911dbe4] | 503 | controls_sizer.Add(self._transform_btn, wx.CENTER | wx.EXPAND) |
---|
[033c14c] | 504 | controls_sizer.Add(self._extract_btn, wx.CENTER | wx.EXPAND) |
---|
[7858575] | 505 | |
---|
[9f7dde3] | 506 | controlbox_sizer.Add(controls_sizer, wx.TOP | wx.EXPAND, 0) |
---|
| 507 | vbox.Add(controlbox_sizer, (3, 0), (1, 1), |
---|
| 508 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
[7858575] | 509 | |
---|
| 510 | self.SetSizer(vbox) |
---|
[54a0989] | 511 | |
---|
| 512 | def _disable_inputs(self): |
---|
[6970e51] | 513 | """ |
---|
| 514 | Disable all input fields |
---|
| 515 | """ |
---|
[54a0989] | 516 | self._qmin_input.Disable() |
---|
| 517 | self._qmax1_input.Disable() |
---|
| 518 | self._qmax2_input.Disable() |
---|
| 519 | self._background_input.Disable() |
---|
| 520 | |
---|
| 521 | def _enable_inputs(self): |
---|
[6970e51] | 522 | """ |
---|
| 523 | Enable all input fields |
---|
| 524 | """ |
---|
[54a0989] | 525 | self._qmin_input.Enable() |
---|
| 526 | self._qmax1_input.Enable() |
---|
| 527 | self._qmax2_input.Enable() |
---|
| 528 | self._background_input.Enable() |
---|