Skip to content

Commit 9a4e97c

Browse files
committed
more organized
1 parent 95868b8 commit 9a4e97c

File tree

1 file changed

+138
-35
lines changed

1 file changed

+138
-35
lines changed

intermediate/intro-to-zarr.ipynb

Lines changed: 138 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,14 @@
217217
"id": "c6a059cc",
218218
"metadata": {},
219219
"source": [
220-
"##### Attributes\n",
220+
"#### Attributes\n",
221221
"\n",
222222
"We can attach arbitrary metadata to our Array via attributes:"
223223
]
224224
},
225225
{
226226
"cell_type": "code",
227-
"execution_count": null,
227+
"execution_count": 35,
228228
"id": "859c9cfe",
229229
"metadata": {},
230230
"outputs": [
@@ -256,7 +256,7 @@
256256
},
257257
{
258258
"cell_type": "code",
259-
"execution_count": null,
259+
"execution_count": 28,
260260
"id": "1bbc935c",
261261
"metadata": {},
262262
"outputs": [
@@ -266,7 +266,7 @@
266266
"LocalStore('file://test.zarr')"
267267
]
268268
},
269-
"execution_count": 7,
269+
"execution_count": 28,
270270
"metadata": {},
271271
"output_type": "execute_result"
272272
}
@@ -277,7 +277,7 @@
277277
},
278278
{
279279
"cell_type": "code",
280-
"execution_count": null,
280+
"execution_count": 30,
281281
"id": "51953f01",
282282
"metadata": {},
283283
"outputs": [
@@ -294,25 +294,111 @@
294294
"│   │   ├── \u001b[00m3\u001b[0m\n",
295295
"│   │   └── \u001b[00m4\u001b[0m\n",
296296
"│   ├── \u001b[01;34m1\u001b[0m\n",
297-
"│   │   ├── \u001b[00m0\u001b[0m\n"
297+
"│   │   ├── \u001b[00m0\u001b[0m\n",
298+
"│   │   ├── \u001b[00m1\u001b[0m\n",
299+
"│   │   ├── \u001b[00m2\u001b[0m\n",
300+
"│   │   ├── \u001b[00m3\u001b[0m\n",
301+
"│   │   └── \u001b[00m4\u001b[0m\n",
302+
"│   ├── \u001b[01;34m2\u001b[0m\n",
303+
"│   │   ├── \u001b[00m0\u001b[0m\n",
304+
"│   │   ├── \u001b[00m1\u001b[0m\n",
305+
"│   │   ├── \u001b[00m2\u001b[0m\n",
306+
"│   │   ├── \u001b[00m3\u001b[0m\n",
307+
"│   │   └── \u001b[00m4\u001b[0m\n",
308+
"│   └── \u001b[01;34m3\u001b[0m\n",
309+
"│   ├── \u001b[00m0\u001b[0m\n",
310+
"│   ├── \u001b[00m1\u001b[0m\n",
311+
"│   ├── \u001b[00m2\u001b[0m\n",
312+
"│   ├── \u001b[00m3\u001b[0m\n",
313+
"│   └── \u001b[00m4\u001b[0m\n",
314+
"└── \u001b[00mzarr.json\u001b[0m\n",
315+
"\n",
316+
"6 directories, 21 files\n"
298317
]
299318
}
300319
],
301320
"source": [
302-
"!tree -a test.zarr | head"
321+
"!tree -a test.zarr"
322+
]
323+
},
324+
{
325+
"cell_type": "code",
326+
"execution_count": 34,
327+
"id": "fbc51436",
328+
"metadata": {},
329+
"outputs": [
330+
{
331+
"name": "stdout",
332+
"output_type": "stream",
333+
"text": [
334+
"{\n",
335+
" \"shape\": [\n",
336+
" 40,\n",
337+
" 50\n",
338+
" ],\n",
339+
" \"data_type\": \"float64\",\n",
340+
" \"chunk_grid\": {\n",
341+
" \"name\": \"regular\",\n",
342+
" \"configuration\": {\n",
343+
" \"chunk_shape\": [\n",
344+
" 10,\n",
345+
" 10\n",
346+
" ]\n",
347+
" }\n",
348+
" },\n",
349+
" \"chunk_key_encoding\": {\n",
350+
" \"name\": \"default\",\n",
351+
" \"configuration\": {\n",
352+
" \"separator\": \"/\"\n",
353+
" }\n",
354+
" },\n",
355+
" \"fill_value\": 0.0,\n",
356+
" \"codecs\": [\n",
357+
" {\n",
358+
" \"name\": \"bytes\",\n",
359+
" \"configuration\": {\n",
360+
" \"endian\": \"little\"\n",
361+
" }\n",
362+
" },\n",
363+
" {\n",
364+
" \"name\": \"zstd\",\n",
365+
" \"configuration\": {\n",
366+
" \"level\": 0,\n",
367+
" \"checksum\": false\n",
368+
" }\n",
369+
" }\n",
370+
" ],\n",
371+
" \"attributes\": {},\n",
372+
" \"zarr_format\": 3,\n",
373+
" \"node_type\": \"array\",\n",
374+
" \"storage_transformers\": []\n",
375+
"}"
376+
]
377+
}
378+
],
379+
"source": [
380+
"!cat test.zarr/zarr.json"
381+
]
382+
},
383+
{
384+
"cell_type": "markdown",
385+
"id": "ead8421e",
386+
"metadata": {},
387+
"source": [
388+
"### Hierarchical Groups"
303389
]
304390
},
305391
{
306392
"cell_type": "markdown",
307393
"id": "35f5384e",
308394
"metadata": {},
309395
"source": [
310-
"To create groups in your store, use the `create_group` method after creating a root group. Here, we’ll create two groups, `temp` and `precip`."
396+
"Zarr allows you to create hierarchical groups, similar to directories. To create groups in your store, use the `create_group` method after creating a root group. Here, we’ll create two groups, `temp` and `precip`."
311397
]
312398
},
313399
{
314400
"cell_type": "code",
315-
"execution_count": null,
401+
"execution_count": 36,
316402
"id": "e3c377a0",
317403
"metadata": {},
318404
"outputs": [],
@@ -335,7 +421,7 @@
335421
},
336422
{
337423
"cell_type": "code",
338-
"execution_count": null,
424+
"execution_count": 37,
339425
"id": "eecad1a6",
340426
"metadata": {},
341427
"outputs": [
@@ -349,7 +435,7 @@
349435
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32)"
350436
]
351437
},
352-
"execution_count": 10,
438+
"execution_count": 37,
353439
"metadata": {},
354440
"output_type": "execute_result"
355441
}
@@ -370,8 +456,33 @@
370456
},
371457
{
372458
"cell_type": "code",
373-
"execution_count": null,
374-
"id": "164febda",
459+
"execution_count": 40,
460+
"id": "2f651707",
461+
"metadata": {},
462+
"outputs": [
463+
{
464+
"data": {
465+
"text/plain": [
466+
"Name : \n",
467+
"Type : Group\n",
468+
"Zarr format : 3\n",
469+
"Read-only : False\n",
470+
"Store type : MemoryStore"
471+
]
472+
},
473+
"execution_count": 40,
474+
"metadata": {},
475+
"output_type": "execute_result"
476+
}
477+
],
478+
"source": [
479+
"root.info"
480+
]
481+
},
482+
{
483+
"cell_type": "code",
484+
"execution_count": 42,
485+
"id": "2363137a",
375486
"metadata": {},
376487
"outputs": [
377488
{
@@ -385,7 +496,7 @@
385496
"\u001b[31mModuleNotFoundError\u001b[39m: No module named 'rich'",
386497
"\nThe above exception was the direct cause of the following exception:\n",
387498
"\u001b[31mImportError\u001b[39m Traceback (most recent call last)",
388-
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[11]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mroot\u001b[49m\u001b[43m.\u001b[49m\u001b[43mtree\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
499+
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[42]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mroot\u001b[49m\u001b[43m.\u001b[49m\u001b[43mtree\u001b[49m\u001b[43m(\u001b[49m\u001b[43mexpand\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n",
389500
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda/envs/zarr_tutorial/lib/python3.13/site-packages/zarr/core/group.py:2361\u001b[39m, in \u001b[36mGroup.tree\u001b[39m\u001b[34m(self, expand, level)\u001b[39m\n\u001b[32m 2342\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mtree\u001b[39m(\u001b[38;5;28mself\u001b[39m, expand: \u001b[38;5;28mbool\u001b[39m | \u001b[38;5;28;01mNone\u001b[39;00m = \u001b[38;5;28;01mNone\u001b[39;00m, level: \u001b[38;5;28mint\u001b[39m | \u001b[38;5;28;01mNone\u001b[39;00m = \u001b[38;5;28;01mNone\u001b[39;00m) -> Any:\n\u001b[32m 2343\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 2344\u001b[39m \u001b[33;03m Return a tree-like representation of a hierarchy.\u001b[39;00m\n\u001b[32m 2345\u001b[39m \n\u001b[32m (...)\u001b[39m\u001b[32m 2359\u001b[39m \u001b[33;03m A pretty-printable object displaying the hierarchy.\u001b[39;00m\n\u001b[32m 2360\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m-> \u001b[39m\u001b[32m2361\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_sync\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43m_async_group\u001b[49m\u001b[43m.\u001b[49m\u001b[43mtree\u001b[49m\u001b[43m(\u001b[49m\u001b[43mexpand\u001b[49m\u001b[43m=\u001b[49m\u001b[43mexpand\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m=\u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n",
390501
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda/envs/zarr_tutorial/lib/python3.13/site-packages/zarr/core/sync.py:208\u001b[39m, in \u001b[36mSyncMixin._sync\u001b[39m\u001b[34m(self, coroutine)\u001b[39m\n\u001b[32m 205\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34m_sync\u001b[39m(\u001b[38;5;28mself\u001b[39m, coroutine: Coroutine[Any, Any, T]) -> T:\n\u001b[32m 206\u001b[39m \u001b[38;5;66;03m# TODO: refactor this to to take *args and **kwargs and pass those to the method\u001b[39;00m\n\u001b[32m 207\u001b[39m \u001b[38;5;66;03m# this should allow us to better type the sync wrapper\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m208\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43msync\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 209\u001b[39m \u001b[43m \u001b[49m\u001b[43mcoroutine\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 210\u001b[39m \u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[43m=\u001b[49m\u001b[43mconfig\u001b[49m\u001b[43m.\u001b[49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43masync.timeout\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 211\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n",
391502
"\u001b[36mFile \u001b[39m\u001b[32m~/miniconda/envs/zarr_tutorial/lib/python3.13/site-packages/zarr/core/sync.py:163\u001b[39m, in \u001b[36msync\u001b[39m\u001b[34m(coro, loop, timeout)\u001b[39m\n\u001b[32m 160\u001b[39m return_result = \u001b[38;5;28mnext\u001b[39m(\u001b[38;5;28miter\u001b[39m(finished)).result()\n\u001b[32m 162\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(return_result, \u001b[38;5;167;01mBaseException\u001b[39;00m):\n\u001b[32m--> \u001b[39m\u001b[32m163\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m return_result\n\u001b[32m 164\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 165\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m return_result\n",
@@ -397,33 +508,19 @@
397508
}
398509
],
399510
"source": [
400-
"root.tree()\n"
511+
"root.tree(expand=True)\n"
401512
]
402513
},
403514
{
404-
"cell_type": "code",
405-
"execution_count": null,
406-
"id": "2363137a",
515+
"cell_type": "markdown",
516+
"id": "a63ebdd7",
407517
"metadata": {},
408-
"outputs": [
409-
{
410-
"data": {
411-
"text/plain": [
412-
"Name : \n",
413-
"Type : Group\n",
414-
"Zarr format : 3\n",
415-
"Read-only : False\n",
416-
"Store type : MemoryStore"
417-
]
418-
},
419-
"execution_count": 81,
420-
"metadata": {},
421-
"output_type": "execute_result"
422-
}
423-
],
424518
"source": [
519+
"### How to Examine and Modify the Chunk Shape\n",
425520
"\n",
426-
"root.info"
521+
"If your data is sufficiently large, Zarr will chose a chunksize for you.\n",
522+
"\n",
523+
"\n"
427524
]
428525
},
429526
{
@@ -539,6 +636,12 @@
539636
"So far we have only been dealing in single array Zarr data stores. In this next example, we will create a zarr store with multiple arrays and then consolidate metadata. The speed up is significant when dealing in remote storage options, which we will see in the following example on accessing cloud storage."
540637
]
541638
},
639+
{
640+
"cell_type": "markdown",
641+
"id": "cdb3f822",
642+
"metadata": {},
643+
"source": []
644+
},
542645
{
543646
"cell_type": "code",
544647
"execution_count": null,

0 commit comments

Comments
 (0)