[f3d51f6] | 1 | #!/usr/bin/env python |
---|
| 2 | |
---|
| 3 | # version |
---|
| 4 | __id__ = "$Id: aboutdialog.py 1193 2007-05-03 17:29:59Z dmitriy $" |
---|
| 5 | __revision__ = "$Revision: 1193 $" |
---|
| 6 | |
---|
| 7 | import wx |
---|
[5d98370] | 8 | import os |
---|
[ceaf16e] | 9 | import sys |
---|
| 10 | import logging |
---|
[9ff861b] | 11 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
[75df58b] | 12 | from sans.guiframe.events import StatusEvent |
---|
| 13 | from sans.guiframe.panel_base import PanelBase |
---|
[5d98370] | 14 | from inversion_state import InversionState |
---|
[3e41f43] | 15 | from pr_widgets import PrTextCtrl |
---|
| 16 | from pr_widgets import DataFileTextCtrl |
---|
| 17 | from pr_widgets import OutputTextCtrl |
---|
[f3d51f6] | 18 | |
---|
| 19 | |
---|
| 20 | |
---|
[75df58b] | 21 | class InversionControl(ScrolledPanel, PanelBase): |
---|
[7116b6e0] | 22 | """ |
---|
| 23 | """ |
---|
[f3d51f6] | 24 | window_name = 'pr_control' |
---|
| 25 | window_caption = "P(r) control panel" |
---|
| 26 | CENTER_PANE = True |
---|
| 27 | |
---|
| 28 | # Figure of merit parameters [default] |
---|
[dfb58f8] | 29 | |
---|
| 30 | ## Oscillation parameters (sin function = 1.1) |
---|
[f3d51f6] | 31 | oscillation_max = 1.5 |
---|
| 32 | |
---|
[3e41f43] | 33 | def __init__(self, parent, id=-1, plots=None, |
---|
| 34 | standalone=False, **kwargs): |
---|
[7116b6e0] | 35 | """ |
---|
| 36 | """ |
---|
[3e41f43] | 37 | ScrolledPanel.__init__(self, parent, id=id, **kwargs) |
---|
[3f0351c6] | 38 | PanelBase.__init__(self, parent) |
---|
[9ff861b] | 39 | self.SetupScrolling() |
---|
[f3d51f6] | 40 | |
---|
| 41 | self.plots = plots |
---|
| 42 | self.radio_buttons = {} |
---|
[c405c69] | 43 | self.parent = parent |
---|
[f3d51f6] | 44 | |
---|
| 45 | ## Data file TextCtrl |
---|
[a4bd2ac] | 46 | self.data_file = None |
---|
| 47 | self.plot_data = None |
---|
| 48 | self.nfunc_ctl = None |
---|
| 49 | self.alpha_ctl = None |
---|
| 50 | self.dmax_ctl = None |
---|
| 51 | self.time_ctl = None |
---|
| 52 | self.chi2_ctl = None |
---|
| 53 | self.osc_ctl = None |
---|
[f3d51f6] | 54 | self.file_radio = None |
---|
| 55 | self.plot_radio = None |
---|
[634f1cf] | 56 | self.label_sugg = None |
---|
[a4bd2ac] | 57 | self.qmin_ctl = None |
---|
| 58 | self.qmax_ctl = None |
---|
[5d98370] | 59 | self.swidth_ctl = None |
---|
| 60 | self.sheight_ctl = None |
---|
[a4bd2ac] | 61 | |
---|
| 62 | self.rg_ctl = None |
---|
| 63 | self.iq0_ctl = None |
---|
| 64 | self.bck_chk = None |
---|
| 65 | self.bck_ctl = None |
---|
[f3d51f6] | 66 | |
---|
[dfb58f8] | 67 | # TextCtrl for fraction of positive P(r) |
---|
| 68 | self.pos_ctl = None |
---|
| 69 | |
---|
| 70 | # TextCtrl for fraction of 1 sigma positive P(r) |
---|
| 71 | self.pos_err_ctl = None |
---|
| 72 | |
---|
[f3d51f6] | 73 | ## Estimates |
---|
| 74 | self.alpha_estimate_ctl = None |
---|
[35adaf6] | 75 | self.nterms_estimate_ctl = None |
---|
[a00ee4c] | 76 | ## D_max distance explorator |
---|
| 77 | self.distance_explorator_ctl = None |
---|
[f3d51f6] | 78 | ## Data manager |
---|
[6d3d5ff] | 79 | self._manager = None |
---|
[aa4b8379] | 80 | ## Standalone flage |
---|
| 81 | self.standalone = standalone |
---|
[5d98370] | 82 | ## Default file location for save |
---|
| 83 | self._default_save_location = os.getcwd() |
---|
[0ccd214] | 84 | # Default width |
---|
| 85 | self._default_width = 350 |
---|
[f3d51f6] | 86 | self._do_layout() |
---|
| 87 | |
---|
| 88 | def __setattr__(self, name, value): |
---|
| 89 | """ |
---|
[7116b6e0] | 90 | Allow direct hooks to text boxes |
---|
[f3d51f6] | 91 | """ |
---|
[3e41f43] | 92 | if name == 'nfunc': |
---|
[5d98370] | 93 | self.nfunc_ctl.SetValue(str(int(value))) |
---|
[3e41f43] | 94 | elif name == 'd_max': |
---|
[f3d51f6] | 95 | self.dmax_ctl.SetValue(str(value)) |
---|
[3e41f43] | 96 | elif name == 'alpha': |
---|
[f3d51f6] | 97 | self.alpha_ctl.SetValue(str(value)) |
---|
[3e41f43] | 98 | elif name == 'chi2': |
---|
[a4bd2ac] | 99 | self.chi2_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 100 | elif name == 'bck': |
---|
[a4bd2ac] | 101 | self.bck_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 102 | elif name == 'q_min': |
---|
[a4bd2ac] | 103 | self.qmin_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 104 | elif name == 'q_max': |
---|
[a4bd2ac] | 105 | self.qmax_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 106 | elif name == 'elapsed': |
---|
[f3d51f6] | 107 | self.time_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 108 | elif name ==' rg': |
---|
[a4bd2ac] | 109 | self.rg_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 110 | elif name == 'iq0': |
---|
[a4bd2ac] | 111 | self.iq0_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 112 | elif name == 'oscillation': |
---|
[f3d51f6] | 113 | self.osc_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 114 | elif name == 'slit_width': |
---|
[5d98370] | 115 | self.swidth_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 116 | elif name == 'slit_height': |
---|
[5d98370] | 117 | self.sheight_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 118 | elif name == 'positive': |
---|
[dfb58f8] | 119 | self.pos_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 120 | elif name == 'pos_err': |
---|
[dfb58f8] | 121 | self.pos_err_ctl.SetValue("%-5.2g" % value) |
---|
[3e41f43] | 122 | elif name == 'alpha_estimate': |
---|
[634f1cf] | 123 | self.alpha_estimate_ctl.SetToolTipString("Click to accept value.") |
---|
| 124 | self.alpha_estimate_ctl.Enable(True) |
---|
| 125 | self.alpha_estimate_ctl.SetLabel("%-3.1g" % value) |
---|
| 126 | #self.alpha_estimate_ctl.Show() |
---|
| 127 | #self.label_sugg.Show() |
---|
[3e41f43] | 128 | elif name == 'nterms_estimate': |
---|
[35adaf6] | 129 | self.nterms_estimate_ctl.SetToolTipString("Click to accept value.") |
---|
| 130 | self.nterms_estimate_ctl.Enable(True) |
---|
| 131 | self.nterms_estimate_ctl.SetLabel("%-g" % value) |
---|
[3e41f43] | 132 | elif name == 'plotname': |
---|
[0d88a09] | 133 | self.plot_data.SetValue(str(value)) |
---|
| 134 | self._on_pars_changed(None) |
---|
[3e41f43] | 135 | elif name == 'datafile': |
---|
[0d88a09] | 136 | self.plot_data.SetValue(str(value)) |
---|
| 137 | self._on_pars_changed(None) |
---|
[f3d51f6] | 138 | else: |
---|
| 139 | wx.Panel.__setattr__(self, name, value) |
---|
| 140 | |
---|
| 141 | def __getattr__(self, name): |
---|
| 142 | """ |
---|
[7116b6e0] | 143 | Allow direct hooks to text boxes |
---|
[f3d51f6] | 144 | """ |
---|
[3e41f43] | 145 | if name == 'nfunc': |
---|
[3fd1ebc] | 146 | try: |
---|
| 147 | return int(self.nfunc_ctl.GetValue()) |
---|
| 148 | except: |
---|
| 149 | return -1 |
---|
[3e41f43] | 150 | elif name == 'd_max': |
---|
[3fd1ebc] | 151 | try: |
---|
| 152 | return self.dmax_ctl.GetValue() |
---|
| 153 | except: |
---|
| 154 | return -1.0 |
---|
[3e41f43] | 155 | elif name == 'alpha': |
---|
[3fd1ebc] | 156 | try: |
---|
| 157 | return self.alpha_ctl.GetValue() |
---|
| 158 | except: |
---|
| 159 | return -1.0 |
---|
[3e41f43] | 160 | elif name == 'chi2': |
---|
[3fd1ebc] | 161 | try: |
---|
| 162 | return float(self.chi2_ctl.GetValue()) |
---|
| 163 | except: |
---|
[5d98370] | 164 | return None |
---|
[3e41f43] | 165 | elif name == 'bck': |
---|
[a4bd2ac] | 166 | try: |
---|
| 167 | return float(self.bck_ctl.GetValue()) |
---|
| 168 | except: |
---|
[5d98370] | 169 | return None |
---|
[3e41f43] | 170 | elif name == 'q_min': |
---|
[3fd1ebc] | 171 | try: |
---|
| 172 | return float(self.qmin_ctl.GetValue()) |
---|
| 173 | except: |
---|
| 174 | return 0.0 |
---|
[634f1cf] | 175 | elif name=='q_max': |
---|
[3fd1ebc] | 176 | try: |
---|
| 177 | return float(self.qmax_ctl.GetValue()) |
---|
| 178 | except: |
---|
| 179 | return 0.0 |
---|
[3e41f43] | 180 | elif name == 'elapsed': |
---|
[3fd1ebc] | 181 | try: |
---|
| 182 | return float(self.time_ctl.GetValue()) |
---|
| 183 | except: |
---|
[5d98370] | 184 | return None |
---|
[3e41f43] | 185 | elif name == 'rg': |
---|
[a4bd2ac] | 186 | try: |
---|
| 187 | return float(self.rg_ctl.GetValue()) |
---|
| 188 | except: |
---|
[5d98370] | 189 | return None |
---|
[a4bd2ac] | 190 | elif name=='iq0': |
---|
| 191 | try: |
---|
| 192 | return float(self.iq0_ctl.GetValue()) |
---|
| 193 | except: |
---|
[5d98370] | 194 | return None |
---|
[3e41f43] | 195 | elif name == 'oscillation': |
---|
[3fd1ebc] | 196 | try: |
---|
| 197 | return float(self.osc_ctl.GetValue()) |
---|
| 198 | except: |
---|
[5d98370] | 199 | return None |
---|
[3e41f43] | 200 | elif name == 'slit_width': |
---|
[5d98370] | 201 | try: |
---|
| 202 | return float(self.swidth_ctl.GetValue()) |
---|
| 203 | except: |
---|
| 204 | return None |
---|
| 205 | elif name=='slit_height': |
---|
| 206 | try: |
---|
| 207 | return float(self.sheight_ctl.GetValue()) |
---|
| 208 | except: |
---|
| 209 | return None |
---|
[3e41f43] | 210 | elif name == 'pos': |
---|
[3fd1ebc] | 211 | try: |
---|
| 212 | return float(self.pos_ctl.GetValue()) |
---|
| 213 | except: |
---|
[5d98370] | 214 | return None |
---|
[3e41f43] | 215 | elif name == 'pos_err': |
---|
[5d98370] | 216 | try: |
---|
| 217 | return float(self.pos_err_ctl.GetValue()) |
---|
| 218 | except: |
---|
| 219 | return None |
---|
[3e41f43] | 220 | elif name == 'alpha_estimate': |
---|
[5d98370] | 221 | try: |
---|
| 222 | return float(self.alpha_estimate_ctl.GetLabel()) |
---|
| 223 | except: |
---|
| 224 | return None |
---|
[3e41f43] | 225 | elif name == 'nterms_estimate': |
---|
[5d98370] | 226 | try: |
---|
| 227 | return int(self.nterms_estimate_ctl.GetLabel()) |
---|
| 228 | except: |
---|
| 229 | return None |
---|
[3e41f43] | 230 | elif name == 'plotname': |
---|
[0d88a09] | 231 | return self.plot_data.GetValue() |
---|
[3e41f43] | 232 | elif name == 'datafile': |
---|
[0d88a09] | 233 | return self.plot_data.GetValue() |
---|
[f3d51f6] | 234 | else: |
---|
[a00ee4c] | 235 | return wx.Panel.__getattribute__(self, name) |
---|
[f3d51f6] | 236 | |
---|
[3f0351c6] | 237 | def on_save(self, evt=None): |
---|
[5d98370] | 238 | """ |
---|
[7116b6e0] | 239 | Method used to create a memento of the current state |
---|
[5d98370] | 240 | |
---|
[7116b6e0] | 241 | :return: state object |
---|
[5d98370] | 242 | """ |
---|
| 243 | # Ask the user the location of the file to write to. |
---|
| 244 | path = None |
---|
[3e41f43] | 245 | dlg = wx.FileDialog(self, "Choose a file", |
---|
| 246 | self._default_save_location, "", "*.prv", wx.SAVE) |
---|
[5d98370] | 247 | if dlg.ShowModal() == wx.ID_OK: |
---|
| 248 | path = dlg.GetPath() |
---|
| 249 | self._default_save_location = os.path.dirname(path) |
---|
[0d88a09] | 250 | else: |
---|
| 251 | return None |
---|
| 252 | |
---|
[5d98370] | 253 | dlg.Destroy() |
---|
[b35d3d1] | 254 | |
---|
| 255 | state = self.get_state() |
---|
| 256 | |
---|
[6d3d5ff] | 257 | self._manager.save_data(filepath=path, prstate=state) |
---|
[b35d3d1] | 258 | |
---|
| 259 | return state |
---|
| 260 | |
---|
[6d3d5ff] | 261 | def get_data(self): |
---|
| 262 | """ |
---|
| 263 | """ |
---|
| 264 | return self._manager.get_data() |
---|
| 265 | |
---|
[b35d3d1] | 266 | def get_state(self): |
---|
| 267 | """ |
---|
| 268 | Get the current state |
---|
| 269 | |
---|
| 270 | : return: state object |
---|
| 271 | """ |
---|
[5d98370] | 272 | # Construct the state object |
---|
| 273 | state = InversionState() |
---|
| 274 | |
---|
| 275 | # Read the panel's parameters |
---|
| 276 | flag, alpha, dmax, nfunc, qmin, \ |
---|
| 277 | qmax, height, width = self._read_pars() |
---|
| 278 | |
---|
| 279 | state.nfunc = nfunc |
---|
| 280 | state.d_max = dmax |
---|
| 281 | state.alpha = alpha |
---|
| 282 | state.qmin = qmin |
---|
| 283 | state.qmax = qmax |
---|
| 284 | state.width = width |
---|
| 285 | state.height = height |
---|
| 286 | |
---|
| 287 | # Data file |
---|
[0d88a09] | 288 | state.file = self.plot_data.GetValue() |
---|
[5d98370] | 289 | |
---|
| 290 | # Background evaluation checkbox |
---|
| 291 | state.estimate_bck = self.bck_chk.IsChecked() |
---|
| 292 | |
---|
| 293 | # Estimates |
---|
| 294 | state.nterms_estimate = self.nterms_estimate |
---|
| 295 | state.alpha_estimate = self.alpha_estimate |
---|
| 296 | |
---|
| 297 | # Read the output values |
---|
| 298 | state.chi2 = self.chi2 |
---|
| 299 | state.elapsed = self.elapsed |
---|
| 300 | state.osc = self.oscillation |
---|
| 301 | state.pos = self.pos |
---|
| 302 | state.pos_err = self.pos_err |
---|
| 303 | state.rg = self.rg |
---|
| 304 | state.iq0 = self.iq0 |
---|
| 305 | state.bck = self.bck |
---|
[fde249c] | 306 | |
---|
[5d98370] | 307 | return state |
---|
| 308 | |
---|
| 309 | def set_state(self, state): |
---|
| 310 | """ |
---|
[7116b6e0] | 311 | Set the state of the panel and inversion problem to |
---|
| 312 | the state passed as a parameter. |
---|
| 313 | Execute the inversion immediately after filling the |
---|
| 314 | controls. |
---|
| 315 | |
---|
| 316 | :param state: InversionState object |
---|
[5d98370] | 317 | """ |
---|
[fde249c] | 318 | if state.nfunc is not None: |
---|
| 319 | self.nfunc = state.nfunc |
---|
| 320 | if state.d_max is not None: |
---|
| 321 | self.d_max = state.d_max |
---|
| 322 | if state.alpha is not None: |
---|
| 323 | self.alpha = state.alpha |
---|
| 324 | if state.qmin is not None: |
---|
| 325 | self.q_min = state.qmin |
---|
| 326 | if state.qmax is not None: |
---|
| 327 | self.q_max = state.qmax |
---|
| 328 | if state.width is not None: |
---|
| 329 | self.slit_width = state.width |
---|
| 330 | if state.height is not None: |
---|
| 331 | self.slit_height = state.height |
---|
[5d98370] | 332 | |
---|
| 333 | # Data file |
---|
[0d88a09] | 334 | self.plot_data.SetValue(str(state.file)) |
---|
[5d98370] | 335 | |
---|
| 336 | # Background evaluation checkbox |
---|
| 337 | self.bck_chk.SetValue(state.estimate_bck) |
---|
| 338 | |
---|
| 339 | # Estimates |
---|
[fde249c] | 340 | if state.nterms_estimate is not None: |
---|
| 341 | self.nterms_estimate = state.nterms_estimate |
---|
| 342 | if state.alpha_estimate is not None: |
---|
| 343 | self.alpha_estimate = state.alpha_estimate |
---|
[5d98370] | 344 | |
---|
| 345 | |
---|
| 346 | # Read the output values |
---|
[fde249c] | 347 | if state.chi2 is not None: |
---|
| 348 | self.chi2 = state.chi2 |
---|
| 349 | if state.elapsed is not None: |
---|
| 350 | self.elapsed = state.elapsed |
---|
| 351 | if state.osc is not None: |
---|
| 352 | self.oscillation = state.osc |
---|
| 353 | if state.pos is not None: |
---|
| 354 | self.positive = state.pos |
---|
| 355 | if state.pos_err is not None: |
---|
| 356 | self.pos_err = state.pos_err |
---|
| 357 | if state.rg is not None: |
---|
| 358 | self.rg = state.rg |
---|
| 359 | if state.iq0 is not None: |
---|
| 360 | self.iq0 = state.iq0 |
---|
| 361 | if state.bck is not None: |
---|
| 362 | self.bck = state.bck |
---|
[5d98370] | 363 | |
---|
[0d88a09] | 364 | # Perform inversion |
---|
[dd03efb] | 365 | self._on_invert(None) |
---|
[5d98370] | 366 | |
---|
[f3d51f6] | 367 | def set_manager(self, manager): |
---|
[6d3d5ff] | 368 | self._manager = manager |
---|
[f3d51f6] | 369 | |
---|
| 370 | def _do_layout(self): |
---|
[4318af7f] | 371 | vbox = wx.GridBagSizer(0,0) |
---|
| 372 | iy_vb = 0 |
---|
[f3d51f6] | 373 | |
---|
| 374 | # ----- I(q) data ----- |
---|
[aa4b8379] | 375 | databox = wx.StaticBox(self, -1, "I(q) data source") |
---|
[f3d51f6] | 376 | |
---|
| 377 | boxsizer1 = wx.StaticBoxSizer(databox, wx.VERTICAL) |
---|
[3e41f43] | 378 | boxsizer1.SetMinSize((self._default_width, 50)) |
---|
| 379 | pars_sizer = wx.GridBagSizer(5, 5) |
---|
[0d21ac1] | 380 | |
---|
[f3d51f6] | 381 | iy = 0 |
---|
[d2ee6f6] | 382 | self.file_radio = wx.StaticText(self, -1, "Data:") |
---|
[3e41f43] | 383 | pars_sizer.Add(self.file_radio, (iy, 0), (1, 1), |
---|
| 384 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[f3d51f6] | 385 | |
---|
[9ff861b] | 386 | self.plot_data = DataFileTextCtrl(self, -1, size=(260,20)) |
---|
| 387 | |
---|
[3e41f43] | 388 | pars_sizer.Add(self.plot_data, (iy, 1), (1, 1), |
---|
| 389 | wx.EXPAND|wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 15) |
---|
[f3d51f6] | 390 | |
---|
[a4bd2ac] | 391 | self.bck_chk = wx.CheckBox(self, -1, "Estimate background level") |
---|
[3e41f43] | 392 | hint_msg = "Check box to let the fit estimate " |
---|
| 393 | hint_msg += "the constant background level." |
---|
| 394 | self.bck_chk.SetToolTipString(hint_msg) |
---|
[a4bd2ac] | 395 | self.bck_chk.Bind(wx.EVT_CHECKBOX, self._on_pars_changed) |
---|
| 396 | iy += 1 |
---|
[3e41f43] | 397 | pars_sizer.Add(self.bck_chk, (iy, 0), (1, 2), |
---|
| 398 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
[a4bd2ac] | 399 | boxsizer1.Add(pars_sizer, 0, wx.EXPAND) |
---|
[3e41f43] | 400 | vbox.Add(boxsizer1, (iy_vb, 0), (1, 1), |
---|
| 401 | wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE|wx.TOP, 5) |
---|
[a4bd2ac] | 402 | |
---|
| 403 | # ----- Add slit parameters ----- |
---|
[2a92852] | 404 | if True: |
---|
[a4bd2ac] | 405 | sbox = wx.StaticBox(self, -1, "Slit parameters") |
---|
| 406 | sboxsizer = wx.StaticBoxSizer(sbox, wx.VERTICAL) |
---|
[3e41f43] | 407 | sboxsizer.SetMinSize((self._default_width, 20)) |
---|
[a4bd2ac] | 408 | |
---|
[3e41f43] | 409 | sizer_slit = wx.GridBagSizer(5, 5) |
---|
[a4bd2ac] | 410 | |
---|
[3e41f43] | 411 | label_sheight = wx.StaticText(self, -1, "Height", size=(40, 20)) |
---|
| 412 | label_swidth = wx.StaticText(self, -1, "Width", size=(40, 20)) |
---|
[a4bd2ac] | 413 | #label_sunits1 = wx.StaticText(self, -1, "[A^(-1)]") |
---|
[4318af7f] | 414 | label_sunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55,20)) |
---|
[3e41f43] | 415 | self.sheight_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, |
---|
| 416 | size=(60,20)) |
---|
| 417 | self.swidth_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, |
---|
| 418 | size=(60,20)) |
---|
| 419 | hint_msg = "Enter slit height in units of Q or leave blank." |
---|
| 420 | self.sheight_ctl.SetToolTipString(hint_msg) |
---|
| 421 | hint_msg = "Enter slit width in units of Q or leave blank." |
---|
| 422 | self.swidth_ctl.SetToolTipString(hint_msg) |
---|
[2a92852] | 423 | #self.sheight_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) |
---|
| 424 | #self.swidth_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) |
---|
[a4bd2ac] | 425 | |
---|
| 426 | iy = 0 |
---|
[3e41f43] | 427 | sizer_slit.Add(label_sheight, (iy, 0), (1, 1), |
---|
| 428 | wx.LEFT|wx.EXPAND, 5) |
---|
| 429 | sizer_slit.Add(self.sheight_ctl, (iy, 1), (1, 1), |
---|
| 430 | wx.LEFT|wx.EXPAND, 5) |
---|
| 431 | |
---|
| 432 | sizer_slit.Add(label_swidth, (iy, 2), (1, 1), |
---|
| 433 | wx.LEFT|wx.EXPAND, 5) |
---|
| 434 | sizer_slit.Add(self.swidth_ctl, (iy, 3), (1, 1), |
---|
| 435 | wx.LEFT|wx.EXPAND, 5) |
---|
| 436 | sizer_slit.Add(label_sunits2, (iy, 4), (1, 1), |
---|
| 437 | wx.LEFT|wx.EXPAND, 5) |
---|
[a4bd2ac] | 438 | |
---|
| 439 | sboxsizer.Add(sizer_slit, wx.TOP, 15) |
---|
[4318af7f] | 440 | iy_vb += 1 |
---|
[3e41f43] | 441 | vbox.Add(sboxsizer, (iy_vb, 0), (1, 1), |
---|
| 442 | wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[a4bd2ac] | 443 | |
---|
[357b79b] | 444 | |
---|
| 445 | # ----- Q range ----- |
---|
| 446 | qbox = wx.StaticBox(self, -1, "Q range") |
---|
| 447 | qboxsizer = wx.StaticBoxSizer(qbox, wx.VERTICAL) |
---|
[3e41f43] | 448 | qboxsizer.SetMinSize((self._default_width, 20)) |
---|
[357b79b] | 449 | |
---|
[3e41f43] | 450 | sizer_q = wx.GridBagSizer(5, 5) |
---|
[357b79b] | 451 | |
---|
[3e41f43] | 452 | label_qmin = wx.StaticText(self, -1, "Q min", size=(40, 20)) |
---|
| 453 | label_qmax = wx.StaticText(self, -1, "Q max", size=(40, 20)) |
---|
[357b79b] | 454 | #label_qunits1 = wx.StaticText(self, -1, "[A^(-1)]") |
---|
[3e41f43] | 455 | label_qunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55, 20)) |
---|
| 456 | self.qmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, |
---|
| 457 | size=(60,20)) |
---|
| 458 | self.qmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, |
---|
| 459 | size=(60,20)) |
---|
| 460 | hint_msg = "Select a lower bound for Q or leave blank." |
---|
| 461 | self.qmin_ctl.SetToolTipString(hint_msg) |
---|
| 462 | hint_msg = "Select an upper bound for Q or leave blank." |
---|
| 463 | self.qmax_ctl.SetToolTipString(hint_msg) |
---|
[357b79b] | 464 | self.qmin_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) |
---|
| 465 | self.qmax_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) |
---|
| 466 | |
---|
| 467 | iy = 0 |
---|
[3e41f43] | 468 | sizer_q.Add(label_qmin, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 5) |
---|
| 469 | sizer_q.Add(self.qmin_ctl, (iy, 1), (1, 1), wx.LEFT|wx.EXPAND, 5) |
---|
[357b79b] | 470 | #sizer_q.Add(label_qunits1, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 15) |
---|
[3e41f43] | 471 | sizer_q.Add(label_qmax, (iy, 2), (1, 1), wx.LEFT|wx.EXPAND, 5) |
---|
| 472 | sizer_q.Add(self.qmax_ctl, (iy, 3), (1, 1), wx.LEFT|wx.EXPAND, 5) |
---|
| 473 | sizer_q.Add(label_qunits2, (iy, 4), (1, 1), wx.LEFT|wx.EXPAND, 5) |
---|
[357b79b] | 474 | qboxsizer.Add(sizer_q, wx.TOP, 15) |
---|
[4318af7f] | 475 | |
---|
| 476 | iy_vb += 1 |
---|
[3e41f43] | 477 | vbox.Add(qboxsizer, (iy_vb,0), (1,1), |
---|
| 478 | wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
| 479 | |
---|
[f3d51f6] | 480 | # ----- Parameters ----- |
---|
| 481 | parsbox = wx.StaticBox(self, -1, "Parameters") |
---|
| 482 | boxsizer2 = wx.StaticBoxSizer(parsbox, wx.VERTICAL) |
---|
[0ccd214] | 483 | boxsizer2.SetMinSize((self._default_width,50)) |
---|
[f3d51f6] | 484 | |
---|
[3e41f43] | 485 | explanation = "P(r) is found by fitting a set of base functions" |
---|
| 486 | explanation += " to I(Q). The minimization involves" |
---|
| 487 | explanation += " a regularization term to ensure a smooth P(r)." |
---|
| 488 | explanation += " The regularization constant gives the size of that " |
---|
| 489 | explanation += "term. The suggested value is the value above which the" |
---|
| 490 | explanation += " output P(r) will have only one peak." |
---|
[0ccd214] | 491 | label_explain = wx.StaticText(self, -1, explanation, size=(280,120)) |
---|
[32dffae4] | 492 | boxsizer2.Add(label_explain, wx.LEFT|wx.BOTTOM, 5) |
---|
| 493 | |
---|
| 494 | |
---|
| 495 | |
---|
[f3d51f6] | 496 | label_nfunc = wx.StaticText(self, -1, "Number of terms") |
---|
[3e41f43] | 497 | label_nfunc.SetMinSize((120, 20)) |
---|
[f3d51f6] | 498 | label_alpha = wx.StaticText(self, -1, "Regularization constant") |
---|
| 499 | label_dmax = wx.StaticText(self, -1, "Max distance [A]") |
---|
[634f1cf] | 500 | self.label_sugg = wx.StaticText(self, -1, "Suggested value") |
---|
| 501 | #self.label_sugg.Hide() |
---|
[f3d51f6] | 502 | |
---|
[3e41f43] | 503 | self.nfunc_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, |
---|
| 504 | size=(60,20)) |
---|
[32dffae4] | 505 | self.nfunc_ctl.SetToolTipString("Number of terms in the expansion.") |
---|
[3e41f43] | 506 | self.alpha_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, |
---|
| 507 | size=(60,20)) |
---|
| 508 | hint_msg = "Control parameter for the size of the regularization term." |
---|
| 509 | self.alpha_ctl.SetToolTipString(hint_msg) |
---|
| 510 | self.dmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, |
---|
| 511 | size=(60,20)) |
---|
| 512 | hint_msg = "Maximum distance between any two points in the system." |
---|
| 513 | self.dmax_ctl.SetToolTipString(hint_msg) |
---|
[634f1cf] | 514 | id = wx.NewId() |
---|
| 515 | self.alpha_estimate_ctl = wx.Button(self, id, "") |
---|
| 516 | #self.alpha_estimate_ctl.Hide() |
---|
| 517 | self.Bind(wx.EVT_BUTTON, self._on_accept_alpha, id = id) |
---|
[f3d51f6] | 518 | self.alpha_estimate_ctl.Enable(False) |
---|
[634f1cf] | 519 | #self.alpha_estimate_ctl.SetBackgroundColour('#ffdf85') |
---|
| 520 | #self.alpha_estimate_ctl.SetBackgroundColour(self.GetBackgroundColour()) |
---|
| 521 | self.alpha_estimate_ctl.SetToolTipString("Waiting for estimate...") |
---|
[f3d51f6] | 522 | |
---|
[35adaf6] | 523 | id = wx.NewId() |
---|
| 524 | self.nterms_estimate_ctl = wx.Button(self, id, "") |
---|
| 525 | #self.nterms_estimate_ctl.Hide() |
---|
| 526 | self.Bind(wx.EVT_BUTTON, self._on_accept_nterms, id = id) |
---|
| 527 | self.nterms_estimate_ctl.Enable(False) |
---|
[3e41f43] | 528 | |
---|
[35adaf6] | 529 | self.nterms_estimate_ctl.SetToolTipString("Waiting for estimate...") |
---|
| 530 | |
---|
[d6113849] | 531 | self.nfunc_ctl.Bind(wx.EVT_TEXT, self._read_pars) |
---|
[a4bd2ac] | 532 | self.alpha_ctl.Bind(wx.EVT_TEXT, self._read_pars) |
---|
| 533 | self.dmax_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) |
---|
| 534 | |
---|
[a00ee4c] | 535 | # Distance explorator |
---|
| 536 | id = wx.NewId() |
---|
| 537 | self.distance_explorator_ctl = wx.Button(self, id, "Explore") |
---|
| 538 | self.Bind(wx.EVT_BUTTON, self._on_explore, id = id) |
---|
[a4bd2ac] | 539 | |
---|
| 540 | |
---|
[f3d51f6] | 541 | sizer_params = wx.GridBagSizer(5,5) |
---|
| 542 | |
---|
| 543 | iy = 0 |
---|
[3e41f43] | 544 | sizer_params.Add(self.label_sugg, (iy, 2), (1, 1), wx.LEFT, 15) |
---|
[f3d51f6] | 545 | iy += 1 |
---|
[3e41f43] | 546 | sizer_params.Add(label_nfunc, (iy, 0), (1, 1), wx.LEFT, 15) |
---|
| 547 | sizer_params.Add(self.nfunc_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) |
---|
| 548 | sizer_params.Add(self.nterms_estimate_ctl, (iy, 2), (1, 1), wx.LEFT, 15) |
---|
[f3d51f6] | 549 | iy += 1 |
---|
[3e41f43] | 550 | sizer_params.Add(label_alpha, (iy, 0), (1, 1), wx.LEFT, 15) |
---|
| 551 | sizer_params.Add(self.alpha_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) |
---|
| 552 | sizer_params.Add(self.alpha_estimate_ctl, (iy, 2), (1, 1), wx.LEFT, 15) |
---|
[f3d51f6] | 553 | iy += 1 |
---|
[3e41f43] | 554 | sizer_params.Add(label_dmax, (iy, 0), (1, 1), wx.LEFT, 15) |
---|
| 555 | sizer_params.Add(self.dmax_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) |
---|
| 556 | sizer_params.Add(self.distance_explorator_ctl, (iy, 2), |
---|
| 557 | (1, 1), wx.LEFT, 15) |
---|
[f3d51f6] | 558 | |
---|
| 559 | boxsizer2.Add(sizer_params, 0) |
---|
[634f1cf] | 560 | |
---|
[4318af7f] | 561 | iy_vb += 1 |
---|
[3e41f43] | 562 | vbox.Add(boxsizer2, (iy_vb, 0), (1, 1), |
---|
| 563 | wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[f3d51f6] | 564 | |
---|
[634f1cf] | 565 | |
---|
[f3d51f6] | 566 | # ----- Results ----- |
---|
| 567 | resbox = wx.StaticBox(self, -1, "Outputs") |
---|
| 568 | ressizer = wx.StaticBoxSizer(resbox, wx.VERTICAL) |
---|
[3e41f43] | 569 | ressizer.SetMinSize((self._default_width, 50)) |
---|
[f3d51f6] | 570 | |
---|
[a4bd2ac] | 571 | label_rg = wx.StaticText(self, -1, "Rg") |
---|
| 572 | label_rg_unit = wx.StaticText(self, -1, "[A]") |
---|
| 573 | label_iq0 = wx.StaticText(self, -1, "I(Q=0)") |
---|
| 574 | label_iq0_unit = wx.StaticText(self, -1, "[A^(-1)]") |
---|
| 575 | label_bck = wx.StaticText(self, -1, "Background") |
---|
| 576 | label_bck_unit = wx.StaticText(self, -1, "[A^(-1)]") |
---|
[9ff861b] | 577 | self.rg_ctl = OutputTextCtrl(self, -1, size=(60,20)) |
---|
[3e41f43] | 578 | hint_msg = "Radius of gyration for the computed P(r)." |
---|
| 579 | self.rg_ctl.SetToolTipString(hint_msg) |
---|
[75df58b] | 580 | self.iq0_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 581 | hint_msg = "Scattering intensity at Q=0 for the computed P(r)." |
---|
| 582 | self.iq0_ctl.SetToolTipString(hint_msg) |
---|
[75df58b] | 583 | self.bck_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[a4bd2ac] | 584 | self.bck_ctl.SetToolTipString("Value of estimated constant background.") |
---|
| 585 | |
---|
[f3d51f6] | 586 | label_time = wx.StaticText(self, -1, "Computation time") |
---|
| 587 | label_time_unit = wx.StaticText(self, -1, "secs") |
---|
| 588 | label_time.SetMinSize((120,20)) |
---|
| 589 | label_chi2 = wx.StaticText(self, -1, "Chi2/dof") |
---|
| 590 | label_osc = wx.StaticText(self, -1, "Oscillations") |
---|
[dfb58f8] | 591 | label_pos = wx.StaticText(self, -1, "Positive fraction") |
---|
| 592 | label_pos_err = wx.StaticText(self, -1, "1-sigma positive fraction") |
---|
[f3d51f6] | 593 | |
---|
[75df58b] | 594 | self.time_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 595 | hint_msg = "Computation time for the last inversion, in seconds." |
---|
| 596 | self.time_ctl.SetToolTipString(hint_msg) |
---|
[32dffae4] | 597 | |
---|
[75df58b] | 598 | self.chi2_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[32dffae4] | 599 | self.chi2_ctl.SetToolTipString("Chi^2 over degrees of freedom.") |
---|
| 600 | |
---|
[dfb58f8] | 601 | # Oscillation parameter |
---|
[75df58b] | 602 | self.osc_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 603 | hint_msg = "Oscillation parameter. P(r) for a sphere has an " |
---|
| 604 | hint_msg += " oscillation parameter of 1.1." |
---|
| 605 | self.osc_ctl.SetToolTipString(hint_msg) |
---|
[f3d51f6] | 606 | |
---|
[dfb58f8] | 607 | # Positive fraction figure of merit |
---|
[75df58b] | 608 | self.pos_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 609 | hint_msg = "Fraction of P(r) that is positive. " |
---|
| 610 | hint_msg += "Theoretically, P(r) is defined positive." |
---|
| 611 | self.pos_ctl.SetToolTipString(hint_msg) |
---|
[dfb58f8] | 612 | |
---|
| 613 | # 1-simga positive fraction figure of merit |
---|
[75df58b] | 614 | self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 615 | message = "Fraction of P(r) that is at least 1 standard deviation" |
---|
| 616 | message += " greater than zero.\n" |
---|
| 617 | message += "This figure of merit tells you about the size of the " |
---|
| 618 | message += "P(r) errors.\n" |
---|
| 619 | message += "If it is close to 1 and the other figures of merit are bad," |
---|
| 620 | message += " consider changing the maximum distance." |
---|
[dfb58f8] | 621 | self.pos_err_ctl.SetToolTipString(message) |
---|
| 622 | |
---|
[3e41f43] | 623 | sizer_res = wx.GridBagSizer(5, 5) |
---|
[f3d51f6] | 624 | |
---|
| 625 | iy = 0 |
---|
[3e41f43] | 626 | sizer_res.Add(label_rg, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) |
---|
| 627 | sizer_res.Add(self.rg_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
| 628 | sizer_res.Add(label_rg_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
[a4bd2ac] | 629 | iy += 1 |
---|
[3e41f43] | 630 | sizer_res.Add(label_iq0, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) |
---|
| 631 | sizer_res.Add(self.iq0_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
| 632 | sizer_res.Add(label_iq0_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
[a4bd2ac] | 633 | iy += 1 |
---|
[3e41f43] | 634 | sizer_res.Add(label_bck, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) |
---|
| 635 | sizer_res.Add(self.bck_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
| 636 | sizer_res.Add(label_bck_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
[a4bd2ac] | 637 | iy += 1 |
---|
[3e41f43] | 638 | sizer_res.Add(label_time, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) |
---|
| 639 | sizer_res.Add(self.time_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
| 640 | sizer_res.Add(label_time_unit, (iy, 2), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
[f3d51f6] | 641 | iy += 1 |
---|
[3e41f43] | 642 | sizer_res.Add(label_chi2, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) |
---|
| 643 | sizer_res.Add(self.chi2_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
[f3d51f6] | 644 | iy += 1 |
---|
[3e41f43] | 645 | sizer_res.Add(label_osc, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) |
---|
| 646 | sizer_res.Add(self.osc_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
[f3d51f6] | 647 | |
---|
[dfb58f8] | 648 | iy += 1 |
---|
[3e41f43] | 649 | sizer_res.Add(label_pos, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) |
---|
| 650 | sizer_res.Add(self.pos_ctl, (iy, 1), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
[dfb58f8] | 651 | |
---|
| 652 | iy += 1 |
---|
[3e41f43] | 653 | sizer_res.Add(label_pos_err, (iy, 0), (1, 1), wx.LEFT|wx.EXPAND, 15) |
---|
| 654 | sizer_res.Add(self.pos_err_ctl, (iy,1), (1, 1), wx.RIGHT|wx.EXPAND, 15) |
---|
[dfb58f8] | 655 | |
---|
[f3d51f6] | 656 | ressizer.Add(sizer_res, 0) |
---|
[4318af7f] | 657 | iy_vb += 1 |
---|
[3e41f43] | 658 | vbox.Add(ressizer, (iy_vb, 0), (1, 1), |
---|
| 659 | wx.LEFT|wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 5) |
---|
[f3d51f6] | 660 | |
---|
| 661 | # ----- Buttons ----- |
---|
| 662 | id = wx.NewId() |
---|
| 663 | button_OK = wx.Button(self, id, "Compute") |
---|
[32dffae4] | 664 | button_OK.SetToolTipString("Perform P(r) inversion.") |
---|
[f3d51f6] | 665 | self.Bind(wx.EVT_BUTTON, self._on_invert, id = id) |
---|
[b659551] | 666 | |
---|
[5771ea3] | 667 | self._set_reset_flag(True) |
---|
[3f0351c6] | 668 | self._set_save_flag(True) |
---|
[f3d51f6] | 669 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 670 | sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 671 | sizer_button.Add(button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) |
---|
[3e41f43] | 672 | |
---|
[4318af7f] | 673 | iy_vb += 1 |
---|
[3e41f43] | 674 | vbox.Add(sizer_button, (iy_vb, 0), (1, 1), |
---|
| 675 | wx.EXPAND|wx.BOTTOM|wx.TOP|wx.RIGHT, 10) |
---|
[f3d51f6] | 676 | |
---|
[a00ee4c] | 677 | self.Bind(wx.EVT_TEXT_ENTER, self._on_invert) |
---|
[f3d51f6] | 678 | |
---|
| 679 | self.SetSizer(vbox) |
---|
| 680 | |
---|
[634f1cf] | 681 | def _on_accept_alpha(self, evt): |
---|
| 682 | """ |
---|
[7116b6e0] | 683 | User has accepted the estimated alpha, |
---|
| 684 | set it as part of the input parameters |
---|
[634f1cf] | 685 | """ |
---|
| 686 | try: |
---|
| 687 | alpha = self.alpha_estimate_ctl.GetLabel() |
---|
| 688 | tmp = float(alpha) |
---|
| 689 | self.alpha_ctl.SetValue(alpha) |
---|
| 690 | except: |
---|
| 691 | # No estimate or bad estimate, either do nothing |
---|
[3e41f43] | 692 | #import sys |
---|
[634f1cf] | 693 | print "InversionControl._on_accept_alpha: %s" % sys.exc_value |
---|
| 694 | pass |
---|
[35adaf6] | 695 | |
---|
| 696 | def _on_accept_nterms(self, evt): |
---|
| 697 | """ |
---|
[7116b6e0] | 698 | User has accepted the estimated number of terms, |
---|
| 699 | set it as part of the input parameters |
---|
[35adaf6] | 700 | """ |
---|
| 701 | try: |
---|
| 702 | nterms = self.nterms_estimate_ctl.GetLabel() |
---|
| 703 | tmp = float(nterms) |
---|
| 704 | self.nfunc_ctl.SetValue(nterms) |
---|
| 705 | except: |
---|
| 706 | # No estimate or bad estimate, either do nothing |
---|
| 707 | import sys |
---|
| 708 | print "InversionControl._on_accept_nterms: %s" % sys.exc_value |
---|
| 709 | pass |
---|
[634f1cf] | 710 | |
---|
[5771ea3] | 711 | def on_reset(self, event): |
---|
[b659551] | 712 | """ |
---|
[7116b6e0] | 713 | Resets inversion parameters |
---|
[b659551] | 714 | """ |
---|
[6d3d5ff] | 715 | self.nfunc = self._manager.DEFAULT_NFUNC |
---|
| 716 | self.d_max = self._manager.DEFAULT_DMAX |
---|
| 717 | self.alpha = self._manager.DEFAULT_ALPHA |
---|
[b659551] | 718 | self.qmin_ctl.SetValue("") |
---|
| 719 | self.qmax_ctl.SetValue("") |
---|
| 720 | self.time_ctl.SetValue("") |
---|
[a4bd2ac] | 721 | self.rg_ctl.SetValue("") |
---|
| 722 | self.iq0_ctl.SetValue("") |
---|
| 723 | self.bck_ctl.SetValue("") |
---|
[b659551] | 724 | self.chi2_ctl.SetValue("") |
---|
| 725 | self.osc_ctl.SetValue("") |
---|
| 726 | self.pos_ctl.SetValue("") |
---|
| 727 | self.pos_err_ctl.SetValue("") |
---|
| 728 | self.alpha_estimate_ctl.Enable(False) |
---|
| 729 | self.alpha_estimate_ctl.SetLabel("") |
---|
[35adaf6] | 730 | self.nterms_estimate_ctl.Enable(False) |
---|
| 731 | self.nterms_estimate_ctl.SetLabel("") |
---|
[b659551] | 732 | self._on_pars_changed() |
---|
[634f1cf] | 733 | |
---|
[b659551] | 734 | def _on_pars_changed(self, evt=None): |
---|
[f3d51f6] | 735 | """ |
---|
[7116b6e0] | 736 | Called when an input parameter has changed |
---|
| 737 | We will estimate the alpha parameter behind the |
---|
| 738 | scenes. |
---|
[f3d51f6] | 739 | """ |
---|
[2a92852] | 740 | flag, alpha, dmax, nfunc, qmin, qmax, height, width = self._read_pars() |
---|
[a4bd2ac] | 741 | has_bck = self.bck_chk.IsChecked() |
---|
[f3d51f6] | 742 | |
---|
| 743 | # If the pars are valid, estimate alpha |
---|
| 744 | if flag: |
---|
[2a92852] | 745 | self.nterms_estimate_ctl.Enable(False) |
---|
| 746 | self.alpha_estimate_ctl.Enable(False) |
---|
| 747 | |
---|
[0d88a09] | 748 | dataset = self.plot_data.GetValue() |
---|
[6d3d5ff] | 749 | self._manager.estimate_plot_inversion(alpha=alpha, nfunc=nfunc, |
---|
[0d88a09] | 750 | d_max=dmax, |
---|
| 751 | q_min=qmin, q_max=qmax, |
---|
| 752 | bck=has_bck, |
---|
| 753 | height=height, |
---|
| 754 | width=width) |
---|
[f3d51f6] | 755 | |
---|
[7116b6e0] | 756 | def _read_pars(self, evt=None): |
---|
| 757 | """ |
---|
| 758 | """ |
---|
[f3d51f6] | 759 | alpha = 0 |
---|
| 760 | nfunc = 5 |
---|
| 761 | dmax = 120 |
---|
[3fd1ebc] | 762 | qmin = 0 |
---|
| 763 | qmax = 0 |
---|
[2a92852] | 764 | height = 0 |
---|
| 765 | width = 0 |
---|
[f3d51f6] | 766 | flag = True |
---|
[2a92852] | 767 | # Read slit height |
---|
| 768 | try: |
---|
| 769 | height_str = self.sheight_ctl.GetValue() |
---|
[3e41f43] | 770 | if len(height_str.lstrip().rstrip()) == 0: |
---|
[2a92852] | 771 | height = 0 |
---|
| 772 | else: |
---|
| 773 | height = float(height_str) |
---|
| 774 | self.sheight_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 775 | self.sheight_ctl.Refresh() |
---|
| 776 | except: |
---|
| 777 | flag = False |
---|
| 778 | self.sheight_ctl.SetBackgroundColour("pink") |
---|
| 779 | self.sheight_ctl.Refresh() |
---|
| 780 | |
---|
| 781 | # Read slit width |
---|
| 782 | try: |
---|
| 783 | width_str = self.swidth_ctl.GetValue() |
---|
| 784 | if len(width_str.lstrip().rstrip())==0: |
---|
| 785 | width = 0 |
---|
| 786 | else: |
---|
| 787 | width = float(width_str) |
---|
| 788 | self.swidth_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 789 | self.swidth_ctl.Refresh() |
---|
| 790 | except: |
---|
| 791 | flag = False |
---|
| 792 | self.swidth_ctl.SetBackgroundColour("pink") |
---|
| 793 | self.swidth_ctl.Refresh() |
---|
| 794 | |
---|
[f3d51f6] | 795 | # Read alpha |
---|
| 796 | try: |
---|
| 797 | alpha = float(self.alpha_ctl.GetValue()) |
---|
| 798 | self.alpha_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 799 | self.alpha_ctl.Refresh() |
---|
| 800 | except: |
---|
| 801 | flag = False |
---|
| 802 | self.alpha_ctl.SetBackgroundColour("pink") |
---|
| 803 | self.alpha_ctl.Refresh() |
---|
| 804 | |
---|
| 805 | # Read d_max |
---|
| 806 | try: |
---|
| 807 | dmax = float(self.dmax_ctl.GetValue()) |
---|
| 808 | self.dmax_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 809 | self.dmax_ctl.Refresh() |
---|
| 810 | except: |
---|
| 811 | flag = False |
---|
| 812 | self.dmax_ctl.SetBackgroundColour("pink") |
---|
| 813 | self.dmax_ctl.Refresh() |
---|
| 814 | |
---|
| 815 | # Read nfunc |
---|
| 816 | try: |
---|
| 817 | nfunc = int(self.nfunc_ctl.GetValue()) |
---|
[6d3d5ff] | 818 | npts = self._manager.get_npts() |
---|
[3e41f43] | 819 | if npts > 0 and nfunc > npts: |
---|
| 820 | message = "Number of function terms should be smaller " |
---|
| 821 | message += "than the number of points" |
---|
[6d3d5ff] | 822 | wx.PostEvent(self._manager.parent, StatusEvent(status=message)) |
---|
[b659551] | 823 | raise ValueError, message |
---|
[f3d51f6] | 824 | self.nfunc_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 825 | self.nfunc_ctl.Refresh() |
---|
| 826 | except: |
---|
| 827 | flag = False |
---|
| 828 | self.nfunc_ctl.SetBackgroundColour("pink") |
---|
| 829 | self.nfunc_ctl.Refresh() |
---|
| 830 | |
---|
[634f1cf] | 831 | # Read qmin |
---|
| 832 | try: |
---|
| 833 | qmin_str = self.qmin_ctl.GetValue() |
---|
[3e41f43] | 834 | if len(qmin_str.lstrip().rstrip()) == 0: |
---|
[634f1cf] | 835 | qmin = None |
---|
| 836 | else: |
---|
| 837 | qmin = float(qmin_str) |
---|
| 838 | self.qmin_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 839 | self.qmin_ctl.Refresh() |
---|
| 840 | except: |
---|
| 841 | flag = False |
---|
| 842 | self.qmin_ctl.SetBackgroundColour("pink") |
---|
| 843 | self.qmin_ctl.Refresh() |
---|
| 844 | |
---|
| 845 | # Read qmax |
---|
| 846 | try: |
---|
| 847 | qmax_str = self.qmax_ctl.GetValue() |
---|
[3e41f43] | 848 | if len(qmax_str.lstrip().rstrip()) == 0: |
---|
[634f1cf] | 849 | qmax = None |
---|
| 850 | else: |
---|
| 851 | qmax = float(qmax_str) |
---|
| 852 | self.qmax_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 853 | self.qmax_ctl.Refresh() |
---|
| 854 | except: |
---|
| 855 | flag = False |
---|
| 856 | self.qmax_ctl.SetBackgroundColour("pink") |
---|
| 857 | self.qmax_ctl.Refresh() |
---|
| 858 | |
---|
[2a92852] | 859 | return flag, alpha, dmax, nfunc, qmin, qmax, height, width |
---|
[f3d51f6] | 860 | |
---|
[a00ee4c] | 861 | def _on_explore(self, evt): |
---|
| 862 | """ |
---|
[7116b6e0] | 863 | Invoke the d_max exploration dialog |
---|
[a00ee4c] | 864 | """ |
---|
| 865 | from explore_dialog import ExploreDialog |
---|
[6d3d5ff] | 866 | if self._manager._last_pr is not None: |
---|
| 867 | pr = self._manager._create_plot_pr() |
---|
[a00ee4c] | 868 | dialog = ExploreDialog(pr, 10, None, -1, "") |
---|
| 869 | dialog.ShowModal() |
---|
| 870 | else: |
---|
| 871 | message = "No data to analyze. Please load a data set to proceed." |
---|
[6d3d5ff] | 872 | wx.PostEvent(self._manager.parent, StatusEvent(status=message)) |
---|
[a00ee4c] | 873 | |
---|
[f3d51f6] | 874 | def _on_invert(self, evt): |
---|
| 875 | """ |
---|
[7116b6e0] | 876 | Perform inversion |
---|
| 877 | |
---|
| 878 | :param silent: when True, there will be no output for the user |
---|
| 879 | |
---|
[f3d51f6] | 880 | """ |
---|
| 881 | # Get the data from the form |
---|
| 882 | # Push it to the manager |
---|
| 883 | |
---|
[2a92852] | 884 | flag, alpha, dmax, nfunc, qmin, qmax, height, width = self._read_pars() |
---|
[a4bd2ac] | 885 | has_bck = self.bck_chk.IsChecked() |
---|
[f3d51f6] | 886 | |
---|
| 887 | if flag: |
---|
[0d88a09] | 888 | dataset = self.plot_data.GetValue() |
---|
[9bc4ed23] | 889 | if dataset==None or len(dataset.strip())==0: |
---|
[3e41f43] | 890 | message = "No data to invert. Select a data set before" |
---|
| 891 | message += " proceeding with P(r) inversion." |
---|
[6d3d5ff] | 892 | wx.PostEvent(self._manager.parent, StatusEvent(status=message)) |
---|
[f3d51f6] | 893 | else: |
---|
[6d3d5ff] | 894 | self._manager.setup_plot_inversion(alpha=alpha, nfunc=nfunc, |
---|
[0d88a09] | 895 | d_max=dmax, |
---|
| 896 | q_min=qmin, q_max=qmax, |
---|
| 897 | bck=has_bck, |
---|
| 898 | height=height, |
---|
| 899 | width=width) |
---|
[f3d51f6] | 900 | else: |
---|
[3e41f43] | 901 | message = "The P(r) form contains invalid values: " |
---|
| 902 | message += "please submit it again." |
---|
[f3d51f6] | 903 | wx.PostEvent(self.parent, StatusEvent(status=message)) |
---|
| 904 | |
---|
[75df58b] | 905 | def _change_file(self, evt=None, filepath=None, data=None): |
---|
[f3d51f6] | 906 | """ |
---|
[7116b6e0] | 907 | Choose a new input file for I(q) |
---|
[f3d51f6] | 908 | """ |
---|
[6d3d5ff] | 909 | if not self._manager is None: |
---|
[75df58b] | 910 | self.plot_data.SetValue(str(data.name)) |
---|
| 911 | try: |
---|
[6d3d5ff] | 912 | self._manager.show_data(data=data, reset=True) |
---|
[75df58b] | 913 | self._on_pars_changed(None) |
---|
| 914 | self._on_invert(None) |
---|
| 915 | except: |
---|
| 916 | msg = "InversionControl._change_file: %s" % sys.exc_value |
---|
| 917 | logging.error(msg) |
---|
[119a11d] | 918 | |
---|
| 919 | class HelpDialog(wx.Dialog): |
---|
[7116b6e0] | 920 | """ |
---|
| 921 | """ |
---|
[119a11d] | 922 | def __init__(self, parent, id): |
---|
[7116b6e0] | 923 | """ |
---|
| 924 | """ |
---|
[119a11d] | 925 | from sans.pr.invertor import help |
---|
[fc4ab6e] | 926 | wx.Dialog.__init__(self, parent, id, size=(400, 420)) |
---|
[119a11d] | 927 | self.SetTitle("P(r) help") |
---|
| 928 | |
---|
| 929 | |
---|
| 930 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 931 | |
---|
| 932 | explanation = help() |
---|
| 933 | |
---|
[75df58b] | 934 | label_explain = wx.StaticText(self, -1, explanation, size=(350, 320)) |
---|
[119a11d] | 935 | |
---|
| 936 | vbox.Add(label_explain, 0, wx.ALL|wx.EXPAND, 15) |
---|
| 937 | |
---|
| 938 | |
---|
| 939 | static_line = wx.StaticLine(self, -1) |
---|
| 940 | vbox.Add(static_line, 0, wx.EXPAND, 0) |
---|
| 941 | |
---|
| 942 | button_OK = wx.Button(self, wx.ID_OK, "OK") |
---|
| 943 | #button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
---|
| 944 | |
---|
| 945 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 946 | sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 947 | sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
[3e41f43] | 948 | |
---|
[119a11d] | 949 | vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) |
---|
| 950 | |
---|
| 951 | self.SetSizer(vbox) |
---|
| 952 | self.SetAutoLayout(True) |
---|
| 953 | |
---|
| 954 | self.Layout() |
---|
| 955 | self.Centre() |
---|
| 956 | |
---|
[b659551] | 957 | class PrDistDialog(wx.Dialog): |
---|
| 958 | """ |
---|
[7116b6e0] | 959 | Property dialog to let the user change the number |
---|
| 960 | of points on the P(r) plot. |
---|
[b659551] | 961 | """ |
---|
| 962 | def __init__(self, parent, id): |
---|
| 963 | from sans.pr.invertor import help |
---|
| 964 | wx.Dialog.__init__(self, parent, id, size=(250, 120)) |
---|
| 965 | self.SetTitle("P(r) distribution") |
---|
| 966 | |
---|
| 967 | |
---|
| 968 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
| 969 | |
---|
| 970 | label_npts = wx.StaticText(self, -1, "Number of points") |
---|
[75df58b] | 971 | self.npts_ctl = PrTextCtrl(self, -1, size=(100, 20)) |
---|
[b659551] | 972 | |
---|
[75df58b] | 973 | pars_sizer = wx.GridBagSizer(5, 5) |
---|
[b659551] | 974 | iy = 0 |
---|
[75df58b] | 975 | pars_sizer.Add(label_npts, (iy, 0), (1, 1), wx.LEFT, 15) |
---|
| 976 | pars_sizer.Add(self.npts_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) |
---|
[b659551] | 977 | |
---|
| 978 | vbox.Add(pars_sizer, 0, wx.ALL|wx.EXPAND, 15) |
---|
| 979 | |
---|
| 980 | static_line = wx.StaticLine(self, -1) |
---|
| 981 | vbox.Add(static_line, 0, wx.EXPAND, 0) |
---|
| 982 | |
---|
| 983 | button_OK = wx.Button(self, wx.ID_OK, "OK") |
---|
| 984 | self.Bind(wx.EVT_BUTTON, self._checkValues, button_OK) |
---|
| 985 | button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
---|
| 986 | |
---|
| 987 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
| 988 | sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
| 989 | sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
[3e41f43] | 990 | sizer_button.Add(button_Cancel, 0, |
---|
| 991 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
[b659551] | 992 | vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) |
---|
| 993 | |
---|
| 994 | self.SetSizer(vbox) |
---|
| 995 | self.SetAutoLayout(True) |
---|
| 996 | |
---|
| 997 | self.Layout() |
---|
| 998 | self.Centre() |
---|
| 999 | |
---|
| 1000 | def _checkValues(self, event): |
---|
| 1001 | """ |
---|
[7116b6e0] | 1002 | Check the dialog content. |
---|
[b659551] | 1003 | """ |
---|
| 1004 | flag = True |
---|
| 1005 | try: |
---|
| 1006 | int(self.npts_ctl.GetValue()) |
---|
| 1007 | self.npts_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 1008 | self.npts_ctl.Refresh() |
---|
| 1009 | except: |
---|
| 1010 | flag = False |
---|
| 1011 | self.npts_ctl.SetBackgroundColour("pink") |
---|
| 1012 | self.npts_ctl.Refresh() |
---|
| 1013 | if flag: |
---|
| 1014 | event.Skip(True) |
---|
| 1015 | |
---|
| 1016 | def get_content(self): |
---|
| 1017 | """ |
---|
[7116b6e0] | 1018 | Return the content of the dialog. |
---|
| 1019 | At this point the values have already been |
---|
| 1020 | checked. |
---|
[b659551] | 1021 | """ |
---|
| 1022 | value = int(self.npts_ctl.GetValue()) |
---|
| 1023 | return value |
---|
| 1024 | |
---|
| 1025 | def set_content(self, npts): |
---|
| 1026 | """ |
---|
[7116b6e0] | 1027 | Initialize the content of the dialog. |
---|
[b659551] | 1028 | """ |
---|
| 1029 | self.npts_ctl.SetValue("%i" % npts) |
---|
| 1030 | |
---|
[f3d51f6] | 1031 | ##### testing code ############################################################ |
---|
[7116b6e0] | 1032 | """ |
---|
| 1033 | Example: :: |
---|
| 1034 | |
---|
[f3d51f6] | 1035 | class TestPlot: |
---|
| 1036 | def __init__(self, text): |
---|
| 1037 | self.name = text |
---|
| 1038 | |
---|
| 1039 | class MyApp(wx.App): |
---|
| 1040 | def OnInit(self): |
---|
| 1041 | wx.InitAllImageHandlers() |
---|
[b659551] | 1042 | dialog = PrDistDialog(None, -1) |
---|
[f3d51f6] | 1043 | if dialog.ShowModal() == wx.ID_OK: |
---|
[119a11d] | 1044 | pass |
---|
[f3d51f6] | 1045 | dialog.Destroy() |
---|
| 1046 | |
---|
| 1047 | return 1 |
---|
| 1048 | |
---|
| 1049 | # end of class MyApp |
---|
| 1050 | |
---|
| 1051 | if __name__ == "__main__": |
---|
| 1052 | app = MyApp(0) |
---|
| 1053 | app.MainLoop() |
---|
| 1054 | |
---|
[7116b6e0] | 1055 | """ |
---|
[f3d51f6] | 1056 | ##### end of testing code ##################################################### |
---|