satn_to_movie#

Produces a movie of the invasion sequence from ibip filter. This method can be applied for visualizing image-based invasion percolation algorithm.

[1]:
import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
import inspect
from IPython.display import HTML
ps.visualization.set_mpl_style()
inspect.signature(ps.visualization.satn_to_movie)
[1]:
<Signature (im, satn, cmap='viridis', c_under='grey', c_over='white', v_under=0.001, v_over=1.0, fps=10, repeat=True)>

im#

The input image is a Boolean image True values indicating the void voxels and False for solid. Let’s create a test image:

[2]:
np.random.seed(10)
im = ps.generators.blobs(shape=[100,100], blobiness=1)
fig, ax = plt.subplots()
ax.imshow(im, origin='lower', interpolation='none')
ax.axis(False);
../../../_images/examples_visualization_reference_satn_to_movie_5_0.svg

satn#

The saturation image can be generated from ibip data using seq_to_satn method. The satn is the image of porous material where each voxel indicates the global saturation at which it was invaded. Voxels with 0 values indicate solid and and -1 indicate uninvaded.

[3]:
bd = np.zeros_like(im, dtype=bool)
bd[:, 0] = 1
bd *= im
out = ps.filters.ibip(im=im, inlets=bd)
inv_seq, inv_size = out.inv_sequence, out.inv_sizes
satn = ps.filters.seq_to_satn(seq=inv_seq)

Now we can create an animation of the invasion sequence using satn_to_movie: (To save animation as a file and for visualizing use animation.save)

[4]:
mov = ps.visualization.satn_to_movie(im=im, satn=satn)
mov_image_based_ip = mov.to_html5_video()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [4], in <cell line: 2>()
      1 mov = ps.visualization.satn_to_movie(im=im, satn=satn)
----> 2 mov_image_based_ip = mov.to_html5_video()

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:1266, in Animation.to_html5_video(self, embed_limit)
   1263 path = Path(tmpdir, "temp.m4v")
   1264 # We create a writer manually so that we can get the
   1265 # appropriate size for the tag
-> 1266 Writer = writers[mpl.rcParams['animation.writer']]
   1267 writer = Writer(codec='h264',
   1268                 bitrate=mpl.rcParams['animation.bitrate'],
   1269                 fps=1000. / self._interval)
   1270 self.save(str(path), writer=writer)

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:151, in MovieWriterRegistry.__getitem__(self, name)
    149 if self.is_available(name):
    150     return self._registered[name]
--> 151 raise RuntimeError(f"Requested MovieWriter ({name}) not available")

RuntimeError: Requested MovieWriter (ffmpeg) not available
../../../_images/examples_visualization_reference_satn_to_movie_10_2.svg
[5]:
HTML(mov_image_based_ip)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 HTML(mov_image_based_ip)

NameError: name 'mov_image_based_ip' is not defined

cmap#

The Colormap used to map invasion sequence values to colors. By default the cmap is ‘viridis’.

[6]:
mov = ps.visualization.satn_to_movie(im=im, satn=satn, cmap='plasma')
image_based_ip_cmap = mov.to_html5_video()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [6], in <cell line: 2>()
      1 mov = ps.visualization.satn_to_movie(im=im, satn=satn, cmap='plasma')
----> 2 image_based_ip_cmap = mov.to_html5_video()

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:1266, in Animation.to_html5_video(self, embed_limit)
   1263 path = Path(tmpdir, "temp.m4v")
   1264 # We create a writer manually so that we can get the
   1265 # appropriate size for the tag
-> 1266 Writer = writers[mpl.rcParams['animation.writer']]
   1267 writer = Writer(codec='h264',
   1268                 bitrate=mpl.rcParams['animation.bitrate'],
   1269                 fps=1000. / self._interval)
   1270 self.save(str(path), writer=writer)

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:151, in MovieWriterRegistry.__getitem__(self, name)
    149 if self.is_available(name):
    150     return self._registered[name]
--> 151 raise RuntimeError(f"Requested MovieWriter ({name}) not available")

RuntimeError: Requested MovieWriter (ffmpeg) not available
../../../_images/examples_visualization_reference_satn_to_movie_14_2.svg
[7]:
HTML(image_based_ip_cmap)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 HTML(image_based_ip_cmap)

NameError: name 'image_based_ip_cmap' is not defined

c_under#

Colormap to be assigned to the lowest color bound (under color) in the color map. The voxeled colored by c_under are the uninvaded void space. The default under color is grey.

