|
217 | 217 | "id": "c6a059cc",
|
218 | 218 | "metadata": {},
|
219 | 219 | "source": [
|
220 |
| - "##### Attributes\n", |
| 220 | + "#### Attributes\n", |
221 | 221 | "\n",
|
222 | 222 | "We can attach arbitrary metadata to our Array via attributes:"
|
223 | 223 | ]
|
224 | 224 | },
|
225 | 225 | {
|
226 | 226 | "cell_type": "code",
|
227 |
| - "execution_count": null, |
| 227 | + "execution_count": 35, |
228 | 228 | "id": "859c9cfe",
|
229 | 229 | "metadata": {},
|
230 | 230 | "outputs": [
|
|
256 | 256 | },
|
257 | 257 | {
|
258 | 258 | "cell_type": "code",
|
259 |
| - "execution_count": null, |
| 259 | + "execution_count": 28, |
260 | 260 | "id": "1bbc935c",
|
261 | 261 | "metadata": {},
|
262 | 262 | "outputs": [
|
|
266 | 266 | "LocalStore('file://test.zarr')"
|
267 | 267 | ]
|
268 | 268 | },
|
269 |
| - "execution_count": 7, |
| 269 | + "execution_count": 28, |
270 | 270 | "metadata": {},
|
271 | 271 | "output_type": "execute_result"
|
272 | 272 | }
|
|
277 | 277 | },
|
278 | 278 | {
|
279 | 279 | "cell_type": "code",
|
280 |
| - "execution_count": null, |
| 280 | + "execution_count": 30, |
281 | 281 | "id": "51953f01",
|
282 | 282 | "metadata": {},
|
283 | 283 | "outputs": [
|
|
294 | 294 | "│ │ ├── \u001b[00m3\u001b[0m\n",
|
295 | 295 | "│ │ └── \u001b[00m4\u001b[0m\n",
|
296 | 296 | "│ ├── \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" |
298 | 317 | ]
|
299 | 318 | }
|
300 | 319 | ],
|
301 | 320 | "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" |
303 | 389 | ]
|
304 | 390 | },
|
305 | 391 | {
|
306 | 392 | "cell_type": "markdown",
|
307 | 393 | "id": "35f5384e",
|
308 | 394 | "metadata": {},
|
309 | 395 | "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`." |
311 | 397 | ]
|
312 | 398 | },
|
313 | 399 | {
|
314 | 400 | "cell_type": "code",
|
315 |
| - "execution_count": null, |
| 401 | + "execution_count": 36, |
316 | 402 | "id": "e3c377a0",
|
317 | 403 | "metadata": {},
|
318 | 404 | "outputs": [],
|
|
335 | 421 | },
|
336 | 422 | {
|
337 | 423 | "cell_type": "code",
|
338 |
| - "execution_count": null, |
| 424 | + "execution_count": 37, |
339 | 425 | "id": "eecad1a6",
|
340 | 426 | "metadata": {},
|
341 | 427 | "outputs": [
|
|
349 | 435 | " 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32)"
|
350 | 436 | ]
|
351 | 437 | },
|
352 |
| - "execution_count": 10, |
| 438 | + "execution_count": 37, |
353 | 439 | "metadata": {},
|
354 | 440 | "output_type": "execute_result"
|
355 | 441 | }
|
|
370 | 456 | },
|
371 | 457 | {
|
372 | 458 | "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", |
375 | 486 | "metadata": {},
|
376 | 487 | "outputs": [
|
377 | 488 | {
|
|
385 | 496 | "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'rich'",
|
386 | 497 | "\nThe above exception was the direct cause of the following exception:\n",
|
387 | 498 | "\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", |
389 | 500 | "\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",
|
390 | 501 | "\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",
|
391 | 502 | "\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 | 508 | }
|
398 | 509 | ],
|
399 | 510 | "source": [
|
400 |
| - "root.tree()\n" |
| 511 | + "root.tree(expand=True)\n" |
401 | 512 | ]
|
402 | 513 | },
|
403 | 514 | {
|
404 |
| - "cell_type": "code", |
405 |
| - "execution_count": null, |
406 |
| - "id": "2363137a", |
| 515 | + "cell_type": "markdown", |
| 516 | + "id": "a63ebdd7", |
407 | 517 | "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 |
| - ], |
424 | 518 | "source": [
|
| 519 | + "### How to Examine and Modify the Chunk Shape\n", |
425 | 520 | "\n",
|
426 |
| - "root.info" |
| 521 | + "If your data is sufficiently large, Zarr will chose a chunksize for you.\n", |
| 522 | + "\n", |
| 523 | + "\n" |
427 | 524 | ]
|
428 | 525 | },
|
429 | 526 | {
|
|
539 | 636 | "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."
|
540 | 637 | ]
|
541 | 638 | },
|
| 639 | + { |
| 640 | + "cell_type": "markdown", |
| 641 | + "id": "cdb3f822", |
| 642 | + "metadata": {}, |
| 643 | + "source": [] |
| 644 | + }, |
542 | 645 | {
|
543 | 646 | "cell_type": "code",
|
544 | 647 | "execution_count": null,
|
|
0 commit comments