medh5
The MEDH5 format engine. A .medh5 file is one subject at one or more
timepoints, with every image, annotation, transform and curation record about
them, in one self-describing HDF5 container. This crate is the canonical
implementation of formats 1.0 and 1.1 (the specification, and 1.1 for the
optional clinical profile): the data model, HDF5 I/O, validation, chunked
access, compression, geometry and transforms, annotations, provenance,
integrity — and, for 1.1, clinical events on a subject clock, strict
prospective selection, and the task and cache contract training builds on.
It has two siblings, and all three read and write the same bytes:
- the Python package (
pip install medh5), a thin layer over this crate that adds the NumPy, PyTorch, MONAI and converter integrations; - the
medh5command line (medh5-cli), a native binary over this crate.
HDF5 and C-Blosc2 are built from source and linked statically (see
medh5-sys), so a dependent crate needs no HDF5 installation. For an MSVC
target, set CFLAGS_x86_64_pc_windows_msvc=-DNDEBUG (or the variable for your
target): without it HDF5 keeps its assertions, and medh5-sys stops the build.
Write and read a sample
use NdArray;
use ;
Where things are
| Module | Specification |
|---|---|
sample |
§2, §4, §14.4 — reading (Sample) and writing (SampleWriter, create, amend) |
document |
§2.4 — the sample document, everything in /meta |
ids |
§2.2, §2.3 — identifier rules |
geometry |
§3 — grids, affines, frames, multiscale |
labels |
§5 — label sets, hierarchies and ontology codes |
annotations |
§6–§9 — the voxel and geometric encodings, headers, coverage |
transforms |
§10 — affine, displacement, B-spline and composite transforms |
curation |
§11, §12 — identity, provenance, quality, timelines, splits, scrubbing |
integrity, digest |
§13 — per-object digests and content_id; the hash algorithms and digest strings |
storage |
§14 — codec profiles, chunking, the sampling index |
validate, codes |
§15 — the validator and its diagnostic code table |
collection |
§2.2 — packing samples into a .medh5c shard |
convert |
Appendix B — the 0.x migration, and the ConversionReport every importer fills |
array |
NdArray, the array every reader returns and every writer takes |
dataset, sampling |
cohort manifests, splits, statistics; patch sampling |
bench |
reproducing the performance targets |
[rng] |
the generator behind sampling, the same stream in every frontend |
error |
the one Error type, and the code each error carries |
conformance |
the conformance corpus third-party implementations run |
version |
1.1 §2 — which versions are read fully, read as a projection, or refused |
clinical |
1.1 §3–§10 — the clinical profile: records, columns, checks, selection, augmentation |
companion |
task-cache-1 — task manifests, source pins, preflight row views, feature caches |
h5, json, numeric, pyval |
plumbing, outside semver (below) |
h5, json, numeric and pyval are the engine's plumbing rather than the
format, and from 2.1 they are outside semver: a minor release may change them.
They are HDF5 access below the high-level API, the format's exact JSON
serialisations, NumPy-compatible reductions and the 1.x value coercions. The
documented way to the canonical JSON of §5.1 is [labels::canonical_json]; an attribute value is
[AttrValue], re-exported at the crate root.
The crate's public signatures take and return types from three other crates,
so they are public dependencies: hdf5-metno 0.15 (re-exported as hdf5),
ndarray 0.17 (re-exported as ndarray) and IndexMap 2. A bump of any of
them is a major medh5 release.
Errors are one Error type whose diagnostic code, when it has one, is the
code the validator reports for the same defect (§15.2, 1.1 §11.2).