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