[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 | import sys |
---|
| 8 | |
---|
[272d91e] | 9 | from sans.invariant import invariant |
---|
| 10 | |
---|
[c128284] | 11 | from sans.guiframe.utils import format_number, check_float |
---|
| 12 | from sans.guicomm.events import NewPlotEvent, StatusEvent |
---|
| 13 | |
---|
| 14 | # The minimum q-value to be used when extrapolating |
---|
| 15 | Q_MINIMUM = 1e-5 |
---|
| 16 | # The maximum q-value to be used when extrapolating |
---|
| 17 | Q_MAXIMUM = 10 |
---|
| 18 | # the maximum value to plot the theory data |
---|
| 19 | Q_MAXIMUM_PLOT = 2 |
---|
| 20 | # the number of points to consider during fit |
---|
| 21 | NPTS = 10 |
---|
| 22 | #Default value for background |
---|
| 23 | BACKGROUND = 0.0 |
---|
| 24 | #default value for the scale |
---|
| 25 | SCALE = 1.0 |
---|
| 26 | #Invariant panel size |
---|
| 27 | _BOX_WIDTH = 76 |
---|
| 28 | _SCALE = 1e-6 |
---|
| 29 | |
---|
| 30 | if sys.platform.count("win32")>0: |
---|
| 31 | _STATICBOX_WIDTH = 450 |
---|
| 32 | PANEL_WIDTH = 500 |
---|
| 33 | PANEL_HEIGHT = 700 |
---|
| 34 | FONT_VARIANT = 0 |
---|
| 35 | else: |
---|
| 36 | _STATICBOX_WIDTH = 480 |
---|
| 37 | PANEL_WIDTH = 530 |
---|
| 38 | PANEL_HEIGHT = 700 |
---|
| 39 | FONT_VARIANT = 1 |
---|
| 40 | |
---|
| 41 | class InvariantPanel(wx.ScrolledWindow): |
---|
| 42 | """ |
---|
| 43 | Provides the Invariant GUI. |
---|
| 44 | """ |
---|
| 45 | ## Internal nickname for the window, used by the AUI manager |
---|
| 46 | window_name = "Invariant" |
---|
| 47 | ## Name to appear on the window title bar |
---|
| 48 | window_caption = "Invariant" |
---|
| 49 | ## Flag to tell the AUI manager to put this panel in the center pane |
---|
| 50 | CENTER_PANE = True |
---|
[272d91e] | 51 | def __init__(self, parent, data=None, manager=None): |
---|
[c128284] | 52 | wx.ScrolledWindow.__init__(self, parent, style= wx.FULL_REPAINT_ON_RESIZE ) |
---|
| 53 | #Font size |
---|
| 54 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
| 55 | #Object that receive status event |
---|
| 56 | self.parent = parent |
---|
[272d91e] | 57 | #plug-in using this panel |
---|
| 58 | self._manager = manager |
---|
[c128284] | 59 | #Default power value |
---|
| 60 | self.power_law_exponant = 4 |
---|
[272d91e] | 61 | #Data uses for computation |
---|
| 62 | self._data = data |
---|
[c128284] | 63 | #Draw the panel |
---|
| 64 | self._do_layout() |
---|
| 65 | self.SetScrollbars(20,20,25,65) |
---|
| 66 | self.SetAutoLayout(True) |
---|
| 67 | self.Layout() |
---|
[272d91e] | 68 | |
---|
| 69 | def set_data(self, data): |
---|
[c128284] | 70 | """ |
---|
[272d91e] | 71 | Set the data |
---|
[c128284] | 72 | """ |
---|
[272d91e] | 73 | self._data = data |
---|
| 74 | #edit the panel |
---|
| 75 | if self._data is not None: |
---|
| 76 | data_name = self._data.name |
---|
| 77 | data_qmin = min (self._data.x) |
---|
| 78 | data_qmax = max (self._data.x) |
---|
| 79 | data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) |
---|
| 80 | |
---|
| 81 | self.data_name_txt.SetLabel('Data : '+str(data_name)) |
---|
[c128284] | 82 | self.data_range_value_txt.SetLabel(str(data_range)) |
---|
[272d91e] | 83 | |
---|
[c128284] | 84 | def set_manager(self, manager): |
---|
| 85 | """ |
---|
[272d91e] | 86 | set value for the manager |
---|
[c128284] | 87 | """ |
---|
[272d91e] | 88 | self._manager = manager |
---|
[c128284] | 89 | |
---|
| 90 | def compute_invariant(self, event): |
---|
| 91 | """ |
---|
| 92 | compute invariant |
---|
| 93 | """ |
---|
| 94 | #clear outputs textctrl |
---|
| 95 | self._reset_output() |
---|
| 96 | background = self.background_ctl.GetValue().lstrip().rstrip() |
---|
| 97 | scale = self.scale_ctl.GetValue().lstrip().rstrip() |
---|
| 98 | if background == "": |
---|
| 99 | background = 0 |
---|
| 100 | if scale == "": |
---|
| 101 | scale = 1 |
---|
| 102 | if check_float(self.background_ctl) and check_float(self.scale_ctl): |
---|
[272d91e] | 103 | inv = invariant.InvariantCalculator(data=self._data, |
---|
| 104 | background=float(background), |
---|
| 105 | scale=float(scale)) |
---|
| 106 | |
---|
[c128284] | 107 | #Get the number of points to extrapolated |
---|
| 108 | npts_low = self.npts_low_ctl.GetValue() |
---|
| 109 | if check_float(self.npts_low_ctl): |
---|
| 110 | npts_low = float(npts_low) |
---|
| 111 | power_low = self.power_low_ctl.GetValue() |
---|
| 112 | if check_float(self.power_low_ctl): |
---|
| 113 | power_low = float(power_low) |
---|
| 114 | npts_high = self.npts_high_ctl.GetValue() |
---|
| 115 | if check_float(self.npts_high_ctl): |
---|
| 116 | npts_high = float(npts_high) |
---|
| 117 | power_high = self.power_high_ctl.GetValue() |
---|
| 118 | if check_float(self.power_high_ctl): |
---|
| 119 | power_high = float(power_high) |
---|
| 120 | # get the function |
---|
| 121 | if self.power_law_low.GetValue(): |
---|
| 122 | function_low = "power_law" |
---|
| 123 | if self.guinier.GetValue(): |
---|
| 124 | function_low = "guinier" |
---|
| 125 | #power_low = None |
---|
| 126 | |
---|
| 127 | function_high = "power_law" |
---|
| 128 | if self.power_law_high.GetValue(): |
---|
| 129 | function_high = "power_law" |
---|
| 130 | #check the type of extrapolation |
---|
| 131 | extrapolation = None |
---|
| 132 | low_q = self.enable_low_cbox.GetValue() |
---|
| 133 | high_q = self.enable_high_cbox.GetValue() |
---|
| 134 | if low_q and not high_q: |
---|
| 135 | extrapolation = "low" |
---|
| 136 | elif not low_q and high_q: |
---|
| 137 | extrapolation = "high" |
---|
| 138 | elif low_q and high_q: |
---|
| 139 | extrapolation = "both" |
---|
| 140 | |
---|
| 141 | #Set the invariant calculator |
---|
[272d91e] | 142 | inv.set_extrapolation(range="low", npts=npts_low, |
---|
[c128284] | 143 | function=function_low, power=power_low) |
---|
[272d91e] | 144 | inv.set_extrapolation(range="high", npts=npts_high, |
---|
[c128284] | 145 | function=function_high, power=power_high) |
---|
| 146 | #Compute invariant |
---|
| 147 | try: |
---|
[272d91e] | 148 | qstar, qstar_err = inv.get_qstar_with_error() |
---|
[c128284] | 149 | self.invariant_ctl.SetValue(format_number(qstar)) |
---|
| 150 | self.invariant_err_ctl.SetValue(format_number(qstar)) |
---|
| 151 | except: |
---|
[2661d8b] | 152 | msg= "Error occurred computing invariant: %s"%sys.exc_value |
---|
[c128284] | 153 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 154 | return |
---|
| 155 | #Compute qstar extrapolated to low q range |
---|
| 156 | #Clear the previous extrapolated plot |
---|
| 157 | if low_q: |
---|
| 158 | try: |
---|
[53b6b74] | 159 | qstar_low, qstar_low_err = inv.get_qstar_low() |
---|
[c128284] | 160 | self.invariant_low_ctl.SetValue(format_number(qstar_low)) |
---|
[2661d8b] | 161 | extrapolated_data = inv.get_extra_data_low(npts_in=npts_low) |
---|
| 162 | self._manager.plot_theory(data=extrapolated_data, |
---|
| 163 | name="Low-Q extrapolation") |
---|
[c128284] | 164 | except: |
---|
[2661d8b] | 165 | msg= "Error occurred computing low-Q invariant: %s"%sys.exc_value |
---|
[272d91e] | 166 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
[2661d8b] | 167 | else: |
---|
| 168 | self._manager.plot_theory(name="Low-Q extrapolation") |
---|
| 169 | |
---|
[c128284] | 170 | if high_q: |
---|
| 171 | try: |
---|
[53b6b74] | 172 | qstar_high, qstar_high_err = inv.get_qstar_high() |
---|
[c128284] | 173 | self.invariant_high_ctl.SetValue(format_number(qstar_high)) |
---|
[2661d8b] | 174 | high_out_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT) |
---|
| 175 | self._manager.plot_theory(data=high_out_data, |
---|
| 176 | name="High-Q extrapolation") |
---|
[c128284] | 177 | except: |
---|
[2661d8b] | 178 | msg= "Error occurred computing high-Q invariant: %s"%sys.exc_value |
---|
[c128284] | 179 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
[2661d8b] | 180 | else: |
---|
| 181 | self._manager.plot_theory(name="High-Q extrapolation") |
---|
| 182 | |
---|
[c128284] | 183 | try: |
---|
[272d91e] | 184 | qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) |
---|
[c128284] | 185 | self.invariant_total_ctl.SetValue(format_number(qstar_total)) |
---|
| 186 | self.invariant_total_err_ctl.SetValue(format_number(qstar_total)) |
---|
| 187 | check_float(self.invariant_total_ctl) |
---|
| 188 | check_float(self.invariant_total_err_ctl) |
---|
| 189 | except: |
---|
[2661d8b] | 190 | msg= "Error occurred computing invariant using extrapolation: %s"%sys.exc_value |
---|
[272d91e] | 191 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 192 | |
---|
[53b6b74] | 193 | # Parse additional parameters |
---|
| 194 | par_str = self.porod_const_ctl.GetValue().strip() |
---|
| 195 | porod_const = None |
---|
| 196 | if len(par_str)>0 and check_float(self.porod_const_ctl): |
---|
| 197 | porod_const = float(par_str) |
---|
| 198 | |
---|
| 199 | par_str = self.contrast_ctl.GetValue().strip() |
---|
| 200 | contrast = None |
---|
| 201 | if len(par_str)>0 and check_float(self.contrast_ctl): |
---|
| 202 | contrast = float(par_str) |
---|
| 203 | |
---|
| 204 | if contrast is not None: |
---|
| 205 | try: |
---|
| 206 | v, dv = inv.get_volume_fraction_with_error(contrast=contrast) |
---|
| 207 | self.volume_ctl.SetValue(format_number(v)) |
---|
| 208 | self.volume_err_ctl.SetValue(format_number(dv)) |
---|
| 209 | except: |
---|
[2661d8b] | 210 | msg= "Error occurred computing volume fraction: %s"%sys.exc_value |
---|
[53b6b74] | 211 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 212 | |
---|
| 213 | if contrast is not None and porod_const is not None: |
---|
| 214 | try: |
---|
| 215 | s, ds = inv.get_surface_with_error(contrast=contrast, |
---|
| 216 | porod_const=porod_const) |
---|
| 217 | self.surface_ctl.SetValue(format_number(s)) |
---|
| 218 | self.surface_err_ctl.SetValue(format_number(ds)) |
---|
| 219 | except: |
---|
[2661d8b] | 220 | msg= "Error occurred computing specific surface: %s"%sys.exc_value |
---|
[53b6b74] | 221 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
[272d91e] | 222 | |
---|
[c128284] | 223 | else: |
---|
[2661d8b] | 224 | msg= "A float value is required for background and scale" |
---|
[c128284] | 225 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 226 | return |
---|
[272d91e] | 227 | |
---|
[c128284] | 228 | def _reset_output(self): |
---|
| 229 | """ |
---|
| 230 | clear outputs textcrtl |
---|
| 231 | """ |
---|
| 232 | self.invariant_ctl.Clear() |
---|
| 233 | self.invariant_err_ctl.Clear() |
---|
| 234 | self.invariant_low_ctl.Clear() |
---|
| 235 | self.invariant_high_ctl.Clear() |
---|
| 236 | self.invariant_total_ctl.Clear() |
---|
| 237 | self.invariant_total_err_ctl.Clear() |
---|
| 238 | self.volume_ctl.Clear() |
---|
| 239 | self.volume_err_ctl.Clear() |
---|
| 240 | self.surface_ctl.Clear() |
---|
| 241 | self.surface_err_ctl.Clear() |
---|
| 242 | |
---|
| 243 | def _do_layout(self): |
---|
| 244 | """ |
---|
| 245 | Draw window content |
---|
| 246 | """ |
---|
| 247 | unit_invariant = '[1/cm][1/A]' |
---|
| 248 | unit_volume = '' |
---|
| 249 | unit_surface = '' |
---|
| 250 | uncertainty = "+/-" |
---|
| 251 | npts_hint_txt = "Number of points to consider during extrapolation." |
---|
| 252 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
| 253 | |
---|
| 254 | sizer_input = wx.FlexGridSizer(5,4)#wx.GridBagSizer(5,5) |
---|
| 255 | sizer_output = wx.GridBagSizer(5,5) |
---|
| 256 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 257 | |
---|
| 258 | sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
| 259 | sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
| 260 | sizer3 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 261 | |
---|
| 262 | sizer1.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
| 263 | sizer2.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
| 264 | sizer3.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
[d5f0dcb9] | 265 | |
---|
| 266 | ## Box sizers must be defined first before defining buttons/textctrls (MAC). |
---|
| 267 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 268 | inputbox = wx.StaticBox(self, -1, "Input") |
---|
| 269 | extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") |
---|
| 270 | boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL) |
---|
| 271 | high_q_box = wx.StaticBox(self, -1, "High Q") |
---|
| 272 | boxsizer_high_q = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) |
---|
| 273 | low_q_box = wx.StaticBox(self, -1, "Low Q") |
---|
| 274 | boxsizer_low_q = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) |
---|
| 275 | |
---|
[c128284] | 276 | #---------inputs---------------- |
---|
[272d91e] | 277 | data_name = "" |
---|
[c128284] | 278 | data_range = "[? - ?]" |
---|
[272d91e] | 279 | if self._data is not None: |
---|
| 280 | data_name = self._data.name |
---|
| 281 | data_qmin = min (self._data.x) |
---|
| 282 | data_qmax = max (self._data.x) |
---|
| 283 | data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) |
---|
| 284 | |
---|
| 285 | self.data_name_txt = wx.StaticText(self, -1, 'Data : '+str(data_name)) |
---|
[c128284] | 286 | data_range_txt = wx.StaticText(self, -1, "Range : ") |
---|
| 287 | self.data_range_value_txt = wx.StaticText(self, -1, str(data_range)) |
---|
| 288 | |
---|
[2661d8b] | 289 | background_txt = wx.StaticText(self, -1, 'Background') |
---|
[c128284] | 290 | self.background_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 291 | self.background_ctl.SetValue(str(BACKGROUND)) |
---|
[2661d8b] | 292 | self.background_ctl.SetToolTipString("Background to be subtracted from data.") |
---|
| 293 | scale_txt = wx.StaticText(self, -1, 'Scale') |
---|
[c128284] | 294 | self.scale_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 295 | self.scale_ctl.SetValue(str(SCALE)) |
---|
[2661d8b] | 296 | self.scale_ctl.SetToolTipString("Scaling factor to be applied to data.") |
---|
[c128284] | 297 | contrast_txt = wx.StaticText(self, -1, 'Contrast (Optional)') |
---|
| 298 | self.contrast_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
[2661d8b] | 299 | msg_hint = "Enter a value for the contrast to compute the volume fraction" |
---|
[c128284] | 300 | self.contrast_ctl.SetToolTipString(str(msg_hint)) |
---|
[2661d8b] | 301 | porod_const_txt = wx.StaticText(self, -1, 'Porod Constant (Optional)') |
---|
[c128284] | 302 | self.porod_const_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
[2661d8b] | 303 | msg_hint ="Enter a Porod constant value to compute the specific surface" |
---|
[c128284] | 304 | self.porod_const_ctl.SetToolTipString(str(msg_hint)) |
---|
| 305 | |
---|
[272d91e] | 306 | sizer_input.Add(self.data_name_txt, 0, wx.LEFT, 5) |
---|
| 307 | sizer_input.Add((10,10), 0, wx.LEFT, 5) |
---|
[c128284] | 308 | sizer_input.Add(data_range_txt, 0, wx.LEFT, 10) |
---|
| 309 | sizer_input.Add(self.data_range_value_txt) |
---|
| 310 | sizer_input.Add(background_txt, 0, wx.ALL, 5) |
---|
| 311 | sizer_input.Add(self.background_ctl, 0, wx.ALL, 5) |
---|
| 312 | sizer_input.Add((10,10)) |
---|
| 313 | sizer_input.Add((10,10)) |
---|
| 314 | sizer_input.Add(scale_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 315 | sizer_input.Add(self.scale_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 316 | sizer_input.Add((10,10)) |
---|
| 317 | sizer_input.Add((10,10)) |
---|
| 318 | sizer_input.Add(contrast_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 319 | sizer_input.Add(self.contrast_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 320 | sizer_input.Add((10,10)) |
---|
| 321 | sizer_input.Add((10,10)) |
---|
| 322 | sizer_input.Add(porod_const_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 323 | sizer_input.Add(self.porod_const_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 324 | #-------------Extrapolation sizer---------------- |
---|
| 325 | sizer_low_q = wx.GridBagSizer(5,5) |
---|
| 326 | |
---|
[2661d8b] | 327 | self.enable_low_cbox = wx.CheckBox(self, -1, "Extrapolate low-Q") |
---|
[c128284] | 328 | self.enable_low_cbox.SetValue(False) |
---|
[2661d8b] | 329 | self.enable_high_cbox = wx.CheckBox(self, -1, "Extrapolate high-Q") |
---|
[c128284] | 330 | self.enable_high_cbox.SetValue(False) |
---|
| 331 | |
---|
| 332 | self.guinier = wx.RadioButton(self, -1, 'Guinier', |
---|
| 333 | (10, 10),style=wx.RB_GROUP) |
---|
[2661d8b] | 334 | self.power_law_low = wx.RadioButton(self, -1, 'Power Law', (10, 10)) |
---|
[c128284] | 335 | self.guinier.SetValue(True) |
---|
| 336 | |
---|
| 337 | npts_low_txt = wx.StaticText(self, -1, 'Npts') |
---|
| 338 | self.npts_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
| 339 | self.npts_low_ctl.SetValue(str(NPTS)) |
---|
[2661d8b] | 340 | msg_hint = "Number of Q points to consider" |
---|
| 341 | msg_hint +="while extrapolating the low-Q region" |
---|
[c128284] | 342 | self.npts_low_ctl.SetToolTipString(msg_hint) |
---|
[2661d8b] | 343 | npts_exp_txt = wx.StaticText(self, -1, 'Power') |
---|
[c128284] | 344 | self.power_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
| 345 | self.power_low_ctl.SetValue(str(self.power_law_exponant)) |
---|
| 346 | self.power_low_ctl.SetToolTipString(power_hint_txt) |
---|
| 347 | iy = 0 |
---|
| 348 | ix = 0 |
---|
[2661d8b] | 349 | sizer_low_q.Add(self.guinier,(iy, ix),(1,2), |
---|
[c128284] | 350 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 351 | iy += 1 |
---|
| 352 | ix = 0 |
---|
[2661d8b] | 353 | |
---|
| 354 | sizer_low_q.Add(self.power_law_low,(iy, ix),(1,2), |
---|
| 355 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 356 | |
---|
| 357 | # Parameter controls for power law |
---|
| 358 | ix = 1 |
---|
| 359 | iy += 1 |
---|
| 360 | sizer_low_q.Add(npts_exp_txt,(iy, ix),(1,1), |
---|
[c128284] | 361 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[2661d8b] | 362 | |
---|
[c128284] | 363 | ix += 1 |
---|
| 364 | sizer_low_q.Add(self.power_low_ctl, (iy, ix), (1,1), |
---|
| 365 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 366 | iy += 1 |
---|
[2661d8b] | 367 | ix = 1 |
---|
[c128284] | 368 | sizer_low_q.Add(npts_low_txt,(iy, ix),(1,1), |
---|
| 369 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 370 | ix += 1 |
---|
| 371 | sizer_low_q.Add(self.npts_low_ctl, (iy, ix), (1,1), |
---|
| 372 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 373 | iy += 1 |
---|
| 374 | ix = 0 |
---|
[2661d8b] | 375 | sizer_low_q.Add(self.enable_low_cbox,(iy, ix),(1,5), |
---|
[c128284] | 376 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 377 | sizer_high_q = wx.GridBagSizer(5,5) |
---|
[2661d8b] | 378 | self.power_law_high = wx.RadioButton(self, -1, 'Power Law', |
---|
[c128284] | 379 | (10, 10), style=wx.RB_GROUP) |
---|
[2661d8b] | 380 | msg_hint ="Check to extrapolate data at high-Q" |
---|
[c128284] | 381 | self.power_law_high.SetToolTipString(msg_hint) |
---|
| 382 | |
---|
| 383 | #MAC needs SetValue |
---|
| 384 | self.power_law_high.SetValue(True) |
---|
| 385 | npts_high_txt = wx.StaticText(self, -1, 'Npts') |
---|
[2661d8b] | 386 | npts_high_exp_txt = wx.StaticText(self, -1, 'Power') |
---|
[c128284] | 387 | self.npts_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
[2661d8b] | 388 | msg_hint = "Number of Q points to consider" |
---|
| 389 | msg_hint += "while extrapolating the high-Q region" |
---|
[c128284] | 390 | self.npts_high_ctl.SetToolTipString(msg_hint) |
---|
| 391 | self.npts_high_ctl.SetValue(str(NPTS)) |
---|
| 392 | self.power_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
| 393 | self.power_high_ctl.SetValue(str(self.power_law_exponant)) |
---|
| 394 | self.power_high_ctl.SetToolTipString(power_hint_txt) |
---|
| 395 | |
---|
| 396 | iy = 1 |
---|
| 397 | ix = 0 |
---|
[2661d8b] | 398 | sizer_high_q.Add(self.power_law_high,(iy, ix),(1,2), |
---|
| 399 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 400 | ix = 1 |
---|
| 401 | iy += 1 |
---|
| 402 | sizer_high_q.Add(npts_high_exp_txt,(iy, ix),(1,1), |
---|
[c128284] | 403 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[2661d8b] | 404 | |
---|
[c128284] | 405 | ix += 1 |
---|
| 406 | sizer_high_q.Add(self.power_high_ctl, (iy, ix), (1,1), |
---|
| 407 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 408 | iy += 1 |
---|
[2661d8b] | 409 | ix = 1 |
---|
[c128284] | 410 | sizer_high_q.Add(npts_high_txt,(iy, ix),(1,1), |
---|
| 411 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 412 | ix += 1 |
---|
| 413 | sizer_high_q.Add(self.npts_high_ctl, (iy, ix), (1,1), |
---|
| 414 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 415 | iy += 1 |
---|
| 416 | ix = 0 |
---|
[2661d8b] | 417 | sizer_high_q.Add(self.enable_high_cbox,(iy, ix),(1,5), |
---|
[c128284] | 418 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[d5f0dcb9] | 419 | |
---|
| 420 | boxsizer_high_q.Add(sizer_high_q) |
---|
[c128284] | 421 | boxsizer_low_q.Add(sizer_low_q) |
---|
| 422 | |
---|
| 423 | #-------------Enable extrapolation------- |
---|
| 424 | extra_hint = "Extrapolation Maximum Range: " |
---|
| 425 | extra_hint_txt= wx.StaticText(self, -1,extra_hint ) |
---|
| 426 | extra_range = "[%s - %s]"%(str(Q_MINIMUM), str(Q_MAXIMUM)) |
---|
| 427 | extra_range_value_txt = wx.StaticText(self, -1, str(extra_range)) |
---|
| 428 | extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !" |
---|
| 429 | extra_enable_hint_txt= wx.StaticText(self, -1, extra_enable_hint ) |
---|
[272d91e] | 430 | |
---|
[c128284] | 431 | enable_sizer = wx.GridBagSizer(5,5) |
---|
[272d91e] | 432 | |
---|
[c128284] | 433 | iy = 0 |
---|
| 434 | ix = 0 |
---|
| 435 | enable_sizer.Add(extra_hint_txt,(iy, ix),(1,1), |
---|
| 436 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 437 | ix += 1 |
---|
| 438 | enable_sizer.Add(extra_range_value_txt, (iy, ix), (1,1), |
---|
| 439 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 440 | ix = 0 |
---|
| 441 | iy += 1 |
---|
| 442 | enable_sizer.Add(extra_enable_hint_txt,(iy, ix),(1,1), |
---|
| 443 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 444 | |
---|
| 445 | type_extrapolation_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 446 | type_extrapolation_sizer.Add((10,10)) |
---|
| 447 | type_extrapolation_sizer.Add(boxsizer_low_q, 0, wx.ALL, 10) |
---|
| 448 | type_extrapolation_sizer.Add((20,20)) |
---|
| 449 | type_extrapolation_sizer.Add(boxsizer_high_q, 0, wx.ALL, 10) |
---|
| 450 | type_extrapolation_sizer.Add((10,10)) |
---|
[d5f0dcb9] | 451 | |
---|
[c128284] | 452 | boxsizer_extra = wx.StaticBoxSizer(extrapolation_box, wx.VERTICAL) |
---|
| 453 | boxsizer_extra.Add(enable_sizer, 0, wx.ALL, 10) |
---|
| 454 | boxsizer_extra.Add(type_extrapolation_sizer) |
---|
[d5f0dcb9] | 455 | |
---|
[c128284] | 456 | boxsizer1.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
| 457 | boxsizer1.Add(sizer_input) |
---|
| 458 | boxsizer1.Add(boxsizer_extra, 0, wx.ALL, 10) |
---|
| 459 | sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 460 | |
---|
| 461 | #---------Outputs sizer-------- |
---|
| 462 | invariant_txt = wx.StaticText(self, -1, 'Invariant') |
---|
| 463 | self.invariant_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 464 | self.invariant_ctl.SetEditable(False) |
---|
[2661d8b] | 465 | self.invariant_ctl.SetToolTipString("Invariant in the data set's Q range.") |
---|
[c128284] | 466 | self.invariant_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 467 | self.invariant_err_ctl.SetEditable(False) |
---|
[2661d8b] | 468 | self.invariant_err_ctl.SetToolTipString("Uncertainty on the invariant.") |
---|
[c128284] | 469 | invariant_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 470 | |
---|
| 471 | invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total') |
---|
| 472 | self.invariant_total_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 473 | self.invariant_total_ctl.SetEditable(False) |
---|
[2661d8b] | 474 | msg_hint = "Total invariant, including extrapolated regions." |
---|
[c128284] | 475 | self.invariant_total_ctl.SetToolTipString(msg_hint) |
---|
| 476 | self.invariant_total_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 477 | self.invariant_total_err_ctl.SetEditable(False) |
---|
| 478 | self.invariant_total_err_ctl.SetToolTipString("Uncertainty on invariant.") |
---|
| 479 | invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 480 | |
---|
| 481 | volume_txt = wx.StaticText(self, -1, 'Volume Fraction') |
---|
| 482 | self.volume_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 483 | self.volume_ctl.SetEditable(False) |
---|
[2661d8b] | 484 | self.volume_ctl.SetToolTipString("Volume fraction.") |
---|
[c128284] | 485 | self.volume_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 486 | self.volume_err_ctl.SetEditable(False) |
---|
[2661d8b] | 487 | self.volume_err_ctl.SetToolTipString("Uncertainty on the volume fraction.") |
---|
[c128284] | 488 | volume_units_txt = wx.StaticText(self, -1, unit_volume) |
---|
| 489 | |
---|
[2661d8b] | 490 | surface_txt = wx.StaticText(self, -1, 'Specific surface') |
---|
[c128284] | 491 | self.surface_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 492 | self.surface_ctl.SetEditable(False) |
---|
[2661d8b] | 493 | self.surface_ctl.SetToolTipString("Specific surface value.") |
---|
[c128284] | 494 | self.surface_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 495 | self.surface_err_ctl.SetEditable(False) |
---|
[2661d8b] | 496 | self.surface_err_ctl.SetToolTipString("Uncertainty on the specific surface.") |
---|
[c128284] | 497 | surface_units_txt = wx.StaticText(self, -1, unit_surface) |
---|
| 498 | |
---|
[2661d8b] | 499 | invariant_low_txt = wx.StaticText(self, -1, 'Invariant in low-Q region') |
---|
[c128284] | 500 | self.invariant_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 501 | self.invariant_low_ctl.SetEditable(False) |
---|
[2661d8b] | 502 | self.invariant_low_ctl.SetToolTipString("Invariant computed with the extrapolated low-Q data.") |
---|
[c128284] | 503 | invariant_low_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 504 | |
---|
[2661d8b] | 505 | invariant_high_txt = wx.StaticText(self, -1, 'Invariant in high-Q region') |
---|
[c128284] | 506 | self.invariant_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 507 | self.invariant_high_ctl.SetEditable(False) |
---|
[2661d8b] | 508 | self.invariant_high_ctl.SetToolTipString("Invariant computed with the extrapolated high-Q data") |
---|
[c128284] | 509 | invariant_high_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 510 | |
---|
| 511 | iy = 0 |
---|
| 512 | ix = 0 |
---|
| 513 | sizer_output.Add(invariant_low_txt, (iy, ix), (1,1), |
---|
| 514 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 515 | ix +=1 |
---|
| 516 | sizer_output.Add(self.invariant_low_ctl, (iy, ix), (1,1), |
---|
| 517 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 518 | ix += 2 |
---|
| 519 | sizer_output.Add(invariant_low_units_txt, (iy, ix), (1,1), |
---|
| 520 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 521 | iy += 1 |
---|
| 522 | ix = 0 |
---|
| 523 | sizer_output.Add(invariant_high_txt, (iy, ix), (1,1), |
---|
| 524 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 525 | ix +=1 |
---|
| 526 | sizer_output.Add(self.invariant_high_ctl, (iy, ix), (1,1), |
---|
| 527 | wx.EXPAND|wx.ADJUST_MINSIZE, ) |
---|
| 528 | ix += 2 |
---|
| 529 | sizer_output.Add(invariant_high_units_txt, (iy, ix), (1,1), |
---|
| 530 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 531 | iy += 1 |
---|
| 532 | ix = 0 |
---|
| 533 | sizer_output.Add(invariant_txt,(iy, ix),(1,1), |
---|
| 534 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 535 | ix += 1 |
---|
| 536 | sizer_output.Add(self.invariant_ctl,(iy, ix),(1,1), |
---|
| 537 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 538 | ix += 1 |
---|
| 539 | sizer_output.Add( wx.StaticText(self, -1, uncertainty), |
---|
| 540 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 541 | ix +=1 |
---|
| 542 | sizer_output.Add(self.invariant_err_ctl |
---|
| 543 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 544 | ix +=1 |
---|
| 545 | sizer_output.Add(invariant_units_txt |
---|
| 546 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 547 | iy += 1 |
---|
| 548 | ix = 0 |
---|
| 549 | sizer_output.Add(invariant_total_txt,(iy, ix),(1,1), |
---|
| 550 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 551 | ix += 1 |
---|
| 552 | sizer_output.Add(self.invariant_total_ctl,(iy, ix),(1,1), |
---|
| 553 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 554 | ix += 1 |
---|
| 555 | sizer_output.Add( wx.StaticText(self, -1, uncertainty), |
---|
| 556 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 557 | ix +=1 |
---|
| 558 | sizer_output.Add(self.invariant_total_err_ctl |
---|
| 559 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 560 | ix +=1 |
---|
| 561 | sizer_output.Add(invariant_total_units_txt,(iy, ix), |
---|
| 562 | (1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 563 | iy += 1 |
---|
| 564 | ix = 0 |
---|
| 565 | sizer_output.Add(volume_txt,(iy, ix),(1,1), |
---|
| 566 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 567 | ix +=1 |
---|
| 568 | sizer_output.Add(self.volume_ctl,(iy, ix),(1,1), |
---|
| 569 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 570 | ix +=1 |
---|
| 571 | sizer_output.Add(wx.StaticText(self, -1, uncertainty) |
---|
| 572 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 573 | ix += 1 |
---|
| 574 | sizer_output.Add(self.volume_err_ctl |
---|
| 575 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 576 | ix += 1 |
---|
| 577 | sizer_output.Add(volume_units_txt |
---|
| 578 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 579 | iy += 1 |
---|
| 580 | ix = 0 |
---|
| 581 | sizer_output.Add(surface_txt,(iy, ix),(1,1), |
---|
| 582 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 583 | ix +=1 |
---|
| 584 | sizer_output.Add(self.surface_ctl,(iy, ix),(1,1), |
---|
| 585 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 586 | ix +=1 |
---|
| 587 | sizer_output.Add(wx.StaticText(self, -1, uncertainty) |
---|
| 588 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 589 | ix += 1 |
---|
| 590 | sizer_output.Add(self.surface_err_ctl |
---|
| 591 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 592 | ix +=1 |
---|
| 593 | sizer_output.Add(surface_units_txt |
---|
| 594 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 595 | |
---|
| 596 | outputbox = wx.StaticBox(self, -1, "Output") |
---|
| 597 | boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL) |
---|
| 598 | boxsizer2.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
| 599 | boxsizer2.Add( sizer_output ) |
---|
| 600 | sizer2.Add(boxsizer2,0, wx.EXPAND|wx.ALL, 10) |
---|
| 601 | #-----Button sizer------------ |
---|
| 602 | id = wx.NewId() |
---|
| 603 | button_calculate = wx.Button(self, id, "Compute") |
---|
[2661d8b] | 604 | button_calculate.SetToolTipString("Compute invariant") |
---|
[c128284] | 605 | self.Bind(wx.EVT_BUTTON, self.compute_invariant, id = id) |
---|
| 606 | |
---|
| 607 | sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 608 | sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE,20) |
---|
| 609 | sizer3.Add(sizer_button) |
---|
| 610 | #---------layout---------------- |
---|
[d5f0dcb9] | 611 | |
---|
[c128284] | 612 | vbox.Add(sizer1) |
---|
| 613 | vbox.Add(sizer2) |
---|
| 614 | vbox.Add(sizer3) |
---|
| 615 | vbox.Fit(self) |
---|
| 616 | self.SetSizer(vbox) |
---|
| 617 | |
---|
| 618 | class InvariantDialog(wx.Dialog): |
---|
| 619 | def __init__(self, parent=None, id=1,graph=None, |
---|
[272d91e] | 620 | data=None, title="Invariant",base=None): |
---|
| 621 | wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
[c128284] | 622 | PANEL_HEIGHT)) |
---|
[272d91e] | 623 | self.panel = InvariantPanel(self) |
---|
[c128284] | 624 | self.Centre() |
---|
| 625 | self.Show(True) |
---|
| 626 | |
---|
| 627 | class InvariantWindow(wx.Frame): |
---|
[272d91e] | 628 | def __init__(self, parent=None, id=1,graph=None, |
---|
| 629 | data=None, title="Invariant",base=None): |
---|
[c128284] | 630 | |
---|
[272d91e] | 631 | wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
[c128284] | 632 | PANEL_HEIGHT)) |
---|
| 633 | |
---|
[272d91e] | 634 | self.panel = InvariantPanel(self) |
---|
[c128284] | 635 | self.Centre() |
---|
| 636 | self.Show(True) |
---|
| 637 | |
---|
| 638 | class MyApp(wx.App): |
---|
| 639 | def OnInit(self): |
---|
| 640 | wx.InitAllImageHandlers() |
---|
| 641 | frame = InvariantWindow() |
---|
| 642 | frame.Show(True) |
---|
| 643 | self.SetTopWindow(frame) |
---|
| 644 | |
---|
| 645 | return True |
---|
[272d91e] | 646 | |
---|
[c128284] | 647 | # end of class MyApp |
---|
| 648 | |
---|
| 649 | if __name__ == "__main__": |
---|
| 650 | app = MyApp(0) |
---|
| 651 | app.MainLoop() |
---|