SciPy

tethne.persistence.hdf5 package

Module contents

Classes and methods for persisting Tethne data objects in HDF5.

to_hdf5 Convert a Tethne data object to its HDF5 representation.
from_hdf5 Load a data object from a HDF5 object, or a path to an HDF5 repository.
tethne.persistence.hdf5.from_hdf5(HD_or_path)[source]

Load a data object from a HDF5 object, or a path to an HDF5 repository.

Parameters:

HD_or_path : str or object

If an object, expects an object from persistence.hdf5. If str, expects a path to an H5 repo, and will determine object type from the contents of that file.

Returns:

object

Corresponding Tethne data object (e.g. Corpus).

Examples

From an HDF5 object:

>>> from tethne.persistence import hdf5
>>> MyCorpus = hdf5.from_hdf5(MyHDF5Corpus)
>>> MyCorpus
<tethne.classes.corpus.Corpus object at 0x1007d5fd0>

From an HDF5 repo containing a HDF5Corpus:

>>> MyCorpus = hdf5.from_hdf5('/path/to/my/corpus.h5')
>>> MyCorpus
<tethne.classes.corpus.Corpus object at 0x1007d5fd0>
tethne.persistence.hdf5.to_hdf5(obj, datapath=None)[source]

Convert a Tethne data object to its HDF5 representation.

Parameters:

obj : object

Can be a Corpus, GraphCollection, or an object from model.

datapath : str

Path to HDF5 file (will be created).

Returns:

HDF5 object

Examples

>>> from tethne.persistence import hdf5
>>> MyHDF5Corpus = hdf5.to_hdf5(MyCorpus, datapath='/path/to/my/data.h5')
>>> MyHDF5Corpus
<tethne.persistence.hdf5.corpus.HDF5Corpus object at 0x10770fd10>