5151 # https://ngff.openmicroscopy.org/specifications/0.5/index.html#images
5252 # The name of the array is arbitrary with the ordering defined by
5353 # by the "multiscales" metadata, but is often a sequence starting at 0.
54- ds <- .validate_multiscales_paths(x , datasets(mdattr ))
55- ds <- file.path (x , as.character( ds ) )
54+ # ds <- .validate_multiscales_paths(x, datasets(mdattr))
55+ ds <- paste0 (x , ds )
5656 as <- lapply(ds , ZarrArray )
5757 list (array = as , mdattr = mdattr )
5858}
@@ -77,7 +77,7 @@ readLabel <- function(x, ...) {
7777# ' @importFrom dplyr sql
7878# ' @export
7979readPoint <- function (x , ... ) {
80- pq <- list.files (x , " \\ .parquet$ " , full.names = TRUE )
80+ pq <- paste0 (x , file.path( " points .parquet" , " part.0.parquet " ) )
8181 md <- read_zarr_attributes(x )
8282 ax <- unlist(md $ axes )
8383 df <- ddbs_open_dataset(pq , conn = .conn()) | >
@@ -107,7 +107,8 @@ readPoint <- function(x, ...) {
107107# ' @export
108108readShape <- function (x , ... ) {
109109 md <- read_zarr_attributes(x )
110- pq <- list.files(x , " \\ .parquet$" , full.names = TRUE )
110+ # "shapes.parquet" currently hardcoded in SpatialData.io
111+ pq <- paste0(x , " shapes.parquet" )
111112 df <- ddbs_open_dataset(pq , conn = .conn(), crs = NA_character_ )
112113 SpatialDataShape(data = df , meta = SpatialDataAttrs(md ))
113114}
@@ -145,10 +146,22 @@ readSpatialData <- function(x,
145146 args <- as.list(environment())[.LAYERS ]
146147 skip <- vapply(args , isFALSE , logical (1 ))
147148
149+ x <- Rarr ::: .normalize_array_path(x )
150+ store_meta <- Rarr ::: .read_consolidated_metadata(x )$ metadata
151+ # is.null(.$data_type) is a hack that works for both v2 and v3 Zarr stores, to keep only
152+ # groups, but not arrays
153+ # In v3, we could just do .$node_type == "group", but in v2, there is no node_type.
154+ store_groups <- names(store_meta [vapply(store_meta , \(. ) is.null(. $ data_type ), logical (1 ))])
155+
148156 # helper for layer reading
149157 .readLayer <- \(l ) {
150- j <- list.dirs(file.path(x , l ), recursive = FALSE , full.names = TRUE )
151- names(j ) <- basename(j )
158+ message(" reading " , l , " ..." )
159+ j <- store_groups [startsWith(store_groups , paste0(l , " /" ))]
160+ j <- setNames(
161+ paste0(x , j , " /" , recycle0 = TRUE ),
162+ basename(j )
163+ )
164+
152165 opt <- args [[l ]]
153166 if (! isTRUE(opt )) {
154167 if (is.numeric(opt ) && opt > (. <- length(j )))
@@ -157,8 +170,8 @@ readSpatialData <- function(x,
157170 stop(" couldn't find " , l , " of name" , . )
158171 j <- j [opt ]
159172 }
160- f <- get(paste0(" read" , toupper(substr(l , 1 , 1 )), substr(l , 2 , nchar(l )- 1 )))
161- lapply(j , \( . ) do.call( f , list ( . )) )
173+ reader <- get(paste0(" read" , toupper(substr(l , 1 , 1 )), substr(l , 2 , nchar(l )- 1 )))
174+ lapply(j , reader )
162175 }
163176
164177 names(ls ) <- ls <- .LAYERS [! skip ]
0 commit comments