Skip to content

io

File reading and writing for point cloud data: JSON, OFF meshes, PLY, and safetensors.

Functions:

  • load_json –

    Read a JSON file.

  • load_off –

    Read an OFF mesh, triangulating its quadrilateral faces.

  • load_ply –

    Read a PLY file into one structured array per element.

  • save_ply –

    Write structured arrays as the elements of a PLY file.

  • save_safetensors –

    Write a mapping to a safetensors file, storing its string entries as metadata.

  • load_safetensors –

    Read a safetensors file, merging its metadata back into the tensor mapping.

load_json [source] ΒΆ

load_json(file_path: PathLike) -> Dict[str, Any]

Read a JSON file.

Parameters:

  • file_path (PathLike) –

    Path to the JSON file.

Returns:

  • Dict[str, Any] –

    The decoded JSON object.

load_off [source] ΒΆ

load_off(file_path: PathLike) -> Tuple[ndarray, ndarray]

Read an OFF mesh, triangulating its quadrilateral faces.

Parameters:

  • file_path (PathLike) –

    Path to the OFF file.

Returns:

  • Tuple[ndarray, ndarray] –

    The vertices \((V, 3)\) and the triangle indices \((F, 3)\).

load_ply [source] ΒΆ

load_ply(file_path: PathLike) -> Dict[str, ndarray]

Read a PLY file into one structured array per element.

Reads the ASCII and both binary encodings. A scalar property is a field of its element's array. A list property whose length is the same on every row is a field of shape \((k,)\); one whose length varies is an object field holding one array per row.

Parameters:

  • file_path (PathLike) –

    Path to the PLY file.

Returns:

  • Dict[str, ndarray] –

    The elements keyed by name, in file order, each a structured array with one field per property.

save_ply [source] ΒΆ

save_ply(
    file_path: PathLike,
    elements: Mapping[str, ndarray],
    *,
    text: bool = False,
) -> None

Write structured arrays as the elements of a PLY file.

A scalar field becomes a scalar property and a field with a sub-array shape \((k,)\) a list uchar property of \(k\) items. The binary encoding is little endian.

Parameters:

  • file_path (PathLike) –

    Path to the PLY file to write.

  • elements (Mapping[str, ndarray]) –

    The elements keyed by name, written in that order, each a structured array.

  • text (bool, default: False ) –

    Write the ASCII encoding instead of the binary one.

save_safetensors [source] ΒΆ

save_safetensors(
    file_path: PathLike, data: Mapping[str, Any]
) -> None

Write a mapping to a safetensors file, storing its string entries as metadata.

Parameters:

  • file_path (PathLike) –

    Path to the safetensors file to write.

  • data (Mapping[str, Any]) –

    Mapping of names to tensors, scalars (wrapped in a tensor) or strings.

load_safetensors [source] ΒΆ

load_safetensors(
    file_path: PathLike,
) -> Dict[str, Tensor | str]

Read a safetensors file, merging its metadata back into the tensor mapping.

Parameters:

  • file_path (PathLike) –

    Path to the safetensors file.

Returns:

  • Dict[str, Tensor | str] –

    The file's tensors and string metadata, keyed by name.