Skip to content

Commit

Permalink
update snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Mar 6, 2024
1 parent e817f31 commit bb67768
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 0 deletions.
158 changes: 158 additions & 0 deletions Untitled.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8e33e371-5d5f-48f3-9450-ca81700a7458",
"metadata": {},
"outputs": [],
"source": [
"import anywidget\n",
"import traitlets\n",
"\n",
"class ZarrWidget(anywidget.AnyWidget):\n",
" _esm = \"\"\"\n",
" import * as zarr from \"https://esm.sh/zarrita@next\";\n",
" \n",
" function render({ model, el, experimental }) {\n",
" let root = zarr.root({\n",
" async get(key) {\n",
" const [data, buffers] = await experimental.dispatch({\n",
" type: \"get\",\n",
" key,\n",
" });\n",
" if (!data.success) return undefined;\n",
" return buffers[0].buffer;\n",
" },\n",
" });\n",
" \n",
" let pre = document.createElement(\"pre\");\n",
"\n",
" let btn = document.createElement(\"button\");\n",
" btn.innerHTML = `click to load`;\n",
" btn.addEventListener(\"click\", async () => {\n",
" const node = await zarr.open(root.resolve(\"/foo\"), { kind: \"array\" });\n",
" const { data, shape, stride } = await zarr.get(node);\n",
" pre.innerText = JSON.stringify({ data: data.constructor.name, shape, stride });\n",
" });\n",
" el.append(btn, pre);\n",
" }\n",
" export default { render };\n",
" \"\"\"\n",
" def __init__(self, store, **kwargs):\n",
" super().__init__(**kwargs)\n",
" self._store = store\n",
"\n",
" def _anywidget_experimental_reducer(self, action, buffers):\n",
" match action:\n",
" case { \"type\": \"get\", \"key\": key }:\n",
" try:\n",
" buffers = [store[key.lstrip(\"/\")]]\n",
" except KeyError:\n",
" buffers = []\n",
" return { \"success\": len(buffers) == 1 }, buffers\n",
" case _:\n",
" raise ValueError(\"Unknown action\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "11c02f74-25aa-406e-9fe8-f3dbb0e58d0f",
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'zarr'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mzarr\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mzarr\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mstorage\u001b[39;00m\n\u001b[1;32m 4\u001b[0m store \u001b[38;5;241m=\u001b[39m zarr\u001b[38;5;241m.\u001b[39mstorage\u001b[38;5;241m.\u001b[39mMemoryStore()\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'zarr'"
]
}
],
"source": [
"import zarr\n",
"import zarr.storage\n",
"\n",
"store = zarr.storage.MemoryStore()\n",
"grp = zarr.open(store)\n",
"grp.create_dataset(\"foo\", shape=[10, 10])\n",
"\n",
"ZarrWidget(store=store)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "9b5a3ee9-5aad-44dd-a5c2-202bac57bd3f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting zarr\n",
" Using cached zarr-2.17.0-py3-none-any.whl.metadata (5.7 kB)\n",
"Collecting asciitree (from zarr)\n",
" Using cached asciitree-0.3.3-py3-none-any.whl\n",
"Collecting numpy>=1.21.1 (from zarr)\n",
" Using cached numpy-1.26.4-cp312-cp312-macosx_11_0_arm64.whl.metadata (61 kB)\n",
"Collecting numcodecs>=0.10.0 (from zarr)\n",
" Using cached numcodecs-0.12.1-cp312-cp312-macosx_11_0_arm64.whl.metadata (2.8 kB)\n",
"Collecting fasteners (from zarr)\n",
" Using cached fasteners-0.19-py3-none-any.whl.metadata (4.9 kB)\n",
"Using cached zarr-2.17.0-py3-none-any.whl (207 kB)\n",
"Using cached numcodecs-0.12.1-cp312-cp312-macosx_11_0_arm64.whl (1.4 MB)\n",
"Using cached numpy-1.26.4-cp312-cp312-macosx_11_0_arm64.whl (13.7 MB)\n",
"Using cached fasteners-0.19-py3-none-any.whl (18 kB)\n",
"Installing collected packages: asciitree, numpy, fasteners, numcodecs, zarr\n",
"Successfully installed asciitree-0.3.3 fasteners-0.19 numcodecs-0.12.1 numpy-1.26.4 zarr-2.17.0\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
}
],
"source": [
"%pip install zarr"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66f1bd83-d08c-4f47-a97b-d8ce3a74e19d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.1"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
40 changes: 40 additions & 0 deletions Untitled1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "31fea651-983d-4d48-b8a3-6407f8e9cc75",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.1"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as zarr from "https://esm.sh/zarrita@next";

function render({ model, el, experimental }) {
let root = zarr.root({
async get(key) {
const [data, buffers] = await experimental.dispatch({
type: "get",
key,
});
if (!data.success) return undefined;
return buffers[0].buffer;
},
});

let btn = document.createElement("button");
btn.innerHTML = `click to load`;
btn.addEventListener("click", async () => {
const node = await zarr.open(root.resolve("/blosc"), { kind: "array" });
const arr = await zarr.get(node);
console.log(arr);
});
el.appendChild(btn);
}
export default { render };
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -185,6 +194,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -388,6 +406,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -555,6 +582,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -723,6 +759,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -928,6 +973,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1099,6 +1153,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1302,6 +1365,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1469,6 +1541,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -1637,6 +1718,15 @@ pip install undefined
{
"content": "{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%env ANYWIDGET_HMR=1"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit bb67768

Please sign in to comment.