Changeset 32dffae4 in sasview for prview/perspectives
- Timestamp:
- May 8, 2008 7:20:22 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:
- f71287f4
- Parents:
- 4f63160
- Location:
- prview/perspectives/pr
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/perspectives/pr/inversion_panel.py
rf3d51f6 r32dffae4 150 150 self.osc_ctl.SetValue("%-5.2g" % value) 151 151 elif name=='alpha_estimate': 152 self.alpha_estimate_ctl.SetValue("%- 5.2g" % value)152 self.alpha_estimate_ctl.SetValue("%-3.1g" % value) 153 153 elif name=='plotname': 154 154 self.plot_data.SetValue(str(value)) … … 226 226 boxsizer2.SetMinSize((320,50)) 227 227 228 explanation = "P(r) is found by fitting a set of base functions to I(Q). " 229 explanation += "The minimization involves a regularization term to ensure " 230 explanation += "a smooth P(r). The alpha parameter gives the size of that " 231 explanation += "term. The suggested value is the value above which the" 232 explanation += "output P(r) will have only one peak." 233 label_explain = wx.StaticText(self, -1, explanation, size=(280,80)) 234 boxsizer2.Add(label_explain, wx.LEFT|wx.BOTTOM, 5) 235 236 237 228 238 label_nfunc = wx.StaticText(self, -1, "Number of terms") 229 239 label_nfunc.SetMinSize((120,20)) … … 233 243 234 244 self.nfunc_ctl = wx.TextCtrl(self, -1, size=(60,20)) 245 self.nfunc_ctl.SetToolTipString("Number of terms in the expansion.") 235 246 self.alpha_ctl = wx.TextCtrl(self, -1, size=(60,20)) 247 self.alpha_ctl.SetToolTipString("Control parameter for the size of the regularization term.") 236 248 self.dmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) 249 self.dmax_ctl.SetToolTipString("Maximum distance between any two points in the system.") 237 250 self.alpha_estimate_ctl = wx.TextCtrl(self, -1, size=(60,20)) 238 251 self.alpha_estimate_ctl.Enable(False) 252 self.alpha_estimate_ctl.SetToolTipString("Value of alpha below which P(r) may have multiple peaks.") 239 253 240 254 # EVT_TEXT would trigger an event for each character entered … … 247 261 248 262 iy = 0 249 sizer_params.Add(label_sugg, (iy,2), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15)250 iy += 1 251 sizer_params.Add(label_nfunc, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)252 sizer_params.Add(self.nfunc_ctl, (iy,1), (1,1), wx.RIGHT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)253 iy += 1 254 sizer_params.Add(label_alpha, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)255 sizer_params.Add(self.alpha_ctl, (iy,1), (1,1), wx.RIGHT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)256 sizer_params.Add(self.alpha_estimate_ctl, (iy,2), (1,1), wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)257 iy += 1 258 sizer_params.Add(label_dmax, (iy,0), (1,1), wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)259 sizer_params.Add(self.dmax_ctl, (iy,1), (1,1), wx.RIGHT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)263 sizer_params.Add(label_sugg, (iy,2), (1,1), wx.LEFT, 15) 264 iy += 1 265 sizer_params.Add(label_nfunc, (iy,0), (1,1), wx.LEFT, 15) 266 sizer_params.Add(self.nfunc_ctl, (iy,1), (1,1), wx.RIGHT, 0) 267 iy += 1 268 sizer_params.Add(label_alpha, (iy,0), (1,1), wx.LEFT, 15) 269 sizer_params.Add(self.alpha_ctl, (iy,1), (1,1), wx.RIGHT, 0) 270 sizer_params.Add(self.alpha_estimate_ctl, (iy,2), (1,1), wx.LEFT, 15) 271 iy += 1 272 sizer_params.Add(label_dmax, (iy,0), (1,1), wx.LEFT, 15) 273 sizer_params.Add(self.dmax_ctl, (iy,1), (1,1), wx.RIGHT, 0) 260 274 261 275 boxsizer2.Add(sizer_params, 0) … … 275 289 self.time_ctl = wx.TextCtrl(self, -1, size=(60,20)) 276 290 self.time_ctl.SetEditable(False) 291 self.time_ctl.SetToolTipString("Computation time for the last inversion, in seconds.") 292 277 293 self.chi2_ctl = wx.TextCtrl(self, -1, size=(60,20)) 278 294 self.chi2_ctl.SetEditable(False) 295 self.chi2_ctl.SetToolTipString("Chi^2 over degrees of freedom.") 296 279 297 self.osc_ctl = wx.TextCtrl(self, -1, size=(60,20)) 280 298 self.osc_ctl.SetEditable(False) 299 self.osc_ctl.SetToolTipString("Oscillation parameter. P(r) for a sphere has an oscillation parameter of 1.1.") 281 300 282 301 sizer_res = wx.GridBagSizer(5,5) … … 302 321 id = wx.NewId() 303 322 button_OK = wx.Button(self, id, "Compute") 323 button_OK.SetToolTipString("Perform P(r) inversion.") 304 324 self.Bind(wx.EVT_BUTTON, self._on_invert, id = id) 305 325 #button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") -
prview/perspectives/pr/pr.py
rf3d51f6 r32dffae4 291 291 wx.PostEvent(self.parent, StatusEvent(status=error)) 292 292 293 def _estimate_completed(self, alpha, elapsed):293 def _estimate_completed(self, alpha, message, elapsed): 294 294 """ 295 295 Parameter estimation completed, … … 301 301 self.elapsed = elapsed 302 302 self.control_panel.alpha_estimate = alpha 303 if not message==None: 304 wx.PostEvent(self.parent, StatusEvent(status=str(message))) 303 305 304 306 def _completed(self, out, cov, pr, elapsed): … … 322 324 self.control_panel.oscillation = pr.oscillations(out) 323 325 #print "OSCILL", pr.oscillations(out) 326 print "PEAKS:", pr.get_peaks(out) 324 327 325 328 for i in range(len(out)): … … 428 431 429 432 def perform_estimate(self): 430 print "ESTIMATE"431 433 from pr_thread import EstimatePr 432 434 from copy import deepcopy 433 435 436 wx.PostEvent(self.parent, StatusEvent(status='')) 434 437 # If a thread is already started, stop it 435 438 if self.estimation_thread != None and self.estimation_thread.isrunning(): … … 548 551 [Somehow openGL needs this call] 549 552 """ 550 pass551 553 self.parent.set_perspective(self.perspective) 554 -
prview/perspectives/pr/pr_thread.py
rf3d51f6 r32dffae4 75 75 except KeyboardInterrupt: 76 76 printEVT("P(r) calc interrupted") 77 raise KeyboardInterrupt 77 raise KeyboardInterrupt 78 78 79 79 def compute(self): 80 80 import time 81 try: 82 83 print "Alpha Oscill" 84 81 try: 85 82 self.starttime = time.time() 86 83 # If the current alpha is zero, try … … 89 86 self.pr.alpha = 0.0001 90 87 88 # Perform inversion to find the largest alpha 91 89 out, cov = self.pr.lstsq(self.nfunc) 92 90 elapsed = time.time()-self.starttime 93 91 initial_alpha = self.pr.alpha 92 initial_peaks = self.pr.get_peaks(out) 94 93 95 # Take the default and try to find 96 # a better value 97 best_alpha = self.pr.alpha 98 best_osc = self.pr.oscillations(out) 99 100 print best_alpha, best_osc 101 102 alpha = self.pr.suggested_alpha 103 print "initial:", alpha 94 # Try the inversion with the estimated alpha 95 self.pr.alpha = self.pr.suggested_alpha 96 out, cov = self.pr.lstsq(self.nfunc) 104 97 105 # Look at smaller values 106 for i in range(5): 107 self.pr.alpha = (0.1)**(i)*alpha 108 out, cov = self.pr.lstsq(self.nfunc) 109 osc = self.pr.oscillations(out) 110 print self.pr.alpha, osc 111 if osc < best_osc: 112 best_osc = osc 113 best_alpha = alpha 114 115 ## Look at larger values 116 #for i in range(4): 117 # self.pr.alpha = (10.0)**(i+1)*alpha 118 # out, cov = self.pr.lstsq(self.nfunc) 119 # osc = self.pr.oscillations(out) 120 # print self.pr.alpha, osc 121 # if osc < best_osc: 122 # best_osc = osc 123 # best_alpha = alpha 124 125 126 self.complete(alpha=best_alpha, elapsed=elapsed) 127 128 129 130 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 131 144 except: 132 145 if not self.error_func==None: -
prview/perspectives/pr/requirements.txt
rf3d51f6 r32dffae4 18 18 14. Clean up the InversionDialog 19 19 15. Add online help for inputs and outputs (especially figures of merit) 20 16. Add help text to the interface (description of what we are minimizing, to explain alpha and nfunc).
Note: See TracChangeset
for help on using the changeset viewer.