Skip to main content

cmb-format

CMB (Cell Model Binary) is a binary file format and Python I/O library for storing UBC GIF–style tensor and octree meshes and their associated models. It provides an alternative to the ASCII mesh and model files used by UBC GIF software. CMB supports uniform and variable-spacing tensor meshes, octree meshes, multiple named models, and file- and model-level metadata.

CMB stores mesh geometry and model values as typed arrays, with metadata in JSON, so consumers can avoid parsing millions of numbers from text. Large octree consumers that need only arrays can also avoid allocating a full consumer mesh; see the discretize round trips and benchmarks.

Capabilities

  • Store mesh geometry and per-cell model arrays together in a .cmb file.
  • Store models separately from geometry to avoid duplicating large meshes.
  • Read individual arrays without loading the whole file.
  • Verify each array's integrity with a SHA-256 checksum.

Installation

Requires Python 3.11 or newer. NumPy is the only runtime dependency. From a local checkout:

python -m pip install .

Usage

The API accepts dictionaries of NumPy arrays describing meshes and models. CMB uses a different cell ordering from UBC GIF; these routines do not convert between the two. See Cell numbering / ordering in the format specification.

Write a four-cell tensor mesh and a resistivity model, then read them back:

import numpy as np

import cmb_format as cmb

mesh = {
    "mode": "embedded",
    "mesh_class": "TensorMesh",
    "arrays": {
        "origin": np.zeros(3),
        "h_x": np.array([1.0, 2.0]),
        "h_y": np.array([1.0, 1.0]),
        "h_z": np.array([3.0]),
    },
}
models = {
    "rho": {
        "metadata": {"units": "ohm-m"},
        "array": np.array([10.0, 20.0, 30.0, 40.0]),
    }
}
cmb.write_file("example.cmb", mesh, models)

mesh, models, metadata = cmb.read_file("example.cmb")
rho = models["rho"]["array"]

read_file loads and checksum-verifies all geometry and model arrays, including nested base-mesh geometry. Its three results match write_file's mesh, models, and metadata parameters, so passing them straight back preserves the mesh geometry, model arrays, and metadata. The NumPy arrays are read-only; use .copy() if you need to modify them.

To read individual arrays without loading the whole file:

with open("example.cmb", "rb") as f:
    header, data_start = cmb.read_header(f)
    metadata = header["metadata"]
    geometry = cmb.read_arrays(f, data_start, header["mesh"]["arrays"])
    rho = cmb.read_array(f, data_start, header["models"]["rho"]["array"])

For measured large-octree and tensor round trips and timing methodology, see the discretize interoperability notes. On the measured 2.18-million-leaf sample, the generated CMB file is 10.4 MiB versus 28.8 MiB for UBC, and conversion plus CMB writing is about 21× faster.

Development

From a local checkout, with pip 25.1 or newer:

python -m pip install --group dev -e .
python -m pytest
python -m ruff check .
python -m ruff format --check .

Committed reference files in tests/goldens/ test compatibility with the binary format alongside round-trip tests.

The format specification defines the file layout and mesh schemas. Package and format versions are independent; see versioning and the package changelog.

Metadata

Release files for cmb-format 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cmb-format 0.1.0
File Size Uploaded
cmb_format-0.1.0.tar.gz 39.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cmb-format 0.1.0
File Interpreter ABI Platform
cmb_format-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 56.3 kB

Release files / cmb_format-0.1.0.tar.gz

Download URL cmb_format-0.1.0.tar.gz
Size 39.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f538382630d0755921d75ec5fb643a336371281fbce6d67fbd3bc22c8dc790d3
BLAKE2b-256 checksum
How to use checksums
190673a3e71ddc0c4b23d57b9dc4fa3cf3007e757223f1757f20402a2686201d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Release files / cmb_format-0.1.0-py3-none-any.whl

Download URL cmb_format-0.1.0-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dff56bf55336f1b99b9346215e854e760ee5fbf3912ea94b43d6e4b77595d9bb
BLAKE2b-256 checksum
How to use checksums
7fd4d46f0fb9edae8cb4e02801d194ebeb9c5849a8866831d769cca99dd208aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page