source: sasview/guiframe/data_loader.py @ d292959

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 d292959 was 978967c, checked in by Gervaise Alina <gervyh@…>, 16 years ago

changing the loaddata name to filename

  • Property mode set to 100644
File size: 3.3 KB
Line 
1import os, sys
2import wx
3from danse.common.plottools.plottables import Data1D, Theory1D, Data2D
4from DataLoader.loader import Loader
5class Theory2D(Data2D):
6    def __init__(self,image=None,err_image=None,xmin=None,
7                 xmax=None,ymin=None,ymax=None,zmin=None,zmax=None):
8        Data2D.__init__(self,image,err_image,xmin,
9                        xmax,ymin,ymax,zmin,zmax)
10def choose_data_file(parent, location=None):
11    path = None
12    if location==None:
13        location = os.getcwd()
14   
15    l = Loader()
16    cards = l.get_wildcards()
17    wlist = '|'.join(cards)
18   
19    dlg = wx.FileDialog(parent, "Choose a file", location, "", wlist, wx.OPEN)
20    if dlg.ShowModal() == wx.ID_OK:
21        path = dlg.GetPath()
22        mypath = os.path.basename(path)
23    dlg.Destroy()
24   
25    return path
26
27
28def load_ascii_1D(path):
29    """
30        Load a 1D ascii file, with errors
31    """
32    import numpy
33    if path and os.path.isfile(path):
34   
35        file_x = numpy.zeros(0)
36        file_y = numpy.zeros(0)
37        file_dy = numpy.zeros(0)
38       
39        input_f = open(path,'r')
40        buff = input_f.read()
41        lines = buff.split('\n')
42       
43        has_dy = False
44       
45        for line in lines:
46            try:
47                toks = line.split()
48                x = float(toks[0])
49                y = float(toks[1])
50                if len(toks)==3:
51                    has_dy = True
52                    err = float(toks[2])
53                else:
54                    err = 0.0
55                file_x  = numpy.append(file_x, x)
56                file_y  = numpy.append(file_y, y)
57                file_dy = numpy.append(file_dy, err)
58            except:
59                print "READ ERROR", line
60   
61        if has_dy==False:
62            file_dy = None
63           
64        return file_x, file_y, file_dy
65    return None, None, None
66
67def plot_data(parent, path, name="Loaded Data"):
68    from sans.guicomm.events import NewPlotEvent, StatusEvent
69   
70    from DataLoader.loader import  Loader
71    import numpy
72    #Instantiate a loader
73    L=Loader()
74   
75    #Recieves data
76    try:
77        output=L.load(path)
78    except:
79        wx.PostEvent(parent, StatusEvent(status="Problem loading file: %s" % sys.exc_value))
80        return
81    if hasattr(output,'data'):
82        new_plot = Data2D(image=output.data,err_image=output.err_data,
83                          xmin=output.xmin,xmax=output.xmax,
84                          ymin=output.ymin,ymax=output.ymax)
85        new_plot.x_bins=output.x_bins
86        new_plot.y_bins=output.y_bins
87        #print "data_loader",output
88    else:
89        if output.dy==None:
90            new_plot = Theory1D(output.x,output.y)
91        else:
92            new_plot = Data1D(x=output.x,y=output.y,dy=output.dy)
93   
94    filename = os.path.basename(path)
95    new_plot.source=output   
96    new_plot.name = filename
97    new_plot.interactive = True
98    # If the data file does not tell us what the axes are, just assume...
99    new_plot.xaxis(output._xaxis,output._xunit)
100    new_plot.yaxis(output._yaxis,output._yunit)
101    #new_plot.xaxis("\\rm{Q}",'A^{-1}')
102    #new_plot.yaxis("\\rm{Intensity} ","cm^{-1}")
103   
104    new_plot.group_id = filename
105       
106    wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=filename))
Note: See TracBrowser for help on using the repository browser.