Skip to content

Support partial reading of Zarr datasets #106

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

krisfed
Copy link
Member

@krisfed krisfed commented Jun 19, 2025

This is a first draft of allowing partial reads from Zarr datasets.

The proposed interface is as follows (somewhat modeled on h5read and ncread):

>> fullData = zarrread("grp_v2/smallArr") % reading full dataset works the same

fullData =

     1     4     7    10
     2     5     8    11
     3     6     9    12

>> d = zarrread("grp_v2/smallArr", Start=[2,3]) % read starting from the 2nd row and 3rd column

d =

     8    11
     9    12

>> d = zarrread("grp_v2/smallArr", Count=[2,4]) % read 2 elements in 1st dimension and 4 in 2nd dimension

d =

     1     4     7    10
     2     5     8    11

>> d = zarrread("grp_v2/smallArr", Stride=[1,2]) % read every element in 1st dimension and every second one in 2nd dimension

d =

     1     7
     2     8
     3     9

>> d = zarrread("grp_v2/smallArr", Start=[1,2], Stride=[1,2], Count=[2,2]) % use any combination of Start/Stride/Count

d =

     4    10
     5    11

The number of elements in Start/Stride/Count must be the same as the number of dimensions:

>> d = zarrread("grp_v2/smallArr", Start=[1,2,3])
Error using Zarr.processPartialReadParams (line 86)
Number of elements in Start must be the same as the number of Zarr array dimensions.

Error in Zarr/read (line 260)
            start = Zarr.processPartialReadParams(start, info.shape,...
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in zarrread (line 36)
data = zarrObj.read(options.Start, options.Count, options.Stride);
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Only exception is if the dataset is a vector, in which case scalar Start/Stride/Count are allowed:

>> d = zarrread("grp_v2/vectorData")

d =

     1     2     3     4     5     6     7     8     9    10

>> d = zarrread("grp_v2/vectorData", Start=3, Stride=2)

d =

     3     5     7     9

Copy link

codecov bot commented Jun 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.07%. Comparing base (1ad7173) to head (7889203).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
+ Coverage   96.66%   97.07%   +0.40%     
==========================================
  Files           8        8              
  Lines         210      239      +29     
==========================================
+ Hits          203      232      +29     
  Misses          7        7              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@krisfed krisfed marked this pull request as ready for review June 19, 2025 16:54
@krisfed krisfed requested review from jm9176 and jhughes-mw June 19, 2025 16:54
@krisfed krisfed changed the title First draft of partial read Support partial reading of Zarr datasets Jun 19, 2025
@jm9176
Copy link
Member

jm9176 commented Jun 19, 2025

@krisfed Please create a test task geck once you are done submitting all of your changes.

Zarr.m Outdated
Comment on lines 60 to 62
arguments (Output)
newParams (1,:) int64
end
Copy link
Member

Choose a reason for hiding this comment

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

Surprised considering the name of the function, you didn't also use arguments block to validate inputs

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I am doing the basic arguments block validation for Start/Stride/Count in zarrread (better error message and faster erroring out), so not much left to validate here. Not great to validate different things in different places though..

Copy link
Member

@jhughes-mw jhughes-mw left a comment

Choose a reason for hiding this comment

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

Looks Good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants