Skip to content
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

Creating and managing Zarr groups #12

Open
Artur-man opened this issue Nov 27, 2024 · 3 comments
Open

Creating and managing Zarr groups #12

Artur-man opened this issue Nov 27, 2024 · 3 comments

Comments

@Artur-man
Copy link

Artur-man commented Nov 27, 2024

I think it might be necessary to provide this utility at some point which will be needed to create sophisticated zarr stores like in https://github.com/HelenaLC/SpatialData, similar to h5createGroup.

@grimbough I might as well give it a try and start a PR if you are up for it.

@grimbough
Copy link
Owner

I think this means we'll need to expand Rarr's concept of a Zarr store. Currently the package is designed just to work with a single array. It has no concept of the heirachy or group, other than to represent the individual chunks. You just point it to the root location of the invidual array you want to work with.

I haven't thought about this much, but I guess you'd want something like an S4 class called 'ZarrStore' where one slot was a list of ZarrArrays. Alternatively, maybe it could be recursive, extend ZarrArray so that it has a 'child' slot that stores the next array down in the heirachy. I'm not how complex Zarr stores can be, and if either of those would cope with all possible structures.

@Artur-man
Copy link
Author

Artur-man commented Dec 4, 2024

Hey Mike,

I think I had a rather simpler idea in mind, which one can program themselves but would be nice to have it wrapped in Rarr as well.

I think the current ZarrArray object is quite nice, I would just get it a name component just like in HDF5Array. Then the name could be the path to the ZarrArray within the root store /, really simple ... one should just be able to open group (or nested groups) associated with the name just like in h5createGroup. I will give an example shortly.

@Artur-man
Copy link
Author

Artur-man commented Dec 4, 2024

Following an example similar from
https://htmlpreview.github.io/?https://github.com/HelenaLC/SpatialData/blob/main/vignettes/SpatialData.html#introduction

An ideal use case would be to create nested groups just like in h5createGroup but for zarr stores instead.

Here, one might wanna create a zarr store in SpatialData format with multiple images where one of those images is a multiscale image (the same image in different resolutions)

# create array list
mat_list <- lapply(c(64,32,16), function(s){
  array(rep(sample.int(255),s*s*3), dim = c(3,s,s))
})

# create empty zarr
zarr_store = tempfile(fileext = ".zarr")
Rarr::create_zarr_store(path = zarr_store)

# create images under SpatialData zarr store
Rarr::ZarrCreateGroup(zarr_store, group = "images")
Rarr::ZarrCreateGroup(zarr_store, group = "images/blobs_multiscale_image")
for(i in 1:length(mat_list))
  writeZarrArray(mat_list[[i]], zarr_array_path = paste0(zarr_store, "/images/blobs_multiscale_image/", i-1))
  
# or
for(i in 1:length(mat_list))
  writeZarrArray(mat_list[[i]], zarr_store_path = zarr_store, name = paste0("images/blobs_multiscale_image/", i-1))

The zarr group is just a folder with a .zgroup in a JSON format within (zarr v2), otherwise the functionality of writeZarrArray I must say is complete.

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

No branches or pull requests

2 participants