Skip to content

Commit

Permalink
Merge pull request #884 from PMEAL/speedup_cylinders
Browse files Browse the repository at this point in the history
Improved speed of cylinders 5x by using _insert_disk_at_points_parallel method instead of dilating using edt #enh
  • Loading branch information
jgostick authored Aug 23, 2023
2 parents e78aa70 + ef53ba8 commit d008465
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions porespy/filters/_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand All @@ -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():
Expand Down
17 changes: 9 additions & 8 deletions porespy/generators/_imgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d008465

Please sign in to comment.