Changeset a4bd2ac in sasview for prview/perspectives/pr
- Timestamp:
- Jun 30, 2008 2:18:57 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:
- e96a852
- Parents:
- 9a23253e
- Location:
- prview/perspectives/pr
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/perspectives/pr/inversion_panel.py
r3fd1ebc ra4bd2ac 122 122 123 123 ## Data file TextCtrl 124 self.data_file = None125 self.plot_data = None126 self.nfunc_ctl = None127 self.alpha_ctl = None128 self.dmax_ctl = None129 self.time_ctl = None130 self.chi2_ctl = None131 self.osc_ctl = None124 self.data_file = None 125 self.plot_data = None 126 self.nfunc_ctl = None 127 self.alpha_ctl = None 128 self.dmax_ctl = None 129 self.time_ctl = None 130 self.chi2_ctl = None 131 self.osc_ctl = None 132 132 self.file_radio = None 133 133 self.plot_radio = None 134 134 self.label_sugg = None 135 self.qmin_ctl = None 136 self.qmax_ctl = None 135 self.qmin_ctl = None 136 self.qmax_ctl = None 137 138 self.rg_ctl = None 139 self.iq0_ctl = None 140 self.bck_chk = None 141 self.bck_ctl = None 137 142 138 143 # TextCtrl for fraction of positive P(r) … … 164 169 self.alpha_ctl.SetValue(str(value)) 165 170 elif name=='chi2': 166 self.chi2_ctl.SetValue("%-5.3g" % value) 171 self.chi2_ctl.SetValue("%-5.2g" % value) 172 elif name=='bck': 173 self.bck_ctl.SetValue("%-5.2g" % value) 167 174 elif name=='q_min': 168 self.qmin_ctl.SetValue("%-5. 3g" % value)175 self.qmin_ctl.SetValue("%-5.2g" % value) 169 176 elif name=='q_max': 170 self.qmax_ctl.SetValue("%-5. 3g" % value)177 self.qmax_ctl.SetValue("%-5.2g" % value) 171 178 elif name=='elapsed': 172 179 self.time_ctl.SetValue("%-5.2g" % value) 180 elif name=='rg': 181 self.rg_ctl.SetValue("%-5.2g" % value) 182 elif name=='iq0': 183 self.iq0_ctl.SetValue("%-5.2g" % value) 173 184 elif name=='oscillation': 174 185 self.osc_ctl.SetValue("%-5.2g" % value) … … 219 230 except: 220 231 return -1.0 232 elif name=='bck': 233 try: 234 return float(self.bck_ctl.GetValue()) 235 except: 236 return -1.0 221 237 elif name=='q_min': 222 238 try: … … 232 248 try: 233 249 return float(self.time_ctl.GetValue()) 250 except: 251 return -1.0 252 elif name=='rg': 253 try: 254 return float(self.rg_ctl.GetValue()) 255 except: 256 return -1.0 257 elif name=='iq0': 258 try: 259 return float(self.iq0_ctl.GetValue()) 234 260 except: 235 261 return -1.0 … … 275 301 276 302 iy = 0 277 self.file_radio = wx.RadioButton(self, -1, "File data:") 303 if self.standalone==False: 304 self.file_radio = wx.RadioButton(self, -1, "File data:") 305 else: 306 self.file_radio = wx.StaticText(self, -1, "Data file:") 278 307 self.data_file = wx.TextCtrl(self, -1, size=(100,20)) 279 308 self.data_file.SetEditable(False) … … 283 312 self.Bind(wx.EVT_BUTTON, self._change_file, id = id) 284 313 pars_sizer.Add(self.file_radio, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 285 pars_sizer.Add(self.data_file, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15) 314 #pars_sizer.Add(self.data_file, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15) 315 pars_sizer.Add(self.data_file, (iy,1), (1,1), wx.ADJUST_MINSIZE, 15) 286 316 pars_sizer.Add(choose_button, (iy,3), (1,1), wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 287 317 … … 294 324 pars_sizer.Add(self.plot_data, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15) 295 325 296 boxsizer1.Add(pars_sizer, 0, wx.EXPAND) 326 self.bck_chk = wx.CheckBox(self, -1, "Estimate background level") 327 self.bck_chk.SetToolTipString("Check box to let the fit estimate the constant background level.") 328 self.bck_chk.Bind(wx.EVT_CHECKBOX, self._on_pars_changed) 329 iy += 1 330 pars_sizer.Add(self.bck_chk, (iy,0), (1,2), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 331 boxsizer1.Add(pars_sizer, 0, wx.EXPAND) 297 332 vbox.Add(boxsizer1) 333 334 # ----- Add slit parameters ----- 335 if False: 336 sbox = wx.StaticBox(self, -1, "Slit parameters") 337 sboxsizer = wx.StaticBoxSizer(sbox, wx.VERTICAL) 338 sboxsizer.SetMinSize((320,20)) 339 340 sizer_slit = wx.GridBagSizer(5,5) 341 342 label_sheight = wx.StaticText(self, -1, "Height") 343 label_swidth = wx.StaticText(self, -1, "Width") 344 #label_sunits1 = wx.StaticText(self, -1, "[A^(-1)]") 345 label_sunits2 = wx.StaticText(self, -1, "[A^(-1)]") 346 self.sheight_ctl = wx.TextCtrl(self, -1, size=(60,20)) 347 self.swidth_ctl = wx.TextCtrl(self, -1, size=(60,20)) 348 self.sheight_ctl.SetToolTipString("Enter slit height in units of Q or leave blank.") 349 self.swidth_ctl.SetToolTipString("Enter slit width in units of Q or leave blank.") 350 self.sheight_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 351 self.swidth_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 352 353 iy = 0 354 sizer_slit.Add(label_sheight, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 15) 355 sizer_slit.Add(self.sheight_ctl, (iy,1), (1,1), wx.LEFT|wx.EXPAND, 10) 356 #sizer_slit.Add(label_sunits1, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 10) 357 sizer_slit.Add(label_swidth, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 15) 358 sizer_slit.Add(self.swidth_ctl, (iy,3), (1,1), wx.LEFT|wx.EXPAND, 10) 359 sizer_slit.Add(label_sunits2, (iy,4), (1,1), wx.LEFT|wx.EXPAND, 10) 360 361 sboxsizer.Add(sizer_slit, wx.TOP, 15) 362 vbox.Add(sboxsizer) 363 298 364 299 365 # ----- Parameters ----- … … 335 401 336 402 # EVT_TEXT would trigger an event for each character entered 337 self.nfunc_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed)338 self.alpha_ctl.Bind(wx.EVT_KILL_FOCUS, self._read_pars)339 self.dmax_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed)403 #self.nfunc_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed) 404 #self.alpha_ctl.Bind(wx.EVT_KILL_FOCUS, self._read_pars) 405 #self.dmax_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed) 340 406 #self.dmax_ctl.Bind(wx.EVT_TEXT_ENTER, self._on_pars_changed) 341 407 #self.Bind(wx.EVT_TEXT_ENTER, self._on_pars_changed) 408 409 self.nfunc_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 410 self.alpha_ctl.Bind(wx.EVT_TEXT, self._read_pars) 411 self.dmax_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 412 413 342 414 343 415 sizer_params = wx.GridBagSizer(5,5) … … 369 441 label_qmin = wx.StaticText(self, -1, "Q min") 370 442 label_qmax = wx.StaticText(self, -1, "Q max") 443 #label_qunits1 = wx.StaticText(self, -1, "[A^(-1)]") 444 label_qunits2 = wx.StaticText(self, -1, "[A^(-1)]") 371 445 self.qmin_ctl = wx.TextCtrl(self, -1, size=(60,20)) 372 446 self.qmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) 373 self.qmin_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed) 374 self.qmax_ctl.Bind(wx.EVT_KILL_FOCUS, self._on_pars_changed) 447 self.qmin_ctl.SetToolTipString("Select a lower bound for Q or leave blank.") 448 self.qmax_ctl.SetToolTipString("Select an upper bound for Q or leave blank.") 449 self.qmin_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 450 self.qmax_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 375 451 376 452 iy = 0 377 sizer_q.Add(label_qmin, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 15)453 sizer_q.Add(label_qmin, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 15) 378 454 sizer_q.Add(self.qmin_ctl, (iy,1), (1,1), wx.LEFT|wx.EXPAND, 10) 379 sizer_q.Add(label_qmax, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 15) 455 #sizer_q.Add(label_qunits1, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 15) 456 sizer_q.Add(label_qmax, (iy,2), (1,1), wx.LEFT|wx.EXPAND, 15) 380 457 sizer_q.Add(self.qmax_ctl, (iy,3), (1,1), wx.LEFT|wx.EXPAND, 10) 458 sizer_q.Add(label_qunits2, (iy,4), (1,1), wx.LEFT|wx.EXPAND, 15) 381 459 qboxsizer.Add(sizer_q, wx.TOP, 15) 382 460 vbox.Add(qboxsizer) … … 388 466 ressizer = wx.StaticBoxSizer(resbox, wx.VERTICAL) 389 467 ressizer.SetMinSize((320,50)) 468 469 label_rg = wx.StaticText(self, -1, "Rg") 470 label_rg_unit = wx.StaticText(self, -1, "[A]") 471 label_iq0 = wx.StaticText(self, -1, "I(Q=0)") 472 label_iq0_unit = wx.StaticText(self, -1, "[A^(-1)]") 473 label_bck = wx.StaticText(self, -1, "Background") 474 label_bck_unit = wx.StaticText(self, -1, "[A^(-1)]") 475 self.rg_ctl = wx.TextCtrl(self, -1, size=(60,20)) 476 self.rg_ctl.SetEditable(False) 477 self.rg_ctl.SetToolTipString("Radius of gyration for the computed P(r).") 478 self.iq0_ctl = wx.TextCtrl(self, -1, size=(60,20)) 479 self.iq0_ctl.SetEditable(False) 480 self.iq0_ctl.SetToolTipString("Scattering intensity at Q=0 for the computed P(r).") 481 self.bck_ctl = wx.TextCtrl(self, -1, size=(60,20)) 482 self.bck_ctl.SetEditable(False) 483 self.bck_ctl.SetToolTipString("Value of estimated constant background.") 390 484 391 485 label_time = wx.StaticText(self, -1, "Computation time") … … 427 521 428 522 iy = 0 523 sizer_res.Add(label_rg, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 15) 524 sizer_res.Add(self.rg_ctl, (iy,1), (1,1), wx.RIGHT|wx.EXPAND, 15) 525 sizer_res.Add(label_rg_unit, (iy,2), (1,1), wx.RIGHT|wx.EXPAND, 15) 526 iy += 1 527 sizer_res.Add(label_iq0, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 15) 528 sizer_res.Add(self.iq0_ctl, (iy,1), (1,1), wx.RIGHT|wx.EXPAND, 15) 529 sizer_res.Add(label_iq0_unit, (iy,2), (1,1), wx.RIGHT|wx.EXPAND, 15) 530 iy += 1 531 sizer_res.Add(label_bck, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 15) 532 sizer_res.Add(self.bck_ctl, (iy,1), (1,1), wx.RIGHT|wx.EXPAND, 15) 533 sizer_res.Add(label_bck_unit, (iy,2), (1,1), wx.RIGHT|wx.EXPAND, 15) 534 iy += 1 429 535 sizer_res.Add(label_time, (iy,0), (1,1), wx.LEFT|wx.EXPAND, 15) 430 536 sizer_res.Add(self.time_ctl, (iy,1), (1,1), wx.RIGHT|wx.EXPAND, 15) … … 472 578 473 579 self.SetSizer(vbox) 474 475 476 580 477 581 def _on_accept_alpha(self, evt): … … 500 604 self.qmax_ctl.SetValue("") 501 605 self.time_ctl.SetValue("") 606 self.rg_ctl.SetValue("") 607 self.iq0_ctl.SetValue("") 608 self.bck_ctl.SetValue("") 502 609 self.chi2_ctl.SetValue("") 503 610 self.osc_ctl.SetValue("") … … 515 622 """ 516 623 flag, alpha, dmax, nfunc, qmin, qmax = self._read_pars() 624 has_bck = self.bck_chk.IsChecked() 517 625 518 626 # If the pars are valid, estimate alpha … … 522 630 self.manager.estimate_plot_inversion(alpha=alpha, nfunc=nfunc, 523 631 d_max=dmax, 524 q_min=qmin, q_max=qmax) 632 q_min=qmin, q_max=qmax, 633 bck=has_bck) 525 634 else: 526 635 path = self.data_file.GetValue() 527 636 self.manager.estimate_file_inversion(alpha=alpha, nfunc=nfunc, 528 637 d_max=dmax, path=path, 529 q_min=qmin, q_max=qmax) 638 q_min=qmin, q_max=qmax, 639 bck=has_bck) 530 640 531 641 … … 613 723 614 724 flag, alpha, dmax, nfunc, qmin, qmax = self._read_pars() 725 has_bck = self.bck_chk.IsChecked() 615 726 616 727 if flag: … … 623 734 self.manager.setup_plot_inversion(alpha=alpha, nfunc=nfunc, 624 735 d_max=dmax, 625 q_min=qmin, q_max=qmax) 736 q_min=qmin, q_max=qmax, 737 bck=has_bck) 626 738 else: 627 739 path = self.data_file.GetValue() … … 632 744 self.manager.setup_file_inversion(alpha=alpha, nfunc=nfunc, 633 745 d_max=dmax, path=path, 634 q_min=qmin, q_max=qmax 635 )746 q_min=qmin, q_max=qmax, 747 bck=has_bck) 636 748 637 749 else: … … 649 761 if path and os.path.isfile(path): 650 762 self.data_file.SetValue(str(path)) 651 self.file_radio.SetValue(True) 763 if self.standalone==False: 764 self.file_radio.SetValue(True) 652 765 self._on_pars_changed(None) 653 766 self.manager.show_data(path) -
prview/perspectives/pr/pr.py
r9b85e93 ra4bd2ac 45 45 self.q_min = None 46 46 self.q_max = None 47 self.has_bck = False 47 48 ## Remember last plottable processed 48 49 self.last_data = "sphere_60_q0_2.txt" … … 78 79 """ 79 80 return [] 80 import wx81 shapes = wx.Menu()82 83 id = wx.NewId()84 shapes.Append(id, '&Sphere test')85 wx.EVT_MENU(owner, id, self._fit_pr)86 87 return [(id, shapes, "P(r)")]88 81 89 82 def help(self, evt): … … 440 433 self.control_panel.positive = pr.get_positive(out) 441 434 self.control_panel.pos_err = pr.get_pos_err(out, cov) 435 self.control_panel.rg = pr.rg(out) 436 self.control_panel.iq0 = pr.iq0(out) 437 self.control_panel.bck = pr.background 442 438 443 439 for i in range(len(out)): … … 457 453 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 458 454 455 # Compute the fit I(Q=0) 456 try: 457 print "I(0) = ", self.pr.iq0(out) 458 except: 459 pass 460 461 # Get R_g 462 print "Rg = ", self.pr.rg(out) 459 463 # Show I(q) fit 460 464 self.show_iq(out, self.pr) … … 485 489 486 490 487 def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None ):491 def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, bck=False): 488 492 self.alpha = alpha 489 493 self.nfunc = nfunc … … 491 495 self.q_min = q_min 492 496 self.q_max = q_max 497 self.has_bck = bck 493 498 494 499 try: … … 498 503 wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 499 504 500 def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None ):505 def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, bck=False): 501 506 self.alpha = alpha 502 507 self.nfunc = nfunc … … 504 509 self.q_min = q_min 505 510 self.q_max = q_max 511 self.has_bck = bck 506 512 507 513 try: … … 525 531 pr.x = self.current_plottable.x 526 532 pr.y = self.current_plottable.y 533 pr.has_bck = self.has_bck 527 534 528 535 # Fill in errors if none were provided … … 540 547 541 548 542 def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None ):549 def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, bck=False): 543 550 self.alpha = alpha 544 551 self.nfunc = nfunc … … 546 553 self.q_min = q_min 547 554 self.q_max = q_max 555 self.has_bck = bck 548 556 549 557 try: … … 553 561 wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 554 562 555 def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None ):563 def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, bck=False): 556 564 self.alpha = alpha 557 565 self.nfunc = nfunc … … 559 567 self.q_min = q_min 560 568 self.q_max = q_max 569 self.has_bck = bck 561 570 562 571 try: … … 586 595 pr.y = y 587 596 pr.err = err 597 pr.has_bck = self.has_bck 588 598 589 599 self.pr = pr
Note: See TracChangeset
for help on using the changeset viewer.