Skip to content

Commit

Permalink
Basic documentation updates for introspection of a store (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
dblodgett-usgs committed May 8, 2024
1 parent a74dd63 commit c74a9c3
Showing 1 changed file with 57 additions and 22 deletions.
79 changes: 57 additions & 22 deletions vignettes/basics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -7,49 +7,48 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
out.width = "100%"
)
```

## Load the package

```r
```{r}
library(pizzarr)
```

## Create an empty ZarrArray

```r
```{r}
(a <- array(data=1:20, dim=c(2, 10)))
z <- zarr_create_empty(shape=dim(a), dtype="<f4")
```

## Create a ZarrArray based on a base R array

```r
a <- array(data=1:20, dim=c(2, 10))
# [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
# [1,] 1 3 5 7 9 11 13 15 17 19
# [2,] 2 4 6 8 10 12 14 16 18 20
```{r}
z <- zarr_create_array(data = a, shape=dim(a), dtype="<f4", fill_value=NA)
# R-like one-based slicing
s1 <- z$get_item(list(slice(1, 2), slice(1, 5)))
print(s1$data)
# [,1] [,2] [,3] [,4] [,5]
# [1,] 1 3 5 7 9
# [2,] 2 4 6 8 10

# Python-like zero-based slicing
s2 <- z$get_item(list(zb_slice(0, 2), zb_slice(0, 5)))
print(s2$data)
# Imagine the printed indices as:
# [,0] [,1] [,2] [,3] [,4]
# [0,] 1 3 5 7 9
# [1,] 2 4 6 8 10
```

## Create nested ZarrGroups and ZarrArrays

```r
```{r}
g1 <- zarr_create_group()
g2 <- g1$create_group("foo")
g3 <- g2$create_group("bar")
Expand All @@ -58,33 +57,69 @@ data <- array(data=1:10, dim=c(2, 5))
a <- g3$create_dataset("baz", data=data, shape=dim(data))
print(a$get_name())
# [1] "/foo/bar/baz"
print(a$get_shape())
# [1] 2 5
```

## List arrays in a zarr root group

```{r}
root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
z <- zarr_open(root)
class(z)
store <- z$get_store()
class(store)
print(store$listdir())
```

## Open a ZarrArray from a DirectoryStore (convenience)

```r
```{r}
root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
g <- zarr_open_group(root)
a <- g$get_item("1d.contiguous.lz4.i2")
print(a$get_shape())
# [1] 4
```

## Open a ZarrArray from a DirectoryStore

```r
```{r}
root <- system.file("extdata", "fixtures", "v2", "data.zarr", package="pizzarr")
store <- DirectoryStore$new(root)
g <- ZarrGroup$new(store)
a <- g$get_item("1d.contiguous.lz4.i2")
print(a$get_shape())
# [1] 4
```

## Get attributes from a root group and ZarrArray

```{r}
root <- system.file("extdata", "dog.ome.zarr", package="pizzarr")
z <- zarr_open(root)
class(z)
attrs <- z$get_attrs()$to_list()
names(attrs)
lengths(attrs$omero)
z$get_store()$listdir()
a <- z$get_item("4")
class(a)
a$get_attrs()$to_list()
```

0 comments on commit c74a9c3

Please sign in to comment.