source: sasview/guiframe/data_loader.py @ 9198b83

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 9198b83 was acb1ad1, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

allow multiple loaded data plots

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