Changeset 9c0f3c17 in sasview for src/sas/sascalc
- Timestamp:
- Apr 4, 2017 12:50:04 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:
- f2940c4
- Parents:
- 463e7ffc (diff), 1779e72 (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. - Location:
- src/sas/sascalc
- Files:
-
- 35 edited
Legend:
- Unmodified
- Added
- Removed
-
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
r463e7ffc r9c0f3c17 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 … … 395 395 dx_size = (self.qx_max - self.qx_min) / (1000 - 1) 396 396 dy_size = (self.qy_max - self.qy_min) / (1000 - 1) 397 x_val = n umpy.arange(self.qx_min, self.qx_max, dx_size)398 y_val = n umpy.arange(self.qy_max, self.qy_min, -dy_size)399 q_1, q_2 = n umpy.meshgrid(x_val, y_val)397 x_val = np.arange(self.qx_min, self.qx_max, dx_size) 398 y_val = np.arange(self.qy_max, self.qy_min, -dy_size) 399 q_1, q_2 = np.meshgrid(x_val, y_val) 400 400 #q_phi = numpy.arctan(q_1,q_2) 401 401 # check whether polar or cartesian … … 889 889 x_value = x_val - x0_val 890 890 y_value = y_val - y0_val 891 phi_i = n umpy.arctan2(y_val, x_val)891 phi_i = np.arctan2(y_val, x_val) 892 892 893 893 # phi correction due to the gravity shift (in phi) … … 895 895 phi_i = phi_i - phi_0 + self.gravity_phi 896 896 897 sin_phi = n umpy.sin(self.gravity_phi)898 cos_phi = n umpy.cos(self.gravity_phi)897 sin_phi = np.sin(self.gravity_phi) 898 cos_phi = np.cos(self.gravity_phi) 899 899 900 900 x_p = x_value * cos_phi + y_value * sin_phi … … 910 910 nu_value = -0.5 * (new_x * new_x + new_y * new_y) 911 911 912 gaussian = n umpy.exp(nu_value)912 gaussian = np.exp(nu_value) 913 913 # normalizing factor correction 914 914 gaussian /= gaussian.sum() … … 956 956 nu_value *= nu_value 957 957 nu_value *= -0.5 958 gaussian *= n umpy.exp(nu_value)958 gaussian *= np.exp(nu_value) 959 959 gaussian /= sigma 960 960 # normalize … … 1028 1028 offset_x, offset_y) 1029 1029 # distance [cm] from the beam center on detector plane 1030 detector_ind_x = n umpy.arange(detector_pix_nums_x)1031 detector_ind_y = n umpy.arange(detector_pix_nums_y)1030 detector_ind_x = np.arange(detector_pix_nums_x) 1031 detector_ind_y = np.arange(detector_pix_nums_y) 1032 1032 1033 1033 # shif 0.5 pixel so that pix position is at the center of the pixel … … 1043 1043 detector_ind_y = detector_ind_y * pix_y_size 1044 1044 1045 qx_value = n umpy.zeros(len(detector_ind_x))1046 qy_value = n umpy.zeros(len(detector_ind_y))1045 qx_value = np.zeros(len(detector_ind_x)) 1046 qy_value = np.zeros(len(detector_ind_y)) 1047 1047 i = 0 1048 1048 … … 1063 1063 1064 1064 # p min and max values among the center of pixels 1065 self.qx_min = n umpy.min(qx_value)1066 self.qx_max = n umpy.max(qx_value)1067 self.qy_min = n umpy.min(qy_value)1068 self.qy_max = n umpy.max(qy_value)1065 self.qx_min = np.min(qx_value) 1066 self.qx_max = np.max(qx_value) 1067 self.qy_min = np.min(qy_value) 1068 self.qy_max = np.max(qy_value) 1069 1069 1070 1070 # Appr. min and max values of the detector display limits … … 1090 1090 from sas.sascalc.dataloader.data_info import Data2D 1091 1091 output = Data2D() 1092 inten = n umpy.zeros_like(qx_value)1092 inten = np.zeros_like(qx_value) 1093 1093 output.data = inten 1094 1094 output.qx_data = qx_value … … 1109 1109 plane_dist = dx_size 1110 1110 # full scattering angle on the x-axis 1111 theta = n umpy.arctan(plane_dist / det_dist)1112 qx_value = (2.0 * pi / wavelength) * n umpy.sin(theta)1111 theta = np.arctan(plane_dist / det_dist) 1112 qx_value = (2.0 * pi / wavelength) * np.sin(theta) 1113 1113 return qx_value 1114 1114 -
src/sas/sascalc/calculator/sas_gen.py
r463e7ffc r9c0f3c17 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 … … 82 82 ## Parameter details [units, min, max] 83 83 self.details = {} 84 self.details['scale'] = ['', 0.0, n umpy.inf]85 self.details['background'] = ['[1/cm]', 0.0, n umpy.inf]86 self.details['solvent_SLD'] = ['1/A^(2)', -n umpy.inf, numpy.inf]87 self.details['total_volume'] = ['A^(3)', 0.0, n umpy.inf]84 self.details['scale'] = ['', 0.0, np.inf] 85 self.details['background'] = ['[1/cm]', 0.0, np.inf] 86 self.details['solvent_SLD'] = ['1/A^(2)', -np.inf, np.inf] 87 self.details['total_volume'] = ['A^(3)', 0.0, np.inf] 88 88 self.details['Up_frac_in'] = ['[u/(u+d)]', 0.0, 1.0] 89 89 self.details['Up_frac_out'] = ['[u/(u+d)]', 0.0, 1.0] 90 self.details['Up_theta'] = ['[deg]', -n umpy.inf, numpy.inf]90 self.details['Up_theta'] = ['[deg]', -np.inf, np.inf] 91 91 # fixed parameters 92 92 self.fixed = [] … … 173 173 msg = "Not a 1D." 174 174 raise ValueError, msg 175 i_out = n umpy.zeros_like(x[0])175 i_out = np.zeros_like(x[0]) 176 176 # 1D I is found at y =0 in the 2D pattern 177 177 out = self._gen(x[0], [], i_out) … … 189 189 """ 190 190 if x.__class__.__name__ == 'list': 191 i_out = n umpy.zeros_like(x[0])191 i_out = np.zeros_like(x[0]) 192 192 out = self._gen(x[0], x[1], i_out) 193 193 return out … … 239 239 self.omfdata = omfdata 240 240 length = int(omfdata.xnodes * omfdata.ynodes * omfdata.znodes) 241 pos_x = n umpy.arange(omfdata.xmin,241 pos_x = np.arange(omfdata.xmin, 242 242 omfdata.xnodes*omfdata.xstepsize + omfdata.xmin, 243 243 omfdata.xstepsize) 244 pos_y = n umpy.arange(omfdata.ymin,244 pos_y = np.arange(omfdata.ymin, 245 245 omfdata.ynodes*omfdata.ystepsize + omfdata.ymin, 246 246 omfdata.ystepsize) 247 pos_z = n umpy.arange(omfdata.zmin,247 pos_z = np.arange(omfdata.zmin, 248 248 omfdata.znodes*omfdata.zstepsize + omfdata.zmin, 249 249 omfdata.zstepsize) 250 self.pos_x = n umpy.tile(pos_x, int(omfdata.ynodes * omfdata.znodes))250 self.pos_x = np.tile(pos_x, int(omfdata.ynodes * omfdata.znodes)) 251 251 self.pos_y = pos_y.repeat(int(omfdata.xnodes)) 252 self.pos_y = n umpy.tile(self.pos_y, int(omfdata.znodes))252 self.pos_y = np.tile(self.pos_y, int(omfdata.znodes)) 253 253 self.pos_z = pos_z.repeat(int(omfdata.xnodes * omfdata.ynodes)) 254 254 self.mx = omfdata.mx 255 255 self.my = omfdata.my 256 256 self.mz = omfdata.mz 257 self.sld_n = n umpy.zeros(length)257 self.sld_n = np.zeros(length) 258 258 259 259 if omfdata.mx == None: 260 self.mx = n umpy.zeros(length)260 self.mx = np.zeros(length) 261 261 if omfdata.my == None: 262 self.my = n umpy.zeros(length)262 self.my = np.zeros(length) 263 263 if omfdata.mz == None: 264 self.mz = n umpy.zeros(length)264 self.mz = np.zeros(length) 265 265 266 266 self._check_data_length(length) 267 267 self.remove_null_points(False, False) 268 mask = n umpy.ones(len(self.sld_n), dtype=bool)268 mask = np.ones(len(self.sld_n), dtype=bool) 269 269 if shape.lower() == 'ellipsoid': 270 270 try: … … 330 330 """ 331 331 if remove: 332 is_nonzero = (n umpy.fabs(self.mx) + numpy.fabs(self.my) +333 n umpy.fabs(self.mz)).nonzero()332 is_nonzero = (np.fabs(self.mx) + np.fabs(self.my) + 333 np.fabs(self.mz)).nonzero() 334 334 if len(is_nonzero[0]) > 0: 335 335 self.pos_x = self.pos_x[is_nonzero] … … 371 371 """ 372 372 desc = "" 373 mx = n umpy.zeros(0)374 my = n umpy.zeros(0)375 mz = n umpy.zeros(0)373 mx = np.zeros(0) 374 my = np.zeros(0) 375 mz = np.zeros(0) 376 376 try: 377 377 input_f = open(path, 'rb') … … 391 391 _my = mag2sld(_my, valueunit) 392 392 _mz = mag2sld(_mz, valueunit) 393 mx = n umpy.append(mx, _mx)394 my = n umpy.append(my, _my)395 mz = n umpy.append(mz, _mz)393 mx = np.append(mx, _mx) 394 my = np.append(my, _my) 395 mz = np.append(mz, _mz) 396 396 except: 397 397 # Skip non-data lines … … 503 503 :raise RuntimeError: when the file can't be opened 504 504 """ 505 pos_x = n umpy.zeros(0)506 pos_y = n umpy.zeros(0)507 pos_z = n umpy.zeros(0)508 sld_n = n umpy.zeros(0)509 sld_mx = n umpy.zeros(0)510 sld_my = n umpy.zeros(0)511 sld_mz = n umpy.zeros(0)512 vol_pix = n umpy.zeros(0)513 pix_symbol = n umpy.zeros(0)505 pos_x = np.zeros(0) 506 pos_y = np.zeros(0) 507 pos_z = np.zeros(0) 508 sld_n = np.zeros(0) 509 sld_mx = np.zeros(0) 510 sld_my = np.zeros(0) 511 sld_mz = np.zeros(0) 512 vol_pix = np.zeros(0) 513 pix_symbol = np.zeros(0) 514 514 x_line = [] 515 515 y_line = [] … … 545 545 _pos_y = float(line[38:46].strip()) 546 546 _pos_z = float(line[46:54].strip()) 547 pos_x = n umpy.append(pos_x, _pos_x)548 pos_y = n umpy.append(pos_y, _pos_y)549 pos_z = n umpy.append(pos_z, _pos_z)547 pos_x = np.append(pos_x, _pos_x) 548 pos_y = np.append(pos_y, _pos_y) 549 pos_z = np.append(pos_z, _pos_z) 550 550 try: 551 551 val = nsf.neutron_sld(atom_name)[0] 552 552 # sld in Ang^-2 unit 553 553 val *= 1.0e-6 554 sld_n = n umpy.append(sld_n, val)554 sld_n = np.append(sld_n, val) 555 555 atom = formula(atom_name) 556 556 # cm to A units 557 557 vol = 1.0e+24 * atom.mass / atom.density / NA 558 vol_pix = n umpy.append(vol_pix, vol)558 vol_pix = np.append(vol_pix, vol) 559 559 except: 560 560 print "Error: set the sld of %s to zero"% atom_name 561 sld_n = n umpy.append(sld_n, 0.0)562 sld_mx = n umpy.append(sld_mx, 0)563 sld_my = n umpy.append(sld_my, 0)564 sld_mz = n umpy.append(sld_mz, 0)565 pix_symbol = n umpy.append(pix_symbol, atom_name)561 sld_n = np.append(sld_n, 0.0) 562 sld_mx = np.append(sld_mx, 0) 563 sld_my = np.append(sld_my, 0) 564 sld_mz = np.append(sld_mz, 0) 565 pix_symbol = np.append(pix_symbol, atom_name) 566 566 elif line[0:6].strip().count('CONECT') > 0: 567 567 toks = line.split() … … 632 632 """ 633 633 try: 634 pos_x = n umpy.zeros(0)635 pos_y = n umpy.zeros(0)636 pos_z = n umpy.zeros(0)637 sld_n = n umpy.zeros(0)638 sld_mx = n umpy.zeros(0)639 sld_my = n umpy.zeros(0)640 sld_mz = n umpy.zeros(0)634 pos_x = np.zeros(0) 635 pos_y = np.zeros(0) 636 pos_z = np.zeros(0) 637 sld_n = np.zeros(0) 638 sld_mx = np.zeros(0) 639 sld_my = np.zeros(0) 640 sld_mz = np.zeros(0) 641 641 try: 642 642 # Use numpy to speed up loading 643 input_f = n umpy.loadtxt(path, dtype='float', skiprows=1,643 input_f = np.loadtxt(path, dtype='float', skiprows=1, 644 644 ndmin=1, unpack=True) 645 pos_x = n umpy.array(input_f[0])646 pos_y = n umpy.array(input_f[1])647 pos_z = n umpy.array(input_f[2])648 sld_n = n umpy.array(input_f[3])649 sld_mx = n umpy.array(input_f[4])650 sld_my = n umpy.array(input_f[5])651 sld_mz = n umpy.array(input_f[6])645 pos_x = np.array(input_f[0]) 646 pos_y = np.array(input_f[1]) 647 pos_z = np.array(input_f[2]) 648 sld_n = np.array(input_f[3]) 649 sld_mx = np.array(input_f[4]) 650 sld_my = np.array(input_f[5]) 651 sld_mz = np.array(input_f[6]) 652 652 ncols = len(input_f) 653 653 if ncols == 8: 654 vol_pix = n umpy.array(input_f[7])654 vol_pix = np.array(input_f[7]) 655 655 elif ncols == 7: 656 656 vol_pix = None … … 671 671 _sld_my = float(toks[5]) 672 672 _sld_mz = float(toks[6]) 673 pos_x = n umpy.append(pos_x, _pos_x)674 pos_y = n umpy.append(pos_y, _pos_y)675 pos_z = n umpy.append(pos_z, _pos_z)676 sld_n = n umpy.append(sld_n, _sld_n)677 sld_mx = n umpy.append(sld_mx, _sld_mx)678 sld_my = n umpy.append(sld_my, _sld_my)679 sld_mz = n umpy.append(sld_mz, _sld_mz)673 pos_x = np.append(pos_x, _pos_x) 674 pos_y = np.append(pos_y, _pos_y) 675 pos_z = np.append(pos_z, _pos_z) 676 sld_n = np.append(sld_n, _sld_n) 677 sld_mx = np.append(sld_mx, _sld_mx) 678 sld_my = np.append(sld_my, _sld_my) 679 sld_mz = np.append(sld_mz, _sld_mz) 680 680 try: 681 681 _vol_pix = float(toks[7]) 682 vol_pix = n umpy.append(vol_pix, _vol_pix)682 vol_pix = np.append(vol_pix, _vol_pix) 683 683 except: 684 684 vol_pix = None … … 714 714 sld_n = data.sld_n 715 715 if sld_n == None: 716 sld_n = n umpy.zeros(length)716 sld_n = np.zeros(length) 717 717 sld_mx = data.sld_mx 718 718 if sld_mx == None: 719 sld_mx = n umpy.zeros(length)720 sld_my = n umpy.zeros(length)721 sld_mz = n umpy.zeros(length)719 sld_mx = np.zeros(length) 720 sld_my = np.zeros(length) 721 sld_mz = np.zeros(length) 722 722 else: 723 723 sld_my = data.sld_my … … 895 895 if self.is_data: 896 896 # For data, put the value to only the pixels w non-zero M 897 is_nonzero = (n umpy.fabs(self.sld_mx) +898 n umpy.fabs(self.sld_my) +899 n umpy.fabs(self.sld_mz)).nonzero()900 self.sld_n = n umpy.zeros(len(self.pos_x))897 is_nonzero = (np.fabs(self.sld_mx) + 898 np.fabs(self.sld_my) + 899 np.fabs(self.sld_mz)).nonzero() 900 self.sld_n = np.zeros(len(self.pos_x)) 901 901 if len(self.sld_n[is_nonzero]) > 0: 902 902 self.sld_n[is_nonzero] = sld_n … … 905 905 else: 906 906 # For non-data, put the value to all the pixels 907 self.sld_n = n umpy.ones(len(self.pos_x)) * sld_n907 self.sld_n = np.ones(len(self.pos_x)) * sld_n 908 908 else: 909 909 self.sld_n = sld_n … … 914 914 """ 915 915 if sld_mx.__class__.__name__ == 'float': 916 self.sld_mx = n umpy.ones(len(self.pos_x)) * sld_mx916 self.sld_mx = np.ones(len(self.pos_x)) * sld_mx 917 917 else: 918 918 self.sld_mx = sld_mx 919 919 if sld_my.__class__.__name__ == 'float': 920 self.sld_my = n umpy.ones(len(self.pos_x)) * sld_my920 self.sld_my = np.ones(len(self.pos_x)) * sld_my 921 921 else: 922 922 self.sld_my = sld_my 923 923 if sld_mz.__class__.__name__ == 'float': 924 self.sld_mz = n umpy.ones(len(self.pos_x)) * sld_mz924 self.sld_mz = np.ones(len(self.pos_x)) * sld_mz 925 925 else: 926 926 self.sld_mz = sld_mz 927 927 928 sld_m = n umpy.sqrt(sld_mx * sld_mx + sld_my * sld_my + \928 sld_m = np.sqrt(sld_mx * sld_mx + sld_my * sld_my + \ 929 929 sld_mz * sld_mz) 930 930 self.sld_m = sld_m … … 938 938 return 939 939 if symbol.__class__.__name__ == 'str': 940 self.pix_symbol = n umpy.repeat(symbol, len(self.sld_n))940 self.pix_symbol = np.repeat(symbol, len(self.sld_n)) 941 941 else: 942 942 self.pix_symbol = symbol … … 952 952 self.vol_pix = vol 953 953 elif vol.__class__.__name__.count('float') > 0: 954 self.vol_pix = n umpy.repeat(vol, len(self.sld_n))954 self.vol_pix = np.repeat(vol, len(self.sld_n)) 955 955 else: 956 956 self.vol_pix = None … … 995 995 for x_pos in self.pos_x: 996 996 if xpos_pre != x_pos: 997 self.xstepsize = n umpy.fabs(x_pos - xpos_pre)997 self.xstepsize = np.fabs(x_pos - xpos_pre) 998 998 break 999 999 for y_pos in self.pos_y: 1000 1000 if ypos_pre != y_pos: 1001 self.ystepsize = n umpy.fabs(y_pos - ypos_pre)1001 self.ystepsize = np.fabs(y_pos - ypos_pre) 1002 1002 break 1003 1003 for z_pos in self.pos_z: 1004 1004 if zpos_pre != z_pos: 1005 self.zstepsize = n umpy.fabs(z_pos - zpos_pre)1005 self.zstepsize = np.fabs(z_pos - zpos_pre) 1006 1006 break 1007 1007 #default pix volume 1008 self.vol_pix = n umpy.ones(len(self.pos_x))1008 self.vol_pix = np.ones(len(self.pos_x)) 1009 1009 vol = self.xstepsize * self.ystepsize * self.zstepsize 1010 1010 self.set_pixel_volumes(vol) … … 1073 1073 y2 = output.pos_y+output.sld_my/max_m * gap 1074 1074 z2 = output.pos_z+output.sld_mz/max_m * gap 1075 x_arrow = n umpy.column_stack((output.pos_x, x2))1076 y_arrow = n umpy.column_stack((output.pos_y, y2))1077 z_arrow = n umpy.column_stack((output.pos_z, z2))1075 x_arrow = np.column_stack((output.pos_x, x2)) 1076 y_arrow = np.column_stack((output.pos_y, y2)) 1077 z_arrow = np.column_stack((output.pos_z, z2)) 1078 1078 unit_x2 = output.sld_mx / max_m 1079 1079 unit_y2 = output.sld_my / max_m 1080 1080 unit_z2 = output.sld_mz / max_m 1081 color_x = n umpy.fabs(unit_x2 * 0.8)1082 color_y = n umpy.fabs(unit_y2 * 0.8)1083 color_z = n umpy.fabs(unit_z2 * 0.8)1084 colors = n umpy.column_stack((color_x, color_y, color_z))1081 color_x = np.fabs(unit_x2 * 0.8) 1082 color_y = np.fabs(unit_y2 * 0.8) 1083 color_z = np.fabs(unit_z2 * 0.8) 1084 colors = np.column_stack((color_x, color_y, color_z)) 1085 1085 plt.show() 1086 1086 … … 1105 1105 model = GenSAS() 1106 1106 model.set_sld_data(foutput.output) 1107 x = n umpy.arange(1000)/10000. + 1e-51108 y = n umpy.arange(1000)/10000. + 1e-51109 i = n umpy.zeros(1000)1107 x = np.arange(1000)/10000. + 1e-5 1108 y = np.arange(1000)/10000. + 1e-5 1109 i = np.zeros(1000) 1110 1110 model.runXY([x, y, i]) 1111 1111 -
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/manipulations.py
rb2b36932 red2276f 14 14 #TODO: copy the meta data from the 2D object to the resulting 1D object 15 15 import math 16 import numpy 16 import numpy as np 17 17 18 18 #from data_info import plottable_2D … … 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 new_x = n umpy.tile(data2d.x_bins, (len(data2d.y_bins), 1))85 new_y = n umpy.tile(data2d.y_bins, (len(data2d.x_bins), 1))84 new_x = np.tile(data2d.x_bins, (len(data2d.y_bins), 1)) 85 new_y = np.tile(data2d.y_bins, (len(data2d.x_bins), 1)) 86 86 new_y = new_y.swapaxes(0, 1) 87 87 … … 89 89 qx_data = new_x.flatten() 90 90 qy_data = new_y.flatten() 91 q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 92 if data2d.err_data == None or numpy.any(data2d.err_data <= 0): 93 new_err_data = numpy.sqrt(numpy.abs(new_data)) 91 q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 92 if data2d.err_data == None or np.any(data2d.err_data <= 0): 93 new_err_data = np.sqrt(np.abs(new_data)) 94 94 95 else: 95 96 new_err_data = data2d.err_data.flatten() 96 mask = n umpy.ones(len(new_data), dtype=bool)97 mask = np.ones(len(new_data), dtype=bool) 97 98 98 99 #TODO: make sense of the following two lines... … … 149 150 150 151 # Get data 151 data = data2D.data[n umpy.isfinite(data2D.data)]152 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]153 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]154 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]152 data = data2D.data[np.isfinite(data2D.data)] 153 err_data = data2D.err_data[np.isfinite(data2D.data)] 154 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 155 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 155 156 156 157 # Build array of Q intervals … … 170 171 raise RuntimeError, "_Slab._avg: unrecognized axis %s" % str(maj) 171 172 172 x = n umpy.zeros(nbins)173 y = n umpy.zeros(nbins)174 err_y = n umpy.zeros(nbins)175 y_counts = n umpy.zeros(nbins)173 x = np.zeros(nbins) 174 y = np.zeros(nbins) 175 err_y = np.zeros(nbins) 176 y_counts = np.zeros(nbins) 176 177 177 178 # Average pixelsize in q space … … 225 226 y = y / y_counts 226 227 x = x / y_counts 227 idx = (n umpy.isfinite(y) & numpy.isfinite(x))228 idx = (np.isfinite(y) & np.isfinite(x)) 228 229 229 230 if not idx.any(): … … 304 305 raise RuntimeError, msg 305 306 # Get data 306 data = data2D.data[n umpy.isfinite(data2D.data)]307 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]308 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]309 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]307 data = data2D.data[np.isfinite(data2D.data)] 308 err_data = data2D.err_data[np.isfinite(data2D.data)] 309 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 310 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 310 311 311 312 y = 0.0 … … 414 415 """ 415 416 # Get data W/ finite values 416 data = data2D.data[n umpy.isfinite(data2D.data)]417 q_data = data2D.q_data[n umpy.isfinite(data2D.data)]418 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]419 mask_data = data2D.mask[n umpy.isfinite(data2D.data)]417 data = data2D.data[np.isfinite(data2D.data)] 418 q_data = data2D.q_data[np.isfinite(data2D.data)] 419 err_data = data2D.err_data[np.isfinite(data2D.data)] 420 mask_data = data2D.mask[np.isfinite(data2D.data)] 420 421 421 422 dq_data = None … … 448 449 dq_overlap_y *= dq_overlap_y 449 450 450 dq_overlap = n umpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)451 dq_overlap = np.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 451 452 # Final protection of dq 452 453 if dq_overlap < 0: 453 454 dq_overlap = y_min 454 dqx_data = data2D.dqx_data[n umpy.isfinite(data2D.data)]455 dqy_data = data2D.dqy_data[n umpy.isfinite(data2D.data)] - dq_overlap455 dqx_data = data2D.dqx_data[np.isfinite(data2D.data)] 456 dqy_data = data2D.dqy_data[np.isfinite(data2D.data)] - dq_overlap 456 457 # def; dqx_data = dq_r dqy_data = dq_phi 457 458 # Convert dq 2D to 1D here 458 459 dqx = dqx_data * dqx_data 459 460 dqy = dqy_data * dqy_data 460 dq_data = n umpy.add(dqx, dqy)461 dq_data = n umpy.sqrt(dq_data)462 463 #q_data_max = n umpy.max(q_data)461 dq_data = np.add(dqx, dqy) 462 dq_data = np.sqrt(dq_data) 463 464 #q_data_max = np.max(q_data) 464 465 if len(data2D.q_data) == None: 465 466 msg = "Circular averaging: invalid q_data: %g" % data2D.q_data … … 469 470 nbins = int(math.ceil((self.r_max - self.r_min) / self.bin_width)) 470 471 471 x = n umpy.zeros(nbins)472 y = n umpy.zeros(nbins)473 err_y = n umpy.zeros(nbins)474 err_x = n umpy.zeros(nbins)475 y_counts = n umpy.zeros(nbins)472 x = np.zeros(nbins) 473 y = np.zeros(nbins) 474 err_y = np.zeros(nbins) 475 err_x = np.zeros(nbins) 476 y_counts = np.zeros(nbins) 476 477 477 478 for npt in range(len(data)): … … 527 528 528 529 err_y = err_y / y_counts 529 err_y[err_y == 0] = n umpy.average(err_y)530 err_y[err_y == 0] = np.average(err_y) 530 531 y = y / y_counts 531 532 x = x / y_counts 532 idx = (n umpy.isfinite(y)) & (numpy.isfinite(x))533 idx = (np.isfinite(y)) & (np.isfinite(x)) 533 534 534 535 if err_x != None: … … 585 586 586 587 # Get data 587 data = data2D.data[n umpy.isfinite(data2D.data)]588 q_data = data2D.q_data[n umpy.isfinite(data2D.data)]589 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]590 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]591 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]588 data = data2D.data[np.isfinite(data2D.data)] 589 q_data = data2D.q_data[np.isfinite(data2D.data)] 590 err_data = data2D.err_data[np.isfinite(data2D.data)] 591 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 592 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 592 593 593 594 # Set space for 1d outputs 594 phi_bins = n umpy.zeros(self.nbins_phi)595 phi_counts = n umpy.zeros(self.nbins_phi)596 phi_values = n umpy.zeros(self.nbins_phi)597 phi_err = n umpy.zeros(self.nbins_phi)595 phi_bins = np.zeros(self.nbins_phi) 596 phi_counts = np.zeros(self.nbins_phi) 597 phi_values = np.zeros(self.nbins_phi) 598 phi_err = np.zeros(self.nbins_phi) 598 599 599 600 # Shift to apply to calculated phi values in order … … 636 637 phi_values[i] = 2.0 * math.pi / self.nbins_phi * (1.0 * i) 637 638 638 idx = (n umpy.isfinite(phi_bins))639 idx = (np.isfinite(phi_bins)) 639 640 640 641 if not idx.any(): … … 769 770 770 771 # Get the all data & info 771 data = data2D.data[n umpy.isfinite(data2D.data)]772 q_data = data2D.q_data[n umpy.isfinite(data2D.data)]773 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]774 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]775 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]772 data = data2D.data[np.isfinite(data2D.data)] 773 q_data = data2D.q_data[np.isfinite(data2D.data)] 774 err_data = data2D.err_data[np.isfinite(data2D.data)] 775 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 776 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 776 777 dq_data = None 777 778 … … 803 804 dq_overlap_y *= dq_overlap_y 804 805 805 dq_overlap = n umpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)806 dq_overlap = np.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 806 807 if dq_overlap < 0: 807 808 dq_overlap = y_min 808 dqx_data = data2D.dqx_data[n umpy.isfinite(data2D.data)]809 dqy_data = data2D.dqy_data[n umpy.isfinite(data2D.data)] - dq_overlap809 dqx_data = data2D.dqx_data[np.isfinite(data2D.data)] 810 dqy_data = data2D.dqy_data[np.isfinite(data2D.data)] - dq_overlap 810 811 # def; dqx_data = dq_r dqy_data = dq_phi 811 812 # Convert dq 2D to 1D here 812 813 dqx = dqx_data * dqx_data 813 814 dqy = dqy_data * dqy_data 814 dq_data = n umpy.add(dqx, dqy)815 dq_data = n umpy.sqrt(dq_data)815 dq_data = np.add(dqx, dqy) 816 dq_data = np.sqrt(dq_data) 816 817 817 818 #set space for 1d outputs 818 x = n umpy.zeros(self.nbins)819 y = n umpy.zeros(self.nbins)820 y_err = n umpy.zeros(self.nbins)821 x_err = n umpy.zeros(self.nbins)822 y_counts = n umpy.zeros(self.nbins)819 x = np.zeros(self.nbins) 820 y = np.zeros(self.nbins) 821 y_err = np.zeros(self.nbins) 822 x_err = np.zeros(self.nbins) 823 y_counts = np.zeros(self.nbins) 823 824 824 825 # Get the min and max into the region: 0 <= phi < 2Pi … … 923 924 #x[i] = math.sqrt((r_inner * r_inner + r_outer * r_outer) / 2) 924 925 x[i] = x[i] / y_counts[i] 925 y_err[y_err == 0] = n umpy.average(y_err)926 idx = (n umpy.isfinite(y) & numpy.isfinite(y_err))926 y_err[y_err == 0] = np.average(y_err) 927 idx = (np.isfinite(y) & np.isfinite(y_err)) 927 928 if x_err != None: 928 929 d_x = x_err[idx] / y_counts[idx] … … 1012 1013 qx_data = data2D.qx_data 1013 1014 qy_data = data2D.qy_data 1014 q_data = n umpy.sqrt(qx_data * qx_data + qy_data * qy_data)1015 q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 1015 1016 1016 1017 # check whether or not the data point is inside ROI … … 1113 1114 1114 1115 # get phi from data 1115 phi_data = n umpy.arctan2(qy_data, qx_data)1116 phi_data = np.arctan2(qy_data, qx_data) 1116 1117 1117 1118 # Get the min and max into the region: -pi <= phi < Pi -
src/sas/sascalc/dataloader/readers/IgorReader.py
rb699768 red2276f 13 13 ############################################################################# 14 14 import os 15 import numpy 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 … … 118 93 size_x = i_tot_row # 192#128 119 94 size_y = i_tot_row # 192#128 120 output.data = numpy.zeros([size_x, size_y]) 121 output.err_data = numpy.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 95 output.data = np.zeros([size_x, size_y]) 96 output.err_data = np.zeros([size_x, size_y]) 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/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
r463e7ffc r9c0f3c17 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 … … 81 81 output.detector.append(detector) 82 82 83 output.data = n umpy.zeros([size_x,size_y])84 output.err_data = n umpy.zeros([size_x, size_y])83 output.data = np.zeros([size_x,size_y]) 84 output.err_data = np.zeros([size_x, size_y]) 85 85 86 86 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
r463e7ffc r9c0f3c17 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 … … 58 58 59 59 # Initiazed the output data object 60 output.data = n umpy.zeros([im.size[0], im.size[1]])61 output.err_data = n umpy.zeros([im.size[0], im.size[1]])62 output.mask = n umpy.ones([im.size[0], im.size[1]], dtype=bool)60 output.data = np.zeros([im.size[0], im.size[1]]) 61 output.err_data = np.zeros([im.size[0], im.size[1]]) 62 output.mask = np.ones([im.size[0], im.size[1]], dtype=bool) 63 63 64 64 # Initialize … … 96 96 output.x_bins = x_vals 97 97 output.y_bins = y_vals 98 output.qx_data = n umpy.array(x_vals)99 output.qy_data = n umpy.array(y_vals)98 output.qx_data = np.array(x_vals) 99 output.qy_data = np.array(y_vals) 100 100 output.xmin = 0 101 101 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
r463e7ffc r9c0f3c17 7 7 """ 8 8 9 import numpy 9 import numpy as np 10 10 import sys 11 11 import math … … 191 191 #import numpy 192 192 if name == 'x': 193 out = n umpy.ones(self.get_nx())193 out = np.ones(self.get_nx()) 194 194 self.get_x(out) 195 195 return out 196 196 elif name == 'y': 197 out = n umpy.ones(self.get_ny())197 out = np.ones(self.get_ny()) 198 198 self.get_y(out) 199 199 return out 200 200 elif name == 'err': 201 out = n umpy.ones(self.get_nerr())201 out = np.ones(self.get_nerr()) 202 202 self.get_err(out) 203 203 return out … … 327 327 raise RuntimeError, msg 328 328 329 p = n umpy.ones(nfunc)329 p = np.ones(nfunc) 330 330 t_0 = time.time() 331 331 out, cov_x, _, _, _ = optimize.leastsq(self.residuals, p, full_output=1) … … 343 343 344 344 if cov_x is None: 345 cov_x = n umpy.ones([nfunc, nfunc])345 cov_x = np.ones([nfunc, nfunc]) 346 346 cov_x *= math.fabs(chisqr) 347 347 return out, cov_x … … 360 360 raise RuntimeError, msg 361 361 362 p = n umpy.ones(nfunc)362 p = np.ones(nfunc) 363 363 t_0 = time.time() 364 364 out, cov_x, _, _, _ = optimize.leastsq(self.pr_residuals, p, full_output=1) … … 437 437 """ 438 438 # Note: To make sure an array is contiguous: 439 # blah = n umpy.ascontiguousarray(blah_original)439 # blah = np.ascontiguousarray(blah_original) 440 440 # ... before passing it to C 441 441 … … 458 458 nfunc += 1 459 459 460 a = n umpy.zeros([npts + nq, nfunc])461 b = n umpy.zeros(npts + nq)462 err = n umpy.zeros([nfunc, nfunc])460 a = np.zeros([npts + nq, nfunc]) 461 b = np.zeros(npts + nq) 462 err = np.zeros([nfunc, nfunc]) 463 463 464 464 # Construct the a matrix and b vector that represent the problem … … 478 478 self.chi2 = chi2 479 479 480 inv_cov = n umpy.zeros([nfunc, nfunc])480 inv_cov = np.zeros([nfunc, nfunc]) 481 481 # Get the covariance matrix, defined as inv_cov = a_transposed * a 482 482 self._get_invcov_matrix(nfunc, nr, a, inv_cov) … … 492 492 493 493 try: 494 cov = n umpy.linalg.pinv(inv_cov)494 cov = np.linalg.pinv(inv_cov) 495 495 err = math.fabs(chi2 / float(npts - nfunc)) * cov 496 496 except: … … 507 507 self.background = c[0] 508 508 509 err_0 = n umpy.zeros([nfunc, nfunc])510 c_0 = n umpy.zeros(nfunc)509 err_0 = np.zeros([nfunc, nfunc]) 510 c_0 = np.zeros(nfunc) 511 511 512 512 for i in range(nfunc_0): … … 664 664 str(self.cov[i][i]))) 665 665 file.write("<r> <Pr> <dPr>\n") 666 r = n umpy.arange(0.0, self.d_max, self.d_max / npts)666 r = np.arange(0.0, self.d_max, self.d_max / npts) 667 667 668 668 for r_i in r: … … 696 696 toks = line.split('=') 697 697 self.nfunc = int(toks[1]) 698 self.out = n umpy.zeros(self.nfunc)699 self.cov = n umpy.zeros([self.nfunc, self.nfunc])698 self.out = np.zeros(self.nfunc) 699 self.cov = np.zeros([self.nfunc, self.nfunc]) 700 700 elif line.startswith('#alpha='): 701 701 toks = line.split('=') -
src/sas/sascalc/pr/num_term.py
r463e7ffc r9c0f3c17 1 1 import math 2 import numpy 2 import numpy as np 3 3 import copy 4 4 import sys … … 154 154 def load(path): 155 155 # Read the data from the data file 156 data_x = n umpy.zeros(0)157 data_y = n umpy.zeros(0)158 data_err = n umpy.zeros(0)156 data_x = np.zeros(0) 157 data_y = np.zeros(0) 158 data_err = np.zeros(0) 159 159 scale = None 160 160 min_err = 0.0 … … 178 178 #err = 0 179 179 180 data_x = n umpy.append(data_x, test_x)181 data_y = n umpy.append(data_y, test_y)182 data_err = n umpy.append(data_err, err)180 data_x = np.append(data_x, test_x) 181 data_y = np.append(data_y, test_y) 182 data_err = np.append(data_err, err) 183 183 except: 184 184 logger.error(sys.exc_value) -
src/sas/sascalc/data_util/calcthread.py
r934ce649 r463e7ffc 8 8 import traceback 9 9 import sys 10 import logging 10 11 11 12 if sys.platform.count("darwin") > 0: … … 21 22 from time import clock 22 23 from time import sleep 24 25 logger = logging.getLogger(__name__) 23 26 24 27 … … 244 247 pass 245 248 import logging 246 logg ing.error(traceback.format_exc())249 logger.error(traceback.format_exc()) 247 250 #print 'CalcThread exception', 248 251 -
src/sas/sascalc/dataloader/loader.py
rb699768 r463e7ffc 32 32 from readers import cansas_reader 33 33 34 logger = logging.getLogger(__name__) 35 34 36 class Registry(ExtensionRegistry): 35 37 """ … … 99 101 msg = "DataLoader couldn't locate DataLoader plugin folder." 100 102 msg += """ "%s" does not exist""" % dir 101 logg ing.warning(msg)103 logger.warning(msg) 102 104 return readers_found 103 105 … … 117 119 msg = "Loader: Error importing " 118 120 msg += "%s\n %s" % (item, sys.exc_value) 119 logg ing.error(msg)121 logger.error(msg) 120 122 121 123 # Process zip files … … 139 141 msg = "Loader: Error importing" 140 142 msg += " %s\n %s" % (mfile, sys.exc_value) 141 logg ing.error(msg)143 logger.error(msg) 142 144 143 145 except: 144 146 msg = "Loader: Error importing " 145 147 msg += " %s\n %s" % (item, sys.exc_value) 146 logg ing.error(msg)148 logger.error(msg) 147 149 148 150 return readers_found … … 190 192 msg = "Loader: Error accessing" 191 193 msg += " Reader in %s\n %s" % (module.__name__, sys.exc_value) 192 logg ing.error(msg)194 logger.error(msg) 193 195 return reader_found 194 196 … … 223 225 msg = "Loader: Error accessing Reader " 224 226 msg += "in %s\n %s" % (loader.__name__, sys.exc_value) 225 logg ing.error(msg)227 logger.error(msg) 226 228 return reader_found 227 229 … … 268 270 msg = "Loader: Error accessing Reader" 269 271 msg += " in %s\n %s" % (module.__name__, sys.exc_value) 270 logg ing.error(msg)272 logger.error(msg) 271 273 return reader_found 272 274 -
src/sas/sascalc/dataloader/readers/associations.py
re5c09cf r463e7ffc 18 18 import logging 19 19 import json 20 21 logger = logging.getLogger(__name__) 20 22 21 23 FILE_NAME = 'defaults.json' … … 67 69 msg = "read_associations: skipping association" 68 70 msg += " for %s\n %s" % (ext.lower(), sys.exc_value) 69 logg ing.error(msg)71 logger.error(msg) 70 72 else: 71 73 print "Could not find reader association settings\n %s [%s]" % (__file__, os.getcwd()) … … 81 83 :param registry_function: function to be called to register each reader 82 84 """ 83 logg ing.info("register_readers is now obsolete: use read_associations()")85 logger.info("register_readers is now obsolete: use read_associations()") 84 86 import abs_reader 85 87 import ascii_reader -
src/sas/sascalc/dataloader/readers/cansas_reader.py
r8434365 r463e7ffc 33 33 import xml.dom.minidom 34 34 from xml.dom.minidom import parseString 35 36 logger = logging.getLogger(__name__) 35 37 36 38 PREPROCESS = "xmlpreprocess" … … 1471 1473 self.errors.add(err_mess) 1472 1474 if optional: 1473 logg ing.info(err_mess)1475 logger.info(err_mess) 1474 1476 else: 1475 1477 raise ValueError, err_mess … … 1480 1482 self.errors.add(err_mess) 1481 1483 if optional: 1482 logg ing.info(err_mess)1484 logger.info(err_mess) 1483 1485 else: 1484 1486 raise ValueError, err_mess -
src/sas/sascalc/dataloader/readers/xml_reader.py
ra235f715 r463e7ffc 18 18 from lxml import etree 19 19 from lxml.builder import E 20 21 logger = logging.getLogger(__name__) 20 22 21 23 PARSER = etree.ETCompatXMLParser(remove_comments=True, remove_pis=False) … … 71 73 self.xmlroot = self.xmldoc.getroot() 72 74 except etree.XMLSyntaxError as xml_error: 73 logg ing.info(xml_error)75 logger.info(xml_error) 74 76 except Exception: 75 77 self.xml = None … … 88 90 self.xmlroot = etree.fromstring(tag_soup) 89 91 except etree.XMLSyntaxError as xml_error: 90 logg ing.info(xml_error)92 logger.info(xml_error) 91 93 except Exception: 92 94 self.xml = None … … 102 104 self.schemadoc = etree.parse(self.schema, parser=PARSER) 103 105 except etree.XMLSyntaxError as xml_error: 104 logg ing.info(xml_error)106 logger.info(xml_error) 105 107 except Exception: 106 108 self.schema = None
Note: See TracChangeset
for help on using the changeset viewer.