Changeset dd11014 in sasview
- Timestamp:
- Apr 4, 2017 1:00:50 PM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 7b15990, a2e980b, 4b81e01, 3a33740
- Parents:
- 1779e72
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/manipulations.py
red2276f rdd11014 14 14 #TODO: copy the meta data from the 2D object to the resulting 1D object 15 15 import math 16 import numpy as np16 import numpy 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 p.tile(data2d.x_bins, (len(data2d.y_bins), 1))85 new_y = n p.tile(data2d.y_bins, (len(data2d.x_bins), 1))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)) 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 = 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 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)) 95 94 else: 96 95 new_err_data = data2d.err_data.flatten() 97 mask = n p.ones(len(new_data), dtype=bool)96 mask = numpy.ones(len(new_data), dtype=bool) 98 97 99 98 #TODO: make sense of the following two lines... … … 150 149 151 150 # Get data 152 data = data2D.data[n p.isfinite(data2D.data)]153 err_data = data2D.err_data[n p.isfinite(data2D.data)]154 qx_data = data2D.qx_data[n p.isfinite(data2D.data)]155 qy_data = data2D.qy_data[n p.isfinite(data2D.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)] 156 155 157 156 # Build array of Q intervals … … 171 170 raise RuntimeError, "_Slab._avg: unrecognized axis %s" % str(maj) 172 171 173 x = n p.zeros(nbins)174 y = n p.zeros(nbins)175 err_y = n p.zeros(nbins)176 y_counts = n p.zeros(nbins)172 x = numpy.zeros(nbins) 173 y = numpy.zeros(nbins) 174 err_y = numpy.zeros(nbins) 175 y_counts = numpy.zeros(nbins) 177 176 178 177 # Average pixelsize in q space … … 226 225 y = y / y_counts 227 226 x = x / y_counts 228 idx = (n p.isfinite(y) & np.isfinite(x))227 idx = (numpy.isfinite(y) & numpy.isfinite(x)) 229 228 230 229 if not idx.any(): … … 305 304 raise RuntimeError, msg 306 305 # Get data 307 data = data2D.data[n p.isfinite(data2D.data)]308 err_data = data2D.err_data[n p.isfinite(data2D.data)]309 qx_data = data2D.qx_data[n p.isfinite(data2D.data)]310 qy_data = data2D.qy_data[n p.isfinite(data2D.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)] 311 310 312 311 y = 0.0 … … 415 414 """ 416 415 # Get data W/ finite values 417 data = data2D.data[n p.isfinite(data2D.data)]418 q_data = data2D.q_data[n p.isfinite(data2D.data)]419 err_data = data2D.err_data[n p.isfinite(data2D.data)]420 mask_data = data2D.mask[n p.isfinite(data2D.data)]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)] 421 420 422 421 dq_data = None … … 449 448 dq_overlap_y *= dq_overlap_y 450 449 451 dq_overlap = n p.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)450 dq_overlap = numpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 452 451 # Final protection of dq 453 452 if dq_overlap < 0: 454 453 dq_overlap = y_min 455 dqx_data = data2D.dqx_data[n p.isfinite(data2D.data)]456 dqy_data = data2D.dqy_data[n p.isfinite(data2D.data)] - dq_overlap454 dqx_data = data2D.dqx_data[numpy.isfinite(data2D.data)] 455 dqy_data = data2D.dqy_data[numpy.isfinite(data2D.data)] - dq_overlap 457 456 # def; dqx_data = dq_r dqy_data = dq_phi 458 457 # Convert dq 2D to 1D here 459 458 dqx = dqx_data * dqx_data 460 459 dqy = dqy_data * dqy_data 461 dq_data = n p.add(dqx, dqy)462 dq_data = n p.sqrt(dq_data)463 464 #q_data_max = n p.max(q_data)460 dq_data = numpy.add(dqx, dqy) 461 dq_data = numpy.sqrt(dq_data) 462 463 #q_data_max = numpy.max(q_data) 465 464 if len(data2D.q_data) == None: 466 465 msg = "Circular averaging: invalid q_data: %g" % data2D.q_data … … 470 469 nbins = int(math.ceil((self.r_max - self.r_min) / self.bin_width)) 471 470 472 x = n p.zeros(nbins)473 y = n p.zeros(nbins)474 err_y = n p.zeros(nbins)475 err_x = n p.zeros(nbins)476 y_counts = n p.zeros(nbins)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) 477 476 478 477 for npt in range(len(data)): … … 528 527 529 528 err_y = err_y / y_counts 530 err_y[err_y == 0] = n p.average(err_y)529 err_y[err_y == 0] = numpy.average(err_y) 531 530 y = y / y_counts 532 531 x = x / y_counts 533 idx = (n p.isfinite(y)) & (np.isfinite(x))532 idx = (numpy.isfinite(y)) & (numpy.isfinite(x)) 534 533 535 534 if err_x != None: … … 586 585 587 586 # Get data 588 data = data2D.data[n p.isfinite(data2D.data)]589 q_data = data2D.q_data[n p.isfinite(data2D.data)]590 err_data = data2D.err_data[n p.isfinite(data2D.data)]591 qx_data = data2D.qx_data[n p.isfinite(data2D.data)]592 qy_data = data2D.qy_data[n p.isfinite(data2D.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)] 593 592 594 593 # Set space for 1d outputs 595 phi_bins = n p.zeros(self.nbins_phi)596 phi_counts = n p.zeros(self.nbins_phi)597 phi_values = n p.zeros(self.nbins_phi)598 phi_err = n p.zeros(self.nbins_phi)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) 599 598 600 599 # Shift to apply to calculated phi values in order … … 637 636 phi_values[i] = 2.0 * math.pi / self.nbins_phi * (1.0 * i) 638 637 639 idx = (n p.isfinite(phi_bins))638 idx = (numpy.isfinite(phi_bins)) 640 639 641 640 if not idx.any(): … … 770 769 771 770 # Get the all data & info 772 data = data2D.data[n p.isfinite(data2D.data)]773 q_data = data2D.q_data[n p.isfinite(data2D.data)]774 err_data = data2D.err_data[n p.isfinite(data2D.data)]775 qx_data = data2D.qx_data[n p.isfinite(data2D.data)]776 qy_data = data2D.qy_data[n p.isfinite(data2D.data)]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)] 777 776 dq_data = None 778 777 … … 804 803 dq_overlap_y *= dq_overlap_y 805 804 806 dq_overlap = n p.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)805 dq_overlap = numpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 807 806 if dq_overlap < 0: 808 807 dq_overlap = y_min 809 dqx_data = data2D.dqx_data[n p.isfinite(data2D.data)]810 dqy_data = data2D.dqy_data[n p.isfinite(data2D.data)] - dq_overlap808 dqx_data = data2D.dqx_data[numpy.isfinite(data2D.data)] 809 dqy_data = data2D.dqy_data[numpy.isfinite(data2D.data)] - dq_overlap 811 810 # def; dqx_data = dq_r dqy_data = dq_phi 812 811 # Convert dq 2D to 1D here 813 812 dqx = dqx_data * dqx_data 814 813 dqy = dqy_data * dqy_data 815 dq_data = n p.add(dqx, dqy)816 dq_data = n p.sqrt(dq_data)814 dq_data = numpy.add(dqx, dqy) 815 dq_data = numpy.sqrt(dq_data) 817 816 818 817 #set space for 1d outputs 819 x = n p.zeros(self.nbins)820 y = n p.zeros(self.nbins)821 y_err = n p.zeros(self.nbins)822 x_err = n p.zeros(self.nbins)823 y_counts = n p.zeros(self.nbins)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) 824 823 825 824 # Get the min and max into the region: 0 <= phi < 2Pi … … 924 923 #x[i] = math.sqrt((r_inner * r_inner + r_outer * r_outer) / 2) 925 924 x[i] = x[i] / y_counts[i] 926 y_err[y_err == 0] = n p.average(y_err)927 idx = (n p.isfinite(y) & np.isfinite(y_err))925 y_err[y_err == 0] = numpy.average(y_err) 926 idx = (numpy.isfinite(y) & numpy.isfinite(y_err)) 928 927 if x_err != None: 929 928 d_x = x_err[idx] / y_counts[idx] … … 1013 1012 qx_data = data2D.qx_data 1014 1013 qy_data = data2D.qy_data 1015 q_data = n p.sqrt(qx_data * qx_data + qy_data * qy_data)1014 q_data = numpy.sqrt(qx_data * qx_data + qy_data * qy_data) 1016 1015 1017 1016 # check whether or not the data point is inside ROI … … 1114 1113 1115 1114 # get phi from data 1116 phi_data = n p.arctan2(qy_data, qx_data)1115 phi_data = numpy.arctan2(qy_data, qx_data) 1117 1116 1118 1117 # Get the min and max into the region: -pi <= phi < Pi -
src/sas/sascalc/dataloader/readers/IgorReader.py
red2276f rdd11014 14 14 import os 15 15 16 import numpy as np17 import math18 #import logging19 20 16 from sas.sascalc.dataloader.data_info import Data2D 21 17 from sas.sascalc.dataloader.data_info import Detector 22 18 from sas.sascalc.dataloader.manipulations import reader2D_converter 19 import numpy as np 23 20 24 21 # Look for unit converter … … 65 62 data_conv_i(1.0, output.I_unit) 66 63 67 for line in lines:68 69 # Find setup info line70 if isInfo:71 isInfo = False72 line_toks = line.split()73 # Wavelength in Angstrom74 try:75 wavelength = float(line_toks[1])76 except:77 msg = "IgorReader: can't read this file, missing wavelength"78 raise ValueError, msg79 80 #Find # of bins in a row assuming the detector is square.81 if dataStarted == True:82 try:83 value = float(line)84 except:85 # Found a non-float entry, skip it86 continue87 88 # Get total bin number89 90 i_tot_row += 191 i_tot_row = math.ceil(math.sqrt(i_tot_row)) - 192 #print "i_tot", i_tot_row93 size_x = i_tot_row # 192#12894 size_y = i_tot_row # 192#12895 output.data = np.zeros([size_x, size_y])96 output.err_data = np.zeros([size_x, size_y])97 98 64 data_row = 0 99 65 wavelength = distance = center_x = center_y = None -
test/sasdataloader/test/utest_abs_reader.py
red2276f rdd11014 4 4 5 5 import unittest 6 7 6 import math 8 7 import numpy as np … … 11 10 from sas.sascalc.dataloader.data_info import Data1D 12 11 12 import os.path 13 13 14 14 class abs_reader(unittest.TestCase):
Note: See TracChangeset
for help on using the changeset viewer.