In [1]:
import zarr
zarr.__version__
Out[1]:
'2.1.5.dev211'
In [2]:
g1 = zarr.group()
g2 = g1.create_group('foo')
g3 = g1.create_group('bar')
g3.create_group('baz')
g3.create_dataset('xxx', shape=100)
g3.create_dataset('yyy', shape=(100, 100), dtype='i4')
g5 = g3.create_group('quux')
g5.create_dataset('aaa', shape=100)
g5.create_dataset('bbb', shape=(100, 100), dtype='i4')
g7 = g3.create_group('zoo')

Generate text (unicode) tree:

In [3]:
print(g1.tree())
/
 ├── bar
 │   ├── baz
 │   ├── quux
 │   │   ├── aaa (100,) float64
 │   │   └── bbb (100, 100) int32
 │   ├── xxx (100,) float64
 │   ├── yyy (100, 100) int32
 │   └── zoo
 └── foo

The level parameter controls how deep the tree is.

In [4]:
print(g1.tree(level=1))
/
 ├── bar
 └── foo
In [5]:
print(g1.tree(level=2))
/
 ├── bar
 │   ├── baz
 │   ├── quux
 │   ├── xxx (100,) float64
 │   ├── yyy (100, 100) int32
 │   └── zoo
 └── foo

Alternative plain ASCII tree:

In [6]:
print(bytes(g1.tree()).decode())
/
 +-- bar
 |   +-- baz
 |   +-- quux
 |   |   +-- aaa (100,) float64
 |   |   +-- bbb (100, 100) int32
 |   +-- xxx (100,) float64
 |   +-- yyy (100, 100) int32
 |   +-- zoo
 +-- foo

HTML trees:

In [7]:
g1.tree()
Out[7]:
  • /
    • bar
      • baz
      • quux
        • aaa (100,) float64
        • bbb (100, 100) int32
      • xxx (100,) float64
      • yyy (100, 100) int32
      • zoo
    • foo

Use expand=True to have all groups automatically expanded.

In [8]:
g1.tree(expand=True)
Out[8]:
  • /
    • bar
      • baz
      • quux
        • aaa (100,) float64
        • bbb (100, 100) int32
      • xxx (100,) float64
      • yyy (100, 100) int32
      • zoo
    • foo
In [9]:
g1.tree(expand=True, level=2)
Out[9]:
  • /
    • bar
      • baz
      • quux
      • xxx (100,) float64
      • yyy (100, 100) int32
      • zoo
    • foo
In [10]:
g1.tree(expand=True, level=1)
Out[10]:
  • /
    • bar
    • foo

The expand parameter can also be an integer, giving the depth to expand to.

In [11]:
g1.tree(expand=1)
Out[11]:
  • /
    • bar
      • baz
      • quux
        • aaa (100,) float64
        • bbb (100, 100) int32
      • xxx (100,) float64
      • yyy (100, 100) int32
      • zoo
    • foo
In [12]:
g1.tree(expand=2)
Out[12]:
  • /
    • bar
      • baz
      • quux
        • aaa (100,) float64
        • bbb (100, 100) int32
      • xxx (100,) float64
      • yyy (100, 100) int32
      • zoo
    • foo
In [13]:
g1.tree(expand=3)
Out[13]:
  • /
    • bar
      • baz
      • quux
        • aaa (100,) float64
        • bbb (100, 100) int32
      • xxx (100,) float64
      • yyy (100, 100) int32
      • zoo
    • foo

Change default icons, use icons from jstree default theme:

In [14]:
zarr.util.tree_array_icon = 'jstree-file'
zarr.util.tree_group_icon = 'jstree-folder'
In [15]:
g1.tree(expand=True)
Out[15]:
  • /
    • bar
      • baz
      • quux
        • aaa (100,) float64
        • bbb (100, 100) int32
      • xxx (100,) float64
      • yyy (100, 100) int32
      • zoo
    • foo

Change default icons, use font awesome icons.

In [16]:
zarr.util.tree_array_icon = 'fa fa-space-shuttle'
zarr.util.tree_group_icon = 'fa fa-star-o'
In [17]:
g1.tree(expand=True)
Out[17]:
  • /
    • bar
      • baz
      • quux
        • aaa (100,) float64
        • bbb (100, 100) int32
      • xxx (100,) float64
      • yyy (100, 100) int32
      • zoo
    • foo
In [ ]: