- Timestamp:
- May 10, 2017 9:39:17 AM (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:
- e0ebd56
- Parents:
- 914c49d5
- Location:
- src/sas
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sascalc/dataloader/manipulations.py
r3e5648b r8e15dce 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 = n umpy.sqrt(qx_data * qx_data + qy_data * qy_data)92 if data2d.err_data is None or n umpy.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 is 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 … … 430 430 z_max = max(data2D.q_data) 431 431 z_min = min(data2D.q_data) 432 x_max = data2D.dqx_data[numpy.where(data2D.q_data == z_max)]433 x_min = data2D.dqx_data[numpy.where(data2D.q_data == z_min)]434 y_max = data2D.dqy_data[numpy.where(data2D.q_data == z_max)]435 y_min = data2D.dqy_data[numpy.where(data2D.q_data == z_min)]432 dqx_at_z_max = data2D.dqx_data[np.argmax(data2D.q_data)] 433 dqx_at_z_min = data2D.dqx_data[np.argmin(data2D.q_data)] 434 dqy_at_z_max = data2D.dqy_data[np.argmax(data2D.q_data)] 435 dqy_at_z_min = data2D.dqy_data[np.argmin(data2D.q_data)] 436 436 # Find qdx at q = 0 437 dq_overlap_x = (x_min * z_max - x_max * z_min) / (z_max - z_min) 437 dq_overlap_x = ((dqx_at_z_min * z_max - dqx_at_z_max * z_min) / 438 (z_max - z_min)) 438 439 # when extrapolation goes wrong 439 440 if dq_overlap_x > min(data2D.dqx_data): … … 441 442 dq_overlap_x *= dq_overlap_x 442 443 # Find qdx at q = 0 443 dq_overlap_y = (y_min * z_max - y_max * z_min) / (z_max - z_min) 444 dq_overlap_y = ((dqy_at_z_min * z_max - dqy_at_z_max * z_min) / 445 (z_max - z_min)) 444 446 # when extrapolation goes wrong 445 447 if dq_overlap_y > min(data2D.dqy_data): … … 448 450 dq_overlap_y *= dq_overlap_y 449 451 450 dq_overlap = n umpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)452 dq_overlap = np.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 451 453 # Final protection of dq 452 454 if dq_overlap < 0: 453 dq_overlap = y_min454 dqx_data = data2D.dqx_data[n umpy.isfinite(data2D.data)]455 dqy_data = data2D.dqy_data[n umpy.isfinite(data2D.data)] - dq_overlap455 dq_overlap = dqy_at_z_min 456 dqx_data = data2D.dqx_data[np.isfinite(data2D.data)] 457 dqy_data = data2D.dqy_data[np.isfinite(data2D.data)] - dq_overlap 456 458 # def; dqx_data = dq_r dqy_data = dq_phi 457 459 # Convert dq 2D to 1D here 458 460 dqx = dqx_data * dqx_data 459 461 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)462 dq_data = np.add(dqx, dqy) 463 dq_data = np.sqrt(dq_data) 464 465 #q_data_max = np.max(q_data) 464 466 if len(data2D.q_data) is None: 465 467 msg = "Circular averaging: invalid q_data: %g" % data2D.q_data … … 469 471 nbins = int(math.ceil((self.r_max - self.r_min) / self.bin_width)) 470 472 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)473 x = np.zeros(nbins) 474 y = np.zeros(nbins) 475 err_y = np.zeros(nbins) 476 err_x = np.zeros(nbins) 477 y_counts = np.zeros(nbins) 476 478 477 479 for npt in range(len(data)): … … 527 529 528 530 err_y = err_y / y_counts 529 err_y[err_y == 0] = n umpy.average(err_y)531 err_y[err_y == 0] = np.average(err_y) 530 532 y = y / y_counts 531 533 x = x / y_counts 532 idx = (n umpy.isfinite(y)) & (numpy.isfinite(x))534 idx = (np.isfinite(y)) & (np.isfinite(x)) 533 535 534 536 if err_x is not None: … … 585 587 586 588 # 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)]589 data = data2D.data[np.isfinite(data2D.data)] 590 q_data = data2D.q_data[np.isfinite(data2D.data)] 591 err_data = data2D.err_data[np.isfinite(data2D.data)] 592 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 593 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 592 594 593 595 # 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)596 phi_bins = np.zeros(self.nbins_phi) 597 phi_counts = np.zeros(self.nbins_phi) 598 phi_values = np.zeros(self.nbins_phi) 599 phi_err = np.zeros(self.nbins_phi) 598 600 599 601 # Shift to apply to calculated phi values in order … … 636 638 phi_values[i] = 2.0 * math.pi / self.nbins_phi * (1.0 * i) 637 639 638 idx = (n umpy.isfinite(phi_bins))640 idx = (np.isfinite(phi_bins)) 639 641 640 642 if not idx.any(): … … 769 771 770 772 # 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)]773 data = data2D.data[np.isfinite(data2D.data)] 774 q_data = data2D.q_data[np.isfinite(data2D.data)] 775 err_data = data2D.err_data[np.isfinite(data2D.data)] 776 qx_data = data2D.qx_data[np.isfinite(data2D.data)] 777 qy_data = data2D.qy_data[np.isfinite(data2D.data)] 776 778 dq_data = None 777 779 … … 785 787 z_max = max(data2D.q_data) 786 788 z_min = min(data2D.q_data) 787 x_max = data2D.dqx_data[numpy.where(data2D.q_data == z_max)]788 x_min = data2D.dqx_data[numpy.where(data2D.q_data == z_min)]789 y_max = data2D.dqy_data[numpy.where(data2D.q_data == z_max)]790 y_min = data2D.dqy_data[numpy.where(data2D.q_data == z_min)]789 dqx_at_z_max = data2D.dqx_data[np.argmax(data2D.q_data)] 790 dqx_at_z_min = data2D.dqx_data[np.argmin(data2D.q_data)] 791 dqy_at_z_max = data2D.dqy_data[np.argmax(data2D.q_data)] 792 dqy_at_z_min = data2D.dqy_data[np.argmin(data2D.q_data)] 791 793 # Find qdx at q = 0 792 dq_overlap_x = (x_min * z_max - x_max * z_min) / (z_max - z_min) 794 dq_overlap_x = ((dqx_at_z_min * z_max - dqx_at_z_max * z_min) / 795 (z_max - z_min)) 793 796 # when extrapolation goes wrong 794 797 if dq_overlap_x > min(data2D.dqx_data): … … 796 799 dq_overlap_x *= dq_overlap_x 797 800 # Find qdx at q = 0 798 dq_overlap_y = (y_min * z_max - y_max * z_min) / (z_max - z_min) 801 dq_overlap_y = ((dqy_at_z_min * z_max - dqy_at_z_max * z_min) / 802 (z_max - z_min)) 799 803 # when extrapolation goes wrong 800 804 if dq_overlap_y > min(data2D.dqy_data): … … 803 807 dq_overlap_y *= dq_overlap_y 804 808 805 dq_overlap = n umpy.sqrt((dq_overlap_x + dq_overlap_y) / 2.0)809 dq_overlap = np.sqrt((dq_overlap_x + dq_overlap_y) / 2.0) 806 810 if dq_overlap < 0: 807 dq_overlap = y_min808 dqx_data = data2D.dqx_data[n umpy.isfinite(data2D.data)]809 dqy_data = data2D.dqy_data[n umpy.isfinite(data2D.data)] - dq_overlap811 dq_overlap = dqy_at_z_min 812 dqx_data = data2D.dqx_data[np.isfinite(data2D.data)] 813 dqy_data = data2D.dqy_data[np.isfinite(data2D.data)] - dq_overlap 810 814 # def; dqx_data = dq_r dqy_data = dq_phi 811 815 # Convert dq 2D to 1D here 812 816 dqx = dqx_data * dqx_data 813 817 dqy = dqy_data * dqy_data 814 dq_data = n umpy.add(dqx, dqy)815 dq_data = n umpy.sqrt(dq_data)818 dq_data = np.add(dqx, dqy) 819 dq_data = np.sqrt(dq_data) 816 820 817 821 #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)822 x = np.zeros(self.nbins) 823 y = np.zeros(self.nbins) 824 y_err = np.zeros(self.nbins) 825 x_err = np.zeros(self.nbins) 826 y_counts = np.zeros(self.nbins) 823 827 824 828 # Get the min and max into the region: 0 <= phi < 2Pi … … 923 927 #x[i] = math.sqrt((r_inner * r_inner + r_outer * r_outer) / 2) 924 928 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))929 y_err[y_err == 0] = np.average(y_err) 930 idx = (np.isfinite(y) & np.isfinite(y_err)) 927 931 if x_err is not None: 928 932 d_x = x_err[idx] / y_counts[idx] … … 1012 1016 qx_data = data2D.qx_data 1013 1017 qy_data = data2D.qy_data 1014 q_data = n umpy.sqrt(qx_data * qx_data + qy_data * qy_data)1018 q_data = np.sqrt(qx_data * qx_data + qy_data * qy_data) 1015 1019 1016 1020 # check whether or not the data point is inside ROI … … 1113 1117 1114 1118 # get phi from data 1115 phi_data = n umpy.arctan2(qy_data, qx_data)1119 phi_data = np.arctan2(qy_data, qx_data) 1116 1120 1117 1121 # Get the min and max into the region: -pi <= phi < Pi -
src/sas/sasgui/guiframe/local_perspectives/plotting/parameters_panel_slicer.py
r3e5648b r8e15dce 193 193 name="Append to file name:") 194 194 append_tool_tip = "Files will be saved as <SlicerType><FileName>" 195 append_tool_tip += "<AppendToText>. xml"195 append_tool_tip += "<AppendToText>.txt" 196 196 self.append_name.SetToolTipString(append_tool_tip) 197 197 self.append_name.SetValue(self.default_value) … … 417 417 data_dic[item] = plot.plots[item] 418 418 419 # Save files as XML419 # Save files as Text 420 420 for item, data1d in data_dic.iteritems(): 421 421 base = '.'.join(item.split('.')[:-1]) 422 file_name = base + append + ". xml"422 file_name = base + append + ".txt" 423 423 save_to = evt.path + "\\" + file_name 424 424 writer.write(save_to, data1d) … … 439 439 :param file_list: list of loaded file names to send to fit 440 440 """ 441 if fit != FIT_OPTIONS[0] and file_list is not None: 441 if fit in FIT_OPTIONS and fit != FIT_OPTIONS[0] and \ 442 file_list is not None: 442 443 # Set perspective to fitting 443 444 int = self.data_panel.perspective_cbox.FindString("Fitting")
Note: See TracChangeset
for help on using the changeset viewer.