Changeset ff3f900b in sasview for guiframe/data_loader.py
- Timestamp:
- Jun 8, 2009 12:22:35 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- f0a9a3cc
- Parents:
- 4ac8556
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/data_loader.py
r675e0ab rff3f900b 1 1 import os, sys,numpy 2 2 import wx 3 from dataFitting import Data1D , Theory1D4 from da nse.common.plottools.plottablesimport Data2D3 from dataFitting import Data1D 4 from dataFitting import Data2D 5 5 from DataLoader.loader import Loader 6 6 … … 74 74 """ 75 75 Use the DataLoader loader to created data to plot. 76 77 TODO: this method needs a major cleanup.78 It's a complete mess. It needs:79 - to be cleaned of code duplication80 - to be cleaned of data duplication: we should not81 need to reference all the Data1D data members.82 It should be sufficient to use the Data1D class83 defined in dataFitting (which btw needs a better name).84 85 76 @param path: the path of the data to load 86 77 """ … … 94 85 try: 95 86 output=L.load(path) 96 87 if output==None: 88 msg="Could not open this page" 89 wx.PostEvent(parent, StatusEvent(status=msg)) 90 return 97 91 except: 98 92 wx.PostEvent(parent, StatusEvent(status="Problem loading file: %s" % sys.exc_value)) 99 93 return 100 if output==None: 101 msg="Could not open this page" 102 wx.PostEvent(parent, StatusEvent(status=msg)) 103 return 94 95 104 96 filename = os.path.basename(path) 105 97 106 98 if not output.__class__.__name__=="list": 107 ## smearing info108 try:109 dxl = output.dxl110 dxw = output.dxw111 except:112 dxl = None113 dxw = None114 115 116 99 ## Creating a Data2D with output 117 100 if hasattr(output,'data'): 118 119 new_plot = Data2D(image=output.data,err_image=output.err_data, 120 xmin=output.xmin,xmax=output.xmax, 121 ymin=output.ymin,ymax=output.ymax) 122 new_plot.x_bins=output.x_bins 123 new_plot.y_bins=output.y_bins 124 125 ##Creating Data1D with output 101 new_plot = Data2D(image=None,err_image=None) 102 126 103 else: 127 ##dy values checked128 dy= output.dy129 if dy ==None:130 dy= numpy.zeros(len(output.y))131 132 104 msg="Loading 1D data: " 133 105 wx.PostEvent(parent, StatusEvent(status= "%s %s"%(msg, output.filename))) 134 new_plot = Data1D(x=output.x, y=output.y, dx=output.dx, 135 dy= dy, dxl=dxl, dxw=dxw) 136 # Copy all the data to the new object so that the 137 # new_plot object properly behaves as a data_info.Data1D. 138 # This also means that we should not have to copy all 139 # the data below... 140 output.clone_without_data(clone=new_plot) 141 142 ## source will request in dataLoader .manipulation module 143 new_plot.source=output.source 106 new_plot = Data1D(x=[], y=[], dx=None,dy= None) 107 108 new_plot.copy_from_datainfo(output) 109 output.clone_without_data(clone=new_plot) 110 144 111 ## data 's name 145 if output.filename==None :146 output.filename =str(filename)112 if output.filename==None or output.filename=="": 113 output.filename = str(filename) 147 114 ## name of the data allow to differentiate data when plotted 148 115 name= output.filename … … 152 119 ## create a copy of the loaded data 153 120 parent.indice_load_data[name]+=1 154 name = name +" (copy %i)"%parent.indice_load_data[name]155 121 name = name +"[%i]"%parent.indice_load_data[name] 122 156 123 new_plot.name = name 157 124 ## allow to highlight data when plotted … … 162 129 ## to save data 1D as cansas xml file 163 130 new_plot.info= output 164 ## detector used by dataLoader.manipulation module165 new_plot.detector =output.detector166 ## If the data file does not tell us what the axes are, just assume...167 new_plot.xaxis(output._xaxis,output._xunit)168 new_plot.yaxis(output._yaxis,output._yunit)169 131 ##group_id specify on which panel to plot this data 170 132 new_plot.group_id = name 171 133 new_plot.is_data =True 172 134 ##post data to plot 173 wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title=str(name))) 135 if hasattr(new_plot,"title"): 136 title= str(new_plot.title) 137 else: 138 title = str(name) 139 wx.PostEvent(parent, NewPlotEvent(plot=new_plot, title= title )) 174 140 175 141 ## the output of the loader is a list , some xml files contain more than one data 176 #TODO: refactor this so that there is no duplication of code.177 # There is no reason why the code above shouldn't be put in178 # a private method to be used within the loop below.179 142 else: 180 143 i=1 … … 188 151 dxl=None 189 152 dxw=None 190 dy = item.dy 191 if dy ==None: 192 dy= numpy.zeros(len(item.y)) 193 194 new_plot = Data1D(x=item.x,y=item.y,dx=dx,dy=item.dy,dxl=dxl,dxw=dxw) 195 # Copy all the data to the new object 153 154 new_plot = Data1D(x=item.x,y=item.y,dx=dx,dy=item.dy) 155 new_plot.copy_from_datainfo(item) 196 156 item.clone_without_data(clone=new_plot) 197 new_plot.source=item.source 198 157 new_plot.dxl = dxl 158 new_plot.dxw = dxw 159 199 160 name= str(item.run[0]) 200 161 if not name in parent.indice_load_data.keys(): … … 213 174 new_plot.name = name 214 175 new_plot.interactive = True 215 new_plot.detector =item.detector 216 # If the data file does not tell us what the axes are, just assume... 217 new_plot.xaxis(item._xaxis,item._xunit) 218 new_plot.yaxis(item._yaxis,item._yunit) 176 219 177 new_plot.group_id = name 220 178 new_plot.id = name
Note: See TracChangeset
for help on using the changeset viewer.