Skip to content

mathworks/MATLAB-support-for-Zarr-files

Repository files navigation

MATLAB Support for Zarr files

Zarr® is a chunked, compressed, N-dimensional array storage format optimized for performance and scalability. It is widely used in scientific computing for handling large arrays efficiently. This repository provides an interface to read and write Zarr arrays and metadata from MATLAB®.

For complete documentation, refer to documentation.md or the help section of each function.

Feedback/Requests

The direction and capabilities of this package depend on feedback from users. We encourage you to ask for what you need, and we look forward to hearing from you. See CONTRIBUTING.md for adding new features and bug fixing.

Create/view issues for MATLAB Support for Zarr files here. See Creating good issues for tips and best practices.

Community Support

For general questions and support for MATLAB, visit MATLAB Central

Status

  • Supports only Zarr v2.
  • Supports reading and writing of Zarr arrays from local storage and Amazon S3.
  • Supports reading and writing of Zarr metadata from local storage and Amazon S3.

codecov

Setup

To use this repository, clone the repo to your local folder and add it to your MATLAB using addpath. For example:

>> addpath("C:\<username>\support-Zarr-in-MATLAB\")

MathWorks Products (https://www.mathworks.com)

Requires MATLAB release R2024a or newer

Installation

Before proceeding, please ensure that you have a supported version of Python® installed on your machine. See MATLAB Compatible Python Versions for the Python versions compatible with different MATLAB releases.

3rd Party Products

The following versions are required by this package:

  • Python - v3.10 or newer
  • tensorstore - v0.1.71 or newer
  • numpy - v1.26.4 or newer

Configuring Python

Please refer to the following links to configure your system to use Python with MATLAB:

Make sure that the Python path is included in your system path environment variable. To verify that you have a supported version of Python, type (in MATLAB Command Window):

>> pyenv

ans = 

  PythonEnvironment with properties:

          Version: "3.11"
       Executable: "C:\Users\<username>\AppData\Local\Programs\Python\Python311\pythonw.exe"
          Library: "C:\Users\<username>\AppData\Local\Programs\Python\Python311\python311.dll"
             Home: "C:\Users\<username>\AppData\Local\Programs\Python\Python311"
           Status: NotLoaded
    ExecutionMode: OutOfProcess

If the value of the Version property is empty, then you do not have a supported version available.

Once Python is installed, install the Python packages tensorstore and numpy.

Getting Started

  1. Clone the github repo to your local drive.
  2. Start MATLAB.
  3. Add the parent cloned directory to your MATLAB path:
>> addpath ("C:\<username>\support-Zarr-in-MATLAB\")

Examples

Read a Zarr array

filepath = "group1\dset1";
data     = zarrread(filepath);

Create and write to a Zarr array

filepath   = "myZarrfiles\singleDset";
data_size = [10,10];               % shape of the Zarr array to be written
data       = 5*ones(10,10);        % Data to be written

zarrcreate(filepath, data_size)    % Create the Zarr array with default attributes
zarrwrite(filepath, data)          % Write data to the Zarr array

Create a Zarr array and write data to it using zlib compression with non-default chunking

filepath = "myZarrfiles\singleZlibDset";

% Size of the data
data_size = [10, 20];
% Chunk size
chunk_size = [5, 5];
% Sample data to be written
data = single(5*ones(10, 20));

% Set the compression ID and compression level
compress.id = "zlib";
compress.level = 8;

% Create the Zarr array

zarrcreate(filepath, data_size, ChunkSize=chunk_size, DataType="single", ...
    Compression=compress)

% Write to the Zarr array
zarrwrite(filepath, data)

Read the metadata from a Zarr array

filepath = "group1\dset1";
info = zarrinfo(filepath);

Help

To view documentation of a function, type help <function_name>. For example,

>> help zarrcreate

or refer to the documentation.md and examples.md files.

License

The license is available in the License.txt file in this GitHub repository.

Copyright 2025-2026 The MathWorks, Inc.

About

This repository provides an interface in MATLAB to read and write Zarr files. Zarr is a file format for scientific data (like HDF5 and netCDF) which is optimized for cloud storage and parallel computing environments.

Resources

License

Contributing

Security policy

Stars

18 stars

Watchers

7 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors