diff --git a/porespy/filters/_funcs.py b/porespy/filters/_funcs.py index 1fce77090..6303371c5 100644 --- a/porespy/filters/_funcs.py +++ b/porespy/filters/_funcs.py @@ -1218,7 +1218,7 @@ def trim_disconnected_blobs(im, inlets, strel=None): to view online example. """ - if type(inlets) == tuple: + if isinstance(inlets, tuple): temp = np.copy(inlets) inlets = np.zeros_like(im, dtype=bool) inlets[temp] = True @@ -1516,7 +1516,7 @@ def apply_func(func, **kwargs): return func(**kwargs) # Determine the value for im_arg - if type(im_arg) == str: + if isinstance(im_arg, str): im_arg = [im_arg] for item in im_arg: if item in kwargs.keys(): @@ -1533,7 +1533,7 @@ def apply_func(func, **kwargs): if overlap is not None: overlap = overlap * (divs > 1) else: - if type(strel_arg) == str: + if isinstance(strel_arg, str): strel_arg = [strel_arg] for item in strel_arg: if item in kwargs.keys(): diff --git a/porespy/generators/_imgen.py b/porespy/generators/_imgen.py index 5e3964d33..a3d67b359 100644 --- a/porespy/generators/_imgen.py +++ b/porespy/generators/_imgen.py @@ -11,7 +11,7 @@ from porespy.tools import norm_to_uniform, ps_ball, ps_disk, get_border, ps_round from porespy.tools import extract_subsection from porespy.tools import insert_sphere -from porespy.tools import _insert_disk_at_points +from porespy.tools import _insert_disk_at_points, _insert_disk_at_points_parallel from porespy import settings from typing import List @@ -1216,12 +1216,12 @@ def _cylinders( upper = ~np.any(np.vstack(crds).T >= shape + L, axis=1) valid = upper * lower if np.any(valid): - im[crds[0][valid] - L, crds[1][valid] - L, crds[2][valid] - L] = 1 + coords = np.vstack(crds).T[valid] - L + _insert_disk_at_points_parallel(im, coords=coords.T, r=r, v=1, + smooth=True, overwrite=False) n += 1 pbar.update() - im = np.array(im, dtype=bool) - dt = edt(~im) < r - return ~dt + return ~im def cylinders( @@ -1365,9 +1365,10 @@ def get_num_pixels(porosity): n_fibers_total = n_pixels_to_add / vol_fiber n_fibers = int(np.ceil(frac * n_fibers_total) - n_fibers_added) if n_fibers > 0: - im = im & _cylinders(shape, r, n_fibers, - phi_max, theta_max, length, - verbose=False) + tmp = _cylinders(shape, r, n_fibers, + phi_max, theta_max, length, + verbose=False) + im = im * tmp n_fibers_added += n_fibers # Update parameters for next iteration porosity = ps.metrics.porosity(im)