- Timestamp:
- Jun 13, 2008 1:10:42 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:
- ad8bcd6
- Parents:
- b00b487
- Location:
- prview/perspectives/pr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/perspectives/pr/inversion_panel.py
r660b1e6 rb659551 414 414 button_OK.SetToolTipString("Perform P(r) inversion.") 415 415 self.Bind(wx.EVT_BUTTON, self._on_invert, id = id) 416 417 id = wx.NewId() 418 button_Reset = wx.Button(self, id, "Reset") 419 button_Reset.SetToolTipString("Reset inversion parameters to default.") 420 self.Bind(wx.EVT_BUTTON, self._on_reset, id = id) 416 421 #button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 417 422 418 423 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 419 424 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 425 sizer_button.Add(button_Reset, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 420 426 sizer_button.Add(button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 421 427 #sizer_button.Add(button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) … … 442 448 pass 443 449 444 445 def _on_pars_changed(self, evt): 450 def _on_reset(self, evt): 451 """ 452 Resets inversion parameters 453 """ 454 self.nfunc = self.manager.DEFAULT_NFUNC 455 self.d_max = self.manager.DEFAULT_DMAX 456 self.alpha = self.manager.DEFAULT_ALPHA 457 self.qmin_ctl.SetValue("") 458 self.qmax_ctl.SetValue("") 459 self.time_ctl.SetValue("") 460 self.chi2_ctl.SetValue("") 461 self.osc_ctl.SetValue("") 462 self.pos_ctl.SetValue("") 463 self.pos_err_ctl.SetValue("") 464 self.alpha_estimate_ctl.Enable(False) 465 self.alpha_estimate_ctl.SetLabel("") 466 self._on_pars_changed() 467 468 def _on_pars_changed(self, evt=None): 446 469 """ 447 470 Called when an input parameter has changed … … 495 518 try: 496 519 nfunc = int(self.nfunc_ctl.GetValue()) 520 npts = self.manager.get_npts() 521 if npts>0 and nfunc>npts: 522 message = "Number of function terms should be smaller than the number of points" 523 wx.PostEvent(self.manager.parent, StatusEvent(status=message)) 524 raise ValueError, message 497 525 self.nfunc_ctl.SetBackgroundColour(wx.WHITE) 498 526 self.nfunc_ctl.Refresh() … … 610 638 self.Centre() 611 639 640 class PrDistDialog(wx.Dialog): 641 """ 642 Property dialog to let the user change the number 643 of points on the P(r) plot. 644 """ 645 def __init__(self, parent, id): 646 from sans.pr.invertor import help 647 wx.Dialog.__init__(self, parent, id, size=(250, 120)) 648 self.SetTitle("P(r) distribution") 649 650 651 vbox = wx.BoxSizer(wx.VERTICAL) 652 653 label_npts = wx.StaticText(self, -1, "Number of points") 654 self.npts_ctl = wx.TextCtrl(self, -1, size=(100,20)) 655 656 pars_sizer = wx.GridBagSizer(5,5) 657 iy = 0 658 pars_sizer.Add(label_npts, (iy,0), (1,1), wx.LEFT, 15) 659 pars_sizer.Add(self.npts_ctl, (iy,1), (1,1), wx.RIGHT, 0) 660 661 vbox.Add(pars_sizer, 0, wx.ALL|wx.EXPAND, 15) 662 663 664 static_line = wx.StaticLine(self, -1) 665 vbox.Add(static_line, 0, wx.EXPAND, 0) 666 667 button_OK = wx.Button(self, wx.ID_OK, "OK") 668 self.Bind(wx.EVT_BUTTON, self._checkValues, button_OK) 669 button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 670 671 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 672 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 673 sizer_button.Add(button_OK, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 674 sizer_button.Add(button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 675 vbox.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 676 677 self.SetSizer(vbox) 678 self.SetAutoLayout(True) 679 680 self.Layout() 681 self.Centre() 682 683 def _checkValues(self, event): 684 """ 685 Check the dialog content. 686 """ 687 flag = True 688 try: 689 int(self.npts_ctl.GetValue()) 690 self.npts_ctl.SetBackgroundColour(wx.WHITE) 691 self.npts_ctl.Refresh() 692 except: 693 flag = False 694 self.npts_ctl.SetBackgroundColour("pink") 695 self.npts_ctl.Refresh() 696 if flag: 697 event.Skip(True) 698 699 def get_content(self): 700 """ 701 Return the content of the dialog. 702 At this point the values have already been 703 checked. 704 """ 705 value = int(self.npts_ctl.GetValue()) 706 return value 707 708 def set_content(self, npts): 709 """ 710 Initialize the content of the dialog. 711 """ 712 self.npts_ctl.SetValue("%i" % npts) 713 612 714 613 715 class ParsDialog(wx.Panel): … … 751 853 def OnInit(self): 752 854 wx.InitAllImageHandlers() 753 dialog = HelpDialog(None, -1)855 dialog = PrDistDialog(None, -1) 754 856 if dialog.ShowModal() == wx.ID_OK: 755 857 pass -
prview/perspectives/pr/pr.py
r660b1e6 rb659551 13 13 class Plugin: 14 14 15 DEFAULT_ALPHA = 0.0001 16 DEFAULT_NFUNC = 10 17 DEFAULT_DMAX = 140.0 18 15 19 def __init__(self): 16 20 ## Plug-in name … … 27 31 28 32 ## State data 29 self.alpha = 0.000130 self.nfunc = 1031 self.max_length = 140.033 self.alpha = self.DEFAULT_ALPHA 34 self.nfunc = self.DEFAULT_NFUNC 35 self.max_length = self.DEFAULT_DMAX 32 36 self.q_min = None 33 37 self.q_max = None … … 48 52 ## Currently views plottable 49 53 self.current_plottable = None 54 ## Number of P(r) points to display on the output plot 55 self._pr_npts = 51 50 56 51 57 def populate_menu(self, id, owner): … … 118 124 119 125 # Show input P(r) 120 new_plot = Data1D(pr.x, pr.y, pr.err)126 new_plot = Data1D(pr.x, pr.y, dy=pr.err) 121 127 new_plot.name = "P_{obs}(r)" 122 128 new_plot.xaxis("\\rm{r}", 'A') … … 157 163 #Put this call in plottables/guitools 158 164 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Sphere P(r)")) 165 166 def get_npts(self): 167 """ 168 Returns the number of points in the I(q) data 169 """ 170 try: 171 return len(self.pr.x) 172 except: 173 return 0 159 174 160 175 def show_iq(self, out, pr, q=None): … … 203 218 204 219 220 def _on_pr_npts(self, evt): 221 """ 222 Redisplay P(r) with a different number of points 223 """ 224 from inversion_panel import PrDistDialog 225 dialog = PrDistDialog(None, -1) 226 dialog.set_content(self._pr_npts) 227 if dialog.ShowModal() == wx.ID_OK: 228 self._pr_npts= dialog.get_content() 229 dialog.Destroy() 230 self.show_pr(self.pr.out, self.pr, self.pr.cov) 231 else: 232 dialog.Destroy() 205 233 206 234 … … 213 241 214 242 # Show P(r) 215 x = pylab.arange(0.0, pr.d_max, pr.d_max/ 51.0)243 x = pylab.arange(0.0, pr.d_max, pr.d_max/self._pr_npts) 216 244 217 245 y = numpy.zeros(len(x)) … … 253 281 return self.parent.choose_file() 254 282 255 def load(self, path = "sphere_ test_data.txt"):283 def load(self, path = "sphere_60_q0_2.txt"): 256 284 import numpy, math, sys 257 285 # Read the data from the data file … … 259 287 data_y = numpy.zeros(0) 260 288 data_err = numpy.zeros(0) 289 scale = None 290 min_err = 0.0 261 291 if not path == None: 262 292 input_f = open(path,'r') … … 268 298 x = float(toks[0]) 269 299 y = float(toks[1]) 270 try: 271 scale = 0.05/math.sqrt(data_x[0]) 272 except: 273 scale = 1.0 274 #data_err = numpy.append(data_err, 10.0*math.sqrt(y)+1000.0) 300 if len(toks)>2: 301 err = float(toks[2]) 302 else: 303 if scale==None: 304 scale = 0.05*math.sqrt(y) 305 #scale = 0.05/math.sqrt(y) 306 min_err = 0.01*y 307 err = scale*math.sqrt(y)+min_err 308 #err = 0 309 275 310 data_x = numpy.append(data_x, x) 276 311 data_y = numpy.append(data_y, y) 277 data_err = numpy.append(data_err, scale*math.sqrt(math.fabs(y)))312 data_err = numpy.append(data_err, err) 278 313 except: 279 print "Error reading line: ", line 280 print sys.exc_value 314 pass 281 315 282 print "Lines read:", len(data_x) 283 return data_x, data_y, data_err 316 return data_x, data_y, data_err 284 317 285 318 def pr_theory(self, r, R): … … 303 336 304 337 return [["Compute P(r)", "Compute P(r) from distribution", self._on_context_inversion], 305 ["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data]] 338 ["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data], 339 ["Change number of P(r) points", "Change the number of points on the P(r) output", self._on_pr_npts]] 306 340 307 341 return [["Compute P(r)", "Compute P(r) from distribution", self._on_context_inversion]] … … 318 352 x, y, err = self.parent.load_ascii_1D(path) 319 353 320 new_plot = Data1D(x, y, dy=err) 354 #new_plot = Data1D(x, y, dy=err) 355 new_plot = Theory1D(x, y) 321 356 new_plot.name = "P_{loaded}(r)" 322 357 new_plot.xaxis("\\rm{r}", 'A') … … 369 404 # Save useful info 370 405 self.elapsed = elapsed 406 # Save Pr invertor 407 self.pr = pr 408 371 409 message = "Computation completed in %g seconds [chi2=%g]" % (elapsed, pr.chi2) 372 410 wx.PostEvent(self.parent, StatusEvent(status=message)) … … 387 425 print "%d: %g +- %g" % (i, out[i], math.sqrt(math.fabs(cov[i][i]))) 388 426 except: 427 print sys.exc_value 389 428 print "%d: %g +- ?" % (i, out[i]) 390 429 391 430 # Make a plot of I(q) data 392 new_plot = Data1D(self.pr.x, self.pr.y, self.pr.err)431 new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) 393 432 new_plot.name = "I_{obs}(q)" 394 433 new_plot.xaxis("\\rm{Q}", 'A^{-1}') … … 411 450 412 451 # Make a plot of I(q) data 413 new_plot = Data1D(self.pr.x, self.pr.y, self.pr.err)452 new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) 414 453 new_plot.name = "I_{obs}(q)" 415 454 new_plot.xaxis("\\rm{Q}", 'A^{-1}')
Note: See TracChangeset
for help on using the changeset viewer.