Got it working nicely, but no numba
import scipy as sp
import scipy.spatial as sptl
import scipy.ndimage as spim
-from numba import njit
+from numba import njit, jit
from porespy.tools import norm_to_uniform, ps_ball, ps_disk, get_border
from porespy.tools import insert_sphere, fftmorphology
from typing import List
@@ -175,9 +175,12 @@ def RSA(im: array, radius: int, volume_fraction: int = 1, n_max: int = None,
pass
options_im = sp.reshape(sp.arange(im.size), newshape=im.shape)
options_im[mask > 0] = 0
+
+ def _begin_inserting(im, options_im, radius, template_sm, template_lg):
vf = im.sum()/im.size
i = 0
free_sites = options_im[options_im > 0]
+ v = template_sm.sum()/im.size
while vf <= volume_fraction and len(free_sites) and (i < n_max):
print(i)
choice = sp.random.choice(free_sites)
@@ -186,7 +189,7 @@ def RSA(im: array, radius: int, volume_fraction: int = 1, n_max: int = None,
im[s_sm] += template_sm
s_lg = tuple([slice(ind - 2*radius, ind + 2*radius + 1, None) for ind in c])
options_im[s_lg] *= ~template_lg
- vf = im.sum()/im.size
+ vf += v
i += 1
free_sites = options_im[options_im > 0]
if vf > volume_fraction:
@@ -197,6 +200,8 @@ def RSA(im: array, radius: int, volume_fraction: int = 1, n_max: int = None,
print('Maximum number of spheres reached')
s = tuple([slice(radius*3, d-radius*3, None) for d in im.shape])
return im[s]
+ im = _begin_inserting(im, options_im, radius, template_sm, template_lg)
+ return im
def bundle_of_tubes(shape: List[int], spacing: int):