[8]:
mov = ps.visualization.satn_to_movie(im=im, satn=satn, c_under='green')
image_based_ip_c_under = mov.to_html5_video()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [8], in <cell line: 2>()
      1 mov = ps.visualization.satn_to_movie(im=im, satn=satn, c_under='green')
----> 2 image_based_ip_c_under = mov.to_html5_video()

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:1266, in Animation.to_html5_video(self, embed_limit)
   1263 path = Path(tmpdir, "temp.m4v")
   1264 # We create a writer manually so that we can get the
   1265 # appropriate size for the tag
-> 1266 Writer = writers[mpl.rcParams['animation.writer']]
   1267 writer = Writer(codec='h264',
   1268                 bitrate=mpl.rcParams['animation.bitrate'],
   1269                 fps=1000. / self._interval)
   1270 self.save(str(path), writer=writer)

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:151, in MovieWriterRegistry.__getitem__(self, name)
    149 if self.is_available(name):
    150     return self._registered[name]
--> 151 raise RuntimeError(f"Requested MovieWriter ({name}) not available")

RuntimeError: Requested MovieWriter (ffmpeg) not available
../../../_images/examples_visualization_reference_satn_to_movie_18_2.svg
[9]:
HTML(image_based_ip_c_under)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [9], in <cell line: 1>()
----> 1 HTML(image_based_ip_c_under)

NameError: name 'image_based_ip_c_under' is not defined

c_over#

Colormap to be assigned to the highest color bound (over color) in the color map. The voxeled colored by c_overer are the solid phase. The default over color is white.

[10]:
mov = ps.visualization.satn_to_movie(im=im, satn=satn, c_over='yellow')
image_based_ip_c_over = mov.to_html5_video()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [10], in <cell line: 2>()
      1 mov = ps.visualization.satn_to_movie(im=im, satn=satn, c_over='yellow')
----> 2 image_based_ip_c_over = mov.to_html5_video()

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:1266, in Animation.to_html5_video(self, embed_limit)
   1263 path = Path(tmpdir, "temp.m4v")
   1264 # We create a writer manually so that we can get the
   1265 # appropriate size for the tag
-> 1266 Writer = writers[mpl.rcParams['animation.writer']]
   1267 writer = Writer(codec='h264',
   1268                 bitrate=mpl.rcParams['animation.bitrate'],
   1269                 fps=1000. / self._interval)
   1270 self.save(str(path), writer=writer)

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:151, in MovieWriterRegistry.__getitem__(self, name)
    149 if self.is_available(name):
    150     return self._registered[name]
--> 151 raise RuntimeError(f"Requested MovieWriter ({name}) not available")

RuntimeError: Requested MovieWriter (ffmpeg) not available
../../../_images/examples_visualization_reference_satn_to_movie_22_2.svg
[11]:
HTML(image_based_ip_c_over)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [11], in <cell line: 1>()
----> 1 HTML(image_based_ip_c_over)

NameError: name 'image_based_ip_c_over' is not defined

v_under#

This is the lowest bound of satn data range that the colormap covers. By default, the v_under is 0.001.

[12]:
mov = ps.visualization.satn_to_movie(im=im, satn=satn, v_under=0.2)
image_based_ip_v_under = mov.to_html5_video()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [12], in <cell line: 2>()
      1 mov = ps.visualization.satn_to_movie(im=im, satn=satn, v_under=0.2)
----> 2 image_based_ip_v_under = mov.to_html5_video()

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:1266, in Animation.to_html5_video(self, embed_limit)
   1263 path = Path(tmpdir, "temp.m4v")
   1264 # We create a writer manually so that we can get the
   1265 # appropriate size for the tag
-> 1266 Writer = writers[mpl.rcParams['animation.writer']]
   1267 writer = Writer(codec='h264',
   1268                 bitrate=mpl.rcParams['animation.bitrate'],
   1269                 fps=1000. / self._interval)
   1270 self.save(str(path), writer=writer)

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:151, in MovieWriterRegistry.__getitem__(self, name)
    149 if self.is_available(name):
    150     return self._registered[name]
--> 151 raise RuntimeError(f"Requested MovieWriter ({name}) not available")

RuntimeError: Requested MovieWriter (ffmpeg) not available
../../../_images/examples_visualization_reference_satn_to_movie_26_2.svg
[13]:
HTML(image_based_ip_v_under)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [13], in <cell line: 1>()
----> 1 HTML(image_based_ip_v_under)

NameError: name 'image_based_ip_v_under' is not defined

v_over#

This is the highest bound of satn data range that the colormap covers. By default, the v_over is 1.

