Skip to content

Move creation of KV store dictionary to python layer #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/test_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ on:
branches:
- main
- branch-bug
- update-test-branch
- test-branch7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is branch 7? Is that a placeholder name, or a test for some specific number branch.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krisfed if you are not using any of these branches (branch-bug and test-branch7), please remove them. I think Abhi was using one of them but I don't see any pending changes.

- test-branch8
- test-branch-pyDict

jobs:
test:
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-14]
matlab-version: ['R2023b','R2024a']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If 23b is working fine after your fix, please make sure to update this section: https://github.com/mathworks/MATLAB-support-for-Zarr-files?tab=readme-ov-file#mathworks-products-httpswwwmathworkscom

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Will check once we are able to run the tests on multiple releases, and update then (if no issues surface in the tests)


steps:
- name: Checkout code
uses: actions/checkout@v2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update this to "v4" instead of "v2"?
https://github.com/actions/checkout?tab=readme-ov-file#checkout-v4


- name: Set up MATLAB R2024a
- name: Set up MATLAB
uses: matlab-actions/setup-matlab@v2
with:
release: R2024a
release: ${{matrix.matlab-version}}

- name: Set up Python
uses: actions/setup-python@v5
Expand Down
28 changes: 27 additions & 1 deletion PythonModule/ZarrPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@
import numpy as np
import tensorstore as ts

def createKVStore(isRemote, objPath, bucketName="") -> dict:
"""
Creates a KV store (a python dictionary) for reading or writing
a Zarr file

Parameters:
- isRemote (bool): whether the resource to be accessed with this
KV store is remote (s3) or local
- objPath (str): path to local Zarr file or to s3 object
- bucketName (str): If file is remote, this should be the S3 bucket
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consistency for using "S3" or "s3"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point - updating to "S3" for consistency

name

Returns:
- KVStore (dict): Key-Value store as required by tensorstore to work
with Zarr
"""
KVStore = dict(path=objPath);

if isRemote:
KVStore['driver'] = 's3'
KVStore['bucket'] = bucketName
else:
KVStore['driver'] = 'file'

return KVStore

def createZarr(kvstore_schema, data_shape, chunk_shape, tstoreDataType, zarrDataType, compressor, fillvalue):
"""
Creates a new Zarr array and writes data to it.
Expand Down Expand Up @@ -72,4 +98,4 @@ def readZarr (kvstore_schema):

# Read a subset of the data
data = zarr_file[...].read().result()
return data
return data
6 changes: 2 additions & 4 deletions Zarr.m
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,12 @@ function makeZarrGroups(existingParentPath, newGroupsPath)
% Extract the S3 bucket name and path
[bucketName, objectPath] = obj.extractS3BucketNameAndPath(obj.Path);
% Create a Python dictionary for the KV store driver
RemoteStoreSchema = dictionary(["driver", "bucket", "path"], ["s3", bucketName, objectPath]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less is more. Nice.

obj.KVStoreSchema = py.dict(RemoteStoreSchema);
obj.KVStoreSchema = py.ZarrPy.createKVStore(obj.isRemote, objectPath, bucketName);

else % Local file
% use full path
obj.Path = Zarr.getFullPath(path);
FileStoreSchema = dictionary(["driver", "path"], ["file", obj.Path]);
obj.KVStoreSchema = py.dict(FileStoreSchema);
obj.KVStoreSchema = py.ZarrPy.createKVStore(obj.isRemote, obj.Path);
end
end

Expand Down
Loading