morphogen.viz.sections¶
Sections of microstructures computed in their planes, without their 3D images.
A section normal to axis is sampled on the pixel centres of a plane: those of the
voxel grid of the domain whose cells have the edge h = max(L_u, L_v) / resolution
(L_u, L_v: the edges of the plane), rint(L_a / h) cells along each edge
(volume_grid()), at the cells of index min(floor(fraction n), n - 1) along the
axis (plane_index(): the cells containing lower + fraction L, the middle ones for
fraction = 1/2 as in morphogen.viz.png.slice_of(); fraction 0 and 1 give the
first and the last cells, inside the domain). The structure is evaluated on a grid one
cell thick (plane_grid()) whose cell centres are those of that slice, bit for bit:
a section is the slice of the voxel image at the same resolution, at the cost of n^2
values instead of n^3 (up to 2048 x 2048 pixels and more).
Every 2D array is displayed like morphogen.viz.png.slice_of(): the first remaining
axis horizontal, the second vertical, rows from the top (np.flipud(s.T) of the slice
s[u, v]).
How the structures are sampled (Section.sampling):
plane: unions of spheres and segments (Boolean and hard-core spheres, fibres, strut and random lattices, foams, trees), TPMS, tessellations, Gaussian fields, lattice fields (automata, growth, reconstructions, tile assemblies; the cells themselves when the grid is their lattice), laminates, honeycombs, nacre, Bouligand plywoods, level-set foams, osteons, fractal sponges and scale-rich networks: they only evaluate the points of the grid they are given. So are the combinations of such structures, Cox spheres in such aggregates, and the coatings and shells of unions of spheres and segments (exact distances);planetoo for dead leaves and transparent dead leaves, on a cell as thick as the box along the axis (centred on the plane): their kernels wrap the leaves over the grid, a periodic grid being the whole box;volume: the slice of the voxel image at the resolution, for the coatings and shells computed through the distance transform of the voxels of their structure (any structure but unions of spheres and segments), and the combinations, Cox spheres and coatings of such structures or of periodic dead leaves;coarsebeyondMAX_VOLUMEvoxels: the slice of a coarser voxel image, enlarged (phases and labels of the coarse voxels containing the pixel centres, level set interpolated linearly).
The level set phi (negative in phase 1) gives the anti-aliased fraction of phase 1 in
each pixel (pixel_coverage()). A straight interface passing at the signed distance
d = phi / |grad phi| from the centre of a pixel of edges (h_u, h_v) leaves the
whole pixel in phase 1 for d <= -w/2 and none of it for d >= w/2, w = h_u |n_u| +
h_v |n_v| being the width of the pixel across the interface (n: its normal); in
between, linearly (exact for interfaces along the axes),
coverage = clip(1/2 - d / w, 0, 1) = clip(1/2 - phi / (|D_u phi| + |D_v phi|), 0, 1)
with D_a phi = h_a dphi/da estimated by the larger of the one-sided differences of the
level set with the two neighbours along a: independent of the scale of the level set
(Gaussian fields, concentrations), and finite at its extrema (features thinner than a
pixel keep a partial coverage).
The structures of several phases (dead leaves of several families, osteons, coatings,
inclusions, tessellations whose cells have phases) have one implicit function per phase
(phase_level_set()), each negative in its
phase: the sections sampled on their plane keep the fraction of each phase in each pixel
(phase_coverages(): the coverage of each function, scaled so that they sum to one),
and their images blend the colours of the phases by them.
level_set_measures() measures the volume fraction and the specific surface of
phase 1 from the 3D level set at a modest resolution (the smoothed Heaviside and the
marching cubes of its zero level set).
- morphogen.viz.sections.MAX_VOLUME = 16777216¶
Largest voxel image (in voxels) of the structures that cannot be sampled on a plane; beyond, their sections are those of a coarser image, enlarged.
- morphogen.viz.sections.MAX_PHASES = 8¶
Most phases whose implicit functions the sections evaluate (one function per phase); beyond, the pixels take the plain colour of the phase of their centre.
- morphogen.viz.sections.CONTOUR = array([20., 20., 20.])¶
Colour of the contours.
- morphogen.viz.sections.volume_grid(domain: Domain, axis: int = 2, resolution: int = 512) Grid[source]¶
The voxel grid of
domainwhose slices normal toaxisare its sections atresolution: cells of edge abouth = max(L_u, L_v) / resolution(L_u,L_v: the edges of the plane),max(1, rint(L_a / h))along each axis, square in the plane up to the rounding of its edges to whole pixels.
- morphogen.viz.sections.plane_index(domain: Domain, axis: int = 2, fraction: float = 0.5, resolution: int = 512) int[source]¶
Index along
axisof the cells ofvolume_grid()holding the section: those containinglower + fraction L,min(floor(fraction n), n - 1)(n // 2for a half).
- morphogen.viz.sections.plane_grid(domain: Domain, axis: int = 2, fraction: float = 0.5, resolution: int = 512) Grid[source]¶
A grid one cell thick of the plane normal to
axisatfractionof the domain (0 to 1 fromdomain.lower): the cells ofvolume_grid()(resolutionpixels along the longest edge of the plane, square pixels) of indexplane_index()along the axis, whose centres lie exactly on the plane.
- class morphogen.viz.sections.Section(axis: int, fraction: float, phase: ndarray, level_set: ndarray | None, coverage: ndarray | None, labels: ndarray | None, pixel: float, extent: tuple[float, float, float, float], names: tuple[str, str], position: float = nan, index: int = 0, sampling: str = 'plane', coverages: dict[int, ndarray] | None = None)[source]¶
Bases:
objectA section of a microstructure normal to
axis, its 2D arrays displayed likemorphogen.viz.png.slice_of()(first in-plane axis horizontal, rows from the top).- axis, fraction
Normal of the plane and the position asked for (0 to 1 from the lower face).
- phase¶
Phase at each pixel centre (uint8).
- Type:
numpy.ndarray
- level_set¶
Level set at the pixel centres, negative in phase 1 (float32; None for the structures without one).
- Type:
numpy.ndarray | None
- coverage¶
Anti-aliased fraction of phase 1 in each pixel, from the level set (float32 in [0, 1],
pixel_coverage(); None without a level set).- Type:
numpy.ndarray | None
- labels¶
Cell or grain labels (int32) of the structures that have them, else None.
- Type:
numpy.ndarray | None
- pixel¶
Pixel size (the larger of its two edges).
- Type:
float
- extent¶
In-plane bounds
(h0, h1, v0, v1): horizontal, then vertical.- Type:
tuple[float, float, float, float]
- names¶
Names of the horizontal and vertical axes, e.g.
("x", "y").- Type:
tuple[str, str]
- position¶
Coordinate of the plane along the axis (the centre of its cells).
- Type:
float
- index¶
Index of the plane in the voxel grid of the same pixels (
volume_grid()).- Type:
int
- sampling¶
plane(evaluated on the plane),volume(slice of the voxel image) orcoarse(slice of a coarser voxel image, enlarged).- Type:
str
- coverages¶
For the structures of several phases sampled on the plane: the anti-aliased fraction of each phase in each pixel, from the implicit function of each phase (float32 in [0, 1], by phase,
phase_coverages()); None otherwise.- Type:
dict[int, numpy.ndarray] | None
- property shape: tuple[int, int]¶
Rows and columns of the arrays.
- property title: str¶
Name of the plane, e.g.
"x-y".
- morphogen.viz.sections.has_level_set(micro) bool[source]¶
Whether the phase 1 of
microis described by a level set (two phases, the model saying so; structures without a model are tried).
- morphogen.viz.sections.is_planar(micro, resolution: int = 512) bool[source]¶
Whether the sections of
microreduce to the x-y one: one cell along z at this resolution, or a lattice of one cell along z (2D structures, extruded).
- morphogen.viz.sections.section(micro, axis: int = 2, fraction: float = 0.5, resolution: int = 512) Section[source]¶
The section of
micronormal toaxisatfractionof the domain, withresolutionpixels along the longest edge of the plane: the slice of indexplane_index()ofmicro.voxelize(grid=volume_grid(...))(and of its level set and labels), computed on the plane alone when the structure allows it (see the module).
- morphogen.viz.sections.sections(micro, resolution: int = 512) list[Section][source]¶
The middle sections normal to x, y and z (y-z, x-z, x-y), or the x-y one alone for planar structures (
is_planar()).
- morphogen.viz.sections.pixel_coverage(phi) ndarray[source]¶
Fraction of phase 1 in each pixel from the level set at the pixel centres:
clip(1/2 - phi / (|D_u phi| + |D_v phi|), 0, 1)(see the module), 1 or 0 by the sign ofphiwhere it does not vary.
- morphogen.viz.sections.phase_coverages(levels: dict[int, ndarray], phase: ndarray) dict[int, ndarray][source]¶
Fraction of each phase in each pixel from the implicit functions
levelsof the phases at the pixel centres (by phase, each negative in its phase): thepixel_coverage()of each, scaled so that they sum to one; where none of them covers the pixel, thephaseof its centre takes it.
- morphogen.viz.sections.render(sec: Section, kind: str = 'phase', *, contour: bool = False) ndarray[source]¶
RGB image (uint8, rows x columns x 3) of a section.
phase: the colours ofmorphogen.viz.png.PALETTE, those of phases 0 and 1 blended by the coverage when the section has a level set (anti-aliased boundaries), those of all the phases by their coverages when it has the implicit functions of several phases, the plain colours of the phases otherwise;labels: a colour per cell or grain (morphogen.viz.png.label_colors()).contourdraws the zero level set as a thin dark line (1 - |2 coverage - 1|of the dark colour; between several phases, twice the share of the pixel that is not of its main phase), or without a level set the boundaries between the phases or labels shown.
- morphogen.viz.sections.level_set_measures(micro, resolution: int = 128) dict[str, float][source]¶
Volume fraction and specific surface of phase 1 from its level set
phi.phiis sampled on the voxel grid of the domain withresolutioncells along its longest edge (at the cell centres of a periodic domain, at the nodes from face to face otherwise, weighted by the trapezoidal rule), and turned into the distanced = phi / |grad phi|to its zero level set (centred differences). Witheps = h(the largest cell edge):volume_fraction: the mean of the smoothed HeavisideH(-d),H(x) = (1 + x / eps + sin(pi x / eps) / pi) / 2on[-eps, eps]. Its samples sum exactly to the volume for plane interfaces (the spectrum ofH'vanishes at the multiples of1 / h); curvature adds about0.13 eps^2times the integral of the mean curvature (0.39 (eps / R)^2of the volume of spheres of radiusR), more for struts a few cells thick;specific_surface: the area of the zero level set in the domain per unit volume, by marching cubes (scikit-image, thesurfaceextra), else by the coarea formulamean(delta(phi') |grad phi'|),delta(x) = (1 + cos(pi x / eps)) / (2 eps)on[-eps, eps],phi'beingphiover its median gradient at the interface (an estimate, low for gaps and struts thinner than2 eps).
Only for structures with a level set (ValueError otherwise).