Changeset 4b73c3e in sasview for inversionview/src/sans/perspectives
- Timestamp:
- Apr 12, 2012 5:03:43 PM (13 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:
- 14cd6b92
- Parents:
- 5a0dac1f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inversionview/src/sans/perspectives/pr/pr.py
r6813da7d r4b73c3e 19 19 import logging 20 20 import time 21 import copy22 21 import math 23 22 import numpy … … 47 46 class Plugin(PluginBase): 48 47 """ 48 P(r) inversion perspective 49 49 """ 50 50 DEFAULT_ALPHA = 0.0001 … … 119 119 delete the data association with prview 120 120 """ 121 if self.calc_thread is not None and self.calc_thread.isrunning():122 msg = "Data in use in Prview\n"123 if self.estimation_thread is not None and \124 self.estimation_thread.isrunning():125 msg = "Data in use in Prview\n"126 121 self.control_panel.clear_panel() 127 122 128 123 def get_data(self): 129 124 """ 125 Returns the current data 130 126 """ 131 127 return self.current_plottable … … 149 145 data = datainfo 150 146 if data is None: 151 raise RuntimeError, "Pr.set_state: datainfo parameter cannot be None in standalone mode" 147 msg = "Pr.set_state: datainfo parameter cannot " 148 msg += "be None in standalone mode" 149 raise RuntimeError, msg 152 150 153 151 # Ensuring that plots are coordinated correctly … … 160 158 max_char = len(data.meta_data['prstate'].file) 161 159 162 datainfo.meta_data['prstate'].file = data.meta_data['prstate'].file[0:max_char] +' [' + time_str + ']' 160 datainfo.meta_data['prstate'].file =\ 161 data.meta_data['prstate'].file[0:max_char]\ 162 + ' [' + time_str + ']' 163 163 164 data.filename = data.meta_data['prstate'].file 164 165 # TODO: … … 166 167 # such as ID , Group_ID, etc... 167 168 #make self.current_plottable = datainfo directly 168 self.current_plottable = self.parent.create_gui_data(data, None)169 self.current_plottable = self.parent.create_gui_data(data, None) 169 170 self.current_plottable.group_id = data.meta_data['prstate'].file 170 171 … … 200 201 """ 201 202 """ 202 from sans.pr.invertor import Invertor203 203 # Generate P(r) for sphere 204 204 radius = 60.0 … … 289 289 """ 290 290 qtemp = pr.x 291 if not q ==None:291 if not q == None: 292 292 qtemp = q 293 293 … … 301 301 302 302 # Check for user min/max 303 if not pr.q_min ==None:303 if not pr.q_min == None: 304 304 minq = pr.q_min 305 if not pr.q_max ==None:305 if not pr.q_max == None: 306 306 maxq = pr.q_max 307 307 … … 335 335 336 336 # If we have used slit smearing, plot the smeared I(q) too 337 if pr.slit_width >0 or pr.slit_height>0:337 if pr.slit_width > 0 or pr.slit_height > 0: 338 338 x = pylab.arange(minq, maxq, maxq/301.0) 339 339 y = numpy.zeros(len(x)) … … 480 480 Load 2- or 3- column ascii 481 481 """ 482 import numpy, math, sys483 482 # Read the data from the data file 484 483 data_x = numpy.zeros(0) … … 529 528 530 529 """ 531 import numpy, math, sys532 530 # Read the data from the data file 533 531 data_x = numpy.zeros(0) … … 543 541 lines = buff.split('\n') 544 542 for line in lines: 545 if data_started ==True:543 if data_started == True: 546 544 try: 547 545 toks = line.split() … … 551 549 err = float(toks[2]) 552 550 else: 553 if scale ==None:551 if scale == None: 554 552 scale = 0.05*math.sqrt(y) 555 553 #scale = 0.05/math.sqrt(y) … … 566 564 data_started = True 567 565 568 if not scale ==None:566 if not scale == None: 569 567 message = "The loaded file had no error bars, statistical errors are assumed." 570 568 wx.PostEvent(self.parent, StatusEvent(status=message)) … … 576 574 def pr_theory(self, r, R): 577 575 """ 578 """ 579 if r<=2*R: 576 Return P(r) of a sphere for a given R 577 For test purposes 578 """ 579 if r <= 2*R: 580 580 return 12.0* ((0.5*r/R)**2) * ((1.0-0.5*r/R)**2) * ( 2.0 + 0.5*r/R ) 581 581 else: … … 623 623 return [] 624 624 elif item.id == graph.selected_plottable: 625 625 if not self.standalone and issubclass(item.__class__, Data1D): 626 626 return [["Compute P(r)", 627 627 "Compute P(r) from distribution", … … 714 714 NewPlotEvent(plot=new_plot, update=True, 715 715 title=self._added_plots[plot].name)) 716 717 718 def _on_add_data(self, evt): 719 """ 720 Add a data curve to the plot 721 722 :WARNING: this will be removed once guiframe.plotting has 723 its full functionality 724 """ 725 path = self.choose_file() 726 if path==None: 727 return 728 729 #x, y, err = self.parent.load_ascii_1D(path) 730 # Use data loader to load file 731 try: 732 dataread = Loader().load(path) 733 x = None 734 y = None 735 err = None 736 if dataread.__class__.__name__ == 'Data1D': 737 x = dataread.x 738 y = dataread.y 739 err = dataread.dy 740 else: 741 if isinstance(dataread, list) and len(dataread)>0: 742 x = dataread[0].x 743 y = dataread[0].y 744 err = dataread[0].dy 745 msg = "PrView only allows a single data set at a time. " 746 msg += "Only the first data set was loaded." 747 wx.PostEvent(self.parent, StatusEvent(status=msg)) 748 else: 749 msg = "This tool can only read 1D data" 750 wx.PostEvent(self.parent, StatusEvent(status=msg)) 751 return 752 753 except: 754 wx.PostEvent(self.parent, StatusEvent(status=sys.exc_value)) 755 return 756 757 filename = os.path.basename(path) 758 new_plot = Data1D(x, y) 759 new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 760 new_plot.name = filename 761 new_plot.xaxis("\\rm{r}", 'A') 762 new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 763 # Store a ref to the plottable for later use 764 self._added_plots[filename] = new_plot 765 self._default_Iq[filename] = numpy.copy(y) 766 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=filename)) 767 716 768 717 def start_thread(self): 769 718 """ 770 719 """ 771 720 from pr_thread import CalcPr 772 from copy import deepcopy773 721 774 722 # If a thread is already started, stop it … … 846 794 847 795 """ 848 from copy import deepcopy849 796 # Save useful info 850 797 self.elapsed = elapsed … … 867 814 self.control_panel.elapsed = elapsed 868 815 self.control_panel.oscillation = pr.oscillations(out) 869 #print "OSCILL", pr.oscillations(out)870 #print "PEAKS:", pr.get_peaks(out)871 816 self.control_panel.positive = pr.get_positive(out) 872 817 self.control_panel.pos_err = pr.get_pos_err(out, cov) … … 874 819 self.control_panel.iq0 = pr.iq0(out) 875 820 self.control_panel.bck = pr.background 876 877 if False: 878 for i in range(len(out)): 879 try: 880 print "%d: %g +- %g" % (i, out[i], 881 math.sqrt(math.fabs(cov[i][i]))) 882 except: 883 print sys.exc_value 884 print "%d: %g +- ?" % (i, out[i]) 885 886 # Make a plot of I(q) data 887 new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) 888 new_plot.name = IQ_DATA_LABEL 889 new_plot.xaxis("\\rm{Q}", 'A^{-1}') 890 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 891 if pr.info.has_key("plot_group_id"): 892 new_plot.group_id = pr.info["plot_group_id"] 893 new_plot.id = self.data_id 894 self.parent.update_theory(data_id=self.data_id, 895 theory=new_plot) 896 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 897 821 898 822 # Show I(q) fit 899 823 self.show_iq(out, self.pr) … … 901 825 # Show P(r) fit 902 826 x_values, x_range = self.show_pr(out, self.pr, cov) 903 904 # Popup result panel 905 #result_panel = InversionResults(self.parent, 906 #-1, style=wx.RAISED_BORDER) 907 827 908 828 def show_data(self, path=None, data=None, reset=False): 909 829 """ … … 1399 1319 self.control_panel._change_file(evt=None, data=data) 1400 1320 except: 1401 1402 1321 msg = "Prview Set_data: " + str(sys.exc_value) 1322 wx.PostEvent(self.parent, StatusEvent(status=msg, 1403 1323 info="error")) 1404 1324 else:
Note: See TracChangeset
for help on using the changeset viewer.