Changeset c6f95bb in sasview
- Timestamp:
- Mar 17, 2010 1:23:48 PM (15 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 43e685d
- Parents:
- 32e8c78
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/manipulations.py
r095ab1b rc6f95bb 132 132 133 133 # Get data 134 data = data2D.data 135 q_data = data2D.q_data 136 err_data = data2D.err_data 137 qx_data = data2D.qx_data 138 qy_data = data2D.qy_data 134 data = data2D.data[numpy.isfinite(data2D.data)] 135 q_data = data2D.q_data[numpy.isfinite(data2D.data)] 136 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 137 qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 138 qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 139 139 140 140 # Build array of Q intervals … … 195 195 196 196 if err_data == None or err_data[npts]==0.0: 197 err_y[i_q] += frac * frac * math.fabs(data[npts]) 197 if data[npts] <0: data[npts] = -data[npts] 198 err_y[i_q] += frac * frac * data[npts] 198 199 else: 199 200 err_y[i_q] += frac * frac * err_data[npts] * err_data[npts] … … 280 281 281 282 # Get data 282 data = data2D.data 283 q_data = data2D.q_data 284 err_data = data2D.err_data 285 qx_data = data2D.qx_data 286 qy_data = data2D.qy_data 283 data = data2D.data[numpy.isfinite(data2D.data)] 284 q_data = data2D.q_data[numpy.isfinite(data2D.data)] 285 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 286 qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 287 qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 287 288 288 289 y = 0.0 … … 312 313 y += frac * data[npts] 313 314 if err_data == None or err_data[npts]==0.0: 314 err_y += frac * frac * math.fabs(data[npts]) 315 if data[npts] <0: data[npts] = -data[npts] 316 err_y += frac * frac * data[npts] 315 317 else: 316 318 err_y += frac * frac * err_data[npts] * err_data[npts] … … 389 391 """ 390 392 # Get data 391 data = data2D.data 392 err_data = data2D.err_data393 q_data = data2D.q_data393 data = data2D.data[numpy.isfinite(data2D.data)] 394 q_data = data2D.q_data[numpy.isfinite(data2D.data)] 395 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 394 396 395 397 q_data_max = numpy.max(q_data) … … 432 434 433 435 if err_data == None or err_data[npt]==0.0: 434 err_y[i_q] += frac * frac * math.fabs(data_n) 436 if data_n <0: data_n = -data_n 437 err_y[i_q] += frac * frac * data_n 435 438 else: 436 439 err_y[i_q] += frac * frac * err_data[npt] * err_data[npt] … … 442 445 # Average the sums 443 446 for n in range(nbins): 447 if err_y[n] <0: err_y[n] = -err_y[n] 444 448 err_y[n] = math.sqrt(err_y[n]) 445 449 … … 495 499 496 500 # Get data 497 data = data2D.data 498 err_data = data2D.err_data499 q_data = data2D.q_data500 qx_data = data2D.qx_data 501 qy_data = data2D.qy_data 502 501 data = data2D.data[numpy.isfinite(data2D.data)] 502 q_data = data2D.q_data[numpy.isfinite(data2D.data)] 503 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 504 qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 505 qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 506 503 507 q_data_max = numpy.max(q_data) 504 508 … … 534 538 535 539 if err_data == None or err_data[npt] ==0.0: 540 if data_n <0: data_n = -data_n 536 541 phi_err[i_phi] += frac * frac * math.fabs(data_n) 537 542 else: … … 680 685 raise RuntimeError, "Ring averaging only take plottable_2D objects" 681 686 Pi = math.pi 682 687 683 688 # Get the all data & info 684 data = data2D.data 685 err_data = data2D.err_data686 qx_data = data2D.qx_data687 q y_data = data2D.qy_data688 q _data = data2D.q_data689 data = data2D.data[numpy.isfinite(data2D.data)] 690 q_data = data2D.q_data[numpy.isfinite(data2D.data)] 691 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 692 qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 693 qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 689 694 690 695 #set space for 1d outputs … … 757 762 758 763 if err_data == None or err_data[n] ==0.0: 759 y_err[i_bin] += frac * frac * math.fabs(data_n) 764 if data_n<0: data_n= -data_n 765 y_err[i_bin] += frac * frac * data_n 760 766 else: 761 767 y_err[i_bin] += frac * frac * err_data[n]*err_data[n] … … 797 803 @return: Data1D object 798 804 """ 805 799 806 return self._agv(data2D, 'phi') 800 807 … … 816 823 """ 817 824 return self._agv(data2D, 'q2') 825 826 class Boxcut(object): 827 """ 828 Find a rectangular 2D region of interest. 829 """ 830 def __init__(self, x_min=0.0, x_max=0.0, y_min=0.0, y_max=0.0): 831 # Minimum Qx value [A-1] 832 self.x_min = x_min 833 # Maximum Qx value [A-1] 834 self.x_max = x_max 835 # Minimum Qy value [A-1] 836 self.y_min = y_min 837 # Maximum Qy value [A-1] 838 self.y_max = y_max 839 840 def __call__(self, data2D): 841 """ 842 Find a rectangular 2D region of interest. 843 844 @param data2D: Data2D object 845 @return: mask, 1d array (len = len(data)) 846 with Trues where the data points are inside ROI, otherwise False 847 """ 848 mask = self._find(data2D) 849 850 return mask 851 852 def _find(self, data2D): 853 """ 854 Find a rectangular 2D region of interest. 855 @param data2D: Data2D object 856 @return: out, 1d array (length = len(data)) 857 with Trues where the data points are inside ROI, otherwise Falses 858 """ 859 if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 860 raise RuntimeError, "Boxcut take only plottable_2D objects" 861 # Get qx_ and qy_data 862 qx_data = data2D.qx_data 863 qy_data = data2D.qy_data 864 865 # check whether or not the data point is inside ROI 866 outx = [self.x_min <= qx_data & self.x_max > qx_data] 867 outy = [self.y_min <= qy_data & self.y_max > qy_data] 868 869 return (outx & outy) 870 871 class Sectorcut(object): 872 """ 873 Defines a sector (major + minor) region on a 2D data set. 874 The sector is defined by phi_min, phi_max, 875 where phi_min and phi_max are defined by the right and left lines wrt central line. 876 877 Phi_min and phi_max are given in units of radian 878 and (phi_max-phi_min) should not be larger than pi 879 """ 880 def __init__(self,phi_min=0, phi_max=math.pi): 881 self.phi_min = phi_min 882 self.phi_max = phi_max 883 884 def __call__(self, data2D): 885 """ 886 Perform sector averaging. 887 888 @param data2D: Data2D object 889 @return: mask, 1d array (len = len(data)) 890 with Trues where the data points are inside ROI, otherwise False 891 """ 892 mask = self._find(data2D) 893 894 return mask 895 896 def _find(self, data2D): 897 """ 898 Find a rectangular 2D region of interest. 899 @param data2D: Data2D object 900 @return: out, 1d array (length = len(data)) 901 with Trues where the data points are inside ROI, otherwise Falses 902 """ 903 if data2D.__class__.__name__ not in ["Data2D", "plottable_2D"]: 904 raise RuntimeError, "Sectorcut take only plottable_2D objects" 905 Pi = math.pi 906 # Get data 907 qx_data = data2D.qx_data 908 qy_data = data2D.qy_data 909 phi_data = numpy.zeros(len(qx_data)) 910 911 # get phi from data 912 phi_data = numpy.arctan2(qy_data, qy_data) 913 # check for major sector 914 if self.phi_min > self.phi_max: 915 out_major = (self.phi_min <= phi_data) or (self.phi_max > phi_data) 916 else: 917 out_major = (self.phi_min <= phi_data) & (self.phi_max > phi_data) 918 919 # minor sector 920 # Get the min and max into the region: -pi <= phi < Pi 921 phi_min_minor = flip_phi(self.phi_min)-Pi 922 phi_max_minor = flip_phi(self.phi_max)-Pi 923 924 # check for minor sector 925 if phi_min_minor > phi_max_minor: 926 out_minor= (phi_min_minor <= phi_data) or (phi_max_minor> phi_data) 927 else: 928 out_minor = (phi_min_minor <= phi_data) & (phi_max_minor > phi_data) 929 out = out_major + out_minor 930 931 return out 932 818 933 if __name__ == "__main__": 819 934
Note: See TracChangeset
for help on using the changeset viewer.