Skip to content

Commit

Permalink
replaced rsa with random_spheres in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgostick committed Mar 13, 2024
1 parent dc53ce7 commit a8c61b0
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions test/unit/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,88 +264,97 @@ def test_blobs_w_divs(self):
im2 = ps.generators.blobs(shape=[101, 101], seed=0, divs=2)
assert np.all(im1 == im2)

def test_rsa_2d_contained(self):
def test_random_spheres_2d_contained(self):
im = np.zeros([100, 100], dtype=int)
im = ps.generators.rsa(im, r=10, volume_fraction=0.5, mode='contained')
im = ps.generators.random_spheres(
im, r=10, volume_fraction=0.5, mode='contained')
im = np.pad(im, pad_width=1, mode='constant', constant_values=False)
lt = ps.filters.local_thickness(im)
assert len(np.unique(lt)) == 2

def test_rsa_2d_extended(self):
def test_random_spheres_2d_extended(self):
im = np.zeros([100, 100], dtype=int)
im = ps.generators.rsa(im, r=10, volume_fraction=0.5, mode='extended')
im = ps.generators.random_spheres(
im, r=10, volume_fraction=0.5, mode='extended')
im = np.pad(im, pad_width=1, mode='constant', constant_values=False)
lt = ps.filters.local_thickness(im)
assert len(np.unique(lt)) > 2

def test_rsa_2d_extended_with_clearance(self):
def test_random_spheres_2d_extended_with_clearance(self):
im = np.zeros([100, 100], dtype=int)
im = ps.generators.rsa(im, r=10,
volume_fraction=0.5,
clearance=2,
mode='extended')
im = ps.generators.random_spheres(im, r=10,
volume_fraction=0.5,
clearance=2,
mode='extended')
im = np.pad(im, pad_width=1, mode='constant', constant_values=False)
lt = ps.filters.local_thickness(im)
assert len(np.unique(lt)) > 2

def test_rsa_3d_contained(self):
def test_random_spheres_3d_contained(self):
im = np.zeros([100, 100, 100], dtype=int)
im = ps.generators.rsa(im, r=10, volume_fraction=0.5, mode='contained')
im = ps.generators.random_spheres(
im, r=10, volume_fraction=0.5, mode='contained')
lt = ps.filters.local_thickness(im, sizes=[10, 9, 8, 7, 6, 5])
assert len(np.unique(lt)) == 2

def test_rsa_3d_extended(self):
def test_random_spheres_3d_extended(self):
im = np.zeros([100, 100, 100], dtype=int)
im = ps.generators.rsa(im, r=10, volume_fraction=0.5, mode='extended')
im = ps.generators.random_spheres(
im, r=10, volume_fraction=0.5, mode='extended')
im = np.pad(im, pad_width=1, mode='constant', constant_values=False)
lt = ps.filters.local_thickness(im, sizes=[10, 9, 8, 7, 6, 5])
assert len(np.unique(lt)) > 2

def test_rsa_2d_seqential_additions(self):
def test_random_spheres_2d_seqential_additions(self):
im = np.zeros([100, 100], dtype=int)
im = ps.generators.rsa(im, r=10)
im = ps.generators.random_spheres(im, r=10)
phi1 = ps.metrics.porosity(im)
im = ps.generators.rsa(im, r=5)
im = ps.generators.random_spheres(im, r=5)
phi2 = ps.metrics.porosity(im)
assert phi2 > phi1

def test_rsa_preexisting_structure(self):
def test_random_spheres_preexisting_structure(self):
im = ps.generators.blobs(shape=[200, 200, 200])
phi1 = im.sum()/im.size
im = ps.generators.rsa(im, r=8, n_max=200, mode='contained')
im = ps.generators.random_spheres(im, r=8, n_max=200, mode='contained')
phi2 = im.sum()/im.size
assert phi2 > phi1
# Ensure that 3 passes through rsa fills up image
im = ps.generators.rsa(im, r=8, n_max=200, mode='contained')
im = ps.generators.rsa(im, r=8, n_max=200, mode='contained')
im = ps.generators.rsa(im, r=8, n_max=200, mode='contained')
# Ensure that 3 passes through random_spheres fills up image
im = ps.generators.random_spheres(im, r=8, n_max=200, mode='contained')
im = ps.generators.random_spheres(im, r=8, n_max=200, mode='contained')
im = ps.generators.random_spheres(im, r=8, n_max=200, mode='contained')
phi1 = im.sum()/im.size
im = ps.generators.rsa(im, r=8, n_max=200, mode='contained')
im = ps.generators.random_spheres(im, r=8, n_max=200, mode='contained')
phi2 = im.sum()/im.size
assert phi2 == phi1

def test_rsa_shape(self):
rsa = ps.generators.rsa(im_or_shape=[200, 200], r=10)
assert np.all(rsa.shape == (200, 200))

def test_rsa_clearance_large_spheres(self):
rsa0 = ps.generators.rsa(im_or_shape=[200, 200], r=9, clearance=0, seed=0)
rsa2p = ps.generators.rsa(im_or_shape=[200, 200], r=9, clearance=3, seed=0)
assert rsa0.sum() > rsa2p.sum()
rsa1n = ps.generators.rsa(im_or_shape=[200, 200], r=9, clearance=-3, seed=0)
assert rsa0.sum() < rsa1n.sum()

def test_rsa_clearance_small_spheres(self):
def test_random_spheres_shape(self):
random_spheres = ps.generators.random_spheres(im_or_shape=[200, 200], r=10)
assert np.all(random_spheres.shape == (200, 200))

def test_random_spheres_clearance_large_spheres(self):
random_spheres0 = ps.generators.random_spheres(
im_or_shape=[200, 200], r=9, clearance=0, seed=0)
random_spheres2p = ps.generators.random_spheres(
im_or_shape=[200, 200], r=9, clearance=3, seed=0)
assert random_spheres0.sum() > random_spheres2p.sum()
random_spheres1n = ps.generators.random_spheres(
im_or_shape=[200, 200], r=9, clearance=-3, seed=0)
assert random_spheres0.sum() < random_spheres1n.sum()

def test_random_spheres_clearance_small_spheres(self):
np.random.seed(0)
rsa0 = ps.generators.rsa(im_or_shape=[200, 200], r=1, clearance=0)
random_spheres0 = ps.generators.random_spheres(
im_or_shape=[200, 200], r=1, clearance=0)
np.random.seed(0)
rsa2p = ps.generators.rsa(im_or_shape=[200, 200], r=1, clearance=2)
assert rsa0.sum() > rsa2p.sum()

def test_rsa_w_seed(self):
im1 = ps.generators.rsa([50, 50], r=5, seed=0)
im2 = ps.generators.rsa([50, 50], r=5, seed=0)
im3 = ps.generators.rsa([50, 50], r=5, seed=1)
random_spheres2p = ps.generators.random_spheres(
im_or_shape=[200, 200], r=1, clearance=2)
assert random_spheres0.sum() > random_spheres2p.sum()

def test_random_spheres_w_seed(self):
im1 = ps.generators.random_spheres([50, 50], r=5, seed=0)
im2 = ps.generators.random_spheres([50, 50], r=5, seed=0)
im3 = ps.generators.random_spheres([50, 50], r=5, seed=1)
assert np.all(im1 == im2)
assert not np.all(im1 == im3)

Expand Down

0 comments on commit a8c61b0

Please sign in to comment.