map_to_regions#

Maps pore values from a network onto the image from which it was extracted

import numpy as np
import porespy as ps
import openpnm as op
import matplotlib.pyplot as plt

ws = op.Workspace()
ws.settings['loglevel'] = 50
np.random.seed(10)
ps.visualization.set_mpl_style()
/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

Create image and extract network#

im = ps.generators.blobs(shape=[400, 400], porosity=0.6)
ps.imshow(im);
snow_output = ps.networks.snow2(im, voxel_size=1)
pn = op.io.network_from_porespy(snow_output.network)
../../../_images/4855f0a421e2475a41a791abea5ee9ca596a0e770045d9d48a7d4846def91196.png

Plot the pore network#

fig, ax = plt.subplots()
op.visualization.plot_connections(pn, c='w', linewidth=2, ax=ax)
op.visualization.plot_coordinates(pn, c='w', s=100, ax=ax)
plt.imshow(snow_output.regions.T, origin='lower')
plt.axis('off');
../../../_images/21bb1190dd2186276190c045ad838968c9161452e6d1a4e168f4af0118c453bf.png

Now assign some values to the network:

pn['pore.values'] = np.random.rand(pn.Np)

And now assign these values to the image regions:

reg = ps.networks.map_to_regions(regions=snow_output.regions.T, values=pn['pore.values'])
plt.imshow(reg, origin='lower');
../../../_images/7811f78bf51805386efc62d6312a0d4bee3fbb00c0f07590d9dca97aff5f739f.png