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