pumapy.visualization

pumapy.visualization.render

class pumapy.visualization.render.Renderer(existing_plot=None, filter_type=None, workspace=None, cutoff=None, solid_color=None, style=None, origin=None, window_size=None, opacity=None, background=None, show_grid=None, plot_directly=None, show_axes=None, show_outline=None, cmap=None, scale_factor=None, notebook=None, sampling=None)[source]

Bases: object

build_plotter()[source]
render()[source]
pumapy.visualization.render.render_contour(workspace, cutoff, solid_color=(1.0, 1.0, 1.0), style='surface', origin=(0.0, 0.0, 0.0), window_size=(1920, 1200), opacity=1.0, background=(0.3, 0.3, 0.3), show_grid=True, plot_directly=True, show_axes=True, show_outline=True, add_to_plot=None, notebook=False)[source]

Contour render using Pyvista Contour filter

Parameters
  • workspace (Workspace or np.ndarray) – domain

  • cutoff ((int, int)) – specifying the values at which the isosurface is created

  • solid_color ((float, float, float)) – a solid color to color the surface (e.g. for white (1., 1., 1.))

  • style (string) – specifying the representation style (‘surface’, ‘edges’, ‘wireframe’, ‘points’)

  • origin ((float, float, float)) – origin of the data as

  • window_size ((int, int)) – with the popup window size

  • opacity (float) – opacity of contour

  • background – color of the background from (0., 0., 0.) (black) to (1., 1., 1.) (white)

  • show_grid (bool) – show the grid with the size of the sides

  • plot_directly (bool) – whether to return a Plotter object (to make further changes to it) or show the plot directly

  • show_axes (bool) – show orientation axis in the bottom left corner

  • show_outline (bool) – show the bounding box outline of the domain

  • add_to_plot (pyvista.Plotter or None) – pass an already existing plotter object to add on top of this plot

  • notebook (bool) – plotting interactively in a jupyter notebook (overwrites show_grid to False)

Type

background: (float, float, float)

Returns

None is plot_directly is True, otherwise a plotter object

Return type

pyvista.Plotter or None

Example

>>> import pumapy as puma
>>> ws_contour = puma.import_3Dtiff(puma.path_to_example_file("50_artfibers.tif"))
>>> puma.render_contour(ws_contour, (128,255))
pumapy.visualization.render.render_contour_multiphase(workspace, cutoffs, solid_colors=None, style='surface', origin=(0.0, 0.0, 0.0), window_size=(1920, 1200), opacity=1.0, background=(0.3, 0.3, 0.3), show_grid=True, plot_directly=True, show_axes=True, show_outline=True, add_to_plot=None, notebook=False)[source]

Contour render for multi-phase materials using Pyvista

Parameters
  • workspace (Workspace or ndarray) – domain

  • cutoffs (tuple) – n cutoffs is the number of materials. specifies the low and high cutoff ranges

  • solid_colors (tuple or None) – solid colors to color the different phases’ surface e.g. for white ((1., 1., 1.), (0., 0., 0.), …)

  • style (string) – specifying the representation style (‘surface’, ‘edges’, ‘wireframe’, ‘points’)

  • origin ((float, float, float)) – origin of the data as

  • window_size ((int, int)) – with the popup window size

  • opacity (float) – opacity of contour

  • background – color of the background from (0., 0., 0.) (black) to (1., 1., 1.) (white)

  • show_grid (bool) – show the grid with the size of the sides

  • plot_directly (bool) – whether to return a Plotter object (to make further changes to it) or show the plot directly

  • show_axes (bool) – show orientation axis in the bottom left corner

  • show_outline (bool) – show the bounding box outline of the domain

  • add_to_plot (pyvista.Plotter or None) – pass an already existing plotter object to add on top of this plot

  • notebook (bool) – plotting interactively in a jupyter notebook (overwrites show_grid to False)

Type

background: (float, float, float)

Returns

None is plot_directly is True, otherwise a plotter object

Return type

pyvista.Plotter or None

Example

>>> import pumapy as puma
>>> ws_multiphase = puma.import_3Dtiff(puma.path_to_example_file("100_fiberform.tif"), 1.3e-6)
>>> puma.render_contour_multiphase(ws_multiphase, ((100, 150), (150, 255)))
pumapy.visualization.render.render_orientation(workspace, scale_factor=1.0, solid_color=None, style='surface', origin=(0.0, 0.0, 0.0), window_size=(1920, 1200), opacity=1.0, background=(0.3, 0.3, 0.3), show_grid=True, cmap=None, plot_directly=True, show_axes=True, show_outline=True, add_to_plot=None, notebook=False, sampling=None)[source]

Orientation render using Pyvista Glyph filter

