Fixing tqdm usage, adding print outs.
@@ -4,6 +4,7 @@ import scipy.ndimage as spim
from skimage.morphology import disk, ball
from tqdm import tqdm
+
def pseudo_gravity_packing(im, r, max_iter=1000):
if np.isscalar(r):
return _monodisperse(im=im, r=r, max_iter=max_iter)
@@ -12,12 +13,16 @@ def pseudo_gravity_packing(im, r, max_iter=1000):
def _monodisperse(im, r, max_iter=1000):
+ print('_'*60)
+ print('Adding monodisperse spheres of size ', r)
if im.ndim == 2:
strel = disk
else:
strel = ball
sites = ps.tools.fftmorphology(im == 1, strel=strel(r), mode='erosion')
- for _ in tqdm(range(max_iter)):
+ with tqdm(range(max_iter)) as pbar:
+ for _ in range(max_iter):
+ pbar.update()
if im.ndim == 2:
x, y = np.where(sites)
else:
@@ -38,17 +43,22 @@ def _monodisperse(im, r, max_iter=1000):
z[options[choice]]])
im = ps.tools.insert_sphere(im, c=cen, r=r, v=0)
sites = ps.tools.insert_sphere(sites, c=cen, r=2*r, v=0)
+ print('A total of ', _, 'spheres were added')
im = spim.minimum_filter(input=im, footprint=ball(1))
return im
def _polydisperse(im, r_min, r_max, max_iter=1000):
+ print('_'*60)
+ print('Adding polydisperse spheres of sizes ', r_min, ' to ', r_max)
bd = np.zeros_like(im)
bd[-r_max:, ...] = 1
if im.ndim == 2:
strel = disk
else:
strel = ball
- for _ in tqdm(range(max_iter)):
+ with tqdm(range(max_iter)) as pbar:
+ for _ in range(max_iter):
+ pbar.update()
r = np.random.randint(r_min, r_max)
sites = ps.filters.chunked_func(func=ps.tools.fftmorphology,
overlap=r, divs=3, cores=None,
@@ -75,6 +85,7 @@ def _polydisperse(im, r_min, r_max, max_iter=1000):
z[options[choice]]])
im = ps.tools.insert_sphere(im, c=cen, r=r, v=0)
im = spim.minimum_filter(input=im, footprint=ball(1))
+ print('A total of ', _, 'spheres were added')
return im
# im = np.ones([1000, 250, 250])
