liblaf.melon.io
¶
I/O dispatchers and mesh-format conversion helpers.
Modules:
-
abc–Reusable dispatchers for readers, writers, and converters.
-
pyvista–PyVista readers, writers, and conversion dispatchers.
-
trimesh–Trimesh conversion and writer registration.
-
utils– -
vtk– -
warp–Warp mesh conversion helpers.
-
wrap–JSON sidecar helpers for Faceform Wrap projects.
Classes:
-
AbstractConverter–Callable that converts one object into another mesh representation.
-
AbstractReader–Callable that loads an object from a path.
-
AbstractWriter–Callable that writes an object to a path.
-
ConverterDispatcher–Single-dispatch conversion registry with identity conversion built in.
-
ReaderDispatcher–Dispatch readers by file suffix with an optional fallback reader.
-
VTKHDFTemporalUnstructuredGridWriter– -
WriterDispatcher–Dispatch writers first by file suffix and then by object type.
Functions:
-
load_landmarks–Load Wrap landmark points from JSON.
-
load_polygons–Load selected polygon indices from JSON.
-
save_landmarks–Save landmark points in Wrap-compatible JSON format.
-
save_polygons–Save selected polygon indices for Wrap projects.
Attributes:
-
as_multiblock(ConverterDispatcher[MultiBlock]) –Convert supported scene objects to [
pyvista.MultiBlock][]. -
as_polydata(ConverterDispatcher[PolyData]) –Convert supported mesh objects to [
pyvista.PolyData][]. -
as_trimesh(ConverterDispatcher[Trimesh]) –Convert supported triangular mesh objects to [
trimesh.Trimesh][]. -
as_unstructured_grid(ConverterDispatcher[UnstructuredGrid]) –Convert supported volume meshes to [
pyvista.UnstructuredGrid][]. -
as_warp_mesh(ConverterDispatcher[Mesh]) –Convert supported triangular meshes to [
warp.Mesh][]. -
load_multiblock(ReaderDispatcher[MultiBlock]) –Load a multi-block PyVista dataset.
-
load_polydata(ReaderDispatcher[PolyData]) –Load a surface mesh as [
pyvista.PolyData][]. -
load_unstructured_grid(ReaderDispatcher[UnstructuredGrid]) –Load an unstructured volume mesh with PyVista.
-
save(WriterDispatcher[Any]) –Write registered mesh and scene objects to disk based on path suffix.
as_multiblock
module-attribute
¶
as_multiblock: ConverterDispatcher[MultiBlock] = (
ConverterDispatcher(MultiBlock)
)
Convert supported scene objects to [pyvista.MultiBlock][].
as_polydata
module-attribute
¶
as_polydata: ConverterDispatcher[PolyData] = (
ConverterDispatcher(PolyData)
)
Convert supported mesh objects to [pyvista.PolyData][].
as_trimesh
module-attribute
¶
as_trimesh: ConverterDispatcher[Trimesh] = (
ConverterDispatcher(Trimesh)
)
Convert supported triangular mesh objects to [trimesh.Trimesh][].
as_unstructured_grid
module-attribute
¶
as_unstructured_grid: ConverterDispatcher[
UnstructuredGrid
] = ConverterDispatcher(UnstructuredGrid)
Convert supported volume meshes to [pyvista.UnstructuredGrid][].
as_warp_mesh
module-attribute
¶
as_warp_mesh: ConverterDispatcher[Mesh] = (
ConverterDispatcher(Mesh)
)
Convert supported triangular meshes to [warp.Mesh][].
load_multiblock
module-attribute
¶
load_multiblock: ReaderDispatcher[MultiBlock] = (
ReaderDispatcher(MultiBlock)
)
Load a multi-block PyVista dataset.
load_polydata
module-attribute
¶
load_polydata: ReaderDispatcher[PolyData] = (
ReaderDispatcher(PolyData)
)
Load a surface mesh as [pyvista.PolyData][].
load_unstructured_grid
module-attribute
¶
load_unstructured_grid: ReaderDispatcher[
UnstructuredGrid
] = ReaderDispatcher(UnstructuredGrid)
Load an unstructured volume mesh with PyVista.
save
module-attribute
¶
save: WriterDispatcher[Any] = WriterDispatcher()
Write registered mesh and scene objects to disk based on path suffix.
AbstractConverter
¶
AbstractReader
¶
AbstractWriter
¶
ConverterDispatcher
¶
Single-dispatch conversion registry with identity conversion built in.
The target type is registered as an identity conversion, so callers can pass through objects that are already in the requested representation.
Examples:
>>> converter = ConverterDispatcher(str)
>>> converter("mesh")
'mesh'
>>> @converter.register(int)
... def _from_int(obj, /, **kwargs):
... return str(obj)
>>> converter(42)
'42'
Parameters:
-
to_type(type[T]) –Target type returned unchanged when the input already has that runtime type.
-
registry(_SingleDispatchCallable[T], default:<dynamic>) –Underlying
functools.singledispatchregistry.
Methods:
Attributes:
-
registry(_SingleDispatchCallable[T]) –Underlying
functools.singledispatchregistry. -
to_type(type[T]) –Target type returned unchanged when the input already has that runtime type.
registry
class-attribute
instance-attribute
¶
Underlying functools.singledispatch registry.
to_type
instance-attribute
¶
to_type: type[T]
Target type returned unchanged when the input already has that runtime type.
register
¶
register[F](
cls: _RegType, converter: AbstractConverter[F, T]
) -> AbstractConverter[F, T]
register[F](
cls: _RegType, converter: None = None
) -> Callable[
[AbstractConverter[F, T]], AbstractConverter[F, T]
]
Source code in src/liblaf/melon/io/abc/_converter.py
ReaderDispatcher
¶
Dispatch readers by file suffix with an optional fallback reader.
Raises:
-
KeyError–If the path suffix is unknown and no fallback reader exists.
Attributes:
Parameters:
-
to_type(type[T]) – -
fallback(AbstractReader[T] | None, default:None) – -
registry(dict[str, AbstractReader[T]], default:<class 'dict'>) –dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
Methods:
registry
class-attribute
instance-attribute
¶
registry: dict[str, AbstractReader[T]] = field(
factory=dict
)
__call__
¶
Source code in src/liblaf/melon/io/abc/_reader.py
register
¶
register(
suffixes: Iterable[str], reader: AbstractReader[T]
) -> AbstractReader[T]
register(
suffixes: Iterable[str], reader: None = None
) -> Callable[[AbstractReader[T]], AbstractReader[T]]
Source code in src/liblaf/melon/io/abc/_reader.py
register_fallback
¶
register_fallback(
reader: AbstractReader[T],
) -> AbstractReader[T]
VTKHDFTemporalUnstructuredGridWriter
¶
Methods:
-
__enter__– -
__exit__– -
append– -
dataset– -
dataset_offsets– -
dataset_tail_equal– -
group–
Attributes:
__enter__
¶
__enter__() -> Self
Source code in src/liblaf/melon/io/vtk/_temporal_unstructured_grid.py
__exit__
¶
__exit__(
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None
Source code in src/liblaf/melon/io/vtk/_temporal_unstructured_grid.py
append
¶
append(
mesh: UnstructuredGrid,
time: SupportsFloat | None = None,
) -> None
Source code in src/liblaf/melon/io/vtk/_temporal_unstructured_grid.py
dataset
¶
dataset(
name: str, data: ArrayLike | None = None
) -> Dataset
Source code in src/liblaf/melon/io/vtk/_temporal_unstructured_grid.py
dataset_offsets
¶
Source code in src/liblaf/melon/io/vtk/_temporal_unstructured_grid.py
dataset_tail_equal
¶
Source code in src/liblaf/melon/io/vtk/_temporal_unstructured_grid.py
WriterDispatcher
¶
Dispatch writers first by file suffix and then by object type.
Registered writers receive a pathlib.Path. Parent directories are created
before the writer is called, which keeps concrete writer implementations
focused on serialization.
Raises:
-
KeyError–If no writer registry exists for the path suffix.
-
NotImplementedError–If the suffix exists but the object type is not registered for that suffix.
Parameters:
-
registry(dict[str, _SingleDispatchCallable[None]], default:<class 'dict'>) –dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
Methods:
Attributes:
registry
class-attribute
instance-attribute
¶
__call__
¶
Source code in src/liblaf/melon/io/abc/_writer.py
register
¶
register(
cls: _RegType,
suffixes: Iterable[str],
writer: AbstractWriter[T],
) -> AbstractWriter[T]
register(
cls: _RegType,
suffixes: Iterable[str],
writer: None = None,
) -> Callable[[AbstractWriter[T]], AbstractWriter[T]]
Source code in src/liblaf/melon/io/abc/_writer.py
load_landmarks
¶
Load Wrap landmark points from JSON.
Non-JSON mesh paths are mapped to a sibling .landmarks.json file. Missing
files return an empty (0, 3) array so annotation workflows can start from
an unmarked mesh.
Parameters:
-
path(StrPath) –Landmark JSON file or mesh path whose landmark sidecar should be inferred.
Returns:
-
Float[ndarray, 'L 3']–Landmark coordinates in
x,y,zorder.
Source code in src/liblaf/melon/io/wrap/_landmarks.py
load_polygons
¶
Load selected polygon indices from JSON.
Parameters:
-
path(StrPath) –JSON file containing polygon indices.
Returns:
-
Integer[ndarray, ' N']–One-dimensional
int32array of selected polygon indices. Missing files -
Integer[ndarray, ' N']–return an empty array.
Source code in src/liblaf/melon/io/wrap/_polygons.py
save_landmarks
¶
Save landmark points in Wrap-compatible JSON format.
Parameters:
-
landmarks(Float[ArrayLike, 'L 3']) –Array-like landmark coordinates with shape
(n, 3). -
path(StrPath) –Landmark JSON file or mesh path whose landmark sidecar should be inferred.
Source code in src/liblaf/melon/io/wrap/_landmarks.py
save_polygons
¶
save_polygons(
polygons: Bool[ArrayLike, " full"]
| Integer[ArrayLike, " selection"],
path: StrPath,
) -> None
Save selected polygon indices for Wrap projects.
Boolean masks are converted to their selected indices before serialization.
Parameters:
-
polygons(Bool[ArrayLike, ' full'] | Integer[ArrayLike, ' selection']) –Boolean mask over all polygons or explicit polygon indices.
-
path(StrPath) –JSON file to write.