Skip to content
/ h5attr Public

H5Attr: Quick access to hdf5 data via attributes, allowing 'group.dataset' and IPython/Jupyter tab completion.

License

Notifications You must be signed in to change notification settings

syrte/h5attr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

H5Attr

H5Attr: Quick access to hdf5 data via attributes, allowing group.dataset (equivalent to group['dataset']) and IPython/Jupyter tab completion.

Installation

pip install git+https://github.com/syrte/h5attr

Usage

# create example HDF5 file for this guide
import h5py, io
file = io.BytesIO()
with h5py.File(file, 'w') as fp:
    fp['0'] = [1, 2]
    fp['a'] = [3, 4]
    fp['b/c'] = 5
    fp.attrs['d'] = 's'

# import package
from h5attr import H5Attr

# open file
f = H5Attr(file)

# easy access to members, with tab completion in IPython/Jupyter
f.a, f['a']

# also work for subgroups, but note that f['b/c'] is more efficient
# because it does not create f['b']
f.b.c, f['b'].c, f['b/c']

# convert integer keys to strings automatically (cannot use f.0)
f[0], f['0']

# allow dict-like operations
list(f), [key for key in f], 'a' in f

# access to HDF5 attrs via a H5Attr wrapper
f._attrs.d, f._attrs['d']

# show summary of the data
f._show()
# 0   int64 (2,)
# a   int64 (2,)
# b/  1 members

# close the hdf5 file
f._close()

# lazy (default) and non-lazy mode
f = H5Attr(file)
f.a  # <HDF5 dataset "a": shape (2,), type "<i8">

f = H5Attr(file, lazy=False)
f.a  # array([3, 4])

API

H5Attr(path, lazy=True, **args)

  • Parameters
    • path: h5py group, file path, or file-like object.
    • lazy: bool, if true, dataset[()] will be returned.
    • args: additional arguments used for opening h5py file.
  • Properties
    • _attrs: access to the h5py attrs dict.
  • Methods
    • _close(): close the h5py file if applicable.
    • _show(): show a summary of the h5py group.

About

H5Attr: Quick access to hdf5 data via attributes, allowing 'group.dataset' and IPython/Jupyter tab completion.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages