Changeset aab8ad7 in sasview for prview/perspectives/pr
- Timestamp:
- Sep 14, 2008 10:11:00 AM (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:
- 14d05ba
- Parents:
- c7bc3e7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/perspectives/pr/pr.py
rf1181977 raab8ad7 11 11 import math, numpy 12 12 from sans.pr.invertor import Invertor 13 from DataLoader.loader import Loader 13 14 14 15 PR_FIT_LABEL = r"$P_{fit}(r)$" … … 344 345 by our standard DataLoader class. 345 346 """ 346 #TODO: use DataLoader347 347 class FileData: 348 348 x = None … … 355 355 356 356 self._current_file_data = FileData(path) 357 basename = os.path.basename(path) 358 root, ext = os.path.splitext(basename) 359 if ext.lower()=='.abs': 360 x, y, err = self.load_abs(path) 361 362 else: 363 x, y, err = self.load_columns(path) 364 357 358 # Use data loader to load file 359 dataread = Loader().load(path) 360 x = None 361 y = None 362 err = None 363 if dataread.__class__.__name__ == 'Data1D': 364 x = dataread.x 365 y = dataread.y 366 err = dataread.dy 367 else: 368 raise RuntimeError, "This tool can only read 1D data" 369 365 370 self._current_file_data.x = x 366 371 self._current_file_data.y = y … … 874 879 @param path: path of the file to read in 875 880 """ 876 from sans.guiframe.data_loader import load_ascii_1D877 import numpy878 879 881 # Load data 880 882 if os.path.isfile(path): … … 882 884 if self._current_file_data is not None \ 883 885 and self._current_file_data.path==path: 886 # Protect against corrupted data from 887 # previous failed load attempt 888 if self._current_file_data.x is None: 889 return None 884 890 x = self._current_file_data.x 885 891 y = self._current_file_data.y … … 887 893 else: 888 894 x, y, err = self.load(path) 889 #x, y, err = load_ascii_1D(path)890 895 891 896 # If we have not errors, add statistical errors 892 if err==None :897 if err==None and y is not None: 893 898 err = numpy.zeros(len(y)) 899 scale = None 900 min_err = 0.0 894 901 for i in range(len(y)): 895 err[i] = math.sqrt( math.fabs(y[i]) ) 902 # Scale the error so that we can fit over several decades of Q 903 if scale==None: 904 scale = 0.05*math.sqrt(y[i]) 905 min_err = 0.01*y[i] 906 err[i] = scale*math.sqrt( math.fabs(y[i]) ) + min_err 896 907 message = "The loaded file had no error bars, statistical errors are assumed." 897 908 wx.PostEvent(self.parent, StatusEvent(status=message)) … … 899 910 wx.PostEvent(self.parent, StatusEvent(status='')) 900 911 901 # Get the data from the chosen data set and perform inversion 902 pr = Invertor() 903 pr.d_max = self.max_length 904 pr.alpha = self.alpha 905 pr.q_min = self.q_min 906 pr.q_max = self.q_max 907 pr.x = x 908 pr.y = y 909 pr.err = err 910 pr.has_bck = self.has_bck 911 pr.slit_height = self.slit_height 912 pr.slit_width = self.slit_width 913 return pr 912 try: 913 # Get the data from the chosen data set and perform inversion 914 pr = Invertor() 915 pr.d_max = self.max_length 916 pr.alpha = self.alpha 917 pr.q_min = self.q_min 918 pr.q_max = self.q_max 919 pr.x = x 920 pr.y = y 921 pr.err = err 922 pr.has_bck = self.has_bck 923 pr.slit_height = self.slit_height 924 pr.slit_width = self.slit_width 925 return pr 926 except: 927 wx.PostEvent(self.parent, StatusEvent(status="Problem reading data: %s" % sys.exc_value)) 914 928 return None 915 929
Note: See TracChangeset
for help on using the changeset viewer.