source: sasview/guiframe/data_loader.py @ cc37c818

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 cc37c818 was 159db3b, checked in by Gervaise Alina <gervyh@…>, 16 years ago

still working on the load for 2 D data

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import os
2import wx
3
4def choose_data_file(parent, location=None):
5    path = None
6    if location==None:
7        location = os.getcwd()
8    dlg = wx.FileDialog(parent, "Choose a file", location, "", "*", wx.OPEN)
9    if dlg.ShowModal() == wx.ID_OK:
10        path = dlg.GetPath()
11        mypath = os.path.basename(path)
12    dlg.Destroy()
13   
14    return path
15
16
17def load_ascii_1D(path):
18    """
19        Load a 1D ascii file, with errors
20    """
21    import numpy
22    if path and os.path.isfile(path):
23   
24        file_x = numpy.zeros(0)
25        file_y = numpy.zeros(0)
26        file_dy = numpy.zeros(0)
27       
28        input_f = open(path,'r')
29        buff = input_f.read()
30        lines = buff.split('\n')
31       
32        has_dy = False
33       
34        for line in lines:
35            try:
36                toks = line.split()
37                x = float(toks[0])
38                y = float(toks[1])
39                if len(toks)==3:
40                    has_dy = True
41                    err = float(toks[2])
42                else:
43                    err = 0.0
44                file_x  = numpy.append(file_x, x)
45                file_y  = numpy.append(file_y, y)
46                file_dy = numpy.append(file_dy, err)
47            except:
48                print "READ ERROR", line
49   
50        if has_dy==False:
51            file_dy = None
52           
53        return file_x, file_y, file_dy
54    return None, None, None
55
56def plot_data(parent, path, name="Loaded Data"):
57    from sans.guicomm.events import NewPlotEvent
58    from sans.guitools.plottables import Data1D, Theory1D
59    from DataLoader.loader import  Loader
60    #Instantiate a loader
61    L=Loader()
62   
63    #Recieves data
64    output=L.load(path)
65   
66    import numpy
67   
68    if output.dy==None:
69        new_plot = Theory1D(output.x, output.y)
70    else:
71        new_plot = Data1D(output.x, output.y, dy=output.dy)
72    new_plot.name = name
73    new_plot.interactive = True
74   
75    # If the data file does not tell us what the axes are, just assume...
76    new_plot.xaxis("\\rm{Q}", 'A^{-1}')
77    new_plot.yaxis("\\rm{Intensity} ","cm^{-1}")
78       
79    wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title="Loaded data"))
Note: See TracBrowser for help on using the repository browser.