- Timestamp:
- Jun 8, 2009 12:22:35 PM (16 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
- Location:
- guiframe
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/dataFitting.py
r1abcb04 rff3f900b 1 1 """ 2 A Data1D class compatible with guiframe from the output of DataLoader.2 Adapters for fitting module 3 3 """ 4 from danse.common.plottools.plottables import Data1D as plotData1D5 from danse.common.plottools.plottables import Theory1D as plotTheory1D4 from danse.common.plottools.plottables import Data1D as PlotData1D 5 from danse.common.plottools.plottables import Data2D as PlotData2D 6 6 7 from DataLoader.data_info import Data1D as loader_data_1D 7 from DataLoader.data_info import Data1D as LoadData1D 8 from DataLoader.data_info import Data2D as LoadData2D 8 9 9 class Data1D(plotData1D, loader_data_1D): 10 """ 11 A Data1D class compatible with guiframe from 12 the output of DataLoader. The new class inherits 13 from DataLoader.data_info.Data1D 14 """ 15 def __init__(self,x=[],y=[],dx=None,dy=None,dxl=None, dxw=None): 16 plotData1D.__init__(self, x, y, dx, dy) 17 loader_data_1D.__init__(self, x=x, y=y, dx=dx, dy=dy) 18 self.smearer=None 19 20 self.dxl = dxl 21 self.dxw = dxw 22 23 class Theory1D(plotTheory1D, loader_data_1D): 24 """ 25 A Theory1D class compatible with guiframe from 26 the output of DataLoader. The new class inherits 27 from DataLoader.data_info.Data1D 28 """ 29 def __init__(self,x=[],y=[],dy=None,dxl=None, dxw=None): 30 plotTheory1D.__init__(self, x, y) 31 loader_data_1D.__init__(self, x=x, y=y, dx=dx, dy=dy) 32 self.smearer=None 10 import copy 11 12 class Data1D(PlotData1D,LoadData1D): 13 14 def __init__(self,x=[],y=[],dx=None,dy=None): 15 PlotData1D.__init__(self, x, y, dx, dy) 16 LoadData1D.__init__(self, x, y, dx, dy) 17 self.id= None 18 self.group_id =None 19 self.is_data = True 20 21 def copy_from_datainfo(self, data1d): 22 """ 23 copy values of Data1D of type DataLaoder.Data_info 24 """ 25 self.x = copy.deepcopy(data1d.x) 26 self.dx = copy.deepcopy(data1d.dx) 27 self.y = copy.deepcopy(data1d.y) 28 self.dy = copy.deepcopy(data1d.dy) 29 dxl = copy.deepcopy(data1d.dxl) 30 dxw = copy.deepcopy(data1d.dxw) 31 32 self.xaxis(data1d._xaxis,data1d._xunit) 33 self.yaxis(data1d._yaxis,data1d._yunit) 34 35 36 37 class Data2D(PlotData2D,LoadData2D): 38 def __init__(self,image=None,err_image=None,xmin=None,xmax=None,ymin=None,ymax=None,zmin=None,zmax=None): 33 39 34 self.dxl = dxl 35 self.dxw = dxw 36 40 PlotData2D.__init__(self, image=image, err_image=err_image,xmin=xmin, xmax=xmax, 41 ymin=ymin, ymax=ymax) 42 43 LoadData2D.__init__(self,data=image, err_data=err_image) 44 45 def copy_from_datainfo(self, data2d): 46 """ 47 copy value of Data2D of type DataLoader.data_info 48 """ 49 self.data = copy.deepcopy(data2d.data) 50 self.err_data = copy.deepcopy(data2d.err_data) 51 self.x_bins = copy.deepcopy(data2d.x_bins) 52 self.y_bins = copy.deepcopy(data2d.y_bins) 53 54 self.xmin = data2d.xmin 55 self.xmax = data2d.xmax 56 self.ymin = data2d.ymin 57 self.ymax = data2d.ymax 58 59 self.xaxis(data2d._xaxis,data2d._xunit) 60 self.yaxis(data2d._yaxis,data2d._yunit) 61 62 63 -
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.