- Timestamp:
- Jan 21, 2011 12:44:46 PM (14 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:
- f444b20
- Parents:
- 8dc02d8b
- Location:
- prview
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/PrView.py
r43db4a8 r75df58b 6 6 import local_config 7 7 import sys 8 from perspectives.pr.pr import NewPrFileEvent 8 9 9 10 10 # Application dimensions … … 18 18 """ 19 19 """ 20 wx.PostEvent(self, NewPrFileEvent()) 20 pass 21 21 22 22 23 class PrApp(gui_manager.ViewApp): -
prview/perspectives/pr/inversion_panel.py
r3e41f43 r75df58b 10 10 import logging 11 11 from wx.lib.scrolledpanel import ScrolledPanel 12 from sans.guicomm.events import StatusEvent 12 from sans.guiframe.events import StatusEvent 13 from sans.guiframe.panel_base import PanelBase 13 14 from inversion_state import InversionState 14 15 from pr_widgets import PrTextCtrl … … 18 19 19 20 20 class InversionControl(ScrolledPanel ):21 class InversionControl(ScrolledPanel, PanelBase): 21 22 """ 22 23 """ … … 35 36 """ 36 37 ScrolledPanel.__init__(self, parent, id=id, **kwargs) 38 PanelBase.__init__(self) 37 39 self.SetupScrolling() 38 40 … … 72 74 self.alpha_estimate_ctl = None 73 75 self.nterms_estimate_ctl = None 74 75 76 ## D_max distance explorator 76 77 self.distance_explorator_ctl = None 77 78 78 ## Data manager 79 79 self.manager = None 80 81 80 ## Standalone flage 82 81 self.standalone = standalone 83 84 82 ## Default file location for save 85 83 self._default_save_location = os.getcwd() 86 87 88 84 # Default width 89 85 self._default_width = 350 … … 578 574 hint_msg = "Radius of gyration for the computed P(r)." 579 575 self.rg_ctl.SetToolTipString(hint_msg) 580 self.iq0_ctl = OutputTextCtrl(self, -1, size=(60, 20))576 self.iq0_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 581 577 hint_msg = "Scattering intensity at Q=0 for the computed P(r)." 582 578 self.iq0_ctl.SetToolTipString(hint_msg) 583 self.bck_ctl = OutputTextCtrl(self, -1, size=(60, 20))579 self.bck_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 584 580 self.bck_ctl.SetToolTipString("Value of estimated constant background.") 585 581 … … 592 588 label_pos_err = wx.StaticText(self, -1, "1-sigma positive fraction") 593 589 594 self.time_ctl = OutputTextCtrl(self, -1, size=(60, 20))590 self.time_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 595 591 hint_msg = "Computation time for the last inversion, in seconds." 596 592 self.time_ctl.SetToolTipString(hint_msg) 597 593 598 self.chi2_ctl = OutputTextCtrl(self, -1, size=(60, 20))594 self.chi2_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 599 595 self.chi2_ctl.SetToolTipString("Chi^2 over degrees of freedom.") 600 596 601 597 # Oscillation parameter 602 self.osc_ctl = OutputTextCtrl(self, -1, size=(60, 20))598 self.osc_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 603 599 hint_msg = "Oscillation parameter. P(r) for a sphere has an " 604 600 hint_msg += " oscillation parameter of 1.1." … … 606 602 607 603 # Positive fraction figure of merit 608 self.pos_ctl = OutputTextCtrl(self, -1, size=(60, 20))604 self.pos_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 609 605 hint_msg = "Fraction of P(r) that is positive. " 610 606 hint_msg += "Theoretically, P(r) is defined positive." … … 612 608 613 609 # 1-simga positive fraction figure of merit 614 self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60, 20))610 self.pos_err_ctl = OutputTextCtrl(self, -1, size=(60, 20)) 615 611 message = "Fraction of P(r) that is at least 1 standard deviation" 616 612 message += " greater than zero.\n" … … 775 771 height = 0 776 772 width = 0 777 778 773 flag = True 779 780 781 774 # Read slit height 782 775 try: … … 917 910 wx.PostEvent(self.parent, StatusEvent(status=message)) 918 911 919 def _change_file(self, evt=None, filepath=None ):912 def _change_file(self, evt=None, filepath=None, data=None): 920 913 """ 921 914 Choose a new input file for I(q) 922 915 """ 923 import os 924 if not self.manager==None: 925 path = self.manager.choose_file(path=filepath) 926 927 if path and os.path.isfile(path): 928 self.plot_data.SetValue(str(path)) 929 try: 930 self.manager.show_data(path, reset=True) 931 self._on_pars_changed(None) 932 933 # Perform inversion 934 if self.standalone == True: 935 self._on_invert(None) 936 except: 937 # Invalid data 938 msg = "InversionControl._change_file: %s" % sys.exc_value 939 logging.error(msg) 916 if not self.manager is None: 917 self.plot_data.SetValue(str(data.name)) 918 try: 919 self.manager.show_data(data=data, reset=True) 920 self._on_pars_changed(None) 921 self._on_invert(None) 922 except: 923 msg = "InversionControl._change_file: %s" % sys.exc_value 924 logging.error(msg) 940 925 941 926 class HelpDialog(wx.Dialog): … … 954 939 explanation = help() 955 940 956 label_explain = wx.StaticText(self, -1, explanation, size=(350, 320))941 label_explain = wx.StaticText(self, -1, explanation, size=(350, 320)) 957 942 958 943 vbox.Add(label_explain, 0, wx.ALL|wx.EXPAND, 15) … … 991 976 992 977 label_npts = wx.StaticText(self, -1, "Number of points") 993 self.npts_ctl = PrTextCtrl(self, -1, size=(100, 20))978 self.npts_ctl = PrTextCtrl(self, -1, size=(100, 20)) 994 979 995 pars_sizer = wx.GridBagSizer(5, 5)980 pars_sizer = wx.GridBagSizer(5, 5) 996 981 iy = 0 997 pars_sizer.Add(label_npts, (iy,0), (1,1), wx.LEFT, 15)998 pars_sizer.Add(self.npts_ctl, (iy,1), (1,1), wx.RIGHT, 0)982 pars_sizer.Add(label_npts, (iy, 0), (1, 1), wx.LEFT, 15) 983 pars_sizer.Add(self.npts_ctl, (iy, 1), (1, 1), wx.RIGHT, 0) 999 984 1000 985 vbox.Add(pars_sizer, 0, wx.ALL|wx.EXPAND, 15) 1001 1002 986 1003 987 static_line = wx.StaticLine(self, -1) -
prview/perspectives/pr/pr.py
r3e41f43 r75df58b 19 19 import logging 20 20 import time 21 from sans.guiframe.dataFitting import Data1D, Theory1D 22 from sans.guicomm.events import NewPlotEvent, StatusEvent 23 import math, numpy 21 import copy 22 import math 23 import numpy 24 import pylab 25 from sans.guiframe.dataFitting import Data1D 26 from sans.guiframe.dataFitting import Theory1D 27 from sans.guiframe.events import NewPlotEvent 28 from sans.guiframe.events import StatusEvent 29 24 30 from sans.pr.invertor import Invertor 25 31 from DataLoader.loader import Loader 32 from DataLoader.data_info import Data1D as LoaderData1D 26 33 import DataLoader 27 34 from sans.guiframe.data_loader import load_error 28 29 import copy 35 from sans.guiframe.plugin_base import PluginBase 36 30 37 31 38 PR_FIT_LABEL = r"$P_{fit}(r)$" … … 35 42 IQ_SMEARED_LABEL = r"$I_{smeared}(q)$" 36 43 37 import wx.lib38 (NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent()39 40 from sans.guiframe.plugin_base import PluginBase 44 #import wx.lib 45 #(NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent() 46 47 41 48 42 49 class Plugin(PluginBase): … … 169 176 """ 170 177 from sans.pr.invertor import Invertor 171 import numpy 172 import pylab 173 import math 174 from sans.guicomm.events import NewPlotEvent 175 from danse.common.plottools import Data1D, Theory1D 178 179 from danse.common.plottools import Data1D as PlotData1D 180 from danse.common.plottools import Theory1D as Theory1D 176 181 177 182 # Generate P(r) for sphere … … 205 210 206 211 # Show input P(r) 207 new_plot = Data1D(pr.x, pr.y, dy=pr.err)212 new_plot = PlotData1D(pr.x, pr.y, dy=pr.err) 208 213 new_plot.name = "P_{obs}(r)" 209 214 new_plot.xaxis("\\rm{r}", 'A') 210 215 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 216 print "_fit_pr" 211 217 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Pr")) 212 218 … … 221 227 """ 222 228 """ 223 import numpy 224 import pylab 225 import math 226 from sans.guicomm.events import NewPlotEvent 227 from danse.common.plottools import Data1D, Theory1D 229 from danse.common.plottools import Theory1D as PlotTheory1D 228 230 # Show P(r) 229 231 y_true = numpy.zeros(len(x)) … … 237 239 238 240 # Show the theory P(r) 239 new_plot = Theory1D(x, y_true)241 new_plot = PlotTheory1D(x, y_true) 240 242 new_plot.name = "P_{true}(r)" 241 243 new_plot.xaxis("\\rm{r}", 'A') 242 244 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 243 245 244 245 246 #Put this call in plottables/guitools 246 247 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Sphere P(r)")) 248 247 249 248 250 def get_npts(self): … … 257 259 def show_iq(self, out, pr, q=None): 258 260 """ 259 """ 260 import numpy 261 import pylab 262 import math 263 from sans.guicomm.events import NewPlotEvent 264 from danse.common.plottools import Data1D, Theory1D 261 """ 262 from danse.common.plottools import Theory1D as PlotTheory1D 265 263 266 264 qtemp = pr.x … … 294 292 print "Error getting error", value, x[i] 295 293 296 new_plot = Theory1D(x, y)294 new_plot = PlotTheory1D(x, y) 297 295 new_plot.name = IQ_FIT_LABEL 298 296 new_plot.xaxis("\\rm{Q}", 'A^{-1}') … … 348 346 def show_pr(self, out, pr, cov=None): 349 347 """ 350 """ 351 import numpy 352 import pylab 353 import math 354 from sans.guicomm.events import NewPlotEvent 355 from danse.common.plottools import Data1D, Theory1D 348 """ 349 from danse.common.plottools import Data1D as PlotData1D 350 from danse.common.plottools import Theory1D as PlotTheory1D 356 351 357 352 # Show P(r) … … 387 382 388 383 if cov2==None: 389 new_plot = Theory1D(x, y)384 new_plot = PlotTheory1D(x, y) 390 385 else: 391 new_plot = Data1D(x, y, dy=dy)386 new_plot = PlotData1D(x, y, dy=dy) 392 387 new_plot.name = PR_FIT_LABEL 393 388 new_plot.xaxis("\\rm{r}", 'A') 394 389 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 390 new_plot.title = "P(r) fit" 395 391 # Make sure that the plot is linear 396 392 new_plot.xtransform="x" … … 400 396 return x, pr.d_max 401 397 402 403 def choose_file(self, path=None): 404 """ 405 """ 406 #TODO: this should be in a common module 407 return self.parent.choose_file(path=path) 408 409 410 def load(self, path): 398 399 def load(self, data): 411 400 """ 412 401 Load data. This will eventually be replaced … … 422 411 self.path = path 423 412 424 self._current_file_data = FileData( path)413 self._current_file_data = FileData(data.path) 425 414 426 415 # Use data loader to load file 427 dataread = Loader().load(path)428 416 #dataread = Loader().load(path) 417 dataread = data 429 418 # Notify the user if we could not read the file 430 419 if dataread is None: … … 574 563 #if graph.selected_plottable==IQ_DATA_LABEL: 575 564 for item in graph.plottables: 576 if item.name==PR_FIT_LABEL: 577 m_list = [["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data], 578 ["Change number of P(r) points", "Change the number of points on the P(r) output", self._on_pr_npts]] 579 580 if self._scale_output_unity==True or self._normalize_output==True: 581 m_list.append(["Disable P(r) scaling", 582 "Let the output P(r) keep the scale of the data", 565 if item.name == PR_FIT_LABEL: 566 #add_data_hint = "Load a data file and display it on this plot" 567 #["Add P(r) data",add_data_hint , self._on_add_data], 568 change_n_hint = "Change the number of" 569 change_n_hint += " points on the P(r) output" 570 change_n_label = "Change number of P(r) points" 571 m_list = [[change_n_label, change_n_hint , self._on_pr_npts]] 572 573 if self._scale_output_unity or self._normalize_output: 574 hint = "Let the output P(r) keep the scale of the data" 575 m_list.append(["Disable P(r) scaling", hint, 583 576 self._on_disable_scaling]) 584 585 if self._scale_output_unity==False: 577 if not self._scale_output_unity: 586 578 m_list.append(["Scale P_max(r) to unity", 587 579 "Scale P(r) so that its maximum is 1", 588 580 self._on_scale_unity]) 589 590 if self._normalize_output==False: 581 if not self._normalize_output: 591 582 m_list.append(["Normalize P(r) to unity", 592 583 "Normalize the integral of P(r) to 1", … … 594 585 595 586 return m_list 596 #return [["Add P(r) data", "Load a data file and display it on this plot", self._on_add_data], 597 # ["Change number of P(r) points", "Change the number of points on the P(r) output", self._on_pr_npts]] 598 599 elif item.name==graph.selected_plottable: 600 #TODO: we might want to check that the units are consistent with I(q) 601 # before allowing this menu item 602 if not self.standalone and issubclass(item.__class__, DataLoader.data_info.Data1D): 603 return [["Compute P(r)", "Compute P(r) from distribution", self._on_context_inversion]] 587 #return [["Add P(r) data", 588 #"Load a data file and display it on this plot", 589 # self._on_add_data], 590 # ["Change number of P(r) points", 591 # "Change the number of points on the P(r) output", 592 # self._on_pr_npts]] 593 594 elif item.name == graph.selected_plottable: 595 #TODO: we might want to check that the units are 596 # consistent with I(q) before allowing this menu item 597 if not self.standalone and \ 598 issubclass(item.__class__, DataLoader.data_info.Data1D): 599 return [["Compute P(r)", 600 "Compute P(r) from distribution", 601 self._on_context_inversion]] 604 602 605 603 return [] … … 619 617 for plot in self._added_plots: 620 618 self._added_plots[plot].y = numpy.copy(self._default_Iq[plot]) 621 wx.PostEvent(self.parent, NewPlotEvent(plot=self._added_plots[plot], 622 title=self._added_plots[plot].name, 619 wx.PostEvent(self.parent, 620 NewPlotEvent(plot=self._added_plots[plot], 621 title=self._added_plots[plot].name, 623 622 update=True)) 624 623 … … 651 650 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 652 651 653 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, update=True, 654 title=self._added_plots[plot].name)) 652 wx.PostEvent(self.parent, 653 NewPlotEvent(plot=new_plot, update=True, 654 title=self._added_plots[plot].name)) 655 655 656 656 def _on_scale_unity(self, evt): … … 679 679 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 680 680 681 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, update=True, 682 title=self._added_plots[plot].name)) 681 wx.PostEvent(self.parent, 682 NewPlotEvent(plot=new_plot, update=True, 683 title=self._added_plots[plot].name)) 683 684 684 685 … … 714 715 wx.PostEvent(self.parent, StatusEvent(status=msg)) 715 716 else: 716 wx.PostEvent(self.parent, StatusEvent(status="This tool can only read 1D data")) 717 msg = "This tool can only read 1D data" 718 wx.PostEvent(self.parent, StatusEvent(status=msg)) 717 719 return 718 720 … … 748 750 749 751 pr = self.pr.clone() 750 self.calc_thread = CalcPr(pr, self.nfunc, error_func=self._thread_error, completefn=self._completed, updatefn=None) 752 self.calc_thread = CalcPr(pr, self.nfunc, 753 error_func=self._thread_error, 754 completefn=self._completed, updatefn=None) 751 755 self.calc_thread.queue() 752 756 self.calc_thread.ready(2.5) … … 815 819 self.pr = pr 816 820 817 #message = "Computation completed in %g seconds [chi2=%g]" % (elapsed, pr.chi2) 821 #message = "Computation completed in" 822 #message += %g seconds [chi2=%g]" % (elapsed, pr.chi2) 818 823 #wx.PostEvent(self.parent, StatusEvent(status=message)) 819 824 … … 835 840 for i in range(len(out)): 836 841 try: 837 print "%d: %g +- %g" % (i, out[i], math.sqrt(math.fabs(cov[i][i]))) 842 print "%d: %g +- %g" % (i, out[i], 843 math.sqrt(math.fabs(cov[i][i]))) 838 844 except: 839 845 print sys.exc_value … … 855 861 856 862 # Popup result panel 857 #result_panel = InversionResults(self.parent, -1, style=wx.RAISED_BORDER) 858 859 def show_data(self, path=None, reset=False): 863 #result_panel = InversionResults(self.parent, 864 #-1, style=wx.RAISED_BORDER) 865 866 def show_data(self, path=None, data=None, reset=False): 860 867 """ 861 868 Show data read from a file … … 865 872 866 873 """ 867 if path is not None: 874 print "show_data", data.name 875 #if path is not None: 876 if data is not None: 868 877 try: 869 pr = self._create_file_pr(path) 878 #pr = self._create_file_pr(path) 879 pr = self._create_file_pr(data) 870 880 except: 871 status ="Problem reading data: %s" % sys.exc_value881 status = "Problem reading data: %s" % sys.exc_value 872 882 wx.PostEvent(self.parent, StatusEvent(status=status)) 873 883 raise RuntimeError, status … … 878 888 879 889 self.pr = pr 880 890 881 891 # Make a plot of I(q) data 882 892 if self.pr.err==None: … … 889 899 new_plot.interactive = True 890 900 #new_plot.group_id = "test group" 891 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) 901 wx.PostEvent(self.parent, 902 NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) 892 903 893 904 self.current_plottable = new_plot … … 918 929 # Write the output to file 919 930 # First, check that the data is of the right type 920 if issubclass(self.current_plottable.__class__, DataLoader.data_info.Data1D): 931 if issubclass(self.current_plottable.__class__, 932 DataLoader.data_info.Data1D): 921 933 self.state_reader.write(filepath, self.current_plottable, prstate) 922 934 else: 923 raise RuntimeError, "pr.save_data: the data being saved is not a DataLoader.data_info.Data1D object" 935 msg = "pr.save_data: the data being saved is not a" 936 msg += " DataLoader.data_info.Data1D object" 937 raise RuntimeError, msg 924 938 925 939 … … 945 959 wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 946 960 947 def estimate_plot_inversion(self, alpha, nfunc, d_max, q_min=None, q_max=None, 961 def estimate_plot_inversion(self, alpha, nfunc, d_max, 962 q_min=None, q_max=None, 948 963 bck=False, height=0, width=0): 949 964 """ … … 1016 1031 min_err = 0.01*pr.y[i] 1017 1032 err[i] = scale*math.sqrt( math.fabs(pr.y[i]) ) + min_err 1018 message = "The loaded file had no error bars, statistical errors are assumed." 1033 message = "The loaded file had no error bars, " 1034 message += "statistical errors are assumed." 1019 1035 wx.PostEvent(self.parent, StatusEvent(status=message)) 1020 1036 … … 1024 1040 1025 1041 1026 def setup_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, 1042 def setup_file_inversion(self, alpha, nfunc, d_max, data, 1043 path=None, q_min=None, q_max=None, 1027 1044 bck=False, height=0, width=0): 1028 1045 """ … … 1038 1055 1039 1056 try: 1040 pr = self._create_file_pr(path) 1057 #pr = self._create_file_pr(path) 1058 pr = self._create_file_pr(data) 1041 1059 if not pr==None: 1042 1060 self.pr = pr … … 1045 1063 wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 1046 1064 1047 def estimate_file_inversion(self, alpha, nfunc, d_max, path, q_min=None, q_max=None, 1065 def estimate_file_inversion(self, alpha, nfunc, d_max, data, 1066 path=None, q_min=None, q_max=None, 1048 1067 bck=False, height=0, width=0): 1049 1068 """ … … 1059 1078 1060 1079 try: 1061 pr = self._create_file_pr(path) 1062 if not pr==None: 1080 pr = self._create_file_pr(data) 1081 #pr = self._create_file_pr(path) 1082 if not pr is None: 1063 1083 self.pr = pr 1064 1084 self.perform_estimate() … … 1067 1087 1068 1088 1069 def _create_file_pr(self, path):1089 def _create_file_pr(self, data): 1070 1090 """ 1071 1091 Create and prepare invertor instance from … … 1076 1096 """ 1077 1097 # Load data 1078 if os.path.isfile(path): 1079 1080 if self._current_file_data is not None \ 1081 and self._current_file_data.path==path: 1082 # Protect against corrupted data from 1083 # previous failed load attempt 1084 if self._current_file_data.x is None: 1085 return None 1086 x = self._current_file_data.x 1087 y = self._current_file_data.y 1088 err = self._current_file_data.err 1089 1090 message = "The data from this file has already been loaded." 1091 wx.PostEvent(self.parent, StatusEvent(status=message)) 1092 else: 1093 # Reset the status bar so that we don't get mixed up 1094 # with old messages. 1095 #TODO: refactor this into a proper status handling 1096 wx.PostEvent(self.parent, StatusEvent(status='')) 1097 try: 1098 x, y, err = self.load(path) 1099 except: 1100 load_error(sys.exc_value) 1101 return None 1102 1103 # If the file contains no data, just return 1104 if x is None or len(x)==0: 1105 load_error("The loaded file contains no data") 1106 return None 1107 1108 # If we have not errors, add statistical errors 1109 if err==None and y is not None: 1110 err = numpy.zeros(len(y)) 1111 scale = None 1112 min_err = 0.0 1113 for i in range(len(y)): 1114 # Scale the error so that we can fit over several decades of Q 1115 if scale==None: 1116 scale = 0.05*math.sqrt(y[i]) 1117 min_err = 0.01*y[i] 1118 err[i] = scale*math.sqrt( math.fabs(y[i]) ) + min_err 1119 message = "The loaded file had no error bars, statistical errors are assumed." 1120 wx.PostEvent(self.parent, StatusEvent(status=message)) 1121 1122 try: 1123 # Get the data from the chosen data set and perform inversion 1124 pr = Invertor() 1125 pr.d_max = self.max_length 1126 pr.alpha = self.alpha 1127 pr.q_min = self.q_min 1128 pr.q_max = self.q_max 1129 pr.x = x 1130 pr.y = y 1131 pr.err = err 1132 pr.has_bck = self.has_bck 1133 pr.slit_height = self.slit_height 1134 pr.slit_width = self.slit_width 1135 return pr 1136 except: 1137 load_error(sys.exc_value) 1098 #if os.path.isfile(path): 1099 """ 1100 if self._current_file_data is not None \ 1101 and self._current_file_data.path==path: 1102 # Protect against corrupted data from 1103 # previous failed load attempt 1104 if self._current_file_data.x is None: 1105 return None 1106 x = self._current_file_data.x 1107 y = self._current_file_data.y 1108 err = self._current_file_data.err 1109 1110 message = "The data from this file has already been loaded." 1111 wx.PostEvent(self.parent, StatusEvent(status=message)) 1112 else: 1113 """ 1114 # Reset the status bar so that we don't get mixed up 1115 # with old messages. 1116 #TODO: refactor this into a proper status handling 1117 wx.PostEvent(self.parent, StatusEvent(status='')) 1118 try: 1119 class FileData: 1120 x = None 1121 y = None 1122 err = None 1123 path = None 1124 def __init__(self, path): 1125 self.path = path 1126 1127 self._current_file_data = FileData(data.path) 1128 self._current_file_data.x = data.x 1129 self._current_file_data.y = data.y 1130 self._current_file_data.err = data.dy 1131 x, y, err = data.x, data.y, data.dy 1132 except: 1133 load_error(sys.exc_value) 1134 return None 1135 1136 # If the file contains no data, just return 1137 if x is None or len(x) == 0: 1138 load_error("The loaded file contains no data") 1139 return None 1140 1141 # If we have not errors, add statistical errors 1142 if err is not None and y is not None: 1143 err = numpy.zeros(len(y)) 1144 scale = None 1145 min_err = 0.0 1146 for i in range(len(y)): 1147 # Scale the error so that we can fit over several decades of Q 1148 if scale == None: 1149 scale = 0.05 * math.sqrt(y[i]) 1150 min_err = 0.01 * y[i] 1151 err[i] = scale * math.sqrt(math.fabs(y[i])) + min_err 1152 message = "The loaded file had no error bars, " 1153 message += "statistical errors are assumed." 1154 wx.PostEvent(self.parent, StatusEvent(status=message)) 1155 1156 try: 1157 # Get the data from the chosen data set and perform inversion 1158 pr = Invertor() 1159 pr.d_max = self.max_length 1160 pr.alpha = self.alpha 1161 pr.q_min = self.q_min 1162 pr.q_max = self.q_max 1163 pr.x = x 1164 pr.y = y 1165 pr.err = err 1166 pr.has_bck = self.has_bck 1167 pr.slit_height = self.slit_height 1168 pr.slit_width = self.slit_width 1169 return pr 1170 except: 1171 load_error(sys.exc_value) 1138 1172 return None 1139 1173 … … 1145 1179 1146 1180 # If a thread is already started, stop it 1147 if self.estimation_thread != None and self.estimation_thread.isrunning(): 1181 if self.estimation_thread != None and \ 1182 self.estimation_thread.isrunning(): 1148 1183 self.estimation_thread.stop() 1149 1184 1150 1185 pr = self.pr.clone() 1151 self.estimation_thread = EstimatePr(pr, self.nfunc, error_func=self._thread_error, 1152 completefn = self._estimate_completed, 1186 self.estimation_thread = EstimatePr(pr, self.nfunc, 1187 error_func=self._thread_error, 1188 completefn = self._estimate_completed, 1153 1189 updatefn = None) 1154 1190 self.estimation_thread.queue() … … 1170 1206 pr.slit_height = 0.0 1171 1207 pr.slit_width = 0.0 1172 self.estimation_thread = EstimateNT(pr, self.nfunc, error_func=self._thread_error, 1173 completefn = self._estimateNT_completed, 1208 self.estimation_thread = EstimateNT(pr, self.nfunc, 1209 error_func=self._thread_error, 1210 completefn = self._estimateNT_completed, 1174 1211 updatefn = None) 1175 1212 self.estimation_thread.queue() … … 1195 1232 for i in range(len(out)): 1196 1233 try: 1197 print "%d: %g +- %g" % (i, out[i], math.sqrt(math.fabs(cov[i][i]))) 1234 print "%d: %g +- %g" % (i, out[i], 1235 math.sqrt(math.fabs(cov[i][i]))) 1198 1236 except: 1199 1237 print "%d: %g +- ?" % (i, out[i]) … … 1205 1243 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 1206 1244 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 1207 1208 1245 # Show I(q) fit 1209 1246 self.show_iq(out, self.pr) 1210 1211 1247 # Show P(r) fit 1212 1248 x_values, x_range = self.show_pr(out, self.pr, cov=cov) 1213 1249 1214 1215 1216 1250 def _on_context_inversion(self, event): 1251 """ 1252 """ 1217 1253 panel = event.GetEventObject() 1218 1254 1219 1255 # If we have more than one displayed plot, make the user choose 1220 if len(panel.plots)>1 and panel.graph.selected_plottable in panel.plots: 1256 if len(panel.plots) > 1 and \ 1257 panel.graph.selected_plottable in panel.plots: 1221 1258 dataset = panel.graph.selected_plottable 1222 elif len(panel.plots) ==1:1259 elif len(panel.plots) == 1: 1223 1260 dataset = panel.plots.keys()[0] 1224 1261 else: 1225 print "Error: No data is available"1262 logging.info("Prview Error: No data is available") 1226 1263 return 1227 1264 … … 1233 1270 except: 1234 1271 self.control_panel.alpha = self.alpha 1235 print "No estimate yet"1272 logging.info("Prview :Alpha Not estimate yet") 1236 1273 pass 1237 1274 try: … … 1240 1277 except: 1241 1278 self.control_panel.nfunc = self.nfunc 1242 print "No estimate yet"1279 logging.info("Prview : ntemrs Not estimate yet") 1243 1280 pass 1244 1281 … … 1264 1301 self.control_panel.d_max = self.max_length 1265 1302 self.control_panel.alpha = self.alpha 1266 1267 1303 self.perspective = [] 1268 1304 self.perspective.append(self.control_panel.window_name) 1269 1270 self.parent.Bind(EVT_PR_FILE, self._on_new_file) 1271 1305 1272 1306 return [self.control_panel] 1273 1307 1274 def _on_new_file(self, evt): 1275 """ 1276 Called when the application manager posted an 1277 EVT_PR_FILE event. Just prompt the control 1278 panel to load a new data file. 1279 """ 1280 self.control_panel._change_file(None) 1281 1308 def set_data(self, data_list): 1309 """ 1310 receive a list of data to compute pr 1311 """ 1312 if len(data_list) > 1: 1313 msg = "Pr panel does not allow more than one value" 1314 msg += " at this time" 1315 raise ValueError, msg 1316 elif len(data_list) == 1: 1317 if issubclass(data_list[0].__class__, LoaderData1D): 1318 self.control_panel._change_file(evt=None, data=data_list[0]) 1319 else: 1320 msg = "Pr cannot be computed for" 1321 msg += " data of type %s" % (data_list[0].__class__.__name__) 1322 raise ValueError, msg 1323 1282 1324 def post_init(self): 1283 1325 """ -
prview/perspectives/pr/pr_thread.py
r7116b6e0 r75df58b 1 import sys, time 1 2 ################################################################################ 3 #This software was developed by the University of Tennessee as part of the 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 6 # 7 #See the license text in license.txt 8 # 9 #copyright 2009, University of Tennessee 10 ################################################################################ 11 12 import sys 13 import time 2 14 from data_util.calcthread import CalcThread 3 15
Note: See TracChangeset
for help on using the changeset viewer.