source: sasview/guiframe/data_loader.py @ 35d1092

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 35d1092 was 743d75c, checked in by Gervaise Alina <gervyh@…>, 16 years ago

plotting 2 d

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[ccb560a]1import os, sys
[de9483d]2import wx
[7764b41]3from danse.common.plottools.plottables import Data1D, Theory1D, Data2D
[c7bc3e7]4from DataLoader.loader import Loader
[58eac5d]5
[de9483d]6def choose_data_file(parent, location=None):
7    path = None
8    if location==None:
9        location = os.getcwd()
[c7bc3e7]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)
[de9483d]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    """
[fc2b91a]28    import numpy
[de9483d]29    if path and os.path.isfile(path):
30   
[fc2b91a]31        file_x = numpy.zeros(0)
32        file_y = numpy.zeros(0)
33        file_dy = numpy.zeros(0)
[de9483d]34       
35        input_f = open(path,'r')
36        buff = input_f.read()
37        lines = buff.split('\n')
[fc2b91a]38       
39        has_dy = False
40       
[de9483d]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:
[fc2b91a]47                    has_dy = True
[de9483d]48                    err = float(toks[2])
49                else:
50                    err = 0.0
[fc2b91a]51                file_x  = numpy.append(file_x, x)
52                file_y  = numpy.append(file_y, y)
53                file_dy = numpy.append(file_dy, err)
[de9483d]54            except:
55                print "READ ERROR", line
56   
[fc2b91a]57        if has_dy==False:
58            file_dy = None
59           
[de9483d]60        return file_x, file_y, file_dy
[fc2b91a]61    return None, None, None
62
63def plot_data(parent, path, name="Loaded Data"):
[ccb560a]64    from sans.guicomm.events import NewPlotEvent, StatusEvent
[7764b41]65   
[4102709]66    from DataLoader.loader import  Loader
[1c9419f4]67    import numpy
[4102709]68    #Instantiate a loader
69    L=Loader()
70   
71    #Recieves data
[ccb560a]72    try:
73        output=L.load(path)
74    except:
75        wx.PostEvent(parent, StatusEvent(status="Problem loading file: %s" % sys.exc_value))
76        return
[7764b41]77    if hasattr(output,'data'):
[48c7477]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)
[49815a2]81        new_plot.x_bins=output.x_bins
82        new_plot.y_bins=output.y_bins
[978967c]83        #print "data_loader",output
[fc2b91a]84    else:
[1c9419f4]85        if output.dy==None:
[48c7477]86            new_plot = Theory1D(output.x,output.y)
[1c9419f4]87        else:
[48c7477]88            new_plot = Data1D(x=output.x,y=output.y,dy=output.dy)
[978967c]89   
[acb1ad1]90    filename = os.path.basename(path)
[48c7477]91    new_plot.source=output   
[978967c]92    new_plot.name = filename
[fc2b91a]93    new_plot.interactive = True
[743d75c]94    print "loader output.detector",output.detector
95    new_plot.detector =output.detector
[fc2b91a]96    # If the data file does not tell us what the axes are, just assume...
[978967c]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   
[acb1ad1]102    new_plot.group_id = filename
[7764b41]103       
[1c9419f4]104    wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=filename))
Note: See TracBrowser for help on using the repository browser.