Parameters
  • workspace (Workspace or np.ndarray) – domain

  • scale_factor (float) – scale the arrows by a factor

  • solid_color (None or (float, float, float)) – a solid color for the arrows. Deafult is None, which colors the vectors by their magnitude. To color white, input set solid_color=(1., 1., 1.)

  • style (string) – specifying the representation style (‘surface’, ‘edges’, ‘wireframe’, ‘points’)

  • origin ((float, float, float)) – origin of the data as

  • window_size ((int, int)) – with the popup window size

  • opacity (float) – opacity of arrows

  • background – color of the background from (0., 0., 0.) (black) to (1., 1., 1.) (white)

  • show_grid (bool) – show the grid with the size of the sides

  • cmap (str or None) – matplotlib colormap to use (overwritten by solid_color if specified)

  • plot_directly (bool) – whether to return a Plotter object (to make further changes to it) or show the plot directly

  • show_axes (bool) – show orientation axis in the bottom left corner

  • show_outline (bool) – show the bounding box outline of the domain

  • add_to_plot (pyvista.Plotter or None) – pass an already existing plotter object to add on top of this plot

  • notebook (bool) – plotting interactively in a jupyter notebook (overwrites show_grid to False)

  • sampling (int or None) – number of arrows to sample (None means plot an arrow at each voxel)

Type

background: (float, float, float)

Returns

None is plot_directly is True, otherwise a plotter object

Return type

pyvista.Plotter or None

Example

>>> import pumapy as puma
>>> ws_orientation = puma.import_3Dtiff(puma.path_to_example_file("100_fiberform.tif"), 1.3e-6)
>>> puma.compute_orientation_st(ws_orientation, (90, 255))
>>> puma.render_orientation(ws_orientation)
pumapy.visualization.render.render_volume(workspace, cutoff=None, solid_color=None, style='surface', origin=(0.0, 0.0, 0.0), window_size=(1920, 1200), opacity=1.0, background=(0.3, 0.3, 0.3), show_grid=True, plot_directly=True, show_axes=True, show_outline=True, cmap='gray', add_to_plot=None, notebook=False)[source]

Volume render using Pyvista Threshold filter

Parameters
  • workspace (Workspace or np.ndarray) – domain

  • cutoff ((int, int) or None) – specifying the values to render

  • solid_color ((float, float, float) or None) – if set to None (default), the material is colored by the matrix’s values. Otherwise, a solid color can be specified (e.g. for white (1., 1., 1.))

  • style (string) – specifying the representation style (‘surface’, ‘edges’, ‘wireframe’, ‘points’)

  • origin ((float, float, float)) – origin of the data as

  • window_size ((int, int)) – with the popup window size

  • opacity (float) – opacity of volume

  • background – color of the background from (0., 0., 0.) (black) to (1., 1., 1.) (white)

  • show_grid (bool) – show the grid with the size of the sides

  • plot_directly (bool) – whether to return a Plotter object (to make further changes to it) or show the plot directly

  • show_axes (bool) – show orientation axis in the bottom left corner

  • show_outline (bool) – show the bounding box outline of the domain

  • cmap (str) – matplotlib colormap to use (overwritten by solid_color if specified)

  • add_to_plot (pyvista.Plotter or None) – pass an already existing plotter object to add on top of this plot

  • notebook (bool) – plotting interactively in a jupyter notebook (overwrites show_grid to False)

Type

background: (float, float, float)

Returns

None is plot_directly is True, otherwise a plotter object

Return type

pyvista.Plotter or None

Example

>>> import pumapy as puma
>>> ws_volume = puma.import_3Dtiff(puma.path_to_example_file("200_fiberform.tif"), 1.3e-6)
>>> puma.render_volume(ws_volume)
pumapy.visualization.render.render_warp(workspace, scale_factor=1.0, color_by='magnitude', style='surface', origin=(0.0, 0.0, 0.0), window_size=(1920, 1200), opacity=1.0, background=(0.3, 0.3, 0.3), show_grid=True, cmap='jet', plot_directly=True, show_axes=True, show_outline=True, add_to_plot=None, notebook=False)[source]

Warp a domain by an orientation field

Parameters
  • workspace (Workspace) – domain with both matrix and orientation defined

  • scale_factor (float) – scale the orientation by a factor

  • color_by (str) – it can be ‘magnitude’, which colors warped domain by magnitude of vectors, or ‘x’, ‘y’ or ‘z’, which colors it by the orientation component, or ‘matrix’, which colors it by the matrix phases

  • style (string) – specifying the representation style (‘surface’, ‘edges’, ‘wireframe’, ‘points’)

  • origin ((float, float, float)) – origin of the data as

  • window_size ((int, int)) – with the popup window size

  • opacity (float) – opacity of arrows

  • background – color of the background from (0., 0., 0.) (black) to (1., 1., 1.) (white)

  • show_grid (bool) – show the grid with the size of the sides

  • cmap (str) – matplotlib colormap to use (overwritten by solid_color if specified)

  • plot_directly (bool) – whether to return a Plotter object (to make further changes to it) or show the plot directly

  • show_axes (bool) – show orientation axis in the bottom left corner

  • show_outline (bool) – show the bounding box outline of the domain

  • add_to_plot (pyvista.Plotter or None) – pass an already existing plotter object to add on top of this plot

  • notebook (bool) – plotting interactively in a jupyter notebook (overwrites show_grid to False)

