ramp#

ramp is a simple function which creates a linear ramp of values along a given axis. This function is useful for “detrending” a diffusion simulation, or for computing the elevation of each voxel in an image for including gravity effects in invasion simulations.

import porespy as ps
import matplotlib.pyplot as plt
import numpy as np
ps.visualization.set_mpl_style()
[17:46:54] ERROR    PARDISO solver not installed, run `pip install pypardiso`. Otherwise,          _workspace.py:56
                    simulations will be slow. Apple M chips not supported.                                         

shape#

Both 2D and 3D images can be generated. Since this function is typically used in conjunction with some other image, then shape=other_im.shape would be a common option.

shape = [200, 200]
im = ps.generators.ramp(shape=shape, inlet=1, outlet=0)
fig, ax = plt.subplots(1, 1, figsize=[4, 4])
ax.imshow(im, origin='lower', interpolation='none');
../../../_images/15940a3c889514b85221709bc306a79e3d8211ffb94742f84c98ec4354469043.png

inlet and outlet#

These arguments specific the inlet and outlet values. The inlet values will be stored at the start of the specified axis, and outlet values at the end.

fig, ax = plt.subplots(1, 2, figsize=[8, 4])
h0 = ax[0].imshow(ps.generators.ramp([100, 100], inlet=0, outlet=1), origin='lower')
plt.colorbar(h0)
h1 = ax[1].imshow(ps.generators.ramp([100, 100], inlet=100, outlet=0), origin='lower')
plt.colorbar(h1);
../../../_images/09509e8ce6fd443208f9774bbf34929f01453fd540824a438e8d7ba4d7b8f00f.png

axis#

The direction of the ramp can be controlled by change which axis is used:

fig, ax = plt.subplots(1, 2, figsize=[8, 4])
axis = 0
ax[0].imshow(ps.generators.ramp([100, 100], inlet=0, outlet=1, axis=axis), origin='lower')
ax[0].set_title(f"Axis: {axis}")

axis = 1
ax[1].imshow(ps.generators.ramp([100, 100], inlet=0, outlet=1, axis=1), origin='lower')
ax[1].set_title(f"Axis: {axis}");
../../../_images/3d32466dca6d36ac84d78a31a306a451eb29ddd4b4e57234eb38f32a84ce608e.png