def test_surface_area_on_checkerboard(): """Run surface area on checkerboard block""" l = 50 img = generate_checkerboard(l) sa = surface_area(img, phases=[0, 1]) assert sa == 1
def test_surface_area_interfactial_3ph(): l = 3 img = np.zeros([l, l, l]) img[1] = 1 img[2] = 2 sa = surface_area(img, phases=[1, 2]) assert sa == 1 / 6
def test_surface_area_on_empty_block(): """Run surface area on empty block""" l = 20 img = np.zeros([l, l, l]) sa = surface_area(img, phases=0) assert sa == 0
def test_surface_area_on_uniform_block(): """Run surface area on uniform block""" l = 20 img = np.ones([l, l, l]) sa = surface_area(img, phases=1) assert sa == 0
def test_surface_area_on_strip_of_ones(): """Run surface area on single one in small 2x2z2 cube""" l = 2 img = np.zeros([l, l, l]) t = 1 img[0, 0, 0] = 1 sa = surface_area(img, phases=[0, 1]) assert sa == 0.25
def vf_sa_metrics(batch_images): """ :param batch_images: a 4-dim or 3-dim array of images (batch_size x H x W or batch_size x D x H x W) :return: a list of the mean volume fractions of the different phases and the interfacial surface area between every pair of phases. """ batch_size = batch_images.shape[0] phases = np.unique(batch_images) vf = np.mean([[(batch_images[j] == p).mean() for p in phases] for j in range(batch_size)], axis=0) sa = np.mean([[ metrics.surface_area(batch_images[j], [ph1, ph2]).item() for ph1, ph2 in combinations(phases, 2) ] for j in range(batch_size)], axis=0) return list(vf), list(sa)
def test_surface_area_on_periodic_2d(): """Run surface area on a pair of one in small 3x3 square""" img = np.array([[0, 0, 0], [1, 1, 0], [0, 0, 0]]) sa = surface_area(img, phases=[0, 1], periodic=[0, 1]) assert sa == 6 / 18