Changeset ff3f900b in sasview


Ignore:
Timestamp:
Jun 8, 2009 12:22:35 PM (15 years ago)
Author:
Gervaise Alina <gervyh@…>
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:
f0a9a3cc
Parents:
4ac8556
Message:

change on data_loader

Location:
guiframe
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • guiframe/dataFitting.py

    r1abcb04 rff3f900b  
    11""" 
    2     A Data1D class compatible with guiframe from the output of DataLoader.  
     2    Adapters for fitting module 
    33""" 
    4 from danse.common.plottools.plottables import Data1D as plotData1D 
    5 from danse.common.plottools.plottables import Theory1D as plotTheory1D 
     4from danse.common.plottools.plottables import Data1D as PlotData1D 
     5from danse.common.plottools.plottables import Data2D as PlotData2D 
    66 
    7 from DataLoader.data_info import Data1D as loader_data_1D 
     7from DataLoader.data_info import Data1D as LoadData1D 
     8from DataLoader.data_info import Data2D as LoadData2D 
    89 
    9 class Data1D(plotData1D, loader_data_1D): 
    10     """ 
    11         A Data1D class compatible with guiframe from  
    12         the output of DataLoader. The new class inherits  
    13         from DataLoader.data_info.Data1D 
    14     """ 
    15     def __init__(self,x=[],y=[],dx=None,dy=None,dxl=None, dxw=None): 
    16         plotData1D.__init__(self, x, y, dx, dy) 
    17         loader_data_1D.__init__(self, x=x, y=y, dx=dx, dy=dy) 
    18         self.smearer=None 
    19         
    20         self.dxl = dxl 
    21         self.dxw = dxw 
    22   
    23 class Theory1D(plotTheory1D, loader_data_1D): 
    24     """ 
    25         A Theory1D class compatible with guiframe from  
    26         the output of DataLoader. The new class inherits  
    27         from DataLoader.data_info.Data1D 
    28     """ 
    29     def __init__(self,x=[],y=[],dy=None,dxl=None, dxw=None): 
    30         plotTheory1D.__init__(self, x, y) 
    31         loader_data_1D.__init__(self, x=x, y=y, dx=dx, dy=dy) 
    32         self.smearer=None 
     10import copy 
     11 
     12class Data1D(PlotData1D,LoadData1D): 
     13     
     14    def __init__(self,x=[],y=[],dx=None,dy=None): 
     15        PlotData1D.__init__(self, x, y, dx, dy) 
     16        LoadData1D.__init__(self, x, y, dx, dy) 
     17        self.id= None 
     18        self.group_id =None 
     19        self.is_data = True 
     20     
     21    def copy_from_datainfo(self, data1d): 
     22        """ 
     23            copy values of Data1D of type DataLaoder.Data_info 
     24        """ 
     25        self.x  = copy.deepcopy(data1d.x) 
     26        self.dx = copy.deepcopy(data1d.dx) 
     27        self.y  = copy.deepcopy(data1d.y) 
     28        self.dy = copy.deepcopy(data1d.dy) 
     29        dxl = copy.deepcopy(data1d.dxl) 
     30        dxw = copy.deepcopy(data1d.dxw) 
     31     
     32        self.xaxis(data1d._xaxis,data1d._xunit) 
     33        self.yaxis(data1d._yaxis,data1d._yunit) 
     34     
     35     
     36       
     37class Data2D(PlotData2D,LoadData2D): 
     38    def __init__(self,image=None,err_image=None,xmin=None,xmax=None,ymin=None,ymax=None,zmin=None,zmax=None): 
    3339         
    34         self.dxl = dxl 
    35         self.dxw = dxw 
    36   
     40        PlotData2D.__init__(self, image=image, err_image=err_image,xmin=xmin, xmax=xmax, 
     41                            ymin=ymin, ymax=ymax) 
     42         
     43        LoadData2D.__init__(self,data=image, err_data=err_image) 
     44         
     45    def copy_from_datainfo(self, data2d): 
     46        """ 
     47            copy value of Data2D of type DataLoader.data_info 
     48        """ 
     49        self.data     =  copy.deepcopy(data2d.data) 
     50        self.err_data =  copy.deepcopy(data2d.err_data) 
     51        self.x_bins     = copy.deepcopy(data2d.x_bins) 
     52        self.y_bins     = copy.deepcopy(data2d.y_bins) 
     53         
     54        self.xmin       = data2d.xmin 
     55        self.xmax       = data2d.xmax 
     56        self.ymin       = data2d.ymin 
     57        self.ymax       = data2d.ymax 
     58         
     59        self.xaxis(data2d._xaxis,data2d._xunit) 
     60        self.yaxis(data2d._yaxis,data2d._yunit) 
     61         
     62         
     63         
  • guiframe/data_loader.py

    r675e0ab rff3f900b  
    11import os, sys,numpy 
    22import wx 
    3 from dataFitting import Data1D, Theory1D 
    4 from danse.common.plottools.plottables import Data2D 
     3from dataFitting import Data1D 
     4from dataFitting import Data2D 
    55from DataLoader.loader import Loader 
    66 
     
    7474    """ 
    7575        Use the DataLoader loader to created data to plot. 
    76          
    77         TODO: this method needs a major cleanup.  
    78         It's a complete mess. It needs: 
    79           - to be cleaned of code duplication 
    80           - to be cleaned of data duplication: we should not 
    81             need to reference all the Data1D data members. 
    82             It should be sufficient to use the Data1D class 
    83             defined in dataFitting (which btw needs a better name). 
    84          
    8576        @param path: the path of the data to load 
    8677    """ 
     
    9485    try: 
    9586        output=L.load(path) 
    96          
     87        if output==None: 
     88            msg="Could not open this page" 
     89            wx.PostEvent(parent, StatusEvent(status=msg)) 
     90            return 
    9791    except: 
    9892        wx.PostEvent(parent, StatusEvent(status="Problem loading file: %s" % sys.exc_value)) 
    9993        return 
    100     if output==None: 
    101         msg="Could not open this page" 
    102         wx.PostEvent(parent, StatusEvent(status=msg)) 
    103         return 
     94     
     95   
    10496    filename = os.path.basename(path) 
    10597     
    10698    if not  output.__class__.__name__=="list": 
    107         ## smearing info 
    108         try: 
    109             dxl = output.dxl 
    110             dxw = output.dxw 
    111         except: 
    112             dxl = None 
    113             dxw = None 
    114         
    115              
    11699        ## Creating a Data2D with output 
    117100        if hasattr(output,'data'): 
    118              
    119             new_plot = Data2D(image=output.data,err_image=output.err_data, 
    120                               xmin=output.xmin,xmax=output.xmax, 
    121                               ymin=output.ymin,ymax=output.ymax) 
    122             new_plot.x_bins=output.x_bins 
    123             new_plot.y_bins=output.y_bins 
    124              
    125         ##Creating Data1D with output 
     101            new_plot = Data2D(image=None,err_image=None) 
     102       
    126103        else: 
    127             ##dy values checked 
    128             dy= output.dy 
    129             if dy ==None: 
    130                 dy= numpy.zeros(len(output.y)) 
    131              
    132104            msg="Loading 1D data: " 
    133105            wx.PostEvent(parent, StatusEvent(status= "%s %s"%(msg, output.filename))) 
    134             new_plot = Data1D(x=output.x, y=output.y, dx=output.dx, 
    135                               dy= dy, dxl=dxl, dxw=dxw) 
    136             # Copy all the data to the new object so that the  
    137             # new_plot object properly behaves as a data_info.Data1D. 
    138             # This also means that we should not have to copy all 
    139             # the data below... 
    140             output.clone_without_data(clone=new_plot) 
    141                  
    142         ## source will request in dataLoader .manipulation module 
    143         new_plot.source=output.source 
     106            new_plot = Data1D(x=[], y=[], dx=None,dy= None) 
     107             
     108        new_plot.copy_from_datainfo(output)  
     109        output.clone_without_data(clone=new_plot)       
     110       
    144111        ## data 's name 
    145         if output.filename==None: 
    146             output.filename=str(filename) 
     112        if output.filename==None or output.filename=="": 
     113            output.filename = str(filename) 
    147114        ## name of the data allow to differentiate data when plotted 
    148115        name= output.filename 
     
    152119            ## create a copy of the loaded data 
    153120            parent.indice_load_data[name]+=1 
    154             name = name +"(copy %i)"%parent.indice_load_data[name] 
    155              
     121            name = name +"[%i]"%parent.indice_load_data[name] 
     122        
    156123        new_plot.name = name 
    157124        ## allow to highlight data when plotted 
     
    162129        ## to save  data 1D as cansas xml file 
    163130        new_plot.info= output 
    164         ## detector used by dataLoader.manipulation module 
    165         new_plot.detector =output.detector 
    166         ## If the data file does not tell us what the axes are, just assume... 
    167         new_plot.xaxis(output._xaxis,output._xunit) 
    168         new_plot.yaxis(output._yaxis,output._yunit) 
    169131        ##group_id specify on which panel to plot this data 
    170132        new_plot.group_id = name 
    171133        new_plot.is_data =True 
    172134        ##post data to plot 
    173         wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=str(name))) 
     135        if hasattr(new_plot,"title"): 
     136            title= str(new_plot.title) 
     137        else: 
     138            title = str(name) 
     139        wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title= title )) 
    174140         
    175141    ## the output of the loader is a list , some xml files contain more than one data 
    176     #TODO: refactor this so that there is no duplication of code. 
    177     # There is no reason why the code above shouldn't be put in  
    178     # a private method to be used within the loop below. 
    179142    else: 
    180143        i=1 
     
    188151                dxl=None 
    189152                dxw=None 
    190             dy = item.dy   
    191             if dy ==None: 
    192                 dy= numpy.zeros(len(item.y)) 
    193                 
    194             new_plot = Data1D(x=item.x,y=item.y,dx=dx,dy=item.dy,dxl=dxl,dxw=dxw) 
    195             # Copy all the data to the new object 
     153 
     154            new_plot = Data1D(x=item.x,y=item.y,dx=dx,dy=item.dy) 
     155            new_plot.copy_from_datainfo(item) 
    196156            item.clone_without_data(clone=new_plot) 
    197             new_plot.source=item.source 
    198              
     157            new_plot.dxl = dxl 
     158            new_plot.dxw = dxw 
     159            
    199160            name= str(item.run[0]) 
    200161            if not name in parent.indice_load_data.keys(): 
     
    213174            new_plot.name = name 
    214175            new_plot.interactive = True 
    215             new_plot.detector =item.detector 
    216             # If the data file does not tell us what the axes are, just assume... 
    217             new_plot.xaxis(item._xaxis,item._xunit) 
    218             new_plot.yaxis(item._yaxis,item._yunit) 
     176          
    219177            new_plot.group_id = name 
    220178            new_plot.id = name 
Note: See TracChangeset for help on using the changeset viewer.