Changeset ed2276f in sasview for src/sas/sascalc
- Timestamp:
- Apr 4, 2017 12:00:18 PM (8 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.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 7b15990
- Parents:
- 9a5097c (diff), 571bf4b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Andrew Jackson <andrew.jackson@…> (04/04/17 12:00:18)
- git-committer:
- GitHub <noreply@…> (04/04/17 12:00:18)
- Location:
- src/sas/sascalc
- Files:
-
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/manipulations.py
r9a5097c red2276f 80 80 81 81 """ 82 if data2d.data == None or data2d.x_bins == None or data2d.y_bins ==None:82 if data2d.data is None or data2d.x_bins is None or data2d.y_bins is None: 83 83 raise ValueError, "Can't convert this data: data=None..." 84 84 new_x = np.tile(data2d.x_bins, (len(data2d.y_bins), 1)) … … 92 92 if data2d.err_data == None or np.any(data2d.err_data <= 0): 93 93 new_err_data = np.sqrt(np.abs(new_data)) 94 94 95 else: 95 96 new_err_data = data2d.err_data.flatten() -
src/sas/sascalc/dataloader/readers/IgorReader.py
r9a5097c red2276f 13 13 ############################################################################# 14 14 import os 15 15 16 import numpy as np 16 17 import math 17 18 #import logging 19 18 20 from sas.sascalc.dataloader.data_info import Data2D 19 21 from sas.sascalc.dataloader.data_info import Detector … … 40 42 """ Read file """ 41 43 if not os.path.isfile(filename): 42 raise ValueError, \ 43 "Specified file %s is not a regular file" % filename 44 45 # Read file 46 f = open(filename, 'r') 47 buf = f.read() 48 49 # Instantiate data object 44 raise ValueError("Specified file %s is not a regular " 45 "file" % filename) 46 50 47 output = Data2D() 48 51 49 output.filename = os.path.basename(filename) 52 50 detector = Detector() 53 if len(output.detector) > 0:54 print str(output.detector[0])51 if len(output.detector): 52 print(str(output.detector[0])) 55 53 output.detector.append(detector) 56 57 # Get content 58 dataStarted = False 59 60 lines = buf.split('\n') 61 itot = 0 62 x = [] 63 y = [] 64 65 ncounts = 0 66 67 xmin = None 68 xmax = None 69 ymin = None 70 ymax = None 71 72 i_x = 0 73 i_y = -1 74 i_tot_row = 0 75 76 isInfo = False 77 isCenter = False 78 79 data_conv_q = None 80 data_conv_i = None 81 82 if has_converter == True and output.Q_unit != '1/A': 54 55 data_conv_q = data_conv_i = None 56 57 if has_converter and output.Q_unit != '1/A': 83 58 data_conv_q = Converter('1/A') 84 59 # Test it 85 60 data_conv_q(1.0, output.Q_unit) 86 61 87 if has_converter == Trueand output.I_unit != '1/cm':62 if has_converter and output.I_unit != '1/cm': 88 63 data_conv_i = Converter('1/cm') 89 64 # Test it 90 65 data_conv_i(1.0, output.I_unit) 91 66 92 67 for line in lines: 93 68 … … 120 95 output.data = np.zeros([size_x, size_y]) 121 96 output.err_data = np.zeros([size_x, size_y]) 122 123 #Read Header and 2D data 124 for line in lines: 125 # Find setup info line 126 if isInfo: 127 isInfo = False 128 line_toks = line.split() 129 # Wavelength in Angstrom 130 try: 131 wavelength = float(line_toks[1]) 132 except: 133 msg = "IgorReader: can't read this file, missing wavelength" 134 raise ValueError, msg 135 # Distance in meters 136 try: 137 distance = float(line_toks[3]) 138 except: 139 msg = "IgorReader: can't read this file, missing distance" 140 raise ValueError, msg 141 142 # Distance in meters 143 try: 144 transmission = float(line_toks[4]) 145 except: 146 msg = "IgorReader: can't read this file, " 147 msg += "missing transmission" 148 raise ValueError, msg 149 150 if line.count("LAMBDA") > 0: 151 isInfo = True 152 153 # Find center info line 154 if isCenter: 155 isCenter = False 156 line_toks = line.split() 157 158 # Center in bin number: Must substrate 1 because 159 #the index starts from 1 160 center_x = float(line_toks[0]) - 1 161 center_y = float(line_toks[1]) - 1 162 163 if line.count("BCENT") > 0: 164 isCenter = True 165 166 # Find data start 167 if line.count("***")>0: 168 dataStarted = True 169 170 # Check that we have all the info 171 if wavelength == None \ 172 or distance == None \ 173 or center_x == None \ 174 or center_y == None: 175 msg = "IgorReader:Missing information in data file" 176 raise ValueError, msg 177 178 if dataStarted == True: 179 try: 180 value = float(line) 181 except: 182 # Found a non-float entry, skip it 183 continue 184 185 # Get bin number 186 if math.fmod(itot, i_tot_row) == 0: 187 i_x = 0 188 i_y += 1 189 else: 190 i_x += 1 191 192 output.data[i_y][i_x] = value 193 ncounts += 1 194 195 # Det 640 x 640 mm 196 # Q = 4pi/lambda sin(theta/2) 197 # Bin size is 0.5 cm 198 #REmoved +1 from theta = (i_x-center_x+1)*0.5 / distance 199 # / 100.0 and 200 #REmoved +1 from theta = (i_y-center_y+1)*0.5 / 201 # distance / 100.0 202 #ToDo: Need complete check if the following 203 # covert process is consistent with fitting.py. 204 theta = (i_x - center_x) * 0.5 / distance / 100.0 205 qx = 4.0 * math.pi / wavelength * math.sin(theta/2.0) 206 207 if has_converter == True and output.Q_unit != '1/A': 208 qx = data_conv_q(qx, units=output.Q_unit) 209 210 if xmin == None or qx < xmin: 211 xmin = qx 212 if xmax == None or qx > xmax: 213 xmax = qx 214 215 theta = (i_y - center_y) * 0.5 / distance / 100.0 216 qy = 4.0 * math.pi / wavelength * math.sin(theta / 2.0) 217 218 if has_converter == True and output.Q_unit != '1/A': 219 qy = data_conv_q(qy, units=output.Q_unit) 220 221 if ymin == None or qy < ymin: 222 ymin = qy 223 if ymax == None or qy > ymax: 224 ymax = qy 225 226 if not qx in x: 227 x.append(qx) 228 if not qy in y: 229 y.append(qy) 230 231 itot += 1 232 233 97 98 data_row = 0 99 wavelength = distance = center_x = center_y = None 100 dataStarted = isInfo = isCenter = False 101 102 with open(filename, 'r') as f: 103 for line in f: 104 data_row += 1 105 # Find setup info line 106 if isInfo: 107 isInfo = False 108 line_toks = line.split() 109 # Wavelength in Angstrom 110 try: 111 wavelength = float(line_toks[1]) 112 except ValueError: 113 msg = "IgorReader: can't read this file, missing wavelength" 114 raise ValueError(msg) 115 # Distance in meters 116 try: 117 distance = float(line_toks[3]) 118 except ValueError: 119 msg = "IgorReader: can't read this file, missing distance" 120 raise ValueError(msg) 121 122 # Distance in meters 123 try: 124 transmission = float(line_toks[4]) 125 except: 126 msg = "IgorReader: can't read this file, " 127 msg += "missing transmission" 128 raise ValueError(msg) 129 130 if line.count("LAMBDA"): 131 isInfo = True 132 133 # Find center info line 134 if isCenter: 135 isCenter = False 136 line_toks = line.split() 137 138 # Center in bin number: Must subtract 1 because 139 # the index starts from 1 140 center_x = float(line_toks[0]) - 1 141 center_y = float(line_toks[1]) - 1 142 143 if line.count("BCENT"): 144 isCenter = True 145 146 # Find data start 147 if line.count("***"): 148 # now have to continue to blank line 149 dataStarted = True 150 151 # Check that we have all the info 152 if (wavelength is None 153 or distance is None 154 or center_x is None 155 or center_y is None): 156 msg = "IgorReader:Missing information in data file" 157 raise ValueError(msg) 158 159 if dataStarted: 160 if len(line.rstrip()): 161 continue 162 else: 163 break 164 165 # The data is loaded in row major order (last index changing most 166 # rapidly). However, the original data is in column major order (first 167 # index changing most rapidly). The swap to column major order is done 168 # in reader2D_converter at the end of this method. 169 data = np.loadtxt(filename, skiprows=data_row) 170 size_x = size_y = int(np.rint(np.sqrt(data.size))) 171 output.data = np.reshape(data, (size_x, size_y)) 172 output.err_data = np.zeros_like(output.data) 173 174 # Det 640 x 640 mm 175 # Q = 4 * pi/lambda * sin(theta/2) 176 # Bin size is 0.5 cm 177 # Removed +1 from theta = (i_x - center_x + 1)*0.5 / distance 178 # / 100.0 and 179 # Removed +1 from theta = (i_y - center_y + 1)*0.5 / 180 # distance / 100.0 181 # ToDo: Need complete check if the following 182 # convert process is consistent with fitting.py. 183 184 # calculate qx, qy bin centers of each pixel in the image 185 theta = (np.arange(size_x) - center_x) * 0.5 / distance / 100. 186 qx = 4 * np.pi / wavelength * np.sin(theta/2) 187 188 theta = (np.arange(size_y) - center_y) * 0.5 / distance / 100. 189 qy = 4 * np.pi / wavelength * np.sin(theta/2) 190 191 if has_converter and output.Q_unit != '1/A': 192 qx = data_conv_q(qx, units=output.Q_unit) 193 qy = data_conv_q(qx, units=output.Q_unit) 194 195 xmax = np.max(qx) 196 xmin = np.min(qx) 197 ymax = np.max(qy) 198 ymin = np.min(qy) 199 200 # calculate edge offset in q. 234 201 theta = 0.25 / distance / 100.0 235 xstep = 4.0 * math.pi / wavelength * math.sin(theta / 2.0)202 xstep = 4.0 * np.pi / wavelength * np.sin(theta / 2.0) 236 203 237 204 theta = 0.25 / distance / 100.0 238 ystep = 4.0 * math.pi/ wavelength * math.sin(theta / 2.0)205 ystep = 4.0 * np.pi/ wavelength * np.sin(theta / 2.0) 239 206 240 207 # Store all data ###################################### 241 208 # Store wavelength 242 if has_converter == Trueand output.source.wavelength_unit != 'A':209 if has_converter and output.source.wavelength_unit != 'A': 243 210 conv = Converter('A') 244 211 wavelength = conv(wavelength, units=output.source.wavelength_unit) … … 246 213 247 214 # Store distance 248 if has_converter == Trueand detector.distance_unit != 'm':215 if has_converter and detector.distance_unit != 'm': 249 216 conv = Converter('m') 250 217 distance = conv(distance, units=detector.distance_unit) … … 254 221 output.sample.transmission = transmission 255 222 256 # Store pixel size 223 # Store pixel size (mm) 257 224 pixel = 5.0 258 if has_converter == Trueand detector.pixel_size_unit != 'mm':225 if has_converter and detector.pixel_size_unit != 'mm': 259 226 conv = Converter('mm') 260 227 pixel = conv(pixel, units=detector.pixel_size_unit) … … 267 234 268 235 # Store limits of the image (2D array) 269 xmin = xmin -xstep / 2.0270 xmax = xmax +xstep / 2.0271 ymin = ymin -ystep / 2.0272 ymax = ymax +ystep / 2.0273 if has_converter == Trueand output.Q_unit != '1/A':236 xmin -= xstep / 2.0 237 xmax += xstep / 2.0 238 ymin -= ystep / 2.0 239 ymax += ystep / 2.0 240 if has_converter and output.Q_unit != '1/A': 274 241 xmin = data_conv_q(xmin, units=output.Q_unit) 275 242 xmax = data_conv_q(xmax, units=output.Q_unit) … … 282 249 283 250 # Store x and y axis bin centers 284 output.x_bins = x285 output.y_bins = y251 output.x_bins = qx.tolist() 252 output.y_bins = qy.tolist() 286 253 287 254 # Units -
src/sas/sascalc/dataloader/readers/cansas_reader.py
rc221349 r8434365 930 930 self._write_data(datainfo, entry_node) 931 931 # Transmission Spectrum Info 932 self._write_trans_spectrum(datainfo, entry_node) 932 # TODO: fix the writer to linearize all data, including T_spectrum 933 # self._write_trans_spectrum(datainfo, entry_node) 933 934 # Sample info 934 935 self._write_sample_info(datainfo, entry_node) -
src/sas/sascalc/calculator/BaseComponent.py
rdeddda1 r9a5097c 9 9 from collections import OrderedDict 10 10 11 import numpy 11 import numpy as np 12 12 #TO DO: that about a way to make the parameter 13 13 #is self return if it is fittable or not … … 119 119 Then get :: 120 120 121 q = n umpy.sqrt(qx_prime^2+qy_prime^2)121 q = np.sqrt(qx_prime^2+qy_prime^2) 122 122 123 123 that is a qr in 1D array; :: … … 150 150 151 151 # calculate q_r component for 2D isotropic 152 q = n umpy.sqrt(qx**2+qy**2)152 q = np.sqrt(qx**2+qy**2) 153 153 # vectorize the model function runXY 154 v_model = n umpy.vectorize(self.runXY, otypes=[float])154 v_model = np.vectorize(self.runXY, otypes=[float]) 155 155 # calculate the scattering 156 156 iq_array = v_model(q) … … 160 160 elif qdist.__class__.__name__ == 'ndarray': 161 161 # We have a simple 1D distribution of q-values 162 v_model = n umpy.vectorize(self.runXY, otypes=[float])162 v_model = np.vectorize(self.runXY, otypes=[float]) 163 163 iq_array = v_model(qdist) 164 164 return iq_array -
src/sas/sascalc/calculator/instrument.py
rb699768 r9a5097c 3 3 control instrumental parameters 4 4 """ 5 import numpy 5 import numpy as np 6 6 7 7 # defaults in cgs unit … … 168 168 self.spectrum = self.get_default_spectrum() 169 169 # intensity in counts/sec 170 self.intensity = n umpy.interp(self.wavelength,170 self.intensity = np.interp(self.wavelength, 171 171 self.spectrum[0], 172 172 self.spectrum[1], … … 203 203 """ 204 204 spectrum = self.spectrum 205 intensity = n umpy.interp(self.wavelength,205 intensity = np.interp(self.wavelength, 206 206 spectrum[0], 207 207 spectrum[1], … … 244 244 self.wavelength = wavelength 245 245 validate(wavelength) 246 self.intensity = n umpy.interp(self.wavelength,246 self.intensity = np.interp(self.wavelength, 247 247 self.spectrum[0], 248 248 self.spectrum[1], … … 305 305 get default spectrum 306 306 """ 307 return n umpy.array(_LAMBDA_ARRAY)307 return np.array(_LAMBDA_ARRAY) 308 308 309 309 def get_band(self): … … 345 345 get list of the intensity wrt wavelength_list 346 346 """ 347 out = n umpy.interp(self.wavelength_list,347 out = np.interp(self.wavelength_list, 348 348 self.spectrum[0], 349 349 self.spectrum[1], -
src/sas/sascalc/calculator/resolution_calculator.py
rb699768 r9a5097c 12 12 from math import sqrt 13 13 import math 14 import numpy 14 import numpy as np 15 15 import sys 16 16 import logging … … 393 393 dx_size = (self.qx_max - self.qx_min) / (1000 - 1) 394 394 dy_size = (self.qy_max - self.qy_min) / (1000 - 1) 395 x_val = n umpy.arange(self.qx_min, self.qx_max, dx_size)396 y_val = n umpy.arange(self.qy_max, self.qy_min, -dy_size)397 q_1, q_2 = n umpy.meshgrid(x_val, y_val)395 x_val = np.arange(self.qx_min, self.qx_max, dx_size) 396 y_val = np.arange(self.qy_max, self.qy_min, -dy_size) 397 q_1, q_2 = np.meshgrid(x_val, y_val) 398 398 #q_phi = numpy.arctan(q_1,q_2) 399 399 # check whether polar or cartesian … … 887 887 x_value = x_val - x0_val 888 888 y_value = y_val - y0_val 889 phi_i = n umpy.arctan2(y_val, x_val)889 phi_i = np.arctan2(y_val, x_val) 890 890 891 891 # phi correction due to the gravity shift (in phi) … … 893 893 phi_i = phi_i - phi_0 + self.gravity_phi 894 894 895 sin_phi = n umpy.sin(self.gravity_phi)896 cos_phi = n umpy.cos(self.gravity_phi)895 sin_phi = np.sin(self.gravity_phi) 896 cos_phi = np.cos(self.gravity_phi) 897 897 898 898 x_p = x_value * cos_phi + y_value * sin_phi … … 908 908 nu_value = -0.5 * (new_x * new_x + new_y * new_y) 909 909 910 gaussian = n umpy.exp(nu_value)910 gaussian = np.exp(nu_value) 911 911 # normalizing factor correction 912 912 gaussian /= gaussian.sum() … … 954 954 nu_value *= nu_value 955 955 nu_value *= -0.5 956 gaussian *= n umpy.exp(nu_value)956 gaussian *= np.exp(nu_value) 957 957 gaussian /= sigma 958 958 # normalize … … 1026 1026 offset_x, offset_y) 1027 1027 # distance [cm] from the beam center on detector plane 1028 detector_ind_x = n umpy.arange(detector_pix_nums_x)1029 detector_ind_y = n umpy.arange(detector_pix_nums_y)1028 detector_ind_x = np.arange(detector_pix_nums_x) 1029 detector_ind_y = np.arange(detector_pix_nums_y) 1030 1030 1031 1031 # shif 0.5 pixel so that pix position is at the center of the pixel … … 1041 1041 detector_ind_y = detector_ind_y * pix_y_size 1042 1042 1043 qx_value = n umpy.zeros(len(detector_ind_x))1044 qy_value = n umpy.zeros(len(detector_ind_y))1043 qx_value = np.zeros(len(detector_ind_x)) 1044 qy_value = np.zeros(len(detector_ind_y)) 1045 1045 i = 0 1046 1046 … … 1061 1061 1062 1062 # p min and max values among the center of pixels 1063 self.qx_min = n umpy.min(qx_value)1064 self.qx_max = n umpy.max(qx_value)1065 self.qy_min = n umpy.min(qy_value)1066 self.qy_max = n umpy.max(qy_value)1063 self.qx_min = np.min(qx_value) 1064 self.qx_max = np.max(qx_value) 1065 self.qy_min = np.min(qy_value) 1066 self.qy_max = np.max(qy_value) 1067 1067 1068 1068 # Appr. min and max values of the detector display limits … … 1088 1088 from sas.sascalc.dataloader.data_info import Data2D 1089 1089 output = Data2D() 1090 inten = n umpy.zeros_like(qx_value)1090 inten = np.zeros_like(qx_value) 1091 1091 output.data = inten 1092 1092 output.qx_data = qx_value … … 1107 1107 plane_dist = dx_size 1108 1108 # full scattering angle on the x-axis 1109 theta = n umpy.arctan(plane_dist / det_dist)1110 qx_value = (2.0 * pi / wavelength) * n umpy.sin(theta)1109 theta = np.arctan(plane_dist / det_dist) 1110 qx_value = (2.0 * pi / wavelength) * np.sin(theta) 1111 1111 return qx_value 1112 1112 -
src/sas/sascalc/calculator/sas_gen.py
rd2fd8fc r9a5097c 7 7 from periodictable import formula 8 8 from periodictable import nsf 9 import numpy 9 import numpy as np 10 10 import os 11 11 import copy … … 80 80 ## Parameter details [units, min, max] 81 81 self.details = {} 82 self.details['scale'] = ['', 0.0, n umpy.inf]83 self.details['background'] = ['[1/cm]', 0.0, n umpy.inf]84 self.details['solvent_SLD'] = ['1/A^(2)', -n umpy.inf, numpy.inf]85 self.details['total_volume'] = ['A^(3)', 0.0, n umpy.inf]82 self.details['scale'] = ['', 0.0, np.inf] 83 self.details['background'] = ['[1/cm]', 0.0, np.inf] 84 self.details['solvent_SLD'] = ['1/A^(2)', -np.inf, np.inf] 85 self.details['total_volume'] = ['A^(3)', 0.0, np.inf] 86 86 self.details['Up_frac_in'] = ['[u/(u+d)]', 0.0, 1.0] 87 87 self.details['Up_frac_out'] = ['[u/(u+d)]', 0.0, 1.0] 88 self.details['Up_theta'] = ['[deg]', -n umpy.inf, numpy.inf]88 self.details['Up_theta'] = ['[deg]', -np.inf, np.inf] 89 89 # fixed parameters 90 90 self.fixed = [] … … 171 171 msg = "Not a 1D." 172 172 raise ValueError, msg 173 i_out = n umpy.zeros_like(x[0])173 i_out = np.zeros_like(x[0]) 174 174 # 1D I is found at y =0 in the 2D pattern 175 175 out = self._gen(x[0], [], i_out) … … 187 187 """ 188 188 if x.__class__.__name__ == 'list': 189 i_out = n umpy.zeros_like(x[0])189 i_out = np.zeros_like(x[0]) 190 190 out = self._gen(x[0], x[1], i_out) 191 191 return out … … 237 237 self.omfdata = omfdata 238 238 length = int(omfdata.xnodes * omfdata.ynodes * omfdata.znodes) 239 pos_x = n umpy.arange(omfdata.xmin,239 pos_x = np.arange(omfdata.xmin, 240 240 omfdata.xnodes*omfdata.xstepsize + omfdata.xmin, 241 241 omfdata.xstepsize) 242 pos_y = n umpy.arange(omfdata.ymin,242 pos_y = np.arange(omfdata.ymin, 243 243 omfdata.ynodes*omfdata.ystepsize + omfdata.ymin, 244 244 omfdata.ystepsize) 245 pos_z = n umpy.arange(omfdata.zmin,245 pos_z = np.arange(omfdata.zmin, 246 246 omfdata.znodes*omfdata.zstepsize + omfdata.zmin, 247 247 omfdata.zstepsize) 248 self.pos_x = n umpy.tile(pos_x, int(omfdata.ynodes * omfdata.znodes))248 self.pos_x = np.tile(pos_x, int(omfdata.ynodes * omfdata.znodes)) 249 249 self.pos_y = pos_y.repeat(int(omfdata.xnodes)) 250 self.pos_y = n umpy.tile(self.pos_y, int(omfdata.znodes))250 self.pos_y = np.tile(self.pos_y, int(omfdata.znodes)) 251 251 self.pos_z = pos_z.repeat(int(omfdata.xnodes * omfdata.ynodes)) 252 252 self.mx = omfdata.mx 253 253 self.my = omfdata.my 254 254 self.mz = omfdata.mz 255 self.sld_n = n umpy.zeros(length)255 self.sld_n = np.zeros(length) 256 256 257 257 if omfdata.mx == None: 258 self.mx = n umpy.zeros(length)258 self.mx = np.zeros(length) 259 259 if omfdata.my == None: 260 self.my = n umpy.zeros(length)260 self.my = np.zeros(length) 261 261 if omfdata.mz == None: 262 self.mz = n umpy.zeros(length)262 self.mz = np.zeros(length) 263 263 264 264 self._check_data_length(length) 265 265 self.remove_null_points(False, False) 266 mask = n umpy.ones(len(self.sld_n), dtype=bool)266 mask = np.ones(len(self.sld_n), dtype=bool) 267 267 if shape.lower() == 'ellipsoid': 268 268 try: … … 328 328 """ 329 329 if remove: 330 is_nonzero = (n umpy.fabs(self.mx) + numpy.fabs(self.my) +331 n umpy.fabs(self.mz)).nonzero()330 is_nonzero = (np.fabs(self.mx) + np.fabs(self.my) + 331 np.fabs(self.mz)).nonzero() 332 332 if len(is_nonzero[0]) > 0: 333 333 self.pos_x = self.pos_x[is_nonzero] … … 369 369 """ 370 370 desc = "" 371 mx = n umpy.zeros(0)372 my = n umpy.zeros(0)373 mz = n umpy.zeros(0)371 mx = np.zeros(0) 372 my = np.zeros(0) 373 mz = np.zeros(0) 374 374 try: 375 375 input_f = open(path, 'rb') … … 389 389 _my = mag2sld(_my, valueunit) 390 390 _mz = mag2sld(_mz, valueunit) 391 mx = n umpy.append(mx, _mx)392 my = n umpy.append(my, _my)393 mz = n umpy.append(mz, _mz)391 mx = np.append(mx, _mx) 392 my = np.append(my, _my) 393 mz = np.append(mz, _mz) 394 394 except: 395 395 # Skip non-data lines … … 501 501 :raise RuntimeError: when the file can't be opened 502 502 """ 503 pos_x = n umpy.zeros(0)504 pos_y = n umpy.zeros(0)505 pos_z = n umpy.zeros(0)506 sld_n = n umpy.zeros(0)507 sld_mx = n umpy.zeros(0)508 sld_my = n umpy.zeros(0)509 sld_mz = n umpy.zeros(0)510 vol_pix = n umpy.zeros(0)511 pix_symbol = n umpy.zeros(0)503 pos_x = np.zeros(0) 504 pos_y = np.zeros(0) 505 pos_z = np.zeros(0) 506 sld_n = np.zeros(0) 507 sld_mx = np.zeros(0) 508 sld_my = np.zeros(0) 509 sld_mz = np.zeros(0) 510 vol_pix = np.zeros(0) 511 pix_symbol = np.zeros(0) 512 512 x_line = [] 513 513 y_line = [] … … 543 543 _pos_y = float(line[38:46].strip()) 544 544 _pos_z = float(line[46:54].strip()) 545 pos_x = n umpy.append(pos_x, _pos_x)546 pos_y = n umpy.append(pos_y, _pos_y)547 pos_z = n umpy.append(pos_z, _pos_z)545 pos_x = np.append(pos_x, _pos_x) 546 pos_y = np.append(pos_y, _pos_y) 547 pos_z = np.append(pos_z, _pos_z) 548 548 try: 549 549 val = nsf.neutron_sld(atom_name)[0] 550 550 # sld in Ang^-2 unit 551 551 val *= 1.0e-6 552 sld_n = n umpy.append(sld_n, val)552 sld_n = np.append(sld_n, val) 553 553 atom = formula(atom_name) 554 554 # cm to A units 555 555 vol = 1.0e+24 * atom.mass / atom.density / NA 556 vol_pix = n umpy.append(vol_pix, vol)556 vol_pix = np.append(vol_pix, vol) 557 557 except: 558 558 print "Error: set the sld of %s to zero"% atom_name 559 sld_n = n umpy.append(sld_n, 0.0)560 sld_mx = n umpy.append(sld_mx, 0)561 sld_my = n umpy.append(sld_my, 0)562 sld_mz = n umpy.append(sld_mz, 0)563 pix_symbol = n umpy.append(pix_symbol, atom_name)559 sld_n = np.append(sld_n, 0.0) 560 sld_mx = np.append(sld_mx, 0) 561 sld_my = np.append(sld_my, 0) 562 sld_mz = np.append(sld_mz, 0) 563 pix_symbol = np.append(pix_symbol, atom_name) 564 564 elif line[0:6].strip().count('CONECT') > 0: 565 565 toks = line.split() … … 630 630 """ 631 631 try: 632 pos_x = n umpy.zeros(0)633 pos_y = n umpy.zeros(0)634 pos_z = n umpy.zeros(0)635 sld_n = n umpy.zeros(0)636 sld_mx = n umpy.zeros(0)637 sld_my = n umpy.zeros(0)638 sld_mz = n umpy.zeros(0)632 pos_x = np.zeros(0) 633 pos_y = np.zeros(0) 634 pos_z = np.zeros(0) 635 sld_n = np.zeros(0) 636 sld_mx = np.zeros(0) 637 sld_my = np.zeros(0) 638 sld_mz = np.zeros(0) 639 639 try: 640 640 # Use numpy to speed up loading 641 input_f = n umpy.loadtxt(path, dtype='float', skiprows=1,641 input_f = np.loadtxt(path, dtype='float', skiprows=1, 642 642 ndmin=1, unpack=True) 643 pos_x = n umpy.array(input_f[0])644 pos_y = n umpy.array(input_f[1])645 pos_z = n umpy.array(input_f[2])646 sld_n = n umpy.array(input_f[3])647 sld_mx = n umpy.array(input_f[4])648 sld_my = n umpy.array(input_f[5])649 sld_mz = n umpy.array(input_f[6])643 pos_x = np.array(input_f[0]) 644 pos_y = np.array(input_f[1]) 645 pos_z = np.array(input_f[2]) 646 sld_n = np.array(input_f[3]) 647 sld_mx = np.array(input_f[4]) 648 sld_my = np.array(input_f[5]) 649 sld_mz = np.array(input_f[6]) 650 650 ncols = len(input_f) 651 651 if ncols == 8: 652 vol_pix = n umpy.array(input_f[7])652 vol_pix = np.array(input_f[7]) 653 653 elif ncols == 7: 654 654 vol_pix = None … … 669 669 _sld_my = float(toks[5]) 670 670 _sld_mz = float(toks[6]) 671 pos_x = n umpy.append(pos_x, _pos_x)672 pos_y = n umpy.append(pos_y, _pos_y)673 pos_z = n umpy.append(pos_z, _pos_z)674 sld_n = n umpy.append(sld_n, _sld_n)675 sld_mx = n umpy.append(sld_mx, _sld_mx)676 sld_my = n umpy.append(sld_my, _sld_my)677 sld_mz = n umpy.append(sld_mz, _sld_mz)671 pos_x = np.append(pos_x, _pos_x) 672 pos_y = np.append(pos_y, _pos_y) 673 pos_z = np.append(pos_z, _pos_z) 674 sld_n = np.append(sld_n, _sld_n) 675 sld_mx = np.append(sld_mx, _sld_mx) 676 sld_my = np.append(sld_my, _sld_my) 677 sld_mz = np.append(sld_mz, _sld_mz) 678 678 try: 679 679 _vol_pix = float(toks[7]) 680 vol_pix = n umpy.append(vol_pix, _vol_pix)680 vol_pix = np.append(vol_pix, _vol_pix) 681 681 except: 682 682 vol_pix = None … … 712 712 sld_n = data.sld_n 713 713 if sld_n == None: 714 sld_n = n umpy.zeros(length)714 sld_n = np.zeros(length) 715 715 sld_mx = data.sld_mx 716 716 if sld_mx == None: 717 sld_mx = n umpy.zeros(length)718 sld_my = n umpy.zeros(length)719 sld_mz = n umpy.zeros(length)717 sld_mx = np.zeros(length) 718 sld_my = np.zeros(length) 719 sld_mz = np.zeros(length) 720 720 else: 721 721 sld_my = data.sld_my … … 893 893 if self.is_data: 894 894 # For data, put the value to only the pixels w non-zero M 895 is_nonzero = (n umpy.fabs(self.sld_mx) +896 n umpy.fabs(self.sld_my) +897 n umpy.fabs(self.sld_mz)).nonzero()898 self.sld_n = n umpy.zeros(len(self.pos_x))895 is_nonzero = (np.fabs(self.sld_mx) + 896 np.fabs(self.sld_my) + 897 np.fabs(self.sld_mz)).nonzero() 898 self.sld_n = np.zeros(len(self.pos_x)) 899 899 if len(self.sld_n[is_nonzero]) > 0: 900 900 self.sld_n[is_nonzero] = sld_n … … 903 903 else: 904 904 # For non-data, put the value to all the pixels 905 self.sld_n = n umpy.ones(len(self.pos_x)) * sld_n905 self.sld_n = np.ones(len(self.pos_x)) * sld_n 906 906 else: 907 907 self.sld_n = sld_n … … 912 912 """ 913 913 if sld_mx.__class__.__name__ == 'float': 914 self.sld_mx = n umpy.ones(len(self.pos_x)) * sld_mx914 self.sld_mx = np.ones(len(self.pos_x)) * sld_mx 915 915 else: 916 916 self.sld_mx = sld_mx 917 917 if sld_my.__class__.__name__ == 'float': 918 self.sld_my = n umpy.ones(len(self.pos_x)) * sld_my918 self.sld_my = np.ones(len(self.pos_x)) * sld_my 919 919 else: 920 920 self.sld_my = sld_my 921 921 if sld_mz.__class__.__name__ == 'float': 922 self.sld_mz = n umpy.ones(len(self.pos_x)) * sld_mz922 self.sld_mz = np.ones(len(self.pos_x)) * sld_mz 923 923 else: 924 924 self.sld_mz = sld_mz 925 925 926 sld_m = n umpy.sqrt(sld_mx * sld_mx + sld_my * sld_my + \926 sld_m = np.sqrt(sld_mx * sld_mx + sld_my * sld_my + \ 927 927 sld_mz * sld_mz) 928 928 self.sld_m = sld_m … … 936 936 return 937 937 if symbol.__class__.__name__ == 'str': 938 self.pix_symbol = n umpy.repeat(symbol, len(self.sld_n))938 self.pix_symbol = np.repeat(symbol, len(self.sld_n)) 939 939 else: 940 940 self.pix_symbol = symbol … … 950 950 self.vol_pix = vol 951 951 elif vol.__class__.__name__.count('float') > 0: 952 self.vol_pix = n umpy.repeat(vol, len(self.sld_n))952 self.vol_pix = np.repeat(vol, len(self.sld_n)) 953 953 else: 954 954 self.vol_pix = None … … 993 993 for x_pos in self.pos_x: 994 994 if xpos_pre != x_pos: 995 self.xstepsize = n umpy.fabs(x_pos - xpos_pre)995 self.xstepsize = np.fabs(x_pos - xpos_pre) 996 996 break 997 997 for y_pos in self.pos_y: 998 998 if ypos_pre != y_pos: 999 self.ystepsize = n umpy.fabs(y_pos - ypos_pre)999 self.ystepsize = np.fabs(y_pos - ypos_pre) 1000 1000 break 1001 1001 for z_pos in self.pos_z: 1002 1002 if zpos_pre != z_pos: 1003 self.zstepsize = n umpy.fabs(z_pos - zpos_pre)1003 self.zstepsize = np.fabs(z_pos - zpos_pre) 1004 1004 break 1005 1005 #default pix volume 1006 self.vol_pix = n umpy.ones(len(self.pos_x))1006 self.vol_pix = np.ones(len(self.pos_x)) 1007 1007 vol = self.xstepsize * self.ystepsize * self.zstepsize 1008 1008 self.set_pixel_volumes(vol) … … 1071 1071 y2 = output.pos_y+output.sld_my/max_m * gap 1072 1072 z2 = output.pos_z+output.sld_mz/max_m * gap 1073 x_arrow = n umpy.column_stack((output.pos_x, x2))1074 y_arrow = n umpy.column_stack((output.pos_y, y2))1075 z_arrow = n umpy.column_stack((output.pos_z, z2))1073 x_arrow = np.column_stack((output.pos_x, x2)) 1074 y_arrow = np.column_stack((output.pos_y, y2)) 1075 z_arrow = np.column_stack((output.pos_z, z2)) 1076 1076 unit_x2 = output.sld_mx / max_m 1077 1077 unit_y2 = output.sld_my / max_m 1078 1078 unit_z2 = output.sld_mz / max_m 1079 color_x = n umpy.fabs(unit_x2 * 0.8)1080 color_y = n umpy.fabs(unit_y2 * 0.8)1081 color_z = n umpy.fabs(unit_z2 * 0.8)1082 colors = n umpy.column_stack((color_x, color_y, color_z))1079 color_x = np.fabs(unit_x2 * 0.8) 1080 color_y = np.fabs(unit_y2 * 0.8) 1081 color_z = np.fabs(unit_z2 * 0.8) 1082 colors = np.column_stack((color_x, color_y, color_z)) 1083 1083 plt.show() 1084 1084 … … 1103 1103 model = GenSAS() 1104 1104 model.set_sld_data(foutput.output) 1105 x = n umpy.arange(1000)/10000. + 1e-51106 y = n umpy.arange(1000)/10000. + 1e-51107 i = n umpy.zeros(1000)1105 x = np.arange(1000)/10000. + 1e-5 1106 y = np.arange(1000)/10000. + 1e-5 1107 i = np.zeros(1000) 1108 1108 model.runXY([x, y, i]) 1109 1109 -
src/sas/sascalc/data_util/err1d.py
rb699768 r9a5097c 8 8 """ 9 9 from __future__ import division # Get true division 10 import numpy 10 import numpy as np 11 11 12 12 … … 59 59 def exp(X, varX): 60 60 """Exponentiation with error propagation""" 61 Z = n umpy.exp(X)61 Z = np.exp(X) 62 62 varZ = varX * Z**2 63 63 return Z, varZ … … 66 66 def log(X, varX): 67 67 """Logarithm with error propagation""" 68 Z = n umpy.log(X)68 Z = np.log(X) 69 69 varZ = varX / X**2 70 70 return Z, varZ … … 73 73 # def pow(X,varX, Y,varY): 74 74 # Z = X**Y 75 # varZ = (Y**2 * varX/X**2 + varY * n umpy.log(X)**2) * Z**275 # varZ = (Y**2 * varX/X**2 + varY * np.log(X)**2) * Z**2 76 76 # return Z,varZ 77 77 # -
src/sas/sascalc/data_util/formatnum.py
rb699768 r9a5097c 40 40 41 41 import math 42 import numpy 42 import numpy as np 43 43 __all__ = ['format_uncertainty', 'format_uncertainty_pm', 44 44 'format_uncertainty_compact'] … … 102 102 """ 103 103 # Handle indefinite value 104 if n umpy.isinf(value):104 if np.isinf(value): 105 105 return "inf" if value > 0 else "-inf" 106 if n umpy.isnan(value):106 if np.isnan(value): 107 107 return "NaN" 108 108 109 109 # Handle indefinite uncertainty 110 if uncertainty is None or uncertainty <= 0 or n umpy.isnan(uncertainty):110 if uncertainty is None or uncertainty <= 0 or np.isnan(uncertainty): 111 111 return "%g" % value 112 if n umpy.isinf(uncertainty):112 if np.isinf(uncertainty): 113 113 if compact: 114 114 return "%.2g(inf)" % value … … 279 279 280 280 # non-finite values 281 assert value_str(-n umpy.inf,None) == "-inf"282 assert value_str(n umpy.inf,None) == "inf"283 assert value_str(n umpy.NaN,None) == "NaN"281 assert value_str(-np.inf,None) == "-inf" 282 assert value_str(np.inf,None) == "inf" 283 assert value_str(np.NaN,None) == "NaN" 284 284 285 285 # bad or missing uncertainty 286 assert value_str(-1.23567,n umpy.NaN) == "-1.23567"287 assert value_str(-1.23567,-n umpy.inf) == "-1.23567"286 assert value_str(-1.23567,np.NaN) == "-1.23567" 287 assert value_str(-1.23567,-np.inf) == "-1.23567" 288 288 assert value_str(-1.23567,-0.1) == "-1.23567" 289 289 assert value_str(-1.23567,0) == "-1.23567" 290 290 assert value_str(-1.23567,None) == "-1.23567" 291 assert value_str(-1.23567,n umpy.inf) == "-1.2(inf)"291 assert value_str(-1.23567,np.inf) == "-1.2(inf)" 292 292 293 293 def test_pm(): … … 410 410 411 411 # non-finite values 412 assert value_str(-n umpy.inf,None) == "-inf"413 assert value_str(n umpy.inf,None) == "inf"414 assert value_str(n umpy.NaN,None) == "NaN"412 assert value_str(-np.inf,None) == "-inf" 413 assert value_str(np.inf,None) == "inf" 414 assert value_str(np.NaN,None) == "NaN" 415 415 416 416 # bad or missing uncertainty 417 assert value_str(-1.23567,n umpy.NaN) == "-1.23567"418 assert value_str(-1.23567,-n umpy.inf) == "-1.23567"417 assert value_str(-1.23567,np.NaN) == "-1.23567" 418 assert value_str(-1.23567,-np.inf) == "-1.23567" 419 419 assert value_str(-1.23567,-0.1) == "-1.23567" 420 420 assert value_str(-1.23567,0) == "-1.23567" 421 421 assert value_str(-1.23567,None) == "-1.23567" 422 assert value_str(-1.23567,n umpy.inf) == "-1.2 +/- inf"422 assert value_str(-1.23567,np.inf) == "-1.2 +/- inf" 423 423 424 424 def test_default(): -
src/sas/sascalc/data_util/qsmearing.py
r775e0b7 r9a5097c 9 9 #copyright 2008, University of Tennessee 10 10 ###################################################################### 11 import numpy12 11 import math 13 12 import logging … … 60 59 if data.dx is not None and data.isSesans: 61 60 #if data.dx[0] > 0.0: 62 if n umpy.size(data.dx[data.dx <= 0]) == 0:61 if np.size(data.dx[data.dx <= 0]) == 0: 63 62 _found_sesans = True 64 63 # if data.dx[0] <= 0.0: 65 if n umpy.size(data.dx[data.dx <= 0]) > 0:64 if np.size(data.dx[data.dx <= 0]) > 0: 66 65 raise ValueError('one or more of your dx values are negative, please check the data file!') 67 66 … … 121 120 self.resolution = resolution 122 121 if offset is None: 123 offset = n umpy.searchsorted(self.resolution.q_calc, self.resolution.q[0])122 offset = np.searchsorted(self.resolution.q_calc, self.resolution.q[0]) 124 123 self.offset = offset 125 124 … … 137 136 start, end = first_bin + self.offset, last_bin + self.offset 138 137 q_calc = self.resolution.q_calc 139 iq_calc = n umpy.empty_like(q_calc)138 iq_calc = np.empty_like(q_calc) 140 139 if start > 0: 141 140 iq_calc[:start] = self.model.evalDistribution(q_calc[:start]) … … 157 156 """ 158 157 q = self.resolution.q 159 first = n umpy.searchsorted(q, q_min)160 last = n umpy.searchsorted(q, q_max)158 first = np.searchsorted(q, q_min) 159 last = np.searchsorted(q, q_max) 161 160 return first, min(last,len(q)-1) 162 161 -
src/sas/sascalc/data_util/uncertainty.py
rb699768 r9a5097c 17 17 from __future__ import division 18 18 19 import numpy 19 import numpy as np 20 20 import err1d 21 21 from formatnum import format_uncertainty … … 27 27 class Uncertainty(object): 28 28 # Make standard deviation available 29 def _getdx(self): return n umpy.sqrt(self.variance)29 def _getdx(self): return np.sqrt(self.variance) 30 30 def _setdx(self,dx): 31 31 # Direct operation … … 144 144 return self 145 145 def __abs__(self): 146 return Uncertainty(n umpy.abs(self.x),self.variance)146 return Uncertainty(np.abs(self.x),self.variance) 147 147 148 148 def __str__(self): 149 #return str(self.x)+" +/- "+str(n umpy.sqrt(self.variance))150 if n umpy.isscalar(self.x):151 return format_uncertainty(self.x,n umpy.sqrt(self.variance))149 #return str(self.x)+" +/- "+str(np.sqrt(self.variance)) 150 if np.isscalar(self.x): 151 return format_uncertainty(self.x,np.sqrt(self.variance)) 152 152 else: 153 153 return [format_uncertainty(v,dv) 154 for v,dv in zip(self.x,n umpy.sqrt(self.variance))]154 for v,dv in zip(self.x,np.sqrt(self.variance))] 155 155 def __repr__(self): 156 156 return "Uncertainty(%s,%s)"%(str(self.x),str(self.variance)) … … 287 287 # =============== vector operations ================ 288 288 # Slicing 289 z = Uncertainty(n umpy.array([1,2,3,4,5]),numpy.array([2,1,2,3,2]))289 z = Uncertainty(np.array([1,2,3,4,5]),np.array([2,1,2,3,2])) 290 290 assert z[2].x == 3 and z[2].variance == 2 291 291 assert (z[2:4].x == [3,4]).all() 292 292 assert (z[2:4].variance == [2,3]).all() 293 z[2:4] = Uncertainty(n umpy.array([8,7]),numpy.array([4,5]))293 z[2:4] = Uncertainty(np.array([8,7]),np.array([4,5])) 294 294 assert z[2].x == 8 and z[2].variance == 4 295 A = Uncertainty(n umpy.array([a.x]*2),numpy.array([a.variance]*2))296 B = Uncertainty(n umpy.array([b.x]*2),numpy.array([b.variance]*2))295 A = Uncertainty(np.array([a.x]*2),np.array([a.variance]*2)) 296 B = Uncertainty(np.array([b.x]*2),np.array([b.variance]*2)) 297 297 298 298 # TODO complete tests of copy and inplace operations for vectors and slices. -
src/sas/sascalc/dataloader/data_info.py
r2ffe241 r9a5097c 23 23 #from sas.guitools.plottables import Data1D as plottable_1D 24 24 from sas.sascalc.data_util.uncertainty import Uncertainty 25 import numpy 25 import numpy as np 26 26 import math 27 27 … … 51 51 52 52 def __init__(self, x, y, dx=None, dy=None, dxl=None, dxw=None, lam=None, dlam=None): 53 self.x = n umpy.asarray(x)54 self.y = n umpy.asarray(y)53 self.x = np.asarray(x) 54 self.y = np.asarray(y) 55 55 if dx is not None: 56 self.dx = n umpy.asarray(dx)56 self.dx = np.asarray(dx) 57 57 if dy is not None: 58 self.dy = n umpy.asarray(dy)58 self.dy = np.asarray(dy) 59 59 if dxl is not None: 60 self.dxl = n umpy.asarray(dxl)60 self.dxl = np.asarray(dxl) 61 61 if dxw is not None: 62 self.dxw = n umpy.asarray(dxw)62 self.dxw = np.asarray(dxw) 63 63 if lam is not None: 64 self.lam = n umpy.asarray(lam)64 self.lam = np.asarray(lam) 65 65 if dlam is not None: 66 self.dlam = n umpy.asarray(dlam)66 self.dlam = np.asarray(dlam) 67 67 68 68 def xaxis(self, label, unit): … … 109 109 qy_data=None, q_data=None, mask=None, 110 110 dqx_data=None, dqy_data=None): 111 self.data = n umpy.asarray(data)112 self.qx_data = n umpy.asarray(qx_data)113 self.qy_data = n umpy.asarray(qy_data)114 self.q_data = n umpy.asarray(q_data)115 self.mask = n umpy.asarray(mask)116 self.err_data = n umpy.asarray(err_data)111 self.data = np.asarray(data) 112 self.qx_data = np.asarray(qx_data) 113 self.qy_data = np.asarray(qy_data) 114 self.q_data = np.asarray(q_data) 115 self.mask = np.asarray(mask) 116 self.err_data = np.asarray(err_data) 117 117 if dqx_data is not None: 118 self.dqx_data = n umpy.asarray(dqx_data)118 self.dqx_data = np.asarray(dqx_data) 119 119 if dqy_data is not None: 120 self.dqy_data = n umpy.asarray(dqy_data)120 self.dqy_data = np.asarray(dqy_data) 121 121 122 122 def xaxis(self, label, unit): … … 734 734 """ 735 735 def _check(v): 736 if (v.__class__ == list or v.__class__ == n umpy.ndarray) \736 if (v.__class__ == list or v.__class__ == np.ndarray) \ 737 737 and len(v) > 0 and min(v) > 0: 738 738 return True … … 752 752 753 753 if clone is None or not issubclass(clone.__class__, Data1D): 754 x = n umpy.zeros(length)755 dx = n umpy.zeros(length)756 y = n umpy.zeros(length)757 dy = n umpy.zeros(length)758 lam = n umpy.zeros(length)759 dlam = n umpy.zeros(length)754 x = np.zeros(length) 755 dx = np.zeros(length) 756 y = np.zeros(length) 757 dy = np.zeros(length) 758 lam = np.zeros(length) 759 dlam = np.zeros(length) 760 760 clone = Data1D(x, y, lam=lam, dx=dx, dy=dy, dlam=dlam) 761 761 … … 806 806 dy_other = other.dy 807 807 if other.dy == None or (len(other.dy) != len(other.y)): 808 dy_other = n umpy.zeros(len(other.y))808 dy_other = np.zeros(len(other.y)) 809 809 810 810 # Check that we have errors, otherwise create zero vector 811 811 dy = self.dy 812 812 if self.dy == None or (len(self.dy) != len(self.y)): 813 dy = n umpy.zeros(len(self.y))813 dy = np.zeros(len(self.y)) 814 814 815 815 return dy, dy_other … … 824 824 result.dxw = None 825 825 else: 826 result.dxw = n umpy.zeros(len(self.x))826 result.dxw = np.zeros(len(self.x)) 827 827 if self.dxl == None: 828 828 result.dxl = None 829 829 else: 830 result.dxl = n umpy.zeros(len(self.x))830 result.dxl = np.zeros(len(self.x)) 831 831 832 832 for i in range(len(self.x)): … … 886 886 result.dy = None 887 887 else: 888 result.dy = n umpy.zeros(len(self.x) + len(other.x))888 result.dy = np.zeros(len(self.x) + len(other.x)) 889 889 if self.dx == None or other.dx is None: 890 890 result.dx = None 891 891 else: 892 result.dx = n umpy.zeros(len(self.x) + len(other.x))892 result.dx = np.zeros(len(self.x) + len(other.x)) 893 893 if self.dxw == None or other.dxw is None: 894 894 result.dxw = None 895 895 else: 896 result.dxw = n umpy.zeros(len(self.x) + len(other.x))896 result.dxw = np.zeros(len(self.x) + len(other.x)) 897 897 if self.dxl == None or other.dxl is None: 898 898 result.dxl = None 899 899 else: 900 result.dxl = n umpy.zeros(len(self.x) + len(other.x))901 902 result.x = n umpy.append(self.x, other.x)900 result.dxl = np.zeros(len(self.x) + len(other.x)) 901 902 result.x = np.append(self.x, other.x) 903 903 #argsorting 904 ind = n umpy.argsort(result.x)904 ind = np.argsort(result.x) 905 905 result.x = result.x[ind] 906 result.y = n umpy.append(self.y, other.y)906 result.y = np.append(self.y, other.y) 907 907 result.y = result.y[ind] 908 908 if result.dy != None: 909 result.dy = n umpy.append(self.dy, other.dy)909 result.dy = np.append(self.dy, other.dy) 910 910 result.dy = result.dy[ind] 911 911 if result.dx is not None: 912 result.dx = n umpy.append(self.dx, other.dx)912 result.dx = np.append(self.dx, other.dx) 913 913 result.dx = result.dx[ind] 914 914 if result.dxw is not None: 915 result.dxw = n umpy.append(self.dxw, other.dxw)915 result.dxw = np.append(self.dxw, other.dxw) 916 916 result.dxw = result.dxw[ind] 917 917 if result.dxl is not None: 918 result.dxl = n umpy.append(self.dxl, other.dxl)918 result.dxl = np.append(self.dxl, other.dxl) 919 919 result.dxl = result.dxl[ind] 920 920 return result … … 970 970 971 971 if clone is None or not issubclass(clone.__class__, Data2D): 972 data = n umpy.zeros(length)973 err_data = n umpy.zeros(length)974 qx_data = n umpy.zeros(length)975 qy_data = n umpy.zeros(length)976 q_data = n umpy.zeros(length)977 mask = n umpy.zeros(length)972 data = np.zeros(length) 973 err_data = np.zeros(length) 974 qx_data = np.zeros(length) 975 qy_data = np.zeros(length) 976 q_data = np.zeros(length) 977 mask = np.zeros(length) 978 978 dqx_data = None 979 979 dqy_data = None … … 1031 1031 if other.err_data == None or \ 1032 1032 (len(other.err_data) != len(other.data)): 1033 err_other = n umpy.zeros(len(other.data))1033 err_other = np.zeros(len(other.data)) 1034 1034 1035 1035 # Check that we have errors, otherwise create zero vector … … 1037 1037 if self.err_data == None or \ 1038 1038 (len(self.err_data) != len(self.data)): 1039 err = n umpy.zeros(len(other.data))1039 err = np.zeros(len(other.data)) 1040 1040 return err, err_other 1041 1041 … … 1049 1049 # First, check the data compatibility 1050 1050 dy, dy_other = self._validity_check(other) 1051 result = self.clone_without_data(n umpy.size(self.data))1051 result = self.clone_without_data(np.size(self.data)) 1052 1052 if self.dqx_data == None or self.dqy_data == None: 1053 1053 result.dqx_data = None 1054 1054 result.dqy_data = None 1055 1055 else: 1056 result.dqx_data = n umpy.zeros(len(self.data))1057 result.dqy_data = n umpy.zeros(len(self.data))1058 for i in range(n umpy.size(self.data)):1056 result.dqx_data = np.zeros(len(self.data)) 1057 result.dqy_data = np.zeros(len(self.data)) 1058 for i in range(np.size(self.data)): 1059 1059 result.data[i] = self.data[i] 1060 1060 if self.err_data is not None and \ 1061 numpy.size(self.data) == numpy.size(self.err_data):1061 np.size(self.data) == np.size(self.err_data): 1062 1062 result.err_data[i] = self.err_data[i] 1063 1063 if self.dqx_data is not None: … … 1118 1118 # First, check the data compatibility 1119 1119 self._validity_check_union(other) 1120 result = self.clone_without_data(n umpy.size(self.data) + \1121 n umpy.size(other.data))1120 result = self.clone_without_data(np.size(self.data) + \ 1121 np.size(other.data)) 1122 1122 result.xmin = self.xmin 1123 1123 result.xmax = self.xmax … … 1129 1129 result.dqy_data = None 1130 1130 else: 1131 result.dqx_data = n umpy.zeros(len(self.data) + \1132 numpy.size(other.data))1133 result.dqy_data = n umpy.zeros(len(self.data) + \1134 numpy.size(other.data))1135 1136 result.data = n umpy.append(self.data, other.data)1137 result.qx_data = n umpy.append(self.qx_data, other.qx_data)1138 result.qy_data = n umpy.append(self.qy_data, other.qy_data)1139 result.q_data = n umpy.append(self.q_data, other.q_data)1140 result.mask = n umpy.append(self.mask, other.mask)1131 result.dqx_data = np.zeros(len(self.data) + \ 1132 np.size(other.data)) 1133 result.dqy_data = np.zeros(len(self.data) + \ 1134 np.size(other.data)) 1135 1136 result.data = np.append(self.data, other.data) 1137 result.qx_data = np.append(self.qx_data, other.qx_data) 1138 result.qy_data = np.append(self.qy_data, other.qy_data) 1139 result.q_data = np.append(self.q_data, other.q_data) 1140 result.mask = np.append(self.mask, other.mask) 1141 1141 if result.err_data is not None: 1142 result.err_data = n umpy.append(self.err_data, other.err_data)1142 result.err_data = np.append(self.err_data, other.err_data) 1143 1143 if self.dqx_data is not None: 1144 result.dqx_data = n umpy.append(self.dqx_data, other.dqx_data)1144 result.dqx_data = np.append(self.dqx_data, other.dqx_data) 1145 1145 if self.dqy_data is not None: 1146 result.dqy_data = n umpy.append(self.dqy_data, other.dqy_data)1146 result.dqy_data = np.append(self.dqy_data, other.dqy_data) 1147 1147 1148 1148 return result -
src/sas/sascalc/dataloader/readers/abs_reader.py
rb699768 r9a5097c 9 9 ###################################################################### 10 10 11 import numpy 11 import numpy as np 12 12 import os 13 13 from sas.sascalc.dataloader.data_info import Data1D … … 53 53 buff = input_f.read() 54 54 lines = buff.split('\n') 55 x = n umpy.zeros(0)56 y = n umpy.zeros(0)57 dy = n umpy.zeros(0)58 dx = n umpy.zeros(0)55 x = np.zeros(0) 56 y = np.zeros(0) 57 dy = np.zeros(0) 58 dx = np.zeros(0) 59 59 output = Data1D(x, y, dy=dy, dx=dx) 60 60 detector = Detector() … … 204 204 _dy = data_conv_i(_dy, units=output.y_unit) 205 205 206 x = n umpy.append(x, _x)207 y = n umpy.append(y, _y)208 dy = n umpy.append(dy, _dy)209 dx = n umpy.append(dx, _dx)206 x = np.append(x, _x) 207 y = np.append(y, _y) 208 dy = np.append(dy, _dy) 209 dx = np.append(dx, _dx) 210 210 211 211 except: -
src/sas/sascalc/dataloader/readers/ascii_reader.py
rd2471870 r9a5097c 14 14 15 15 16 import numpy 16 import numpy as np 17 17 import os 18 18 from sas.sascalc.dataloader.data_info import Data1D … … 69 69 70 70 # Arrays for data storage 71 tx = n umpy.zeros(0)72 ty = n umpy.zeros(0)73 tdy = n umpy.zeros(0)74 tdx = n umpy.zeros(0)71 tx = np.zeros(0) 72 ty = np.zeros(0) 73 tdy = np.zeros(0) 74 tdx = np.zeros(0) 75 75 76 76 # The first good line of data will define whether … … 140 140 is_data == False: 141 141 try: 142 tx = n umpy.zeros(0)143 ty = n umpy.zeros(0)144 tdy = n umpy.zeros(0)145 tdx = n umpy.zeros(0)142 tx = np.zeros(0) 143 ty = np.zeros(0) 144 tdy = np.zeros(0) 145 tdx = np.zeros(0) 146 146 except: 147 147 pass 148 148 149 149 if has_error_dy == True: 150 tdy = n umpy.append(tdy, _dy)150 tdy = np.append(tdy, _dy) 151 151 if has_error_dx == True: 152 tdx = n umpy.append(tdx, _dx)153 tx = n umpy.append(tx, _x)154 ty = n umpy.append(ty, _y)152 tdx = np.append(tdx, _dx) 153 tx = np.append(tx, _x) 154 ty = np.append(ty, _y) 155 155 156 156 #To remember the # of columns on the current line … … 188 188 #Let's re-order the data to make cal. 189 189 # curve look better some cases 190 ind = n umpy.lexsort((ty, tx))191 x = n umpy.zeros(len(tx))192 y = n umpy.zeros(len(ty))193 dy = n umpy.zeros(len(tdy))194 dx = n umpy.zeros(len(tdx))190 ind = np.lexsort((ty, tx)) 191 x = np.zeros(len(tx)) 192 y = np.zeros(len(ty)) 193 dy = np.zeros(len(tdy)) 194 dx = np.zeros(len(tdx)) 195 195 output = Data1D(x, y, dy=dy, dx=dx) 196 196 self.filename = output.filename = basename … … 212 212 output.y = y[x != 0] 213 213 output.dy = dy[x != 0] if has_error_dy == True\ 214 else n umpy.zeros(len(output.y))214 else np.zeros(len(output.y)) 215 215 output.dx = dx[x != 0] if has_error_dx == True\ 216 else n umpy.zeros(len(output.x))216 else np.zeros(len(output.x)) 217 217 218 218 output.xaxis("\\rm{Q}", 'A^{-1}') -
src/sas/sascalc/dataloader/readers/danse_reader.py
rb699768 r9a5097c 15 15 import os 16 16 import sys 17 import numpy 17 import numpy as np 18 18 import logging 19 19 from sas.sascalc.dataloader.data_info import Data2D, Detector … … 79 79 output.detector.append(detector) 80 80 81 output.data = n umpy.zeros([size_x,size_y])82 output.err_data = n umpy.zeros([size_x, size_y])81 output.data = np.zeros([size_x,size_y]) 82 output.err_data = np.zeros([size_x, size_y]) 83 83 84 84 data_conv_q = None -
src/sas/sascalc/dataloader/readers/hfir1d_reader.py
rb699768 r9a5097c 9 9 #copyright 2008, University of Tennessee 10 10 ###################################################################### 11 import numpy 11 import numpy as np 12 12 import os 13 13 from sas.sascalc.dataloader.data_info import Data1D … … 52 52 buff = input_f.read() 53 53 lines = buff.split('\n') 54 x = n umpy.zeros(0)55 y = n umpy.zeros(0)56 dx = n umpy.zeros(0)57 dy = n umpy.zeros(0)54 x = np.zeros(0) 55 y = np.zeros(0) 56 dx = np.zeros(0) 57 dy = np.zeros(0) 58 58 output = Data1D(x, y, dx=dx, dy=dy) 59 59 self.filename = output.filename = basename … … 88 88 _dy = data_conv_i(_dy, units=output.y_unit) 89 89 90 x = n umpy.append(x, _x)91 y = n umpy.append(y, _y)92 dx = n umpy.append(dx, _dx)93 dy = n umpy.append(dy, _dy)90 x = np.append(x, _x) 91 y = np.append(y, _y) 92 dx = np.append(dx, _dx) 93 dy = np.append(dy, _dy) 94 94 except: 95 95 # Couldn't parse this line, skip it -
src/sas/sascalc/dataloader/readers/red2d_reader.py
rb699768 r9a5097c 10 10 ###################################################################### 11 11 import os 12 import numpy 12 import numpy as np 13 13 import math 14 14 from sas.sascalc.dataloader.data_info import Data2D, Detector … … 198 198 break 199 199 # Make numpy array to remove header lines using index 200 lines_array = n umpy.array(lines)200 lines_array = np.array(lines) 201 201 202 202 # index for lines_array 203 lines_index = n umpy.arange(len(lines))203 lines_index = np.arange(len(lines)) 204 204 205 205 # get the data lines … … 225 225 226 226 # numpy array form 227 data_array = n umpy.array(data_list1)227 data_array = np.array(data_list1) 228 228 # Redimesion based on the row_num and col_num, 229 229 #otherwise raise an error. … … 235 235 ## Get the all data: Let's HARDcoding; Todo find better way 236 236 # Defaults 237 dqx_data = n umpy.zeros(0)238 dqy_data = n umpy.zeros(0)239 err_data = n umpy.ones(row_num)240 qz_data = n umpy.zeros(row_num)241 mask = n umpy.ones(row_num, dtype=bool)237 dqx_data = np.zeros(0) 238 dqy_data = np.zeros(0) 239 err_data = np.ones(row_num) 240 qz_data = np.zeros(row_num) 241 mask = np.ones(row_num, dtype=bool) 242 242 # Get from the array 243 243 qx_data = data_point[0] … … 254 254 dqy_data = data_point[(5 + ver)] 255 255 #if col_num > (6 + ver): mask[data_point[(6 + ver)] < 1] = False 256 q_data = n umpy.sqrt(qx_data*qx_data+qy_data*qy_data+qz_data*qz_data)256 q_data = np.sqrt(qx_data*qx_data+qy_data*qy_data+qz_data*qz_data) 257 257 258 258 # Extra protection(it is needed for some data files): … … 262 262 263 263 # Store limits of the image in q space 264 xmin = n umpy.min(qx_data)265 xmax = n umpy.max(qx_data)266 ymin = n umpy.min(qy_data)267 ymax = n umpy.max(qy_data)264 xmin = np.min(qx_data) 265 xmax = np.max(qx_data) 266 ymin = np.min(qy_data) 267 ymax = np.max(qy_data) 268 268 269 269 # units … … 287 287 288 288 # store x and y axis bin centers in q space 289 x_bins = n umpy.arange(xmin, xmax + xstep, xstep)290 y_bins = n umpy.arange(ymin, ymax + ystep, ystep)289 x_bins = np.arange(xmin, xmax + xstep, xstep) 290 y_bins = np.arange(ymin, ymax + ystep, ystep) 291 291 292 292 # get the limits of q values … … 300 300 output.data = data 301 301 if (err_data == 1).all(): 302 output.err_data = n umpy.sqrt(numpy.abs(data))302 output.err_data = np.sqrt(np.abs(data)) 303 303 output.err_data[output.err_data == 0.0] = 1.0 304 304 else: … … 335 335 # tranfer the comp. to cartesian coord. for newer version. 336 336 if ver != 1: 337 diag = n umpy.sqrt(qx_data * qx_data + qy_data * qy_data)337 diag = np.sqrt(qx_data * qx_data + qy_data * qy_data) 338 338 cos_th = qx_data / diag 339 339 sin_th = qy_data / diag 340 output.dqx_data = n umpy.sqrt((dqx_data * cos_th) * \340 output.dqx_data = np.sqrt((dqx_data * cos_th) * \ 341 341 (dqx_data * cos_th) \ 342 342 + (dqy_data * sin_th) * \ 343 343 (dqy_data * sin_th)) 344 output.dqy_data = n umpy.sqrt((dqx_data * sin_th) * \344 output.dqy_data = np.sqrt((dqx_data * sin_th) * \ 345 345 (dqx_data * sin_th) \ 346 346 + (dqy_data * cos_th) * \ -
src/sas/sascalc/dataloader/readers/sesans_reader.py
r7caf3e5 r9a5097c 6 6 Jurrian Bakker 7 7 """ 8 import numpy 8 import numpy as np 9 9 import os 10 10 from sas.sascalc.dataloader.data_info import Data1D … … 60 60 buff = input_f.read() 61 61 lines = buff.splitlines() 62 x = n umpy.zeros(0)63 y = n umpy.zeros(0)64 dy = n umpy.zeros(0)65 lam = n umpy.zeros(0)66 dlam = n umpy.zeros(0)67 dx = n umpy.zeros(0)62 x = np.zeros(0) 63 y = np.zeros(0) 64 dy = np.zeros(0) 65 lam = np.zeros(0) 66 dlam = np.zeros(0) 67 dx = np.zeros(0) 68 68 69 69 #temp. space to sort data 70 tx = n umpy.zeros(0)71 ty = n umpy.zeros(0)72 tdy = n umpy.zeros(0)73 tlam = n umpy.zeros(0)74 tdlam = n umpy.zeros(0)75 tdx = n umpy.zeros(0)70 tx = np.zeros(0) 71 ty = np.zeros(0) 72 tdy = np.zeros(0) 73 tlam = np.zeros(0) 74 tdlam = np.zeros(0) 75 tdx = np.zeros(0) 76 76 output = Data1D(x=x, y=y, lam=lam, dy=dy, dx=dx, dlam=dlam, isSesans=True) 77 77 self.filename = output.filename = basename … … 128 128 129 129 x,y,lam,dy,dx,dlam = [ 130 numpy.asarray(v, 'double')130 np.asarray(v, 'double') 131 131 for v in (x,y,lam,dy,dx,dlam) 132 132 ] -
src/sas/sascalc/dataloader/readers/tiff_reader.py
rb699768 r9a5097c 13 13 import logging 14 14 import os 15 import numpy 15 import numpy as np 16 16 from sas.sascalc.dataloader.data_info import Data2D 17 17 from sas.sascalc.dataloader.manipulations import reader2D_converter … … 56 56 57 57 # Initiazed the output data object 58 output.data = n umpy.zeros([im.size[0], im.size[1]])59 output.err_data = n umpy.zeros([im.size[0], im.size[1]])60 output.mask = n umpy.ones([im.size[0], im.size[1]], dtype=bool)58 output.data = np.zeros([im.size[0], im.size[1]]) 59 output.err_data = np.zeros([im.size[0], im.size[1]]) 60 output.mask = np.ones([im.size[0], im.size[1]], dtype=bool) 61 61 62 62 # Initialize … … 94 94 output.x_bins = x_vals 95 95 output.y_bins = y_vals 96 output.qx_data = n umpy.array(x_vals)97 output.qy_data = n umpy.array(y_vals)96 output.qx_data = np.array(x_vals) 97 output.qy_data = np.array(y_vals) 98 98 output.xmin = 0 99 99 output.xmax = im.size[0] - 1 -
src/sas/sascalc/fit/AbstractFitEngine.py
ra9f579c r9a5097c 4 4 import sys 5 5 import math 6 import numpy 6 import numpy as np 7 7 8 8 from sas.sascalc.dataloader.data_info import Data1D … … 162 162 # constant, or dy data 163 163 if dy is None or dy == [] or dy.all() == 0: 164 self.dy = n umpy.ones(len(y))164 self.dy = np.ones(len(y)) 165 165 else: 166 self.dy = n umpy.asarray(dy).copy()166 self.dy = np.asarray(dy).copy() 167 167 168 168 ## Min Q-value 169 169 #Skip the Q=0 point, especially when y(q=0)=None at x[0]. 170 170 if min(self.x) == 0.0 and self.x[0] == 0 and\ 171 not n umpy.isfinite(self.y[0]):171 not np.isfinite(self.y[0]): 172 172 self.qmin = min(self.x[self.x != 0]) 173 173 else: … … 188 188 # Skip Q=0 point, (especially for y(q=0)=None at x[0]). 189 189 # ToDo: Find better way to do it. 190 if qmin == 0.0 and not n umpy.isfinite(self.y[qmin]):190 if qmin == 0.0 and not np.isfinite(self.y[qmin]): 191 191 self.qmin = min(self.x[self.x != 0]) 192 192 elif qmin != None: … … 239 239 """ 240 240 # Compute theory data f(x) 241 fx = n umpy.zeros(len(self.x))241 fx = np.zeros(len(self.x)) 242 242 fx[self.idx_unsmeared] = fn(self.x[self.idx_unsmeared]) 243 243 … … 247 247 self._last_unsmeared_bin) 248 248 ## Sanity check 249 if n umpy.size(self.dy) != numpy.size(fx):249 if np.size(self.dy) != np.size(fx): 250 250 msg = "FitData1D: invalid error array " 251 msg += "%d <> %d" % (n umpy.shape(self.dy), numpy.size(fx))251 msg += "%d <> %d" % (np.shape(self.dy), np.size(fx)) 252 252 raise RuntimeError, msg 253 253 return (self.y[self.idx] - fx[self.idx]) / self.dy[self.idx], fx[self.idx] … … 300 300 ## new error image for fitting purpose 301 301 if self.err_data == None or self.err_data == []: 302 self.res_err_data = n umpy.ones(len(self.data))302 self.res_err_data = np.ones(len(self.data)) 303 303 else: 304 304 self.res_err_data = copy.deepcopy(self.err_data) 305 305 #self.res_err_data[self.res_err_data==0]=1 306 306 307 self.radius = n umpy.sqrt(self.qx_data**2 + self.qy_data**2)307 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 308 308 309 309 # Note: mask = True: for MASK while mask = False for NOT to mask … … 311 311 (self.radius <= self.qmax)) 312 312 self.idx = (self.idx) & (self.mask) 313 self.idx = (self.idx) & (n umpy.isfinite(self.data))314 self.num_points = n umpy.sum(self.idx)313 self.idx = (self.idx) & (np.isfinite(self.data)) 314 self.num_points = np.sum(self.idx) 315 315 316 316 def set_smearer(self, smearer): … … 334 334 if qmax != None: 335 335 self.qmax = qmax 336 self.radius = n umpy.sqrt(self.qx_data**2 + self.qy_data**2)336 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 337 337 self.idx = ((self.qmin <= self.radius) &\ 338 338 (self.radius <= self.qmax)) 339 339 self.idx = (self.idx) & (self.mask) 340 self.idx = (self.idx) & (n umpy.isfinite(self.data))340 self.idx = (self.idx) & (np.isfinite(self.data)) 341 341 self.idx = (self.idx) & (self.res_err_data != 0) 342 342 … … 351 351 Number of measurement points in data set after masking, etc. 352 352 """ 353 return n umpy.sum(self.idx)353 return np.sum(self.idx) 354 354 355 355 def residuals(self, fn): -
src/sas/sascalc/fit/BumpsFitting.py
r1a30720 r9a5097c 6 6 import traceback 7 7 8 import numpy 8 import numpy as np 9 9 10 10 from bumps import fitters … … 97 97 try: 98 98 p = history.population_values[0] 99 n,p = len(p), n umpy.sort(p)99 n,p = len(p), np.sort(p) 100 100 QI,Qmid, = int(0.2*n),int(0.5*n) 101 101 self.convergence.append((best, p[0],p[QI],p[Qmid],p[-1-QI],p[-1])) … … 194 194 195 195 def numpoints(self): 196 return n umpy.sum(self.data.idx) # number of fitted points196 return np.sum(self.data.idx) # number of fitted points 197 197 198 198 def nllf(self): 199 return 0.5*n umpy.sum(self.residuals()**2)199 return 0.5*np.sum(self.residuals()**2) 200 200 201 201 def theory(self): … … 295 295 if R.success: 296 296 if result['stderr'] is None: 297 R.stderr = n umpy.NaN*numpy.ones(len(param_list))297 R.stderr = np.NaN*np.ones(len(param_list)) 298 298 else: 299 R.stderr = n umpy.hstack((result['stderr'][fitted_index],300 numpy.NaN*numpy.ones(len(fitness.computed_pars))))301 R.pvec = n umpy.hstack((result['value'][fitted_index],299 R.stderr = np.hstack((result['stderr'][fitted_index], 300 np.NaN*np.ones(len(fitness.computed_pars)))) 301 R.pvec = np.hstack((result['value'][fitted_index], 302 302 [p.value for p in fitness.computed_pars])) 303 R.fitness = n umpy.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index))303 R.fitness = np.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index)) 304 304 else: 305 R.stderr = n umpy.NaN*numpy.ones(len(param_list))306 R.pvec = n umpy.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars])307 R.fitness = n umpy.NaN305 R.stderr = np.NaN*np.ones(len(param_list)) 306 R.pvec = np.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars]) 307 R.fitness = np.NaN 308 308 R.convergence = result['convergence'] 309 309 if result['uncertainty'] is not None: … … 336 336 max_step = steps + options.get('burn', 0) 337 337 pars = [p.name for p in problem._parameters] 338 #x0 = n umpy.asarray([p.value for p in problem._parameters])338 #x0 = np.asarray([p.value for p in problem._parameters]) 339 339 options['monitors'] = [ 340 340 BumpsMonitor(handler, max_step, pars, problem.dof), … … 351 351 errors = [] 352 352 except Exception as exc: 353 best, fbest = None, n umpy.NaN353 best, fbest = None, np.NaN 354 354 errors = [str(exc), traceback.format_exc()] 355 355 finally: … … 358 358 359 359 convergence_list = options['monitors'][-1].convergence 360 convergence = (2*n umpy.asarray(convergence_list)/problem.dof361 if convergence_list else n umpy.empty((0,1),'d'))360 convergence = (2*np.asarray(convergence_list)/problem.dof 361 if convergence_list else np.empty((0,1),'d')) 362 362 363 363 success = best is not None -
src/sas/sascalc/fit/Loader.py
rb699768 r9a5097c 2 2 #import wx 3 3 #import string 4 import numpy 4 import numpy as np 5 5 6 6 class Load: … … 52 52 self.y.append(y) 53 53 self.dy.append(dy) 54 self.dx = n umpy.zeros(len(self.x))54 self.dx = np.zeros(len(self.x)) 55 55 except: 56 56 print "READ ERROR", line -
src/sas/sascalc/fit/MultiplicationModel.py
r68669da r9a5097c 1 1 import copy 2 2 3 import numpy 3 import numpy as np 4 4 5 5 from sas.sascalc.calculator.BaseComponent import BaseComponent … … 52 52 ## Parameter details [units, min, max] 53 53 self._set_details() 54 self.details['scale_factor'] = ['', 0.0, n umpy.inf]55 self.details['background'] = ['',-n umpy.inf,numpy.inf]54 self.details['scale_factor'] = ['', 0.0, np.inf] 55 self.details['background'] = ['',-np.inf,np.inf] 56 56 57 57 #list of parameter that can be fitted -
src/sas/sascalc/fit/expression.py
rb699768 r9a5097c 271 271 272 272 def test_deps(): 273 import numpy 273 import numpy as np 274 274 275 275 # Null case … … 279 279 _check("test1",[(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)]) 280 280 _check("test1 renumbered",[(6,1),(7,3),(7,4),(6,7),(5,7),(3,2)]) 281 _check("test1 numpy",n umpy.array([(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)]))281 _check("test1 numpy",np.array([(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)])) 282 282 283 283 # No dependencies … … 291 291 292 292 # large test for gross speed check 293 A = n umpy.random.randint(4000,size=(1000,2))293 A = np.random.randint(4000,size=(1000,2)) 294 294 A[:,1] += 4000 # Avoid cycles 295 295 _check("test-large",A) … … 297 297 # depth tests 298 298 k = 200 299 A = n umpy.array([range(0,k),range(1,k+1)]).T299 A = np.array([range(0,k),range(1,k+1)]).T 300 300 _check("depth-1",A) 301 301 302 A = n umpy.array([range(1,k+1),range(0,k)]).T302 A = np.array([range(1,k+1),range(0,k)]).T 303 303 _check("depth-2",A) 304 304 -
src/sas/sascalc/invariant/invariant.py
rb699768 r9a5097c 17 17 """ 18 18 import math 19 import numpy 19 import numpy as np 20 20 21 21 from sas.sascalc.dataloader.data_info import Data1D as LoaderData1D … … 50 50 dy = data.dy 51 51 else: 52 dy = n umpy.ones(len(data.y))52 dy = np.ones(len(data.y)) 53 53 54 54 # Transform the data … … 63 63 64 64 # Create Data1D object 65 x_out = n umpy.asarray(x_out)66 y_out = n umpy.asarray(y_out)67 dy_out = n umpy.asarray(dy_out)65 x_out = np.asarray(x_out) 66 y_out = np.asarray(y_out) 67 dy_out = np.asarray(dy_out) 68 68 linear_data = LoaderData1D(x=x_out, y=y_out, dy=dy_out) 69 69 … … 158 158 :param x: array of q-values 159 159 """ 160 p1 = n umpy.array([self.dscale * math.exp(-((self.radius * q) ** 2 / 3)) \160 p1 = np.array([self.dscale * math.exp(-((self.radius * q) ** 2 / 3)) \ 161 161 for q in x]) 162 p2 = n umpy.array([self.scale * math.exp(-((self.radius * q) ** 2 / 3))\162 p2 = np.array([self.scale * math.exp(-((self.radius * q) ** 2 / 3))\ 163 163 * (-(q ** 2 / 3)) * 2 * self.radius * self.dradius for q in x]) 164 164 diq2 = p1 * p1 + p2 * p2 165 return n umpy.array([math.sqrt(err) for err in diq2])165 return np.array([math.sqrt(err) for err in diq2]) 166 166 167 167 def _guinier(self, x): … … 182 182 msg = "Rg expected positive value, but got %s" % self.radius 183 183 raise ValueError(msg) 184 value = n umpy.array([math.exp(-((self.radius * i) ** 2 / 3)) for i in x])184 value = np.array([math.exp(-((self.radius * i) ** 2 / 3)) for i in x]) 185 185 return self.scale * value 186 186 … … 232 232 :param x: array of q-values 233 233 """ 234 p1 = n umpy.array([self.dscale * math.pow(q, -self.power) for q in x])235 p2 = n umpy.array([self.scale * self.power * math.pow(q, -self.power - 1)\234 p1 = np.array([self.dscale * math.pow(q, -self.power) for q in x]) 235 p2 = np.array([self.scale * self.power * math.pow(q, -self.power - 1)\ 236 236 * self.dpower for q in x]) 237 237 diq2 = p1 * p1 + p2 * p2 238 return n umpy.array([math.sqrt(err) for err in diq2])238 return np.array([math.sqrt(err) for err in diq2]) 239 239 240 240 def _power_law(self, x): … … 259 259 raise ValueError(msg) 260 260 261 value = n umpy.array([math.pow(i, -self.power) for i in x])261 value = np.array([math.pow(i, -self.power) for i in x]) 262 262 return self.scale * value 263 263 … … 304 304 idx = (self.data.x >= qmin) & (self.data.x <= qmax) 305 305 306 fx = n umpy.zeros(len(self.data.x))306 fx = np.zeros(len(self.data.x)) 307 307 308 308 # Uncertainty 309 if type(self.data.dy) == n umpy.ndarray and \309 if type(self.data.dy) == np.ndarray and \ 310 310 len(self.data.dy) == len(self.data.x) and \ 311 numpy.all(self.data.dy > 0):311 np.all(self.data.dy > 0): 312 312 sigma = self.data.dy 313 313 else: 314 sigma = n umpy.ones(len(self.data.x))314 sigma = np.ones(len(self.data.x)) 315 315 316 316 # Compute theory data f(x) … … 332 332 sigma2 = linearized_data.dy * linearized_data.dy 333 333 a = -(power) 334 b = (n umpy.sum(linearized_data.y / sigma2) \335 - a * n umpy.sum(linearized_data.x / sigma2)) / numpy.sum(1.0 / sigma2)334 b = (np.sum(linearized_data.y / sigma2) \ 335 - a * np.sum(linearized_data.x / sigma2)) / np.sum(1.0 / sigma2) 336 336 337 337 338 338 deltas = linearized_data.x * a + \ 339 numpy.ones(len(linearized_data.x)) * b - linearized_data.y340 residuals = n umpy.sum(deltas * deltas / sigma2)341 342 err = math.fabs(residuals) / n umpy.sum(1.0 / sigma2)339 np.ones(len(linearized_data.x)) * b - linearized_data.y 340 residuals = np.sum(deltas * deltas / sigma2) 341 342 err = math.fabs(residuals) / np.sum(1.0 / sigma2) 343 343 return [a, b], [0, math.sqrt(err)] 344 344 else: 345 A = n umpy.vstack([linearized_data.x / linearized_data.dy, 1.0 / linearized_data.dy]).T346 (p, residuals, _, _) = n umpy.linalg.lstsq(A, linearized_data.y / linearized_data.dy)345 A = np.vstack([linearized_data.x / linearized_data.dy, 1.0 / linearized_data.dy]).T 346 (p, residuals, _, _) = np.linalg.lstsq(A, linearized_data.y / linearized_data.dy) 347 347 348 348 # Get the covariance matrix, defined as inv_cov = a_transposed * a 349 err = n umpy.zeros(2)349 err = np.zeros(2) 350 350 try: 351 inv_cov = n umpy.dot(A.transpose(), A)352 cov = n umpy.linalg.pinv(inv_cov)351 inv_cov = np.dot(A.transpose(), A) 352 cov = np.linalg.pinv(inv_cov) 353 353 err_matrix = math.fabs(residuals) * cov 354 354 err = [math.sqrt(err_matrix[0][0]), math.sqrt(err_matrix[1][1])] … … 434 434 if new_data.dy is None or len(new_data.x) != len(new_data.dy) or \ 435 435 (min(new_data.dy) == 0 and max(new_data.dy) == 0): 436 new_data.dy = n umpy.ones(len(new_data.x))436 new_data.dy = np.ones(len(new_data.x)) 437 437 return new_data 438 438 … … 571 571 """ 572 572 #create new Data1D to compute the invariant 573 q = n umpy.linspace(start=q_start,573 q = np.linspace(start=q_start, 574 574 stop=q_end, 575 575 num=npts, … … 580 580 result_data = LoaderData1D(x=q, y=iq, dy=diq) 581 581 if self._smeared != None: 582 result_data.dxl = self._smeared * n umpy.ones(len(q))582 result_data.dxl = self._smeared * np.ones(len(q)) 583 583 return result_data 584 584 … … 691 691 692 692 if q_start >= q_end: 693 return n umpy.zeros(0), numpy.zeros(0)693 return np.zeros(0), np.zeros(0) 694 694 695 695 return self._get_extrapolated_data(\ … … 719 719 720 720 if q_start >= q_end: 721 return n umpy.zeros(0), numpy.zeros(0)721 return np.zeros(0), np.zeros(0) 722 722 723 723 return self._get_extrapolated_data(\ -
src/sas/sascalc/pr/fit/AbstractFitEngine.py
rfc18690 r9a5097c 4 4 import sys 5 5 import math 6 import numpy 6 import numpy as np 7 7 8 8 from sas.sascalc.dataloader.data_info import Data1D … … 162 162 # constant, or dy data 163 163 if dy is None or dy == [] or dy.all() == 0: 164 self.dy = n umpy.ones(len(y))164 self.dy = np.ones(len(y)) 165 165 else: 166 self.dy = n umpy.asarray(dy).copy()166 self.dy = np.asarray(dy).copy() 167 167 168 168 ## Min Q-value 169 169 #Skip the Q=0 point, especially when y(q=0)=None at x[0]. 170 170 if min(self.x) == 0.0 and self.x[0] == 0 and\ 171 not n umpy.isfinite(self.y[0]):171 not np.isfinite(self.y[0]): 172 172 self.qmin = min(self.x[self.x != 0]) 173 173 else: … … 188 188 # Skip Q=0 point, (especially for y(q=0)=None at x[0]). 189 189 # ToDo: Find better way to do it. 190 if qmin == 0.0 and not n umpy.isfinite(self.y[qmin]):190 if qmin == 0.0 and not np.isfinite(self.y[qmin]): 191 191 self.qmin = min(self.x[self.x != 0]) 192 192 elif qmin != None: … … 239 239 """ 240 240 # Compute theory data f(x) 241 fx = n umpy.zeros(len(self.x))241 fx = np.zeros(len(self.x)) 242 242 fx[self.idx_unsmeared] = fn(self.x[self.idx_unsmeared]) 243 243 … … 247 247 self._last_unsmeared_bin) 248 248 ## Sanity check 249 if n umpy.size(self.dy) != numpy.size(fx):249 if np.size(self.dy) != np.size(fx): 250 250 msg = "FitData1D: invalid error array " 251 msg += "%d <> %d" % (n umpy.shape(self.dy), numpy.size(fx))251 msg += "%d <> %d" % (np.shape(self.dy), np.size(fx)) 252 252 raise RuntimeError, msg 253 253 return (self.y[self.idx] - fx[self.idx]) / self.dy[self.idx], fx[self.idx] … … 300 300 ## new error image for fitting purpose 301 301 if self.err_data == None or self.err_data == []: 302 self.res_err_data = n umpy.ones(len(self.data))302 self.res_err_data = np.ones(len(self.data)) 303 303 else: 304 304 self.res_err_data = copy.deepcopy(self.err_data) 305 305 #self.res_err_data[self.res_err_data==0]=1 306 306 307 self.radius = n umpy.sqrt(self.qx_data**2 + self.qy_data**2)307 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 308 308 309 309 # Note: mask = True: for MASK while mask = False for NOT to mask … … 311 311 (self.radius <= self.qmax)) 312 312 self.idx = (self.idx) & (self.mask) 313 self.idx = (self.idx) & (n umpy.isfinite(self.data))314 self.num_points = n umpy.sum(self.idx)313 self.idx = (self.idx) & (np.isfinite(self.data)) 314 self.num_points = np.sum(self.idx) 315 315 316 316 def set_smearer(self, smearer): … … 334 334 if qmax != None: 335 335 self.qmax = qmax 336 self.radius = n umpy.sqrt(self.qx_data**2 + self.qy_data**2)336 self.radius = np.sqrt(self.qx_data**2 + self.qy_data**2) 337 337 self.idx = ((self.qmin <= self.radius) &\ 338 338 (self.radius <= self.qmax)) 339 339 self.idx = (self.idx) & (self.mask) 340 self.idx = (self.idx) & (n umpy.isfinite(self.data))340 self.idx = (self.idx) & (np.isfinite(self.data)) 341 341 self.idx = (self.idx) & (self.res_err_data != 0) 342 342 … … 351 351 Number of measurement points in data set after masking, etc. 352 352 """ 353 return n umpy.sum(self.idx)353 return np.sum(self.idx) 354 354 355 355 def residuals(self, fn): -
src/sas/sascalc/pr/fit/BumpsFitting.py
rb699768 r9a5097c 5 5 from datetime import timedelta, datetime 6 6 7 import numpy 7 import numpy as np 8 8 9 9 from bumps import fitters … … 96 96 try: 97 97 p = history.population_values[0] 98 n,p = len(p), n umpy.sort(p)98 n,p = len(p), np.sort(p) 99 99 QI,Qmid, = int(0.2*n),int(0.5*n) 100 100 self.convergence.append((best, p[0],p[QI],p[Qmid],p[-1-QI],p[-1])) … … 193 193 194 194 def numpoints(self): 195 return n umpy.sum(self.data.idx) # number of fitted points195 return np.sum(self.data.idx) # number of fitted points 196 196 197 197 def nllf(self): 198 return 0.5*n umpy.sum(self.residuals()**2)198 return 0.5*np.sum(self.residuals()**2) 199 199 200 200 def theory(self): … … 293 293 R.success = result['success'] 294 294 if R.success: 295 R.stderr = n umpy.hstack((result['stderr'][fitted_index],296 numpy.NaN*numpy.ones(len(fitness.computed_pars))))297 R.pvec = n umpy.hstack((result['value'][fitted_index],295 R.stderr = np.hstack((result['stderr'][fitted_index], 296 np.NaN*np.ones(len(fitness.computed_pars)))) 297 R.pvec = np.hstack((result['value'][fitted_index], 298 298 [p.value for p in fitness.computed_pars])) 299 R.fitness = n umpy.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index))299 R.fitness = np.sum(R.residuals**2)/(fitness.numpoints() - len(fitted_index)) 300 300 else: 301 R.stderr = n umpy.NaN*numpy.ones(len(param_list))302 R.pvec = n umpy.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars])303 R.fitness = n umpy.NaN301 R.stderr = np.NaN*np.ones(len(param_list)) 302 R.pvec = np.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars]) 303 R.fitness = np.NaN 304 304 R.convergence = result['convergence'] 305 305 if result['uncertainty'] is not None: … … 331 331 max_step = steps + options.get('burn', 0) 332 332 pars = [p.name for p in problem._parameters] 333 #x0 = n umpy.asarray([p.value for p in problem._parameters])333 #x0 = np.asarray([p.value for p in problem._parameters]) 334 334 options['monitors'] = [ 335 335 BumpsMonitor(handler, max_step, pars, problem.dof), … … 352 352 353 353 convergence_list = options['monitors'][-1].convergence 354 convergence = (2*n umpy.asarray(convergence_list)/problem.dof355 if convergence_list else n umpy.empty((0,1),'d'))354 convergence = (2*np.asarray(convergence_list)/problem.dof 355 if convergence_list else np.empty((0,1),'d')) 356 356 357 357 success = best is not None -
src/sas/sascalc/pr/fit/Loader.py
rb699768 r9a5097c 2 2 #import wx 3 3 #import string 4 import numpy 4 import numpy as np 5 5 6 6 class Load: … … 52 52 self.y.append(y) 53 53 self.dy.append(dy) 54 self.dx = n umpy.zeros(len(self.x))54 self.dx = np.zeros(len(self.x)) 55 55 except: 56 56 print "READ ERROR", line -
src/sas/sascalc/pr/fit/expression.py
rb699768 r9a5097c 271 271 272 272 def test_deps(): 273 import numpy 273 import numpy as np 274 274 275 275 # Null case … … 279 279 _check("test1",[(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)]) 280 280 _check("test1 renumbered",[(6,1),(7,3),(7,4),(6,7),(5,7),(3,2)]) 281 _check("test1 numpy",n umpy.array([(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)]))281 _check("test1 numpy",np.array([(2,7),(1,5),(1,4),(2,1),(3,1),(5,6)])) 282 282 283 283 # No dependencies … … 291 291 292 292 # large test for gross speed check 293 A = n umpy.random.randint(4000,size=(1000,2))293 A = np.random.randint(4000,size=(1000,2)) 294 294 A[:,1] += 4000 # Avoid cycles 295 295 _check("test-large",A) … … 297 297 # depth tests 298 298 k = 200 299 A = n umpy.array([range(0,k),range(1,k+1)]).T299 A = np.array([range(0,k),range(1,k+1)]).T 300 300 _check("depth-1",A) 301 301 302 A = n umpy.array([range(1,k+1),range(0,k)]).T302 A = np.array([range(1,k+1),range(0,k)]).T 303 303 _check("depth-2",A) 304 304 -
src/sas/sascalc/pr/invertor.py
r2c60f304 r9a5097c 7 7 """ 8 8 9 import numpy 9 import numpy as np 10 10 import sys 11 11 import math … … 189 189 #import numpy 190 190 if name == 'x': 191 out = n umpy.ones(self.get_nx())191 out = np.ones(self.get_nx()) 192 192 self.get_x(out) 193 193 return out 194 194 elif name == 'y': 195 out = n umpy.ones(self.get_ny())195 out = np.ones(self.get_ny()) 196 196 self.get_y(out) 197 197 return out 198 198 elif name == 'err': 199 out = n umpy.ones(self.get_nerr())199 out = np.ones(self.get_nerr()) 200 200 self.get_err(out) 201 201 return out … … 325 325 raise RuntimeError, msg 326 326 327 p = n umpy.ones(nfunc)327 p = np.ones(nfunc) 328 328 t_0 = time.time() 329 329 out, cov_x, _, _, _ = optimize.leastsq(self.residuals, p, full_output=1) … … 341 341 342 342 if cov_x is None: 343 cov_x = n umpy.ones([nfunc, nfunc])343 cov_x = np.ones([nfunc, nfunc]) 344 344 cov_x *= math.fabs(chisqr) 345 345 return out, cov_x … … 358 358 raise RuntimeError, msg 359 359 360 p = n umpy.ones(nfunc)360 p = np.ones(nfunc) 361 361 t_0 = time.time() 362 362 out, cov_x, _, _, _ = optimize.leastsq(self.pr_residuals, p, full_output=1) … … 435 435 """ 436 436 # Note: To make sure an array is contiguous: 437 # blah = n umpy.ascontiguousarray(blah_original)437 # blah = np.ascontiguousarray(blah_original) 438 438 # ... before passing it to C 439 439 … … 456 456 nfunc += 1 457 457 458 a = n umpy.zeros([npts + nq, nfunc])459 b = n umpy.zeros(npts + nq)460 err = n umpy.zeros([nfunc, nfunc])458 a = np.zeros([npts + nq, nfunc]) 459 b = np.zeros(npts + nq) 460 err = np.zeros([nfunc, nfunc]) 461 461 462 462 # Construct the a matrix and b vector that represent the problem … … 476 476 self.chi2 = chi2 477 477 478 inv_cov = n umpy.zeros([nfunc, nfunc])478 inv_cov = np.zeros([nfunc, nfunc]) 479 479 # Get the covariance matrix, defined as inv_cov = a_transposed * a 480 480 self._get_invcov_matrix(nfunc, nr, a, inv_cov) … … 490 490 491 491 try: 492 cov = n umpy.linalg.pinv(inv_cov)492 cov = np.linalg.pinv(inv_cov) 493 493 err = math.fabs(chi2 / float(npts - nfunc)) * cov 494 494 except: … … 505 505 self.background = c[0] 506 506 507 err_0 = n umpy.zeros([nfunc, nfunc])508 c_0 = n umpy.zeros(nfunc)507 err_0 = np.zeros([nfunc, nfunc]) 508 c_0 = np.zeros(nfunc) 509 509 510 510 for i in range(nfunc_0): … … 662 662 str(self.cov[i][i]))) 663 663 file.write("<r> <Pr> <dPr>\n") 664 r = n umpy.arange(0.0, self.d_max, self.d_max / npts)664 r = np.arange(0.0, self.d_max, self.d_max / npts) 665 665 666 666 for r_i in r: … … 694 694 toks = line.split('=') 695 695 self.nfunc = int(toks[1]) 696 self.out = n umpy.zeros(self.nfunc)697 self.cov = n umpy.zeros([self.nfunc, self.nfunc])696 self.out = np.zeros(self.nfunc) 697 self.cov = np.zeros([self.nfunc, self.nfunc]) 698 698 elif line.startswith('#alpha='): 699 699 toks = line.split('=') -
src/sas/sascalc/pr/num_term.py
rb699768 r9a5097c 1 1 import math 2 import numpy 2 import numpy as np 3 3 import copy 4 4 import sys … … 152 152 def load(path): 153 153 # Read the data from the data file 154 data_x = n umpy.zeros(0)155 data_y = n umpy.zeros(0)156 data_err = n umpy.zeros(0)154 data_x = np.zeros(0) 155 data_y = np.zeros(0) 156 data_err = np.zeros(0) 157 157 scale = None 158 158 min_err = 0.0 … … 176 176 #err = 0 177 177 178 data_x = n umpy.append(data_x, test_x)179 data_y = n umpy.append(data_y, test_y)180 data_err = n umpy.append(data_err, err)178 data_x = np.append(data_x, test_x) 179 data_y = np.append(data_y, test_y) 180 data_err = np.append(data_err, err) 181 181 except: 182 182 logging.error(sys.exc_value)
Note: See TracChangeset
for help on using the changeset viewer.