source: sasview/guiframe/data_loader.py @ 1047275

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 1047275 was f2776f6, checked in by Gervaise Alina <gervyh@…>, 15 years ago

remove unused code

  • Property mode set to 100644
File size: 6.7 KB
RevLine 
[6d920cd]1import os, sys,numpy
[de9483d]2import wx
[81812d9]3from dataFitting import Data1D, Theory1D
4from danse.common.plottools.plottables import Data2D
5
[c7bc3e7]6from DataLoader.loader import Loader
[58eac5d]7
[de9483d]8def choose_data_file(parent, location=None):
9    path = None
10    if location==None:
11        location = os.getcwd()
[c7bc3e7]12   
13    l = Loader()
14    cards = l.get_wildcards()
15    wlist = '|'.join(cards)
16   
17    dlg = wx.FileDialog(parent, "Choose a file", location, "", wlist, wx.OPEN)
[de9483d]18    if dlg.ShowModal() == wx.ID_OK:
19        path = dlg.GetPath()
20        mypath = os.path.basename(path)
21    dlg.Destroy()
22   
23    return path
24
25
26def load_ascii_1D(path):
27    """
28        Load a 1D ascii file, with errors
29    """
30    if path and os.path.isfile(path):
31   
[fc2b91a]32        file_x = numpy.zeros(0)
33        file_y = numpy.zeros(0)
34        file_dy = numpy.zeros(0)
[bc3dd65d]35        file_dx = numpy.zeros(0)
[de9483d]36       
37        input_f = open(path,'r')
38        buff = input_f.read()
39        lines = buff.split('\n')
[fc2b91a]40       
41        has_dy = False
[bc3dd65d]42        has_dx = False
[fc2b91a]43       
[de9483d]44        for line in lines:
45            try:
46                toks = line.split()
47                x = float(toks[0])
48                y = float(toks[1])
49                if len(toks)==3:
[fc2b91a]50                    has_dy = True
[bc3dd65d]51                    errdy = float(toks[2])
[de9483d]52                else:
[bc3dd65d]53                    errdy = 0.0
54                if len(toks)==4:
55                    has_dx = True
56                    errdx = float(toks[3])
57                else:
58                    errdx = 0.0
[fc2b91a]59                file_x  = numpy.append(file_x, x)
60                file_y  = numpy.append(file_y, y)
[bc3dd65d]61                file_dy = numpy.append(file_dy, dyerr)
62                file_dx = numpy.append(file_dx, dxerr)
[de9483d]63            except:
64                print "READ ERROR", line
65   
[fc2b91a]66        if has_dy==False:
67            file_dy = None
[bc3dd65d]68        if has_dx==False:
69            file_dx = None
[fc2b91a]70           
[bc3dd65d]71        return file_x, file_y, file_dy, file_dx
[fc2b91a]72    return None, None, None
73
[6d920cd]74def plot_data(parent, path):
75    """
76        Use the DataLoader loader to created data to plot.
77        @param path: the path of the data to load
78    """
[ccb560a]79    from sans.guicomm.events import NewPlotEvent, StatusEvent
[4102709]80    from DataLoader.loader import  Loader
[f2776f6]81   
[4102709]82    #Instantiate a loader
[81812d9]83    L = Loader()
[4102709]84   
85    #Recieves data
[ccb560a]86    try:
87        output=L.load(path)
[81812d9]88       
[ccb560a]89    except:
90        wx.PostEvent(parent, StatusEvent(status="Problem loading file: %s" % sys.exc_value))
91        return
[acb1ad1]92    filename = os.path.basename(path)
[cd84dca]93   
[81812d9]94    if not  output.__class__.__name__=="list":
[12aa9b5]95        ## smearing info
[81812d9]96        try:
[12aa9b5]97            dxl = output.dxl
98            dxw = output.dxw
[81812d9]99        except:
[12aa9b5]100            dxl = None
101            dxw = None
102        ## data 's name
103        if output.filename==None:
104            output.filename=str(filename)
105        ## Creating a Data2D with output
[81812d9]106        if hasattr(output,'data'):
[a19cd4d]107            temp = output.err_data
108            temp[temp==0]=1
[12aa9b5]109            msg= "Loading 2D error bars of value 1 were added to"
110            wx.PostEvent(parent, StatusEvent(status=" %s %s"% (msg,output.filename)))
[a19cd4d]111            new_plot = Data2D(image=output.data,err_image=temp,
[81812d9]112                              xmin=output.xmin,xmax=output.xmax,
113                              ymin=output.ymin,ymax=output.ymax)
114            new_plot.x_bins=output.x_bins
115            new_plot.y_bins=output.y_bins
[12aa9b5]116        ##Creating Data1D with output
[81812d9]117        else:
[12aa9b5]118            ##dy values checked
[8bd764d]119            if output.dy ==None :
[81812d9]120                new_plot = Theory1D(output.x,output.y, dxl, dxw)
[12aa9b5]121               
[8bd764d]122            elif len(output.dy[output.dy==0])==len(output.dy):
123                output.dy[output.dy==0]=1 
[12aa9b5]124                msg="Loading 1D error bars of value 1 were added to "
125                wx.PostEvent(parent, StatusEvent(status= "%s %s"%(msg, output.filename)))
[8bd764d]126                new_plot = Theory1D(output.x,output.y,output.dy, dxl, dxw)
[81812d9]127            else:
[12aa9b5]128                msg="Loading 1D data: "
129                wx.PostEvent(parent, StatusEvent(status= "%s %s"%(msg, output.filename)))
130                new_plot = Data1D(x=output.x, y=output.y, dx=output.dx,
131                                  dy=output.dy, dxl=dxl, dxw=dxw)
132               
133        ## source will request in dataLoader .manipulation module
[81812d9]134        new_plot.source=output.source
[12aa9b5]135        ## name of the data allow to differentiate data when plotted
[35eeea8]136        name= output.filename
[f2776f6]137       
[35eeea8]138           
139        #print "data_name_list",data_name_list
140        new_plot.name = name
[12aa9b5]141        ## allow to highlight data when plotted
[81812d9]142        new_plot.interactive = True
[12aa9b5]143        ## when 2 data have the same id override the 1 st plotted
[35eeea8]144        new_plot.id = name
[12aa9b5]145        ## info is a reference to output of dataloader that can be used
146        ## to save  data 1D as cansas xml file
[81812d9]147        new_plot.info= output
[12aa9b5]148        ## detector used by dataLoader.manipulation module
[81812d9]149        new_plot.detector =output.detector
[12aa9b5]150        ## If the data file does not tell us what the axes are, just assume...
[81812d9]151        new_plot.xaxis(output._xaxis,output._xunit)
152        new_plot.yaxis(output._yaxis,output._yunit)
[12aa9b5]153        ##group_id specify on which panel to plot this data
[35eeea8]154        new_plot.group_id = name
[12aa9b5]155        ##post data to plot
[35eeea8]156        wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=str(name)))
[8bd764d]157       
[12aa9b5]158    ## the output of the loader is a list , some xml files contain more than one data
[81812d9]159    else:
[768656e]160        i=1
[81812d9]161        for item in output:
162            try:
[bc3dd65d]163                dx=item.dx
[81812d9]164                dxl=item.dxl
165                dxw=item.dxw
166            except:
[bc3dd65d]167                dx=None
[81812d9]168                dxl=None
169                dxw=None
[12aa9b5]170               
[7a7bf55]171            if item.dy ==None:
[81812d9]172                new_plot = Theory1D(item.x,item.y,dxl,dxw)
173            else:
[bc3dd65d]174                new_plot = Data1D(x=item.x,y=item.y,dx=dx,dy=item.dy,dxl=dxl,dxw=dxw)
[81812d9]175           
176            new_plot.source=item.source
[35eeea8]177           
178            name= str(item.run[0])
179           
180            new_plot.name = name
[81812d9]181            new_plot.interactive = True
182            new_plot.detector =item.detector
183            # If the data file does not tell us what the axes are, just assume...
184            new_plot.xaxis(item._xaxis,item._xunit)
185            new_plot.yaxis(item._yaxis,item._yunit)
[35eeea8]186            new_plot.group_id = name
187            new_plot.id = name
[6d920cd]188            new_plot.info= item
189           
[18eba35]190            if hasattr(item,"title"):
191                title= item.title
192            else:
[35eeea8]193                title= name
[18eba35]194            wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=str(title)))
[768656e]195            i+=1
[81812d9]196           
197           
Note: See TracBrowser for help on using the repository browser.