def annular_av(data): """ Using annular averging, it converts data to 1D (Q vs. I) **Inputs** data (sans2d): data in **Returns** output (sans1d): converted to I vs. Q 2016-04-08 Brian Maranville """ """ """ from draw_annulus_aa import annular_mask_antialiased #annular_mask_antialiased(shape, center, inner_radius, outer_radius, background_value=0.0, mask_value=1.0, oversampling=8) # calculate the change in q that corresponds to a change in pixel of 1 q_per_pixel = data.qx[1,0]-data.qx[0,0] / 1.0 # for now, we'll make the q-bins have the same width as a single pixel step = q_per_pixel shape1 = data.data.x.shape x0=data.metadata['det.beamx'] #should be close to 64 y0=data.metadata['det.beamy'] #should be close to 64 center = (x0, y0) Qmax = data.q.max() Q = np.arange(0,Qmax,step) I = [] I_error = [] for i in Q: # inner radius is the q we're at right now, converted to pixel dimensions: inner_r = i * (1.0/q_per_pixel) # outer radius is the q of the next bin, also converted to pixel dimensions: outer_r = (i + step) * (1.0/q_per_pixel) mask = annular_mask_antialiased(shape1,center,inner_r,outer_r) if IGNORE_CORNER_PIXELS == True: mask[0,0] = mask[-1,0] = mask[-1,-1] = mask[0,-1] = 0.0 #print "Mask: ",mask integrated_intensity = np.sum(mask.T*data.data.x) #error = getPoissonUncertainty(integrated_intensity) error = np.sqrt(integrated_intensity) mask_sum = np.sum(mask) if (integrated_intensity != 0.0): norm_integrated_intensity = integrated_intensity / mask_sum #error['yupper'] /= mask_sum #error['ylower'] /= mask_sum error /= mask_sum else: norm_integrated_intensity = integrated_intensity I.append(norm_integrated_intensity) # not multiplying by step anymore I_error.append(error) output = Sans1dData(Q, I, dx=0, dv=I_error, xlabel="Q", vlabel="I", xunits="inv. A", vunits="neutrons") output.metadata=deepcopy(data.metadata) return output
def annular_av(sansdata): """Using annular averging, it converts data to 1D (Q vs. I) """ #annular_mask_antialiased(shape, center, inner_radius, outer_radius, background_value=0.0, mask_value=1.0, oversampling=8) #x0=sansdata.metadata['det.beamx'] #should be close to 64 #y0=sansdata.metadata['det.beamy'] #should be close to 64 #shape=sansdata.data.x.shape #x,y = np.indices(shape) #X = PIXEL_SIZE_X_CM*(x-x0) #Y=PIXEL_SIZE_Y_CM*(y-y0) #alpha=np.arctan2(Y,X) #q = sansdata.q #qx=q*np.cos(alpha) #print sansdata.q # calculate the change in q that corresponds to a change in pixel of 1 q_per_pixel = sansdata.qx[1, 0] - sansdata.qx[0, 0] / 1.0 # for now, we'll make the q-bins have the same width as a single pixel step = q_per_pixel #print "Step: ", step shape1 = (128, 128) center = (sansdata.metadata['det.beamx'], sansdata.metadata['det.beamy']) Qmax = sansdata.q.max() #print "QMax: ",Qmax Q = np.arange(0, Qmax, step) #print "Q=",Q I = [] for i in Q: # inner radius is the q we're at right now, converted to pixel dimensions: inner_r = i * (1.0 / q_per_pixel) # outer radius is the q of the next bin, also converted to pixel dimensions: outer_r = (i + step) * (1.0 / q_per_pixel) mask = annular_mask_antialiased(shape1, center, inner_r, outer_r) if IGNORE_CORNER_PIXELS == True: mask[0, 0] = mask[-1, 0] = mask[-1, -1] = mask[0, -1] = 0.0 #print "Mask: ",mask norm_integrated_intensity = np.sum(mask * sansdata.data.x) if (norm_integrated_intensity != 0.0): norm_integrated_intensity /= np.sum(mask) I.append(norm_integrated_intensity) #not multiplying by step anymore Q = Q.tolist() I = (np.array(I)).tolist() metadata = deepcopy(sansdata.metadata) plot1 = plot1D(Q, I, metadata) #print "Q is : ", Q #print "I is : ", I Qlog = np.log10(Q).tolist() Ilog = np.log10(I).tolist() #print "Qlog: ", Qlog #print "Ilog: ", Ilog #plt.plot(Q,I,'ro') #plt.title('1D') #plt.xlabel('q(A^-1)') #plt.ylabel('I(q)') #plt.show() #sys.exit() return plot1
def annular_av(sansdata): """Using annular averging, it converts data to 1D (Q vs. I) """ #annular_mask_antialiased(shape, center, inner_radius, outer_radius, background_value=0.0, mask_value=1.0, oversampling=8) #x0=sansdata.metadata['det.beamx'] #should be close to 64 #y0=sansdata.metadata['det.beamy'] #should be close to 64 #shape=sansdata.data.x.shape #x,y = np.indices(shape) #X = PIXEL_SIZE_X_CM*(x-x0) #Y=PIXEL_SIZE_Y_CM*(y-y0) #alpha=np.arctan2(Y,X) #q = sansdata.q #qx=q*np.cos(alpha) #print sansdata.q # calculate the change in q that corresponds to a change in pixel of 1 q_per_pixel = sansdata.qx[1,0]-sansdata.qx[0,0] / 1.0 # for now, we'll make the q-bins have the same width as a single pixel step = q_per_pixel #print "Step: ", step shape1 = (128,128) center = (sansdata.metadata['det.beamx'],sansdata.metadata['det.beamy']) Qmax = sansdata.q.max() #print "QMax: ",Qmax Q = np.arange(0,Qmax,step) #print "Q=",Q I = [] for i in Q: # inner radius is the q we're at right now, converted to pixel dimensions: inner_r = i * (1.0/q_per_pixel) # outer radius is the q of the next bin, also converted to pixel dimensions: outer_r = (i + step) * (1.0/q_per_pixel) mask = annular_mask_antialiased(shape1,center,inner_r,outer_r) if IGNORE_CORNER_PIXELS == True: mask[0,0] = mask[-1,0] = mask[-1,-1] = mask[0,-1] = 0.0 #print "Mask: ",mask norm_integrated_intensity = np.sum(mask*sansdata.data.x) if (norm_integrated_intensity != 0.0): norm_integrated_intensity/=np.sum(mask) I.append(norm_integrated_intensity)#not multiplying by step anymore Q = Q.tolist() I = (np.array(I)).tolist() metadata = deepcopy(sansdata.metadata) plot1 = plot1D(Q,I,metadata) #print "Q is : ", Q #print "I is : ", I Qlog = np.log10(Q).tolist() Ilog = np.log10(I).tolist() #print "Qlog: ", Qlog #print "Ilog: ", Ilog #plt.plot(Q,I,'ro') #plt.title('1D') #plt.xlabel('q(A^-1)') #plt.ylabel('I(q)') #plt.show() #sys.exit() return plot1
def annular_av(sansdata): # annular_mask_antialiased(shape, center, inner_radius, outer_radius, background_value=0.0, mask_value=1.0, oversampling=8) x0 = sansdata.metadata["det.beamx"] # should be close to 64 y0 = sansdata.metadata["det.beamy"] # should be close to 64 shape = sansdata.data.x.shape x, y = np.indices(shape) X = PIXEL_SIZE_X_CM * (x - x0) Y = PIXEL_SIZE_Y_CM * (y - y0) alpha = np.arctan2(Y, X) q = sansdata.q qx = q * np.cos(alpha) print q # calculate the change in q that corresponds to a change in pixel of 1 q_per_pixel = qx[1, 0] - qx[0, 0] / 1.0 # for now, we'll make the q-bins have the same width as a single pixel step = q_per_pixel # print "Step: ",step shape1 = (128, 128) center = (sansdata.metadata["det.beamx"], sansdata.metadata["det.beamy"]) Qmax = q.max() # print "QMax: ",Qmax Q = np.arange(0, Qmax, step) # print "Q=",Q I = [] for i in Q: # inner radius is the q we're at right now, converted to pixel dimensions: inner_r = i * (1.0 / q_per_pixel) # outer radius is the q of the next bin, also converted to pixel dimensions: outer_r = (i + step) * (1.0 / q_per_pixel) mask = annular_mask_antialiased(shape1, center, inner_r, outer_r) # my handwriting may have been illegible here: I was trying to write the product of mask and data, # not mask.data (sorry - Brian) # print "Mask: ",mask norm_integrated_intensity = np.sum(mask * sansdata.data.x) if norm_integrated_intensity != 0.0: norm_integrated_intensity /= np.sum(mask) I.append(norm_integrated_intensity) print "Q is : ", Q print "I is : ", I