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()

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)
try:
    pn, geo = op.io.PoreSpy.import_data(snow_output.network)
except AttributeError:
    pn, geo = op.io.from_porespy(snow_output.network)
../../../_images/c4819573fd95ad0f90a451fd738c7c4c1d010861c921023e5fd413155726ccdc.svg

Plot the pore network#

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

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)
<matplotlib.image.AxesImage at 0x7f11958b1eb0>
../../../_images/0a1bd99f73c7e7f901a49f10eb873ad69c7ad7da65d1d066a08b918b69975ec7.svg