Changeset 342a506 in sasview
- Timestamp:
- Mar 1, 2011 5:54:15 PM (14 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:
- b1a65b6
- Parents:
- 9f391af
- Location:
- DataLoader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/manipulations.py
r12c5b87 r342a506 430 430 q_data = data2D.q_data[numpy.isfinite(data2D.data)] 431 431 err_data = data2D.err_data[numpy.isfinite(data2D.data)] 432 432 dq_data = None 433 if data2D.dqx_data != None and data2D.dqy_data != None: 434 dq_data = data2D.dqx_data[numpy.isfinite(data2D.data)] * \ 435 data2D.dqx_data[numpy.isfinite(data2D.data)] 436 dq_data += data2D.dqy_data[numpy.isfinite(data2D.data)] * \ 437 data2D.dqy_data[numpy.isfinite(data2D.data)] 438 dq_data = numpy.sqrt(dq_data) 439 433 440 q_data_max = numpy.max(q_data) 434 441 … … 444 451 y = numpy.zeros(nbins) 445 452 err_y = numpy.zeros(nbins) 453 err_x = numpy.zeros(nbins) 446 454 y_counts = numpy.zeros(nbins) 447 455 … … 474 482 else: 475 483 err_y[i_q] += frac * frac * err_data[npt] * err_data[npt] 484 if dq_data != None: 485 err_x[i_q] += frac * frac * dq_data[npt] * dq_data[npt] 486 else: 487 err_x = None 476 488 y_counts[i_q] += frac 477 489 478 ## x should be the center value of each bins 479 x = qbins + self.bin_width / 2 480 490 # We take the center of ring area, not radius. 491 # This is more accurate than taking the radial center of ring. 492 x = (qbins + self.bin_width) * (qbins + self.bin_width) 493 x += qbins * qbins 494 x = x / 2.0 495 x = numpy.sqrt(x) 481 496 # Average the sums 482 497 for n in range(nbins): 483 498 if err_y[n] < 0: err_y[n] = -err_y[n] 484 499 err_y[n] = math.sqrt(err_y[n]) 485 500 if err_x != None: 501 err_x[n] = math.sqrt(err_x[n]) 502 486 503 err_y = err_y / y_counts 504 err_y[err_y==0] = numpy.average(err_y) 487 505 y = y / y_counts 488 506 idx = (numpy.isfinite(y)) & (numpy.isfinite(x)) 489 507 if err_x != None: 508 d_x = err_x[idx] / y_counts[idx] 509 else: 510 d_x = None 511 490 512 if not idx.any(): 491 513 msg = "Average Error: No points inside ROI to average..." 492 514 raise ValueError, msg 515 493 516 #elif len(y[idx])!= nbins: 494 517 # print "resulted",nbins- len(y[idx]) 495 518 #,"empty bin(s) due to tight binning..." 496 return Data1D(x=x[idx], y=y[idx], dy=err_y[idx] )519 return Data1D(x=x[idx], y=y[idx], dy=err_y[idx], dx=d_x) 497 520 498 521 … … 722 745 qx_data = data2D.qx_data[numpy.isfinite(data2D.data)] 723 746 qy_data = data2D.qy_data[numpy.isfinite(data2D.data)] 724 747 dq_data = None 748 # dx (smear) data 749 if data2D.dqx_data != None and data2D.dqy_data != None: 750 dq_data = data2D.dqx_data[numpy.isfinite(data2D.data)] * \ 751 data2D.dqx_data[numpy.isfinite(data2D.data)] 752 dq_data += data2D.dqy_data[numpy.isfinite(data2D.data)] * \ 753 data2D.dqy_data[numpy.isfinite(data2D.data)] 754 dq_data = numpy.sqrt(dq_data) 755 725 756 #set space for 1d outputs 726 757 x = numpy.zeros(self.nbins) 727 758 y = numpy.zeros(self.nbins) 728 y_err = numpy.zeros(self.nbins) 759 y_err = numpy.zeros(self.nbins) 760 x_err = numpy.zeros(self.nbins) 729 761 y_counts = numpy.zeros(self.nbins) 730 762 … … 797 829 y[i_bin] += frac * data_n 798 830 799 if err_data == None or err_data[n] == 0.0:831 if err_data[n] == None or err_data[n] == 0.0: 800 832 if data_n < 0: 801 833 data_n = -data_n … … 803 835 else: 804 836 y_err[i_bin] += frac * frac * err_data[n] * err_data[n] 837 838 if dq_data != None: 839 x_err[i_bin] += frac * frac * dq_data[n] * dq_data[n] 840 else: 841 x_err = None 805 842 y_counts[i_bin] += frac 806 843 … … 809 846 y[i] = y[i] / y_counts[i] 810 847 y_err[i] = math.sqrt(y_err[i]) / y_counts[i] 811 848 if x_err != None: 849 x_err[i] = math.sqrt(x_err[i]) / y_counts[i] 812 850 # The type of averaging: phi,q2, or q 813 851 # Calculate x[i]should be at the center of the bin … … 816 854 (1.0 * i + 0.5) + self.phi_min 817 855 else: 818 x[i] = (self.r_max - self.r_min) / self.nbins * \ 819 (1.0 * i + 0.5) + self.r_min 856 # We take the center of ring area, not radius. 857 # This is more accurate than taking the radial center of ring. 858 delta_r = (self.r_max - self.r_min) / self.nbins 859 r_inner = self.r_min + delta_r * i 860 r_outer = r_inner + delta_r 861 x[i] = math.sqrt((r_inner * r_inner + r_outer * r_outer) / 2) 820 862 863 y_err[y_err==0] = numpy.average(y_err) 821 864 idx = (numpy.isfinite(y) & numpy.isfinite(y_err)) 822 865 if x_err != None: 866 d_x = x_err[idx] 867 else: 868 d_x = None 823 869 if not idx.any(): 824 870 msg = "Average Error: No points inside sector of ROI to average..." … … 827 873 # print "resulted",self.nbins- len(y[idx]), 828 874 #"empty bin(s) due to tight binning..." 829 return Data1D(x=x[idx], y=y[idx], dy=y_err[idx] )875 return Data1D(x=x[idx], y=y[idx], dy=y_err[idx], dx=d_x) 830 876 831 877 class SectorPhi(_Sector): -
DataLoader/test/utest_averaging.py
rafab469 r342a506 71 71 Test sector averaging 72 72 """ 73 r = SectorPhi(r_min=self.qmin, r_max=3*self.qmin, phi_min=0, phi_max=math.pi*2.0) 74 r.nbins_phi = 20 75 o = r(self.data) 76 for i in range(20): 73 r = SectorPhi(r_min=self.qmin, r_max=3*self.qmin, 74 phi_min=0, phi_max=math.pi*2.0) 75 r.nbins_phi = 20 76 o = r(self.data) 77 for i in range(7): 77 78 self.assertEqual(o.y[i], 1.0) 78 79 … … 81 82 """ 82 83 """ 83 phi_max = 1.5 84 r = SectorPhi(r_min=self.qmin, r_max=3*self.qmin, phi_min=0, phi_max=phi_max) 84 phi_max = math.pi * 1.5 85 r = SectorPhi(r_min=self.qmin, r_max=3*self.qmin, 86 phi_min=0, phi_max=phi_max) 85 87 self.assertEqual(r.phi_max, phi_max) 86 88 r.nbins_phi = 20 87 89 o = r(self.data) 88 90 self.assertEqual(r.phi_max, phi_max) 89 for i in range( 20):91 for i in range(17): 90 92 self.assertEqual(o.y[i], 1.0) 91 93
Note: See TracChangeset
for help on using the changeset viewer.