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