Changeset 2a92852 in sasview
- Timestamp:
- Jul 1, 2008 2:57:14 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:
- bb03739
- Parents:
- f168d02
- Location:
- prview
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/perspectives/pr/inversion_panel.py
rd6113849 r2a92852 299 299 #panel = wx.Panel(self, -1) 300 300 vbox = wx.BoxSizer(wx.VERTICAL) 301 #vbox.SetMinSize((1000,50)) 301 302 302 303 # ----- I(q) data ----- … … 340 341 341 342 # ----- Add slit parameters ----- 342 if False:343 if True: 343 344 sbox = wx.StaticBox(self, -1, "Slit parameters") 344 345 sboxsizer = wx.StaticBoxSizer(sbox, wx.VERTICAL) … … 355 356 self.sheight_ctl.SetToolTipString("Enter slit height in units of Q or leave blank.") 356 357 self.swidth_ctl.SetToolTipString("Enter slit width in units of Q or leave blank.") 357 self.sheight_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed)358 self.swidth_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed)358 #self.sheight_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 359 #self.swidth_ctl.Bind(wx.EVT_TEXT, self._on_pars_changed) 359 360 360 361 iy = 0 … … 648 649 scenes. 649 650 """ 650 flag, alpha, dmax, nfunc, qmin, qmax = self._read_pars()651 flag, alpha, dmax, nfunc, qmin, qmax, height, width = self._read_pars() 651 652 has_bck = self.bck_chk.IsChecked() 652 653 653 654 # If the pars are valid, estimate alpha 654 655 if flag: 656 self.nterms_estimate_ctl.Enable(False) 657 self.alpha_estimate_ctl.Enable(False) 658 655 659 if self.standalone==False and self.plot_radio.GetValue(): 656 660 dataset = self.plot_data.GetValue() … … 658 662 d_max=dmax, 659 663 q_min=qmin, q_max=qmax, 660 bck=has_bck) 664 bck=has_bck, 665 height=height, 666 width=width) 661 667 else: 662 668 path = self.data_file.GetValue() … … 664 670 d_max=dmax, path=path, 665 671 q_min=qmin, q_max=qmax, 666 bck=has_bck) 672 bck=has_bck, 673 height=height, 674 width=width) 667 675 668 676 … … 673 681 qmin = 0 674 682 qmax = 0 683 height = 0 684 width = 0 675 685 676 686 flag = True 687 688 689 # Read slit height 690 try: 691 height_str = self.sheight_ctl.GetValue() 692 if len(height_str.lstrip().rstrip())==0: 693 height = 0 694 else: 695 height = float(height_str) 696 self.sheight_ctl.SetBackgroundColour(wx.WHITE) 697 self.sheight_ctl.Refresh() 698 except: 699 flag = False 700 self.sheight_ctl.SetBackgroundColour("pink") 701 self.sheight_ctl.Refresh() 702 703 # Read slit width 704 try: 705 width_str = self.swidth_ctl.GetValue() 706 if len(width_str.lstrip().rstrip())==0: 707 width = 0 708 else: 709 width = float(width_str) 710 self.swidth_ctl.SetBackgroundColour(wx.WHITE) 711 self.swidth_ctl.Refresh() 712 except: 713 flag = False 714 self.swidth_ctl.SetBackgroundColour("pink") 715 self.swidth_ctl.Refresh() 677 716 678 717 # Read alpha … … 739 778 self.qmax_ctl.Refresh() 740 779 741 return flag, alpha, dmax, nfunc, qmin, qmax 780 return flag, alpha, dmax, nfunc, qmin, qmax, height, width 742 781 743 782 def _on_invert(self, evt): … … 749 788 # Push it to the manager 750 789 751 flag, alpha, dmax, nfunc, qmin, qmax = self._read_pars()790 flag, alpha, dmax, nfunc, qmin, qmax, height, width = self._read_pars() 752 791 has_bck = self.bck_chk.IsChecked() 753 792 … … 762 801 d_max=dmax, 763 802 q_min=qmin, q_max=qmax, 764 bck=has_bck) 803 bck=has_bck, 804 height=height, 805 width=width) 765 806 else: 766 807 path = self.data_file.GetValue() … … 772 813 d_max=dmax, path=path, 773 814 q_min=qmin, q_max=qmax, 774 bck=has_bck) 815 bck=has_bck, 816 height=height, 817 width=width) 775 818 776 819 else: … … 791 834 self.file_radio.SetValue(True) 792 835 self._on_pars_changed(None) 793 self.manager.show_data(path )836 self.manager.show_data(path, reset=True) 794 837 795 838 -
prview/perspectives/pr/pr.py
rd6113849 r2a92852 12 12 from sans.pr.invertor import Invertor 13 13 14 PR_FIT_LABEL = "P_{fit}(r)" 15 PR_LOADED_LABEL = "P_{loaded}(r)" 16 IQ_DATA_LABEL = "I_{obs}(q)" 14 PR_FIT_LABEL = "P_{fit}(r)" 15 PR_LOADED_LABEL = "P_{loaded}(r)" 16 IQ_DATA_LABEL = "I_{obs}(q)" 17 IQ_FIT_LABEL = "I_{fit}(q)" 18 IQ_SMEARED_LABEL = "I_{smeared}(q)" 17 19 18 20 import wx.lib … … 46 48 self.q_max = None 47 49 self.has_bck = False 50 self.slit_height = 0 51 self.slit_width = 0 48 52 ## Remember last plottable processed 49 53 self.last_data = "sphere_60_q0_2.txt" … … 56 60 self.invertor = None 57 61 self.pr = None 62 self.pr_estimate = None 58 63 ## Calculation thread 59 64 self.calc_thread = None … … 222 227 223 228 new_plot = Theory1D(x, y) 224 new_plot.name = "I_{fit}(q)"229 new_plot.name = IQ_FIT_LABEL 225 230 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 226 231 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 227 232 #new_plot.group_id = "test group" 228 233 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="I(q)")) 234 235 # If we have used slit smearing, plot the smeared I(q) too 236 if pr.slit_width>0 or pr.slit_height>0: 237 x = pylab.arange(minq, maxq, maxq/301.0) 238 y = numpy.zeros(len(x)) 239 err = numpy.zeros(len(x)) 240 for i in range(len(x)): 241 value = pr.iq_smeared(out, x[i]) 242 y[i] = value 243 try: 244 err[i] = math.sqrt(math.fabs(value)) 245 except: 246 err[i] = 1.0 247 print "Error getting error", value, x[i] 248 249 new_plot = Theory1D(x, y) 250 new_plot.name = IQ_SMEARED_LABEL 251 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 252 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 253 #new_plot.group_id = "test group" 254 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="I(q)")) 229 255 230 256 … … 417 443 """ 418 444 # Save useful info 419 print "Number of terms =", nterms420 445 self.elapsed = elapsed 421 446 self.control_panel.nterms_estimate = nterms … … 482 507 #result_panel = InversionResults(self.parent, -1, style=wx.RAISED_BORDER) 483 508 484 def show_data(self, path=None): 509 def show_data(self, path=None, reset=False): 510 """ 511 Show data read from a file 512 @param path: file path 513 @param reset: if True all other plottables will be cleared 514 """ 515 516 485 517 if not path==None: 486 518 self._create_file_pr(path) … … 493 525 new_plot.interactive = True 494 526 #new_plot.group_id = "test group" 495 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="I(q)" ))527 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) 496 528 497 529 # Get Q range … … 501 533 502 534 503 def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, bck=False): 535 def setup_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, 536 bck=False, height=0, width=0): 504 537 self.alpha = alpha 505 538 self.nfunc = nfunc … … 508 541 self.q_max = q_max 509 542 self.has_bck = bck 543 self.slit_height = height 544 self.slit_width = width 510 545 511 546 try: 512 self._create_plot_pr() 513 self.perform_inversion() 547 pr = self._create_plot_pr() 548 if not pr==None: 549 self.pr = pr 550 self.perform_inversion() 514 551 except: 515 552 wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 516 553 517 def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, bck=False): 554 def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, 555 bck=False, height=0, width=0): 518 556 self.alpha = alpha 519 557 self.nfunc = nfunc … … 522 560 self.q_max = q_max 523 561 self.has_bck = bck 562 self.slit_height = height 563 self.slit_width = width 524 564 525 565 try: 526 self._create_plot_pr() 527 self.perform_estimate() 566 pr = self._create_plot_pr() 567 if not pr==None: 568 self.pr = pr 569 self.perform_estimate() 528 570 except: 529 571 wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 530 572 531 def _create_plot_pr(self ):573 def _create_plot_pr(self, estimate=False): 532 574 """ 533 575 Create and prepare invertor instance from … … 544 586 pr.y = self.current_plottable.y 545 587 pr.has_bck = self.has_bck 588 pr.slit_height = self.slit_height 589 pr.slit_width = self.slit_width 546 590 547 591 # Fill in errors if none were provided … … 554 598 else: 555 599 pr.err = self.current_plottable.dy 556 557 self.pr = pr558 self.iq_data_shown = True600 601 #self.pr = pr 602 return pr 559 603 560 604 561 def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, bck=False): 605 def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, 606 bck=False, height=0, width=0): 562 607 self.alpha = alpha 563 608 self.nfunc = nfunc … … 566 611 self.q_max = q_max 567 612 self.has_bck = bck 613 self.slit_height = height 614 self.slit_width = width 568 615 569 616 try: 570 if self._create_file_pr(path): 617 pr = self._create_file_pr(path) 618 if not pr==None: 619 self.pr = pr 571 620 self.perform_inversion() 572 621 except: 573 622 wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 574 623 575 def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, bck=False): 624 def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, 625 bck=False, height=0, width=0): 576 626 self.alpha = alpha 577 627 self.nfunc = nfunc … … 580 630 self.q_max = q_max 581 631 self.has_bck = bck 632 self.slit_height = height 633 self.slit_width = width 582 634 583 635 try: 584 if self._create_file_pr(path): 636 pr = self._create_file_pr(path) 637 if not pr==None: 638 self.pr = pr 585 639 self.perform_estimate() 586 640 except: … … 608 662 pr.err = err 609 663 pr.has_bck = self.has_bck 610 611 self.pr = pr 612 return True 613 return False 664 pr.slit_height = self.slit_height 665 pr.slit_width = self.slit_width 666 return pr 667 #self.pr = pr 668 #return True 669 #return False 670 return None 614 671 615 672 def perform_estimate(self): … … 639 696 640 697 pr = self.pr.clone() 698 # Skip the slit settings for the estimation 699 # It slows down the application and it doesn't change the estimates 700 pr.slit_height = 0.0 701 pr.slit_width = 0.0 641 702 self.estimation_thread = EstimateNT(pr, self.nfunc, error_func=self._thread_error, 642 703 completefn = self._estimateNT_completed, … … 649 710 # Time estimate 650 711 #estimated = self.elapsed*self.nfunc**2 651 message = "Computation time may take up to %g seconds" % self.elapsed652 wx.PostEvent(self.parent, StatusEvent(status=message))712 #message = "Computation time may take up to %g seconds" % self.elapsed 713 #wx.PostEvent(self.parent, StatusEvent(status=message)) 653 714 654 715 # Start inversion thread -
prview/perspectives/pr/pr_thread.py
r35adaf6 r2a92852 44 44 elapsed = time.time()-self.starttime 45 45 self.complete(out=out, cov=cov, pr=self.pr, elapsed=elapsed) 46 except KeyboardInterrupt: 47 # Thread was interrupted, just proceed 48 printEVT("P(r) calc interrupted") 46 49 except: 47 50 if not self.error_func==None: … … 71 74 self.starttime = 0 72 75 73 def isquit(self):74 try:75 CalcThread.isquit(self)76 except KeyboardInterrupt:77 printEVT("Alpha estimator thread interrupted")78 raise KeyboardInterrupt79 80 76 def compute(self): 81 77 """ … … 86 82 self.isquit() 87 83 self.complete(alpha=alpha, message=message, elapsed=elapsed) 84 except KeyboardInterrupt: 85 # Thread was interrupted, just proceed 86 printEVT("Alpha estimator thread interrupted") 88 87 except: 89 88 if not self.error_func==None: 90 printEVT("EstimatePr.compute: %s" % sys.exc_value)89 self.error_func("EstimatePr.compute: %s" % sys.exc_value) 91 90 92 91 class EstimateNT(CalcThread): … … 107 106 self.starttime = 0 108 107 109 def isquit(self):110 try:111 CalcThread.isquit(self)112 except KeyboardInterrupt:113 printEVT("Number of terms thread interrupted")114 raise KeyboardInterrupt115 116 108 def compute(self): 117 109 """ … … 125 117 self.isquit() 126 118 self.complete(nterms=nterms, alpha=alpha, message=message, elapsed=t_1) 119 except KeyboardInterrupt: 120 # Thread was interrupted, just proceed 121 printEVT("Number of terms thread interrupted") 127 122 except: 128 123 if not self.error_func==None: 129 printEVT("EstimatePr2.compute: %s" % sys.exc_value)124 self.error_func("EstimatePr2.compute: %s" % sys.exc_value) 130 125 131 126 -
prview/sansview.py
raa4b8379 r2a92852 14 14 def OnInit(self): 15 15 #from gui_manager import ViewerFrame 16 self.frame = PrFrame(None, -1, local_config.__appname__) 16 self.frame = PrFrame(None, -1, local_config.__appname__, 17 window_height=650, window_width=750) 17 18 self.frame.Show(True) 18 19
Note: See TracChangeset
for help on using the changeset viewer.