lattice_spheres#

Generates a cubic packing of spheres in a specified lattice arrangement.

import matplotlib.pyplot as plt
import porespy as ps
/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/openpnm/algorithms/_invasion_percolation.py:358: NumbaDeprecationWarning: The 'nopython' keyword argument was not supplied to the 'numba.jit' decorator. The implicit default value for this argument is currently False, but it will be changed to True in Numba 0.59.0. See https://numba.readthedocs.io/en/stable/reference/deprecation.html#deprecation-of-object-mode-fall-back-behaviour-when-using-jit for details.
  def _find_trapped_pores(inv_seq, indices, indptr, outlets):  # pragma: no cover
import inspect
b = inspect.signature(ps.generators.lattice_spheres)
print(b)
(shape: List[int], r: int, spacing: int = None, offset: int = None, smooth: bool = True, lattice: str = 'sc')

radius#

Controls the size of the spheres.

fig, ax = plt.subplots(1, 2, figsize=[8, 4])

shape = [200, 200]
r=10
im1 = ps.generators.lattice_spheres(shape=shape, r=r)
ax[0].imshow(im1, interpolation='none')
ax[0].axis(False)
ax[0].set_title(f'radius = {r}')

r= 20
im2 = ps.generators.lattice_spheres(shape=shape, r=r)
ax[1].imshow(im2, interpolation='none')
ax[1].axis(False)
ax[1].set_title(f'radius = {r}');
../../../_images/cde58662a2dcf461c60f5cab828c4e5bc15162f56b8e8dfb2e29d3c636aa5c69.png

spacing#

The center-to-center spacing between the spheres. If this value is less than the sphere diamter then the spheres will overlap.

fig, ax = plt.subplots(1, 2, figsize=[8, 4])

s = 35
im1 = ps.generators.lattice_spheres(shape=shape, r=r, spacing=s)
ax[0].imshow(im1, interpolation='none')
ax[0].axis(False)
ax[0].set_title(f'spacing = {s}')


s = 50
im2 = ps.generators.lattice_spheres(shape=shape, r=r, spacing=s)
ax[1].imshow(im2, interpolation='none')
ax[1].axis(False)
ax[1].set_title(f'spacing = {s}');
../../../_images/bca0274893e7f8e0ee7218a35cadf41f85f83105868db76ada521e25dadb18fe.png

offset#

Controls how far away from the edge the first sphere is located. The default is the sphere radius but it can be more or less depending on the desired effect:

fig, ax = plt.subplots(1, 2, figsize=[8, 4])

o = 0
im1 = ps.generators.lattice_spheres(shape=shape, r=r, spacing=s, offset=o)
ax[0].imshow(im1, interpolation='none')
ax[0].axis(False)
ax[0].set_title(f'offset = {o}')

o = 25
im2 = ps.generators.lattice_spheres(shape=shape, r=r, spacing=s, offset=o)
ax[1].imshow(im2, interpolation='none')
ax[1].axis(False)
ax[1].set_title(f'offset = {o}');
../../../_images/9ffafa6e90a7c4e09ffd49148dcc9df8895f89dec28167d00c8ddcc6e37dec73.png

lattice#

Controls the arrange of spheres. In 2D the options are simple cubic (‘sc’) and triangular (‘tri’). Note that the offset and spacing apply to the outer spheres when lattice='tri'.

fig, ax = plt.subplots(1, 2, figsize=[8, 4])

L='sc'
r = 10
im1 = ps.generators.lattice_spheres(shape=shape, r=r, spacing=s, offset=o, lattice=L)

ax[0].imshow(im1, interpolation='none')
ax[0].axis(False)
ax[0].set_title(f'lattice = {L}')

L='tri'
im2 = ps.generators.lattice_spheres(shape=shape, r=r, spacing=s, offset=o, lattice=L)

ax[1].imshow(im2, interpolation='none')
ax[1].axis(False)
ax[1].set_title(f'lattice = {L}');
../../../_images/beb8a2296aba80cfe930112bab699deb682d4bddc8445debaa24705635e049e4.png

In 3D the options are simple cubic (‘sc’), face centered cubic (‘fcc’), and body centered cubic (‘bcc’). It’s more difficult to visualize in 3D but PoreSpy has a basic function called “show_3D” that works if the image is small:

fig, ax = plt.subplots(1, 3, figsize=[9, 3])

r = 10
s = 25
shape = [100, 100, 100]
L = 'sc'
im1 = ps.generators.lattice_spheres(shape=shape, r=r, spacing=s, offset=o, lattice=L)
ax[0].imshow(ps.visualization.show_3D(im1))
ax[0].axis(False)
ax[0].set_title(f'lattice = {L}')

L = 'fcc'
im2 = ps.generators.lattice_spheres(shape=shape, r=r, spacing=s, offset=o, lattice=L)
ax[1].imshow(ps.visualization.show_3D(im2))
ax[1].axis(False)
ax[1].set_title(f'lattice = {L}');

L = 'bcc'
im3 = ps.generators.lattice_spheres(shape=shape, r=r, spacing=s, offset=o, lattice=L)
ax[2].imshow(ps.visualization.show_3D(im3))
ax[2].axis(False)
ax[2].set_title(f'lattice = {L}');
../../../_images/e471d8e8e1c124e51959f14d3c3abe5e97a83af505822bc1f9ae66a148ed063b.png