[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 |
---|
[8b21fa7] | 12 | from sas.guiframe.events import StatusEvent |
---|
| 13 | from sas.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 |
---|
[dea2f6e] | 18 | from sas.guiframe.documentation_window import DocumentationWindow |
---|
[f3d51f6] | 19 | |
---|
[b8ff610] | 20 | if sys.platform.count("win32") > 0: |
---|
[7d9e7a9] | 21 | FONT_VARIANT = 0 |
---|
| 22 | else: |
---|
| 23 | FONT_VARIANT = 1 |
---|
[f3d51f6] | 24 | |
---|
[75df58b] | 25 | class InversionControl(ScrolledPanel, PanelBase): |
---|
[7116b6e0] | 26 | """ |
---|
| 27 | """ |
---|
[f3d51f6] | 28 | window_name = 'pr_control' |
---|
| 29 | window_caption = "P(r) control panel" |
---|
| 30 | CENTER_PANE = True |
---|
[8b21fa7] | 31 | |
---|
[f3d51f6] | 32 | # Figure of merit parameters [default] |
---|
[8b21fa7] | 33 | |
---|
[dfb58f8] | 34 | ## Oscillation parameters (sin function = 1.1) |
---|
[f3d51f6] | 35 | oscillation_max = 1.5 |
---|
[8b21fa7] | 36 | |
---|
| 37 | def __init__(self, parent, id=-1, plots=None, 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() |
---|
[8b21fa7] | 43 | #Set window's font size |
---|
[7d9e7a9] | 44 | self.SetWindowVariant(variant=FONT_VARIANT) |
---|
[8b21fa7] | 45 | |
---|
[f3d51f6] | 46 | self.plots = plots |
---|
| 47 | self.radio_buttons = {} |
---|
[ae84427] | 48 | self.parent = parent.parent |
---|
[8b21fa7] | 49 | |
---|
[f3d51f6] | 50 | ## Data file TextCtrl |
---|
[8b21fa7] | 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 |
---|
[8b21fa7] | 62 | self.qmin_ctl = None |
---|
| 63 | self.qmax_ctl = None |
---|
[5d98370] | 64 | self.swidth_ctl = None |
---|
| 65 | self.sheight_ctl = None |
---|
[8b21fa7] | 66 | |
---|
| 67 | self.rg_ctl = None |
---|
| 68 | self.iq0_ctl = None |
---|
| 69 | self.bck_chk = None |
---|
| 70 | self.bck_ctl = None |
---|
| 71 | |
---|
[dfb58f8] | 72 | # TextCtrl for fraction of positive P(r) |
---|
| 73 | self.pos_ctl = None |
---|
[8b21fa7] | 74 | |
---|
[dfb58f8] | 75 | # TextCtrl for fraction of 1 sigma positive P(r) |
---|
[8b21fa7] | 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 |
---|
[8b21fa7] | 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: |
---|
[8b21fa7] | 90 | self._default_save_location = \ |
---|
[c4ae1c2] | 91 | self.parent._default_save_location |
---|
[8b21fa7] | 92 | |
---|
[0ccd214] | 93 | # Default width |
---|
| 94 | self._default_width = 350 |
---|
[f3d51f6] | 95 | self._do_layout() |
---|
[8b21fa7] | 96 | |
---|
[f3d51f6] | 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) |
---|
[8b21fa7] | 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) |
---|
[8b21fa7] | 149 | |
---|
[f3d51f6] | 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 |
---|
[8b21fa7] | 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 |
---|
[8b21fa7] | 199 | elif name == 'iq0': |
---|
[a4bd2ac] | 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 |
---|
[8b21fa7] | 214 | elif name == 'slit_height': |
---|
[5d98370] | 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) |
---|
[8b21fa7] | 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"): |
---|
[92a2ecd] | 257 | child = new_doc.getElementsByTagName("SASentry") |
---|
| 258 | for item in child: |
---|
| 259 | doc.firstChild.appendChild(item) |
---|
[d85ee8c] | 260 | else: |
---|
| 261 | doc = new_doc |
---|
[8b21fa7] | 262 | return doc |
---|
| 263 | |
---|
[3f0351c6] | 264 | def on_save(self, evt=None): |
---|
[5d98370] | 265 | """ |
---|
[7116b6e0] | 266 | Method used to create a memento of the current state |
---|
[8b21fa7] | 267 | |
---|
| 268 | :return: state object |
---|
[5d98370] | 269 | """ |
---|
| 270 | # Ask the user the location of the file to write to. |
---|
| 271 | path = None |
---|
[c4ae1c2] | 272 | if self.parent != None: |
---|
[8b21fa7] | 273 | self._default_save_location = self.parent._default_save_location |
---|
[3e41f43] | 274 | dlg = wx.FileDialog(self, "Choose a file", |
---|
[8b21fa7] | 275 | self._default_save_location, |
---|
[c4ae1c2] | 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: |
---|
[8b21fa7] | 281 | self.parent._default_save_location = self._default_save_location |
---|
[0d88a09] | 282 | else: |
---|
| 283 | return None |
---|
[8b21fa7] | 284 | |
---|
[5d98370] | 285 | dlg.Destroy() |
---|
[8b21fa7] | 286 | |
---|
[b35d3d1] | 287 | state = self.get_state() |
---|
[8b21fa7] | 288 | |
---|
[23cdeab] | 289 | # MAC always needs the extension for saving |
---|
| 290 | extens = ".prv" |
---|
| 291 | # Make sure the ext included in the file name |
---|
| 292 | fName = os.path.splitext(path)[0] + extens |
---|
| 293 | self._manager.save_data(filepath=fName, prstate=state) |
---|
[8b21fa7] | 294 | |
---|
[b35d3d1] | 295 | return state |
---|
[8b21fa7] | 296 | |
---|
[6d3d5ff] | 297 | def get_data(self): |
---|
| 298 | """ |
---|
| 299 | """ |
---|
| 300 | return self._manager.get_data() |
---|
[8b21fa7] | 301 | |
---|
[b35d3d1] | 302 | def get_state(self): |
---|
| 303 | """ |
---|
| 304 | Get the current state |
---|
[8b21fa7] | 305 | |
---|
[b35d3d1] | 306 | : return: state object |
---|
| 307 | """ |
---|
[8b21fa7] | 308 | # Construct the state object |
---|
[5d98370] | 309 | state = InversionState() |
---|
[8b21fa7] | 310 | |
---|
[5d98370] | 311 | # Read the panel's parameters |
---|
| 312 | flag, alpha, dmax, nfunc, qmin, \ |
---|
| 313 | qmax, height, width = self._read_pars() |
---|
[8b21fa7] | 314 | |
---|
[5d98370] | 315 | state.nfunc = nfunc |
---|
| 316 | state.d_max = dmax |
---|
| 317 | state.alpha = alpha |
---|
[8b21fa7] | 318 | state.qmin = qmin |
---|
| 319 | state.qmax = qmax |
---|
[5d98370] | 320 | state.width = width |
---|
| 321 | state.height = height |
---|
[8b21fa7] | 322 | |
---|
[5d98370] | 323 | # Data file |
---|
[0d88a09] | 324 | state.file = self.plot_data.GetValue() |
---|
[8b21fa7] | 325 | |
---|
[5d98370] | 326 | # Background evaluation checkbox |
---|
| 327 | state.estimate_bck = self.bck_chk.IsChecked() |
---|
[8b21fa7] | 328 | |
---|
[5d98370] | 329 | # Estimates |
---|
| 330 | state.nterms_estimate = self.nterms_estimate |
---|
| 331 | state.alpha_estimate = self.alpha_estimate |
---|
[8b21fa7] | 332 | |
---|
[5d98370] | 333 | # Read the output values |
---|
[8b21fa7] | 334 | state.chi2 = self.chi2 |
---|
[5d98370] | 335 | state.elapsed = self.elapsed |
---|
[8b21fa7] | 336 | state.osc = self.oscillation |
---|
| 337 | state.pos = self.pos |
---|
[5d98370] | 338 | state.pos_err = self.pos_err |
---|
[8b21fa7] | 339 | state.rg = self.rg |
---|
| 340 | state.iq0 = self.iq0 |
---|
| 341 | state.bck = self.bck |
---|
| 342 | |
---|
[5d98370] | 343 | return state |
---|
[8b21fa7] | 344 | |
---|
[5d98370] | 345 | def set_state(self, state): |
---|
| 346 | """ |
---|
[7116b6e0] | 347 | Set the state of the panel and inversion problem to |
---|
| 348 | the state passed as a parameter. |
---|
[8b21fa7] | 349 | Execute the inversion immediately after filling the |
---|
[7116b6e0] | 350 | controls. |
---|
[8b21fa7] | 351 | |
---|
[7116b6e0] | 352 | :param state: InversionState object |
---|
[5d98370] | 353 | """ |
---|
[fde249c] | 354 | if state.nfunc is not None: |
---|
| 355 | self.nfunc = state.nfunc |
---|
| 356 | if state.d_max is not None: |
---|
| 357 | self.d_max = state.d_max |
---|
| 358 | if state.alpha is not None: |
---|
| 359 | self.alpha = state.alpha |
---|
| 360 | if state.qmin is not None: |
---|
[8b21fa7] | 361 | self.q_min = state.qmin |
---|
[fde249c] | 362 | if state.qmax is not None: |
---|
[8b21fa7] | 363 | self.q_max = state.qmax |
---|
[fde249c] | 364 | if state.width is not None: |
---|
| 365 | self.slit_width = state.width |
---|
| 366 | if state.height is not None: |
---|
| 367 | self.slit_height = state.height |
---|
[8b21fa7] | 368 | |
---|
[5d98370] | 369 | # Data file |
---|
[0d88a09] | 370 | self.plot_data.SetValue(str(state.file)) |
---|
[8b21fa7] | 371 | |
---|
[5d98370] | 372 | # Background evaluation checkbox |
---|
| 373 | self.bck_chk.SetValue(state.estimate_bck) |
---|
[8b21fa7] | 374 | |
---|
[5d98370] | 375 | # Estimates |
---|
[fde249c] | 376 | if state.nterms_estimate is not None: |
---|
| 377 | self.nterms_estimate = state.nterms_estimate |
---|
[8b21fa7] | 378 | if state.alpha_estimate is not None: |
---|
| 379 | self.alpha_estimate = state.alpha_estimate |
---|
| 380 | |
---|
| 381 | |
---|
[5d98370] | 382 | # Read the output values |
---|
[fde249c] | 383 | if state.chi2 is not None: |
---|
[8b21fa7] | 384 | self.chi2 = state.chi2 |
---|
[fde249c] | 385 | if state.elapsed is not None: |
---|
| 386 | self.elapsed = state.elapsed |
---|
| 387 | if state.osc is not None: |
---|
| 388 | self.oscillation = state.osc |
---|
| 389 | if state.pos is not None: |
---|
| 390 | self.positive = state.pos |
---|
| 391 | if state.pos_err is not None: |
---|
| 392 | self.pos_err = state.pos_err |
---|
| 393 | if state.rg is not None: |
---|
[8b21fa7] | 394 | self.rg = state.rg |
---|
[fde249c] | 395 | if state.iq0 is not None: |
---|
[8b21fa7] | 396 | self.iq0 = state.iq0 |
---|
[fde249c] | 397 | if state.bck is not None: |
---|
[8b21fa7] | 398 | self.bck = state.bck |
---|
[5d98370] | 399 | |
---|
[0d88a09] | 400 | # Perform inversion |
---|
[8b21fa7] | 401 | self._on_invert(None) |
---|
| 402 | |
---|
[f3d51f6] | 403 | def set_manager(self, manager): |
---|
[6d3d5ff] | 404 | self._manager = manager |
---|
[8b21fa7] | 405 | |
---|
[f3d51f6] | 406 | def _do_layout(self): |
---|
[8b21fa7] | 407 | vbox = wx.GridBagSizer(0, 0) |
---|
[4318af7f] | 408 | iy_vb = 0 |
---|
[f3d51f6] | 409 | |
---|
| 410 | # ----- I(q) data ----- |
---|
[aa4b8379] | 411 | databox = wx.StaticBox(self, -1, "I(q) data source") |
---|
[8b21fa7] | 412 | |
---|
[f3d51f6] | 413 | boxsizer1 = wx.StaticBoxSizer(databox, wx.VERTICAL) |
---|
[3e41f43] | 414 | boxsizer1.SetMinSize((self._default_width, 50)) |
---|
| 415 | pars_sizer = wx.GridBagSizer(5, 5) |
---|
[0d21ac1] | 416 | |
---|
[f3d51f6] | 417 | iy = 0 |
---|
[57b551e] | 418 | self.file_radio = wx.StaticText(self, -1, "Name:") |
---|
[3e41f43] | 419 | pars_sizer.Add(self.file_radio, (iy, 0), (1, 1), |
---|
[8b21fa7] | 420 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
| 421 | |
---|
| 422 | self.plot_data = DataFileTextCtrl(self, -1, size=(260, 20)) |
---|
| 423 | |
---|
[3e41f43] | 424 | pars_sizer.Add(self.plot_data, (iy, 1), (1, 1), |
---|
[8b21fa7] | 425 | wx.EXPAND | wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 15) |
---|
| 426 | |
---|
[a4bd2ac] | 427 | self.bck_chk = wx.CheckBox(self, -1, "Estimate background level") |
---|
[3e41f43] | 428 | hint_msg = "Check box to let the fit estimate " |
---|
| 429 | hint_msg += "the constant background level." |
---|
| 430 | self.bck_chk.SetToolTipString(hint_msg) |
---|
[a4bd2ac] | 431 | self.bck_chk.Bind(wx.EVT_CHECKBOX, self._on_pars_changed) |
---|
| 432 | iy += 1 |
---|
[3e41f43] | 433 | pars_sizer.Add(self.bck_chk, (iy, 0), (1, 2), |
---|
[8b21fa7] | 434 | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) |
---|
| 435 | boxsizer1.Add(pars_sizer, 0, wx.EXPAND) |
---|
[3e41f43] | 436 | vbox.Add(boxsizer1, (iy_vb, 0), (1, 1), |
---|
[8b21fa7] | 437 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE | wx.TOP, 5) |
---|
| 438 | |
---|
[a4bd2ac] | 439 | # ----- Add slit parameters ----- |
---|
[2a92852] | 440 | if True: |
---|
[a4bd2ac] | 441 | sbox = wx.StaticBox(self, -1, "Slit parameters") |
---|
| 442 | sboxsizer = wx.StaticBoxSizer(sbox, wx.VERTICAL) |
---|
[3e41f43] | 443 | sboxsizer.SetMinSize((self._default_width, 20)) |
---|
[8b21fa7] | 444 | |
---|
[3e41f43] | 445 | sizer_slit = wx.GridBagSizer(5, 5) |
---|
[8b21fa7] | 446 | |
---|
[3e41f43] | 447 | label_sheight = wx.StaticText(self, -1, "Height", size=(40, 20)) |
---|
| 448 | label_swidth = wx.StaticText(self, -1, "Width", size=(40, 20)) |
---|
[8b21fa7] | 449 | label_sunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55, 20)) |
---|
| 450 | self.sheight_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) |
---|
| 451 | self.swidth_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) |
---|
[3e41f43] | 452 | hint_msg = "Enter slit height in units of Q or leave blank." |
---|
| 453 | self.sheight_ctl.SetToolTipString(hint_msg) |
---|
| 454 | hint_msg = "Enter slit width in units of Q or leave blank." |
---|
| 455 | self.swidth_ctl.SetToolTipString(hint_msg) |
---|
[8b21fa7] | 456 | |
---|
[a4bd2ac] | 457 | iy = 0 |
---|
[8b21fa7] | 458 | sizer_slit.Add(label_sheight, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 459 | sizer_slit.Add(self.sheight_ctl, (iy, 1), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 460 | sizer_slit.Add(label_swidth, (iy, 2), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 461 | sizer_slit.Add(self.swidth_ctl, (iy, 3), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 462 | sizer_slit.Add(label_sunits2, (iy, 4), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 463 | |
---|
[a4bd2ac] | 464 | sboxsizer.Add(sizer_slit, wx.TOP, 15) |
---|
[4318af7f] | 465 | iy_vb += 1 |
---|
[3e41f43] | 466 | vbox.Add(sboxsizer, (iy_vb, 0), (1, 1), |
---|
[8b21fa7] | 467 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
---|
| 468 | |
---|
[357b79b] | 469 | # ----- Q range ----- |
---|
| 470 | qbox = wx.StaticBox(self, -1, "Q range") |
---|
| 471 | qboxsizer = wx.StaticBoxSizer(qbox, wx.VERTICAL) |
---|
[3e41f43] | 472 | qboxsizer.SetMinSize((self._default_width, 20)) |
---|
[8b21fa7] | 473 | |
---|
[3e41f43] | 474 | sizer_q = wx.GridBagSizer(5, 5) |
---|
[357b79b] | 475 | |
---|
[3e41f43] | 476 | label_qmin = wx.StaticText(self, -1, "Q min", size=(40, 20)) |
---|
| 477 | label_qmax = wx.StaticText(self, -1, "Q max", size=(40, 20)) |
---|
| 478 | label_qunits2 = wx.StaticText(self, -1, "[A^(-1)]", size=(55, 20)) |
---|
[8b21fa7] | 479 | self.qmin_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) |
---|
| 480 | self.qmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) |
---|
[3e41f43] | 481 | hint_msg = "Select a lower bound for Q or leave blank." |
---|
| 482 | self.qmin_ctl.SetToolTipString(hint_msg) |
---|
| 483 | hint_msg = "Select an upper bound for Q or leave blank." |
---|
| 484 | self.qmax_ctl.SetToolTipString(hint_msg) |
---|
[357b79b] | 485 | self.qmin_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) |
---|
| 486 | self.qmax_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) |
---|
[8b21fa7] | 487 | |
---|
[357b79b] | 488 | iy = 0 |
---|
[8b21fa7] | 489 | sizer_q.Add(label_qmin, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 490 | sizer_q.Add(self.qmin_ctl, (iy, 1), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 491 | sizer_q.Add(label_qmax, (iy, 2), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 492 | sizer_q.Add(self.qmax_ctl, (iy, 3), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
| 493 | sizer_q.Add(label_qunits2, (iy, 4), (1, 1), wx.LEFT | wx.EXPAND, 5) |
---|
[357b79b] | 494 | qboxsizer.Add(sizer_q, wx.TOP, 15) |
---|
[4318af7f] | 495 | |
---|
| 496 | iy_vb += 1 |
---|
[8b21fa7] | 497 | vbox.Add(qboxsizer, (iy_vb, 0), (1, 1), |
---|
| 498 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
---|
| 499 | |
---|
[f3d51f6] | 500 | # ----- Parameters ----- |
---|
| 501 | parsbox = wx.StaticBox(self, -1, "Parameters") |
---|
| 502 | boxsizer2 = wx.StaticBoxSizer(parsbox, wx.VERTICAL) |
---|
[8b21fa7] | 503 | boxsizer2.SetMinSize((self._default_width, 50)) |
---|
| 504 | |
---|
| 505 | explanation = "P(r) is found by fitting a set of base functions" |
---|
[3e41f43] | 506 | explanation += " to I(Q). The minimization involves" |
---|
| 507 | explanation += " a regularization term to ensure a smooth P(r)." |
---|
[8b21fa7] | 508 | explanation += " The regularization constant gives the size of that " |
---|
[3e41f43] | 509 | explanation += "term. The suggested value is the value above which the" |
---|
| 510 | explanation += " output P(r) will have only one peak." |
---|
[8b21fa7] | 511 | label_explain = wx.StaticText(self, -1, explanation, size=(280, 90)) |
---|
| 512 | boxsizer2.Add(label_explain, wx.LEFT | wx.BOTTOM, 5) |
---|
| 513 | |
---|
[f3d51f6] | 514 | label_nfunc = wx.StaticText(self, -1, "Number of terms") |
---|
[3e41f43] | 515 | label_nfunc.SetMinSize((120, 20)) |
---|
[f3d51f6] | 516 | label_alpha = wx.StaticText(self, -1, "Regularization constant") |
---|
[8b21fa7] | 517 | label_dmax = wx.StaticText(self, -1, "Max distance [A]") |
---|
| 518 | self.label_sugg = wx.StaticText(self, -1, "Suggested value") |
---|
| 519 | |
---|
| 520 | self.nfunc_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) |
---|
[32dffae4] | 521 | self.nfunc_ctl.SetToolTipString("Number of terms in the expansion.") |
---|
[8b21fa7] | 522 | self.alpha_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) |
---|
[3e41f43] | 523 | hint_msg = "Control parameter for the size of the regularization term." |
---|
| 524 | self.alpha_ctl.SetToolTipString(hint_msg) |
---|
[8b21fa7] | 525 | self.dmax_ctl = PrTextCtrl(self, -1, style=wx.TE_PROCESS_ENTER, size=(60, 20)) |
---|
[3e41f43] | 526 | hint_msg = "Maximum distance between any two points in the system." |
---|
| 527 | self.dmax_ctl.SetToolTipString(hint_msg) |
---|
[8b21fa7] | 528 | wx_id = wx.NewId() |
---|
| 529 | self.alpha_estimate_ctl = wx.Button(self, wx_id, "") |
---|
| 530 | self.Bind(wx.EVT_BUTTON, self._on_accept_alpha, id=wx_id) |
---|
[f3d51f6] | 531 | self.alpha_estimate_ctl.Enable(False) |
---|
[634f1cf] | 532 | self.alpha_estimate_ctl.SetToolTipString("Waiting for estimate...") |
---|
[8b21fa7] | 533 | |
---|
| 534 | wx_id = wx.NewId() |
---|
| 535 | self.nterms_estimate_ctl = wx.Button(self, wx_id, "") |
---|
[35adaf6] | 536 | #self.nterms_estimate_ctl.Hide() |
---|
[8b21fa7] | 537 | self.Bind(wx.EVT_BUTTON, self._on_accept_nterms, id=wx_id) |
---|
[35adaf6] | 538 | self.nterms_estimate_ctl.Enable(False) |
---|
[8b21fa7] | 539 | |
---|
[35adaf6] | 540 | self.nterms_estimate_ctl.SetToolTipString("Waiting for estimate...") |
---|
[8b21fa7] | 541 | |
---|
[d6113849] | 542 | self.nfunc_ctl.Bind(wx.EVT_TEXT, self._read_pars) |
---|
[a4bd2ac] | 543 | self.alpha_ctl.Bind(wx.EVT_TEXT, self._read_pars) |
---|
| 544 | self.dmax_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) |
---|
[8b21fa7] | 545 | |
---|
[a00ee4c] | 546 | # Distance explorator |
---|
[8b21fa7] | 547 | wx_id = wx.NewId() |
---|
| 548 | self.distance_explorator_ctl = wx.Button(self, wx_id, "Explore") |
---|
| 549 | self.Bind(wx.EVT_BUTTON, self._on_explore, id=wx_id) |
---|
| 550 | |
---|
| 551 | |
---|
| 552 | sizer_params = wx.GridBagSizer(5, 5) |
---|
[f3d51f6] | 553 | |
---|
| 554 | iy = 0 |
---|
[3e41f43] | 555 | sizer_params.Add(self.label_sugg, (iy, 2), (1, 1), wx.LEFT, 15) |
---|
[f3d51f6] | 556 | iy += 1 |
---|
[8b21fa7] | 557 | sizer_params.Add(label_nfunc, (iy, 0), (1, 1), wx.LEFT, 15) |
---|
| 558 | sizer_params.Add(self.nfunc_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) |
---|
[3e41f43] | 559 | sizer_params.Add(self.nterms_estimate_ctl, (iy, 2), (1, 1), wx.LEFT, 15) |
---|
[f3d51f6] | 560 | iy += 1 |
---|
[8b21fa7] | 561 | sizer_params.Add(label_alpha, (iy, 0), (1, 1), wx.LEFT, 15) |
---|
| 562 | sizer_params.Add(self.alpha_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) |
---|
[3e41f43] | 563 | sizer_params.Add(self.alpha_estimate_ctl, (iy, 2), (1, 1), wx.LEFT, 15) |
---|
[f3d51f6] | 564 | iy += 1 |
---|
[3e41f43] | 565 | sizer_params.Add(label_dmax, (iy, 0), (1, 1), wx.LEFT, 15) |
---|
[8b21fa7] | 566 | sizer_params.Add(self.dmax_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) |
---|
[3e41f43] | 567 | sizer_params.Add(self.distance_explorator_ctl, (iy, 2), |
---|
| 568 | (1, 1), wx.LEFT, 15) |
---|
[f3d51f6] | 569 | |
---|
| 570 | boxsizer2.Add(sizer_params, 0) |
---|
[8b21fa7] | 571 | |
---|
[4318af7f] | 572 | iy_vb += 1 |
---|
[3e41f43] | 573 | vbox.Add(boxsizer2, (iy_vb, 0), (1, 1), |
---|
[8b21fa7] | 574 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
---|
[f3d51f6] | 575 | |
---|
[634f1cf] | 576 | |
---|
[f3d51f6] | 577 | # ----- Results ----- |
---|
| 578 | resbox = wx.StaticBox(self, -1, "Outputs") |
---|
| 579 | ressizer = wx.StaticBoxSizer(resbox, wx.VERTICAL) |
---|
[3e41f43] | 580 | ressizer.SetMinSize((self._default_width, 50)) |
---|
[8b21fa7] | 581 | |
---|
| 582 | label_rg = wx.StaticText(self, -1, "Rg") |
---|
| 583 | label_rg_unit = wx.StaticText(self, -1, "[A]") |
---|
| 584 | label_iq0 = wx.StaticText(self, -1, "I(Q=0)") |
---|
[a4bd2ac] | 585 | label_iq0_unit = wx.StaticText(self, -1, "[A^(-1)]") |
---|
[8b21fa7] | 586 | label_bck = wx.StaticText(self, -1, "Background") |
---|
[a4bd2ac] | 587 | label_bck_unit = wx.StaticText(self, -1, "[A^(-1)]") |
---|
[8b21fa7] | 588 | self.rg_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 589 | hint_msg = "Radius of gyration for the computed P(r)." |
---|
| 590 | self.rg_ctl.SetToolTipString(hint_msg) |
---|
[8b21fa7] | 591 | self.iq0_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 592 | hint_msg = "Scattering intensity at Q=0 for the computed P(r)." |
---|
| 593 | self.iq0_ctl.SetToolTipString(hint_msg) |
---|
[8b21fa7] | 594 | self.bck_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[a4bd2ac] | 595 | self.bck_ctl.SetToolTipString("Value of estimated constant background.") |
---|
[8b21fa7] | 596 | |
---|
[f3d51f6] | 597 | label_time = wx.StaticText(self, -1, "Computation time") |
---|
| 598 | label_time_unit = wx.StaticText(self, -1, "secs") |
---|
[8b21fa7] | 599 | label_time.SetMinSize((120, 20)) |
---|
[f3d51f6] | 600 | label_chi2 = wx.StaticText(self, -1, "Chi2/dof") |
---|
| 601 | label_osc = wx.StaticText(self, -1, "Oscillations") |
---|
[dfb58f8] | 602 | label_pos = wx.StaticText(self, -1, "Positive fraction") |
---|
| 603 | label_pos_err = wx.StaticText(self, -1, "1-sigma positive fraction") |
---|
[8b21fa7] | 604 | |
---|
[75df58b] | 605 | self.time_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 606 | hint_msg = "Computation time for the last inversion, in seconds." |
---|
| 607 | self.time_ctl.SetToolTipString(hint_msg) |
---|
[8b21fa7] | 608 | |
---|
[75df58b] | 609 | self.chi2_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[32dffae4] | 610 | self.chi2_ctl.SetToolTipString("Chi^2 over degrees of freedom.") |
---|
[8b21fa7] | 611 | |
---|
[dfb58f8] | 612 | # Oscillation parameter |
---|
[75df58b] | 613 | self.osc_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 614 | hint_msg = "Oscillation parameter. P(r) for a sphere has an " |
---|
| 615 | hint_msg += " oscillation parameter of 1.1." |
---|
| 616 | self.osc_ctl.SetToolTipString(hint_msg) |
---|
[8b21fa7] | 617 | |
---|
[dfb58f8] | 618 | # Positive fraction figure of merit |
---|
[75df58b] | 619 | self.pos_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[3e41f43] | 620 | hint_msg = "Fraction of P(r) that is positive. " |
---|
| 621 | hint_msg += "Theoretically, P(r) is defined positive." |
---|
| 622 | self.pos_ctl.SetToolTipString(hint_msg) |
---|
[8b21fa7] | 623 | |
---|
[dfb58f8] | 624 | # 1-simga positive fraction figure of merit |
---|
[75df58b] | 625 | self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60, 20)) |
---|
[8b21fa7] | 626 | message = "Fraction of P(r) that is at least 1 standard deviation" |
---|
[3e41f43] | 627 | message += " greater than zero.\n" |
---|
| 628 | message += "This figure of merit tells you about the size of the " |
---|
| 629 | message += "P(r) errors.\n" |
---|
| 630 | message += "If it is close to 1 and the other figures of merit are bad," |
---|
| 631 | message += " consider changing the maximum distance." |
---|
[dfb58f8] | 632 | self.pos_err_ctl.SetToolTipString(message) |
---|
[8b21fa7] | 633 | |
---|
[3e41f43] | 634 | sizer_res = wx.GridBagSizer(5, 5) |
---|
[f3d51f6] | 635 | |
---|
| 636 | iy = 0 |
---|
[8b21fa7] | 637 | sizer_res.Add(label_rg, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
| 638 | sizer_res.Add(self.rg_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
| 639 | sizer_res.Add(label_rg_unit, (iy, 2), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
[a4bd2ac] | 640 | iy += 1 |
---|
[8b21fa7] | 641 | sizer_res.Add(label_iq0, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
| 642 | sizer_res.Add(self.iq0_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
| 643 | sizer_res.Add(label_iq0_unit, (iy, 2), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
[a4bd2ac] | 644 | iy += 1 |
---|
[8b21fa7] | 645 | sizer_res.Add(label_bck, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
| 646 | sizer_res.Add(self.bck_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
| 647 | sizer_res.Add(label_bck_unit, (iy, 2), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
[a4bd2ac] | 648 | iy += 1 |
---|
[8b21fa7] | 649 | sizer_res.Add(label_time, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
| 650 | sizer_res.Add(self.time_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
| 651 | sizer_res.Add(label_time_unit, (iy, 2), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
[f3d51f6] | 652 | iy += 1 |
---|
[8b21fa7] | 653 | sizer_res.Add(label_chi2, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
| 654 | sizer_res.Add(self.chi2_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
[f3d51f6] | 655 | iy += 1 |
---|
[8b21fa7] | 656 | sizer_res.Add(label_osc, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
| 657 | sizer_res.Add(self.osc_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
[f3d51f6] | 658 | |
---|
[dfb58f8] | 659 | iy += 1 |
---|
[8b21fa7] | 660 | sizer_res.Add(label_pos, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
| 661 | sizer_res.Add(self.pos_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
[dfb58f8] | 662 | |
---|
| 663 | iy += 1 |
---|
[8b21fa7] | 664 | sizer_res.Add(label_pos_err, (iy, 0), (1, 1), wx.LEFT | wx.EXPAND, 15) |
---|
| 665 | sizer_res.Add(self.pos_err_ctl, (iy, 1), (1, 1), wx.RIGHT | wx.EXPAND, 15) |
---|
[dfb58f8] | 666 | |
---|
[f3d51f6] | 667 | ressizer.Add(sizer_res, 0) |
---|
[4318af7f] | 668 | iy_vb += 1 |
---|
[3e41f43] | 669 | vbox.Add(ressizer, (iy_vb, 0), (1, 1), |
---|
[8b21fa7] | 670 | wx.LEFT | wx.RIGHT | wx.EXPAND | wx.ADJUST_MINSIZE, 5) |
---|
[f3d51f6] | 671 | |
---|
| 672 | # ----- Buttons ----- |
---|
[8b21fa7] | 673 | wx_id = wx.NewId() |
---|
| 674 | button_ok = wx.Button(self, wx_id, "Compute") |
---|
| 675 | button_ok.SetToolTipString("Perform P(r) inversion.") |
---|
| 676 | self.Bind(wx.EVT_BUTTON, self._on_invert, id=wx_id) |
---|
| 677 | |
---|
[f71700b] | 678 | self.button_help = wx.Button(self, -1, "HELP") |
---|
| 679 | self.button_help.SetToolTipString("Get help on P(r) inversion.") |
---|
| 680 | self.button_help.Bind(wx.EVT_BUTTON, self.on_help) |
---|
[dea2f6e] | 681 | |
---|
[5771ea3] | 682 | self._set_reset_flag(True) |
---|
[3f0351c6] | 683 | self._set_save_flag(True) |
---|
[f3d51f6] | 684 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
[8b21fa7] | 685 | sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
| 686 | sizer_button.Add(button_ok, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) |
---|
[f71700b] | 687 | sizer_button.Add(self.button_help, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) |
---|
[8b21fa7] | 688 | |
---|
[4318af7f] | 689 | iy_vb += 1 |
---|
[3e41f43] | 690 | vbox.Add(sizer_button, (iy_vb, 0), (1, 1), |
---|
[8b21fa7] | 691 | wx.EXPAND | wx.BOTTOM | wx.TOP | wx.RIGHT, 10) |
---|
[f3d51f6] | 692 | |
---|
[a00ee4c] | 693 | self.Bind(wx.EVT_TEXT_ENTER, self._on_invert) |
---|
[f3d51f6] | 694 | |
---|
| 695 | self.SetSizer(vbox) |
---|
[8b21fa7] | 696 | |
---|
[634f1cf] | 697 | def _on_accept_alpha(self, evt): |
---|
| 698 | """ |
---|
[8b21fa7] | 699 | User has accepted the estimated alpha, |
---|
[7116b6e0] | 700 | set it as part of the input parameters |
---|
[634f1cf] | 701 | """ |
---|
| 702 | try: |
---|
| 703 | alpha = self.alpha_estimate_ctl.GetLabel() |
---|
[c1bffa5] | 704 | # Check that we have a number |
---|
| 705 | float(alpha) |
---|
| 706 | self.alpha_ctl.SetValue(alpha) |
---|
| 707 | except ValueError: |
---|
| 708 | logging.error("InversionControl._on_accept_alpha got a value that was not a number: %s" % alpha ) |
---|
[634f1cf] | 709 | except: |
---|
| 710 | # No estimate or bad estimate, either do nothing |
---|
[8b21fa7] | 711 | logging.error("InversionControl._on_accept_alpha: %s" % sys.exc_value) |
---|
| 712 | |
---|
[35adaf6] | 713 | def _on_accept_nterms(self, evt): |
---|
| 714 | """ |
---|
[8b21fa7] | 715 | User has accepted the estimated number of terms, |
---|
[7116b6e0] | 716 | set it as part of the input parameters |
---|
[35adaf6] | 717 | """ |
---|
| 718 | try: |
---|
| 719 | nterms = self.nterms_estimate_ctl.GetLabel() |
---|
[c1bffa5] | 720 | # Check that we have a number |
---|
| 721 | float(nterms) |
---|
| 722 | self.nfunc_ctl.SetValue(nterms) |
---|
| 723 | except ValueError: |
---|
| 724 | logging.error("InversionControl._on_accept_nterms got a value that was not a number: %s" % nterms ) |
---|
[35adaf6] | 725 | except: |
---|
| 726 | # No estimate or bad estimate, either do nothing |
---|
[8b21fa7] | 727 | logging.error("InversionControl._on_accept_nterms: %s" % sys.exc_value) |
---|
| 728 | |
---|
[91d910d] | 729 | def clear_panel(self): |
---|
| 730 | """ |
---|
| 731 | """ |
---|
| 732 | self.plot_data.SetValue("") |
---|
| 733 | self.on_reset(event=None) |
---|
[8b21fa7] | 734 | |
---|
[91d910d] | 735 | def on_reset(self, event=None): |
---|
[b659551] | 736 | """ |
---|
[7116b6e0] | 737 | Resets inversion parameters |
---|
[b659551] | 738 | """ |
---|
[6d3d5ff] | 739 | self.nfunc = self._manager.DEFAULT_NFUNC |
---|
| 740 | self.d_max = self._manager.DEFAULT_DMAX |
---|
| 741 | self.alpha = self._manager.DEFAULT_ALPHA |
---|
[b659551] | 742 | self.qmin_ctl.SetValue("") |
---|
| 743 | self.qmax_ctl.SetValue("") |
---|
| 744 | self.time_ctl.SetValue("") |
---|
[a4bd2ac] | 745 | self.rg_ctl.SetValue("") |
---|
| 746 | self.iq0_ctl.SetValue("") |
---|
| 747 | self.bck_ctl.SetValue("") |
---|
[b659551] | 748 | self.chi2_ctl.SetValue("") |
---|
| 749 | self.osc_ctl.SetValue("") |
---|
| 750 | self.pos_ctl.SetValue("") |
---|
| 751 | self.pos_err_ctl.SetValue("") |
---|
| 752 | self.alpha_estimate_ctl.Enable(False) |
---|
| 753 | self.alpha_estimate_ctl.SetLabel("") |
---|
[35adaf6] | 754 | self.nterms_estimate_ctl.Enable(False) |
---|
| 755 | self.nterms_estimate_ctl.SetLabel("") |
---|
[b659551] | 756 | self._on_pars_changed() |
---|
[8b21fa7] | 757 | |
---|
[b659551] | 758 | def _on_pars_changed(self, evt=None): |
---|
[f3d51f6] | 759 | """ |
---|
[7116b6e0] | 760 | Called when an input parameter has changed |
---|
| 761 | We will estimate the alpha parameter behind the |
---|
[8b21fa7] | 762 | scenes. |
---|
[f3d51f6] | 763 | """ |
---|
[2a92852] | 764 | flag, alpha, dmax, nfunc, qmin, qmax, height, width = self._read_pars() |
---|
[a4bd2ac] | 765 | has_bck = self.bck_chk.IsChecked() |
---|
[8b21fa7] | 766 | |
---|
[f3d51f6] | 767 | # If the pars are valid, estimate alpha |
---|
| 768 | if flag: |
---|
[2a92852] | 769 | self.nterms_estimate_ctl.Enable(False) |
---|
| 770 | self.alpha_estimate_ctl.Enable(False) |
---|
[8b21fa7] | 771 | |
---|
[0d88a09] | 772 | dataset = self.plot_data.GetValue() |
---|
[6ce7201] | 773 | if dataset is not None and dataset.strip() != "": |
---|
[8b21fa7] | 774 | self._manager.estimate_plot_inversion(alpha=alpha, nfunc=nfunc, |
---|
| 775 | d_max=dmax, |
---|
| 776 | q_min=qmin, q_max=qmax, |
---|
| 777 | bck=has_bck, |
---|
| 778 | height=height, |
---|
| 779 | width=width) |
---|
| 780 | |
---|
[7116b6e0] | 781 | def _read_pars(self, evt=None): |
---|
| 782 | """ |
---|
[8b21fa7] | 783 | """ |
---|
[f3d51f6] | 784 | alpha = 0 |
---|
| 785 | nfunc = 5 |
---|
[8b21fa7] | 786 | dmax = 120 |
---|
| 787 | qmin = 0 |
---|
| 788 | qmax = 0 |
---|
[2a92852] | 789 | height = 0 |
---|
[8b21fa7] | 790 | width = 0 |
---|
[f3d51f6] | 791 | flag = True |
---|
[2a92852] | 792 | # Read slit height |
---|
| 793 | try: |
---|
| 794 | height_str = self.sheight_ctl.GetValue() |
---|
[3e41f43] | 795 | if len(height_str.lstrip().rstrip()) == 0: |
---|
[2a92852] | 796 | height = 0 |
---|
| 797 | else: |
---|
| 798 | height = float(height_str) |
---|
| 799 | self.sheight_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 800 | self.sheight_ctl.Refresh() |
---|
| 801 | except: |
---|
| 802 | flag = False |
---|
| 803 | self.sheight_ctl.SetBackgroundColour("pink") |
---|
| 804 | self.sheight_ctl.Refresh() |
---|
[8b21fa7] | 805 | |
---|
[2a92852] | 806 | # Read slit width |
---|
| 807 | try: |
---|
| 808 | width_str = self.swidth_ctl.GetValue() |
---|
[8b21fa7] | 809 | if len(width_str.lstrip().rstrip()) == 0: |
---|
[2a92852] | 810 | width = 0 |
---|
| 811 | else: |
---|
| 812 | width = float(width_str) |
---|
| 813 | self.swidth_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 814 | self.swidth_ctl.Refresh() |
---|
| 815 | except: |
---|
| 816 | flag = False |
---|
| 817 | self.swidth_ctl.SetBackgroundColour("pink") |
---|
| 818 | self.swidth_ctl.Refresh() |
---|
[8b21fa7] | 819 | |
---|
[f3d51f6] | 820 | # Read alpha |
---|
| 821 | try: |
---|
| 822 | alpha = float(self.alpha_ctl.GetValue()) |
---|
| 823 | self.alpha_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 824 | self.alpha_ctl.Refresh() |
---|
| 825 | except: |
---|
| 826 | flag = False |
---|
| 827 | self.alpha_ctl.SetBackgroundColour("pink") |
---|
| 828 | self.alpha_ctl.Refresh() |
---|
[8b21fa7] | 829 | |
---|
| 830 | # Read d_max |
---|
[f3d51f6] | 831 | try: |
---|
| 832 | dmax = float(self.dmax_ctl.GetValue()) |
---|
| 833 | self.dmax_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 834 | self.dmax_ctl.Refresh() |
---|
| 835 | except: |
---|
| 836 | flag = False |
---|
| 837 | self.dmax_ctl.SetBackgroundColour("pink") |
---|
| 838 | self.dmax_ctl.Refresh() |
---|
[8b21fa7] | 839 | |
---|
[f3d51f6] | 840 | # Read nfunc |
---|
| 841 | try: |
---|
| 842 | nfunc = int(self.nfunc_ctl.GetValue()) |
---|
[6d3d5ff] | 843 | npts = self._manager.get_npts() |
---|
[3e41f43] | 844 | if npts > 0 and nfunc > npts: |
---|
| 845 | message = "Number of function terms should be smaller " |
---|
| 846 | message += "than the number of points" |
---|
[6d3d5ff] | 847 | wx.PostEvent(self._manager.parent, StatusEvent(status=message)) |
---|
[b659551] | 848 | raise ValueError, message |
---|
[f3d51f6] | 849 | self.nfunc_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 850 | self.nfunc_ctl.Refresh() |
---|
| 851 | except: |
---|
| 852 | flag = False |
---|
| 853 | self.nfunc_ctl.SetBackgroundColour("pink") |
---|
| 854 | self.nfunc_ctl.Refresh() |
---|
[8b21fa7] | 855 | |
---|
[634f1cf] | 856 | # Read qmin |
---|
| 857 | try: |
---|
| 858 | qmin_str = self.qmin_ctl.GetValue() |
---|
[3e41f43] | 859 | if len(qmin_str.lstrip().rstrip()) == 0: |
---|
[634f1cf] | 860 | qmin = None |
---|
| 861 | else: |
---|
| 862 | qmin = float(qmin_str) |
---|
| 863 | self.qmin_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 864 | self.qmin_ctl.Refresh() |
---|
| 865 | except: |
---|
| 866 | flag = False |
---|
| 867 | self.qmin_ctl.SetBackgroundColour("pink") |
---|
| 868 | self.qmin_ctl.Refresh() |
---|
[8b21fa7] | 869 | |
---|
[634f1cf] | 870 | # Read qmax |
---|
| 871 | try: |
---|
| 872 | qmax_str = self.qmax_ctl.GetValue() |
---|
[3e41f43] | 873 | if len(qmax_str.lstrip().rstrip()) == 0: |
---|
[634f1cf] | 874 | qmax = None |
---|
| 875 | else: |
---|
| 876 | qmax = float(qmax_str) |
---|
| 877 | self.qmax_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 878 | self.qmax_ctl.Refresh() |
---|
| 879 | except: |
---|
| 880 | flag = False |
---|
| 881 | self.qmax_ctl.SetBackgroundColour("pink") |
---|
| 882 | self.qmax_ctl.Refresh() |
---|
[8b21fa7] | 883 | |
---|
[2a92852] | 884 | return flag, alpha, dmax, nfunc, qmin, qmax, height, width |
---|
[8b21fa7] | 885 | |
---|
[a00ee4c] | 886 | def _on_explore(self, evt): |
---|
| 887 | """ |
---|
[7116b6e0] | 888 | Invoke the d_max exploration dialog |
---|
[a00ee4c] | 889 | """ |
---|
| 890 | from explore_dialog import ExploreDialog |
---|
[6d3d5ff] | 891 | if self._manager._last_pr is not None: |
---|
| 892 | pr = self._manager._create_plot_pr() |
---|
[a00ee4c] | 893 | dialog = ExploreDialog(pr, 10, None, -1, "") |
---|
[3d250da3] | 894 | dialog.Show() |
---|
[a00ee4c] | 895 | else: |
---|
| 896 | message = "No data to analyze. Please load a data set to proceed." |
---|
[6d3d5ff] | 897 | wx.PostEvent(self._manager.parent, StatusEvent(status=message)) |
---|
[8b21fa7] | 898 | |
---|
[f3d51f6] | 899 | def _on_invert(self, evt): |
---|
| 900 | """ |
---|
[7116b6e0] | 901 | Perform inversion |
---|
[8b21fa7] | 902 | |
---|
| 903 | :param silent: when True, there will be no output for the user |
---|
| 904 | |
---|
[f3d51f6] | 905 | """ |
---|
| 906 | # Get the data from the form |
---|
| 907 | # Push it to the manager |
---|
[8b21fa7] | 908 | |
---|
[2a92852] | 909 | flag, alpha, dmax, nfunc, qmin, qmax, height, width = self._read_pars() |
---|
[a4bd2ac] | 910 | has_bck = self.bck_chk.IsChecked() |
---|
[8b21fa7] | 911 | |
---|
[f3d51f6] | 912 | if flag: |
---|
[0d88a09] | 913 | dataset = self.plot_data.GetValue() |
---|
[8b21fa7] | 914 | if dataset == None or len(dataset.strip()) == 0: |
---|
[3e41f43] | 915 | message = "No data to invert. Select a data set before" |
---|
| 916 | message += " proceeding with P(r) inversion." |
---|
[6d3d5ff] | 917 | wx.PostEvent(self._manager.parent, StatusEvent(status=message)) |
---|
[f3d51f6] | 918 | else: |
---|
[8b21fa7] | 919 | self._manager.setup_plot_inversion(alpha=alpha, nfunc=nfunc, |
---|
| 920 | d_max=dmax, |
---|
| 921 | q_min=qmin, q_max=qmax, |
---|
| 922 | bck=has_bck, |
---|
| 923 | height=height, |
---|
| 924 | width=width) |
---|
[f3d51f6] | 925 | else: |
---|
[3e41f43] | 926 | message = "The P(r) form contains invalid values: " |
---|
| 927 | message += "please submit it again." |
---|
[f3d51f6] | 928 | wx.PostEvent(self.parent, StatusEvent(status=message)) |
---|
[8b21fa7] | 929 | |
---|
[75df58b] | 930 | def _change_file(self, evt=None, filepath=None, data=None): |
---|
[f3d51f6] | 931 | """ |
---|
[7116b6e0] | 932 | Choose a new input file for I(q) |
---|
[f3d51f6] | 933 | """ |
---|
[6d3d5ff] | 934 | if not self._manager is None: |
---|
[75df58b] | 935 | self.plot_data.SetValue(str(data.name)) |
---|
| 936 | try: |
---|
[6d3d5ff] | 937 | self._manager.show_data(data=data, reset=True) |
---|
[75df58b] | 938 | self._on_pars_changed(None) |
---|
| 939 | self._on_invert(None) |
---|
| 940 | except: |
---|
| 941 | msg = "InversionControl._change_file: %s" % sys.exc_value |
---|
[8b21fa7] | 942 | logging.error(msg) |
---|
[119a11d] | 943 | |
---|
[dea2f6e] | 944 | def on_help(self, event): |
---|
[7116b6e0] | 945 | """ |
---|
[dea2f6e] | 946 | Bring up the P(r) Documentation whenever |
---|
| 947 | the HELP button is clicked. |
---|
[8b21fa7] | 948 | |
---|
[dea2f6e] | 949 | Calls DocumentationWindow with the path of the location within the |
---|
| 950 | documentation tree (after /doc/ ....". Note that when using old |
---|
| 951 | versions of Wx (before 2.9) and thus not the release version of |
---|
| 952 | installers, the help comes up at the top level of the file as |
---|
| 953 | webbrowser does not pass anything past the # to the browser when it is |
---|
| 954 | running "file:///...." |
---|
[8b21fa7] | 955 | |
---|
[dea2f6e] | 956 | :param evt: Triggers on clicking the help button |
---|
| 957 | """ |
---|
[8b21fa7] | 958 | |
---|
[dea2f6e] | 959 | _TreeLocation = "user/perspectives/pr/pr_help.html" |
---|
[3db44fb] | 960 | _doc_viewer = DocumentationWindow(self, -1, _TreeLocation, "", |
---|
| 961 | "P(r) Help") |
---|
[dea2f6e] | 962 | |
---|
| 963 | |
---|
[b659551] | 964 | class PrDistDialog(wx.Dialog): |
---|
| 965 | """ |
---|
[7116b6e0] | 966 | Property dialog to let the user change the number |
---|
| 967 | of points on the P(r) plot. |
---|
[b659551] | 968 | """ |
---|
| 969 | def __init__(self, parent, id): |
---|
[79492222] | 970 | from sas.pr.invertor import help |
---|
[b659551] | 971 | wx.Dialog.__init__(self, parent, id, size=(250, 120)) |
---|
[8b21fa7] | 972 | self.SetTitle("P(r) distribution") |
---|
| 973 | |
---|
[b659551] | 974 | |
---|
| 975 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
[8b21fa7] | 976 | |
---|
[b659551] | 977 | label_npts = wx.StaticText(self, -1, "Number of points") |
---|
[75df58b] | 978 | self.npts_ctl = PrTextCtrl(self, -1, size=(100, 20)) |
---|
[8b21fa7] | 979 | |
---|
[75df58b] | 980 | pars_sizer = wx.GridBagSizer(5, 5) |
---|
[b659551] | 981 | iy = 0 |
---|
[75df58b] | 982 | pars_sizer.Add(label_npts, (iy, 0), (1, 1), wx.LEFT, 15) |
---|
| 983 | pars_sizer.Add(self.npts_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) |
---|
[8b21fa7] | 984 | |
---|
| 985 | vbox.Add(pars_sizer, 0, wx.ALL | wx.EXPAND, 15) |
---|
[b659551] | 986 | |
---|
| 987 | static_line = wx.StaticLine(self, -1) |
---|
| 988 | vbox.Add(static_line, 0, wx.EXPAND, 0) |
---|
[8b21fa7] | 989 | |
---|
| 990 | button_ok = wx.Button(self, wx.ID_OK, "OK") |
---|
| 991 | self.Bind(wx.EVT_BUTTON, self._checkValues, button_ok) |
---|
| 992 | button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
---|
| 993 | |
---|
[b659551] | 994 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
[8b21fa7] | 995 | sizer_button.Add((20, 20), 1, wx.EXPAND | wx.ADJUST_MINSIZE, 0) |
---|
| 996 | sizer_button.Add(button_ok, 0, wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) |
---|
| 997 | sizer_button.Add(button_cancel, 0, |
---|
| 998 | wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) |
---|
| 999 | vbox.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) |
---|
[b659551] | 1000 | |
---|
| 1001 | self.SetSizer(vbox) |
---|
| 1002 | self.SetAutoLayout(True) |
---|
[8b21fa7] | 1003 | |
---|
[b659551] | 1004 | self.Layout() |
---|
| 1005 | self.Centre() |
---|
| 1006 | |
---|
| 1007 | def _checkValues(self, event): |
---|
| 1008 | """ |
---|
[7116b6e0] | 1009 | Check the dialog content. |
---|
[b659551] | 1010 | """ |
---|
| 1011 | flag = True |
---|
| 1012 | try: |
---|
| 1013 | int(self.npts_ctl.GetValue()) |
---|
| 1014 | self.npts_ctl.SetBackgroundColour(wx.WHITE) |
---|
| 1015 | self.npts_ctl.Refresh() |
---|
| 1016 | except: |
---|
| 1017 | flag = False |
---|
| 1018 | self.npts_ctl.SetBackgroundColour("pink") |
---|
| 1019 | self.npts_ctl.Refresh() |
---|
| 1020 | if flag: |
---|
| 1021 | event.Skip(True) |
---|
| 1022 | |
---|
| 1023 | def get_content(self): |
---|
| 1024 | """ |
---|
[7116b6e0] | 1025 | Return the content of the dialog. |
---|
| 1026 | At this point the values have already been |
---|
| 1027 | checked. |
---|
[b659551] | 1028 | """ |
---|
| 1029 | value = int(self.npts_ctl.GetValue()) |
---|
| 1030 | return value |
---|
[8b21fa7] | 1031 | |
---|
[b659551] | 1032 | def set_content(self, npts): |
---|
| 1033 | """ |
---|
[7116b6e0] | 1034 | Initialize the content of the dialog. |
---|
[b659551] | 1035 | """ |
---|
| 1036 | self.npts_ctl.SetValue("%i" % npts) |
---|