Changeset a07e72f in sasview for prview/perspectives/pr/pr.py
- Timestamp:
- Feb 28, 2011 4:07:14 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:
- 243a8d4
- Parents:
- 6bbeacd4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/perspectives/pr/pr.py
r229da98 ra07e72f 24 24 import pylab 25 25 from sans.guiframe.dataFitting import Data1D 26 from sans.guiframe.dataFitting import Theory1D27 26 from sans.guiframe.events import NewPlotEvent 28 from sans.guiframe.events import StatusEvent 29 27 from sans.guiframe.events import StatusEvent 28 from sans.guiframe.gui_style import GUIFRAME_ID 30 29 from sans.pr.invertor import Invertor 31 30 from DataLoader.loader import Loader 32 from DataLoader.data_info import Data1D as LoaderData1D 33 import DataLoader 31 34 32 from pr_widgets import load_error 35 33 from sans.guiframe.plugin_base import PluginBase … … 41 39 IQ_FIT_LABEL = r"$I_{fit}(q)$" 42 40 IQ_SMEARED_LABEL = r"$I_{smeared}(q)$" 43 44 #import wx.lib45 #(NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent()46 47 41 48 42 … … 103 97 104 98 # Associate the inversion state reader with .prv files 105 from DataLoader.loader import Loader106 99 from inversion_state import Reader 107 100 … … 166 159 self.control_panel.set_state(state) 167 160 except: 168 raise 169 #logging.error("prview.set_state: %s" % sys.exc_value) 161 logging.error("prview.set_state: %s" % sys.exc_value) 170 162 171 163 … … 188 180 """ 189 181 from sans.pr.invertor import Invertor 190 191 from danse.common.plottools import Data1D as PlotData1D192 from danse.common.plottools import Theory1D as Theory1D193 194 182 # Generate P(r) for sphere 195 183 radius = 60.0 … … 220 208 for i in range(len(out)): 221 209 print "%g +- %g" % (out[i], math.sqrt(cov[i][i])) 222 210 223 211 # Show input P(r) 224 new_plot = PlotData1D(pr.x, pr.y, dy=pr.err) 212 title = "Pr" 213 new_plot = Data1D(pr.x, pr.y, dy=pr.err) 225 214 new_plot.name = "P_{obs}(r)" 226 215 new_plot.xaxis("\\rm{r}", 'A') 227 216 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 228 print "_fit_pr" 229 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Pr")) 217 group_id = "P_{obs}(r)" 218 if group_id not in new_plot.group_id: 219 new_plot.group_id.append(group_id) 220 new_plot.id = "P_{obs}(r)" 221 new_plot.title = title 222 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 230 223 231 224 # Show P(r) fit … … 239 232 """ 240 233 """ 241 from danse.common.plottools import Theory1D as PlotTheory1D242 234 # Show P(r) 243 235 y_true = numpy.zeros(len(x)) … … 251 243 252 244 # Show the theory P(r) 253 new_plot = PlotTheory1D(x, y_true) 245 new_plot = Data1D(x, y_true) 246 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 254 247 new_plot.name = "P_{true}(r)" 255 248 new_plot.xaxis("\\rm{r}", 'A') … … 272 265 """ 273 266 """ 274 from danse.common.plottools import Theory1D as PlotTheory1D275 276 267 qtemp = pr.x 277 268 if not q==None: … … 304 295 print "Error getting error", value, x[i] 305 296 306 new_plot = PlotTheory1D(x, y) 297 new_plot = Data1D(x, y) 298 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 307 299 new_plot.name = IQ_FIT_LABEL 308 300 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 309 301 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 310 311 302 title = "I(q)" 303 new_plot.title = title 304 312 305 # If we have a group ID, use it 313 306 if pr.info.has_key("plot_group_id"): 314 new_plot.group_id = pr.info["plot_group_id"] 315 title = pr.info["plot_group_id"] 316 307 if len( pr.info["plot_group_id"]) > 0: 308 index = len( pr.info["plot_group_id"]) - 1 309 new_plot.group_id.append( pr.info["plot_group_id"][index]) 310 new_plot.id = IQ_FIT_LABEL 311 #new_plot.group_id.append(2) 317 312 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 318 313 … … 331 326 print "Error getting error", value, x[i] 332 327 333 new_plot = Theory1D(x, y) 328 new_plot = Data1D(x, y) 329 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 334 330 new_plot.name = IQ_SMEARED_LABEL 335 331 new_plot.xaxis("\\rm{Q}", 'A^{-1}') … … 337 333 # If we have a group ID, use it 338 334 if pr.info.has_key("plot_group_id"): 339 new_plot.group_id = pr.info["plot_group_id"] 335 if len( pr.info["plot_group_id"]) > 0: 336 index = len( pr.info["plot_group_id"]) - 1 337 new_plot.group_id.append( pr.info["plot_group_id"][index]) 338 339 new_plot.id = IQ_SMEARED_LABEL 340 new_plot.title = title 341 #new_plot.group_id.append(2) 340 342 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 341 343 … … 359 361 """ 360 362 """ 361 from danse.common.plottools import Data1D as PlotData1D362 from danse.common.plottools import Theory1D as PlotTheory1D363 364 363 # Show P(r) 365 364 x = pylab.arange(0.0, pr.d_max, pr.d_max/self._pr_npts) … … 394 393 395 394 if cov2==None: 396 new_plot = PlotTheory1D(x, y) 395 new_plot = Data1D(x, y) 396 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 397 397 else: 398 new_plot = PlotData1D(x, y, dy=dy)398 new_plot = Data1D(x, y, dy=dy) 399 399 new_plot.name = PR_FIT_LABEL 400 400 new_plot.xaxis("\\rm{r}", 'A') 401 401 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 402 402 new_plot.title = "P(r) fit" 403 new_plot.id = PR_FIT_LABEL 403 404 # Make sure that the plot is linear 404 405 new_plot.xtransform = "x" … … 563 564 return 0.0 564 565 565 def get_context_menu(self, graph=None):566 def get_context_menu(self, plotpanel=None): 566 567 """ 567 568 Get the context menu items available for P(r) … … 572 573 573 574 """ 575 graph = plotpanel.graph 574 576 # Look whether this Graph contains P(r) data 575 #if graph.selected_plottable==IQ_DATA_LABEL: 576 for item in graph.plottables: 577 if item.name == PR_FIT_LABEL: 578 #add_data_hint = "Load a data file and display it on this plot" 579 #["Add P(r) data",add_data_hint , self._on_add_data], 580 change_n_hint = "Change the number of" 581 change_n_hint += " points on the P(r) output" 582 change_n_label = "Change number of P(r) points" 583 m_list = [[change_n_label, change_n_hint , self._on_pr_npts]] 584 585 if self._scale_output_unity or self._normalize_output: 586 hint = "Let the output P(r) keep the scale of the data" 587 m_list.append(["Disable P(r) scaling", hint, 588 self._on_disable_scaling]) 589 if not self._scale_output_unity: 590 m_list.append(["Scale P_max(r) to unity", 591 "Scale P(r) so that its maximum is 1", 592 self._on_scale_unity]) 593 if not self._normalize_output: 594 m_list.append(["Normalize P(r) to unity", 595 "Normalize the integral of P(r) to 1", 596 self._on_normalize]) 597 598 return m_list 599 #return [["Add P(r) data", 600 #"Load a data file and display it on this plot", 601 # self._on_add_data], 602 # ["Change number of P(r) points", 603 # "Change the number of points on the P(r) output", 604 # self._on_pr_npts]] 605 606 elif item.name == graph.selected_plottable: 607 #TODO: we might want to check that the units are 608 # consistent with I(q) before allowing this menu item 609 if not self.standalone and \ 610 issubclass(item.__class__, DataLoader.data_info.Data1D): 611 return [["Compute P(r)", 577 if graph.selected_plottable not in plotpanel.plots: 578 return [] 579 item = plotpanel.plots[graph.selected_plottable] 580 if item.id == PR_FIT_LABEL: 581 #add_data_hint = "Load a data file and display it on this plot" 582 #["Add P(r) data",add_data_hint , self._on_add_data], 583 change_n_hint = "Change the number of" 584 change_n_hint += " points on the P(r) output" 585 change_n_label = "Change number of P(r) points" 586 m_list = [[change_n_label, change_n_hint , self._on_pr_npts]] 587 588 if self._scale_output_unity or self._normalize_output: 589 hint = "Let the output P(r) keep the scale of the data" 590 m_list.append(["Disable P(r) scaling", hint, 591 self._on_disable_scaling]) 592 if not self._scale_output_unity: 593 m_list.append(["Scale P_max(r) to unity", 594 "Scale P(r) so that its maximum is 1", 595 self._on_scale_unity]) 596 if not self._normalize_output: 597 m_list.append(["Normalize P(r) to unity", 598 "Normalize the integral of P(r) to 1", 599 self._on_normalize]) 600 601 return m_list 602 603 elif item.id in [PR_LOADED_LABEL, IQ_DATA_LABEL, IQ_FIT_LABEL, 604 IQ_SMEARED_LABEL]: 605 return [] 606 elif item.id == graph.selected_plottable: 607 if not self.standalone and issubclass(item.__class__, Data1D): 608 return [["Compute P(r)", 612 609 "Compute P(r) from distribution", 613 610 self._on_context_inversion]] … … 657 654 y = self._added_plots[plot].y/sum 658 655 659 new_plot = Theory1D(self._added_plots[plot].x, y) 656 new_plot = Data1D(self._added_plots[plot].x, y) 657 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 658 index = len(self._added_plots[plot].group_id) - 1 659 if group_id not in new_plot.group_id: 660 new_plot.group_id.append(group_id) 661 new_plot.id = self._added_plots[plot].id 662 new_plot.title = self._added_plots[plot].title 660 663 new_plot.name = self._added_plots[plot].name 661 664 new_plot.xaxis("\\rm{r}", 'A') … … 686 689 y = self._added_plots[plot].y/_max 687 690 688 new_plot = Theory1D(self._added_plots[plot].x, y) 691 new_plot = Data1D(self._added_plots[plot].x, y) 692 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 689 693 new_plot.name = self._added_plots[plot].name 690 694 new_plot.xaxis("\\rm{r}", 'A') … … 736 740 737 741 filename = os.path.basename(path) 738 739 #new_plot = Data1D(x, y, dy=err)740 new_plot = Theory1D(x, y)742 743 new_plot = Data1D(x, y) 744 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 741 745 new_plot.name = filename 742 746 new_plot.xaxis("\\rm{r}", 'A') … … 863 867 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 864 868 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 865 #new_plot.group_id = "test group" 869 if pr.info.has_key("plot_group_id"): 870 new_plot.group_id.append(pr.info["plot_group_id"]) 871 new_plot.id = IQ_DATA_LABEL 866 872 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 867 873 … … 884 890 885 891 """ 886 print "show_data", data.name887 892 #if path is not None: 888 893 if data is not None: 889 894 try: 890 #pr = self._create_file_pr(path)891 895 pr = self._create_file_pr(data) 892 896 except: … … 902 906 903 907 # Make a plot of I(q) data 904 if self.pr.err==None: 905 new_plot = Theory1D(self.pr.x, self.pr.y) 908 if self.pr.err == None: 909 new_plot = Data1D(self.pr.x, self.pr.y) 910 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 906 911 else: 907 912 new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) … … 910 915 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 911 916 new_plot.interactive = True 912 #new_plot.group_id = "test group" 917 new_plot.group_id.append(IQ_DATA_LABEL) 918 new_plot.id = IQ_DATA_LABEL 919 new_plot.title = "I(q)" 913 920 wx.PostEvent(self.parent, 914 921 NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) 915 922 916 923 self.current_plottable = new_plot 917 self.current_plottable.group_id = IQ_DATA_LABEL918 919 920 924 # Get Q range 921 925 self.control_panel.q_min = self.pr.x.min() … … 1021 1025 # Keep track of the plot window title to ensure that 1022 1026 # we can overlay the plots 1023 if hasattr(self.current_plottable, "group_id"): 1027 if self.current_plottable.group_id: 1028 index = len(self.current_plottable.group_id) - 1 1029 group_id = self.current_plottable.group_id[index] 1024 1030 pr.info["plot_group_id"] = self.current_plottable.group_id 1025 1031 … … 1329 1335 if dlg.ShowModal() == wx.ID_OK: 1330 1336 data = dlg.get_data() 1331 if issubclass(data.__class__, LoaderData1D):1337 if issubclass(data.__class__, Data1D): 1332 1338 self.control_panel._change_file(evt=None, data=data) 1333 1339 else: … … 1337 1343 StatusEvent(status=msg, info='error')) 1338 1344 elif len(data_list) == 1: 1339 if issubclass(data_list[0].__class__, LoaderData1D):1345 if issubclass(data_list[0].__class__, Data1D): 1340 1346 self.control_panel._change_file(evt=None, data=data_list[0]) 1341 1347 else:
Note: See TracChangeset
for help on using the changeset viewer.