morphogen.viz.video¶
Videos of morphologies and fields: .mp4 through ffmpeg (ffmpeg on the path, the
MORPHOGEN_FFMPEG variable or the imageio-ffmpeg package), .gif through Pillow, or a
folder of PNG frames.
Morphologies: a section sweeping through a voxel image along an axis, the three orthogonal
sections moving together (as the orthoslices of Avizo), a turntable of the surface of a
phase or of a mesh. Fields on tetrahedral meshes: a turntable coloured by a field, a
cross-section sweeping through the mesh, and the deformed mesh with a magnified
displacement (a mode oscillating, or a load growing), optionally cut by a plane, and its
history along the steps of a loading path; fields on voxel images, the same section at
successive times. The 3D views are rendered off screen by VTK; colours come from
matplotlib colormaps, on a fixed range over the frames, with a colour bar beside them.
Every video plays once, loops (repeat times) or goes back and forth
(mode="bounce").
- morphogen.viz.video.ffmpeg_path() str | None[source]¶
The ffmpeg executable:
MORPHOGEN_FFMPEG, the path, or imageio-ffmpeg’s.
- morphogen.viz.video.sequence(frames, mode: str = 'once', repeat: int = 1) list[ndarray][source]¶
The frames played once,
repeattimes in a loop, or forth and back.
- morphogen.viz.video.write_video(frames, path, *, fps: float = 24.0, mode: str = 'once', repeat: int = 1, crf: int = 18) Path[source]¶
Write RGB frames (uint8, all of one size) to
.mp4(H.264 by ffmpeg, qualitycrf),.gifor a folder of PNG files (a path without suffix).
- morphogen.viz.video.BAR = 88¶
Width in pixels of the colour bars beside the frames
- morphogen.viz.video.DIVERGING = ('coolwarm', 'bwr', 'seismic', 'RdBu', 'RdBu_r', 'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdYlBu', 'RdYlGn', 'Spectral', 'berlin', 'managua', 'vanimo')¶
their range is centred on zero for fields of both signs
- Type:
Diverging colormaps
- morphogen.viz.video.section_frames(image, axis: int = 2, *, size: int = 480, cmap='viridis', vmin=None, vmax=None, labels=None, caption=True, bar: bool = False, label: str = '')[source]¶
A section sweeping through a voxel image along
axis: label colours for phase images, a colormap (fixed range) for continuous ones, with a colour bar (bar) titledlabel.
- morphogen.viz.video.time_section_frames(images, axis: int = 2, index: int | None = None, *, size: int = 480, cmap='viridis', vmin=None, vmax=None, captions=None, bar: bool = True, label: str = '')[source]¶
The same section (
indexalongaxis, by default the middle one) of successive fields on a voxel grid (a field at the times of a loading path), on one colour range, with a colour bar and a caption per time (e.g."t = 10").
- morphogen.viz.video.orthoslice_frames(image, *, frames: int = 48, size: int = 300, cmap='viridis', vmin=None, vmax=None, labels=None)[source]¶
The three orthogonal sections moving together through a voxel image, side by side (normal to x, y and z).
- morphogen.viz.video.vtk_can_render() bool[source]¶
Whether VTK can render off screen here. Without a display, EGL or OSMesa, VTK aborts the process at its first render, so a subprocess renders first; the answer is kept.
- class morphogen.viz.video.Scene(size=(640, 480), background=(1.0, 1.0, 1.0))[source]¶
Bases:
objectAn off-screen VTK scene: actors, a camera turning about the centre of their bounds, and the rendered frames as RGB arrays.
- morphogen.viz.video.turntable_frames(obj, *, field=None, phase: int = 1, frames: int = 72, size=(640, 480), elevation: float = 25.0, azimuth: float = 30.0, cmap='viridis', clim=None, title: str = '', edges: bool = False)[source]¶
A turntable of the surface of a phase of a voxel image, or of a tetrahedral mesh coloured by
field(per node or element, vectors by their norm;"phase": the phases of the elements).
- morphogen.viz.video.section_sweep_frames(mesh, field=None, *, axis: int = 2, frames: int = 48, size=(640, 480), elevation: float = 25.0, azimuth: float = 30.0, cmap='viridis', clim=None, title: str = '')[source]¶
A cross-section sweeping through a tetrahedral mesh along
axis: the part beyond the plane, coloured byfieldon its outer faces and on the cut ("phase": the phases of the elements).
- morphogen.viz.video.field_frames(mesh, displacement, field=None, *, magnification: float | None = None, frames: int = 48, wave: str = 'sine', section=None, size=(640, 480), elevation: float = 25.0, azimuth: float = 30.0, cmap='viridis', clim=None, title: str = '', scaling: str | None = None)[source]¶
The deformed mesh
x + s(t) m u:wave“sine” (a mode oscillating,s = sin 2πt) or “ramp” (a load growing,s = t);mthe magnification (by default the largest displacement drawn as a tenth of the mesh); coloured byfield(by default the norm of the displacement), optionally cut by a planesection = (axis, fraction). The field is that of the full load, which a linear solution scales bys(scalingoffield_scaling(): by default"magnitude"for the norm of the displacement,"linear"for other values,"none"for the phases), so that the colours follow the load in a range fixed over the frames (clim, else that of the full load from zero, symmetric when an oscillating load changes the sign).
- morphogen.viz.video.SCALINGS = ('linear', 'magnitude', 'quadratic', 'none')¶
How the fields of a linear solution follow its load factor
s(field_scaling())
- morphogen.viz.video.field_scaling(name: str | None) str[source]¶
How a field of a linear solution follows its load factor
s:"linear"(s v: the components of stresses, strains and displacements),"magnitude"(|s| v: norms and equivalent values, the von Mises stress, the norm of the displacement,None),"quadratic"(s² v: energy densities) or"none"(the phases).
- morphogen.viz.video.deformed_view(mesh, displacement=None, field=None, *, magnification: float | None = None, section=None, size=(640, 480), elevation: float = 25.0, azimuth: float = 30.0, cmap='viridis', clim=None, title: str = '', edges: bool = False) ndarray[source]¶
One view (an RGB array) of a tetrahedral mesh coloured by
field(per node or element, vectors by their norm;"phase": the phases of the elements), deformed bym uwhen adisplacementis given (mas infield_frames()), cut by the planesection = (axis, fraction).
- morphogen.viz.video.history_frames(mesh, displacements, fields=None, *, frames: int | None = None, magnification: float | None = None, section=None, size=(640, 480), elevation: float = 25.0, azimuth: float = 30.0, cmap='viridis', clim=None, title: str = '', captions=None)[source]¶
The mesh deformed by the displacements of successive times (the steps of a loading path),
x + m u_k(mas infield_frames()), coloured by thefieldsof these times (per node or element; by default the norm of the displacement) on one range, cut by the planesection = (axis, fraction).frames: that many frames interpolated linearly between the times (by default one per time);captions: a text per time (e.g."t = 10"), shown on the frames nearest to it.
- morphogen.viz.video.frame_pattern_frames(frame, mode, *, magnification: float = 1.0, frames: int = 48, wave: str = 'sine', tiles=None, size: int = 480)[source]¶
A pattern of a frame of beams oscillating (
wave="sine") or growing ("ramp") ontilescopies of its cell: a plane frame (Frame, 3 x 3 cells by default) or a frame of struts in space (SpaceFrame, one cell seen in perspective).