def test_circular_average(): image = np.zeros((12, 12)) calib_center = (5, 5) inner_radius = 1 edges = roi.ring_edges(inner_radius, width=1, spacing=1, num_rings=2) labels = roi.rings(edges, calib_center, image.shape) image[labels == 1] = 10 image[labels == 2] = 10 bin_cen, ring_avg = roi.circular_average(image, calib_center, nx=6) assert_array_almost_equal(bin_cen, [0.70710678, 2.12132034, 3.53553391, 4.94974747, 6.36396103, 7.77817459], decimal=6) assert_array_almost_equal(ring_avg, [8., 2.5, 5.55555556, 0., 0., 0.], decimal=6) bin_cen1, ring_avg1 = roi.circular_average(image, calib_center, min_x=0, max_x=10, nx=None) assert_array_almost_equal(bin_cen1, [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5]) mask = np.ones_like(image) mask[4:6, 2:3] = 0 bin_cen_masked, ring_avg_masked = roi.circular_average(image, calib_center, min_x=0, max_x=10, nx=6, mask=mask) assert_array_almost_equal(bin_cen_masked, [0.83333333, 2.5, 4.16666667, 5.83333333, 7.5, 9.16666667]) assert_array_almost_equal(ring_avg_masked, [8.88888889, 3.84615385, 2.5, 0., 0., 0.])
def test_construct_circ_avg_image(): # need to test with center and dims and without # and test anisotropic pixels image = np.zeros((12, 12)) calib_center = (2, 2) inner_radius = 1 edges = roi.ring_edges(inner_radius, width=1, spacing=1, num_rings=2) labels = roi.rings(edges, calib_center, image.shape) image[labels == 1] = 10 image[labels == 2] = 10 bin_cen, ring_avg = roi.circular_average(image, calib_center, nx=6) # check that the beam center and dims yield the circavg in the right place cimg = nimage.construct_circ_avg_image(bin_cen, ring_avg, dims=image.shape, center=calib_center) assert_array_almost_equal( cimg[2], np.array([ 5.0103283, 6.15384615, 6.15384615, 6.15384615, 5.0103283, 3.79296498, 2.19422113, 0.51063356, 0., 0., 0., 0. ])) # check that the default values center in the same place cimg2 = nimage.construct_circ_avg_image(bin_cen, ring_avg) assert_array_almost_equal( cimg2[12], np.array([ 0., 0., 0., 0., 0., 0., 0., 0.51063356, 2.19422113, 3.79296498, 5.0103283, 6.15384615, 6.15384615, 6.15384615, 5.0103283, 3.79296498, 2.19422113, 0.51063356, 0., 0., 0., 0., 0., 0., 0. ])) # check that anisotropic pixels are treated properly cimg3 = nimage.construct_circ_avg_image(bin_cen, ring_avg, dims=image.shape, pixel_size=(2, 1)) assert_array_almost_equal( cimg3[5], np.array([ 0., 1.16761618, 2.80022015, 4.16720388, 5.250422, 6.08400137, 6.08400137, 5.250422, 4.16720388, 2.80022015, 1.16761618, 0. ])) with assert_raises(ValueError): nimage.construct_circ_avg_image(bin_cen, ring_avg, center=calib_center, pixel_size=(2, 1))
def circavg(self): ''' calculate and plot circular average.''' if hasattr(self.saxsdata,"mask") and self.saxsdata.mask is not None: mask = self.saxsdata.mask else: mask = None #sqx, sqy = circavg(self.saxsdata.avg_img, x0=self.saxsdata.getxcen(), y0=self.saxsdata.getycen(),\ #noqs=self.saxsdata.getnoqs_circavg(), mask=mask) x0 = self.saxsdata.getxcen() y0 = self.saxsdata.getycen() noqs = self.saxsdata.getnoqs_circavg() sqx, sqy = circular_average(self.saxsdata.avg_img,(y0,x0),mask=mask,nx=noqs) p1 = pg.plot(sqx*self.saxsdata.getqperpixel(),sqy) p1.getPlotItem().setLogMode(True,True)
def test_construct_circ_avg_image(): # need to test with center and dims and without # and test anisotropic pixels image = np.zeros((12, 12)) calib_center = (2, 2) inner_radius = 1 edges = roi.ring_edges(inner_radius, width=1, spacing=1, num_rings=2) labels = roi.rings(edges, calib_center, image.shape) image[labels == 1] = 10 image[labels == 2] = 10 bin_cen, ring_avg = roi.circular_average(image, calib_center, nx=6) # check that the beam center and dims yield the circavg in the right place cimg = nimage.construct_circ_avg_image(bin_cen, ring_avg, dims=image.shape, center=calib_center) assert_array_almost_equal(cimg[2], np.array([5.0103283, 6.15384615, 6.15384615, 6.15384615, 5.0103283, 3.79296498, 2.19422113, 0.51063356, 0., 0., 0., 0.])) # check that the default values center in the same place cimg2 = nimage.construct_circ_avg_image(bin_cen, ring_avg) assert_array_almost_equal(cimg2[12], np.array([0., 0., 0., 0., 0., 0., 0., 0.51063356, 2.19422113, 3.79296498, 5.0103283, 6.15384615, 6.15384615, 6.15384615, 5.0103283, 3.79296498, 2.19422113, 0.51063356, 0., 0., 0., 0., 0., 0., 0.])) # check that anisotropic pixels are treated properly cimg3 = nimage.construct_circ_avg_image(bin_cen, ring_avg, dims=image.shape, pixel_size=(2, 1)) assert_array_almost_equal(cimg3[5], np.array([0., 1.16761618, 2.80022015, 4.16720388, 5.250422, 6.08400137, 6.08400137, 5.250422, 4.16720388, 2.80022015, 1.16761618, 0.])) with assert_raises(ValueError): nimage.construct_circ_avg_image(bin_cen, ring_avg, center=calib_center, pixel_size=(2, 1))