Skip to content

Commit

Permalink
Merge pull request #16 from davidbrochart/notebook
Browse files Browse the repository at this point in the history
Add notebook explore_hierarchy.ipynb
  • Loading branch information
davidbrochart committed Nov 21, 2020
2 parents dffd91a + 6cc8e6a commit a06fca6
Showing 1 changed file with 296 additions and 0 deletions.
296 changes: 296 additions & 0 deletions examples/explore_hierarchy.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Zarr (v3) store API"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this notebook we make use of the Zarr (v3) store API to access a hierarchy in C++."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Download development source code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">bash\n",
"rm -rf zarrita *.tar.gz*\n",
"mkdir -p zarrita\n",
"\n",
"wget https://github.com/alimanfoo/zarrita/archive/master.tar.gz -O zarrita.tar.gz -q\n",
"tar zxf zarrita.tar.gz -C zarrita --strip-components 1\n",
"mv zarrita/zarrita.py ."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"#pragma cling add_include_path(\"../include\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"#pragma cling add_library_path(\"$CONDA_PREFIX/lib\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"#pragma cling load(\"storage_client\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"#include \"xtensor/xio.hpp\"\n",
"#include \"xtensor/xview.hpp\"\n",
"#include \"xtensor/xchunked_array.hpp\"\n",
"#include \"xtensor-io/xio_gzip.hpp\"\n",
"#include \"xtensor-io/xchunk_store_manager.hpp\"\n",
"#include \"xtensor-zarr/xzarr_hierarchy.hpp\"\n",
"#include \"xtensor-zarr/xzarr_file_system_store.hpp\"\n",
"#include \"xtensor-zarr/xzarr_gcs_store.hpp\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create a Zarr hierarchy in Python"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">bash\n",
"rm -rf test.zr3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import zarrita\n",
"h = zarrita.create_hierarchy('test.zr3')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"h.create_group('marvin')\n",
"h['marvin'].create_group('paranoid')\n",
"attrs = {'age': 42, 'gender': 'male'}\n",
"h.create_group('/tricia/mcmillan', attrs=attrs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">bash\n",
"find test.zr3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Open the Zarr hierarchy in C++"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"xt::xzarr_file_system_store s1(\"test.zr3\");\n",
"auto h1 = xt::get_zarr_hierarchy(s1);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Explore the hierarchy in C++"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Explore the hierarchy top-down:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"std::string children1 = h1.get_children(\"/\").dump();\n",
"children1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"std::string children2 = h1.get_children(\"/marvin\").dump();\n",
"children2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"std::string children3 = h1.get_children(\"/tricia\").dump();\n",
"children3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"std::string attrs1 = h1[\"/tricia/mcmillan\"].get_group().attrs().dump();\n",
"attrs1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"View the whole hierarchy in one go:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"std::string nodes = h1.get_nodes().dump();\n",
"nodes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create groups in C++"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
">xcpp14\n",
"nlohmann::json attrs2 = {{\"heart\", \"gold\"}, {\"improbability\", \"infinite\"}};\n",
"auto g1 = h1.create_group(\"/foo/bar\", attrs2);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Explore the hierarchy in Python"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"h = zarrita.get_hierarchy('test.zr3')\n",
"h.get_children('/')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"h.get_children('foo')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"h['foo/bar'].attrs"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "All the Kernels",
"language": "",
"name": "atk"
},
"language_info": {
"mimetype": "text/plain",
"name": "all-of-them"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit a06fca6

Please sign in to comment.