Last active
February 26, 2020 18:14
-
-
Save jakirkham/1710dde6991cb8a593665ddbeae9fbf5 to your computer and use it in GitHub Desktop.
Zarr quick demo for lightning talk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from pprint import pprint\n", | |
"\n", | |
"import numpy as np\n", | |
"import zarr" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "fa1a11ec8b284c0c8b723e0adf309fa3", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"Tree(nodes=(Node(disabled=True, name='/'),))" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"store = dict()\n", | |
"g = zarr.group(store)\n", | |
"g.tree()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "39778166d84f45f692eddbec25391af5", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"Tree(nodes=(Node(disabled=True, name='/', nodes=(Node(disabled=True, name='mygroup', opened=False),)),))" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"g_mygroup = g.create_group(\"mygroup\")\n", | |
"g.tree()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "258b1b589537453b81168e5edf10d6c5", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"Tree(nodes=(Node(disabled=True, name='/', nodes=(Node(disabled=True, icon='table', name='data1 (5, 6) int64', …" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"data1 = g.create_dataset(\"data1\", dtype=int, shape=(5, 6), chunks=(2, 3))\n", | |
"data2 = g_mygroup.create_dataset(\"data2\", dtype=float, shape=(10, 12), chunks=(2, 3))\n", | |
"g.tree()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'.zgroup': b'{\\n \"zarr_format\": 2\\n}',\n", | |
" 'data1/.zarray': b'{\\n \"chunks\": [\\n 2,\\n 3\\n ],\\n \"c'\n", | |
" b'ompressor\": {\\n \"blocksize\": 0,\\n \"clevel\": '\n", | |
" b'5,\\n \"cname\": \"lz4\",\\n \"id\": \"blosc\",\\n '\n", | |
" b' \"shuffle\": 1\\n },\\n \"dtype\": \"<i8\",\\n \"fill_valu'\n", | |
" b'e\": 0,\\n \"filters\": null,\\n \"order\": \"C\",\\n \"shape'\n", | |
" b'\": [\\n 5,\\n 6\\n ],\\n \"zarr_format\": '\n", | |
" b'2\\n}',\n", | |
" 'mygroup/.zgroup': b'{\\n \"zarr_format\": 2\\n}',\n", | |
" 'mygroup/data2/.zarray': b'{\\n \"chunks\": [\\n 2,\\n 3\\n ]'\n", | |
" b',\\n \"compressor\": {\\n \"blocksize\": 0,\\n '\n", | |
" b' \"clevel\": 5,\\n \"cname\": \"lz4\",\\n '\n", | |
" b' \"id\": \"blosc\",\\n \"shuffle\": 1\\n },\\n '\n", | |
" b' \"dtype\": \"<f8\",\\n \"fill_value\": 0.0,\\n \"fi'\n", | |
" b'lters\": null,\\n \"order\": \"C\",\\n \"shape\": [\\n '\n", | |
" b' 10,\\n 12\\n ],\\n \"zarr_format\": '\n", | |
" b'2\\n}'}\n" | |
] | |
} | |
], | |
"source": [ | |
"pprint(store)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"data2[:3, :4] = np.arange(12, dtype=data2.dtype).reshape(3, 4)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'.zgroup': b'{\\n \"zarr_format\": 2\\n}',\n", | |
" 'data1/.zarray': b'{\\n \"chunks\": [\\n 2,\\n 3\\n ],\\n \"c'\n", | |
" b'ompressor\": {\\n \"blocksize\": 0,\\n \"clevel\": '\n", | |
" b'5,\\n \"cname\": \"lz4\",\\n \"id\": \"blosc\",\\n '\n", | |
" b' \"shuffle\": 1\\n },\\n \"dtype\": \"<i8\",\\n \"fill_valu'\n", | |
" b'e\": 0,\\n \"filters\": null,\\n \"order\": \"C\",\\n \"shape'\n", | |
" b'\": [\\n 5,\\n 6\\n ],\\n \"zarr_format\": '\n", | |
" b'2\\n}',\n", | |
" 'mygroup/.zgroup': b'{\\n \"zarr_format\": 2\\n}',\n", | |
" 'mygroup/data2/.zarray': b'{\\n \"chunks\": [\\n 2,\\n 3\\n ]'\n", | |
" b',\\n \"compressor\": {\\n \"blocksize\": 0,\\n '\n", | |
" b' \"clevel\": 5,\\n \"cname\": \"lz4\",\\n '\n", | |
" b' \"id\": \"blosc\",\\n \"shuffle\": 1\\n },\\n '\n", | |
" b' \"dtype\": \"<f8\",\\n \"fill_value\": 0.0,\\n \"fi'\n", | |
" b'lters\": null,\\n \"order\": \"C\",\\n \"shape\": [\\n '\n", | |
" b' 10,\\n 12\\n ],\\n \"zarr_format\": '\n", | |
" b'2\\n}',\n", | |
" 'mygroup/data2/0.0': b'\\x02\\x013\\x080\\x00\\x00\\x000\\x00\\x00\\x00@\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\xf0?\\x00\\x00\\x00\\x00\\x00\\x00\\x00@'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x10@\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x14@\\x00\\x00\\x00\\x00\\x00\\x00\\x18@',\n", | |
" 'mygroup/data2/0.1': b'\\x02\\x013\\x080\\x00\\x00\\x000\\x00\\x00\\x00@\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x08@\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x1c@\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00',\n", | |
" 'mygroup/data2/1.0': b'\\x02\\x013\\x080\\x00\\x00\\x000\\x00\\x00\\x00@\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00 @\\x00\\x00\\x00\\x00\\x00\\x00\"@'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00$@\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00',\n", | |
" 'mygroup/data2/1.1': b'\\x02\\x013\\x080\\x00\\x00\\x000\\x00\\x00\\x00@\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00&@\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'\n", | |
" b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'}\n" | |
] | |
} | |
], | |
"source": [ | |
"pprint(store)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([[ 0., 1., 2., 3., 0.],\n", | |
" [ 4., 5., 6., 7., 0.],\n", | |
" [ 8., 9., 10., 11., 0.],\n", | |
" [ 0., 0., 0., 0., 0.]])" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"data2[:4, :5]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.6" | |
}, | |
"widgets": { | |
"application/vnd.jupyter.widget-state+json": { | |
"state": { | |
"029cb4b8533f492c9eed637c9d11f7e2": { | |
"model_module": "@jupyter-widgets/base", | |
"model_module_version": "1.2.0", | |
"model_name": "LayoutModel", | |
"state": {} | |
}, | |
"258b1b589537453b81168e5edf10d6c5": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "TreeModel", | |
"state": { | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"layout": "IPY_MODEL_67c825933e0d41ac8e6bd5ab86829310", | |
"nodes": [ | |
"IPY_MODEL_54aa44b4fa8c461e930712cb97b19d6c" | |
] | |
} | |
}, | |
"39778166d84f45f692eddbec25391af5": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "TreeModel", | |
"state": { | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"layout": "IPY_MODEL_dde469f189494f48bf8f45de39ffcd04", | |
"nodes": [ | |
"IPY_MODEL_8ce28f61579d4a35b6e43ef59911bd19" | |
] | |
} | |
}, | |
"4aec32c829fe44668a38f87b649c4f04": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "NodeModel", | |
"state": { | |
"_id": "a31944bf-d78d-4ce1-a39f-38d408afa42d", | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"disabled": true, | |
"name": "/" | |
} | |
}, | |
"54aa44b4fa8c461e930712cb97b19d6c": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "NodeModel", | |
"state": { | |
"_id": "554d9b04-5a0d-4094-a99e-56b27b7cad86", | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"disabled": true, | |
"name": "/", | |
"nodes": [ | |
"IPY_MODEL_a57095ee3be3416693f1171d85fdeb85", | |
"IPY_MODEL_cd12c28840de46f1a78d220e5570cfa0" | |
] | |
} | |
}, | |
"67c825933e0d41ac8e6bd5ab86829310": { | |
"model_module": "@jupyter-widgets/base", | |
"model_module_version": "1.2.0", | |
"model_name": "LayoutModel", | |
"state": {} | |
}, | |
"8ce28f61579d4a35b6e43ef59911bd19": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "NodeModel", | |
"state": { | |
"_id": "0ed0eb0c-9bc0-4ebe-a33a-acf4fa1a52f1", | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"disabled": true, | |
"name": "/", | |
"nodes": [ | |
"IPY_MODEL_96cd6816abfc462bb192bcca7058273c" | |
] | |
} | |
}, | |
"96cd6816abfc462bb192bcca7058273c": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "NodeModel", | |
"state": { | |
"_id": "fe5a4b60-8e7a-46b7-86b2-b43679db343b", | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"disabled": true, | |
"name": "mygroup", | |
"opened": false | |
} | |
}, | |
"a57095ee3be3416693f1171d85fdeb85": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "NodeModel", | |
"state": { | |
"_id": "cc934046-37f1-4f09-bf89-e114b5780221", | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"disabled": true, | |
"icon": "table", | |
"name": "data1 (5, 6) int64", | |
"opened": false | |
} | |
}, | |
"cd12c28840de46f1a78d220e5570cfa0": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "NodeModel", | |
"state": { | |
"_id": "49bfc6d7-4a58-40bf-adb4-ba737c98c299", | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"disabled": true, | |
"name": "mygroup", | |
"nodes": [ | |
"IPY_MODEL_fd877395d5cd4a91af11757238d3b674" | |
], | |
"opened": false | |
} | |
}, | |
"dde469f189494f48bf8f45de39ffcd04": { | |
"model_module": "@jupyter-widgets/base", | |
"model_module_version": "1.2.0", | |
"model_name": "LayoutModel", | |
"state": {} | |
}, | |
"fa1a11ec8b284c0c8b723e0adf309fa3": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "TreeModel", | |
"state": { | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"layout": "IPY_MODEL_029cb4b8533f492c9eed637c9d11f7e2", | |
"nodes": [ | |
"IPY_MODEL_4aec32c829fe44668a38f87b649c4f04" | |
] | |
} | |
}, | |
"fd877395d5cd4a91af11757238d3b674": { | |
"model_module": "ipytree", | |
"model_module_version": "0.1.5", | |
"model_name": "NodeModel", | |
"state": { | |
"_id": "70e67c31-0852-42d3-800e-aeeac17496e5", | |
"_model_module_version": "0.1.5", | |
"_view_module_version": "0.1.5", | |
"disabled": true, | |
"icon": "table", | |
"name": "data2 (10, 12) float64", | |
"opened": false | |
} | |
} | |
}, | |
"version_major": 2, | |
"version_minor": 0 | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment