Changeset aab8ad7 in sasview for prview/perspectives/pr


Ignore:
Timestamp:
Sep 14, 2008 8:11:00 AM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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
Message:

prview update for DataLoader?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • prview/perspectives/pr/pr.py

    rf1181977 raab8ad7  
    1111import math, numpy 
    1212from sans.pr.invertor import Invertor 
     13from DataLoader.loader import Loader 
    1314 
    1415PR_FIT_LABEL       = r"$P_{fit}(r)$" 
     
    344345            by our standard DataLoader class. 
    345346        """ 
    346         #TODO: use DataLoader 
    347347        class FileData: 
    348348            x = None 
     
    355355                 
    356356        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         
    365370        self._current_file_data.x = x 
    366371        self._current_file_data.y = y 
     
    874879            @param path: path of the file to read in  
    875880        """ 
    876         from sans.guiframe.data_loader import load_ascii_1D 
    877         import numpy 
    878          
    879881        # Load data 
    880882        if os.path.isfile(path): 
     
    882884            if self._current_file_data is not None \ 
    883885                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 
    884890                x = self._current_file_data.x 
    885891                y = self._current_file_data.y 
     
    887893            else: 
    888894                x, y, err = self.load(path) 
    889             #x, y, err = load_ascii_1D(path) 
    890895             
    891896            # If we have not errors, add statistical errors 
    892             if err==None: 
     897            if err==None and y is not None: 
    893898                err = numpy.zeros(len(y)) 
     899                scale = None 
     900                min_err = 0.0 
    894901                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 
    896907                message = "The loaded file had no error bars, statistical errors are assumed." 
    897908                wx.PostEvent(self.parent, StatusEvent(status=message)) 
     
    899910                wx.PostEvent(self.parent, StatusEvent(status='')) 
    900911             
    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)) 
    914928        return None 
    915929         
Note: See TracChangeset for help on using the changeset viewer.