Changeset b2b3009d in sasview for src/sas/sascalc/dataloader/manipulations.py
- Timestamp:
- Apr 4, 2017 12:00:30 PM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- f68d503
- Parents:
- 571bf4b (diff), ed2276f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Andrew Jackson <andrew.jackson@…> (04/04/17 12:00:30)
- git-committer:
- GitHub <noreply@…> (04/04/17 12:00:30)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/manipulations.py
r36d69e1 red2276f 14 14 #TODO: copy the meta data from the 2D object to the resulting 1D object 15 15 import math 16 import numpy 16 import numpy as np 17 17 18 18 #from data_info import plottable_2D … … 82 82 if data2d.data is None or data2d.x_bins is None or data2d.y_bins is None: 83 83 raise ValueError, "Can't convert this data: data=None..." 84 new_x = n umpy.tile(data2d.x_bins, (len(data2d.y_bins), 1))85 new_y = n umpy.tile(data2d.y_bins, (len(data2d.x_bins), 1))84 new_x = np.tile(data2d.x_bins, (len(data2d.y_bins), 1)) 85 new_y = np.tile(data2d.y_bins, (len(data2d.x_bins), 1)) 86 86 new_y = new_y.swapaxes(0, 1) 87 87 … … 89 89 qx_data = new_x.flatten() 90 90 qy_data = new_y.flatten() 91 q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 92 if data2d.err_data is None or numpy.any(data2d.err_data <= 0): 93 new_err_data = numpy.sqrt(numpy.abs(new_data)) 91 q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 92 if data2d.err_data == None or np.any(data2d.err_data <= 0): 93 new_err_data = np.sqrt(np.abs(new_data)) 94 94 95 else: 95 96 new_err_data = data2d.err_data.flatten() 96 mask = n umpy.ones(len(new_data), dtype=bool)97 mask = np.ones(len(new_data), dtype=bool) 97 98 98 99 #TODO: make sense of the following two lines... … … 149 150 150 151 # Get data 151 data = data2D.data[n umpy.isfinite(data2D.data)]152 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]153 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]154 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]152 data = data2D.data[np.isfinite(data2D.data)] 153 err_data = data2D.err_data[np.isfinite(data2D.data)] 154 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 155 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 155 156 156 157 # Build array of Q intervals … … 170 171 raise RuntimeError, "_Slab._avg: unrecognized axis %s" % str(maj) 171 172 172 x = n umpy.zeros(nbins)173 y = n umpy.zeros(nbins)174 err_y = n umpy.zeros(nbins)175 y_counts = n umpy.zeros(nbins)173 x = np.zeros(nbins) 174 y = np.zeros(nbins) 175 err_y = np.zeros(nbins) 176 y_counts = np.zeros(nbins) 176 177 177 178 # Average pixelsize in q space … … 225 226 y = y / y_counts 226 227 x = x / y_counts 227 idx = (n umpy.isfinite(y) & numpy.isfinite(x))228 idx = (np.isfinite(y) & np.isfinite(x)) 228 229 229 230 if not idx.any(): … … 304 305 raise RuntimeError, msg 305 306 # Get data 306 data = data2D.data[n umpy.isfinite(data2D.data)]307 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]308 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]309 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]307 data = data2D.data[np.isfinite(data2D.data)] 308 err_data = data2D.err_data[np.isfinite(data2D.data)] 309 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 310 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 310 311 311 312 y = 0.0 … … 414 415 """ 415 416 # Get data W/ finite values 416 data = data2D.data[n umpy.isfinite(data2D.data)]417 q_data = data2D.q_data[n umpy.isfinite(data2D.data)]418 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]419 mask_data = data2D.mask[n umpy.isfinite(data2D.data)]417 data = data2D.data[np.isfinite(data2D.data)] 418 q_data = data2D.q_data[np.isfinite(data2D.data)] 419 err_data = data2D.err_data[np.isfinite(data2D.data)] 420 mask_data = data2D.mask[np.isfinite(data2D.data)] 420 421 421 422 dq_data = None … … 448 449 dq_overlap_y *= dq_overlap_y 449 450 450 dq_overlap = n umpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)451 dq_overlap = np.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 451 452 # Final protection of dq 452 453 if dq_overlap < 0: 453 454 dq_overlap = y_min 454 dqx_data = data2D.dqx_data[n umpy.isfinite(data2D.data)]455 dqy_data = data2D.dqy_data[n umpy.isfinite(data2D.data)] - dq_overlap455 dqx_data = data2D.dqx_data[np.isfinite(data2D.data)] 456 dqy_data = data2D.dqy_data[np.isfinite(data2D.data)] - dq_overlap 456 457 # def; dqx_data = dq_r dqy_data = dq_phi 457 458 # Convert dq 2D to 1D here 458 459 dqx = dqx_data * dqx_data 459 460 dqy = dqy_data * dqy_data 460 dq_data = n umpy.add(dqx, dqy)461 dq_data = n umpy.sqrt(dq_data)462 463 #q_data_max = n umpy.max(q_data)461 dq_data = np.add(dqx, dqy) 462 dq_data = np.sqrt(dq_data) 463 464 #q_data_max = np.max(q_data) 464 465 if len(data2D.q_data) == None: 465 466 msg = "Circular averaging: invalid q_data: %g" % data2D.q_data … … 469 470 nbins = int(math.ceil((self.r_max - self.r_min) / self.bin_width)) 470 471 471 x = n umpy.zeros(nbins)472 y = n umpy.zeros(nbins)473 err_y = n umpy.zeros(nbins)474 err_x = n umpy.zeros(nbins)475 y_counts = n umpy.zeros(nbins)472 x = np.zeros(nbins) 473 y = np.zeros(nbins) 474 err_y = np.zeros(nbins) 475 err_x = np.zeros(nbins) 476 y_counts = np.zeros(nbins) 476 477 477 478 for npt in range(len(data)): … … 527 528 528 529 err_y = err_y / y_counts 529 err_y[err_y == 0] = n umpy.average(err_y)530 err_y[err_y == 0] = np.average(err_y) 530 531 y = y / y_counts 531 532 x = x / y_counts 532 idx = (n umpy.isfinite(y)) & (numpy.isfinite(x))533 idx = (np.isfinite(y)) & (np.isfinite(x)) 533 534 534 535 if err_x != None: … … 585 586 586 587 # Get data 587 data = data2D.data[n umpy.isfinite(data2D.data)]588 q_data = data2D.q_data[n umpy.isfinite(data2D.data)]589 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]590 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]591 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]588 data = data2D.data[np.isfinite(data2D.data)] 589 q_data = data2D.q_data[np.isfinite(data2D.data)] 590 err_data = data2D.err_data[np.isfinite(data2D.data)] 591 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 592 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 592 593 593 594 # Set space for 1d outputs 594 phi_bins = n umpy.zeros(self.nbins_phi)595 phi_counts = n umpy.zeros(self.nbins_phi)596 phi_values = n umpy.zeros(self.nbins_phi)597 phi_err = n umpy.zeros(self.nbins_phi)595 phi_bins = np.zeros(self.nbins_phi) 596 phi_counts = np.zeros(self.nbins_phi) 597 phi_values = np.zeros(self.nbins_phi) 598 phi_err = np.zeros(self.nbins_phi) 598 599 599 600 # Shift to apply to calculated phi values in order … … 636 637 phi_values[i] = 2.0 * math.pi / self.nbins_phi * (1.0 * i) 637 638 638 idx = (n umpy.isfinite(phi_bins))639 idx = (np.isfinite(phi_bins)) 639 640 640 641 if not idx.any(): … … 769 770 770 771 # Get the all data & info 771 data = data2D.data[n umpy.isfinite(data2D.data)]772 q_data = data2D.q_data[n umpy.isfinite(data2D.data)]773 err_data = data2D.err_data[n umpy.isfinite(data2D.data)]774 qx_data = data2D.qx_data[n umpy.isfinite(data2D.data)]775 qy_data = data2D.qy_data[n umpy.isfinite(data2D.data)]772 data = data2D.data[np.isfinite(data2D.data)] 773 q_data = data2D.q_data[np.isfinite(data2D.data)] 774 err_data = data2D.err_data[np.isfinite(data2D.data)] 775 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 776 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 776 777 dq_data = None 777 778 … … 803 804 dq_overlap_y *= dq_overlap_y 804 805 805 dq_overlap = n umpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)806 dq_overlap = np.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 806 807 if dq_overlap < 0: 807 808 dq_overlap = y_min 808 dqx_data = data2D.dqx_data[n umpy.isfinite(data2D.data)]809 dqy_data = data2D.dqy_data[n umpy.isfinite(data2D.data)] - dq_overlap809 dqx_data = data2D.dqx_data[np.isfinite(data2D.data)] 810 dqy_data = data2D.dqy_data[np.isfinite(data2D.data)] - dq_overlap 810 811 # def; dqx_data = dq_r dqy_data = dq_phi 811 812 # Convert dq 2D to 1D here 812 813 dqx = dqx_data * dqx_data 813 814 dqy = dqy_data * dqy_data 814 dq_data = n umpy.add(dqx, dqy)815 dq_data = n umpy.sqrt(dq_data)815 dq_data = np.add(dqx, dqy) 816 dq_data = np.sqrt(dq_data) 816 817 817 818 #set space for 1d outputs 818 x = n umpy.zeros(self.nbins)819 y = n umpy.zeros(self.nbins)820 y_err = n umpy.zeros(self.nbins)821 x_err = n umpy.zeros(self.nbins)822 y_counts = n umpy.zeros(self.nbins)819 x = np.zeros(self.nbins) 820 y = np.zeros(self.nbins) 821 y_err = np.zeros(self.nbins) 822 x_err = np.zeros(self.nbins) 823 y_counts = np.zeros(self.nbins) 823 824 824 825 # Get the min and max into the region: 0 <= phi < 2Pi … … 923 924 #x[i] = math.sqrt((r_inner * r_inner + r_outer * r_outer) / 2) 924 925 x[i] = x[i] / y_counts[i] 925 y_err[y_err == 0] = n umpy.average(y_err)926 idx = (n umpy.isfinite(y) & numpy.isfinite(y_err))926 y_err[y_err == 0] = np.average(y_err) 927 idx = (np.isfinite(y) & np.isfinite(y_err)) 927 928 if x_err != None: 928 929 d_x = x_err[idx] / y_counts[idx] … … 1012 1013 qx_data = data2D.qx_data 1013 1014 qy_data = data2D.qy_data 1014 q_data = n umpy.sqrt(qx_data * qx_data + qy_data * qy_data)1015 q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 1015 1016 1016 1017 # check whether or not the data point is inside ROI … … 1113 1114 1114 1115 # get phi from data 1115 phi_data = n umpy.arctan2(qy_data, qx_data)1116 phi_data = np.arctan2(qy_data, qx_data) 1116 1117 1117 1118 # Get the min and max into the region: -pi <= phi < Pi
Note: See TracChangeset
for help on using the changeset viewer.