[c128284] | 1 | """ |
---|
| 2 | This module provide GUI for the neutron scattering length density calculator |
---|
| 3 | @author: Gervaise B. Alina |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | import wx |
---|
| 7 | |
---|
[9abec44] | 8 | import sys |
---|
| 9 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
[272d91e] | 10 | from sans.invariant import invariant |
---|
[c128284] | 11 | from sans.guiframe.utils import format_number, check_float |
---|
| 12 | from sans.guicomm.events import NewPlotEvent, StatusEvent |
---|
[d0cc0bbc] | 13 | from invariant_details import InvariantDetailsPanel, InvariantContainer |
---|
[518d35d] | 14 | from invariant_widgets import OutputTextCtrl, InvTextCtrl |
---|
[6d55d81] | 15 | |
---|
[c128284] | 16 | # The minimum q-value to be used when extrapolating |
---|
| 17 | Q_MINIMUM = 1e-5 |
---|
| 18 | # The maximum q-value to be used when extrapolating |
---|
| 19 | Q_MAXIMUM = 10 |
---|
| 20 | # the maximum value to plot the theory data |
---|
| 21 | Q_MAXIMUM_PLOT = 2 |
---|
| 22 | # the number of points to consider during fit |
---|
| 23 | NPTS = 10 |
---|
| 24 | #Default value for background |
---|
| 25 | BACKGROUND = 0.0 |
---|
| 26 | #default value for the scale |
---|
| 27 | SCALE = 1.0 |
---|
[9ce7641c] | 28 | #default value of the contrast |
---|
| 29 | CONTRAST = 1.0 |
---|
[d0cc0bbc] | 30 | #default value of the power used for power law |
---|
| 31 | POWER = 4.0 |
---|
[c128284] | 32 | #Invariant panel size |
---|
| 33 | _BOX_WIDTH = 76 |
---|
| 34 | |
---|
| 35 | if sys.platform.count("win32")>0: |
---|
| 36 | _STATICBOX_WIDTH = 450 |
---|
[355b684] | 37 | PANEL_WIDTH = 500 |
---|
[c128284] | 38 | PANEL_HEIGHT = 700 |
---|
| 39 | FONT_VARIANT = 0 |
---|
| 40 | else: |
---|
| 41 | _STATICBOX_WIDTH = 480 |
---|
| 42 | PANEL_WIDTH = 530 |
---|
| 43 | PANEL_HEIGHT = 700 |
---|
| 44 | FONT_VARIANT = 1 |
---|
[d0cc0bbc] | 45 | |
---|
| 46 | |
---|
[9abec44] | 47 | class InvariantPanel(ScrolledPanel): |
---|
[c128284] | 48 | """ |
---|
| 49 | Provides the Invariant GUI. |
---|
| 50 | """ |
---|
| 51 | ## Internal nickname for the window, used by the AUI manager |
---|
| 52 | window_name = "Invariant" |
---|
| 53 | ## Name to appear on the window title bar |
---|
| 54 | window_caption = "Invariant" |
---|
| 55 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
| 56 | CENTER_PANE = True |
---|
[355b684] | 57 | def __init__(self, parent, data=None, manager=None,*args, **kwds): |
---|
[e825f72] | 58 | kwds["size"]= (PANEL_WIDTH, PANEL_HEIGHT) |
---|
[f1b0f70] | 59 | kwds["style"]= wx.FULL_REPAINT_ON_RESIZE |
---|
[355b684] | 60 | ScrolledPanel.__init__(self, parent=parent, *args, **kwds) |
---|
[c128284] | 61 | #Font size |
---|
| 62 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 63 | #Object that receive status event |
---|
| 64 | self.parent = parent |
---|
[272d91e] | 65 | #plug-in using this panel |
---|
| 66 | self._manager = manager |
---|
| 67 | #Data uses for computation |
---|
| 68 | self._data = data |
---|
[6d55d81] | 69 | self._scale = SCALE |
---|
| 70 | self._background = BACKGROUND |
---|
[9ce7641c] | 71 | #container of invariant value |
---|
| 72 | self.inv_container = None |
---|
[c128284] | 73 | #Draw the panel |
---|
| 74 | self._do_layout() |
---|
[d0cc0bbc] | 75 | self.reset_panel() |
---|
[a0a4486] | 76 | if self.parent is not None: |
---|
| 77 | msg = "" |
---|
[e3f721e4] | 78 | wx.PostEvent(self.parent,StatusEvent(status=msg, info="info")) |
---|
[b7f29fc] | 79 | self.SetupScrolling() |
---|
[9ce7641c] | 80 | |
---|
[a0a4486] | 81 | def err_check_on_data(self): |
---|
| 82 | """ |
---|
| 83 | Check if data is valid for further computation |
---|
| 84 | """ |
---|
| 85 | flag = False |
---|
[e3f721e4] | 86 | self.hint_msg_txt.SetLabel('') |
---|
[a0a4486] | 87 | #edit the panel |
---|
| 88 | if self._data is not None: |
---|
| 89 | if len(self._data.x[self._data.x==0]) > 0: |
---|
| 90 | flag = True |
---|
| 91 | msg = "Invariant: one of your q-values is zero. Delete that entry before proceeding" |
---|
[f1b0f70] | 92 | self.hint_msg_txt.SetLabel(msg) |
---|
[e3f721e4] | 93 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
| 94 | info="warning", |
---|
| 95 | type="stop")) |
---|
[a0a4486] | 96 | return flag |
---|
| 97 | |
---|
[272d91e] | 98 | def set_data(self, data): |
---|
[c128284] | 99 | """ |
---|
[272d91e] | 100 | Set the data |
---|
[c128284] | 101 | """ |
---|
[272d91e] | 102 | self._data = data |
---|
| 103 | #edit the panel |
---|
| 104 | if self._data is not None: |
---|
[a0a4486] | 105 | self.err_check_on_data() |
---|
[272d91e] | 106 | data_name = self._data.name |
---|
| 107 | data_qmin = min (self._data.x) |
---|
| 108 | data_qmax = max (self._data.x) |
---|
[9ce7641c] | 109 | self.data_name_tcl.SetValue(str(data_name)) |
---|
| 110 | self.data_min_tcl.SetLabel(str(data_qmin)) |
---|
| 111 | self.data_max_tcl.SetLabel(str(data_qmax)) |
---|
[d0cc0bbc] | 112 | self.reset_panel() |
---|
| 113 | self.compute_invariant(event=None) |
---|
[b7f29fc] | 114 | |
---|
[d0cc0bbc] | 115 | def set_message(self): |
---|
| 116 | """ |
---|
| 117 | Display warning message if available |
---|
| 118 | """ |
---|
| 119 | if self.inv_container is not None: |
---|
| 120 | if self.inv_container.existing_warning: |
---|
| 121 | msg = "Warning! Computations on invariant require your " |
---|
| 122 | msg += "attention.\n Please click on Details button." |
---|
| 123 | self.hint_msg_txt.SetForegroundColour("red") |
---|
[1c271f2] | 124 | |
---|
| 125 | wx.PostEvent(self.parent,StatusEvent(status=msg,info="warning")) |
---|
[d0cc0bbc] | 126 | else: |
---|
| 127 | msg = "For more information, click on Details button." |
---|
| 128 | self.hint_msg_txt.SetForegroundColour("black") |
---|
[1c271f2] | 129 | wx.PostEvent(self.parent,StatusEvent(status=msg,info="info")) |
---|
[d0cc0bbc] | 130 | self.hint_msg_txt.SetLabel(msg) |
---|
| 131 | self.data_name_boxsizer.Layout() |
---|
| 132 | |
---|
[c128284] | 133 | def set_manager(self, manager): |
---|
| 134 | """ |
---|
[272d91e] | 135 | set value for the manager |
---|
[c128284] | 136 | """ |
---|
[272d91e] | 137 | self._manager = manager |
---|
[9ce7641c] | 138 | |
---|
| 139 | def get_background(self): |
---|
[c128284] | 140 | """ |
---|
[9ce7641c] | 141 | @return the background textcrtl value as a float |
---|
[c128284] | 142 | """ |
---|
[9ce7641c] | 143 | background = self.background_tcl.GetValue().lstrip().rstrip() |
---|
[c128284] | 144 | if background == "": |
---|
[9ce7641c] | 145 | raise ValueError, "Need a background" |
---|
| 146 | if check_float(self.background_tcl): |
---|
| 147 | return float(background) |
---|
| 148 | else: |
---|
| 149 | raise ValueError, "Receive invalid value for background : %s"%(background) |
---|
| 150 | |
---|
| 151 | def get_scale(self): |
---|
| 152 | """ |
---|
| 153 | @return the scale textcrtl value as a float |
---|
| 154 | """ |
---|
| 155 | scale = self.scale_tcl.GetValue().lstrip().rstrip() |
---|
[c128284] | 156 | if scale == "": |
---|
[9ce7641c] | 157 | raise ValueError, "Need a background" |
---|
| 158 | if check_float(self.scale_tcl): |
---|
[6d55d81] | 159 | if float(scale)<= 0.0: |
---|
| 160 | self.scale_tcl.SetBackgroundColour("pink") |
---|
| 161 | self.scale_tcl.Refresh() |
---|
| 162 | raise ValueError, "Receive invalid value for scale: %s"%(scale) |
---|
[9ce7641c] | 163 | return float(scale) |
---|
| 164 | else: |
---|
[6d55d81] | 165 | raise ValueError, "Receive invalid value for scale : %s"%(scale) |
---|
[9ce7641c] | 166 | |
---|
| 167 | def get_contrast(self): |
---|
| 168 | """ |
---|
| 169 | @return the contrast textcrtl value as a float |
---|
| 170 | """ |
---|
| 171 | par_str = self.contrast_tcl.GetValue().strip() |
---|
| 172 | contrast = None |
---|
| 173 | if par_str !="" and check_float(self.contrast_tcl): |
---|
| 174 | contrast = float(par_str) |
---|
| 175 | return contrast |
---|
| 176 | |
---|
| 177 | def get_extrapolation_type(self, low_q, high_q): |
---|
| 178 | """ |
---|
| 179 | """ |
---|
| 180 | extrapolation = None |
---|
| 181 | if low_q and not high_q: |
---|
| 182 | extrapolation = "low" |
---|
| 183 | elif not low_q and high_q: |
---|
| 184 | extrapolation = "high" |
---|
| 185 | elif low_q and high_q: |
---|
| 186 | extrapolation = "both" |
---|
| 187 | return extrapolation |
---|
[272d91e] | 188 | |
---|
[9ce7641c] | 189 | def get_porod_const(self): |
---|
| 190 | """ |
---|
| 191 | @return the porod constant textcrtl value as a float |
---|
| 192 | """ |
---|
| 193 | par_str = self.porod_constant_tcl.GetValue().strip() |
---|
| 194 | porod_const = None |
---|
| 195 | if par_str !="" and check_float(self.porod_constant_tcl): |
---|
| 196 | porod_const = float(par_str) |
---|
| 197 | return porod_const |
---|
| 198 | |
---|
| 199 | def get_volume(self, inv, contrast, extrapolation): |
---|
| 200 | """ |
---|
| 201 | """ |
---|
| 202 | if contrast is not None: |
---|
[c128284] | 203 | try: |
---|
[9ce7641c] | 204 | v, dv = inv.get_volume_fraction_with_error(contrast=contrast, |
---|
| 205 | extrapolation=extrapolation) |
---|
| 206 | self.volume_tcl.SetValue(format_number(v)) |
---|
| 207 | self.volume_err_tcl.SetValue(format_number(dv)) |
---|
[c128284] | 208 | except: |
---|
[9ce7641c] | 209 | msg= "Error occurred computing volume fraction: %s"%sys.exc_value |
---|
[e3f721e4] | 210 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
| 211 | info="error", |
---|
| 212 | type="stop")) |
---|
[9ce7641c] | 213 | |
---|
| 214 | def get_surface(self, inv, contrast, porod_const, extrapolation): |
---|
| 215 | """ |
---|
| 216 | """ |
---|
| 217 | if contrast is not None and porod_const is not None: |
---|
[c128284] | 218 | try: |
---|
[9ce7641c] | 219 | s, ds = inv.get_surface_with_error(contrast=contrast, |
---|
| 220 | porod_const=porod_const, |
---|
| 221 | extrapolation=extrapolation) |
---|
| 222 | self.surface_tcl.SetValue(format_number(s)) |
---|
| 223 | self.surface_err_tcl.SetValue(format_number(ds)) |
---|
[c128284] | 224 | except: |
---|
[4e74e13] | 225 | msg = "Error occurred computing specific surface: %s"%sys.exc_value |
---|
[e3f721e4] | 226 | wx.PostEvent(self.parent, StatusEvent(status=msg, info="error", |
---|
| 227 | type="stop")) |
---|
[53b6b74] | 228 | |
---|
[9ce7641c] | 229 | def get_total_qstar(self, inv, extrapolation): |
---|
| 230 | """ |
---|
| 231 | """ |
---|
| 232 | try: |
---|
| 233 | qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) |
---|
| 234 | self.invariant_total_tcl.SetValue(format_number(qstar_total)) |
---|
[518d35d] | 235 | self.invariant_total_err_tcl.SetValue(format_number(qstar_total_err)) |
---|
[9ce7641c] | 236 | self.inv_container.qstar_total = qstar_total |
---|
| 237 | self.inv_container.qstar_total_err = qstar_total_err |
---|
[518d35d] | 238 | |
---|
[9ce7641c] | 239 | except: |
---|
| 240 | msg= "Error occurred computing invariant using extrapolation: %s"%sys.exc_value |
---|
| 241 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 242 | |
---|
| 243 | def get_low_qstar(self, inv, npts_low, low_q=False): |
---|
| 244 | """ |
---|
| 245 | """ |
---|
| 246 | if low_q: |
---|
| 247 | try: |
---|
| 248 | qstar_low, qstar_low_err = inv.get_qstar_low() |
---|
| 249 | self.inv_container.qstar_low = qstar_low |
---|
| 250 | self.inv_container.qstar_low_err = qstar_low_err |
---|
| 251 | extrapolated_data = inv.get_extra_data_low(npts_in=npts_low) |
---|
| 252 | power_low = inv.get_extrapolation_power(range='low') |
---|
[518d35d] | 253 | if self.power_law_low.GetValue(): |
---|
[d0cc0bbc] | 254 | self.power_low_tcl.SetValue(format_number(power_low)) |
---|
[9ce7641c] | 255 | self._manager.plot_theory(data=extrapolated_data, |
---|
| 256 | name="Low-Q extrapolation") |
---|
| 257 | except: |
---|
| 258 | msg= "Error occurred computing low-Q invariant: %s"%sys.exc_value |
---|
| 259 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
[c128284] | 260 | else: |
---|
[9ce7641c] | 261 | self._manager.plot_theory(name="Low-Q extrapolation") |
---|
| 262 | |
---|
| 263 | def get_high_qstar(self, inv, high_q=False): |
---|
| 264 | """ |
---|
| 265 | """ |
---|
| 266 | if high_q: |
---|
| 267 | try: |
---|
| 268 | qstar_high, qstar_high_err = inv.get_qstar_high() |
---|
| 269 | self.inv_container.qstar_high = qstar_high |
---|
| 270 | self.inv_container.qstar_high_err = qstar_high_err |
---|
[518d35d] | 271 | power_high = inv.get_extrapolation_power(range='high') |
---|
[d0cc0bbc] | 272 | self.power_high_tcl.SetValue(format_number(power_high)) |
---|
[9ce7641c] | 273 | high_out_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT) |
---|
| 274 | self._manager.plot_theory(data=high_out_data, |
---|
| 275 | name="High-Q extrapolation") |
---|
| 276 | except: |
---|
| 277 | msg= "Error occurred computing high-Q invariant: %s"%sys.exc_value |
---|
| 278 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 279 | else: |
---|
| 280 | self._manager.plot_theory(name="High-Q extrapolation") |
---|
| 281 | |
---|
| 282 | def get_qstar(self, inv): |
---|
| 283 | """ |
---|
| 284 | """ |
---|
| 285 | qstar, qstar_err = inv.get_qstar_with_error() |
---|
| 286 | self.inv_container.qstar = qstar |
---|
| 287 | self.inv_container.qstar_err = qstar_err |
---|
| 288 | |
---|
| 289 | def set_extrapolation_low(self, inv, low_q=False): |
---|
| 290 | """ |
---|
| 291 | @return float value necessary to compute invariant a low q |
---|
| 292 | """ |
---|
| 293 | #get funtion |
---|
| 294 | if self.guinier.GetValue(): |
---|
| 295 | function_low = "guinier" |
---|
| 296 | # get the function |
---|
[518d35d] | 297 | power_low = None #2.0/3.0 |
---|
[9ce7641c] | 298 | if self.power_law_low.GetValue(): |
---|
| 299 | function_low = "power_law" |
---|
[518d35d] | 300 | if self.fit_enable_low.GetValue(): |
---|
[9ce7641c] | 301 | #set value of power_low to none to allow fitting |
---|
| 302 | power_low = None |
---|
| 303 | else: |
---|
| 304 | power_low = self.power_low_tcl.GetValue().lstrip().rstrip() |
---|
| 305 | if check_float(self.power_low_tcl): |
---|
| 306 | power_low = float(power_low) |
---|
| 307 | else: |
---|
| 308 | if low_q : |
---|
| 309 | #Raise error only when qstar at low q is requested |
---|
| 310 | msg = "Expect float for power at low q , got %s"%(power_low) |
---|
| 311 | raise ValueError, msg |
---|
[518d35d] | 312 | |
---|
[9ce7641c] | 313 | #Get the number of points to extrapolated |
---|
| 314 | npts_low = self.npts_low_tcl.GetValue().lstrip().rstrip() |
---|
| 315 | if check_float(self.npts_low_tcl): |
---|
| 316 | npts_low = float(npts_low) |
---|
| 317 | else: |
---|
| 318 | if low_q: |
---|
| 319 | msg = "Expect float for number of points at low q , got %s"%(npts_low) |
---|
| 320 | raise ValueError, msg |
---|
| 321 | #Set the invariant calculator |
---|
| 322 | inv.set_extrapolation(range="low", npts=npts_low, |
---|
| 323 | function=function_low, power=power_low) |
---|
| 324 | return inv, npts_low |
---|
| 325 | |
---|
| 326 | def set_extrapolation_high(self, inv, high_q=False): |
---|
| 327 | """ |
---|
| 328 | @return float value necessary to compute invariant a high q |
---|
| 329 | """ |
---|
| 330 | power_high = None |
---|
[277fad8] | 331 | #if self.power_law_high.GetValue(): |
---|
| 332 | function_high = "power_law" |
---|
| 333 | if self.fit_enable_high.GetValue(): |
---|
| 334 | #set value of power_high to none to allow fitting |
---|
| 335 | power_high = None |
---|
| 336 | else: |
---|
| 337 | power_high = self.power_high_tcl.GetValue().lstrip().rstrip() |
---|
| 338 | if check_float(self.power_high_tcl): |
---|
| 339 | power_high = float(power_high) |
---|
[9ce7641c] | 340 | else: |
---|
[277fad8] | 341 | if high_q : |
---|
| 342 | #Raise error only when qstar at high q is requested |
---|
| 343 | msg = "Expect float for power at high q , got %s"%(power_high) |
---|
| 344 | raise ValueError, msg |
---|
[9ce7641c] | 345 | |
---|
| 346 | npts_high = self.npts_high_tcl.GetValue().lstrip().rstrip() |
---|
| 347 | if check_float(self.npts_high_tcl): |
---|
| 348 | npts_high = float(npts_high) |
---|
| 349 | else: |
---|
| 350 | if high_q: |
---|
| 351 | msg = "Expect float for number of points at high q , got %s"%(npts_high) |
---|
| 352 | raise ValueError, msg |
---|
| 353 | inv.set_extrapolation(range="high", npts=npts_high, |
---|
| 354 | function=function_high, power=power_high) |
---|
| 355 | return inv, npts_high |
---|
| 356 | |
---|
| 357 | def display_details(self, event): |
---|
| 358 | """ |
---|
| 359 | open another panel for more details on invariant calculation |
---|
| 360 | """ |
---|
[d3fac18] | 361 | panel = InvariantDetailsPanel(parent=self, |
---|
| 362 | qstar_container=self.inv_container) |
---|
| 363 | panel.ShowModal() |
---|
| 364 | panel.Destroy() |
---|
[d0cc0bbc] | 365 | self.button_calculate.SetFocus() |
---|
[9ce7641c] | 366 | |
---|
[d0cc0bbc] | 367 | def compute_invariant(self, event=None): |
---|
[9ce7641c] | 368 | """ |
---|
| 369 | compute invariant |
---|
| 370 | """ |
---|
[437e639] | 371 | msg= "" |
---|
[e3f721e4] | 372 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
[a0a4486] | 373 | if self._data is None or self.err_check_on_data(): |
---|
[9ce7641c] | 374 | return |
---|
[a0a4486] | 375 | |
---|
[9ce7641c] | 376 | #clear outputs textctrl |
---|
| 377 | self._reset_output() |
---|
| 378 | try: |
---|
| 379 | background = self.get_background() |
---|
| 380 | scale = self.get_scale() |
---|
| 381 | except: |
---|
| 382 | msg= "Invariant Error: %s"%(sys.exc_value) |
---|
| 383 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 384 | return |
---|
| 385 | |
---|
| 386 | low_q = self.enable_low_cbox.GetValue() |
---|
| 387 | high_q = self.enable_high_cbox.GetValue() |
---|
| 388 | #set invariant calculator |
---|
| 389 | inv = invariant.InvariantCalculator(data=self._data, |
---|
| 390 | background=background, |
---|
| 391 | scale=scale) |
---|
[437e639] | 392 | try: |
---|
| 393 | inv, npts_low = self.set_extrapolation_low(inv=inv, low_q=low_q) |
---|
| 394 | inv, npts_high = self.set_extrapolation_high(inv=inv, high_q=high_q) |
---|
| 395 | except: |
---|
[e3f721e4] | 396 | msg = "Error occurred computing invariant: %s"%sys.exc_value |
---|
| 397 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
| 398 | info="warning",type="stop")) |
---|
[437e639] | 399 | return |
---|
[9ce7641c] | 400 | #check the type of extrapolation |
---|
| 401 | extrapolation = self.get_extrapolation_type(low_q=low_q, high_q=high_q) |
---|
[a0a4486] | 402 | |
---|
[9ce7641c] | 403 | #Compute invariant |
---|
[6d55d81] | 404 | bkg_changed = False |
---|
| 405 | scale_changed = False |
---|
[9ce7641c] | 406 | try: |
---|
| 407 | self.get_qstar(inv=inv) |
---|
[6d55d81] | 408 | #if scale_changed or bkg_changed: |
---|
| 409 | self._manager.plot_data(data=inv.get_data()) |
---|
| 410 | |
---|
[9ce7641c] | 411 | except: |
---|
| 412 | msg= "Error occurred computing invariant: %s"%sys.exc_value |
---|
[e3f721e4] | 413 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
| 414 | info="warning",type="stop")) |
---|
[c128284] | 415 | return |
---|
[9ce7641c] | 416 | #Compute qstar extrapolated to low q range |
---|
| 417 | self.get_low_qstar(inv=inv, npts_low=npts_low, low_q=low_q) |
---|
| 418 | #Compute qstar extrapolated to high q range |
---|
| 419 | self.get_high_qstar(inv=inv, high_q=high_q) |
---|
| 420 | #Compute qstar extrapolated to total q range and set value to txtcrtl |
---|
| 421 | self.get_total_qstar(inv=inv, extrapolation=extrapolation) |
---|
| 422 | # Parse additional parameters |
---|
| 423 | porod_const = self.get_porod_const() |
---|
| 424 | contrast = self.get_contrast() |
---|
[f43827cc] | 425 | try: |
---|
| 426 | #Compute volume and set value to txtcrtl |
---|
| 427 | self.get_volume(inv=inv, contrast=contrast, extrapolation=extrapolation) |
---|
| 428 | #compute surface and set value to txtcrtl |
---|
| 429 | except: |
---|
[4e74e13] | 430 | msg = "Error occurred computing invariant: %s"%sys.exc_value |
---|
[e3f721e4] | 431 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
| 432 | info="warning",type="stop")) |
---|
[f43827cc] | 433 | try: |
---|
| 434 | self.get_surface(inv=inv, contrast=contrast, porod_const=porod_const, |
---|
[9ce7641c] | 435 | extrapolation=extrapolation) |
---|
[f43827cc] | 436 | except: |
---|
[4e74e13] | 437 | msg = "Error occurred computing invariant: %s"%sys.exc_value |
---|
[e3f721e4] | 438 | wx.PostEvent(self.parent, StatusEvent(status=msg, |
---|
| 439 | info="warning",type="stop")) |
---|
[d0cc0bbc] | 440 | |
---|
| 441 | #compute percentage of each invariant |
---|
| 442 | self.inv_container.compute_percentage() |
---|
| 443 | #display a message |
---|
| 444 | self.set_message() |
---|
[9ce7641c] | 445 | #enable the button_ok for more details |
---|
[d0cc0bbc] | 446 | self.button_details.Enable() |
---|
| 447 | self.button_details.SetFocus() |
---|
[9abec44] | 448 | |
---|
[f338d3b] | 449 | def reset_panel(self): |
---|
| 450 | """ |
---|
| 451 | set the panel at its initial state. |
---|
| 452 | """ |
---|
[d0cc0bbc] | 453 | self.background_tcl.SetValue(str(BACKGROUND)) |
---|
| 454 | self.scale_tcl.SetValue(str(SCALE)) |
---|
[4e74e13] | 455 | self.contrast_tcl.SetValue(str(CONTRAST)) |
---|
| 456 | self.porod_constant_tcl.SetValue('') |
---|
[d0cc0bbc] | 457 | self.npts_low_tcl.SetValue(str(NPTS)) |
---|
| 458 | self.enable_low_cbox.SetValue(False) |
---|
| 459 | self.fix_enable_low.SetValue(True) |
---|
| 460 | self.power_low_tcl.SetValue(str(POWER)) |
---|
| 461 | self.guinier.SetValue(True) |
---|
| 462 | self.power_low_tcl.Disable() |
---|
| 463 | self.enable_high_cbox.SetValue(False) |
---|
| 464 | self.fix_enable_high.SetValue(True) |
---|
| 465 | self.power_high_tcl.SetValue(str(POWER)) |
---|
| 466 | self.npts_high_tcl.SetValue(str(NPTS)) |
---|
| 467 | self.button_details.Disable() |
---|
| 468 | #Change the state of txtcrtl to enable/disable |
---|
| 469 | self._enable_low_q_section() |
---|
| 470 | #Change the state of txtcrtl to enable/disable |
---|
| 471 | self._enable_high_q_section() |
---|
| 472 | self._reset_output() |
---|
| 473 | self.button_calculate.SetFocus() |
---|
[9ce7641c] | 474 | |
---|
[c128284] | 475 | def _reset_output(self): |
---|
| 476 | """ |
---|
| 477 | clear outputs textcrtl |
---|
| 478 | """ |
---|
[9ce7641c] | 479 | self.invariant_total_tcl.Clear() |
---|
| 480 | self.invariant_total_err_tcl.Clear() |
---|
| 481 | self.volume_tcl.Clear() |
---|
| 482 | self.volume_err_tcl.Clear() |
---|
| 483 | self.surface_tcl.Clear() |
---|
| 484 | self.surface_err_tcl.Clear() |
---|
[a0a4486] | 485 | #prepare a new container to put result of invariant |
---|
| 486 | self.inv_container = InvariantContainer() |
---|
[b7f29fc] | 487 | |
---|
[9ce7641c] | 488 | def _define_structure(self): |
---|
[c128284] | 489 | """ |
---|
[9ce7641c] | 490 | Define main sizers needed for this panel |
---|
[c128284] | 491 | """ |
---|
[d5f0dcb9] | 492 | ## Box sizers must be defined first before defining buttons/textctrls (MAC). |
---|
[9ce7641c] | 493 | self.main_sizer = wx.BoxSizer(wx.VERTICAL) |
---|
| 494 | #Sizer related to outputs |
---|
| 495 | outputs_box = wx.StaticBox(self, -1, "Outputs") |
---|
| 496 | self.outputs_sizer = wx.StaticBoxSizer(outputs_box, wx.VERTICAL) |
---|
| 497 | self.outputs_sizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 498 | #Sizer related to data |
---|
| 499 | data_name_box = wx.StaticBox(self, -1, "I(q) Data Source") |
---|
| 500 | self.data_name_boxsizer = wx.StaticBoxSizer(data_name_box, wx.VERTICAL) |
---|
| 501 | self.data_name_boxsizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 502 | self.hint_msg_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 503 | self.data_name_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 504 | self.data_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[d0cc0bbc] | 505 | #Sizer related to background and scale |
---|
| 506 | self.bkg_scale_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 507 | #Sizer related to contrast and porod constant |
---|
| 508 | self.contrast_porod_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 509 | #Sizer related to inputs |
---|
| 510 | inputs_box = wx.StaticBox(self, -1, "Customized Inputs") |
---|
| 511 | self.inputs_sizer = wx.StaticBoxSizer(inputs_box, wx.VERTICAL) |
---|
| 512 | #Sizer related to extrapolation |
---|
[d5f0dcb9] | 513 | extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") |
---|
[9ce7641c] | 514 | self.extrapolation_sizer = wx.StaticBoxSizer(extrapolation_box, |
---|
| 515 | wx.VERTICAL) |
---|
| 516 | self.extrapolation_sizer.SetMinSize((PANEL_WIDTH,-1)) |
---|
| 517 | self.extrapolation_range_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 518 | self.extrapolation_low_high_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 519 | #Sizer related to extrapolation at low q range |
---|
[d5f0dcb9] | 520 | low_q_box = wx.StaticBox(self, -1, "Low Q") |
---|
[9ce7641c] | 521 | self.low_extrapolation_sizer = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) |
---|
| 522 | self.low_q_sizer = wx.GridBagSizer(5,5) |
---|
| 523 | #Sizer related to extrapolation at low q range |
---|
| 524 | high_q_box = wx.StaticBox(self, -1, "High Q") |
---|
| 525 | self.high_extrapolation_sizer = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) |
---|
| 526 | self.high_q_sizer = wx.GridBagSizer(5,5) |
---|
| 527 | #sizer to define outputs |
---|
| 528 | self.volume_surface_sizer = wx.GridBagSizer(5,5) |
---|
| 529 | #Sizer related to invariant output |
---|
[277fad8] | 530 | self.invariant_sizer = wx.GridBagSizer(5, 5) |
---|
[9ce7641c] | 531 | #Sizer related to button |
---|
| 532 | self.button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
[c128284] | 533 | |
---|
[9ce7641c] | 534 | def _layout_data_name(self): |
---|
| 535 | """ |
---|
| 536 | Draw widgets related to data's name |
---|
| 537 | """ |
---|
| 538 | #Sizer hint |
---|
[6848131] | 539 | hint_msg = "First open data file from 'File' menu. Then Highlight and right click on the data plot. \n" |
---|
| 540 | hint_msg += "Finally, select 'Compute Invariant'. \n" |
---|
[277fad8] | 541 | self.hint_msg_txt = wx.StaticText(self, -1, hint_msg) |
---|
| 542 | self.hint_msg_txt.SetForegroundColour("red") |
---|
[6848131] | 543 | msg = "Highlight = mouse the mouse's cursor on the data until the plot's color changes to yellow" |
---|
| 544 | self.hint_msg_txt.SetToolTipString(msg) |
---|
[277fad8] | 545 | self.hint_msg_sizer.Add(self.hint_msg_txt) |
---|
[9ce7641c] | 546 | #Data name [string] |
---|
| 547 | data_name_txt = wx.StaticText(self, -1, 'Data : ') |
---|
| 548 | |
---|
[518d35d] | 549 | self.data_name_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH*5, 20), style=0) |
---|
[9ce7641c] | 550 | self.data_name_tcl.SetToolTipString("Data's name.") |
---|
| 551 | self.data_name_sizer.AddMany([(data_name_txt, 0, wx.LEFT|wx.RIGHT, 10), |
---|
| 552 | (self.data_name_tcl, 0, wx.EXPAND)]) |
---|
| 553 | #Data range [string] |
---|
| 554 | data_range_txt = wx.StaticText(self, -1, 'Total Q Range (1/A): ') |
---|
| 555 | data_min_txt = wx.StaticText(self, -1, 'Min : ') |
---|
[518d35d] | 556 | self.data_min_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
[9ce7641c] | 557 | self.data_min_tcl.SetToolTipString("The minimum value of q range.") |
---|
| 558 | data_max_txt = wx.StaticText(self, -1, 'Max : ') |
---|
[518d35d] | 559 | self.data_max_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
[9ce7641c] | 560 | self.data_max_tcl.SetToolTipString("The maximum value of q range.") |
---|
| 561 | self.data_range_sizer.AddMany([(data_range_txt, 0, wx.RIGHT, 10), |
---|
| 562 | (data_min_txt, 0, wx.RIGHT, 10), |
---|
| 563 | (self.data_min_tcl, 0, wx.RIGHT, 10), |
---|
| 564 | (data_max_txt, 0, wx.RIGHT, 10), |
---|
| 565 | (self.data_max_tcl, 0, wx.RIGHT, 10)]) |
---|
| 566 | self.data_name_boxsizer.AddMany([(self.hint_msg_sizer, 0 , wx.ALL, 10), |
---|
| 567 | (self.data_name_sizer, 0 , wx.RIGHT, 10), |
---|
| 568 | (self.data_range_sizer, 0 , wx.ALL, 10)]) |
---|
| 569 | |
---|
[d0cc0bbc] | 570 | def _layout_bkg_scale(self): |
---|
[9ce7641c] | 571 | """ |
---|
[d0cc0bbc] | 572 | Draw widgets related to background and scale |
---|
[9ce7641c] | 573 | """ |
---|
| 574 | background_txt = wx.StaticText(self, -1, 'Background : ') |
---|
[518d35d] | 575 | self.background_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
| 576 | background_hint_txt = "background" |
---|
| 577 | self.background_tcl.SetToolTipString(background_hint_txt) |
---|
| 578 | background_unit_txt = wx.StaticText(self, -1, '[1/cm]') |
---|
[9ce7641c] | 579 | scale_txt = wx.StaticText(self, -1, 'Scale : ') |
---|
[518d35d] | 580 | self.scale_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
| 581 | scale_hint_txt = "Scale" |
---|
| 582 | self.scale_tcl.SetToolTipString(scale_hint_txt) |
---|
[d0cc0bbc] | 583 | self.bkg_scale_sizer.AddMany([(background_txt, 0, wx.LEFT, 10), |
---|
| 584 | (self.background_tcl, 0, wx.LEFT, 5), |
---|
| 585 | (background_unit_txt, 0, wx.LEFT, 10), |
---|
| 586 | (scale_txt, 0, wx.LEFT, 70), |
---|
| 587 | (self.scale_tcl, 0, wx.LEFT, 40)]) |
---|
| 588 | |
---|
| 589 | def _layout_contrast_porod(self): |
---|
[9ce7641c] | 590 | """ |
---|
[d0cc0bbc] | 591 | Draw widgets related to porod constant and contrast |
---|
[9ce7641c] | 592 | """ |
---|
| 593 | contrast_txt = wx.StaticText(self, -1, 'Contrast : ') |
---|
[518d35d] | 594 | self.contrast_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH, 20), style=0) |
---|
| 595 | contrast_hint_txt = "Contrast" |
---|
| 596 | self.contrast_tcl.SetToolTipString(contrast_hint_txt) |
---|
| 597 | contrast_unit_txt = wx.StaticText(self, -1, '[1/A^(2)]') |
---|
[9ce7641c] | 598 | porod_const_txt = wx.StaticText(self, -1, 'Porod Constant:') |
---|
[518d35d] | 599 | self.porod_constant_tcl = InvTextCtrl(self, -1, |
---|
[9ce7641c] | 600 | size=(_BOX_WIDTH, 20), style=0) |
---|
[518d35d] | 601 | porod_const_hint_txt = "Porod Constant" |
---|
| 602 | self.porod_constant_tcl.SetToolTipString(porod_const_hint_txt) |
---|
[9ce7641c] | 603 | optional_txt = wx.StaticText(self, -1, '(Optional)') |
---|
[d0cc0bbc] | 604 | self.contrast_porod_sizer.AddMany([(contrast_txt, 0, wx.LEFT, 10), |
---|
| 605 | (self.contrast_tcl, 0, wx.LEFT, 20), |
---|
| 606 | (contrast_unit_txt, 0, wx.LEFT, 10), |
---|
| 607 | (porod_const_txt, 0, wx.LEFT, 50), |
---|
[9ce7641c] | 608 | (self.porod_constant_tcl, 0, wx.LEFT, 0), |
---|
| 609 | (optional_txt, 0, wx.LEFT, 10)]) |
---|
| 610 | |
---|
[518d35d] | 611 | def _enable_fit_power_law_low(self, event=None): |
---|
| 612 | """ |
---|
| 613 | Enable and disable the power value editing |
---|
| 614 | """ |
---|
| 615 | if self.fix_enable_low.IsEnabled(): |
---|
| 616 | if self.fix_enable_low.GetValue(): |
---|
| 617 | self.power_low_tcl.Enable() |
---|
| 618 | else: |
---|
| 619 | self.power_low_tcl.Disable() |
---|
| 620 | |
---|
| 621 | def _enable_low_q_section(self, event=None): |
---|
| 622 | """ |
---|
| 623 | Disable or enable some button if the user enable low q extrapolation |
---|
| 624 | """ |
---|
| 625 | if self.enable_low_cbox.GetValue(): |
---|
| 626 | self.npts_low_tcl.Enable() |
---|
| 627 | self.fix_enable_low.Enable() |
---|
| 628 | self.fit_enable_low.Enable() |
---|
| 629 | self.guinier.Enable() |
---|
| 630 | self.power_law_low.Enable() |
---|
| 631 | |
---|
| 632 | else: |
---|
| 633 | self.npts_low_tcl.Disable() |
---|
| 634 | self.fix_enable_low.Disable() |
---|
| 635 | self.fit_enable_low.Disable() |
---|
| 636 | self.guinier.Disable() |
---|
| 637 | self.power_law_low.Disable() |
---|
| 638 | self._enable_power_law_low() |
---|
| 639 | self._enable_fit_power_law_low() |
---|
[d0cc0bbc] | 640 | self.button_calculate.SetFocus() |
---|
[518d35d] | 641 | |
---|
| 642 | def _enable_power_law_low(self, event=None): |
---|
| 643 | """ |
---|
| 644 | Enable editing power law section at low q range |
---|
| 645 | """ |
---|
| 646 | if self.guinier.GetValue(): |
---|
| 647 | self.fix_enable_low.Disable() |
---|
| 648 | self.fit_enable_low.Disable() |
---|
| 649 | self.power_low_tcl.Disable() |
---|
| 650 | else: |
---|
| 651 | self.fix_enable_low.Enable() |
---|
| 652 | self.fit_enable_low.Enable() |
---|
| 653 | self.power_low_tcl.Enable() |
---|
| 654 | self._enable_fit_power_law_low() |
---|
| 655 | |
---|
[9ce7641c] | 656 | def _layout_extrapolation_low(self): |
---|
| 657 | """ |
---|
| 658 | Draw widgets related to extrapolation at low q range |
---|
| 659 | """ |
---|
[437e639] | 660 | self.enable_low_cbox = wx.CheckBox(self, -1, "Enable Extrapolate Low Q") |
---|
[518d35d] | 661 | wx.EVT_CHECKBOX(self, self.enable_low_cbox.GetId(), |
---|
| 662 | self._enable_low_q_section) |
---|
| 663 | self.fix_enable_low = wx.RadioButton(self, -1, 'Fix', |
---|
| 664 | (10, 10),style=wx.RB_GROUP) |
---|
| 665 | self.fit_enable_low = wx.RadioButton(self, -1, 'Fit', (10, 10)) |
---|
| 666 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
| 667 | id=self.fix_enable_low.GetId()) |
---|
| 668 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_low, |
---|
| 669 | id=self.fit_enable_low.GetId()) |
---|
[c128284] | 670 | self.guinier = wx.RadioButton(self, -1, 'Guinier', |
---|
| 671 | (10, 10),style=wx.RB_GROUP) |
---|
[9ce7641c] | 672 | self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10)) |
---|
[518d35d] | 673 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
| 674 | id=self.guinier.GetId()) |
---|
| 675 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_power_law_low, |
---|
| 676 | id=self.power_law_low.GetId()) |
---|
| 677 | |
---|
[c128284] | 678 | npts_low_txt = wx.StaticText(self, -1, 'Npts') |
---|
[518d35d] | 679 | self.npts_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
[2661d8b] | 680 | msg_hint = "Number of Q points to consider" |
---|
| 681 | msg_hint +="while extrapolating the low-Q region" |
---|
[9ce7641c] | 682 | self.npts_low_tcl.SetToolTipString(msg_hint) |
---|
| 683 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
[518d35d] | 684 | self.power_low_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
[d0cc0bbc] | 685 | |
---|
[9ce7641c] | 686 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
| 687 | self.power_low_tcl.SetToolTipString(power_hint_txt) |
---|
[c128284] | 688 | iy = 0 |
---|
| 689 | ix = 0 |
---|
[518d35d] | 690 | self.low_q_sizer.Add(self.enable_low_cbox,(iy, ix),(1,5), |
---|
| 691 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 692 | iy += 1 |
---|
| 693 | ix = 0 |
---|
| 694 | self.low_q_sizer.Add(npts_low_txt,(iy, ix),(1,1), |
---|
| 695 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 696 | ix += 1 |
---|
| 697 | self.low_q_sizer.Add(self.npts_low_tcl, (iy, ix), (1,1), |
---|
| 698 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 699 | iy += 1 |
---|
| 700 | ix = 0 |
---|
[9ce7641c] | 701 | self.low_q_sizer.Add(self.guinier,(iy, ix),(1,2), |
---|
[c128284] | 702 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 703 | iy += 1 |
---|
| 704 | ix = 0 |
---|
[9ce7641c] | 705 | self.low_q_sizer.Add(self.power_law_low,(iy, ix),(1,2), |
---|
[2661d8b] | 706 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[518d35d] | 707 | |
---|
[2661d8b] | 708 | # Parameter controls for power law |
---|
| 709 | ix = 1 |
---|
| 710 | iy += 1 |
---|
[518d35d] | 711 | self.low_q_sizer.Add(self.fix_enable_low,(iy, ix),(1,1), |
---|
| 712 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 713 | ix += 1 |
---|
| 714 | self.low_q_sizer.Add(self.fit_enable_low,(iy, ix),(1,1), |
---|
| 715 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 716 | ix = 1 |
---|
| 717 | iy += 1 |
---|
| 718 | self.low_q_sizer.Add(power_txt,(iy, ix),(1,1), |
---|
[518d35d] | 719 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[c128284] | 720 | ix += 1 |
---|
[9ce7641c] | 721 | self.low_q_sizer.Add(self.power_low_tcl, (iy, ix), (1,1), |
---|
[c128284] | 722 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 723 | self.low_extrapolation_sizer.AddMany([(self.low_q_sizer, 0, |
---|
[d0cc0bbc] | 724 | wx.BOTTOM|wx.RIGHT, 15)]) |
---|
| 725 | |
---|
[518d35d] | 726 | def _enable_fit_power_law_high(self, event=None): |
---|
| 727 | """ |
---|
| 728 | Enable and disable the power value editing |
---|
| 729 | """ |
---|
| 730 | if self.fix_enable_high.IsEnabled(): |
---|
| 731 | if self.fix_enable_high.GetValue(): |
---|
| 732 | self.power_high_tcl.Enable() |
---|
| 733 | else: |
---|
| 734 | self.power_high_tcl.Disable() |
---|
[9ce7641c] | 735 | |
---|
[518d35d] | 736 | def _enable_high_q_section(self, event=None): |
---|
| 737 | """ |
---|
| 738 | Disable or enable some button if the user enable high q extrapolation |
---|
| 739 | """ |
---|
| 740 | if self.enable_high_cbox.GetValue(): |
---|
| 741 | self.npts_high_tcl.Enable() |
---|
| 742 | self.power_law_high.Enable() |
---|
| 743 | self.power_high_tcl.Enable() |
---|
| 744 | self.fix_enable_high.Enable() |
---|
| 745 | self.fit_enable_high.Enable() |
---|
| 746 | else: |
---|
| 747 | self.npts_high_tcl.Disable() |
---|
| 748 | self.power_law_high.Disable() |
---|
| 749 | self.power_high_tcl.Disable() |
---|
| 750 | self.fix_enable_high.Disable() |
---|
| 751 | self.fit_enable_high.Disable() |
---|
| 752 | self._enable_fit_power_law_high() |
---|
[d0cc0bbc] | 753 | self.button_calculate.SetFocus() |
---|
[b7f29fc] | 754 | |
---|
[9ce7641c] | 755 | def _layout_extrapolation_high(self): |
---|
| 756 | """ |
---|
| 757 | Draw widgets related to extrapolation at high q range |
---|
| 758 | """ |
---|
[437e639] | 759 | self.enable_high_cbox = wx.CheckBox(self, -1, "Enable Extrapolate high-Q") |
---|
[518d35d] | 760 | wx.EVT_CHECKBOX(self, self.enable_high_cbox.GetId(), |
---|
| 761 | self._enable_high_q_section) |
---|
| 762 | |
---|
| 763 | self.fix_enable_high = wx.RadioButton(self, -1, 'Fix', |
---|
| 764 | (10, 10),style=wx.RB_GROUP) |
---|
| 765 | self.fit_enable_high = wx.RadioButton(self, -1, 'Fit', (10, 10)) |
---|
| 766 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
| 767 | id=self.fix_enable_high.GetId()) |
---|
| 768 | self.Bind(wx.EVT_RADIOBUTTON, self._enable_fit_power_law_high, |
---|
| 769 | id=self.fit_enable_high.GetId()) |
---|
| 770 | |
---|
[277fad8] | 771 | self.power_law_high = wx.StaticText(self, -1, 'Power Law') |
---|
[d0cc0bbc] | 772 | msg_hint ="Check to extrapolate data at high-Q" |
---|
| 773 | self.power_law_high.SetToolTipString(msg_hint) |
---|
[c128284] | 774 | npts_high_txt = wx.StaticText(self, -1, 'Npts') |
---|
[518d35d] | 775 | self.npts_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
[2661d8b] | 776 | msg_hint = "Number of Q points to consider" |
---|
| 777 | msg_hint += "while extrapolating the high-Q region" |
---|
[9ce7641c] | 778 | self.npts_high_tcl.SetToolTipString(msg_hint) |
---|
| 779 | power_txt = wx.StaticText(self, -1, 'Power') |
---|
[518d35d] | 780 | self.power_high_tcl = InvTextCtrl(self, -1, size=(_BOX_WIDTH*2/3, -1)) |
---|
[9ce7641c] | 781 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
| 782 | self.power_high_tcl.SetToolTipString(power_hint_txt) |
---|
[518d35d] | 783 | iy = 0 |
---|
| 784 | ix = 0 |
---|
| 785 | self.high_q_sizer.Add(self.enable_high_cbox,(iy, ix),(1,5), |
---|
| 786 | wx.TOP|wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 787 | iy += 1 |
---|
| 788 | ix = 0 |
---|
| 789 | self.high_q_sizer.Add(npts_high_txt,(iy, ix),(1,1), |
---|
| 790 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 791 | ix += 1 |
---|
| 792 | self.high_q_sizer.Add(self.npts_high_tcl, (iy, ix), (1,1), |
---|
| 793 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 794 | iy += 2 |
---|
[c128284] | 795 | ix = 0 |
---|
[9ce7641c] | 796 | self.high_q_sizer.Add(self.power_law_high,(iy, ix),(1,2), |
---|
[2661d8b] | 797 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[518d35d] | 798 | |
---|
| 799 | # Parameter controls for power law |
---|
[2661d8b] | 800 | ix = 1 |
---|
| 801 | iy += 1 |
---|
[518d35d] | 802 | self.high_q_sizer.Add(self.fix_enable_high,(iy, ix),(1,1), |
---|
| 803 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 804 | ix += 1 |
---|
| 805 | self.high_q_sizer.Add(self.fit_enable_high,(iy, ix),(1,1), |
---|
| 806 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[9ce7641c] | 807 | ix = 1 |
---|
| 808 | iy += 1 |
---|
| 809 | self.high_q_sizer.Add(power_txt,(iy, ix),(1,1), |
---|
[c128284] | 810 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 811 | ix += 1 |
---|
[9ce7641c] | 812 | self.high_q_sizer.Add(self.power_high_tcl, (iy, ix), (1,1), |
---|
[c128284] | 813 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[d0cc0bbc] | 814 | self.high_extrapolation_sizer.AddMany([(self.high_q_sizer, 0, |
---|
| 815 | wx.BOTTOM|wx.RIGHT, 10)]) |
---|
[c128284] | 816 | |
---|
[9ce7641c] | 817 | def _layout_extrapolation(self): |
---|
| 818 | """ |
---|
| 819 | Draw widgets related to extrapolation |
---|
| 820 | """ |
---|
[518d35d] | 821 | extra_hint = "Extrapolation Maximum Q Range [1/A]: " |
---|
[9ce7641c] | 822 | extra_hint_txt = wx.StaticText(self, -1, extra_hint) |
---|
| 823 | #Extrapolation range [string] |
---|
| 824 | extrapolation_min_txt = wx.StaticText(self, -1, 'Min : ') |
---|
[518d35d] | 825 | self.extrapolation_min_tcl = OutputTextCtrl(self, -1, |
---|
[9ce7641c] | 826 | size=(_BOX_WIDTH, 20), style=0) |
---|
| 827 | self.extrapolation_min_tcl.SetValue(str(Q_MINIMUM)) |
---|
| 828 | self.extrapolation_min_tcl.SetToolTipString("The minimum extrapolated q value.") |
---|
| 829 | extrapolation_max_txt = wx.StaticText(self, -1, 'Max : ') |
---|
[518d35d] | 830 | self.extrapolation_max_tcl = OutputTextCtrl(self, -1, |
---|
[9ce7641c] | 831 | size=(_BOX_WIDTH, 20), style=0) |
---|
| 832 | self.extrapolation_max_tcl.SetValue(str(Q_MAXIMUM)) |
---|
| 833 | self.extrapolation_max_tcl.SetToolTipString("The maximum extrapolated q value.") |
---|
| 834 | self.extrapolation_range_sizer.AddMany([(extra_hint_txt, 0, wx.LEFT, 10), |
---|
| 835 | (extrapolation_min_txt, 0, wx.LEFT, 10), |
---|
| 836 | (self.extrapolation_min_tcl, |
---|
| 837 | 0, wx.LEFT, 10), |
---|
| 838 | (extrapolation_max_txt, 0, wx.LEFT, 10), |
---|
| 839 | (self.extrapolation_max_tcl, |
---|
| 840 | 0, wx.LEFT, 10), |
---|
| 841 | ]) |
---|
| 842 | self._layout_extrapolation_low() |
---|
| 843 | self._layout_extrapolation_high() |
---|
| 844 | self.extrapolation_low_high_sizer.AddMany([(self.low_extrapolation_sizer, |
---|
| 845 | 0, wx.ALL, 10), |
---|
| 846 | (self.high_extrapolation_sizer, |
---|
| 847 | 0, wx.ALL, 10)]) |
---|
| 848 | self.extrapolation_sizer.AddMany([(self.extrapolation_range_sizer, 0, |
---|
| 849 | wx.RIGHT, 10), |
---|
| 850 | (self.extrapolation_low_high_sizer, 0, |
---|
| 851 | wx.ALL, 10)]) |
---|
| 852 | |
---|
| 853 | def _layout_volume_surface_sizer(self): |
---|
| 854 | """ |
---|
| 855 | Draw widgets related to volume and surface |
---|
| 856 | """ |
---|
| 857 | unit_volume = '' |
---|
| 858 | unit_surface = '' |
---|
| 859 | uncertainty = "+/-" |
---|
[dce0756] | 860 | volume_txt = wx.StaticText(self, -1, 'Volume Fraction ') |
---|
[518d35d] | 861 | self.volume_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
[9ce7641c] | 862 | self.volume_tcl.SetToolTipString("Volume fraction.") |
---|
[518d35d] | 863 | self.volume_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
[9ce7641c] | 864 | self.volume_err_tcl.SetToolTipString("Uncertainty on the volume fraction.") |
---|
[c128284] | 865 | volume_units_txt = wx.StaticText(self, -1, unit_volume) |
---|
| 866 | |
---|
[277fad8] | 867 | surface_txt = wx.StaticText(self, -1, 'Specific Surface') |
---|
[518d35d] | 868 | self.surface_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
[9ce7641c] | 869 | self.surface_tcl.SetToolTipString("Specific surface value.") |
---|
[518d35d] | 870 | self.surface_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
[9ce7641c] | 871 | self.surface_err_tcl.SetToolTipString("Uncertainty on the specific surface.") |
---|
[c128284] | 872 | surface_units_txt = wx.StaticText(self, -1, unit_surface) |
---|
| 873 | iy = 0 |
---|
| 874 | ix = 0 |
---|
[9ce7641c] | 875 | self.volume_surface_sizer.Add(volume_txt, (iy, ix), (1,1), |
---|
[c128284] | 876 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[9ce7641c] | 877 | ix += 1 |
---|
| 878 | self.volume_surface_sizer.Add(self.volume_tcl, (iy, ix), (1,1), |
---|
| 879 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 880 | ix += 1 |
---|
| 881 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
| 882 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 883 | ix += 1 |
---|
| 884 | self.volume_surface_sizer.Add(self.volume_err_tcl, (iy, ix), (1,1), |
---|
| 885 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 886 | ix += 1 |
---|
| 887 | self.volume_surface_sizer.Add(volume_units_txt, (iy, ix), (1,1), |
---|
| 888 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[c128284] | 889 | iy += 1 |
---|
| 890 | ix = 0 |
---|
[9ce7641c] | 891 | self.volume_surface_sizer.Add(surface_txt, (iy, ix), (1,1), |
---|
| 892 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[c128284] | 893 | ix += 1 |
---|
[9ce7641c] | 894 | self.volume_surface_sizer.Add(self.surface_tcl, (iy, ix), (1,1), |
---|
| 895 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
[c128284] | 896 | ix += 1 |
---|
[9ce7641c] | 897 | self.volume_surface_sizer.Add(wx.StaticText(self, -1, uncertainty), |
---|
[c128284] | 898 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 899 | ix += 1 |
---|
[9ce7641c] | 900 | self.volume_surface_sizer.Add(self.surface_err_tcl, (iy, ix), (1,1), |
---|
[c128284] | 901 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 902 | ix += 1 |
---|
[9ce7641c] | 903 | self.volume_surface_sizer.Add(surface_units_txt, (iy, ix), (1,1), |
---|
| 904 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
| 905 | |
---|
| 906 | def _layout_invariant_sizer(self): |
---|
| 907 | """ |
---|
| 908 | Draw widgets related to invariant |
---|
| 909 | """ |
---|
| 910 | uncertainty = "+/-" |
---|
[277fad8] | 911 | unit_invariant = '[1/(cm * A)]' |
---|
[eed601e] | 912 | invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total [Q*]') |
---|
[518d35d] | 913 | self.invariant_total_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
[eed601e] | 914 | msg_hint = "Total invariant [Q*], including extrapolated regions." |
---|
[9ce7641c] | 915 | self.invariant_total_tcl.SetToolTipString(msg_hint) |
---|
[518d35d] | 916 | self.invariant_total_err_tcl = OutputTextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
[9ce7641c] | 917 | self.invariant_total_err_tcl.SetToolTipString("Uncertainty on invariant.") |
---|
| 918 | invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 919 | |
---|
| 920 | #Invariant total |
---|
| 921 | iy = 0 |
---|
[c128284] | 922 | ix = 0 |
---|
[9ce7641c] | 923 | self.invariant_sizer.Add(invariant_total_txt, (iy, ix), (1,1), |
---|
[c128284] | 924 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[9ce7641c] | 925 | ix += 1 |
---|
| 926 | self.invariant_sizer.Add(self.invariant_total_tcl, (iy, ix), (1,1), |
---|
[dce0756] | 927 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[c128284] | 928 | ix += 1 |
---|
[9ce7641c] | 929 | self.invariant_sizer.Add( wx.StaticText(self, -1, uncertainty), |
---|
[277fad8] | 930 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[c128284] | 931 | ix += 1 |
---|
[9ce7641c] | 932 | self.invariant_sizer.Add(self.invariant_total_err_tcl, (iy, ix), (1,1), |
---|
[277fad8] | 933 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[c128284] | 934 | ix += 1 |
---|
[277fad8] | 935 | self.invariant_sizer.Add(invariant_total_units_txt,(iy, ix), (1,1), |
---|
| 936 | wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
[9ce7641c] | 937 | |
---|
[d0cc0bbc] | 938 | def _layout_inputs_sizer(self): |
---|
| 939 | """ |
---|
| 940 | Draw widgets related to inputs |
---|
| 941 | """ |
---|
| 942 | self._layout_bkg_scale() |
---|
| 943 | self._layout_contrast_porod() |
---|
| 944 | self.inputs_sizer.AddMany([(self.bkg_scale_sizer, 0, wx.ALL, 5), |
---|
| 945 | (self.contrast_porod_sizer, 0, wx.ALL, 5)]) |
---|
| 946 | |
---|
[9ce7641c] | 947 | def _layout_outputs_sizer(self): |
---|
| 948 | """ |
---|
| 949 | Draw widgets related to outputs |
---|
| 950 | """ |
---|
| 951 | self._layout_volume_surface_sizer() |
---|
| 952 | self._layout_invariant_sizer() |
---|
| 953 | static_line = wx.StaticLine(self, -1) |
---|
| 954 | self.outputs_sizer.AddMany([(self.volume_surface_sizer, 0, wx.ALL, 10), |
---|
| 955 | (static_line, 0, wx.EXPAND, 0), |
---|
| 956 | (self.invariant_sizer, 0, wx.ALL, 10)]) |
---|
| 957 | def _layout_button(self): |
---|
| 958 | """ |
---|
| 959 | Do the layout for the button widgets |
---|
| 960 | """ |
---|
| 961 | #compute button |
---|
[c128284] | 962 | id = wx.NewId() |
---|
[d0cc0bbc] | 963 | self.button_calculate = wx.Button(self, id, "Compute") |
---|
| 964 | self.button_calculate.SetToolTipString("Compute invariant") |
---|
[9ce7641c] | 965 | self.Bind(wx.EVT_BUTTON, self.compute_invariant, id=id) |
---|
| 966 | #detail button |
---|
| 967 | id = wx.NewId() |
---|
[d0cc0bbc] | 968 | self.button_details = wx.Button(self, id, "Details?") |
---|
| 969 | self.button_details.SetToolTipString("Give Details on Computation") |
---|
[9ce7641c] | 970 | self.Bind(wx.EVT_BUTTON, self.display_details, id=id) |
---|
| 971 | details = "Details on Invariant Total Calculations" |
---|
| 972 | details_txt = wx.StaticText(self, -1, details) |
---|
[d0cc0bbc] | 973 | self.button_sizer.AddMany([((10,10), 0 , wx.LEFT,0), |
---|
| 974 | (details_txt, 0 , |
---|
| 975 | wx.RIGHT|wx.BOTTOM|wx.TOP, 10), |
---|
| 976 | (self.button_details, 0 , wx.ALL, 10), |
---|
| 977 | (self.button_calculate, 0 , wx.RIGHT|wx.TOP|wx.BOTTOM, 10)]) |
---|
[d5f0dcb9] | 978 | |
---|
[9ce7641c] | 979 | def _do_layout(self): |
---|
| 980 | """ |
---|
| 981 | Draw window content |
---|
| 982 | """ |
---|
| 983 | self._define_structure() |
---|
| 984 | self._layout_data_name() |
---|
| 985 | self._layout_extrapolation() |
---|
[d0cc0bbc] | 986 | self._layout_inputs_sizer() |
---|
[9ce7641c] | 987 | self._layout_outputs_sizer() |
---|
| 988 | self._layout_button() |
---|
[355b684] | 989 | self.main_sizer.AddMany([(self.data_name_boxsizer,0, wx.ALL, 10), |
---|
[9ce7641c] | 990 | (self.outputs_sizer, 0, |
---|
| 991 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
[355b684] | 992 | (self.button_sizer,0, |
---|
[d0cc0bbc] | 993 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
| 994 | (self.inputs_sizer, 0, |
---|
| 995 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10), |
---|
| 996 | (self.extrapolation_sizer, 0, |
---|
[9ce7641c] | 997 | wx.LEFT|wx.RIGHT|wx.BOTTOM, 10)]) |
---|
| 998 | self.SetSizer(self.main_sizer) |
---|
[355b684] | 999 | self.SetAutoLayout(True) |
---|
[c128284] | 1000 | |
---|
| 1001 | class InvariantDialog(wx.Dialog): |
---|
| 1002 | def __init__(self, parent=None, id=1,graph=None, |
---|
[272d91e] | 1003 | data=None, title="Invariant",base=None): |
---|
| 1004 | wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
[c128284] | 1005 | PANEL_HEIGHT)) |
---|
[272d91e] | 1006 | self.panel = InvariantPanel(self) |
---|
[c128284] | 1007 | self.Centre() |
---|
| 1008 | self.Show(True) |
---|
| 1009 | |
---|
| 1010 | class InvariantWindow(wx.Frame): |
---|
[272d91e] | 1011 | def __init__(self, parent=None, id=1,graph=None, |
---|
| 1012 | data=None, title="Invariant",base=None): |
---|
[c128284] | 1013 | |
---|
[9ce7641c] | 1014 | wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH +100, |
---|
| 1015 | PANEL_HEIGHT+100)) |
---|
[c128284] | 1016 | |
---|
[272d91e] | 1017 | self.panel = InvariantPanel(self) |
---|
[c128284] | 1018 | self.Centre() |
---|
| 1019 | self.Show(True) |
---|
| 1020 | |
---|
| 1021 | class MyApp(wx.App): |
---|
| 1022 | def OnInit(self): |
---|
| 1023 | wx.InitAllImageHandlers() |
---|
| 1024 | frame = InvariantWindow() |
---|
| 1025 | frame.Show(True) |
---|
| 1026 | self.SetTopWindow(frame) |
---|
| 1027 | |
---|
| 1028 | return True |
---|
[272d91e] | 1029 | |
---|
[c128284] | 1030 | # end of class MyApp |
---|
| 1031 | |
---|
| 1032 | if __name__ == "__main__": |
---|
| 1033 | app = MyApp(0) |
---|
| 1034 | app.MainLoop() |
---|