-
Notifications
You must be signed in to change notification settings - Fork 2
/
basics.Rmd
125 lines (81 loc) 路 2.06 KB
/
basics.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
title: "Basics"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Basics}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
out.width = "100%"
)
```
## Load the package
```{r}
library(pizzarr)
```
## Create an empty ZarrArray
```{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}
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)
# Python-like zero-based slicing
s2 <- z$get_item(list(zb_slice(0, 2), zb_slice(0, 5)))
print(s2$data)
```
## Create nested ZarrGroups and ZarrArrays
```{r}
g1 <- zarr_create_group()
g2 <- g1$create_group("foo")
g3 <- g2$create_group("bar")
data <- array(data=1:10, dim=c(2, 5))
a <- g3$create_dataset("baz", data=data, shape=dim(data))
print(a$get_name())
print(a$get_shape())
```
## 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}
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())
```
## Open a ZarrArray from a DirectoryStore
```{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())
```
## 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()
```