|
1 |
| -import zarr |
| 1 | +import zarr |
2 | 2 | import numpy as np
|
3 |
| -from numcodecs import Zlib, Blosc, LZ4, Zstd |
| 3 | +import shutil |
| 4 | +from numcodecs import Zlib, Blosc, LZ4, Zstd, VLenUTF8 |
4 | 5 |
|
5 |
| -store = zarr.DirectoryStore('data.zarr') |
| 6 | +shutil.rmtree("data.zarr", ignore_errors=True) |
| 7 | + |
| 8 | +store = zarr.DirectoryStore("data.zarr") |
6 | 9 | root = zarr.open_group(store)
|
7 |
| -root.attrs['answer'] = 42 |
| 10 | +root.attrs["answer"] = 42 |
8 | 11 |
|
9 | 12 | # 1d.contiguous.zlib.i2
|
10 |
| -root.create_dataset("1d.contiguous.zlib.i2", data=[1, 2, 3, 4], dtype='i2', chunks=(4,), compressor=Zlib()) |
| 13 | +root.create_dataset( |
| 14 | + "1d.contiguous.zlib.i2", |
| 15 | + data=[1, 2, 3, 4], |
| 16 | + dtype="i2", |
| 17 | + chunks=(4,), |
| 18 | + compressor=Zlib(), |
| 19 | +) |
11 | 20 |
|
12 | 21 | # 1d.contiguous.blosc.i2
|
13 |
| -root.create_dataset("1d.contiguous.blosc.i2", data=[1, 2, 3, 4], dtype='i2', chunks=(4,), compressor=Blosc()) |
| 22 | +root.create_dataset( |
| 23 | + "1d.contiguous.blosc.i2", |
| 24 | + data=[1, 2, 3, 4], |
| 25 | + dtype="i2", |
| 26 | + chunks=(4,), |
| 27 | + compressor=Blosc(), |
| 28 | +) |
14 | 29 |
|
15 | 30 | # 1d.contiguous.lz4.i2
|
16 |
| -root.create_dataset("1d.contiguous.lz4.i2", data=[1, 2, 3, 4], dtype='i2', chunks=(4,), compressor=LZ4()) |
| 31 | +root.create_dataset( |
| 32 | + "1d.contiguous.lz4.i2", data=[1, 2, 3, 4], dtype="i2", chunks=(4,), compressor=LZ4() |
| 33 | +) |
17 | 34 |
|
18 | 35 | # 1d.contiguous.zstd.i2
|
19 |
| -root.create_dataset("1d.contiguous.zstd.i2", data=[1, 2, 3, 4], dtype='i2', chunks=(4,), compressor=Zstd()) |
| 36 | +root.create_dataset( |
| 37 | + "1d.contiguous.zstd.i2", |
| 38 | + data=[1, 2, 3, 4], |
| 39 | + dtype="i2", |
| 40 | + chunks=(4,), |
| 41 | + compressor=Zstd(), |
| 42 | +) |
20 | 43 |
|
21 | 44 | # 1d.contiguous.raw.i2
|
22 |
| -root.create_dataset("1d.contiguous.raw.i2", data=[1, 2, 3, 4], dtype='i2', chunks=(4,), compressor=None) |
| 45 | +root.create_dataset( |
| 46 | + "1d.contiguous.raw.i2", data=[1, 2, 3, 4], dtype="i2", chunks=(4,), compressor=None |
| 47 | +) |
23 | 48 |
|
24 | 49 |
|
25 | 50 | # 1d.contiguous.i4
|
26 |
| -root.create_dataset('1d.contiguous.i4', data=[1, 2, 3, 4], dtype='i4', chunks=(4,)) |
| 51 | +root.create_dataset("1d.contiguous.i4", data=[1, 2, 3, 4], dtype="i4", chunks=(4,)) |
27 | 52 |
|
28 | 53 | # 1d.contiguous.u1
|
29 |
| -root.create_dataset('1d.contiguous.u1', data=[255, 0, 255, 0], dtype='u1', chunks=(4,)) |
| 54 | +root.create_dataset("1d.contiguous.u1", data=[255, 0, 255, 0], dtype="u1", chunks=(4,)) |
30 | 55 |
|
31 | 56 | # 1d.contiguous.<f4
|
32 |
| -root.create_dataset('1d.contiguous.f4.le', data=[-1000.5, 0, 1000.5, 0], dtype='<f4', chunks=(4,)) |
| 57 | +root.create_dataset( |
| 58 | + "1d.contiguous.f4.le", data=[-1000.5, 0, 1000.5, 0], dtype="<f4", chunks=(4,) |
| 59 | +) |
33 | 60 |
|
34 | 61 | # 1d.contiguous.>f4
|
35 |
| -root.create_dataset('1d.contiguous.f4.be', data=[-1000.5, 0, 1000.5, 0], dtype='>f4', chunks=(4,)) |
| 62 | +root.create_dataset( |
| 63 | + "1d.contiguous.f4.be", data=[-1000.5, 0, 1000.5, 0], dtype=">f4", chunks=(4,) |
| 64 | +) |
36 | 65 |
|
37 | 66 | # 1d.contiguous.f8
|
38 |
| -root.create_dataset('1d.contiguous.f8', data=[1.5, 2.5, 3.5, 4.5], dtype='f8', chunks=(4,)) |
| 67 | +root.create_dataset( |
| 68 | + "1d.contiguous.f8", data=[1.5, 2.5, 3.5, 4.5], dtype="f8", chunks=(4,) |
| 69 | +) |
39 | 70 |
|
40 | 71 | # 1d.contiguous.<U13
|
41 |
| -root.create_dataset('1d.contiguous.U13.le', data=['a', 'b', 'cc', 'd'], dtype='<U13', chunks=(4,)) |
| 72 | +root.create_dataset( |
| 73 | + "1d.contiguous.U13.le", data=["a", "b", "cc", "d"], dtype="<U13", chunks=(4,) |
| 74 | +) |
42 | 75 |
|
43 | 76 | # 1d.contiguous.>U13
|
44 |
| -root.create_dataset('1d.contiguous.U13.be', data=['a', 'b', 'cc', 'd'], dtype='>U13', chunks=(4,)) |
| 77 | +root.create_dataset( |
| 78 | + "1d.contiguous.U13.be", data=["a", "b", "cc", "d"], dtype=">U13", chunks=(4,) |
| 79 | +) |
45 | 80 |
|
46 | 81 | # 1d.contiguous.U7
|
47 |
| -root.create_dataset('1d.contiguous.U7', data=['a', 'b', 'cc', 'd'], dtype='U7', chunks=(4,)) |
| 82 | +root.create_dataset( |
| 83 | + "1d.contiguous.U7", data=["a", "b", "cc", "d"], dtype="U7", chunks=(4,) |
| 84 | +) |
48 | 85 |
|
49 | 86 | # 1d.contiguous.S7
|
50 |
| -root.create_dataset('1d.contiguous.S7', data=['a', 'b', 'cc', 'd'], dtype='S7', chunks=(4,)) |
| 87 | +root.create_dataset( |
| 88 | + "1d.contiguous.S7", data=["a", "b", "cc", "d"], dtype="S7", chunks=(4,) |
| 89 | +) |
51 | 90 |
|
52 | 91 | # 1d.contiguous.b1
|
53 |
| -root.create_dataset('1d.contiguous.b1', data=[True, False, True, False], dtype='b1', chunks=(4,)) |
54 |
| - |
| 92 | +root.create_dataset( |
| 93 | + "1d.contiguous.b1", data=[True, False, True, False], dtype="b1", chunks=(4,) |
| 94 | +) |
55 | 95 |
|
56 | 96 |
|
57 | 97 | # 1d.chunked.i2
|
58 |
| -root.create_dataset('1d.chunked.i2', data=[1, 2, 3, 4], dtype='i2', chunks=(2,)) |
| 98 | +root.create_dataset("1d.chunked.i2", data=[1, 2, 3, 4], dtype="i2", chunks=(2,)) |
59 | 99 |
|
60 | 100 | # 1d.chunked.ragged.i2
|
61 |
| -root.create_dataset('1d.chunked.ragged.i2', data=[1, 2, 3, 4, 5], dtype='i2', chunks=(2,)) |
| 101 | +root.create_dataset( |
| 102 | + "1d.chunked.ragged.i2", data=[1, 2, 3, 4, 5], dtype="i2", chunks=(2,) |
| 103 | +) |
62 | 104 |
|
63 | 105 |
|
64 | 106 | # 2d.contiguous.i2
|
65 |
| -root.create_dataset('2d.contiguous.i2', data=[[1, 2],[3, 4]], dtype='i2', chunks=(2,2)) |
| 107 | +root.create_dataset( |
| 108 | + "2d.contiguous.i2", data=[[1, 2], [3, 4]], dtype="i2", chunks=(2, 2) |
| 109 | +) |
66 | 110 |
|
67 | 111 | # 2d.chunked.i2
|
68 |
| -root.create_dataset('2d.chunked.i2', data=[[1, 2],[3, 4]], dtype='i2', chunks=(1,1)) |
| 112 | +root.create_dataset("2d.chunked.i2", data=[[1, 2], [3, 4]], dtype="i2", chunks=(1, 1)) |
69 | 113 |
|
70 | 114 | # 2d.chunked.U7
|
71 |
| -root.create_dataset('2d.chunked.U7', data=[['a', 'b'],['cc', 'd']], dtype='U7', chunks=(1,1)) |
| 115 | +root.create_dataset( |
| 116 | + "2d.chunked.U7", data=[["a", "b"], ["cc", "d"]], dtype="U7", chunks=(1, 1) |
| 117 | +) |
72 | 118 |
|
73 | 119 | # 2d.chunked.ragged.i2
|
74 |
| -root.create_dataset('2d.chunked.ragged.i2', data=[[1, 2, 3],[4, 5, 6], [7, 8, 9]], dtype='i2', chunks=(2,2)) |
| 120 | +root.create_dataset( |
| 121 | + "2d.chunked.ragged.i2", |
| 122 | + data=[[1, 2, 3], [4, 5, 6], [7, 8, 9]], |
| 123 | + dtype="i2", |
| 124 | + chunks=(2, 2), |
| 125 | +) |
75 | 126 |
|
76 | 127 | # 3d.contiguous.i2
|
77 |
| -root.create_dataset('3d.contiguous.i2', data=np.arange(27).reshape(3,3,3), dtype='i2', chunks=(3,3,3)) |
| 128 | +root.create_dataset( |
| 129 | + "3d.contiguous.i2", |
| 130 | + data=np.arange(27).reshape(3, 3, 3), |
| 131 | + dtype="i2", |
| 132 | + chunks=(3, 3, 3), |
| 133 | +) |
78 | 134 |
|
79 | 135 | # 3d.chunked.i2
|
80 |
| -root.create_dataset('3d.chunked.i2', data=np.arange(27).reshape(3,3,3), dtype='i2', chunks=(1,1,1)) |
| 136 | +root.create_dataset( |
| 137 | + "3d.chunked.i2", data=np.arange(27).reshape(3, 3, 3), dtype="i2", chunks=(1, 1, 1) |
| 138 | +) |
81 | 139 |
|
82 | 140 | # 3d.chunked.mixed.i2.C
|
83 |
| -root.create_dataset('3d.chunked.mixed.i2.C', data=np.arange(27).reshape(3,3,3), dtype='i2', chunks=(3,3,1)) |
| 141 | +root.create_dataset( |
| 142 | + "3d.chunked.mixed.i2.C", |
| 143 | + data=np.arange(27).reshape(3, 3, 3), |
| 144 | + dtype="i2", |
| 145 | + chunks=(3, 3, 1), |
| 146 | +) |
84 | 147 |
|
85 | 148 | # 3d.chunked.mixed.i2.F
|
86 |
| -arr = root.create_dataset('3d.chunked.mixed.i2.F', data=np.arange(27).reshape(3,3,3), order="F", dtype='i2', chunks=(3,3,1)) |
| 149 | +arr = root.create_dataset( |
| 150 | + "3d.chunked.mixed.i2.F", |
| 151 | + data=np.arange(27).reshape(3, 3, 3), |
| 152 | + order="F", |
| 153 | + dtype="i2", |
| 154 | + chunks=(3, 3, 1), |
| 155 | +) |
| 156 | + |
| 157 | + |
| 158 | +# 3d.chunked.o |
| 159 | +data = np.array( |
| 160 | + [ |
| 161 | + [["a", "aa"], ["aaa", "aaaa"]], |
| 162 | + [["b", "bb"], ["bbb", "bbbb"]], |
| 163 | + ], |
| 164 | + dtype=object, |
| 165 | +) |
| 166 | +root.create_dataset( |
| 167 | + "3d.chunked.O", |
| 168 | + data=data, |
| 169 | + object_codec=VLenUTF8(), |
| 170 | + dtype="O", |
| 171 | + chunks=(1, 1, 2), |
| 172 | +) |
87 | 173 |
|
88 | 174 | zarr.consolidate_metadata(store)
|
0 commit comments