- Timestamp:
- Apr 23, 2010 10:06:21 AM (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:
- 18d0bba
- Parents:
- 8569cb9
- Location:
- guiframe
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/dataFitting.py
r8e87ece r901142f 4 4 import copy 5 5 import numpy 6 6 import math 7 from data_util.uncertainty import Uncertainty 7 8 from danse.common.plottools.plottables import Data1D as PlotData1D 8 9 from danse.common.plottools.plottables import Data2D as PlotData2D … … 17 18 PlotData1D.__init__(self, x, y, dx, dy) 18 19 LoadData1D.__init__(self, x, y, dx, dy) 19 self.id = None20 self.group_id = None20 self.id = None 21 self.group_id = None 21 22 self.is_data = True 22 23 … … 36 37 self.dxw = copy.deepcopy(data1d.dxw) 37 38 38 self.xaxis(data1d._xaxis, data1d._xunit)39 self.yaxis(data1d._yaxis, data1d._yunit)39 self.xaxis(data1d._xaxis, data1d._xunit) 40 self.yaxis(data1d._yaxis, data1d._yunit) 40 41 41 42 def __str__(self): … … 46 47 47 48 return _str 49 50 def _perform_operation(self, other, operation): 51 """ 52 """ 53 # First, check the data compatibility 54 dy, dy_other = self._validity_check(other) 55 result = Data1D(x=[], y=[], dx=None, dy=None) 56 result.clone_without_data(clone=self) 57 result.copy_from_datainfo(data1d=self) 58 for i in range(len(self.x)): 59 result.x[i] = self.x[i] 60 if self.dx is not None and len(self.x) == len(self.dx): 61 result.dx[i] = self.dx[i] 62 63 a = Uncertainty(self.y[i], dy[i]**2) 64 if isinstance(other, Data1D): 65 b = Uncertainty(other.y[i], dy_other[i]**2) 66 else: 67 b = other 68 69 output = operation(a, b) 70 result.y[i] = output.x 71 if result.dy is None: result.dy = numpy.zeros(len(self.x)) 72 result.dy[i] = math.sqrt(math.fabs(output.variance)) 73 return result 74 48 75 class Theory1D(PlotTheory1D,LoadData1D): 49 76 50 def __init__(self, x=[],y=[],dy=None):77 def __init__(self, x=[], y=[], dy=None): 51 78 PlotTheory1D.__init__(self, x, y, dy) 52 79 LoadData1D.__init__(self, x, y, dy) 53 self.id = None80 self.id = None 54 81 self.group_id = None 55 82 self.is_data = True … … 68 95 if hasattr(data1d, "dxw"): 69 96 self.dxw = copy.deepcopy(data1d.dxw) 70 self.xaxis(data1d._xaxis, data1d._xunit)71 self.yaxis(data1d._yaxis, data1d._yunit)97 self.xaxis(data1d._xaxis, data1d._xunit) 98 self.yaxis(data1d._yaxis, data1d._yunit) 72 99 73 100 def __str__(self): … … 78 105 79 106 return _str 107 108 def _perform_operation(self, other, operation): 109 """ 110 """ 111 # First, check the data compatibility 112 dy, dy_other = self._validity_check(other) 113 result = Theory1D(x=[], y=[], dy=None) 114 result.clone_without_data(clone=self) 115 result.copy_from_datainfo(data1d=self) 116 for i in range(len(self.x)): 117 result.x[i] = self.x[i] 118 119 a = Uncertainty(self.y[i], dy[i]**2) 120 if isinstance(other, Data1D): 121 b = Uncertainty(other.y[i], dy_other[i]**2) 122 else: 123 b = other 124 125 output = operation(a, b) 126 result.y[i] = output.x 127 if result.dy is None: result.dy = numpy.zeros(len(self.x)) 128 result.dy[i] = math.sqrt(math.fabs(output.variance)) 129 return result 130 80 131 81 132 class Data2D(PlotData2D,LoadData2D): 82 def __init__(self,image=None,err_image=None,xmin=None,xmax=None,ymin=None,ymax=None,zmin=None,zmax=None): 83 84 PlotData2D.__init__(self, image=image, err_image=err_image,xmin=xmin, xmax=xmax, 85 ymin=ymin, ymax=ymax) 86 87 LoadData2D.__init__(self,data=image, err_data=err_image, qx_data=None,qy_data=None,q_data=None,mask=None) 133 def __init__(self, image=None, err_image=None, 134 xmin=None, xmax=None, ymin=None, ymax=None, 135 zmin=None, zmax=None, qx_data=None, qy_data=None, 136 q_data=None, mask=None, dqx_data=None, dqy_data=None): 137 138 PlotData2D.__init__(self, image=image, err_image=err_image, 139 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, 140 zmin=zmin, zmax=zmax, qx_data=qx_data, 141 qy_data=qy_data) 142 143 LoadData2D.__init__(self, data=image, err_data=err_image, 144 qx_data=qx_data, qy_data=qy_data, 145 dqx_data=dqx_data, dqy_data=dqy_data, 146 q_data=q_data, mask=mask) 88 147 89 148 def copy_from_datainfo(self, data2d): … … 92 151 """ 93 152 self.data = copy.deepcopy(data2d.data) 94 self.qx_data 95 self.qy_data 96 self.q_data 153 self.qx_data = copy.deepcopy(data2d.qx_data) 154 self.qy_data = copy.deepcopy(data2d.qy_data) 155 self.q_data = copy.deepcopy(data2d.q_data) 97 156 self.mask = copy.deepcopy(data2d.mask) 98 157 self.err_data = copy.deepcopy(data2d.err_data) … … 104 163 self.ymin = data2d.ymin 105 164 self.ymax = data2d.ymax 106 107 self.xaxis(data2d._xaxis,data2d._xunit) 108 self.yaxis(data2d._yaxis,data2d._yunit) 165 self.zmin = data2d.zmin 166 self.zmax = data2d.zmax 167 168 self.xaxis(data2d._xaxis, data2d._xunit) 169 self.yaxis(data2d._yaxis, data2d._yunit) 109 170 110 171 def __str__(self): … … 115 176 116 177 return _str 117 178 179 def _perform_operation(self, other, operation): 180 """ 181 Perform 2D operations between data sets 182 183 @param other: other data set 184 @param operation: function defining the operation 185 """ 186 # First, check the data compatibility 187 dy, dy_other = self._validity_check(other) 188 189 result = Data2D(image=None, qx_data=None, qy_data=None, 190 err_image=None, xmin=None, xmax=None, 191 ymin=None, ymax=None, zmin=None, zmax=None) 192 193 result.clone_without_data(clone=self) 194 result.copy_from_datainfo(data2d=self) 195 196 for i in range(numpy.size(self.data,0)): 197 for j in range(numpy.size(self.data,1)): 198 result.data[i][j] = self.data[i][j] 199 if self.err_data is not None and \ 200 numpy.size(self.data)==numpy.size(self.err_data): 201 result.err_data[i][j] = self.err_data[i][j] 202 203 a = Uncertainty(self.data[i][j], dy[i][j]**2) 204 if isinstance(other, Data2D): 205 b = Uncertainty(other.data[i][j], dy_other[i][j]**2) 206 else: 207 b = other 208 209 output = operation(a, b) 210 result.data[i][j] = output.x 211 result.err_data[i][j] = math.sqrt(math.fabs(output.variance)) 212 return result 213
Note: See TracChangeset
for help on using the changeset viewer.