source: sasview/guiframe/data_loader.py @ 7764b41

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

modify panel for data2d purposed

  • Property mode set to 100644
File size: 3.5 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
[7764b41]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       
[de9483d]15
[7764b41]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   
[de9483d]29def choose_data_file(parent, location=None):
30    path = None
31    if location==None:
32        location = os.getcwd()
[c7bc3e7]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)
[de9483d]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    """
[fc2b91a]51    import numpy
[de9483d]52    if path and os.path.isfile(path):
53   
[fc2b91a]54        file_x = numpy.zeros(0)
55        file_y = numpy.zeros(0)
56        file_dy = numpy.zeros(0)
[de9483d]57       
58        input_f = open(path,'r')
59        buff = input_f.read()
60        lines = buff.split('\n')
[fc2b91a]61       
62        has_dy = False
63       
[de9483d]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:
[fc2b91a]70                    has_dy = True
[de9483d]71                    err = float(toks[2])
72                else:
73                    err = 0.0
[fc2b91a]74                file_x  = numpy.append(file_x, x)
75                file_y  = numpy.append(file_y, y)
76                file_dy = numpy.append(file_dy, err)
[de9483d]77            except:
78                print "READ ERROR", line
79   
[fc2b91a]80        if has_dy==False:
81            file_dy = None
82           
[de9483d]83        return file_x, file_y, file_dy
[fc2b91a]84    return None, None, None
85
86def plot_data(parent, path, name="Loaded Data"):
[ccb560a]87    from sans.guicomm.events import NewPlotEvent, StatusEvent
[7764b41]88   
[4102709]89    from DataLoader.loader import  Loader
[1c9419f4]90    import numpy
[4102709]91    #Instantiate a loader
92    L=Loader()
93   
94    #Recieves data
[ccb560a]95    try:
96        output=L.load(path)
97    except:
98        wx.PostEvent(parent, StatusEvent(status="Problem loading file: %s" % sys.exc_value))
99        return
[7764b41]100    if hasattr(output,'data'):
101        new_plot = MetaData2D(output)
[fc2b91a]102    else:
[1c9419f4]103        if output.dy==None:
[7764b41]104            new_plot = MetaTheory1D(output)
[1c9419f4]105        else:
[7764b41]106            new_plot = MetaData1D(output)
[acb1ad1]107       
108    filename = os.path.basename(path)
109       
[fc2b91a]110    new_plot.name = name
111    new_plot.interactive = True
112    # If the data file does not tell us what the axes are, just assume...
[7764b41]113    new_plot.xaxis("\\rm{Q}",'A^{-1}')
[fc2b91a]114    new_plot.yaxis("\\rm{Intensity} ","cm^{-1}")
[acb1ad1]115    new_plot.group_id = filename
[7764b41]116       
[1c9419f4]117    wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=filename))
Note: See TracBrowser for help on using the repository browser.