Skip to content

Commit 017de3f

Browse files
committed
Include notebook demonstrating tree
Provides a quick demo showing how to use `tree` to get text-based and HTML-based representations of a Zarr `Group` object.
1 parent 399eee8 commit 017de3f

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

notebooks/repr_tree.ipynb

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import zarr"
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": 2,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"g1 = zarr.group()\n",
19+
"g3 = g1.create_group('bar')\n",
20+
"g3.create_group('baz')\n",
21+
"g5 = g3.create_group('quux')\n",
22+
"g5.create_dataset('baz', shape=100, chunks=10)\n",
23+
"g7 = g3.create_group('zoo')"
24+
]
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": 3,
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"/\n",
36+
" +-- bar\n",
37+
" +-- baz\n",
38+
" +-- quux\n",
39+
" | +-- baz[...]\n",
40+
" +-- zoo\n"
41+
]
42+
}
43+
],
44+
"source": [
45+
"print(g1.tree())"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 4,
51+
"metadata": {},
52+
"outputs": [
53+
{
54+
"data": {
55+
"text/html": [
56+
"<style type=\"text/css\">\n",
57+
"div.zarrTree {\n",
58+
" font-family: Courier, monospace;\n",
59+
" font-size: 11pt;\n",
60+
" font-style: normal;\n",
61+
"}\n",
62+
"\n",
63+
"div.zarrTree ul,\n",
64+
"div.zarrTree li,\n",
65+
"div.zarrTree li > div {\n",
66+
" display: block;\n",
67+
" position: relative;\n",
68+
"}\n",
69+
"\n",
70+
"div.zarrTree ul,\n",
71+
"div.zarrTree li {\n",
72+
" list-style-type: none;\n",
73+
"}\n",
74+
"\n",
75+
"div.zarrTree li {\n",
76+
" border-left: 2px solid #000;\n",
77+
" margin-left: 1em;\n",
78+
"}\n",
79+
"\n",
80+
"div.zarrTree li > div {\n",
81+
" padding-left: 1.3em;\n",
82+
" padding-top: 0.225em;\n",
83+
" padding-bottom: 0.225em;\n",
84+
"}\n",
85+
"\n",
86+
"div.zarrTree li > div::before {\n",
87+
" content: '';\n",
88+
" position: absolute;\n",
89+
" top: 0;\n",
90+
" left: -2px;\n",
91+
" bottom: 50%;\n",
92+
" width: 1.2em;\n",
93+
" border-left: 2px solid #000;\n",
94+
" border-bottom: 2px solid #000;\n",
95+
"}\n",
96+
"\n",
97+
"div.zarrTree > ul > li:first-child > div {\n",
98+
" padding-left: 4%;\n",
99+
"}\n",
100+
"\n",
101+
"div.zarrTree > ul > li:first-child > div::before {\n",
102+
" border: 0 none transparent;\n",
103+
"}\n",
104+
"\n",
105+
"div.zarrTree ul > li:last-child {\n",
106+
" border-left: 2px solid transparent;\n",
107+
"}\n",
108+
"</style>\n",
109+
"\n",
110+
"<div class=\"zarrTree\">\n",
111+
"<ul>\n",
112+
" <li><div>/</div>\n",
113+
" <ul>\n",
114+
" <li><div>bar</div>\n",
115+
" <ul>\n",
116+
" <li><div>baz</div></li>\n",
117+
" <li><div>quux</div>\n",
118+
" <ul>\n",
119+
" <li><div>baz[...]</div></li>\n",
120+
" </ul>\n",
121+
" </li>\n",
122+
" <li><div>zoo</div></li>\n",
123+
" </ul>\n",
124+
" </li>\n",
125+
" </ul>\n",
126+
" </li>\n",
127+
"</ul>\n",
128+
"</div>\n"
129+
],
130+
"text/plain": [
131+
"/\n",
132+
" +-- bar\n",
133+
" +-- baz\n",
134+
" +-- quux\n",
135+
" | +-- baz[...]\n",
136+
" +-- zoo"
137+
]
138+
},
139+
"execution_count": 4,
140+
"metadata": {},
141+
"output_type": "execute_result"
142+
}
143+
],
144+
"source": [
145+
"g1.tree()"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": null,
151+
"metadata": {},
152+
"outputs": [],
153+
"source": []
154+
}
155+
],
156+
"metadata": {
157+
"kernelspec": {
158+
"display_name": "Python 3",
159+
"language": "python",
160+
"name": "python3"
161+
},
162+
"language_info": {
163+
"codemirror_mode": {
164+
"name": "ipython",
165+
"version": 3
166+
},
167+
"file_extension": ".py",
168+
"mimetype": "text/x-python",
169+
"name": "python",
170+
"nbconvert_exporter": "python",
171+
"pygments_lexer": "ipython3",
172+
"version": "3.6.3"
173+
}
174+
},
175+
"nbformat": 4,
176+
"nbformat_minor": 2
177+
}

0 commit comments

Comments
 (0)