[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: |
---|
| 152 | msg= "Error occurs for invariant: %s"%sys.exc_value |
---|
| 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)) |
---|
| 161 | #plot data |
---|
[272d91e] | 162 | low_out_data, low_in_data = inv.get_extra_data_low() |
---|
| 163 | self._manager._plot_theory(reel_data=self._data, |
---|
| 164 | extra_data=low_out_data, |
---|
| 165 | name=self._data.name+" Extra_low_Q") |
---|
| 166 | self._manager._plot_data(reel_data=self._data, |
---|
| 167 | extra_data=low_in_data, |
---|
| 168 | name=self._data.name+"Fitted data for low_Q") |
---|
[c128284] | 169 | except: |
---|
| 170 | msg= "Error occurs for low q invariant: %s"%sys.exc_value |
---|
[272d91e] | 171 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
[c128284] | 172 | if high_q: |
---|
| 173 | try: |
---|
[53b6b74] | 174 | qstar_high, qstar_high_err = inv.get_qstar_high() |
---|
[c128284] | 175 | self.invariant_high_ctl.SetValue(format_number(qstar_high)) |
---|
| 176 | #plot data |
---|
[272d91e] | 177 | high_out_data, high_in_data = inv.get_extra_data_high(q_end=Q_MAXIMUM_PLOT) |
---|
| 178 | self._manager._plot_theory(reel_data=self._data, |
---|
| 179 | extra_data=high_out_data, |
---|
| 180 | name=self._data.name+" Extra_high_Q") |
---|
| 181 | self._manager._plot_data(reel_data=self._data, |
---|
| 182 | extra_data=high_in_data, |
---|
| 183 | name=self._data.name+"Fitted data for high_Q") |
---|
[c128284] | 184 | except: |
---|
| 185 | msg= "Error occurs for high q invariant: %s"%sys.exc_value |
---|
| 186 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 187 | try: |
---|
[272d91e] | 188 | qstar_total, qstar_total_err = inv.get_qstar_with_error(extrapolation) |
---|
[c128284] | 189 | self.invariant_total_ctl.SetValue(format_number(qstar_total)) |
---|
| 190 | self.invariant_total_err_ctl.SetValue(format_number(qstar_total)) |
---|
| 191 | check_float(self.invariant_total_ctl) |
---|
| 192 | check_float(self.invariant_total_err_ctl) |
---|
| 193 | except: |
---|
| 194 | msg= "Error occurs for total invariant: %s"%sys.exc_value |
---|
[272d91e] | 195 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 196 | |
---|
[53b6b74] | 197 | # Parse additional parameters |
---|
| 198 | par_str = self.porod_const_ctl.GetValue().strip() |
---|
| 199 | porod_const = None |
---|
| 200 | if len(par_str)>0 and check_float(self.porod_const_ctl): |
---|
| 201 | porod_const = float(par_str) |
---|
| 202 | |
---|
| 203 | par_str = self.contrast_ctl.GetValue().strip() |
---|
| 204 | contrast = None |
---|
| 205 | if len(par_str)>0 and check_float(self.contrast_ctl): |
---|
| 206 | contrast = float(par_str) |
---|
| 207 | |
---|
| 208 | if contrast is not None: |
---|
| 209 | try: |
---|
| 210 | v, dv = inv.get_volume_fraction_with_error(contrast=contrast) |
---|
| 211 | self.volume_ctl.SetValue(format_number(v)) |
---|
| 212 | self.volume_err_ctl.SetValue(format_number(dv)) |
---|
| 213 | except: |
---|
| 214 | msg= "Error occurs for volume fraction: %s"%sys.exc_value |
---|
| 215 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 216 | |
---|
| 217 | if contrast is not None and porod_const is not None: |
---|
| 218 | try: |
---|
| 219 | s, ds = inv.get_surface_with_error(contrast=contrast, |
---|
| 220 | porod_const=porod_const) |
---|
| 221 | self.surface_ctl.SetValue(format_number(s)) |
---|
| 222 | self.surface_err_ctl.SetValue(format_number(ds)) |
---|
| 223 | except: |
---|
| 224 | msg= "Error occurs for surface: %s"%sys.exc_value |
---|
| 225 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
[272d91e] | 226 | |
---|
[c128284] | 227 | else: |
---|
| 228 | msg= "invariant: Need float for background and scale" |
---|
| 229 | wx.PostEvent(self.parent, StatusEvent(status= msg, type="stop")) |
---|
| 230 | return |
---|
[272d91e] | 231 | |
---|
[c128284] | 232 | def _reset_output(self): |
---|
| 233 | """ |
---|
| 234 | clear outputs textcrtl |
---|
| 235 | """ |
---|
| 236 | self.invariant_ctl.Clear() |
---|
| 237 | self.invariant_err_ctl.Clear() |
---|
| 238 | self.invariant_low_ctl.Clear() |
---|
| 239 | self.invariant_high_ctl.Clear() |
---|
| 240 | self.invariant_total_ctl.Clear() |
---|
| 241 | self.invariant_total_err_ctl.Clear() |
---|
| 242 | self.volume_ctl.Clear() |
---|
| 243 | self.volume_err_ctl.Clear() |
---|
| 244 | self.surface_ctl.Clear() |
---|
| 245 | self.surface_err_ctl.Clear() |
---|
| 246 | |
---|
| 247 | def _do_layout(self): |
---|
| 248 | """ |
---|
| 249 | Draw window content |
---|
| 250 | """ |
---|
| 251 | unit_invariant = '[1/cm][1/A]' |
---|
| 252 | unit_volume = '' |
---|
| 253 | unit_surface = '' |
---|
| 254 | uncertainty = "+/-" |
---|
| 255 | npts_hint_txt = "Number of points to consider during extrapolation." |
---|
| 256 | power_hint_txt = "Exponent to apply to the Power_law function." |
---|
| 257 | |
---|
| 258 | sizer_input = wx.FlexGridSizer(5,4)#wx.GridBagSizer(5,5) |
---|
| 259 | sizer_output = wx.GridBagSizer(5,5) |
---|
| 260 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 261 | |
---|
| 262 | sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
| 263 | sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
| 264 | sizer3 = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 265 | |
---|
| 266 | sizer1.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
| 267 | sizer2.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
| 268 | sizer3.SetMinSize((_STATICBOX_WIDTH, -1)) |
---|
[d5f0dcb9] | 269 | |
---|
| 270 | ## Box sizers must be defined first before defining buttons/textctrls (MAC). |
---|
| 271 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 272 | inputbox = wx.StaticBox(self, -1, "Input") |
---|
| 273 | extrapolation_box = wx.StaticBox(self, -1, "Extrapolation") |
---|
| 274 | boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL) |
---|
| 275 | high_q_box = wx.StaticBox(self, -1, "High Q") |
---|
| 276 | boxsizer_high_q = wx.StaticBoxSizer(high_q_box, wx.VERTICAL) |
---|
| 277 | low_q_box = wx.StaticBox(self, -1, "Low Q") |
---|
| 278 | boxsizer_low_q = wx.StaticBoxSizer(low_q_box, wx.VERTICAL) |
---|
| 279 | |
---|
[c128284] | 280 | #---------inputs---------------- |
---|
[272d91e] | 281 | data_name = "" |
---|
[c128284] | 282 | data_range = "[? - ?]" |
---|
[272d91e] | 283 | if self._data is not None: |
---|
| 284 | data_name = self._data.name |
---|
| 285 | data_qmin = min (self._data.x) |
---|
| 286 | data_qmax = max (self._data.x) |
---|
| 287 | data_range = "[%s - %s]"%(str(data_qmin), str(data_qmax)) |
---|
| 288 | |
---|
| 289 | self.data_name_txt = wx.StaticText(self, -1, 'Data : '+str(data_name)) |
---|
[c128284] | 290 | data_range_txt = wx.StaticText(self, -1, "Range : ") |
---|
| 291 | self.data_range_value_txt = wx.StaticText(self, -1, str(data_range)) |
---|
| 292 | |
---|
| 293 | background_txt = wx.StaticText(self, -1, 'Background (Optional)') |
---|
| 294 | self.background_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 295 | self.background_ctl.SetValue(str(BACKGROUND)) |
---|
| 296 | self.background_ctl.SetToolTipString("Background to subtract to data.") |
---|
| 297 | scale_txt = wx.StaticText(self, -1, 'Scale (Optional)') |
---|
| 298 | self.scale_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 299 | self.scale_ctl.SetValue(str(SCALE)) |
---|
| 300 | self.scale_ctl.SetToolTipString("Scale to apply to data.") |
---|
| 301 | contrast_txt = wx.StaticText(self, -1, 'Contrast (Optional)') |
---|
| 302 | self.contrast_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 303 | msg_hint = "Enter a value for the contrast to get the volume fraction" |
---|
| 304 | self.contrast_ctl.SetToolTipString(str(msg_hint)) |
---|
| 305 | porod_const_txt = wx.StaticText(self, -1, 'Porod Constant(Optional)') |
---|
| 306 | self.porod_const_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 307 | msg_hint ="Need both the contrast and surface to get the surface" |
---|
| 308 | self.porod_const_ctl.SetToolTipString(str(msg_hint)) |
---|
| 309 | |
---|
[272d91e] | 310 | sizer_input.Add(self.data_name_txt, 0, wx.LEFT, 5) |
---|
| 311 | sizer_input.Add((10,10), 0, wx.LEFT, 5) |
---|
[c128284] | 312 | sizer_input.Add(data_range_txt, 0, wx.LEFT, 10) |
---|
| 313 | sizer_input.Add(self.data_range_value_txt) |
---|
| 314 | sizer_input.Add(background_txt, 0, wx.ALL, 5) |
---|
| 315 | sizer_input.Add(self.background_ctl, 0, wx.ALL, 5) |
---|
| 316 | sizer_input.Add((10,10)) |
---|
| 317 | sizer_input.Add((10,10)) |
---|
| 318 | sizer_input.Add(scale_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 319 | sizer_input.Add(self.scale_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(contrast_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 323 | sizer_input.Add(self.contrast_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 324 | sizer_input.Add((10,10)) |
---|
| 325 | sizer_input.Add((10,10)) |
---|
| 326 | sizer_input.Add(porod_const_txt, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 327 | sizer_input.Add(self.porod_const_ctl, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM, 5) |
---|
| 328 | #-------------Extrapolation sizer---------------- |
---|
| 329 | sizer_low_q = wx.GridBagSizer(5,5) |
---|
| 330 | |
---|
| 331 | self.enable_low_cbox = wx.CheckBox(self, -1, "Enable low Q") |
---|
| 332 | self.enable_low_cbox.SetValue(False) |
---|
| 333 | self.enable_high_cbox = wx.CheckBox(self, -1, "Enable High Q") |
---|
| 334 | self.enable_high_cbox.SetValue(False) |
---|
| 335 | |
---|
| 336 | self.guinier = wx.RadioButton(self, -1, 'Guinier', |
---|
| 337 | (10, 10),style=wx.RB_GROUP) |
---|
| 338 | self.power_law_low = wx.RadioButton(self, -1, 'Power_law', (10, 10)) |
---|
| 339 | self.guinier.SetValue(True) |
---|
| 340 | |
---|
| 341 | npts_low_txt = wx.StaticText(self, -1, 'Npts') |
---|
| 342 | self.npts_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
| 343 | self.npts_low_ctl.SetValue(str(NPTS)) |
---|
| 344 | msg_hint = "the number of first q points to consider" |
---|
| 345 | msg_hint +="during the fit for extrapolation at low Q" |
---|
| 346 | self.npts_low_ctl.SetToolTipString(msg_hint) |
---|
| 347 | self.power_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
| 348 | self.power_low_ctl.SetValue(str(self.power_law_exponant)) |
---|
| 349 | self.power_low_ctl.SetToolTipString(power_hint_txt) |
---|
| 350 | iy = 0 |
---|
| 351 | ix = 0 |
---|
| 352 | sizer_low_q.Add(self.guinier,(iy, ix),(1,1), |
---|
| 353 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 354 | iy += 1 |
---|
| 355 | ix = 0 |
---|
| 356 | sizer_low_q.Add(self.power_law_low,(iy, ix),(1,1), |
---|
| 357 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 358 | ix += 1 |
---|
| 359 | sizer_low_q.Add(self.power_low_ctl, (iy, ix), (1,1), |
---|
| 360 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 361 | iy += 1 |
---|
| 362 | ix = 0 |
---|
| 363 | sizer_low_q.Add(npts_low_txt,(iy, ix),(1,1), |
---|
| 364 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 365 | ix += 1 |
---|
| 366 | sizer_low_q.Add(self.npts_low_ctl, (iy, ix), (1,1), |
---|
| 367 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 368 | iy += 1 |
---|
| 369 | ix = 0 |
---|
| 370 | sizer_low_q.Add(self.enable_low_cbox,(iy, ix),(1,1), |
---|
| 371 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 372 | sizer_high_q = wx.GridBagSizer(5,5) |
---|
| 373 | self.power_law_high = wx.RadioButton(self, -1, 'Power_law', |
---|
| 374 | (10, 10), style=wx.RB_GROUP) |
---|
| 375 | msg_hint ="Check it to extrapolate data to high Q" |
---|
| 376 | self.power_law_high.SetToolTipString(msg_hint) |
---|
| 377 | |
---|
| 378 | #MAC needs SetValue |
---|
| 379 | self.power_law_high.SetValue(True) |
---|
| 380 | npts_high_txt = wx.StaticText(self, -1, 'Npts') |
---|
| 381 | self.npts_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
| 382 | msg_hint = "the number of last q points to consider" |
---|
| 383 | msg_hint += "during the fit for extrapolation high Q" |
---|
| 384 | self.npts_high_ctl.SetToolTipString(msg_hint) |
---|
| 385 | self.npts_high_ctl.SetValue(str(NPTS)) |
---|
| 386 | self.power_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH/3, -1)) |
---|
| 387 | self.power_high_ctl.SetValue(str(self.power_law_exponant)) |
---|
| 388 | self.power_high_ctl.SetToolTipString(power_hint_txt) |
---|
| 389 | |
---|
| 390 | iy = 1 |
---|
| 391 | ix = 0 |
---|
| 392 | sizer_high_q.Add(self.power_law_high,(iy, ix),(1,1), |
---|
| 393 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 394 | ix += 1 |
---|
| 395 | sizer_high_q.Add(self.power_high_ctl, (iy, ix), (1,1), |
---|
| 396 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 397 | iy += 1 |
---|
| 398 | ix = 0 |
---|
| 399 | sizer_high_q.Add(npts_high_txt,(iy, ix),(1,1), |
---|
| 400 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 401 | ix += 1 |
---|
| 402 | sizer_high_q.Add(self.npts_high_ctl, (iy, ix), (1,1), |
---|
| 403 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 404 | iy += 1 |
---|
| 405 | ix = 0 |
---|
| 406 | sizer_high_q.Add(self.enable_high_cbox,(iy, ix),(1,1), |
---|
| 407 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[d5f0dcb9] | 408 | |
---|
| 409 | boxsizer_high_q.Add(sizer_high_q) |
---|
[c128284] | 410 | boxsizer_low_q.Add(sizer_low_q) |
---|
| 411 | |
---|
| 412 | #-------------Enable extrapolation------- |
---|
| 413 | extra_hint = "Extrapolation Maximum Range: " |
---|
| 414 | extra_hint_txt= wx.StaticText(self, -1,extra_hint ) |
---|
| 415 | extra_range = "[%s - %s]"%(str(Q_MINIMUM), str(Q_MAXIMUM)) |
---|
| 416 | extra_range_value_txt = wx.StaticText(self, -1, str(extra_range)) |
---|
| 417 | extra_enable_hint = "Hint: Check any box to enable a specific extrapolation !" |
---|
| 418 | extra_enable_hint_txt= wx.StaticText(self, -1, extra_enable_hint ) |
---|
[272d91e] | 419 | |
---|
[c128284] | 420 | enable_sizer = wx.GridBagSizer(5,5) |
---|
[272d91e] | 421 | |
---|
[c128284] | 422 | iy = 0 |
---|
| 423 | ix = 0 |
---|
| 424 | enable_sizer.Add(extra_hint_txt,(iy, ix),(1,1), |
---|
| 425 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 426 | ix += 1 |
---|
| 427 | enable_sizer.Add(extra_range_value_txt, (iy, ix), (1,1), |
---|
| 428 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 429 | ix = 0 |
---|
| 430 | iy += 1 |
---|
| 431 | enable_sizer.Add(extra_enable_hint_txt,(iy, ix),(1,1), |
---|
| 432 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 433 | |
---|
| 434 | type_extrapolation_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 435 | type_extrapolation_sizer.Add((10,10)) |
---|
| 436 | type_extrapolation_sizer.Add(boxsizer_low_q, 0, wx.ALL, 10) |
---|
| 437 | type_extrapolation_sizer.Add((20,20)) |
---|
| 438 | type_extrapolation_sizer.Add(boxsizer_high_q, 0, wx.ALL, 10) |
---|
| 439 | type_extrapolation_sizer.Add((10,10)) |
---|
[d5f0dcb9] | 440 | |
---|
[c128284] | 441 | boxsizer_extra = wx.StaticBoxSizer(extrapolation_box, wx.VERTICAL) |
---|
| 442 | boxsizer_extra.Add(enable_sizer, 0, wx.ALL, 10) |
---|
| 443 | boxsizer_extra.Add(type_extrapolation_sizer) |
---|
[d5f0dcb9] | 444 | |
---|
[c128284] | 445 | boxsizer1.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
| 446 | boxsizer1.Add(sizer_input) |
---|
| 447 | boxsizer1.Add(boxsizer_extra, 0, wx.ALL, 10) |
---|
| 448 | sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
| 449 | |
---|
| 450 | #---------Outputs sizer-------- |
---|
| 451 | invariant_txt = wx.StaticText(self, -1, 'Invariant') |
---|
| 452 | self.invariant_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 453 | self.invariant_ctl.SetEditable(False) |
---|
| 454 | self.invariant_ctl.SetToolTipString("Invariant in q range.") |
---|
| 455 | self.invariant_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 456 | self.invariant_err_ctl.SetEditable(False) |
---|
| 457 | self.invariant_err_ctl.SetToolTipString("Uncertainty on invariant.") |
---|
| 458 | invariant_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 459 | |
---|
| 460 | invariant_total_txt = wx.StaticText(self, -1, 'Invariant Total') |
---|
| 461 | self.invariant_total_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 462 | self.invariant_total_ctl.SetEditable(False) |
---|
| 463 | msg_hint = "Invariant in q range and extra polated range." |
---|
| 464 | self.invariant_total_ctl.SetToolTipString(msg_hint) |
---|
| 465 | self.invariant_total_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 466 | self.invariant_total_err_ctl.SetEditable(False) |
---|
| 467 | self.invariant_total_err_ctl.SetToolTipString("Uncertainty on invariant.") |
---|
| 468 | invariant_total_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 469 | |
---|
| 470 | volume_txt = wx.StaticText(self, -1, 'Volume Fraction') |
---|
| 471 | self.volume_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 472 | self.volume_ctl.SetEditable(False) |
---|
| 473 | self.volume_ctl.SetToolTipString("volume fraction.") |
---|
| 474 | self.volume_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 475 | self.volume_err_ctl.SetEditable(False) |
---|
| 476 | self.volume_err_ctl.SetToolTipString("Uncertainty of volume fraction.") |
---|
| 477 | volume_units_txt = wx.StaticText(self, -1, unit_volume) |
---|
| 478 | |
---|
| 479 | surface_txt = wx.StaticText(self, -1, 'Surface') |
---|
| 480 | self.surface_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 481 | self.surface_ctl.SetEditable(False) |
---|
| 482 | self.surface_ctl.SetToolTipString("Surface.") |
---|
| 483 | self.surface_err_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 484 | self.surface_err_ctl.SetEditable(False) |
---|
| 485 | self.surface_err_ctl.SetToolTipString("Uncertainty of surface.") |
---|
| 486 | surface_units_txt = wx.StaticText(self, -1, unit_surface) |
---|
| 487 | |
---|
| 488 | invariant_low_txt = wx.StaticText(self, -1, 'Invariant in low Q') |
---|
| 489 | self.invariant_low_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 490 | self.invariant_low_ctl.SetEditable(False) |
---|
| 491 | self.invariant_low_ctl.SetToolTipString("Invariant compute in low Q") |
---|
| 492 | invariant_low_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 493 | |
---|
| 494 | invariant_high_txt = wx.StaticText(self, -1, 'Invariant in high Q') |
---|
| 495 | self.invariant_high_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
| 496 | self.invariant_high_ctl.SetEditable(False) |
---|
| 497 | self.invariant_high_ctl.SetToolTipString("Invariant compute in high Q") |
---|
| 498 | invariant_high_units_txt = wx.StaticText(self, -1, unit_invariant) |
---|
| 499 | |
---|
| 500 | iy = 0 |
---|
| 501 | ix = 0 |
---|
| 502 | sizer_output.Add(invariant_low_txt, (iy, ix), (1,1), |
---|
| 503 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 504 | ix +=1 |
---|
| 505 | sizer_output.Add(self.invariant_low_ctl, (iy, ix), (1,1), |
---|
| 506 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 507 | ix += 2 |
---|
| 508 | sizer_output.Add(invariant_low_units_txt, (iy, ix), (1,1), |
---|
| 509 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 510 | iy += 1 |
---|
| 511 | ix = 0 |
---|
| 512 | sizer_output.Add(invariant_high_txt, (iy, ix), (1,1), |
---|
| 513 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 514 | ix +=1 |
---|
| 515 | sizer_output.Add(self.invariant_high_ctl, (iy, ix), (1,1), |
---|
| 516 | wx.EXPAND|wx.ADJUST_MINSIZE, ) |
---|
| 517 | ix += 2 |
---|
| 518 | sizer_output.Add(invariant_high_units_txt, (iy, ix), (1,1), |
---|
| 519 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 520 | iy += 1 |
---|
| 521 | ix = 0 |
---|
| 522 | sizer_output.Add(invariant_txt,(iy, ix),(1,1), |
---|
| 523 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 524 | ix += 1 |
---|
| 525 | sizer_output.Add(self.invariant_ctl,(iy, ix),(1,1), |
---|
| 526 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 527 | ix += 1 |
---|
| 528 | sizer_output.Add( wx.StaticText(self, -1, uncertainty), |
---|
| 529 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 530 | ix +=1 |
---|
| 531 | sizer_output.Add(self.invariant_err_ctl |
---|
| 532 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 533 | ix +=1 |
---|
| 534 | sizer_output.Add(invariant_units_txt |
---|
| 535 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 536 | iy += 1 |
---|
| 537 | ix = 0 |
---|
| 538 | sizer_output.Add(invariant_total_txt,(iy, ix),(1,1), |
---|
| 539 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 540 | ix += 1 |
---|
| 541 | sizer_output.Add(self.invariant_total_ctl,(iy, ix),(1,1), |
---|
| 542 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 543 | ix += 1 |
---|
| 544 | sizer_output.Add( wx.StaticText(self, -1, uncertainty), |
---|
| 545 | (iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 546 | ix +=1 |
---|
| 547 | sizer_output.Add(self.invariant_total_err_ctl |
---|
| 548 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 549 | ix +=1 |
---|
| 550 | sizer_output.Add(invariant_total_units_txt,(iy, ix), |
---|
| 551 | (1,1),wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 552 | iy += 1 |
---|
| 553 | ix = 0 |
---|
| 554 | sizer_output.Add(volume_txt,(iy, ix),(1,1), |
---|
| 555 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 556 | ix +=1 |
---|
| 557 | sizer_output.Add(self.volume_ctl,(iy, ix),(1,1), |
---|
| 558 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 559 | ix +=1 |
---|
| 560 | sizer_output.Add(wx.StaticText(self, -1, uncertainty) |
---|
| 561 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 562 | ix += 1 |
---|
| 563 | sizer_output.Add(self.volume_err_ctl |
---|
| 564 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 565 | ix += 1 |
---|
| 566 | sizer_output.Add(volume_units_txt |
---|
| 567 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 568 | iy += 1 |
---|
| 569 | ix = 0 |
---|
| 570 | sizer_output.Add(surface_txt,(iy, ix),(1,1), |
---|
| 571 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
| 572 | ix +=1 |
---|
| 573 | sizer_output.Add(self.surface_ctl,(iy, ix),(1,1), |
---|
| 574 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 575 | ix +=1 |
---|
| 576 | sizer_output.Add(wx.StaticText(self, -1, uncertainty) |
---|
| 577 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 578 | ix += 1 |
---|
| 579 | sizer_output.Add(self.surface_err_ctl |
---|
| 580 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 581 | ix +=1 |
---|
| 582 | sizer_output.Add(surface_units_txt |
---|
| 583 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 584 | |
---|
| 585 | outputbox = wx.StaticBox(self, -1, "Output") |
---|
| 586 | boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL) |
---|
| 587 | boxsizer2.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
| 588 | boxsizer2.Add( sizer_output ) |
---|
| 589 | sizer2.Add(boxsizer2,0, wx.EXPAND|wx.ALL, 10) |
---|
| 590 | #-----Button sizer------------ |
---|
| 591 | id = wx.NewId() |
---|
| 592 | button_calculate = wx.Button(self, id, "Compute") |
---|
| 593 | button_calculate.SetToolTipString("Compute SlD of neutrons.") |
---|
| 594 | self.Bind(wx.EVT_BUTTON, self.compute_invariant, id = id) |
---|
| 595 | |
---|
| 596 | sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 597 | sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE,20) |
---|
| 598 | sizer3.Add(sizer_button) |
---|
| 599 | #---------layout---------------- |
---|
[d5f0dcb9] | 600 | |
---|
[c128284] | 601 | vbox.Add(sizer1) |
---|
| 602 | vbox.Add(sizer2) |
---|
| 603 | vbox.Add(sizer3) |
---|
| 604 | vbox.Fit(self) |
---|
| 605 | self.SetSizer(vbox) |
---|
| 606 | |
---|
| 607 | class InvariantDialog(wx.Dialog): |
---|
| 608 | def __init__(self, parent=None, id=1,graph=None, |
---|
[272d91e] | 609 | data=None, title="Invariant",base=None): |
---|
| 610 | wx.Dialog.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
[c128284] | 611 | PANEL_HEIGHT)) |
---|
[272d91e] | 612 | self.panel = InvariantPanel(self) |
---|
[c128284] | 613 | self.Centre() |
---|
| 614 | self.Show(True) |
---|
| 615 | |
---|
| 616 | class InvariantWindow(wx.Frame): |
---|
[272d91e] | 617 | def __init__(self, parent=None, id=1,graph=None, |
---|
| 618 | data=None, title="Invariant",base=None): |
---|
[c128284] | 619 | |
---|
[272d91e] | 620 | wx.Frame.__init__(self, parent, id, title, size=(PANEL_WIDTH, |
---|
[c128284] | 621 | PANEL_HEIGHT)) |
---|
| 622 | |
---|
[272d91e] | 623 | self.panel = InvariantPanel(self) |
---|
[c128284] | 624 | self.Centre() |
---|
| 625 | self.Show(True) |
---|
| 626 | |
---|
| 627 | class MyApp(wx.App): |
---|
| 628 | def OnInit(self): |
---|
| 629 | wx.InitAllImageHandlers() |
---|
| 630 | frame = InvariantWindow() |
---|
| 631 | frame.Show(True) |
---|
| 632 | self.SetTopWindow(frame) |
---|
| 633 | |
---|
| 634 | return True |
---|
[272d91e] | 635 | |
---|
[c128284] | 636 | # end of class MyApp |
---|
| 637 | |
---|
| 638 | if __name__ == "__main__": |
---|
| 639 | app = MyApp(0) |
---|
| 640 | app.MainLoop() |
---|