[14]:
mov = ps.visualization.satn_to_movie(im=im, satn=satn, v_over=0.5)
image_based_ip_v_over = mov.to_html5_video()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [14], in <cell line: 2>()
      1 mov = ps.visualization.satn_to_movie(im=im, satn=satn, v_over=0.5)
----> 2 image_based_ip_v_over = mov.to_html5_video()

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:1266, in Animation.to_html5_video(self, embed_limit)
   1263 path = Path(tmpdir, "temp.m4v")
   1264 # We create a writer manually so that we can get the
   1265 # appropriate size for the tag
-> 1266 Writer = writers[mpl.rcParams['animation.writer']]
   1267 writer = Writer(codec='h264',
   1268                 bitrate=mpl.rcParams['animation.bitrate'],
   1269                 fps=1000. / self._interval)
   1270 self.save(str(path), writer=writer)

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:151, in MovieWriterRegistry.__getitem__(self, name)
    149 if self.is_available(name):
    150     return self._registered[name]
--> 151 raise RuntimeError(f"Requested MovieWriter ({name}) not available")

RuntimeError: Requested MovieWriter (ffmpeg) not available
../../../_images/examples_visualization_reference_satn_to_movie_30_2.svg
[15]:
HTML(image_based_ip_v_over)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [15], in <cell line: 1>()
----> 1 HTML(image_based_ip_v_over)

NameError: name 'image_based_ip_v_over' is not defined

fps#

This is the frames per second that the animation will be saved at. The default value is 10.

[16]:
mov = ps.visualization.satn_to_movie(im=im, satn=satn, fps=5)
image_based_ip_fps = mov.to_html5_video()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [16], in <cell line: 2>()
      1 mov = ps.visualization.satn_to_movie(im=im, satn=satn, fps=5)
----> 2 image_based_ip_fps = mov.to_html5_video()

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:1266, in Animation.to_html5_video(self, embed_limit)
   1263 path = Path(tmpdir, "temp.m4v")
   1264 # We create a writer manually so that we can get the
   1265 # appropriate size for the tag
-> 1266 Writer = writers[mpl.rcParams['animation.writer']]
   1267 writer = Writer(codec='h264',
   1268                 bitrate=mpl.rcParams['animation.bitrate'],
   1269                 fps=1000. / self._interval)
   1270 self.save(str(path), writer=writer)

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:151, in MovieWriterRegistry.__getitem__(self, name)
    149 if self.is_available(name):
    150     return self._registered[name]
--> 151 raise RuntimeError(f"Requested MovieWriter ({name}) not available")

RuntimeError: Requested MovieWriter (ffmpeg) not available
../../../_images/examples_visualization_reference_satn_to_movie_34_2.svg
[17]:
HTML(image_based_ip_fps)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [17], in <cell line: 1>()
----> 1 HTML(image_based_ip_fps)

NameError: name 'image_based_ip_fps' is not defined

repeat#

This variable indicates whether the animation repeats when the sequence of frames is completed. By default repeat=True.

[18]:
mov = ps.visualization.satn_to_movie(im=im, satn=satn, repeat=False)
image_based_ip_repeat = mov.to_html5_video()
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [18], in <cell line: 2>()
      1 mov = ps.visualization.satn_to_movie(im=im, satn=satn, repeat=False)
----> 2 image_based_ip_repeat = mov.to_html5_video()

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:1266, in Animation.to_html5_video(self, embed_limit)
   1263 path = Path(tmpdir, "temp.m4v")
   1264 # We create a writer manually so that we can get the
   1265 # appropriate size for the tag
-> 1266 Writer = writers[mpl.rcParams['animation.writer']]
   1267 writer = Writer(codec='h264',
   1268                 bitrate=mpl.rcParams['animation.bitrate'],
   1269                 fps=1000. / self._interval)
   1270 self.save(str(path), writer=writer)

File /usr/share/miniconda/envs/test/lib/python3.8/site-packages/matplotlib/animation.py:151, in MovieWriterRegistry.__getitem__(self, name)
    149 if self.is_available(name):
    150     return self._registered[name]
--> 151 raise RuntimeError(f"Requested MovieWriter ({name}) not available")

RuntimeError: Requested MovieWriter (ffmpeg) not available
../../../_images/examples_visualization_reference_satn_to_movie_38_2.svg
[19]:
HTML(image_based_ip_repeat)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [19], in <cell line: 1>()
----> 1 HTML(image_based_ip_repeat)

NameError: name 'image_based_ip_repeat' is not defined