porescene.utility module¶
- class porescene.utility.CompassDirection(*values)[source]¶
Bases:
Enum- EAST = 'E'¶
- NORTH = 'N'¶
- NORTHEAST = 'NE'¶
- NORTHWEST = 'NW'¶
- SOUTH = 'S'¶
- SOUTHEAST = 'SE'¶
- SOUTHWEST = 'SW'¶
- WEST = 'W'¶
- class porescene.utility.Mesh(vertices, faces, name='object')[source]¶
Bases:
objectA simple container pairing a mesh’s vertices with its faces.
- class porescene.utility.UnitExponentMetric(*values)[source]¶
Bases:
Enum- ATTO = -18¶
- CENTI = -2¶
- DECA = 1¶
- DECI = -1¶
- EXA = 18¶
- FEMTO = -15¶
- GIGA = 9¶
- HECTO = 2¶
- KILO = 3¶
- MEGA = 6¶
- MICRO = -6¶
- MILLI = -3¶
- NANO = -9¶
- PETA = 15¶
- PICO = -12¶
- QUECTO = -30¶
- QUETTA = 30¶
- RONNA = 27¶
- RONTO = -27¶
- TERA = 12¶
- YOCTO = -24¶
- YOTTA = 24¶
- ZEPTO = -21¶
- ZETTA = 21¶
- class porescene.utility.UnitPrefixMetric(*values)[source]¶
Bases:
Enum- ATTO = 'a'¶
- CENTI = 'c'¶
- DECA = 'da'¶
- DECI = 'd'¶
- EXA = 'E'¶
- FEMTO = 'f'¶
- GIGA = 'G'¶
- HECTO = 'h'¶
- KILO = 'k'¶
- MEGA = 'M'¶
- MICRO = 'µ'¶
- MILLI = 'm'¶
- NANO = 'n'¶
- PETA = 'P'¶
- PICO = 'p'¶
- QUECTO = 'q'¶
- QUETTA = 'Q'¶
- RONNA = 'R'¶
- RONTO = 'r'¶
- TERA = 't'¶
- YOCTO = 'y'¶
- YOTTA = 'Y'¶
- ZEPTO = 'z'¶
- ZETTA = 'Z'¶
- porescene.utility.svg2png(pth, crop=True)[source]¶
Convert a SVG file to PNG.
Uses
resvg_pyfor the conversion, which ships as a self-contained wheel, sopip installpulls in everything and no external software is required. Withcrop=Truethe result is trimmed to its visible content by removing the surrounding transparent margin.Note that
resvg_pyonly renders content inside the SVG viewport; anything drawn beyond the root<svg>width/heightis clipped before the crop and cannot be recovered.
- porescene.utility.volume2mesh(img, voxel_size=(1.0, 1.0, 1.0), labels=1, *, per_label=False, name='object')[source]¶
- Overloads:
img (np.ndarray), voxel_size (float | Sequence[float]), labels (int | Sequence[int] | np.ndarray), per_label (Literal[False]), name (str) → Mesh
img (np.ndarray), voxel_size (float | Sequence[float]), labels (int | Sequence[int] | np.ndarray), per_label (Literal[True]), name (str) → dict[int, Mesh]
Builds a rectangular (quad) surface mesh from a labeled voxel image.
Extracts the axis-aligned boundary faces of the voxels whose label is included in
labels– every face between a selected voxel and a non-selected neighbour (or the volume border) – as unit squares scaled by the voxel size. Coincident vertices are merged, so each position is stored once and shared between faces.- Parameters:
img (
ndarray) – 2D or 3D integer array of voxel labels. A 2D image is treated as a single slice, one voxel thick along the third axis.voxel_size (
Union[float,Sequence[float]]) – Edge length of a voxel. A scalar applies to all three axes; a 3-element sequence gives the length along x, y and z, by default(1.0, 1.0, 1.0).labels (
Union[int,Sequence[int],ndarray]) – Label value(s) to include in the mesh, by default 1.per_label (
bool) – IfFalse(default), all selected labels are meshed into a single surface. IfTrue, a separate mesh is built per label and a{label: Mesh}mapping is returned.name (
str) – Name assigned to the resulting mesh. Inper_labelmode the label is appended as"{name}_{label}". By default"object".
- Returns:
For a single mesh, a
Meshwhoseverticesis an(N, 3)float array andfacesan(M, 4)integer array of quad vertex indices. Withper_label=True, a{label: Mesh}dict.- Return type: