Changeset 9a5097c in sasview
- Timestamp:
-
Mar 26, 2017 11:33:16 PM
(7 years ago)
- Author:
- andyfaff
- 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:
- ed2276f
- Parents:
- 9146ed9
- Message:
-
MAINT: import numpy as np
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
-
r1e13b53
|
r9a5097c
|
|
9 | 9 | from distutils.command.build_ext import build_ext |
10 | 10 | from distutils.core import Command |
11 | | import numpy |
| 11 | import numpy as np |
12 | 12 | |
13 | 13 | # Manage version number ###################################### |
… |
… |
|
225 | 225 | ext_modules.append( Extension("sas.sascalc.file_converter.core.bsl_loader", |
226 | 226 | sources = [os.path.join(mydir, "bsl_loader.c")], |
227 | | include_dirs=[numpy.get_include()], |
| 227 | include_dirs=[np.get_include()], |
228 | 228 | ) ) |
229 | 229 | |
-
rc10d9d6c
|
r9a5097c
|
|
30 | 30 | from sas.sasgui.plottools.plottables import Plottable, Graph, Data1D, Theory1D |
31 | 31 | import sys |
32 | | import numpy |
| 32 | import numpy as np |
33 | 33 | |
34 | 34 | |
… |
… |
|
78 | 78 | # Construct a simple graph |
79 | 79 | if False: |
80 | | x = numpy.array([1,2,3,4,5,6],'d') |
81 | | y = numpy.array([4,5,26,5,4,-1],'d') |
82 | | dy = numpy.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) |
| 80 | x = np.array([1,2,3,4,5,6],'d') |
| 81 | y = np.array([4,5,26,5,4,-1],'d') |
| 82 | dy = np.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) |
83 | 83 | else: |
84 | | x = numpy.linspace(0,2.0, 50) |
85 | | y = numpy.sin(2*numpy.pi*x*2.8) |
86 | | dy = numpy.sqrt(100*numpy.abs(y))/100 |
| 84 | x = np.linspace(0,2.0, 50) |
| 85 | y = np.sin(2*np.pi*x*2.8) |
| 86 | dy = np.sqrt(100*np.abs(y))/100 |
87 | 87 | |
88 | 88 | from sas.sasgui.plottools.plottables import Data1D, Theory1D, Chisq , Graph |
-
rd7bb526
|
r9a5097c
|
|
30 | 30 | import sys |
31 | 31 | sys.platform = 'win95' |
32 | | import numpy |
| 32 | import numpy as np |
33 | 33 | |
34 | 34 | |
… |
… |
|
81 | 81 | def sample_graph(): |
82 | 82 | # Construct a simple graph |
83 | | x = numpy.linspace(0,2.0, 50) |
84 | | y = numpy.sin(2*numpy.pi*x*2.8) |
85 | | dy = numpy.sqrt(100*numpy.abs(y))/100 |
| 83 | x = np.linspace(0,2.0, 50) |
| 84 | y = np.sin(2*np.pi*x*2.8) |
| 85 | dy = np.sqrt(100*np.abs(y))/100 |
86 | 86 | |
87 | 87 | data = Data1D(x,y,dy=dy) |
-
rd7bb526
|
r9a5097c
|
|
39 | 39 | from sas.sasgui.plottools.PlotPanel import PlotPanel |
40 | 40 | from sas.sasgui.plottools.plottables import Data1D |
41 | | import sys |
42 | | import numpy |
| 41 | import sys |
| 42 | import numpy as np |
43 | 43 | import random, math |
44 | 44 | |
… |
… |
|
157 | 157 | def _add_data(self, event): |
158 | 158 | data_len = 50 |
159 | | x = numpy.zeros(data_len) |
160 | | y = numpy.zeros(data_len) |
161 | | x2 = numpy.zeros(data_len) |
162 | | y2 = numpy.zeros(data_len) |
163 | | dy2 = numpy.zeros(data_len) |
164 | | x3 = numpy.zeros(data_len) |
165 | | y3 = numpy.zeros(data_len) |
166 | | dy3 = numpy.zeros(data_len) |
| 159 | x = np.zeros(data_len) |
| 160 | y = np.zeros(data_len) |
| 161 | x2 = np.zeros(data_len) |
| 162 | y2 = np.zeros(data_len) |
| 163 | dy2 = np.zeros(data_len) |
| 164 | x3 = np.zeros(data_len) |
| 165 | y3 = np.zeros(data_len) |
| 166 | dy3 = np.zeros(data_len) |
167 | 167 | for i in range(len(x)): |
168 | 168 | x[i] = i |
-
rd7bb526
|
r9a5097c
|
|
40 | 40 | from sas.sasgui.plottools.plottables import Data1D, Theory1D, Data2D |
41 | 41 | import sys,os |
42 | | import numpy |
| 42 | import numpy as np |
43 | 43 | import random, math |
44 | 44 | |
… |
… |
|
226 | 226 | def _add_data(self, event): |
227 | 227 | data_len = 50 |
228 | | x = numpy.zeros(data_len) |
229 | | y = numpy.zeros(data_len) |
230 | | x2 = numpy.zeros(data_len) |
231 | | y2 = numpy.zeros(data_len) |
232 | | dy2 = numpy.zeros(data_len) |
233 | | x3 = numpy.zeros(data_len) |
234 | | y3 = numpy.zeros(data_len) |
235 | | dy3 = numpy.zeros(data_len) |
| 228 | x = np.zeros(data_len) |
| 229 | y = np.zeros(data_len) |
| 230 | x2 = np.zeros(data_len) |
| 231 | y2 = np.zeros(data_len) |
| 232 | dy2 = np.zeros(data_len) |
| 233 | x3 = np.zeros(data_len) |
| 234 | y3 = np.zeros(data_len) |
| 235 | dy3 = np.zeros(data_len) |
236 | 236 | for i in range(len(x)): |
237 | 237 | x[i] = i |
-
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 = numpy.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 = numpy.sqrt(qx**2+qy**2) |
| 152 | q = np.sqrt(qx**2+qy**2) |
153 | 153 | # vectorize the model function runXY |
154 | | v_model = numpy.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 = numpy.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 |
-
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 = numpy.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 = numpy.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 = numpy.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 numpy.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 = numpy.interp(self.wavelength_list, |
| 347 | out = np.interp(self.wavelength_list, |
348 | 348 | self.spectrum[0], |
349 | 349 | self.spectrum[1], |
-
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 = numpy.arange(self.qx_min, self.qx_max, dx_size) |
396 | | y_val = numpy.arange(self.qy_max, self.qy_min, -dy_size) |
397 | | q_1, q_2 = numpy.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 = numpy.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 = numpy.sin(self.gravity_phi) |
896 | | cos_phi = numpy.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 = numpy.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 *= numpy.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 = numpy.arange(detector_pix_nums_x) |
1029 | | detector_ind_y = numpy.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 = numpy.zeros(len(detector_ind_x)) |
1044 | | qy_value = numpy.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 = numpy.min(qx_value) |
1064 | | self.qx_max = numpy.max(qx_value) |
1065 | | self.qy_min = numpy.min(qy_value) |
1066 | | self.qy_max = numpy.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 = numpy.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 = numpy.arctan(plane_dist / det_dist) |
1110 | | qx_value = (2.0 * pi / wavelength) * numpy.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 | |
-
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, numpy.inf] |
83 | | self.details['background'] = ['[1/cm]', 0.0, numpy.inf] |
84 | | self.details['solvent_SLD'] = ['1/A^(2)', -numpy.inf, numpy.inf] |
85 | | self.details['total_volume'] = ['A^(3)', 0.0, numpy.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]', -numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.zeros(length) |
| 255 | self.sld_n = np.zeros(length) |
256 | 256 | |
257 | 257 | if omfdata.mx == None: |
258 | | self.mx = numpy.zeros(length) |
| 258 | self.mx = np.zeros(length) |
259 | 259 | if omfdata.my == None: |
260 | | self.my = numpy.zeros(length) |
| 260 | self.my = np.zeros(length) |
261 | 261 | if omfdata.mz == None: |
262 | | self.mz = numpy.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 = numpy.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 = (numpy.fabs(self.mx) + numpy.fabs(self.my) + |
331 | | numpy.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 = numpy.zeros(0) |
372 | | my = numpy.zeros(0) |
373 | | mz = numpy.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 = numpy.append(mx, _mx) |
392 | | my = numpy.append(my, _my) |
393 | | mz = numpy.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 = numpy.zeros(0) |
504 | | pos_y = numpy.zeros(0) |
505 | | pos_z = numpy.zeros(0) |
506 | | sld_n = numpy.zeros(0) |
507 | | sld_mx = numpy.zeros(0) |
508 | | sld_my = numpy.zeros(0) |
509 | | sld_mz = numpy.zeros(0) |
510 | | vol_pix = numpy.zeros(0) |
511 | | pix_symbol = numpy.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 = numpy.append(pos_x, _pos_x) |
546 | | pos_y = numpy.append(pos_y, _pos_y) |
547 | | pos_z = numpy.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 = numpy.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 = numpy.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 = numpy.append(sld_n, 0.0) |
560 | | sld_mx = numpy.append(sld_mx, 0) |
561 | | sld_my = numpy.append(sld_my, 0) |
562 | | sld_mz = numpy.append(sld_mz, 0) |
563 | | pix_symbol = numpy.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 = numpy.zeros(0) |
633 | | pos_y = numpy.zeros(0) |
634 | | pos_z = numpy.zeros(0) |
635 | | sld_n = numpy.zeros(0) |
636 | | sld_mx = numpy.zeros(0) |
637 | | sld_my = numpy.zeros(0) |
638 | | sld_mz = numpy.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 = numpy.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 = numpy.array(input_f[0]) |
644 | | pos_y = numpy.array(input_f[1]) |
645 | | pos_z = numpy.array(input_f[2]) |
646 | | sld_n = numpy.array(input_f[3]) |
647 | | sld_mx = numpy.array(input_f[4]) |
648 | | sld_my = numpy.array(input_f[5]) |
649 | | sld_mz = numpy.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 = numpy.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 = numpy.append(pos_x, _pos_x) |
672 | | pos_y = numpy.append(pos_y, _pos_y) |
673 | | pos_z = numpy.append(pos_z, _pos_z) |
674 | | sld_n = numpy.append(sld_n, _sld_n) |
675 | | sld_mx = numpy.append(sld_mx, _sld_mx) |
676 | | sld_my = numpy.append(sld_my, _sld_my) |
677 | | sld_mz = numpy.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 = numpy.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 = numpy.zeros(length) |
| 714 | sld_n = np.zeros(length) |
715 | 715 | sld_mx = data.sld_mx |
716 | 716 | if sld_mx == None: |
717 | | sld_mx = numpy.zeros(length) |
718 | | sld_my = numpy.zeros(length) |
719 | | sld_mz = numpy.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 = (numpy.fabs(self.sld_mx) + |
896 | | numpy.fabs(self.sld_my) + |
897 | | numpy.fabs(self.sld_mz)).nonzero() |
898 | | self.sld_n = numpy.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 = numpy.ones(len(self.pos_x)) * sld_n |
| 905 | 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 = numpy.ones(len(self.pos_x)) * sld_mx |
| 914 | 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 = numpy.ones(len(self.pos_x)) * sld_my |
| 918 | 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 = numpy.ones(len(self.pos_x)) * sld_mz |
| 922 | 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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.column_stack((output.pos_x, x2)) |
1074 | | y_arrow = numpy.column_stack((output.pos_y, y2)) |
1075 | | z_arrow = numpy.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 = numpy.fabs(unit_x2 * 0.8) |
1080 | | color_y = numpy.fabs(unit_y2 * 0.8) |
1081 | | color_z = numpy.fabs(unit_z2 * 0.8) |
1082 | | colors = numpy.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 = numpy.arange(1000)/10000. + 1e-5 |
1106 | | y = numpy.arange(1000)/10000. + 1e-5 |
1107 | | i = numpy.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 | |
-
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 = numpy.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 = numpy.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 * numpy.log(X)**2) * Z**2 |
| 75 | # varZ = (Y**2 * varX/X**2 + varY * np.log(X)**2) * Z**2 |
76 | 76 | # return Z,varZ |
77 | 77 | # |
-
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 numpy.isinf(value): |
| 104 | if np.isinf(value): |
105 | 105 | return "inf" if value > 0 else "-inf" |
106 | | if numpy.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 numpy.isnan(uncertainty): |
| 110 | if uncertainty is None or uncertainty <= 0 or np.isnan(uncertainty): |
111 | 111 | return "%g" % value |
112 | | if numpy.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(-numpy.inf,None) == "-inf" |
282 | | assert value_str(numpy.inf,None) == "inf" |
283 | | assert value_str(numpy.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,numpy.NaN) == "-1.23567" |
287 | | assert value_str(-1.23567,-numpy.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,numpy.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(-numpy.inf,None) == "-inf" |
413 | | assert value_str(numpy.inf,None) == "inf" |
414 | | assert value_str(numpy.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,numpy.NaN) == "-1.23567" |
418 | | assert value_str(-1.23567,-numpy.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,numpy.inf) == "-1.2 +/- inf" |
| 422 | assert value_str(-1.23567,np.inf) == "-1.2 +/- inf" |
423 | 423 | |
424 | 424 | def test_default(): |
-
r775e0b7
|
r9a5097c
|
|
9 | 9 | #copyright 2008, University of Tennessee |
10 | 10 | ###################################################################### |
11 | | import numpy |
12 | 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 numpy.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 numpy.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 = numpy.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 = numpy.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 = numpy.searchsorted(q, q_min) |
160 | | last = numpy.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 | |
-
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 numpy.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(numpy.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(numpy.sqrt(self.variance)) |
150 | | if numpy.isscalar(self.x): |
151 | | return format_uncertainty(self.x,numpy.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,numpy.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(numpy.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(numpy.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(numpy.array([a.x]*2),numpy.array([a.variance]*2)) |
296 | | B = Uncertainty(numpy.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. |
-
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 = numpy.asarray(x) |
54 | | self.y = numpy.asarray(y) |
| 53 | self.x = np.asarray(x) |
| 54 | self.y = np.asarray(y) |
55 | 55 | if dx is not None: |
56 | | self.dx = numpy.asarray(dx) |
| 56 | self.dx = np.asarray(dx) |
57 | 57 | if dy is not None: |
58 | | self.dy = numpy.asarray(dy) |
| 58 | self.dy = np.asarray(dy) |
59 | 59 | if dxl is not None: |
60 | | self.dxl = numpy.asarray(dxl) |
| 60 | self.dxl = np.asarray(dxl) |
61 | 61 | if dxw is not None: |
62 | | self.dxw = numpy.asarray(dxw) |
| 62 | self.dxw = np.asarray(dxw) |
63 | 63 | if lam is not None: |
64 | | self.lam = numpy.asarray(lam) |
| 64 | self.lam = np.asarray(lam) |
65 | 65 | if dlam is not None: |
66 | | self.dlam = numpy.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 = numpy.asarray(data) |
112 | | self.qx_data = numpy.asarray(qx_data) |
113 | | self.qy_data = numpy.asarray(qy_data) |
114 | | self.q_data = numpy.asarray(q_data) |
115 | | self.mask = numpy.asarray(mask) |
116 | | self.err_data = numpy.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 = numpy.asarray(dqx_data) |
| 118 | self.dqx_data = np.asarray(dqx_data) |
119 | 119 | if dqy_data is not None: |
120 | | self.dqy_data = numpy.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__ == numpy.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 = numpy.zeros(length) |
755 | | dx = numpy.zeros(length) |
756 | | y = numpy.zeros(length) |
757 | | dy = numpy.zeros(length) |
758 | | lam = numpy.zeros(length) |
759 | | dlam = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.zeros(len(self.x) + len(other.x)) |
901 | | |
902 | | result.x = numpy.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 = numpy.argsort(result.x) |
| 904 | ind = np.argsort(result.x) |
905 | 905 | result.x = result.x[ind] |
906 | | result.y = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.zeros(length) |
973 | | err_data = numpy.zeros(length) |
974 | | qx_data = numpy.zeros(length) |
975 | | qy_data = numpy.zeros(length) |
976 | | q_data = numpy.zeros(length) |
977 | | mask = numpy.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 = numpy.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 = numpy.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(numpy.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 = numpy.zeros(len(self.data)) |
1057 | | result.dqy_data = numpy.zeros(len(self.data)) |
1058 | | for i in range(numpy.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(numpy.size(self.data) + \ |
1121 | | numpy.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 = numpy.zeros(len(self.data) + \ |
1132 | | numpy.size(other.data)) |
1133 | | result.dqy_data = numpy.zeros(len(self.data) + \ |
1134 | | numpy.size(other.data)) |
1135 | | |
1136 | | result.data = numpy.append(self.data, other.data) |
1137 | | result.qx_data = numpy.append(self.qx_data, other.qx_data) |
1138 | | result.qy_data = numpy.append(self.qy_data, other.qy_data) |
1139 | | result.q_data = numpy.append(self.q_data, other.q_data) |
1140 | | result.mask = numpy.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 = numpy.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 = numpy.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 = numpy.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 |
-
rb2b36932
|
r9a5097c
|
|
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 |
… |
… |
|
82 | 82 | if data2d.data == None or data2d.x_bins == None or data2d.y_bins == None: |
83 | 83 | raise ValueError, "Can't convert this data: data=None..." |
84 | | new_x = numpy.tile(data2d.x_bins, (len(data2d.y_bins), 1)) |
85 | | new_y = numpy.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 | else: |
95 | 95 | new_err_data = data2d.err_data.flatten() |
96 | | mask = numpy.ones(len(new_data), dtype=bool) |
| 96 | mask = np.ones(len(new_data), dtype=bool) |
97 | 97 | |
98 | 98 | #TODO: make sense of the following two lines... |
… |
… |
|
149 | 149 | |
150 | 150 | # Get data |
151 | | data = data2D.data[numpy.isfinite(data2D.data)] |
152 | | err_data = data2D.err_data[numpy.isfinite(data2D.data)] |
153 | | qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] |
154 | | qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] |
| 151 | data = data2D.data[np.isfinite(data2D.data)] |
| 152 | err_data = data2D.err_data[np.isfinite(data2D.data)] |
| 153 | qx_data = data2D.qx_data[np.isfinite(data2D.data)] |
| 154 | qy_data = data2D.qy_data[np.isfinite(data2D.data)] |
155 | 155 | |
156 | 156 | # Build array of Q intervals |
… |
… |
|
170 | 170 | raise RuntimeError, "_Slab._avg: unrecognized axis %s" % str(maj) |
171 | 171 | |
172 | | x = numpy.zeros(nbins) |
173 | | y = numpy.zeros(nbins) |
174 | | err_y = numpy.zeros(nbins) |
175 | | y_counts = numpy.zeros(nbins) |
| 172 | x = np.zeros(nbins) |
| 173 | y = np.zeros(nbins) |
| 174 | err_y = np.zeros(nbins) |
| 175 | y_counts = np.zeros(nbins) |
176 | 176 | |
177 | 177 | # Average pixelsize in q space |
… |
… |
|
225 | 225 | y = y / y_counts |
226 | 226 | x = x / y_counts |
227 | | idx = (numpy.isfinite(y) & numpy.isfinite(x)) |
| 227 | idx = (np.isfinite(y) & np.isfinite(x)) |
228 | 228 | |
229 | 229 | if not idx.any(): |
… |
… |
|
304 | 304 | raise RuntimeError, msg |
305 | 305 | # Get data |
306 | | data = data2D.data[numpy.isfinite(data2D.data)] |
307 | | err_data = data2D.err_data[numpy.isfinite(data2D.data)] |
308 | | qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] |
309 | | qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] |
| 306 | data = data2D.data[np.isfinite(data2D.data)] |
| 307 | err_data = data2D.err_data[np.isfinite(data2D.data)] |
| 308 | qx_data = data2D.qx_data[np.isfinite(data2D.data)] |
| 309 | qy_data = data2D.qy_data[np.isfinite(data2D.data)] |
310 | 310 | |
311 | 311 | y = 0.0 |
… |
… |
|
414 | 414 | """ |
415 | 415 | # Get data W/ finite values |
416 | | data = data2D.data[numpy.isfinite(data2D.data)] |
417 | | q_data = data2D.q_data[numpy.isfinite(data2D.data)] |
418 | | err_data = data2D.err_data[numpy.isfinite(data2D.data)] |
419 | | mask_data = data2D.mask[numpy.isfinite(data2D.data)] |
| 416 | data = data2D.data[np.isfinite(data2D.data)] |
| 417 | q_data = data2D.q_data[np.isfinite(data2D.data)] |
| 418 | err_data = data2D.err_data[np.isfinite(data2D.data)] |
| 419 | mask_data = data2D.mask[np.isfinite(data2D.data)] |
420 | 420 | |
421 | 421 | dq_data = None |
… |
… |
|
448 | 448 | dq_overlap_y *= dq_overlap_y |
449 | 449 | |
450 | | dq_overlap = numpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) |
| 450 | dq_overlap = np.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) |
451 | 451 | # Final protection of dq |
452 | 452 | if dq_overlap < 0: |
453 | 453 | dq_overlap = y_min |
454 | | dqx_data = data2D.dqx_data[numpy.isfinite(data2D.data)] |
455 | | dqy_data = data2D.dqy_data[numpy.isfinite(data2D.data)] - dq_overlap |
| 454 | dqx_data = data2D.dqx_data[np.isfinite(data2D.data)] |
| 455 | dqy_data = data2D.dqy_data[np.isfinite(data2D.data)] - dq_overlap |
456 | 456 | # def; dqx_data = dq_r dqy_data = dq_phi |
457 | 457 | # Convert dq 2D to 1D here |
458 | 458 | dqx = dqx_data * dqx_data |
459 | 459 | dqy = dqy_data * dqy_data |
460 | | dq_data = numpy.add(dqx, dqy) |
461 | | dq_data = numpy.sqrt(dq_data) |
462 | | |
463 | | #q_data_max = numpy.max(q_data) |
| 460 | dq_data = np.add(dqx, dqy) |
| 461 | dq_data = np.sqrt(dq_data) |
| 462 | |
| 463 | #q_data_max = np.max(q_data) |
464 | 464 | if len(data2D.q_data) == None: |
465 | 465 | msg = "Circular averaging: invalid q_data: %g" % data2D.q_data |
… |
… |
|
469 | 469 | nbins = int(math.ceil((self.r_max - self.r_min) / self.bin_width)) |
470 | 470 | |
471 | | x = numpy.zeros(nbins) |
472 | | y = numpy.zeros(nbins) |
473 | | err_y = numpy.zeros(nbins) |
474 | | err_x = numpy.zeros(nbins) |
475 | | y_counts = numpy.zeros(nbins) |
| 471 | x = np.zeros(nbins) |
| 472 | y = np.zeros(nbins) |
| 473 | err_y = np.zeros(nbins) |
| 474 | err_x = np.zeros(nbins) |
| 475 | y_counts = np.zeros(nbins) |
476 | 476 | |
477 | 477 | for npt in range(len(data)): |
… |
… |
|
527 | 527 | |
528 | 528 | err_y = err_y / y_counts |
529 | | err_y[err_y == 0] = numpy.average(err_y) |
| 529 | err_y[err_y == 0] = np.average(err_y) |
530 | 530 | y = y / y_counts |
531 | 531 | x = x / y_counts |
532 | | idx = (numpy.isfinite(y)) & (numpy.isfinite(x)) |
| 532 | idx = (np.isfinite(y)) & (np.isfinite(x)) |
533 | 533 | |
534 | 534 | if err_x != None: |
… |
… |
|
585 | 585 | |
586 | 586 | # Get data |
587 | | data = data2D.data[numpy.isfinite(data2D.data)] |
588 | | q_data = data2D.q_data[numpy.isfinite(data2D.data)] |
589 | | err_data = data2D.err_data[numpy.isfinite(data2D.data)] |
590 | | qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] |
591 | | qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] |
| 587 | data = data2D.data[np.isfinite(data2D.data)] |
| 588 | q_data = data2D.q_data[np.isfinite(data2D.data)] |
| 589 | err_data = data2D.err_data[np.isfinite(data2D.data)] |
| 590 | qx_data = data2D.qx_data[np.isfinite(data2D.data)] |
| 591 | qy_data = data2D.qy_data[np.isfinite(data2D.data)] |
592 | 592 | |
593 | 593 | # Set space for 1d outputs |
594 | | phi_bins = numpy.zeros(self.nbins_phi) |
595 | | phi_counts = numpy.zeros(self.nbins_phi) |
596 | | phi_values = numpy.zeros(self.nbins_phi) |
597 | | phi_err = numpy.zeros(self.nbins_phi) |
| 594 | phi_bins = np.zeros(self.nbins_phi) |
| 595 | phi_counts = np.zeros(self.nbins_phi) |
| 596 | phi_values = np.zeros(self.nbins_phi) |
| 597 | phi_err = np.zeros(self.nbins_phi) |
598 | 598 | |
599 | 599 | # Shift to apply to calculated phi values in order |
… |
… |
|
636 | 636 | phi_values[i] = 2.0 * math.pi / self.nbins_phi * (1.0 * i) |
637 | 637 | |
638 | | idx = (numpy.isfinite(phi_bins)) |
| 638 | idx = (np.isfinite(phi_bins)) |
639 | 639 | |
640 | 640 | if not idx.any(): |
… |
… |
|
769 | 769 | |
770 | 770 | # Get the all data & info |
771 | | data = data2D.data[numpy.isfinite(data2D.data)] |
772 | | q_data = data2D.q_data[numpy.isfinite(data2D.data)] |
773 | | err_data = data2D.err_data[numpy.isfinite(data2D.data)] |
774 | | qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] |
775 | | qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] |
| 771 | data = data2D.data[np.isfinite(data2D.data)] |
| 772 | q_data = data2D.q_data[np.isfinite(data2D.data)] |
| 773 | err_data = data2D.err_data[np.isfinite(data2D.data)] |
| 774 | qx_data = data2D.qx_data[np.isfinite(data2D.data)] |
| 775 | qy_data = data2D.qy_data[np.isfinite(data2D.data)] |
776 | 776 | dq_data = None |
777 | 777 | |
… |
… |
|
803 | 803 | dq_overlap_y *= dq_overlap_y |
804 | 804 | |
805 | | dq_overlap = numpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) |
| 805 | dq_overlap = np.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) |
806 | 806 | if dq_overlap < 0: |
807 | 807 | dq_overlap = y_min |
808 | | dqx_data = data2D.dqx_data[numpy.isfinite(data2D.data)] |
809 | | dqy_data = data2D.dqy_data[numpy.isfinite(data2D.data)] - dq_overlap |
| 808 | dqx_data = data2D.dqx_data[np.isfinite(data2D.data)] |
| 809 | dqy_data = data2D.dqy_data[np.isfinite(data2D.data)] - dq_overlap |
810 | 810 | # def; dqx_data = dq_r dqy_data = dq_phi |
811 | 811 | # Convert dq 2D to 1D here |
812 | 812 | dqx = dqx_data * dqx_data |
813 | 813 | dqy = dqy_data * dqy_data |
814 | | dq_data = numpy.add(dqx, dqy) |
815 | | dq_data = numpy.sqrt(dq_data) |
| 814 | dq_data = np.add(dqx, dqy) |
| 815 | dq_data = np.sqrt(dq_data) |
816 | 816 | |
817 | 817 | #set space for 1d outputs |
818 | | x = numpy.zeros(self.nbins) |
819 | | y = numpy.zeros(self.nbins) |
820 | | y_err = numpy.zeros(self.nbins) |
821 | | x_err = numpy.zeros(self.nbins) |
822 | | y_counts = numpy.zeros(self.nbins) |
| 818 | x = np.zeros(self.nbins) |
| 819 | y = np.zeros(self.nbins) |
| 820 | y_err = np.zeros(self.nbins) |
| 821 | x_err = np.zeros(self.nbins) |
| 822 | y_counts = np.zeros(self.nbins) |
823 | 823 | |
824 | 824 | # Get the min and max into the region: 0 <= phi < 2Pi |
… |
… |
|
923 | 923 | #x[i] = math.sqrt((r_inner * r_inner + r_outer * r_outer) / 2) |
924 | 924 | x[i] = x[i] / y_counts[i] |
925 | | y_err[y_err == 0] = numpy.average(y_err) |
926 | | idx = (numpy.isfinite(y) & numpy.isfinite(y_err)) |
| 925 | y_err[y_err == 0] = np.average(y_err) |
| 926 | idx = (np.isfinite(y) & np.isfinite(y_err)) |
927 | 927 | if x_err != None: |
928 | 928 | d_x = x_err[idx] / y_counts[idx] |
… |
… |
|
1012 | 1012 | qx_data = data2D.qx_data |
1013 | 1013 | qy_data = data2D.qy_data |
1014 | | q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) |
| 1014 | q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) |
1015 | 1015 | |
1016 | 1016 | # check whether or not the data point is inside ROI |
… |
… |
|
1113 | 1113 | |
1114 | 1114 | # get phi from data |
1115 | | phi_data = numpy.arctan2(qy_data, qx_data) |
| 1115 | phi_data = np.arctan2(qy_data, qx_data) |
1116 | 1116 | |
1117 | 1117 | # Get the min and max into the region: -pi <= phi < Pi |
-
rb699768
|
r9a5097c
|
|
13 | 13 | ############################################################################# |
14 | 14 | import os |
15 | | import numpy |
| 15 | import numpy as np |
16 | 16 | import math |
17 | 17 | #import logging |
… |
… |
|
118 | 118 | size_x = i_tot_row # 192#128 |
119 | 119 | 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]) |
| 120 | output.data = np.zeros([size_x, size_y]) |
| 121 | output.err_data = np.zeros([size_x, size_y]) |
122 | 122 | |
123 | 123 | #Read Header and 2D data |
-
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 = numpy.zeros(0) |
56 | | y = numpy.zeros(0) |
57 | | dy = numpy.zeros(0) |
58 | | dx = numpy.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 = numpy.append(x, _x) |
207 | | y = numpy.append(y, _y) |
208 | | dy = numpy.append(dy, _dy) |
209 | | dx = numpy.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: |
-
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 = numpy.zeros(0) |
72 | | ty = numpy.zeros(0) |
73 | | tdy = numpy.zeros(0) |
74 | | tdx = numpy.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 = numpy.zeros(0) |
143 | | ty = numpy.zeros(0) |
144 | | tdy = numpy.zeros(0) |
145 | | tdx = numpy.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 = numpy.append(tdy, _dy) |
| 150 | tdy = np.append(tdy, _dy) |
151 | 151 | if has_error_dx == True: |
152 | | tdx = numpy.append(tdx, _dx) |
153 | | tx = numpy.append(tx, _x) |
154 | | ty = numpy.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 = numpy.lexsort((ty, tx)) |
191 | | x = numpy.zeros(len(tx)) |
192 | | y = numpy.zeros(len(ty)) |
193 | | dy = numpy.zeros(len(tdy)) |
194 | | dx = numpy.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 numpy.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 numpy.zeros(len(output.x)) |
| 216 | else np.zeros(len(output.x)) |
217 | 217 | |
218 | 218 | output.xaxis("\\rm{Q}", 'A^{-1}') |
-
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 = numpy.zeros([size_x,size_y]) |
82 | | output.err_data = numpy.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 |
-
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 = numpy.zeros(0) |
55 | | y = numpy.zeros(0) |
56 | | dx = numpy.zeros(0) |
57 | | dy = numpy.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 = numpy.append(x, _x) |
91 | | y = numpy.append(y, _y) |
92 | | dx = numpy.append(dx, _dx) |
93 | | dy = numpy.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 |
-
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 = numpy.array(lines) |
| 200 | lines_array = np.array(lines) |
201 | 201 | |
202 | 202 | # index for lines_array |
203 | | lines_index = numpy.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 = numpy.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 = numpy.zeros(0) |
238 | | dqy_data = numpy.zeros(0) |
239 | | err_data = numpy.ones(row_num) |
240 | | qz_data = numpy.zeros(row_num) |
241 | | mask = numpy.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 = numpy.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 = numpy.min(qx_data) |
265 | | xmax = numpy.max(qx_data) |
266 | | ymin = numpy.min(qy_data) |
267 | | ymax = numpy.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 = numpy.arange(xmin, xmax + xstep, xstep) |
290 | | y_bins = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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) * \ |
-
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 = numpy.zeros(0) |
63 | | y = numpy.zeros(0) |
64 | | dy = numpy.zeros(0) |
65 | | lam = numpy.zeros(0) |
66 | | dlam = numpy.zeros(0) |
67 | | dx = numpy.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 = numpy.zeros(0) |
71 | | ty = numpy.zeros(0) |
72 | | tdy = numpy.zeros(0) |
73 | | tlam = numpy.zeros(0) |
74 | | tdlam = numpy.zeros(0) |
75 | | tdx = numpy.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 | ] |
-
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 = numpy.zeros([im.size[0], im.size[1]]) |
59 | | output.err_data = numpy.zeros([im.size[0], im.size[1]]) |
60 | | output.mask = numpy.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 = numpy.array(x_vals) |
97 | | output.qy_data = numpy.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 |
-
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 = numpy.ones(len(y)) |
| 164 | self.dy = np.ones(len(y)) |
165 | 165 | else: |
166 | | self.dy = numpy.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 numpy.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 numpy.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 = numpy.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 numpy.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" % (numpy.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 = numpy.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 = numpy.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) & (numpy.isfinite(self.data)) |
314 | | self.num_points = numpy.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 = numpy.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) & (numpy.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 numpy.sum(self.idx) |
| 353 | return np.sum(self.idx) |
354 | 354 | |
355 | 355 | def residuals(self, fn): |
-
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), numpy.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 numpy.sum(self.data.idx) # number of fitted points |
| 196 | return np.sum(self.data.idx) # number of fitted points |
197 | 197 | |
198 | 198 | def nllf(self): |
199 | | return 0.5*numpy.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 = numpy.NaN*numpy.ones(len(param_list)) |
| 297 | R.stderr = np.NaN*np.ones(len(param_list)) |
298 | 298 | else: |
299 | | R.stderr = numpy.hstack((result['stderr'][fitted_index], |
300 | | numpy.NaN*numpy.ones(len(fitness.computed_pars)))) |
301 | | R.pvec = numpy.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 = numpy.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 = numpy.NaN*numpy.ones(len(param_list)) |
306 | | R.pvec = numpy.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars]) |
307 | | R.fitness = numpy.NaN |
| 305 | 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 = numpy.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, numpy.NaN |
| 353 | 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*numpy.asarray(convergence_list)/problem.dof |
361 | | if convergence_list else numpy.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 |
-
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 = numpy.zeros(len(self.x)) |
| 54 | self.dx = np.zeros(len(self.x)) |
55 | 55 | except: |
56 | 56 | print "READ ERROR", line |
-
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, numpy.inf] |
55 | | self.details['background'] = ['',-numpy.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 |
-
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",numpy.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 = numpy.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 = numpy.array([range(0,k),range(1,k+1)]).T |
| 299 | A = np.array([range(0,k),range(1,k+1)]).T |
300 | 300 | _check("depth-1",A) |
301 | 301 | |
302 | | A = numpy.array([range(1,k+1),range(0,k)]).T |
| 302 | A = np.array([range(1,k+1),range(0,k)]).T |
303 | 303 | _check("depth-2",A) |
304 | 304 | |
-
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 = numpy.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 = numpy.asarray(x_out) |
66 | | y_out = numpy.asarray(y_out) |
67 | | dy_out = numpy.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 = numpy.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 = numpy.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 numpy.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 = numpy.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 = numpy.array([self.dscale * math.pow(q, -self.power) for q in x]) |
235 | | p2 = numpy.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 numpy.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 = numpy.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 = numpy.zeros(len(self.data.x)) |
| 306 | fx = np.zeros(len(self.data.x)) |
307 | 307 | |
308 | 308 | # Uncertainty |
309 | | if type(self.data.dy) == numpy.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 = numpy.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 = (numpy.sum(linearized_data.y / sigma2) \ |
335 | | - a * numpy.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.y |
340 | | residuals = numpy.sum(deltas * deltas / sigma2) |
341 | | |
342 | | err = math.fabs(residuals) / numpy.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 = numpy.vstack([linearized_data.x / linearized_data.dy, 1.0 / linearized_data.dy]).T |
346 | | (p, residuals, _, _) = numpy.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 = numpy.zeros(2) |
| 349 | err = np.zeros(2) |
350 | 350 | try: |
351 | | inv_cov = numpy.dot(A.transpose(), A) |
352 | | cov = numpy.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 = numpy.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 = numpy.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 * numpy.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 numpy.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 numpy.zeros(0), numpy.zeros(0) |
| 721 | return np.zeros(0), np.zeros(0) |
722 | 722 | |
723 | 723 | return self._get_extrapolated_data(\ |
-
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 = numpy.ones(len(y)) |
| 164 | self.dy = np.ones(len(y)) |
165 | 165 | else: |
166 | | self.dy = numpy.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 numpy.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 numpy.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 = numpy.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 numpy.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" % (numpy.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 = numpy.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 = numpy.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) & (numpy.isfinite(self.data)) |
314 | | self.num_points = numpy.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 = numpy.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) & (numpy.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 numpy.sum(self.idx) |
| 353 | return np.sum(self.idx) |
354 | 354 | |
355 | 355 | def residuals(self, fn): |
-
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), numpy.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 numpy.sum(self.data.idx) # number of fitted points |
| 195 | return np.sum(self.data.idx) # number of fitted points |
196 | 196 | |
197 | 197 | def nllf(self): |
198 | | return 0.5*numpy.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 = numpy.hstack((result['stderr'][fitted_index], |
296 | | numpy.NaN*numpy.ones(len(fitness.computed_pars)))) |
297 | | R.pvec = numpy.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 = numpy.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 = numpy.NaN*numpy.ones(len(param_list)) |
302 | | R.pvec = numpy.asarray( [p.value for p in fitness.fitted_pars+fitness.computed_pars]) |
303 | | R.fitness = numpy.NaN |
| 301 | 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 = numpy.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*numpy.asarray(convergence_list)/problem.dof |
355 | | if convergence_list else numpy.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 |
-
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 = numpy.zeros(len(self.x)) |
| 54 | self.dx = np.zeros(len(self.x)) |
55 | 55 | except: |
56 | 56 | print "READ ERROR", line |
-
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",numpy.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 = numpy.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 = numpy.array([range(0,k),range(1,k+1)]).T |
| 299 | A = np.array([range(0,k),range(1,k+1)]).T |
300 | 300 | _check("depth-1",A) |
301 | 301 | |
302 | | A = numpy.array([range(1,k+1),range(0,k)]).T |
| 302 | A = np.array([range(1,k+1),range(0,k)]).T |
303 | 303 | _check("depth-2",A) |
304 | 304 | |
-
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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.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 = numpy.zeros([npts + nq, nfunc]) |
459 | | b = numpy.zeros(npts + nq) |
460 | | err = numpy.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 = numpy.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 = numpy.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 = numpy.zeros([nfunc, nfunc]) |
508 | | c_0 = numpy.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 = numpy.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 = numpy.zeros(self.nfunc) |
697 | | self.cov = numpy.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('=') |
-
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 = numpy.zeros(0) |
155 | | data_y = numpy.zeros(0) |
156 | | data_err = numpy.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 = numpy.append(data_x, test_x) |
179 | | data_y = numpy.append(data_y, test_y) |
180 | | data_err = numpy.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) |
-
r68adf86
|
r9a5097c
|
|
3 | 3 | """ |
4 | 4 | import copy |
5 | | import numpy |
| 5 | import numpy as np |
6 | 6 | import math |
7 | 7 | from sas.sascalc.data_util.uncertainty import Uncertainty |
… |
… |
|
81 | 81 | result.dxw = None |
82 | 82 | else: |
83 | | result.dxw = numpy.zeros(len(self.x)) |
| 83 | result.dxw = np.zeros(len(self.x)) |
84 | 84 | if self.dxl == None: |
85 | 85 | result.dxl = None |
86 | 86 | else: |
87 | | result.dxl = numpy.zeros(len(self.x)) |
| 87 | result.dxl = np.zeros(len(self.x)) |
88 | 88 | |
89 | 89 | for i in range(len(self.x)): |
… |
… |
|
128 | 128 | result.dlam = None |
129 | 129 | else: |
130 | | result.dlam = numpy.zeros(tot_length) |
| 130 | result.dlam = np.zeros(tot_length) |
131 | 131 | if self.dy == None or other.dy is None: |
132 | 132 | result.dy = None |
133 | 133 | else: |
134 | | result.dy = numpy.zeros(tot_length) |
| 134 | result.dy = np.zeros(tot_length) |
135 | 135 | if self.dx == None or other.dx is None: |
136 | 136 | result.dx = None |
137 | 137 | else: |
138 | | result.dx = numpy.zeros(tot_length) |
| 138 | result.dx = np.zeros(tot_length) |
139 | 139 | if self.dxw == None or other.dxw is None: |
140 | 140 | result.dxw = None |
141 | 141 | else: |
142 | | result.dxw = numpy.zeros(tot_length) |
| 142 | result.dxw = np.zeros(tot_length) |
143 | 143 | if self.dxl == None or other.dxl is None: |
144 | 144 | result.dxl = None |
145 | 145 | else: |
146 | | result.dxl = numpy.zeros(tot_length) |
147 | | |
148 | | result.x = numpy.append(self.x, other.x) |
| 146 | result.dxl = np.zeros(tot_length) |
| 147 | |
| 148 | result.x = np.append(self.x, other.x) |
149 | 149 | #argsorting |
150 | | ind = numpy.argsort(result.x) |
| 150 | ind = np.argsort(result.x) |
151 | 151 | result.x = result.x[ind] |
152 | | result.y = numpy.append(self.y, other.y) |
| 152 | result.y = np.append(self.y, other.y) |
153 | 153 | result.y = result.y[ind] |
154 | | result.lam = numpy.append(self.lam, other.lam) |
| 154 | result.lam = np.append(self.lam, other.lam) |
155 | 155 | result.lam = result.lam[ind] |
156 | 156 | if result.dlam != None: |
157 | | result.dlam = numpy.append(self.dlam, other.dlam) |
| 157 | result.dlam = np.append(self.dlam, other.dlam) |
158 | 158 | result.dlam = result.dlam[ind] |
159 | 159 | if result.dy != None: |
160 | | result.dy = numpy.append(self.dy, other.dy) |
| 160 | result.dy = np.append(self.dy, other.dy) |
161 | 161 | result.dy = result.dy[ind] |
162 | 162 | if result.dx is not None: |
163 | | result.dx = numpy.append(self.dx, other.dx) |
| 163 | result.dx = np.append(self.dx, other.dx) |
164 | 164 | result.dx = result.dx[ind] |
165 | 165 | if result.dxw is not None: |
166 | | result.dxw = numpy.append(self.dxw, other.dxw) |
| 166 | result.dxw = np.append(self.dxw, other.dxw) |
167 | 167 | result.dxw = result.dxw[ind] |
168 | 168 | if result.dxl is not None: |
169 | | result.dxl = numpy.append(self.dxl, other.dxl) |
| 169 | result.dxl = np.append(self.dxl, other.dxl) |
170 | 170 | result.dxl = result.dxl[ind] |
171 | 171 | return result |
… |
… |
|
230 | 230 | result.dxw = None |
231 | 231 | else: |
232 | | result.dxw = numpy.zeros(len(self.x)) |
| 232 | result.dxw = np.zeros(len(self.x)) |
233 | 233 | if self.dxl == None: |
234 | 234 | result.dxl = None |
235 | 235 | else: |
236 | | result.dxl = numpy.zeros(len(self.x)) |
237 | | |
238 | | for i in range(numpy.size(self.x)): |
| 236 | result.dxl = np.zeros(len(self.x)) |
| 237 | |
| 238 | for i in range(np.size(self.x)): |
239 | 239 | result.x[i] = self.x[i] |
240 | 240 | if self.dx is not None and len(self.x) == len(self.dx): |
… |
… |
|
282 | 282 | result.dlam = None |
283 | 283 | else: |
284 | | result.dlam = numpy.zeros(tot_length) |
| 284 | result.dlam = np.zeros(tot_length) |
285 | 285 | if self.dy == None or other.dy is None: |
286 | 286 | result.dy = None |
287 | 287 | else: |
288 | | result.dy = numpy.zeros(tot_length) |
| 288 | result.dy = np.zeros(tot_length) |
289 | 289 | if self.dx == None or other.dx is None: |
290 | 290 | result.dx = None |
291 | 291 | else: |
292 | | result.dx = numpy.zeros(tot_length) |
| 292 | result.dx = np.zeros(tot_length) |
293 | 293 | if self.dxw == None or other.dxw is None: |
294 | 294 | result.dxw = None |
295 | 295 | else: |
296 | | result.dxw = numpy.zeros(tot_length) |
| 296 | result.dxw = np.zeros(tot_length) |
297 | 297 | if self.dxl == None or other.dxl is None: |
298 | 298 | result.dxl = None |
299 | 299 | else: |
300 | | result.dxl = numpy.zeros(tot_length) |
301 | | result.x = numpy.append(self.x, other.x) |
| 300 | result.dxl = np.zeros(tot_length) |
| 301 | result.x = np.append(self.x, other.x) |
302 | 302 | #argsorting |
303 | | ind = numpy.argsort(result.x) |
| 303 | ind = np.argsort(result.x) |
304 | 304 | result.x = result.x[ind] |
305 | | result.y = numpy.append(self.y, other.y) |
| 305 | result.y = np.append(self.y, other.y) |
306 | 306 | result.y = result.y[ind] |
307 | | result.lam = numpy.append(self.lam, other.lam) |
| 307 | result.lam = np.append(self.lam, other.lam) |
308 | 308 | result.lam = result.lam[ind] |
309 | 309 | if result.dy != None: |
310 | | result.dy = numpy.append(self.dy, other.dy) |
| 310 | result.dy = np.append(self.dy, other.dy) |
311 | 311 | result.dy = result.dy[ind] |
312 | 312 | if result.dx is not None: |
313 | | result.dx = numpy.append(self.dx, other.dx) |
| 313 | result.dx = np.append(self.dx, other.dx) |
314 | 314 | result.dx = result.dx[ind] |
315 | 315 | if result.dxw is not None: |
316 | | result.dxw = numpy.append(self.dxw, other.dxw) |
| 316 | result.dxw = np.append(self.dxw, other.dxw) |
317 | 317 | result.dxw = result.dxw[ind] |
318 | 318 | if result.dxl is not None: |
319 | | result.dxl = numpy.append(self.dxl, other.dxl) |
| 319 | result.dxl = np.append(self.dxl, other.dxl) |
320 | 320 | result.dxl = result.dxl[ind] |
321 | 321 | return result |
… |
… |
|
409 | 409 | result.dqy_data = None |
410 | 410 | else: |
411 | | result.dqx_data = numpy.zeros(len(self.data)) |
412 | | result.dqy_data = numpy.zeros(len(self.data)) |
413 | | for i in range(numpy.size(self.data)): |
| 411 | result.dqx_data = np.zeros(len(self.data)) |
| 412 | result.dqy_data = np.zeros(len(self.data)) |
| 413 | for i in range(np.size(self.data)): |
414 | 414 | result.data[i] = self.data[i] |
415 | 415 | if self.err_data is not None and \ |
416 | | numpy.size(self.data) == numpy.size(self.err_data): |
| 416 | np.size(self.data) == np.size(self.err_data): |
417 | 417 | result.err_data[i] = self.err_data[i] |
418 | 418 | if self.dqx_data is not None: |
… |
… |
|
473 | 473 | result.dqy_data = None |
474 | 474 | else: |
475 | | result.dqx_data = numpy.zeros(len(self.data) + \ |
476 | | numpy.size(other.data)) |
477 | | result.dqy_data = numpy.zeros(len(self.data) + \ |
478 | | numpy.size(other.data)) |
479 | | |
480 | | result.data = numpy.append(self.data, other.data) |
481 | | result.qx_data = numpy.append(self.qx_data, other.qx_data) |
482 | | result.qy_data = numpy.append(self.qy_data, other.qy_data) |
483 | | result.q_data = numpy.append(self.q_data, other.q_data) |
484 | | result.mask = numpy.append(self.mask, other.mask) |
| 475 | result.dqx_data = np.zeros(len(self.data) + \ |
| 476 | np.size(other.data)) |
| 477 | result.dqy_data = np.zeros(len(self.data) + \ |
| 478 | np.size(other.data)) |
| 479 | |
| 480 | result.data = np.append(self.data, other.data) |
| 481 | result.qx_data = np.append(self.qx_data, other.qx_data) |
| 482 | result.qy_data = np.append(self.qy_data, other.qy_data) |
| 483 | result.q_data = np.append(self.q_data, other.q_data) |
| 484 | result.mask = np.append(self.mask, other.mask) |
485 | 485 | if result.err_data is not None: |
486 | | result.err_data = numpy.append(self.err_data, other.err_data) |
| 486 | result.err_data = np.append(self.err_data, other.err_data) |
487 | 487 | if self.dqx_data is not None: |
488 | | result.dqx_data = numpy.append(self.dqx_data, other.dqx_data) |
| 488 | result.dqx_data = np.append(self.dqx_data, other.dqx_data) |
489 | 489 | if self.dqy_data is not None: |
490 | | result.dqy_data = numpy.append(self.dqy_data, other.dqy_data) |
| 490 | result.dqy_data = np.append(self.dqy_data, other.dqy_data) |
491 | 491 | |
492 | 492 | return result |
-
r468c253
|
r9a5097c
|
|
1091 | 1091 | # When inputs are from an external file |
1092 | 1092 | return inputs, outputs |
1093 | | inds = numpy.lexsort((to_be_sort, to_be_sort)) |
| 1093 | inds = np.lexsort((to_be_sort, to_be_sort)) |
1094 | 1094 | for key in outputs.keys(): |
1095 | 1095 | key_list = outputs[key] |
… |
… |
|
1379 | 1379 | return |
1380 | 1380 | if dy == None: |
1381 | | dy = numpy.zeros(len(y)) |
| 1381 | dy = np.zeros(len(y)) |
1382 | 1382 | #plotting |
1383 | 1383 | new_plot = Data1D(x=x, y=y, dy=dy) |
-
r29e872e
|
r9a5097c
|
|
14 | 14 | import sys |
15 | 15 | import math |
16 | | import numpy |
| 16 | import numpy as np |
17 | 17 | import logging |
18 | 18 | from sas.sasgui.plottools.PlotPanel import PlotPanel |
… |
… |
|
288 | 288 | :Param value: float |
289 | 289 | """ |
290 | | idx = (numpy.abs(array - value)).argmin() |
| 290 | idx = (np.abs(array - value)).argmin() |
291 | 291 | return int(idx) # array.flat[idx] |
292 | 292 | |
-
rb2b36932
|
r9a5097c
|
|
14 | 14 | import sys |
15 | 15 | import math |
16 | | import numpy |
| 16 | import numpy as np |
17 | 17 | import logging |
18 | 18 | from sas.sasgui.plottools.PlotPanel import PlotPanel |
… |
… |
|
567 | 567 | """ |
568 | 568 | # Find the best number of bins |
569 | | npt = math.sqrt(len(self.data2D.data[numpy.isfinite(self.data2D.data)])) |
| 569 | npt = math.sqrt(len(self.data2D.data[np.isfinite(self.data2D.data)])) |
570 | 570 | npt = math.floor(npt) |
571 | 571 | from sas.sascalc.dataloader.manipulations import CircularAverage |
-
rd85c194
|
r9a5097c
|
|
1 | 1 | import wx |
2 | 2 | import math |
3 | | import numpy |
| 3 | import numpy as np |
4 | 4 | from sas.sasgui.guiframe.events import NewPlotEvent |
5 | 5 | from sas.sasgui.guiframe.events import StatusEvent |
… |
… |
|
358 | 358 | # # Reset x, y- coordinates if send as parameters |
359 | 359 | if x != None: |
360 | | self.x = numpy.sign(self.x) * math.fabs(x) |
| 360 | self.x = np.sign(self.x) * math.fabs(x) |
361 | 361 | if y != None: |
362 | | self.y = numpy.sign(self.y) * math.fabs(y) |
| 362 | self.y = np.sign(self.y) * math.fabs(y) |
363 | 363 | # # Draw lines and markers |
364 | 364 | self.inner_marker.set(xdata=[0], ydata=[self.y]) |
… |
… |
|
465 | 465 | # # reset x, y -coordinates if given as parameters |
466 | 466 | if x != None: |
467 | | self.x = numpy.sign(self.x) * math.fabs(x) |
| 467 | self.x = np.sign(self.x) * math.fabs(x) |
468 | 468 | if y != None: |
469 | | self.y = numpy.sign(self.y) * math.fabs(y) |
| 469 | self.y = np.sign(self.y) * math.fabs(y) |
470 | 470 | # # draw lines and markers |
471 | 471 | self.inner_marker.set(xdata=[self.x], ydata=[0]) |
-
rd85c194
|
r9a5097c
|
|
24 | 24 | import math |
25 | 25 | import copy |
26 | | import numpy |
| 26 | import numpy as np |
27 | 27 | from sas.sasgui.plottools.PlotPanel import PlotPanel |
28 | 28 | from sas.sasgui.plottools.plottables import Graph |
… |
… |
|
298 | 298 | self.subplot.set_ylim(self.data.ymin, self.data.ymax) |
299 | 299 | self.subplot.set_xlim(self.data.xmin, self.data.xmax) |
300 | | mask = numpy.ones(len(self.data.mask), dtype=bool) |
| 300 | mask = np.ones(len(self.data.mask), dtype=bool) |
301 | 301 | self.data.mask = mask |
302 | 302 | # update mask plot |
… |
… |
|
343 | 343 | self.mask = mask |
344 | 344 | # make temperary data to plot |
345 | | temp_mask = numpy.zeros(len(mask)) |
| 345 | temp_mask = np.zeros(len(mask)) |
346 | 346 | temp_data = copy.deepcopy(self.data) |
347 | 347 | # temp_data default is None |
-
r61780e3
|
r9a5097c
|
|
5 | 5 | import sys |
6 | 6 | import time |
7 | | import numpy |
| 7 | import numpy as np |
8 | 8 | from sas.sascalc.dataloader.data_info import Data1D |
9 | 9 | from sas.sasgui.plottools.PlotPanel import PlotPanel |
… |
… |
|
541 | 541 | theory, _ = theory_list.values()[0] |
542 | 542 | dnames.append(theory.name) |
543 | | ind = numpy.argsort(dnames) |
| 543 | ind = np.argsort(dnames) |
544 | 544 | if len(ind) > 0: |
545 | | val_list = numpy.array(self._data.values())[ind] |
| 545 | val_list = np.array(self._data.values())[ind] |
546 | 546 | for datastate in val_list: |
547 | 547 | data = datastate.data |
-
r0f7c930
|
r9a5097c
|
|
7 | 7 | import sys |
8 | 8 | import os |
9 | | import numpy |
| 9 | import numpy as np |
10 | 10 | #import math |
11 | 11 | import wx.aui as aui |
… |
… |
|
741 | 741 | marker = 'o' |
742 | 742 | m_size = 3.5 |
743 | | sld_tot = (numpy.fabs(sld_mx) + numpy.fabs(sld_my) + \ |
744 | | numpy.fabs(sld_mz) + numpy.fabs(output.sld_n)) |
| 743 | sld_tot = (np.fabs(sld_mx) + np.fabs(sld_my) + \ |
| 744 | np.fabs(sld_mz) + np.fabs(output.sld_n)) |
745 | 745 | is_nonzero = sld_tot > 0.0 |
746 | 746 | is_zero = sld_tot == 0.0 |
… |
… |
|
757 | 757 | pix_symbol = output.pix_symbol[is_nonzero] |
758 | 758 | # II. Plot selective points in color |
759 | | other_color = numpy.ones(len(pix_symbol), dtype='bool') |
| 759 | other_color = np.ones(len(pix_symbol), dtype='bool') |
760 | 760 | for key in color_dic.keys(): |
761 | 761 | chosen_color = pix_symbol == key |
762 | | if numpy.any(chosen_color): |
| 762 | if np.any(chosen_color): |
763 | 763 | other_color = other_color & (chosen_color != True) |
764 | 764 | color = color_dic[key] |
… |
… |
|
767 | 767 | markeredgecolor=color, markersize=m_size, label=key) |
768 | 768 | # III. Plot All others |
769 | | if numpy.any(other_color): |
| 769 | if np.any(other_color): |
770 | 770 | a_name = '' |
771 | 771 | if output.pix_type == 'atom': |
… |
… |
|
795 | 795 | draw magnetic vectors w/arrow |
796 | 796 | """ |
797 | | max_mx = max(numpy.fabs(sld_mx)) |
798 | | max_my = max(numpy.fabs(sld_my)) |
799 | | max_mz = max(numpy.fabs(sld_mz)) |
| 797 | max_mx = max(np.fabs(sld_mx)) |
| 798 | max_my = max(np.fabs(sld_my)) |
| 799 | max_mz = max(np.fabs(sld_mz)) |
800 | 800 | max_m = max(max_mx, max_my, max_mz) |
801 | 801 | try: |
… |
… |
|
812 | 812 | unit_z2 = sld_mz / max_m |
813 | 813 | # 0.8 is for avoiding the color becomes white=(1,1,1)) |
814 | | color_x = numpy.fabs(unit_x2 * 0.8) |
815 | | color_y = numpy.fabs(unit_y2 * 0.8) |
816 | | color_z = numpy.fabs(unit_z2 * 0.8) |
| 814 | color_x = np.fabs(unit_x2 * 0.8) |
| 815 | color_y = np.fabs(unit_y2 * 0.8) |
| 816 | color_z = np.fabs(unit_z2 * 0.8) |
817 | 817 | x2 = pos_x + unit_x2 * max_step |
818 | 818 | y2 = pos_y + unit_y2 * max_step |
819 | 819 | z2 = pos_z + unit_z2 * max_step |
820 | | x_arrow = numpy.column_stack((pos_x, x2)) |
821 | | y_arrow = numpy.column_stack((pos_y, y2)) |
822 | | z_arrow = numpy.column_stack((pos_z, z2)) |
823 | | colors = numpy.column_stack((color_x, color_y, color_z)) |
| 820 | x_arrow = np.column_stack((pos_x, x2)) |
| 821 | y_arrow = np.column_stack((pos_y, y2)) |
| 822 | z_arrow = np.column_stack((pos_z, z2)) |
| 823 | colors = np.column_stack((color_x, color_y, color_z)) |
824 | 824 | arrows = Arrow3D(panel, x_arrow, z_arrow, y_arrow, |
825 | 825 | colors, mutation_scale=10, lw=1, |
… |
… |
|
880 | 880 | if self.is_avg or self.is_avg == None: |
881 | 881 | self._create_default_1d_data() |
882 | | i_out = numpy.zeros(len(self.data.y)) |
| 882 | i_out = np.zeros(len(self.data.y)) |
883 | 883 | inputs = [self.data.x, [], i_out] |
884 | 884 | else: |
885 | 885 | self._create_default_2d_data() |
886 | | i_out = numpy.zeros(len(self.data.data)) |
| 886 | i_out = np.zeros(len(self.data.data)) |
887 | 887 | inputs = [self.data.qx_data, self.data.qy_data, i_out] |
888 | 888 | |
… |
… |
|
989 | 989 | :Param input: input list [qx_data, qy_data, i_out] |
990 | 990 | """ |
991 | | out = numpy.empty(0) |
| 991 | out = np.empty(0) |
992 | 992 | #s = time.time() |
993 | 993 | for ind in range(len(input[0])): |
… |
… |
|
998 | 998 | inputi = [input[0][ind:ind + 1], [], input[2][ind:ind + 1]] |
999 | 999 | outi = self.model.run(inputi) |
1000 | | out = numpy.append(out, outi) |
| 1000 | out = np.append(out, outi) |
1001 | 1001 | else: |
1002 | 1002 | if ind % 50 == 0 and update != None: |
… |
… |
|
1006 | 1006 | input[2][ind:ind + 1]] |
1007 | 1007 | outi = self.model.runXY(inputi) |
1008 | | out = numpy.append(out, outi) |
| 1008 | out = np.append(out, outi) |
1009 | 1009 | #print time.time() - s |
1010 | 1010 | if self.is_avg or self.is_avg == None: |
… |
… |
|
1027 | 1027 | self.npts_x = int(float(self.npt_ctl.GetValue())) |
1028 | 1028 | self.data = Data2D() |
1029 | | qmax = self.qmax_x #/ numpy.sqrt(2) |
| 1029 | qmax = self.qmax_x #/ np.sqrt(2) |
1030 | 1030 | self.data.xaxis('\\rm{Q_{x}}', '\AA^{-1}') |
1031 | 1031 | self.data.yaxis('\\rm{Q_{y}}', '\AA^{-1}') |
… |
… |
|
1048 | 1048 | qstep = self.npts_x |
1049 | 1049 | |
1050 | | x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
1051 | | y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) |
| 1050 | x = np.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
| 1051 | y = np.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) |
1052 | 1052 | ## use data info instead |
1053 | | new_x = numpy.tile(x, (len(y), 1)) |
1054 | | new_y = numpy.tile(y, (len(x), 1)) |
| 1053 | new_x = np.tile(x, (len(y), 1)) |
| 1054 | new_y = np.tile(y, (len(x), 1)) |
1055 | 1055 | new_y = new_y.swapaxes(0, 1) |
1056 | 1056 | # all data reuire now in 1d array |
1057 | 1057 | qx_data = new_x.flatten() |
1058 | 1058 | qy_data = new_y.flatten() |
1059 | | q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) |
| 1059 | q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) |
1060 | 1060 | # set all True (standing for unmasked) as default |
1061 | | mask = numpy.ones(len(qx_data), dtype=bool) |
| 1061 | mask = np.ones(len(qx_data), dtype=bool) |
1062 | 1062 | # store x and y bin centers in q space |
1063 | 1063 | x_bins = x |
1064 | 1064 | y_bins = y |
1065 | 1065 | self.data.source = Source() |
1066 | | self.data.data = numpy.ones(len(mask)) |
1067 | | self.data.err_data = numpy.ones(len(mask)) |
| 1066 | self.data.data = np.ones(len(mask)) |
| 1067 | self.data.err_data = np.ones(len(mask)) |
1068 | 1068 | self.data.qx_data = qx_data |
1069 | 1069 | self.data.qy_data = qy_data |
… |
… |
|
1084 | 1084 | :warning: This data is never plotted. |
1085 | 1085 | residuals.x = data_copy.x[index] |
1086 | | residuals.dy = numpy.ones(len(residuals.y)) |
| 1086 | residuals.dy = np.ones(len(residuals.y)) |
1087 | 1087 | residuals.dx = None |
1088 | 1088 | residuals.dxl = None |
… |
… |
|
1091 | 1091 | self.qmax_x = float(self.qmax_ctl.GetValue()) |
1092 | 1092 | self.npts_x = int(float(self.npt_ctl.GetValue())) |
1093 | | qmax = self.qmax_x #/ numpy.sqrt(2) |
| 1093 | qmax = self.qmax_x #/ np.sqrt(2) |
1094 | 1094 | ## Default values |
1095 | 1095 | xmax = qmax |
1096 | 1096 | xmin = qmax * _Q1D_MIN |
1097 | 1097 | qstep = self.npts_x |
1098 | | x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
| 1098 | x = np.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
1099 | 1099 | # store x and y bin centers in q space |
1100 | 1100 | #self.data.source = Source() |
1101 | | y = numpy.ones(len(x)) |
1102 | | dy = numpy.zeros(len(x)) |
1103 | | dx = numpy.zeros(len(x)) |
| 1101 | y = np.ones(len(x)) |
| 1102 | dy = np.zeros(len(x)) |
| 1103 | dx = np.zeros(len(x)) |
1104 | 1104 | self.data = Data1D(x=x, y=y) |
1105 | 1105 | self.data.dx = dx |
… |
… |
|
1171 | 1171 | state = None |
1172 | 1172 | |
1173 | | numpy.nan_to_num(image) |
| 1173 | np.nan_to_num(image) |
1174 | 1174 | new_plot = Data2D(image=image, err_image=data.err_data) |
1175 | 1175 | new_plot.name = model.name + '2d' |
… |
… |
|
1640 | 1640 | for key in sld_list.keys(): |
1641 | 1641 | if ctr_list[0] == key: |
1642 | | min_val = numpy.min(sld_list[key]) |
1643 | | max_val = numpy.max(sld_list[key]) |
1644 | | mean_val = numpy.mean(sld_list[key]) |
| 1642 | min_val = np.min(sld_list[key]) |
| 1643 | max_val = np.max(sld_list[key]) |
| 1644 | mean_val = np.mean(sld_list[key]) |
1645 | 1645 | enable = (min_val == max_val) and \ |
1646 | 1646 | sld_data.pix_type == 'pixel' |
… |
… |
|
1733 | 1733 | npts = -1 |
1734 | 1734 | break |
1735 | | if numpy.isfinite(n_val): |
| 1735 | if np.isfinite(n_val): |
1736 | 1736 | npts *= int(n_val) |
1737 | 1737 | if npts > 0: |
… |
… |
|
1770 | 1770 | ctl.Refresh() |
1771 | 1771 | return |
1772 | | if numpy.isfinite(s_val): |
| 1772 | if np.isfinite(s_val): |
1773 | 1773 | s_size *= s_val |
1774 | 1774 | self.sld_data.set_pixel_volumes(s_size) |
… |
… |
|
1787 | 1787 | try: |
1788 | 1788 | sld_data = self.parent.get_sld_from_omf() |
1789 | | #nop = (nop * numpy.pi) / 6 |
| 1789 | #nop = (nop * np.pi) / 6 |
1790 | 1790 | nop = len(sld_data.sld_n) |
1791 | 1791 | except: |
-
rb301db9
|
r9a5097c
|
|
5 | 5 | import os |
6 | 6 | import wx |
7 | | import numpy |
| 7 | import numpy as np |
8 | 8 | import time |
9 | 9 | import copy |
… |
… |
|
100 | 100 | self.graph_id = None |
101 | 101 | # Q range for data set |
102 | | self.qmin_data_set = numpy.inf |
| 102 | self.qmin_data_set = np.inf |
103 | 103 | self.qmax_data_set = None |
104 | 104 | self.npts_data_set = 0 |
… |
… |
|
278 | 278 | |
279 | 279 | """ |
280 | | x = numpy.linspace(start=self.qmin_x, stop=self.qmax_x, |
| 280 | x = np.linspace(start=self.qmin_x, stop=self.qmax_x, |
281 | 281 | num=self.npts_x, endpoint=True) |
282 | 282 | self.data = Data1D(x=x) |
… |
… |
|
295 | 295 | """ |
296 | 296 | if self.qmin_x >= 1.e-10: |
297 | | qmin = numpy.log10(self.qmin_x) |
| 297 | qmin = np.log10(self.qmin_x) |
298 | 298 | else: |
299 | 299 | qmin = -10. |
300 | 300 | |
301 | 301 | if self.qmax_x <= 1.e10: |
302 | | qmax = numpy.log10(self.qmax_x) |
| 302 | qmax = np.log10(self.qmax_x) |
303 | 303 | else: |
304 | 304 | qmax = 10. |
305 | 305 | |
306 | | x = numpy.logspace(start=qmin, stop=qmax, |
| 306 | x = np.logspace(start=qmin, stop=qmax, |
307 | 307 | num=self.npts_x, endpoint=True, base=10.0) |
308 | 308 | self.data = Data1D(x=x) |
… |
… |
|
341 | 341 | qstep = self.npts_x |
342 | 342 | |
343 | | x = numpy.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
344 | | y = numpy.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) |
| 343 | x = np.linspace(start=xmin, stop=xmax, num=qstep, endpoint=True) |
| 344 | y = np.linspace(start=ymin, stop=ymax, num=qstep, endpoint=True) |
345 | 345 | # use data info instead |
346 | | new_x = numpy.tile(x, (len(y), 1)) |
347 | | new_y = numpy.tile(y, (len(x), 1)) |
| 346 | new_x = np.tile(x, (len(y), 1)) |
| 347 | new_y = np.tile(y, (len(x), 1)) |
348 | 348 | new_y = new_y.swapaxes(0, 1) |
349 | 349 | # all data reuire now in 1d array |
350 | 350 | qx_data = new_x.flatten() |
351 | 351 | qy_data = new_y.flatten() |
352 | | q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) |
| 352 | q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) |
353 | 353 | # set all True (standing for unmasked) as default |
354 | | mask = numpy.ones(len(qx_data), dtype=bool) |
| 354 | mask = np.ones(len(qx_data), dtype=bool) |
355 | 355 | # store x and y bin centers in q space |
356 | 356 | x_bins = x |
… |
… |
|
358 | 358 | |
359 | 359 | self.data.source = Source() |
360 | | self.data.data = numpy.ones(len(mask)) |
361 | | self.data.err_data = numpy.ones(len(mask)) |
| 360 | self.data.data = np.ones(len(mask)) |
| 361 | self.data.err_data = np.ones(len(mask)) |
362 | 362 | self.data.qx_data = qx_data |
363 | 363 | self.data.qy_data = qy_data |
… |
… |
|
783 | 783 | # Skip non-data lines |
784 | 784 | logging.error(traceback.format_exc()) |
785 | | return numpy.array(angles), numpy.array(weights) |
| 785 | return np.array(angles), np.array(weights) |
786 | 786 | except: |
787 | 787 | raise |
… |
… |
|
2120 | 2120 | for data in self.data_list: |
2121 | 2121 | # q value from qx and qy |
2122 | | radius = numpy.sqrt(data.qx_data * data.qx_data + |
| 2122 | radius = np.sqrt(data.qx_data * data.qx_data + |
2123 | 2123 | data.qy_data * data.qy_data) |
2124 | 2124 | # get unmasked index |
… |
… |
|
2126 | 2126 | (radius <= float(self.qmax.GetValue())) |
2127 | 2127 | index_data = (index_data) & (data.mask) |
2128 | | index_data = (index_data) & (numpy.isfinite(data.data)) |
| 2128 | index_data = (index_data) & (np.isfinite(data.data)) |
2129 | 2129 | |
2130 | 2130 | if len(index_data[index_data]) < 10: |
… |
… |
|
2161 | 2161 | index_data = (float(self.qmin.GetValue()) <= radius) & \ |
2162 | 2162 | (radius <= float(self.qmax.GetValue())) |
2163 | | index_data = (index_data) & (numpy.isfinite(data.y)) |
| 2163 | index_data = (index_data) & (np.isfinite(data.y)) |
2164 | 2164 | |
2165 | 2165 | if len(index_data[index_data]) < 5: |
… |
… |
|
2233 | 2233 | |
2234 | 2234 | # Check that min is less than max |
2235 | | low = -numpy.inf if min_str == "" else float(min_str) |
2236 | | high = numpy.inf if max_str == "" else float(max_str) |
| 2235 | low = -np.inf if min_str == "" else float(min_str) |
| 2236 | high = np.inf if max_str == "" else float(max_str) |
2237 | 2237 | if high < low: |
2238 | 2238 | min_ctrl.SetBackgroundColour("pink") |
… |
… |
|
2654 | 2654 | self.qmin_x = data_min |
2655 | 2655 | self.qmax_x = math.sqrt(x * x + y * y) |
2656 | | # self.data.mask = numpy.ones(len(self.data.data),dtype=bool) |
| 2656 | # self.data.mask = np.ones(len(self.data.data),dtype=bool) |
2657 | 2657 | # check smearing |
2658 | 2658 | if not self.disable_smearer.GetValue(): |
… |
… |
|
3366 | 3366 | |
3367 | 3367 | if value[1] == 'array': |
3368 | | pd_vals = numpy.array(value[2]) |
3369 | | pd_weights = numpy.array(value[3]) |
| 3368 | pd_vals = np.array(value[2]) |
| 3369 | pd_weights = np.array(value[3]) |
3370 | 3370 | if len(pd_vals) == 0 or len(pd_vals) != len(pd_weights): |
3371 | 3371 | msg = ("bad array distribution parameters for %s" |
-
rd85f1d8a
|
r9a5097c
|
|
6 | 6 | import wx |
7 | 7 | import wx.lib.newevent |
8 | | import numpy |
| 8 | import numpy as np |
9 | 9 | import copy |
10 | 10 | import math |
… |
… |
|
1115 | 1115 | if item.GetValue(): |
1116 | 1116 | if button_list.index(item) == 0: |
1117 | | flag = 0 # dy = numpy.ones_like(dy_data) |
| 1117 | flag = 0 # dy = np.ones_like(dy_data) |
1118 | 1118 | elif button_list.index(item) == 1: |
1119 | 1119 | flag = 1 # dy = dy_data |
1120 | 1120 | elif button_list.index(item) == 2: |
1121 | | flag = 2 # dy = numpy.sqrt(numpy.abs(data)) |
| 1121 | flag = 2 # dy = np.sqrt(np.abs(data)) |
1122 | 1122 | elif button_list.index(item) == 3: |
1123 | | flag = 3 # dy = numpy.abs(data) |
| 1123 | flag = 3 # dy = np.abs(data) |
1124 | 1124 | break |
1125 | 1125 | return flag |
… |
… |
|
1422 | 1422 | key = event.GetKeyCode() |
1423 | 1423 | length = len(self.data.x) |
1424 | | indx = (numpy.abs(self.data.x - x_data)).argmin() |
| 1424 | indx = (np.abs(self.data.x - x_data)).argmin() |
1425 | 1425 | # return array.flat[idx] |
1426 | 1426 | if key == wx.WXK_PAGEUP or key == wx.WXK_NUMPAD_PAGEUP: |
… |
… |
|
1477 | 1477 | self.enable2D: |
1478 | 1478 | # set mask |
1479 | | radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + |
| 1479 | radius = np.sqrt(self.data.qx_data * self.data.qx_data + |
1480 | 1480 | self.data.qy_data * self.data.qy_data) |
1481 | 1481 | index_data = ((self.qmin_x <= radius) & (radius <= self.qmax_x)) |
1482 | 1482 | index_data = (index_data) & (self.data.mask) |
1483 | | index_data = (index_data) & (numpy.isfinite(self.data.data)) |
| 1483 | index_data = (index_data) & (np.isfinite(self.data.data)) |
1484 | 1484 | if len(index_data[index_data]) < 10: |
1485 | 1485 | msg = "Cannot Plot :No or too little npts in" |
… |
… |
|
1598 | 1598 | and data.dqx_data.any() != 0: |
1599 | 1599 | self.smear_type = "Pinhole2d" |
1600 | | self.dq_l = format_number(numpy.average(data.dqx_data)) |
1601 | | self.dq_r = format_number(numpy.average(data.dqy_data)) |
| 1600 | self.dq_l = format_number(np.average(data.dqx_data)) |
| 1601 | self.dq_r = format_number(np.average(data.dqy_data)) |
1602 | 1602 | return |
1603 | 1603 | else: |
1604 | 1604 | return |
1605 | 1605 | # check if it is pinhole smear and get min max if it is. |
1606 | | if data.dx is not None and numpy.any(data.dx): |
| 1606 | if data.dx is not None and np.any(data.dx): |
1607 | 1607 | self.smear_type = "Pinhole" |
1608 | 1608 | self.dq_l = data.dx[0] |
… |
… |
|
1612 | 1612 | elif data.dxl is not None or data.dxw is not None: |
1613 | 1613 | self.smear_type = "Slit" |
1614 | | if data.dxl is not None and numpy.all(data.dxl, 0): |
| 1614 | if data.dxl is not None and np.all(data.dxl, 0): |
1615 | 1615 | self.dq_l = data.dxl[0] |
1616 | | if data.dxw is not None and numpy.all(data.dxw, 0): |
| 1616 | if data.dxw is not None and np.all(data.dxw, 0): |
1617 | 1617 | self.dq_r = data.dxw[0] |
1618 | 1618 | # return self.smear_type,self.dq_l,self.dq_r |
… |
… |
|
1921 | 1921 | self.default_mask = copy.deepcopy(self.data.mask) |
1922 | 1922 | if self.data.err_data is not None \ |
1923 | | and numpy.any(self.data.err_data): |
| 1923 | and np.any(self.data.err_data): |
1924 | 1924 | di_flag = True |
1925 | 1925 | if self.data.dqx_data is not None \ |
1926 | | and numpy.any(self.data.dqx_data): |
| 1926 | and np.any(self.data.dqx_data): |
1927 | 1927 | dq_flag = True |
1928 | 1928 | else: |
1929 | 1929 | self.slit_smearer.Enable(True) |
1930 | 1930 | self.pinhole_smearer.Enable(True) |
1931 | | if self.data.dy is not None and numpy.any(self.data.dy): |
| 1931 | if self.data.dy is not None and np.any(self.data.dy): |
1932 | 1932 | di_flag = True |
1933 | | if self.data.dx is not None and numpy.any(self.data.dx): |
| 1933 | if self.data.dx is not None and np.any(self.data.dx): |
1934 | 1934 | dq_flag = True |
1935 | | elif self.data.dxl is not None and numpy.any(self.data.dxl): |
| 1935 | elif self.data.dxl is not None and np.any(self.data.dxl): |
1936 | 1936 | dq_flag = True |
1937 | 1937 | |
… |
… |
|
2067 | 2067 | if self.data.__class__.__name__ == "Data2D" or \ |
2068 | 2068 | self.enable2D: |
2069 | | radius = numpy.sqrt(self.data.qx_data * self.data.qx_data + |
| 2069 | radius = np.sqrt(self.data.qx_data * self.data.qx_data + |
2070 | 2070 | self.data.qy_data * self.data.qy_data) |
2071 | 2071 | index_data = (self.qmin_x <= radius) & (radius <= self.qmax_x) |
2072 | 2072 | index_data = (index_data) & (self.data.mask) |
2073 | | index_data = (index_data) & (numpy.isfinite(self.data.data)) |
| 2073 | index_data = (index_data) & (np.isfinite(self.data.data)) |
2074 | 2074 | npts2fit = len(self.data.data[index_data]) |
2075 | 2075 | else: |
… |
… |
|
2104 | 2104 | # make sure stop button to fit button all the time |
2105 | 2105 | self._on_fit_complete() |
2106 | | if out is None or not numpy.isfinite(chisqr): |
| 2106 | if out is None or not np.isfinite(chisqr): |
2107 | 2107 | raise ValueError, "Fit error occured..." |
2108 | 2108 | |
… |
… |
|
2115 | 2115 | |
2116 | 2116 | # Check if chi2 is finite |
2117 | | if chisqr is not None and numpy.isfinite(chisqr): |
| 2117 | if chisqr is not None and np.isfinite(chisqr): |
2118 | 2118 | # format chi2 |
2119 | 2119 | chi2 = format_number(chisqr, True) |
… |
… |
|
2167 | 2167 | |
2168 | 2168 | if cov[ind] is not None: |
2169 | | if numpy.isfinite(float(cov[ind])): |
| 2169 | if np.isfinite(float(cov[ind])): |
2170 | 2170 | val_err = format_number(cov[ind], True) |
2171 | 2171 | item[4].SetForegroundColour(wx.BLACK) |
… |
… |
|
2291 | 2291 | self.smear_type = 'Pinhole2d' |
2292 | 2292 | len_data = len(data.data) |
2293 | | data.dqx_data = numpy.zeros(len_data) |
2294 | | data.dqy_data = numpy.zeros(len_data) |
| 2293 | data.dqx_data = np.zeros(len_data) |
| 2294 | data.dqy_data = np.zeros(len_data) |
2295 | 2295 | else: |
2296 | 2296 | self.smear_type = 'Pinhole' |
2297 | 2297 | len_data = len(data.x) |
2298 | | data.dx = numpy.zeros(len_data) |
| 2298 | data.dx = np.zeros(len_data) |
2299 | 2299 | data.dxl = None |
2300 | 2300 | data.dxw = None |
… |
… |
|
2469 | 2469 | try: |
2470 | 2470 | self.dxl = float(self.smear_slit_height.GetValue()) |
2471 | | data.dxl = self.dxl * numpy.ones(data_len) |
| 2471 | data.dxl = self.dxl * np.ones(data_len) |
2472 | 2472 | self.smear_slit_height.SetBackgroundColour(wx.WHITE) |
2473 | 2473 | except: |
2474 | 2474 | self.dxl = None |
2475 | | data.dxl = numpy.zeros(data_len) |
| 2475 | data.dxl = np.zeros(data_len) |
2476 | 2476 | if self.smear_slit_height.GetValue().lstrip().rstrip() != "": |
2477 | 2477 | self.smear_slit_height.SetBackgroundColour("pink") |
… |
… |
|
2482 | 2482 | self.dxw = float(self.smear_slit_width.GetValue()) |
2483 | 2483 | self.smear_slit_width.SetBackgroundColour(wx.WHITE) |
2484 | | data.dxw = self.dxw * numpy.ones(data_len) |
| 2484 | data.dxw = self.dxw * np.ones(data_len) |
2485 | 2485 | except: |
2486 | 2486 | self.dxw = None |
2487 | | data.dxw = numpy.zeros(data_len) |
| 2487 | data.dxw = np.zeros(data_len) |
2488 | 2488 | if self.smear_slit_width.GetValue().lstrip().rstrip() != "": |
2489 | 2489 | self.smear_slit_width.SetBackgroundColour("pink") |
… |
… |
|
2612 | 2612 | if event is None: |
2613 | 2613 | output = "-" |
2614 | | elif not numpy.isfinite(event.output): |
| 2614 | elif not np.isfinite(event.output): |
2615 | 2615 | output = "-" |
2616 | 2616 | else: |
-
rddbac66
|
r9a5097c
|
|
16 | 16 | import wx |
17 | 17 | import logging |
18 | | import numpy |
| 18 | import numpy as np |
19 | 19 | import time |
20 | 20 | from copy import deepcopy |
… |
… |
|
1332 | 1332 | new_theory = copy_data.data |
1333 | 1333 | new_theory[res.index] = res.theory |
1334 | | new_theory[res.index == False] = numpy.nan |
| 1334 | new_theory[res.index == False] = np.nan |
1335 | 1335 | correct_result = True |
1336 | 1336 | #get all fittable parameters of the current model |
… |
… |
|
1341 | 1341 | param_list.remove(param) |
1342 | 1342 | if not correct_result or res.fitness is None or \ |
1343 | | not numpy.isfinite(res.fitness) or \ |
1344 | | numpy.any(res.pvec == None) or not \ |
1345 | | numpy.all(numpy.isfinite(res.pvec)): |
| 1343 | not np.isfinite(res.fitness) or \ |
| 1344 | np.any(res.pvec == None) or not \ |
| 1345 | np.all(np.isfinite(res.pvec)): |
1346 | 1346 | data_name = str(None) |
1347 | 1347 | if data is not None: |
… |
… |
|
1352 | 1352 | msg += "Data %s and Model %s did not fit.\n" % (data_name, |
1353 | 1353 | model_name) |
1354 | | ERROR = numpy.NAN |
| 1354 | ERROR = np.NAN |
1355 | 1355 | cell = BatchCell() |
1356 | 1356 | cell.label = res.fitness |
… |
… |
|
1366 | 1366 | batch_inputs["error on %s" % str(param)].append(ERROR) |
1367 | 1367 | else: |
1368 | | # TODO: Why sometimes res.pvec comes with numpy.float64? |
| 1368 | # TODO: Why sometimes res.pvec comes with np.float64? |
1369 | 1369 | # probably from scipy lmfit |
1370 | | if res.pvec.__class__ == numpy.float64: |
| 1370 | if res.pvec.__class__ == np.float64: |
1371 | 1371 | res.pvec = [res.pvec] |
1372 | 1372 | |
… |
… |
|
1533 | 1533 | fit_msg = res.mesg |
1534 | 1534 | if res.fitness is None or \ |
1535 | | not numpy.isfinite(res.fitness) or \ |
1536 | | numpy.any(res.pvec == None) or \ |
1537 | | not numpy.all(numpy.isfinite(res.pvec)): |
| 1535 | not np.isfinite(res.fitness) or \ |
| 1536 | np.any(res.pvec == None) or \ |
| 1537 | not np.all(np.isfinite(res.pvec)): |
1538 | 1538 | fit_msg += "\nFitting did not converge!!!" |
1539 | 1539 | wx.CallAfter(self._update_fit_button, page_id) |
1540 | 1540 | else: |
1541 | 1541 | #set the panel when fit result are float not list |
1542 | | if res.pvec.__class__ == numpy.float64: |
| 1542 | if res.pvec.__class__ == np.float64: |
1543 | 1543 | pvec = [res.pvec] |
1544 | 1544 | else: |
1545 | 1545 | pvec = res.pvec |
1546 | | if res.stderr.__class__ == numpy.float64: |
| 1546 | if res.stderr.__class__ == np.float64: |
1547 | 1547 | stderr = [res.stderr] |
1548 | 1548 | else: |
… |
… |
|
1692 | 1692 | if dy is None: |
1693 | 1693 | new_plot.is_data = False |
1694 | | new_plot.dy = numpy.zeros(len(y)) |
| 1694 | new_plot.dy = np.zeros(len(y)) |
1695 | 1695 | # If this is a theory curve, pick the proper symbol to make it a curve |
1696 | 1696 | new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM |
… |
… |
|
1741 | 1741 | """ |
1742 | 1742 | try: |
1743 | | numpy.nan_to_num(y) |
| 1743 | np.nan_to_num(y) |
1744 | 1744 | new_plot = self.create_theory_1D(x, y, page_id, model, data, state, |
1745 | 1745 | data_description=model.name, |
… |
… |
|
1826 | 1826 | that can be plot. |
1827 | 1827 | """ |
1828 | | numpy.nan_to_num(image) |
| 1828 | np.nan_to_num(image) |
1829 | 1829 | new_plot = Data2D(image=image, err_image=data.err_data) |
1830 | 1830 | new_plot.name = model.name + '2d' |
… |
… |
|
2018 | 2018 | if data_copy.__class__.__name__ == "Data2D": |
2019 | 2019 | if index == None: |
2020 | | index = numpy.ones(len(data_copy.data), dtype=bool) |
| 2020 | index = np.ones(len(data_copy.data), dtype=bool) |
2021 | 2021 | if weight != None: |
2022 | 2022 | data_copy.err_data = weight |
2023 | 2023 | # get rid of zero error points |
2024 | 2024 | index = index & (data_copy.err_data != 0) |
2025 | | index = index & (numpy.isfinite(data_copy.data)) |
| 2025 | index = index & (np.isfinite(data_copy.data)) |
2026 | 2026 | fn = data_copy.data[index] |
2027 | 2027 | theory_data = self.page_finder[page_id].get_theory_data(fid=data_copy.id) |
… |
… |
|
2033 | 2033 | # 1 d theory from model_thread is only in the range of index |
2034 | 2034 | if index == None: |
2035 | | index = numpy.ones(len(data_copy.y), dtype=bool) |
| 2035 | index = np.ones(len(data_copy.y), dtype=bool) |
2036 | 2036 | if weight != None: |
2037 | 2037 | data_copy.dy = weight |
2038 | 2038 | if data_copy.dy == None or data_copy.dy == []: |
2039 | | dy = numpy.ones(len(data_copy.y)) |
| 2039 | dy = np.ones(len(data_copy.y)) |
2040 | 2040 | else: |
2041 | 2041 | ## Set consistently w/AbstractFitengine: |
… |
… |
|
2058 | 2058 | return |
2059 | 2059 | |
2060 | | residuals = res[numpy.isfinite(res)] |
| 2060 | residuals = res[np.isfinite(res)] |
2061 | 2061 | # get chisqr only w/finite |
2062 | | chisqr = numpy.average(residuals * residuals) |
| 2062 | chisqr = np.average(residuals * residuals) |
2063 | 2063 | |
2064 | 2064 | self._plot_residuals(page_id=page_id, data=data_copy, |
… |
… |
|
2097 | 2097 | residuals.qy_data = data_copy.qy_data |
2098 | 2098 | residuals.q_data = data_copy.q_data |
2099 | | residuals.err_data = numpy.ones(len(residuals.data)) |
| 2099 | residuals.err_data = np.ones(len(residuals.data)) |
2100 | 2100 | residuals.xmin = min(residuals.qx_data) |
2101 | 2101 | residuals.xmax = max(residuals.qx_data) |
… |
… |
|
2111 | 2111 | # 1 d theory from model_thread is only in the range of index |
2112 | 2112 | if data_copy.dy == None or data_copy.dy == []: |
2113 | | dy = numpy.ones(len(data_copy.y)) |
| 2113 | dy = np.ones(len(data_copy.y)) |
2114 | 2114 | else: |
2115 | 2115 | if weight == None: |
2116 | | dy = numpy.ones(len(data_copy.y)) |
| 2116 | dy = np.ones(len(data_copy.y)) |
2117 | 2117 | ## Set consitently w/AbstractFitengine: |
2118 | 2118 | ## But this should be corrected later. |
… |
… |
|
2133 | 2133 | residuals.y = (fn - gn[index]) / en |
2134 | 2134 | residuals.x = data_copy.x[index] |
2135 | | residuals.dy = numpy.ones(len(residuals.y)) |
| 2135 | residuals.dy = np.ones(len(residuals.y)) |
2136 | 2136 | residuals.dx = None |
2137 | 2137 | residuals.dxl = None |
-
rc1c9929
|
r9a5097c
|
|
4 | 4 | |
5 | 5 | import time |
6 | | import numpy |
| 6 | import numpy as np |
7 | 7 | import math |
8 | 8 | from sas.sascalc.data_util.calcthread import CalcThread |
… |
… |
|
68 | 68 | |
69 | 69 | # Define matrix where data will be plotted |
70 | | radius = numpy.sqrt((self.data.qx_data * self.data.qx_data) + \ |
| 70 | radius = np.sqrt((self.data.qx_data * self.data.qx_data) + \ |
71 | 71 | (self.data.qy_data * self.data.qy_data)) |
72 | 72 | |
… |
… |
|
75 | 75 | index_model = (self.qmin <= radius) & (radius <= self.qmax) |
76 | 76 | index_model = index_model & self.data.mask |
77 | | index_model = index_model & numpy.isfinite(self.data.data) |
| 77 | index_model = index_model & np.isfinite(self.data.data) |
78 | 78 | |
79 | 79 | if self.smearer is not None: |
… |
… |
|
91 | 91 | self.data.qy_data[index_model] |
92 | 92 | ]) |
93 | | output = numpy.zeros(len(self.data.qx_data)) |
| 93 | output = np.zeros(len(self.data.qx_data)) |
94 | 94 | # output default is None |
95 | 95 | # This method is to distinguish between masked |
… |
… |
|
163 | 163 | """ |
164 | 164 | self.starttime = time.time() |
165 | | output = numpy.zeros((len(self.data.x))) |
| 165 | output = np.zeros((len(self.data.x))) |
166 | 166 | index = (self.qmin <= self.data.x) & (self.data.x <= self.qmax) |
167 | 167 | |
… |
… |
|
175 | 175 | self.qmax) |
176 | 176 | mask = self.data.x[first_bin:last_bin+1] |
177 | | unsmeared_output = numpy.zeros((len(self.data.x))) |
| 177 | unsmeared_output = np.zeros((len(self.data.x))) |
178 | 178 | unsmeared_output[first_bin:last_bin+1] = self.model.evalDistribution(mask) |
179 | 179 | self.smearer.model = self.model |
… |
… |
|
183 | 183 | # Check that the arrays are compatible. If we only have a model but no data, |
184 | 184 | # the length of data.y will be zero. |
185 | | if isinstance(self.data.y, numpy.ndarray) and output.shape == self.data.y.shape: |
186 | | unsmeared_data = numpy.zeros((len(self.data.x))) |
187 | | unsmeared_error = numpy.zeros((len(self.data.x))) |
| 185 | if isinstance(self.data.y, np.ndarray) and output.shape == self.data.y.shape: |
| 186 | unsmeared_data = np.zeros((len(self.data.x))) |
| 187 | unsmeared_error = np.zeros((len(self.data.x))) |
188 | 188 | unsmeared_data[first_bin:last_bin+1] = self.data.y[first_bin:last_bin+1]\ |
189 | 189 | * unsmeared_output[first_bin:last_bin+1]\ |
… |
… |
|
209 | 209 | |
210 | 210 | if p_model is not None and s_model is not None: |
211 | | sq_values = numpy.zeros((len(self.data.x))) |
212 | | pq_values = numpy.zeros((len(self.data.x))) |
| 211 | sq_values = np.zeros((len(self.data.x))) |
| 212 | pq_values = np.zeros((len(self.data.x))) |
213 | 213 | sq_values[index] = s_model.evalDistribution(self.data.x[index]) |
214 | 214 | pq_values[index] = p_model.evalDistribution(self.data.x[index]) |
-
rd5aff7f
|
r9a5097c
|
|
18 | 18 | import copy |
19 | 19 | import logging |
20 | | import numpy |
| 20 | import numpy as np |
21 | 21 | import traceback |
22 | 22 | |
… |
… |
|
410 | 410 | for fittable, name, value, _, uncert, lower, upper, units in params: |
411 | 411 | if not value: |
412 | | value = numpy.nan |
| 412 | value = np.nan |
413 | 413 | if not uncert or uncert[1] == '' or uncert[1] == 'None': |
414 | 414 | uncert[0] = False |
415 | | uncert[1] = numpy.nan |
| 415 | uncert[1] = np.nan |
416 | 416 | if not upper or upper[1] == '' or upper[1] == 'None': |
417 | 417 | upper[0] = False |
418 | | upper[1] = numpy.nan |
| 418 | upper[1] = np.nan |
419 | 419 | if not lower or lower[1] == '' or lower[1] == 'None': |
420 | 420 | lower[0] = False |
421 | | lower[1] = numpy.nan |
| 421 | lower[1] = np.nan |
422 | 422 | if is_string: |
423 | 423 | p[name] = str(value) |
… |
… |
|
449 | 449 | lower = params.get(name + ".lower", '-inf') |
450 | 450 | units = params.get(name + ".units") |
451 | | if std is not None and std is not numpy.nan: |
| 451 | if std is not None and std is not np.nan: |
452 | 452 | std = [True, str(std)] |
453 | 453 | else: |
454 | 454 | std = [False, ''] |
455 | | if lower is not None and lower is not numpy.nan: |
| 455 | if lower is not None and lower is not np.nan: |
456 | 456 | lower = [True, str(lower)] |
457 | 457 | else: |
458 | 458 | lower = [True, '-inf'] |
459 | | if upper is not None and upper is not numpy.nan: |
| 459 | if upper is not None and upper is not np.nan: |
460 | 460 | upper = [True, str(upper)] |
461 | 461 | else: |
… |
… |
|
1100 | 1100 | % (line, tagname, name)) |
1101 | 1101 | logging.error(msg + traceback.format_exc()) |
1102 | | dic[name] = numpy.array(value_list) |
| 1102 | dic[name] = np.array(value_list) |
1103 | 1103 | setattr(self, varname, dic) |
1104 | 1104 | |
-
rd85c194
|
r9a5097c
|
|
2 | 2 | Module contains functions frequently used in this package |
3 | 3 | """ |
4 | | import numpy |
| 4 | import numpy as np |
5 | 5 | |
6 | 6 | |
… |
… |
|
19 | 19 | data = data.y |
20 | 20 | if flag == 0: |
21 | | weight = numpy.ones_like(data) |
| 21 | weight = np.ones_like(data) |
22 | 22 | elif flag == 1: |
23 | 23 | weight = dy_data |
24 | 24 | elif flag == 2: |
25 | | weight = numpy.sqrt(numpy.abs(data)) |
| 25 | weight = np.sqrt(np.abs(data)) |
26 | 26 | elif flag == 3: |
27 | | weight = numpy.abs(data) |
| 27 | weight = np.abs(data) |
28 | 28 | return weight |
-
rd85c194
|
r9a5097c
|
|
19 | 19 | |
20 | 20 | import wx |
21 | | import numpy |
| 21 | import numpy as np |
22 | 22 | import logging |
23 | 23 | import sys |
… |
… |
|
65 | 65 | |
66 | 66 | step = (self.max - self.min) / (self.npts - 1) |
67 | | self.x = numpy.arange(self.min, self.max + step * 0.01, step) |
68 | | dx = numpy.zeros(len(self.x)) |
69 | | y = numpy.ones(len(self.x)) |
70 | | dy = numpy.zeros(len(self.x)) |
| 67 | self.x = np.arange(self.min, self.max + step * 0.01, step) |
| 68 | dx = np.zeros(len(self.x)) |
| 69 | y = np.ones(len(self.x)) |
| 70 | dy = np.zeros(len(self.x)) |
71 | 71 | |
72 | 72 | # Plot area |
-
ra69a967
|
r9a5097c
|
|
21 | 21 | import time |
22 | 22 | import math |
23 | | import numpy |
| 23 | import numpy as np |
24 | 24 | import pylab |
25 | 25 | from sas.sasgui.guiframe.gui_manager import MDIFrame |
… |
… |
|
207 | 207 | r = pylab.arange(0.01, d_max, d_max / 51.0) |
208 | 208 | M = len(r) |
209 | | y = numpy.zeros(M) |
210 | | pr_err = numpy.zeros(M) |
| 209 | y = np.zeros(M) |
| 210 | pr_err = np.zeros(M) |
211 | 211 | |
212 | 212 | total = 0.0 |
… |
… |
|
253 | 253 | """ |
254 | 254 | # Show P(r) |
255 | | y_true = numpy.zeros(len(x)) |
| 255 | y_true = np.zeros(len(x)) |
256 | 256 | |
257 | 257 | sum_true = 0.0 |
… |
… |
|
307 | 307 | |
308 | 308 | x = pylab.arange(minq, maxq, maxq / 301.0) |
309 | | y = numpy.zeros(len(x)) |
310 | | err = numpy.zeros(len(x)) |
| 309 | y = np.zeros(len(x)) |
| 310 | err = np.zeros(len(x)) |
311 | 311 | for i in range(len(x)): |
312 | 312 | value = pr.iq(out, x[i]) |
… |
… |
|
337 | 337 | if pr.slit_width > 0 or pr.slit_height > 0: |
338 | 338 | x = pylab.arange(minq, maxq, maxq / 301.0) |
339 | | y = numpy.zeros(len(x)) |
340 | | err = numpy.zeros(len(x)) |
| 339 | y = np.zeros(len(x)) |
| 340 | err = np.zeros(len(x)) |
341 | 341 | for i in range(len(x)): |
342 | 342 | value = pr.iq_smeared(out, x[i]) |
… |
… |
|
382 | 382 | x = pylab.arange(0.0, pr.d_max, pr.d_max / self._pr_npts) |
383 | 383 | |
384 | | y = numpy.zeros(len(x)) |
385 | | dy = numpy.zeros(len(x)) |
386 | | y_true = numpy.zeros(len(x)) |
| 384 | y = np.zeros(len(x)) |
| 385 | dy = np.zeros(len(x)) |
| 386 | y_true = np.zeros(len(x)) |
387 | 387 | |
388 | 388 | total = 0.0 |
389 | 389 | pmax = 0.0 |
390 | | cov2 = numpy.ascontiguousarray(cov) |
| 390 | cov2 = np.ascontiguousarray(cov) |
391 | 391 | |
392 | 392 | for i in range(len(x)): |
… |
… |
|
480 | 480 | """ |
481 | 481 | # Read the data from the data file |
482 | | data_x = numpy.zeros(0) |
483 | | data_y = numpy.zeros(0) |
484 | | data_err = numpy.zeros(0) |
| 482 | data_x = np.zeros(0) |
| 483 | data_y = np.zeros(0) |
| 484 | data_err = np.zeros(0) |
485 | 485 | scale = None |
486 | 486 | min_err = 0.0 |
… |
… |
|
504 | 504 | #err = 0 |
505 | 505 | |
506 | | data_x = numpy.append(data_x, x) |
507 | | data_y = numpy.append(data_y, y) |
508 | | data_err = numpy.append(data_err, err) |
| 506 | data_x = np.append(data_x, x) |
| 507 | data_y = np.append(data_y, y) |
| 508 | data_err = np.append(data_err, err) |
509 | 509 | except: |
510 | 510 | logging.error(sys.exc_value) |
… |
… |
|
528 | 528 | """ |
529 | 529 | # Read the data from the data file |
530 | | data_x = numpy.zeros(0) |
531 | | data_y = numpy.zeros(0) |
532 | | data_err = numpy.zeros(0) |
| 530 | data_x = np.zeros(0) |
| 531 | data_y = np.zeros(0) |
| 532 | data_err = np.zeros(0) |
533 | 533 | scale = None |
534 | 534 | min_err = 0.0 |
… |
… |
|
555 | 555 | #err = 0 |
556 | 556 | |
557 | | data_x = numpy.append(data_x, x) |
558 | | data_y = numpy.append(data_y, y) |
559 | | data_err = numpy.append(data_err, err) |
| 557 | data_x = np.append(data_x, x) |
| 558 | data_y = np.append(data_y, y) |
| 559 | data_err = np.append(data_err, err) |
560 | 560 | except: |
561 | 561 | logging.error(sys.exc_value) |
… |
… |
|
640 | 640 | # Now replot the original added data |
641 | 641 | for plot in self._added_plots: |
642 | | self._added_plots[plot].y = numpy.copy(self._default_Iq[plot]) |
| 642 | self._added_plots[plot].y = np.copy(self._default_Iq[plot]) |
643 | 643 | wx.PostEvent(self.parent, |
644 | 644 | NewPlotEvent(plot=self._added_plots[plot], |
… |
… |
|
664 | 664 | # Now scale the added plots too |
665 | 665 | for plot in self._added_plots: |
666 | | total = numpy.sum(self._added_plots[plot].y) |
| 666 | total = np.sum(self._added_plots[plot].y) |
667 | 667 | npts = len(self._added_plots[plot].x) |
668 | 668 | total *= self._added_plots[plot].x[npts - 1] / npts |
… |
… |
|
814 | 814 | # Save Pr invertor |
815 | 815 | self.pr = pr |
816 | | cov = numpy.ascontiguousarray(cov) |
| 816 | cov = np.ascontiguousarray(cov) |
817 | 817 | |
818 | 818 | # Show result on control panel |
… |
… |
|
982 | 982 | all_zeros = True |
983 | 983 | if err == None: |
984 | | err = numpy.zeros(len(pr.y)) |
| 984 | err = np.zeros(len(pr.y)) |
985 | 985 | else: |
986 | 986 | for i in range(len(err)): |
… |
… |
|
1088 | 1088 | # If we have not errors, add statistical errors |
1089 | 1089 | if y is not None: |
1090 | | if err == None or numpy.all(err) == 0: |
1091 | | err = numpy.zeros(len(y)) |
| 1090 | if err == None or np.all(err) == 0: |
| 1091 | err = np.zeros(len(y)) |
1092 | 1092 | scale = None |
1093 | 1093 | min_err = 0.0 |
-
rd85c194
|
r9a5097c
|
|
10 | 10 | import wx |
11 | 11 | import os |
12 | | import numpy |
| 12 | import numpy as np |
13 | 13 | import time |
14 | 14 | import logging |
… |
… |
|
46 | 46 | def compute(self): |
47 | 47 | x = self.x |
48 | | output = numpy.zeros(len(x)) |
49 | | error = numpy.zeros(len(x)) |
| 48 | output = np.zeros(len(x)) |
| 49 | error = np.zeros(len(x)) |
50 | 50 | |
51 | 51 | self.starttime = time.time() |
… |
… |
|
123 | 123 | # Q-values for plotting simulated I(Q) |
124 | 124 | step = (self.q_max-self.q_min)/(self.q_npts-1) |
125 | | self.x = numpy.arange(self.q_min, self.q_max+step*0.01, step) |
| 125 | self.x = np.arange(self.q_min, self.q_max+step*0.01, step) |
126 | 126 | |
127 | 127 | # Set the list of panels that are part of the simulation perspective |
… |
… |
|
187 | 187 | # Q-values for plotting simulated I(Q) |
188 | 188 | step = (self.q_max-self.q_min)/(self.q_npts-1) |
189 | | self.x = numpy.arange(self.q_min, self.q_max+step*0.01, step) |
| 189 | self.x = np.arange(self.q_min, self.q_max+step*0.01, step) |
190 | 190 | |
191 | 191 | # Compute the simulated I(Q) |
-
r198fa76
|
r9a5097c
|
|
29 | 29 | DEFAULT_CMAP = pylab.cm.jet |
30 | 30 | import copy |
31 | | import numpy |
| 31 | import numpy as np |
32 | 32 | |
33 | 33 | from sas.sasgui.guiframe.events import StatusEvent |
… |
… |
|
1452 | 1452 | if self.zmin_2D <= 0 and len(output[output > 0]) > 0: |
1453 | 1453 | zmin_temp = self.zmin_2D |
1454 | | output[output > 0] = numpy.log10(output[output > 0]) |
| 1454 | output[output > 0] = np.log10(output[output > 0]) |
1455 | 1455 | #In log scale Negative values are not correct in general |
1456 | | #output[output<=0] = math.log(numpy.min(output[output>0])) |
| 1456 | #output[output<=0] = math.log(np.min(output[output>0])) |
1457 | 1457 | elif self.zmin_2D <= 0: |
1458 | 1458 | zmin_temp = self.zmin_2D |
1459 | | output[output > 0] = numpy.zeros(len(output)) |
| 1459 | output[output > 0] = np.zeros(len(output)) |
1460 | 1460 | output[output <= 0] = -32 |
1461 | 1461 | else: |
1462 | 1462 | zmin_temp = self.zmin_2D |
1463 | | output[output > 0] = numpy.log10(output[output > 0]) |
| 1463 | output[output > 0] = np.log10(output[output > 0]) |
1464 | 1464 | #In log scale Negative values are not correct in general |
1465 | | #output[output<=0] = math.log(numpy.min(output[output>0])) |
| 1465 | #output[output<=0] = math.log(np.min(output[output>0])) |
1466 | 1466 | except: |
1467 | 1467 | #Too many problems in 2D plot with scale |
… |
… |
|
1492 | 1492 | X = self.x_bins[0:-1] |
1493 | 1493 | Y = self.y_bins[0:-1] |
1494 | | X, Y = numpy.meshgrid(X, Y) |
| 1494 | X, Y = np.meshgrid(X, Y) |
1495 | 1495 | |
1496 | 1496 | try: |
… |
… |
|
1555 | 1555 | # 1d array to use for weighting the data point averaging |
1556 | 1556 | #when they fall into a same bin. |
1557 | | weights_data = numpy.ones([self.data.size]) |
| 1557 | weights_data = np.ones([self.data.size]) |
1558 | 1558 | # get histogram of ones w/len(data); this will provide |
1559 | 1559 | #the weights of data on each bins |
1560 | | weights, xedges, yedges = numpy.histogram2d(x=self.qy_data, |
| 1560 | weights, xedges, yedges = np.histogram2d(x=self.qy_data, |
1561 | 1561 | y=self.qx_data, |
1562 | 1562 | bins=[self.y_bins, self.x_bins], |
1563 | 1563 | weights=weights_data) |
1564 | 1564 | # get histogram of data, all points into a bin in a way of summing |
1565 | | image, xedges, yedges = numpy.histogram2d(x=self.qy_data, |
| 1565 | image, xedges, yedges = np.histogram2d(x=self.qy_data, |
1566 | 1566 | y=self.qx_data, |
1567 | 1567 | bins=[self.y_bins, self.x_bins], |
… |
… |
|
1581 | 1581 | # do while loop until all vacant bins are filled up up |
1582 | 1582 | #to loop = max_loop |
1583 | | while not(numpy.isfinite(image[weights == 0])).all(): |
| 1583 | while not(np.isfinite(image[weights == 0])).all(): |
1584 | 1584 | if loop >= max_loop: # this protects never-ending loop |
1585 | 1585 | break |
… |
… |
|
1630 | 1630 | |
1631 | 1631 | # store x and y bin centers in q space |
1632 | | x_bins = numpy.linspace(xmin, xmax, npix_x) |
1633 | | y_bins = numpy.linspace(ymin, ymax, npix_y) |
| 1632 | x_bins = np.linspace(xmin, xmax, npix_x) |
| 1633 | y_bins = np.linspace(ymin, ymax, npix_y) |
1634 | 1634 | |
1635 | 1635 | #set x_bins and y_bins |
… |
… |
|
1650 | 1650 | """ |
1651 | 1651 | # No image matrix given |
1652 | | if image == None or numpy.ndim(image) != 2 \ |
1653 | | or numpy.isfinite(image).all() \ |
| 1652 | if image == None or np.ndim(image) != 2 \ |
| 1653 | or np.isfinite(image).all() \ |
1654 | 1654 | or weights == None: |
1655 | 1655 | return image |
… |
… |
|
1657 | 1657 | len_y = len(image) |
1658 | 1658 | len_x = len(image[1]) |
1659 | | temp_image = numpy.zeros([len_y, len_x]) |
1660 | | weit = numpy.zeros([len_y, len_x]) |
| 1659 | temp_image = np.zeros([len_y, len_x]) |
| 1660 | weit = np.zeros([len_y, len_x]) |
1661 | 1661 | # do for-loop for all pixels |
1662 | 1662 | for n_y in range(len(image)): |
1663 | 1663 | for n_x in range(len(image[1])): |
1664 | 1664 | # find only null pixels |
1665 | | if weights[n_y][n_x] > 0 or numpy.isfinite(image[n_y][n_x]): |
| 1665 | if weights[n_y][n_x] > 0 or np.isfinite(image[n_y][n_x]): |
1666 | 1666 | continue |
1667 | 1667 | else: |
1668 | 1668 | # find 4 nearest neighbors |
1669 | 1669 | # check where or not it is at the corner |
1670 | | if n_y != 0 and numpy.isfinite(image[n_y - 1][n_x]): |
| 1670 | if n_y != 0 and np.isfinite(image[n_y - 1][n_x]): |
1671 | 1671 | temp_image[n_y][n_x] += image[n_y - 1][n_x] |
1672 | 1672 | weit[n_y][n_x] += 1 |
1673 | | if n_x != 0 and numpy.isfinite(image[n_y][n_x - 1]): |
| 1673 | if n_x != 0 and np.isfinite(image[n_y][n_x - 1]): |
1674 | 1674 | temp_image[n_y][n_x] += image[n_y][n_x - 1] |
1675 | 1675 | weit[n_y][n_x] += 1 |
1676 | | if n_y != len_y - 1 and numpy.isfinite(image[n_y + 1][n_x]): |
| 1676 | if n_y != len_y - 1 and np.isfinite(image[n_y + 1][n_x]): |
1677 | 1677 | temp_image[n_y][n_x] += image[n_y + 1][n_x] |
1678 | 1678 | weit[n_y][n_x] += 1 |
1679 | | if n_x != len_x - 1 and numpy.isfinite(image[n_y][n_x + 1]): |
| 1679 | if n_x != len_x - 1 and np.isfinite(image[n_y][n_x + 1]): |
1680 | 1680 | temp_image[n_y][n_x] += image[n_y][n_x + 1] |
1681 | 1681 | weit[n_y][n_x] += 1 |
1682 | 1682 | # go 4 next nearest neighbors when no non-zero |
1683 | 1683 | # neighbor exists |
1684 | | if n_y != 0 and n_x != 0 and\ |
1685 | | numpy.isfinite(image[n_y - 1][n_x - 1]): |
| 1684 | if n_y != 0 and n_x != 0 and \ |
| 1685 | np.isfinite(image[n_y - 1][n_x - 1]): |
1686 | 1686 | temp_image[n_y][n_x] += image[n_y - 1][n_x - 1] |
1687 | 1687 | weit[n_y][n_x] += 1 |
1688 | 1688 | if n_y != len_y - 1 and n_x != 0 and \ |
1689 | | numpy.isfinite(image[n_y + 1][n_x - 1]): |
| 1689 | np.isfinite(image[n_y + 1][n_x - 1]): |
1690 | 1690 | temp_image[n_y][n_x] += image[n_y + 1][n_x - 1] |
1691 | 1691 | weit[n_y][n_x] += 1 |
1692 | 1692 | if n_y != len_y and n_x != len_x - 1 and \ |
1693 | | numpy.isfinite(image[n_y - 1][n_x + 1]): |
| 1693 | np.isfinite(image[n_y - 1][n_x + 1]): |
1694 | 1694 | temp_image[n_y][n_x] += image[n_y - 1][n_x + 1] |
1695 | 1695 | weit[n_y][n_x] += 1 |
1696 | 1696 | if n_y != len_y - 1 and n_x != len_x - 1 and \ |
1697 | | numpy.isfinite(image[n_y + 1][n_x + 1]): |
| 1697 | np.isfinite(image[n_y + 1][n_x + 1]): |
1698 | 1698 | temp_image[n_y][n_x] += image[n_y + 1][n_x + 1] |
1699 | 1699 | weit[n_y][n_x] += 1 |
-
rdd5bf63
|
r9a5097c
|
|
2 | 2 | from plottables import Theory1D |
3 | 3 | import math |
4 | | import numpy |
| 4 | import numpy as np |
5 | 5 | import fittings |
6 | 6 | import transform |
… |
… |
|
482 | 482 | |
483 | 483 | if self.xLabel.lower() == "log10(x)": |
484 | | tempdy = numpy.asarray(tempdy) |
| 484 | tempdy = np.asarray(tempdy) |
485 | 485 | tempdy[tempdy == 0] = 1 |
486 | 486 | chisqr, out, cov = fittings.sasfit(self.model, |
… |
… |
|
491 | 491 | math.log10(xmax)) |
492 | 492 | else: |
493 | | tempdy = numpy.asarray(tempdy) |
| 493 | tempdy = np.asarray(tempdy) |
494 | 494 | tempdy[tempdy == 0] = 1 |
495 | 495 | chisqr, out, cov = fittings.sasfit(self.model, |
… |
… |
|
572 | 572 | if self.rg_on: |
573 | 573 | if self.Rg_tctr.IsShown(): |
574 | | rg = numpy.sqrt(-3 * float(cstA)) |
| 574 | rg = np.sqrt(-3 * float(cstA)) |
575 | 575 | value = format_number(rg) |
576 | 576 | self.Rg_tctr.SetValue(value) |
577 | 577 | if self.I0_tctr.IsShown(): |
578 | | val = numpy.exp(cstB) |
| 578 | val = np.exp(cstB) |
579 | 579 | self.I0_tctr.SetValue(format_number(val)) |
580 | 580 | if self.Rgerr_tctr.IsShown(): |
… |
… |
|
585 | 585 | self.Rgerr_tctr.SetValue(value) |
586 | 586 | if self.I0err_tctr.IsShown(): |
587 | | val = numpy.abs(numpy.exp(cstB) * errB) |
| 587 | val = np.abs(np.exp(cstB) * errB) |
588 | 588 | self.I0err_tctr.SetValue(format_number(val)) |
589 | 589 | if self.Diameter_tctr.IsShown(): |
590 | | rg = numpy.sqrt(-2 * float(cstA)) |
591 | | _diam = 4 * numpy.sqrt(-float(cstA)) |
| 590 | rg = np.sqrt(-2 * float(cstA)) |
| 591 | _diam = 4 * np.sqrt(-float(cstA)) |
592 | 592 | value = format_number(_diam) |
593 | 593 | self.Diameter_tctr.SetValue(value) |
-
ra9f579c
|
r9a5097c
|
|
43 | 43 | # Support for ancient python versions |
44 | 44 | import copy |
45 | | import numpy |
| 45 | import numpy as np |
46 | 46 | import sys |
47 | 47 | import logging |
… |
… |
|
706 | 706 | self.dy = None |
707 | 707 | if not has_err_x: |
708 | | dx = numpy.zeros(len(x)) |
| 708 | dx = np.zeros(len(x)) |
709 | 709 | if not has_err_y: |
710 | | dy = numpy.zeros(len(y)) |
| 710 | dy = np.zeros(len(y)) |
711 | 711 | for i in range(len(x)): |
712 | 712 | try: |
… |
… |
|
796 | 796 | tempdy = [] |
797 | 797 | if self.dx == None: |
798 | | self.dx = numpy.zeros(len(self.x)) |
| 798 | self.dx = np.zeros(len(self.x)) |
799 | 799 | if self.dy == None: |
800 | | self.dy = numpy.zeros(len(self.y)) |
| 800 | self.dy = np.zeros(len(self.y)) |
801 | 801 | if self.xLabel == "log10(x)": |
802 | 802 | for i in range(len(self.x)): |
… |
… |
|
826 | 826 | tempdy = [] |
827 | 827 | if self.dx == None: |
828 | | self.dx = numpy.zeros(len(self.x)) |
| 828 | self.dx = np.zeros(len(self.x)) |
829 | 829 | if self.dy == None: |
830 | | self.dy = numpy.zeros(len(self.y)) |
| 830 | self.dy = np.zeros(len(self.y)) |
831 | 831 | if self.yLabel == "log10(y)": |
832 | 832 | for i in range(len(self.x)): |
… |
… |
|
859 | 859 | tempdy = [] |
860 | 860 | if self.dx == None: |
861 | | self.dx = numpy.zeros(len(self.x)) |
| 861 | self.dx = np.zeros(len(self.x)) |
862 | 862 | if self.dy == None: |
863 | | self.dy = numpy.zeros(len(self.y)) |
| 863 | self.dy = np.zeros(len(self.y)) |
864 | 864 | if xmin != None and xmax != None: |
865 | 865 | for i in range(len(self.x)): |
… |
… |
|
1228 | 1228 | |
1229 | 1229 | def sample_graph(): |
1230 | | import numpy as nx |
| 1230 | import numpy as np |
1231 | 1231 | |
1232 | 1232 | # Construct a simple graph |
1233 | 1233 | if False: |
1234 | | x = nx.array([1, 2, 3, 4, 5, 6], 'd') |
1235 | | y = nx.array([4, 5, 6, 5, 4, 5], 'd') |
1236 | | dy = nx.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) |
| 1234 | x = np.array([1, 2, 3, 4, 5, 6], 'd') |
| 1235 | y = np.array([4, 5, 6, 5, 4, 5], 'd') |
| 1236 | dy = np.array([0.2, 0.3, 0.1, 0.2, 0.9, 0.3]) |
1237 | 1237 | else: |
1238 | | x = nx.linspace(0, 1., 10000) |
1239 | | y = nx.sin(2 * nx.pi * x * 2.8) |
1240 | | dy = nx.sqrt(100 * nx.abs(y)) / 100 |
| 1238 | x = np.linspace(0, 1., 10000) |
| 1239 | y = np.sin(2 * np.pi * x * 2.8) |
| 1240 | dy = np.sqrt(100 * np.abs(y)) / 100 |
1241 | 1241 | data = Data1D(x, y, dy=dy) |
1242 | 1242 | data.xaxis('distance', 'm') |
-
rb699768
|
r9a5097c
|
|
568 | 568 | |
569 | 569 | def load(path = "sphere_60_q0_2.txt"): |
570 | | import numpy, math, sys |
| 570 | import numpy as np |
| 571 | import math |
| 572 | import sys |
571 | 573 | # Read the data from the data file |
572 | | data_x = numpy.zeros(0) |
573 | | data_y = numpy.zeros(0) |
574 | | data_err = numpy.zeros(0) |
| 574 | data_x = np.zeros(0) |
| 575 | data_y = np.zeros(0) |
| 576 | data_err = np.zeros(0) |
575 | 577 | scale = None |
576 | 578 | if not path == None: |
… |
… |
|
589 | 591 | scale = 0.15*math.sqrt(y) |
590 | 592 | err = scale*math.sqrt(y) |
591 | | data_x = numpy.append(data_x, x) |
592 | | data_y = numpy.append(data_y, y) |
593 | | data_err = numpy.append(data_err, err) |
| 593 | data_x = np.append(data_x, x) |
| 594 | data_y = np.append(data_y, y) |
| 595 | data_err = np.append(data_err, err) |
594 | 596 | except: |
595 | 597 | pass |
-
ref908db
|
r9a5097c
|
|
8 | 8 | from sas.sascalc.calculator import sas_gen |
9 | 9 | |
10 | | import numpy |
11 | | |
12 | | import os.path |
13 | 10 | |
14 | 11 | class sas_gen_test(unittest.TestCase): |
… |
… |
|
51 | 48 | self.assertEqual(output.pos_z[0], 0.0) |
52 | 49 | |
| 50 | |
53 | 51 | if __name__ == '__main__': |
54 | 52 | unittest.main() |
55 | | |
| 53 | |
-
rb699768
|
r9a5097c
|
|
8 | 8 | copyright 2008, University of Tennessee |
9 | 9 | """ |
10 | | import numpy, os |
| 10 | import os |
| 11 | import numpy as np |
11 | 12 | from sas.sascalc.dataloader.data_info import Data1D |
12 | 13 | |
… |
… |
|
40 | 41 | buff = input_f.read() |
41 | 42 | lines = buff.split('\n') |
42 | | x = numpy.zeros(0) |
43 | | y = numpy.zeros(0) |
44 | | dy = numpy.zeros(0) |
| 43 | x = np.zeros(0) |
| 44 | y = np.zeros(0) |
| 45 | dy = np.zeros(0) |
45 | 46 | output = Data1D(x, y, dy=dy) |
46 | 47 | self.filename = output.filename = basename |
47 | 48 | |
48 | 49 | for line in lines: |
49 | | x = numpy.append(x, float(line)) |
| 50 | x = np.append(x, float(line)) |
50 | 51 | |
51 | 52 | output.x = x |
-
r5f26aa4
|
r9a5097c
|
|
4 | 4 | |
5 | 5 | import unittest |
6 | | import numpy, math |
| 6 | import numpy as np |
7 | 7 | from sas.sascalc.dataloader.loader import Loader |
8 | 8 | from sas.sascalc.dataloader.data_info import Data1D |
9 | 9 | |
10 | | import os.path |
11 | 10 | |
12 | 11 | class abs_reader(unittest.TestCase): |
… |
… |
|
313 | 312 | from sas.sascalc.dataloader.readers.cansas_reader import Reader |
314 | 313 | r = Reader() |
315 | | x = numpy.ones(5) |
316 | | y = numpy.ones(5) |
317 | | dy = numpy.ones(5) |
| 314 | x = np.ones(5) |
| 315 | y = np.ones(5) |
| 316 | dy = np.ones(5) |
318 | 317 | |
319 | 318 | filename = "write_test.xml" |
-
rb699768
|
r9a5097c
|
|
1 | 1 | |
2 | 2 | import unittest |
| 3 | import math |
3 | 4 | |
4 | 5 | from sas.sascalc.dataloader.loader import Loader |
5 | 6 | from sas.sascalc.dataloader.manipulations import Ring, CircularAverage, SectorPhi, get_q,reader2D_converter |
6 | | |
7 | | import os.path |
8 | | import numpy, math |
| 7 | |
| 8 | import numpy as np |
9 | 9 | import sas.sascalc.dataloader.data_info as data_info |
10 | 10 | |
… |
… |
|
18 | 18 | should return the predefined height of the distribution (1.0). |
19 | 19 | """ |
20 | | x_0 = numpy.ones([100,100]) |
21 | | dx_0 = numpy.ones([100,100]) |
| 20 | x_0 = np.ones([100,100]) |
| 21 | dx_0 = np.ones([100,100]) |
22 | 22 | |
23 | 23 | self.data = data_info.Data2D(data=x_0, err_data=dx_0) |
… |
… |
|
42 | 42 | |
43 | 43 | self.qstep = len(x_0) |
44 | | x= numpy.linspace(start= -1*self.qmax, |
| 44 | x= np.linspace(start= -1*self.qmax, |
45 | 45 | stop= self.qmax, |
46 | 46 | num= self.qstep, |
47 | 47 | endpoint=True ) |
48 | | y = numpy.linspace(start= -1*self.qmax, |
| 48 | y = np.linspace(start= -1*self.qmax, |
49 | 49 | stop= self.qmax, |
50 | 50 | num= self.qstep, |
-