source: sasview/guiframe/data_loader.py @ 49815a2

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

data loader updating x_bins and y_bins for data 2d

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