Skip to content

ipytree #3

@bendichter

Description

@bendichter
from ipytree import Tree, Node
import h5py
import numpy as np

def nwb_ipytree(fpath, driver=None):
    file = h5py.File(fpath, mode="r", driver=driver)
    return Tree(nodes=[add_elem(value) for value in file.values()])


def add_elem(elem, cls=Node):
    name = elem.name.split('/')[-1]
    if isinstance(elem, h5py.Group):
        return cls(name=name, nodes=[add_elem(value) for value in elem.values()], opened=False)
    elif isinstance(elem, h5py.Dataset):
        if elem.dtype == np.object:
            icon = 'font'
        else:
            icon = 'table'
        return cls(name=name, icon=icon, icon_style='info')
            
    else:
        return cls(name)

fpath = "/Users/bendichter/Downloads/136_20170325_576um_360um_170325_125511_stub.nwb"

nwb_ipytree(fpath)

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions