Changeset 634f1cf in sasview for prview/perspectives
- Timestamp:
- May 9, 2008 6:09:46 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 4a0536a
- Parents:
- f71287f4
- Location:
- prview/perspectives/pr
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/perspectives/pr/inversion_panel.py
r32dffae4 r634f1cf 124 124 self.file_radio = None 125 125 self.plot_radio = None 126 self.label_sugg = None 127 self.qmin_ctl = None 128 self.qmax_ctl = None 126 129 127 130 ## Estimates … … 145 148 elif name=='chi2': 146 149 self.chi2_ctl.SetValue("%-5.3g" % value) 150 elif name=='q_min': 151 self.qmin_ctl.SetValue("%-5.3g" % value) 152 elif name=='q_max': 153 self.qmax_ctl.SetValue("%-5.3g" % value) 147 154 elif name=='elapsed': 148 155 self.time_ctl.SetValue("%-5.2g" % value) … … 150 157 self.osc_ctl.SetValue("%-5.2g" % value) 151 158 elif name=='alpha_estimate': 152 self.alpha_estimate_ctl.SetValue("%-3.1g" % value) 159 self.alpha_estimate_ctl.SetToolTipString("Click to accept value.") 160 self.alpha_estimate_ctl.Enable(True) 161 self.alpha_estimate_ctl.SetLabel("%-3.1g" % value) 162 #self.alpha_estimate_ctl.Show() 163 #self.label_sugg.Show() 153 164 elif name=='plotname': 154 165 self.plot_data.SetValue(str(value)) … … 170 181 elif name=='chi2': 171 182 self.chi2_ctl.GetValue() 183 elif name=='q_min': 184 self.qmin_ctl.GetValue() 185 elif name=='q_max': 186 self.qmax_ctl.GetValue() 172 187 elif name=='elapsed': 173 188 self.time_ctl.GetValue() … … 240 255 label_alpha = wx.StaticText(self, -1, "Regularization constant") 241 256 label_dmax = wx.StaticText(self, -1, "Max distance [A]") 242 label_sugg = wx.StaticText(self, -1, "Suggested value") 257 self.label_sugg = wx.StaticText(self, -1, "Suggested value") 258 #self.label_sugg.Hide() 243 259 244 260 self.nfunc_ctl = wx.TextCtrl(self, -1, size=(60,20)) … … 248 264 self.dmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) 249 265 self.dmax_ctl.SetToolTipString("Maximum distance between any two points in the system.") 250 self.alpha_estimate_ctl = wx.TextCtrl(self, -1, size=(60,20)) 266 id = wx.NewId() 267 self.alpha_estimate_ctl = wx.Button(self, id, "") 268 #self.alpha_estimate_ctl.Hide() 269 self.Bind(wx.EVT_BUTTON, self._on_accept_alpha, id = id) 251 270 self.alpha_estimate_ctl.Enable(False) 252 self.alpha_estimate_ctl.SetToolTipString("Value of alpha below which P(r) may have multiple peaks.") 271 #self.alpha_estimate_ctl.SetBackgroundColour('#ffdf85') 272 #self.alpha_estimate_ctl.SetBackgroundColour(self.GetBackgroundColour()) 273 self.alpha_estimate_ctl.SetToolTipString("Waiting for estimate...") 253 274 254 275 # EVT_TEXT would trigger an event for each character entered 255 276 self.nfunc_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed) 256 #self.alpha_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed)277 self.alpha_ctl.Bind(wx.EVT_KILL_FOCUS, self._read_pars) 257 278 self.dmax_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed) 258 279 self.Bind(wx.EVT_TEXT_ENTER, self._on_pars_changed) … … 261 282 262 283 iy = 0 263 sizer_params.Add( label_sugg, (iy,2), (1,1), wx.LEFT, 15)284 sizer_params.Add(self.label_sugg, (iy,2), (1,1), wx.LEFT, 15) 264 285 iy += 1 265 286 sizer_params.Add(label_nfunc, (iy,0), (1,1), wx.LEFT, 15) … … 274 295 275 296 boxsizer2.Add(sizer_params, 0) 297 276 298 vbox.Add(boxsizer2) 299 300 # ----- Q range ----- 301 qbox = wx.StaticBox(self, -1, "Q range") 302 qboxsizer = wx.StaticBoxSizer(qbox, wx.VERTICAL) 303 qboxsizer.SetMinSize((320,20)) 304 305 sizer_q = wx.GridBagSizer(5,5) 306 307 label_qmin = wx.StaticText(self, -1, "Q min") 308 label_qmax = wx.StaticText(self, -1, "Q max") 309 self.qmin_ctl = wx.TextCtrl(self, -1, size=(60,20)) 310 self.qmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) 311 312 iy = 0 313 sizer_q.Add(label_qmin, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 15) 314 sizer_q.Add(self.qmin_ctl, (iy,1), (1,1), wx.LEFT|wx.EXPAND, 10) 315 sizer_q.Add(label_qmax, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 15) 316 sizer_q.Add(self.qmax_ctl, (iy,3), (1,1), wx.LEFT|wx.EXPAND, 10) 317 qboxsizer.Add(sizer_q, wx.TOP, 15) 318 vbox.Add(qboxsizer) 319 320 277 321 278 322 # ----- Results ----- … … 334 378 self.SetSizer(vbox) 335 379 380 381 382 def _on_accept_alpha(self, evt): 383 """ 384 User has accepted the estimated alpha, 385 set it as part of the input parameters 386 """ 387 try: 388 alpha = self.alpha_estimate_ctl.GetLabel() 389 tmp = float(alpha) 390 self.alpha_ctl.SetValue(alpha) 391 except: 392 # No estimate or bad estimate, either do nothing 393 import sys 394 print "InversionControl._on_accept_alpha: %s" % sys.exc_value 395 pass 396 397 336 398 def _on_pars_changed(self, evt): 337 399 """ … … 340 402 scenes. 341 403 """ 342 flag, alpha, dmax, nfunc = self._read_pars()404 flag, alpha, dmax, nfunc, qmin, qmax = self._read_pars() 343 405 344 406 # If the pars are valid, estimate alpha … … 347 409 dataset = self.plot_data.GetValue() 348 410 self.manager.estimate_plot_inversion(alpha=alpha, nfunc=nfunc, 349 d_max=dmax) 411 d_max=dmax, 412 q_min=qmin, q_max=qmax) 350 413 else: 351 414 path = self.data_file.GetValue() 352 415 self.manager.estimate_file_inversion(alpha=alpha, nfunc=nfunc, 353 d_max=dmax, path=path) 354 355 356 def _read_pars(self): 416 d_max=dmax, path=path, 417 q_min=qmin, q_max=qmax) 418 419 420 def _read_pars(self, evt=None): 357 421 alpha = 0 358 422 nfunc = 5 … … 391 455 self.nfunc_ctl.Refresh() 392 456 393 return flag, alpha, dmax, nfunc 457 # Read qmin 458 try: 459 qmin_str = self.qmin_ctl.GetValue() 460 if len(qmin_str.lstrip().rstrip())==0: 461 qmin = None 462 else: 463 qmin = float(qmin_str) 464 self.qmin_ctl.SetBackgroundColour(wx.WHITE) 465 self.qmin_ctl.Refresh() 466 except: 467 flag = False 468 self.qmin_ctl.SetBackgroundColour("pink") 469 self.qmin_ctl.Refresh() 470 471 # Read qmax 472 try: 473 qmax_str = self.qmax_ctl.GetValue() 474 if len(qmax_str.lstrip().rstrip())==0: 475 qmax = None 476 else: 477 qmax = float(qmax_str) 478 self.qmax_ctl.SetBackgroundColour(wx.WHITE) 479 self.qmax_ctl.Refresh() 480 except: 481 flag = False 482 self.qmax_ctl.SetBackgroundColour("pink") 483 self.qmax_ctl.Refresh() 484 485 return flag, alpha, dmax, nfunc, qmin, qmax 394 486 395 487 def _on_invert(self, evt): … … 401 493 # Push it to the manager 402 494 403 flag, alpha, dmax, nfunc = self._read_pars()495 flag, alpha, dmax, nfunc, qmin, qmax = self._read_pars() 404 496 405 497 if flag: … … 407 499 dataset = self.plot_data.GetValue() 408 500 self.manager.setup_plot_inversion(alpha=alpha, nfunc=nfunc, 409 d_max=dmax) 501 d_max=dmax, 502 q_min=qmin, q_max=qmax) 410 503 else: 411 504 path = self.data_file.GetValue() 412 505 self.manager.setup_file_inversion(alpha=alpha, nfunc=nfunc, 413 d_max=dmax, path=path) 506 d_max=dmax, path=path, 507 q_min=qmin, q_max=qmax 508 ) 414 509 415 510 else: -
prview/perspectives/pr/pr.py
r32dffae4 r634f1cf 29 29 self.nfunc = 10 30 30 self.max_length = 140.0 31 self.q_min = None 32 self.q_max = None 31 33 ## Remember last plottable processed 32 34 self.last_data = "sphere_60_q0_2.txt" … … 158 160 maxq=q_i 159 161 160 x = pylab.arange(0.001, maxq, maxq/301.0) 162 minq = 0.001 163 164 # Check for user min/max 165 if not pr.q_min==None: 166 minq = pr.q_min 167 if not pr.q_max==None: 168 maxq = pr.q_max 169 170 x = pylab.arange(minq, maxq, maxq/301.0) 161 171 y = numpy.zeros(len(x)) 162 172 err = numpy.zeros(len(x)) … … 349 359 #result_panel = InversionResults(self.parent, -1, style=wx.RAISED_BORDER) 350 360 351 def setup_plot_inversion(self, alpha, nfunc, d_max ):361 def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None): 352 362 self.alpha = alpha 353 363 self.nfunc = nfunc 354 364 self.max_length = d_max 365 self.q_min = q_min 366 self.q_max = q_max 355 367 356 368 self._create_plot_pr() 357 369 self.perform_inversion() 358 370 359 def estimate_plot_inversion(self, alpha, nfunc, d_max ):371 def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None): 360 372 self.alpha = alpha 361 373 self.nfunc = nfunc 362 374 self.max_length = d_max 375 self.q_min = q_min 376 self.q_max = q_max 363 377 364 378 self._create_plot_pr() … … 375 389 pr.d_max = self.max_length 376 390 pr.alpha = self.alpha 391 pr.q_min = self.q_min 392 pr.q_max = self.q_max 377 393 pr.x = self.current_plottable.x 378 394 pr.y = self.current_plottable.y … … 391 407 392 408 393 def setup_file_inversion(self, alpha, nfunc, d_max, path ):409 def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None): 394 410 self.alpha = alpha 395 411 self.nfunc = nfunc 396 412 self.max_length = d_max 413 self.q_min = q_min 414 self.q_max = q_max 397 415 398 416 self._create_file_pr(path) … … 400 418 self.perform_inversion() 401 419 402 def estimate_file_inversion(self, alpha, nfunc, d_max, path ):420 def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None): 403 421 self.alpha = alpha 404 422 self.nfunc = nfunc 405 423 self.max_length = d_max 424 self.q_min = q_min 425 self.q_max = q_max 406 426 407 427 if self._create_file_pr(path): … … 422 442 pr.d_max = self.max_length 423 443 pr.alpha = self.alpha 444 pr.q_min = self.q_min 445 pr.q_max = self.q_max 424 446 pr.x = x 425 447 pr.y = y -
prview/perspectives/pr/pr_thread.py
r32dffae4 r634f1cf 78 78 79 79 def compute(self): 80 import time 80 """ 81 Calculates the estimate 82 """ 81 83 try: 82 self.starttime = time.time() 83 # If the current alpha is zero, try 84 # another value 85 if self.pr.alpha<=0: 86 self.pr.alpha = 0.0001 87 88 # Perform inversion to find the largest alpha 89 out, cov = self.pr.lstsq(self.nfunc) 90 elapsed = time.time()-self.starttime 91 initial_alpha = self.pr.alpha 92 initial_peaks = self.pr.get_peaks(out) 93 94 # Try the inversion with the estimated alpha 95 self.pr.alpha = self.pr.suggested_alpha 96 out, cov = self.pr.lstsq(self.nfunc) 97 98 npeaks = self.pr.get_peaks(out) 99 # if more than one peak to start with 100 # just return the estimate 101 if npeaks>1: 102 message = "Your P(r) is not smooth, please check your inversion parameters" 103 self.complete(alpha=self.pr.suggested_alpha, message=message, elapsed=elapsed) 104 else: 105 106 # Look at smaller values 107 # We assume that for the suggested alpha, we have 1 peak 108 # if not, send a message to change parameters 109 alpha = self.pr.suggested_alpha 110 best_alpha = self.pr.suggested_alpha 111 found = False 112 for i in range(10): 113 self.pr.alpha = (0.33)**(i+1)*alpha 114 out, cov = self.pr.lstsq(self.nfunc) 115 #osc = self.pr.oscillations(out) 116 #print self.pr.alpha, osc 117 118 peaks = self.pr.get_peaks(out) 119 print self.pr.alpha, peaks 120 if peaks>1: 121 found = True 122 break 123 best_alpha = self.pr.alpha 124 125 # If we didn't find a turning point for alpha and 126 # the initial alpha already had only one peak, 127 # just return that 128 if not found and initial_peaks==1 and initial_alpha<best_alpha: 129 best_alpha = initial_alpha 130 131 # Check whether the size makes sense 132 message=None 133 134 if not found: 135 message = "None" 136 elif best_alpha>=0.5*self.pr.suggested_alpha: 137 # best alpha is too big, return a 138 # reasonable value 139 message = "The estimated alpha for your system is too large. " 140 message += "Try increasing your maximum distance." 141 142 self.complete(alpha=best_alpha, message=None, elapsed=elapsed) 143 84 alpha, message, elapsed = self.pr.estimate_alpha(self.nfunc) 85 self.complete(alpha=alpha, message=message, elapsed=elapsed) 144 86 except: 145 87 if not self.error_func==None: -
prview/perspectives/pr/requirements.txt
r32dffae4 r634f1cf 1 1 1. Thread 2 2 2. Find good defaults. Automate the inversion. 3 -How do we estimate d_max? 4 -How do we estimate alpha? 3 -How do we estimate d_max? Guinier fit? 4 -How do we estimate alpha? [partially done] 5 5 Compute the residuals once and choose a value that brings the reg term up to 6 6 a fraction of the residuals. … … 9 9 5. Create handshake so that a plug-in can set context menu items to its own panels... 10 10 6. Return figure of merit values and suggest the values for d_max and alpha. 11 7. Show time estimate 11 7. Show time estimate [done] 12 12 8. Plot the reg term alone to see what it looks like 13 13 9. Use data loader perspective/plug-in to load data/choose file … … 15 15 11. Define limits of applicability 16 16 12. Return figures of merit 17 13. Errors on output constants 17 13. Errors on output constants [done] 18 18 14. Clean up the InversionDialog 19 19 15. Add online help for inputs and outputs (especially figures of merit)
Note: See TracChangeset
for help on using the changeset viewer.