source: sasview/guiframe/data_loader.py @ ce64735

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

small changes not committed

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