Changes in src/sas/sascalc/dataloader/manipulations.py [dd11014:9a5097c] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/manipulations.py
rdd11014 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 … … 80 80 81 81 """ 82 if data2d.data is None or data2d.x_bins is None or data2d.y_bins isNone: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 = n umpy.tile(data2d.x_bins, (len(data2d.y_bins), 1))85 new_y = n umpy.tile(data2d.y_bins, (len(data2d.x_bins), 1))84 new_x = np.tile(data2d.x_bins, (len(data2d.y_bins), 1)) 85 new_y = np.tile(data2d.y_bins, (len(data2d.x_bins), 1)) 86 86 new_y = new_y.swapaxes(0, 1) 87 87 … … 89 89 qx_data = new_x.flatten() 90 90 qy_data = new_y.flatten() 91 q_data = n umpy.sqrt(qx_data * qx_data + qy_data * qy_data)92 if data2d.err_data is None or numpy.any(data2d.err_data <= 0):93 new_err_data = n umpy.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 = n umpy.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[n umpy.isfinite(data2D.data)]152 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]153 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]154 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]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 = n umpy.zeros(nbins)173 y = n umpy.zeros(nbins)174 err_y = n umpy.zeros(nbins)175 y_counts = n umpy.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 = (n umpy.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[n umpy.isfinite(data2D.data)]307 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]308 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]309 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]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[n umpy.isfinite(data2D.data)]417 q_data = data2D.q_data[n umpy.isfinite(data2D.data)]418 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]419 mask_data = data2D.mask[n umpy.isfinite(data2D.data)]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 = n umpy.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[n umpy.isfinite(data2D.data)]455 dqy_data = data2D.dqy_data[n umpy.isfinite(data2D.data)] - dq_overlap454 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 = n umpy.add(dqx, dqy)461 dq_data = n umpy.sqrt(dq_data)462 463 #q_data_max = n umpy.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 = n umpy.zeros(nbins)472 y = n umpy.zeros(nbins)473 err_y = n umpy.zeros(nbins)474 err_x = n umpy.zeros(nbins)475 y_counts = n umpy.zeros(nbins)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] = n umpy.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 = (n umpy.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[n umpy.isfinite(data2D.data)]588 q_data = data2D.q_data[n umpy.isfinite(data2D.data)]589 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]590 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]591 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]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 = n umpy.zeros(self.nbins_phi)595 phi_counts = n umpy.zeros(self.nbins_phi)596 phi_values = n umpy.zeros(self.nbins_phi)597 phi_err = n umpy.zeros(self.nbins_phi)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 = (n umpy.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[n umpy.isfinite(data2D.data)]772 q_data = data2D.q_data[n umpy.isfinite(data2D.data)]773 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]774 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]775 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]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 = n umpy.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[n umpy.isfinite(data2D.data)]809 dqy_data = data2D.dqy_data[n umpy.isfinite(data2D.data)] - dq_overlap808 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 = n umpy.add(dqx, dqy)815 dq_data = n umpy.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 = n umpy.zeros(self.nbins)819 y = n umpy.zeros(self.nbins)820 y_err = n umpy.zeros(self.nbins)821 x_err = n umpy.zeros(self.nbins)822 y_counts = n umpy.zeros(self.nbins)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] = n umpy.average(y_err)926 idx = (n umpy.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 = n umpy.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 = n umpy.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
Note: See TracChangeset
for help on using the changeset viewer.