This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
MATLAB interface for reading and writing Zarr v2 arrays and metadata, from both local storage and Amazon S3. The MATLAB layer delegates the actual Zarr I/O to Google's tensorstore Python library, which it calls through MATLAB's py. Python bridge.
The codebase is a three-language stack. Data and type information flow across all three layers, so a change to the data path usually touches each:
-
User-facing MATLAB functions (
zarrread.m,zarrwrite.m,zarrcreate.m,zarrinfo.m,zarrwriteatt.m) — thin wrappers that doarguments-block input validation and construct aZarrobject. These are the documented public API. -
Zarr.m— the central gateway class (classdef Zarr < handle). It owns the connection between MATLAB and Python: bootstrapping the Python module path (pySetup/ZarrPy), building the tensorstore KVStore schema (localfiledriver vs. S3s3driver), resolving/creating paths and Zarr groups, validating partial-read parameters, and converting between MATLAB and numpy arrays. Most non-trivial logic lives here as static helper methods. -
PythonModule/ZarrPy.py— a small wrapper over tensorstore. ExposescreateKVStore,createZarr,writeZarr,readZarr. This is the only code that talks to tensorstore directly.Zarr.mimports it viapy.importlib.import_module('ZarrPy')after insertingPythonModule/ontopy.sys.path.
-
Datatype mapping (
ZarrDatatype.m): a single class holds three parallel arrays mapping MATLAB types ↔ tensorstore types ↔ Zarr dtype strings (e.g."double"↔"float64"↔"<f8"). Construct via the staticfromMATLABType/fromTensorstoreType/fromZarrTypemethods, never the private constructor. Any new supported datatype must be added to all three arrays in lockstep. -
Index convention conversion: MATLAB is 1-based and uses count; tensorstore is 0-based and uses end index (exclusive). The translation happens in
Zarr.read(start = start - 1,endInds = start + stride.*count). Partial-read validation (Start/Stride/Count bounds, scalar-into-vector indexing) is inZarr.processPartialReadParams. -
Local vs. remote (S3):
obj.isRemoteis detected from an IRI prefix on the path. S3 URLs/URIs in six different formats are parsed into bucket + object path byZarr.extractS3BucketNameAndPath. Some validity checks (e.g.isZarrArray) are skipped forhttp-style remote paths because they would fail even on valid arrays. -
Zarr metadata files:
.zarraymarks an array,.zgroupmarks a group,.zattrsholds user-defined attributes (all Zarr v2, read/written as JSON).zarr.jsonis the Zarr v3 metadata file — it is detected byzarrinfobut writing v3 is not supported.zarrinfo.mreads these JSON files directly in MATLAB (not via Python); creating group hierarchies writes.zgroupfiles directly too.
There is no build step — it's interpreted MATLAB plus a Python module on the path.
Run the full test suite (from the test/ directory, since tests resolve data paths relative to pwd):
cd test
results = runtests('IncludeSubfolders', true)Run a single test class or method:
cd test
runtests('tZarrRead') % one class
runtests('tZarrRead/verifyPartialArrayData') % one methodCI (.github/workflows/test_setup.yml) runs matlab-actions/run-tests with select-by-folder: 'test' across Ubuntu/Windows/macOS and MATLAB R2024a + latest.
- MATLAB R2024a or newer. Add the repo root to the MATLAB path (
addpath). - Python 3.10+ configured for MATLAB (
pyenv), withnumpyandtensorstoreinstalled (seePythonModule/requirements.txt; CI pinstensorstore==0.1.71, the minimum supported version).
When iterating on ZarrPy.py, MATLAB caches the imported module. Reload with Zarr.pyReloadInProcess() (after clear classes) for in-process Python, or terminate(pyenv) for out-of-process.
xUnit-style classes (matlab.unittest.TestCase) named t<Feature>.m in test/. They inherit shared fixtures from SharedZarrTestSetup.m, which adds the parent source folder to the path and copies test/dataFiles/ into a WorkingFolderFixture so write tests don't pollute the repo. Read-test fixtures live in test/dataFiles/grp_v2 (and grp_v3); expected results are stored in expZarrArrData.mat / expZarrArrInfo.mat.
- All error messages use
error("MATLAB:<area>:<id>", ...)identifiers — match the existing namespacing when adding new ones. - Function help text is the block comment directly under the signature; keep it current since the README points users to
help <function>. - Spelling is checked in CI by codespell (
.codespellrc); add false positives toignore-words-list.