Changeset e2605a5 in sasview
- Timestamp:
- May 23, 2012 3:41:29 PM (13 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:
- 0c24e98
- Parents:
- d56fc67
- Location:
- sansdataloader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sansdataloader/src/sans/dataloader/data_info.py
rf60a8c2 re2605a5 728 728 msg = "Incompatible data sets: x-values do not match" 729 729 raise ValueError, msg 730 if self.dxl != None and other.dxl == None: 731 msg = "Incompatible data sets: dxl-values do not match" 732 raise ValueError, msg 733 if self.dxl == None and other.dxl != None: 734 msg = "Incompatible data sets: dxl-values do not match" 735 raise ValueError, msg 736 if self.dxw != None and other.dxw == None: 737 msg = "Incompatible data sets: dxw-values do not match" 738 raise ValueError, msg 739 if self.dxw == None and other.dxw != None: 740 msg = "Incompatible data sets: dxw-values do not match" 741 raise ValueError, msg 730 742 731 743 # Check that the other data set has errors, otherwise … … 748 760 dy, dy_other = self._validity_check(other) 749 761 result = self.clone_without_data(len(self.x)) 750 762 if self.dxw == None: 763 result.dxw = None 764 else: 765 result.dxw = numpy.zeros(len(self.x)) 766 if self.dxl == None: 767 result.dxl = None 768 else: 769 result.dxl = numpy.zeros(len(self.x)) 770 751 771 for i in range(len(self.x)): 752 772 result.x[i] = self.x[i] 753 773 if self.dx is not None and len(self.x) == len(self.dx): 754 774 result.dx[i] = self.dx[i] 775 if self.dxw is not None and len(self.x) == len(self.dxw): 776 result.dxw[i] = self.dxw[i] 777 if self.dxl is not None and len(self.x) == len(self.dxl): 778 result.dxl[i] = self.dxl[i] 755 779 756 780 a = Uncertainty(self.y[i], dy[i]**2) 757 781 if isinstance(other, Data1D): 758 782 b = Uncertainty(other.y[i], dy_other[i]**2) 783 if other.dx is not None: 784 result.dx[i] *= self.dx[i] 785 result.dx[i] += (other.dx[i]**2) 786 result.dx[i] /= 2 787 result.dx[i] = math.sqrt(result.dx[i]) 788 if result.dxl is not None and other.dxl is not None: 789 result.dxl[i] *= self.dxl[i] 790 other.dxl[i] += (other.dxl[i]**2) 791 result.dxl[i] /= 2 792 result.dxl[i] = math.sqrt(result.dxl[i]) 793 if result.dxw is not None and self.dxw is not None: 794 result.dxw[i] *= self.dxw[i] 795 other.dxw[i] += (other.dxw[i]**2) 796 result.dxw[i] /= 2 797 result.dxw[i] = math.sqrt(result.dxw[i]) 759 798 else: 760 799 b = other … … 866 905 msg = "Unable to perform operation: data length are not equal" 867 906 raise ValueError, msg 868 907 if numpy.size(self.qx_data) != numpy.size(other.qx_data): 908 msg = "Unable to perform operation: data length are not equal" 909 raise ValueError, msg 910 if numpy.size(self.qy_data) != numpy.size(other.qy_data): 911 msg = "Unable to perform operation: data length are not equal" 912 raise ValueError, msg 913 # Here we could also extrapolate between data points 914 for i in range(len(self.data)): 915 if self.qx_data[i] != other.qx_data[i]: 916 msg = "Incompatible data sets: qx-values do not match" 917 raise ValueError, msg 918 if self.qy_data[i] != other.qy_data[i]: 919 msg = "Incompatible data sets: qy-values do not match" 920 raise ValueError, msg 921 869 922 # Check that the scales match 870 #TODO: matching scales?871 872 # Check that the other data set has errors, otherwise873 # create zero vector874 #TODO: test this875 923 err_other = other.err_data 876 924 if other.err_data == None or \ 877 925 (numpy.size(other.err_data) != numpy.size(other.data)): 878 err_other = numpy.zeros([numpy.size(other.data, 0), 879 numpy.size(other.data, 1)]) 926 err_other = numpy.zeros(numpy.size(other.data)) 880 927 881 928 # Check that we have errors, otherwise create zero vector … … 883 930 if self.err_data == None or \ 884 931 (numpy.size(self.err_data) != numpy.size(self.data)): 885 err = numpy.zeros([numpy.size(self.data, 0), 886 numpy.size(self.data, 1)]) 932 err = numpy.zeros(numpy.size(other.data)) 887 933 888 934 return err, err_other … … 898 944 # First, check the data compatibility 899 945 dy, dy_other = self._validity_check(other) 900 901 result = self.clone_without_data([numpy.size(self.data, 0), 902 numpy.size(self.data, 1)]) 903 904 for i in range(numpy.size(self.data, 0)): 905 for j in range(numpy.size(self.data, 1)): 906 result.data[i][j] = self.data[i][j] 907 if self.err_data is not None and \ 908 numpy.size(self.data) == numpy.size(self.err_data): 909 result.err_data[i][j] = self.err_data[i][j] 910 911 a = Uncertainty(self.data[i][j], dy[i][j]**2) 912 if isinstance(other, Data2D): 913 b = Uncertainty(other.data[i][j], dy_other[i][j]**2) 914 else: 915 b = other 916 917 output = operation(a, b) 918 result.data[i][j] = output.x 919 result.err_data[i][j] = math.sqrt(math.fabs(output.variance)) 946 result = self.clone_without_data(numpy.size(self.data)) 947 result.xmin = self.xmin 948 result.xmax = self.xmax 949 result.ymin = self.ymin 950 result.ymax = self.ymax 951 if self.dqx_data == None or self.dqy_data == None: 952 result.dqx_data = None 953 result.dqy_data = None 954 else: 955 result.dqx_data = numpy.zeros(len(self.data)) 956 result.dqy_data = numpy.zeros(len(self.data)) 957 for i in range(numpy.size(self.data)): 958 result.data[i] = self.data[i] 959 if self.err_data is not None and \ 960 numpy.size(self.data) == numpy.size(self.err_data): 961 result.err_data[i] = self.err_data[i] 962 if self.dqx_data is not None: 963 result.dqx_data[i] = self.dqx_data[i] 964 if self.dqy_data is not None: 965 result.dqy_data[i] = self.dqy_data[i] 966 result.qx_data[i] = self.qx_data[i] 967 result.qy_data[i] = self.qy_data[i] 968 result.q_data[i] = self.q_data[i] 969 result.mask[i] = self.mask[i] 970 971 a = Uncertainty(self.data[i], dy[i]**2) 972 if isinstance(other, Data2D): 973 b = Uncertainty(other.data[i], dy_other[i]**2) 974 if other.dqx_data is not None and \ 975 result.dqx_data is not None: 976 result.dqx_data[i] *= self.dqx_data[i] 977 result.dqx_data[i] += (other.dqx_data[i]**2) 978 result.dqx_data[i] /= 2 979 result.dqx_data[i] = math.sqrt(result.dqx_data[i]) 980 if other.dqy_data is not None and \ 981 result.dqy_data is not None: 982 result.dqy_data[i] *= self.dqy_data[i] 983 result.dqy_data[i] += (other.dqy_data[i]**2) 984 result.dqy_data[i] /= 2 985 result.dqy_data[i] = math.sqrt(result.dqy_data[i]) 986 else: 987 b = other 988 989 output = operation(a, b) 990 result.data[i] = output.x 991 result.err_data[i] = math.sqrt(math.fabs(output.variance)) 920 992 return result -
sansdataloader/test/utest_manipulations.py
rca3b9c5d re2605a5 133 133 def setUp(self): 134 134 # Create two data sets to play with 135 x_0 = 2.0*numpy.ones([5,4]) 136 dx_0 = 0.5*numpy.ones([5,4]) 137 self.data = Data2D(x_0, dx_0) 138 139 y = numpy.ones([5,4]) 140 dy = numpy.ones([5,4]) 141 self.data2 = Data2D(y, dy) 135 x_0 = 2.0*numpy.ones(100) 136 dx_0 = 0.5*numpy.ones(100) 137 qx_0 = numpy.arange(100) 138 qy_0 = numpy.arange(100) 139 mask_0 = numpy.zeros(100) 140 dqx_0 = numpy.arange(100)/100 141 dqy_0 = numpy.arange(100)/100 142 q_0 = numpy.sqrt(qx_0 * qx_0 + qy_0 * qy_0) 143 self.data = Data2D(x_0, dx_0, qx_0, qy_0, q_0, mask_0, dqx_0, dqy_0) 144 145 y = numpy.ones(100) 146 dy = numpy.ones(100) 147 qx = numpy.arange(100) 148 qy = numpy.arange(100) 149 mask = numpy.zeros(100) 150 q = numpy.sqrt(qx * qx + qy * qy) 151 self.data2 = Data2D(y, dy, qx, qy, q, mask) 142 152 143 153 … … 147 157 """ 148 158 # There should be 5 entries in the file 149 self.assertEqual(numpy.size(self.data.data, 0), 5) 150 self.assertEqual(numpy.size(self.data.data, 1), 4) 151 152 for i in range(5): 153 for j in range(4): 154 # All y-error values should be 0.5 155 self.assertEqual(self.data.err_data[i][j], 0.5) 156 157 # All y values should be 2.0 158 self.assertEqual(self.data.data[i][j], 2.0) 159 self.assertEqual(numpy.size(self.data.data), 100) 160 161 for i in range(100): 162 # All y-error values should be 0.5 163 self.assertEqual(self.data.err_data[i], 0.5) 164 165 # All y values should be 2.0 166 self.assertEqual(self.data.data[i], 2.0) 159 167 160 168 def test_add(self): 161 169 result = self.data2+self.data 162 for i in range(5): 163 for j in range(4): 164 self.assertEqual(result.data[i][j], 3.0) 165 self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0)) 170 for i in range(100): 171 self.assertEqual(result.data[i], 3.0) 172 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 166 173 167 174 def test_sub(self): 168 175 result = self.data2-self.data 169 for i in range(5): 170 for j in range(4): 171 self.assertEqual(result.data[i][j], -1.0) 172 self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0)) 176 for i in range(100): 177 self.assertEqual(result.data[i], -1.0) 178 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 173 179 174 180 def test_mul(self): 175 181 result = self.data2*self.data 176 for i in range(5): 177 for j in range(4): 178 self.assertEqual(result.data[i][j], 2.0) 179 self.assertEqual(result.err_data[i][j], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 182 for i in range(100): 183 self.assertEqual(result.data[i], 2.0) 184 self.assertEqual(result.err_data[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 180 185 181 186 def test_div(self): 182 187 result = self.data2/self.data 183 for i in range(5): 184 for j in range(4): 185 self.assertEqual(result.data[i][j], 0.5) 186 self.assertEqual(result.err_data[i][j], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 188 for i in range(100): 189 self.assertEqual(result.data[i], 0.5) 190 self.assertEqual(result.err_data[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 187 191 188 192 def test_radd(self): 189 193 result = self.data+3.0 190 for i in range(5): 191 for j in range(4): 192 self.assertEqual(result.data[i][j], 5.0) 193 self.assertEqual(result.err_data[i][j], 0.5) 194 for i in range(100): 195 self.assertEqual(result.data[i], 5.0) 196 self.assertEqual(result.err_data[i], 0.5) 194 197 195 198 result = 3.0+self.data 196 for i in range(5): 197 for j in range(4): 198 self.assertEqual(result.data[i][j], 5.0) 199 self.assertEqual(result.err_data[i][j], 0.5) 199 for i in range(100): 200 self.assertEqual(result.data[i], 5.0) 201 self.assertEqual(result.err_data[i], 0.5) 200 202 201 203 def test_rsub(self): 202 204 result = self.data-3.0 203 for i in range(5): 204 for j in range(4): 205 self.assertEqual(result.data[i][j], -1.0) 206 self.assertEqual(result.err_data[i][j], 0.5) 205 for i in range(100): 206 self.assertEqual(result.data[i], -1.0) 207 self.assertEqual(result.err_data[i], 0.5) 207 208 208 209 result = 3.0-self.data 209 for i in range(5): 210 for j in range(4): 211 self.assertEqual(result.data[i][j], 1.0) 212 self.assertEqual(result.err_data[i][j], 0.5) 210 for i in range(100): 211 self.assertEqual(result.data[i], 1.0) 212 self.assertEqual(result.err_data[i], 0.5) 213 213 214 214 def test_rmul(self): 215 215 result = self.data*3.0 216 for i in range(5): 217 for j in range(4): 218 self.assertEqual(result.data[i][j], 6.0) 219 self.assertEqual(result.err_data[i][j], 1.5) 216 for i in range(100): 217 self.assertEqual(result.data[i], 6.0) 218 self.assertEqual(result.err_data[i], 1.5) 220 219 221 220 result = 3.0*self.data 222 for i in range(5): 223 for j in range(4): 224 self.assertEqual(result.data[i][j], 6.0) 225 self.assertEqual(result.err_data[i][j], 1.5) 221 for i in range(100): 222 self.assertEqual(result.data[i], 6.0) 223 self.assertEqual(result.err_data[i], 1.5) 226 224 227 225 def test_rdiv(self): 228 226 result = self.data/4.0 229 for i in range(5): 230 for j in range(4): 231 self.assertEqual(result.data[i][j], 0.5) 232 self.assertEqual(result.err_data[i][j], 0.125) 227 for i in range(100): 228 self.assertEqual(result.data[i], 0.5) 229 self.assertEqual(result.err_data[i], 0.125) 233 230 234 231 result = 6.0/self.data 235 for i in range(5): 236 for j in range(4): 237 self.assertEqual(result.data[i][j], 3.0) 238 self.assertEqual(result.err_data[i][j], 6.0*0.5/4.0) 232 for i in range(100): 233 self.assertEqual(result.data[i], 3.0) 234 self.assertEqual(result.err_data[i], 6.0*0.5/4.0) 239 235 240 236
Note: See TracChangeset
for help on using the changeset viewer.