Type

background: (float, float, float)

Returns

None is plot_directly is True, otherwise a plotter object

Return type

pyvista.Plotter or None

Example

>>> import pumapy as puma
>>> ws = puma.Workspace.from_shape_value((20, 25, 18), 1)
>>> ws[ws.matrix.shape[0]//2:] = 2
>>> elast_map = puma.ElasticityMap()
>>> elast_map.add_isotropic_material((1, 1), 200, 0.3)
>>> elast_map.add_isotropic_material((2, 2), 400, 0.1)
>>> bc = puma.ElasticityBC(ws)
>>> bc.dirichlet[0] = 0  # hold x -ve face
>>> bc.dirichlet[-1, :, :, 0] = 10   # displace x +ve face by 1 in x direction
>>> bc.dirichlet[-1, :, :, 1:] = 0  # hold x +ve face in y and z directions
>>> ws.orientation, _, _ = puma.compute_stress_analysis(ws, elast_map, bc, side_bc='f', solver_type="direct")
>>> puma.render_warp(ws, color_by='y', style='edges')

pumapy.visualization.slicer

class pumapy.visualization.slicer.CompareSlicer(img1, img2, slice_direction, color_range1, color_map1, color_range2, color_map2, index, axis_labels, slices1, slices2, rows1, cols1, rows2, cols2)[source]

Bases: pumapy.visualization.slicer.IndexTracker

update()[source]
class pumapy.visualization.slicer.IndexTracker(img, img2, slice_direction, index, axis_labels, slices, slices_titles)[source]

Bases: object

static error_checks(img, img2, slice_direction)[source]
static format_coord(x, y)[source]
onkey(event)[source]
onscroll(event)[source]
static rotate_domain_mpl(img, slice_direction)[source]
update()[source]
class pumapy.visualization.slicer.PlotSlicer(img, slice_direction, color_range, color_map, index, axis_labels, slices, rows, cols)[source]

Bases: pumapy.visualization.slicer.IndexTracker

update()[source]
pumapy.visualization.slicer.compare_slices(ws_nparray1, ws_nparray2, slice_direction='z', crange1=None, cmap1='gray', crange2=None, cmap2='gray', index=1)[source]

Plot slices of domain along a specified direction (z default)

Parameters
  • ws_nparray1 (Workspace or np.ndarray) – domain

  • ws_nparray2 (Workspace or np.ndarray) – domain

  • slice_direction (string) – ‘x’, ‘y’, ‘z’

  • crange1 ((int, int)) – color range for plot 1, specify min and max grayscale

  • cmap1 (string) – color map for plot 1, ‘gray’ (default), ‘jet’ or refer to matplotlib for other colormaps

  • crange2 ((int, int)) – color range for plot 2, specify min and max grayscale

  • cmap2 (string) – color map for plot 2, ‘gray’ (default), ‘jet’ or refer to matplotlib for other colormaps

  • index (int) – specifying the slice index in which the plot will be opened

Returns

slicer object

Return type

CompareSlicer

>>> import pumapy as puma
>>> ws = puma.import_3Dtiff(puma.path_to_example_file("100_fiberform.tif"), 1.3e-6)
>>> ws2 = ws.copy()
>>> ws2.binarize_range((100, 255))
>>> puma.compare_slices(ws, ws2)
pumapy.visualization.slicer.plot_slices(ws_nparray, slice_direction='z', crange=None, cmap='gray', index=1)[source]

Plot slices of domain along a specified direction (z default)

Parameters
  • ws_nparray (Workspace or np.ndarray) – domain

  • slice_direction (string) – ‘x’, ‘y’, ‘z’

  • crange ((int, int)) – color range, i.e. specify min and max grayscale

  • cmap (string) – color map for the plot, ‘gray’ (default), ‘jet’ or refer to matplotlib for other colormaps

  • index – specifying the slice index in which the plot will be opened

Type

int

Returns

slicer object

Return type

PlotSlicer

>>> import pumapy as puma
>>> ws = puma.import_3Dtiff(puma.path_to_example_file("100_fiberform.tif"), 1.3e-6)
>>> puma.plot_slices(ws)