Skip to content
Snippets Groups Projects
trx_mat.py 918 B
Newer Older
François  LAURENT's avatar
François LAURENT committed
from larva.qc.file import QCFile, asfun, load, check, save
François  LAURENT's avatar
François LAURENT committed
import h5py
François  LAURENT's avatar
François LAURENT committed
from .backend import hdf5storage as default
François  LAURENT's avatar
François LAURENT committed

class Trx(QCFile):

François  LAURENT's avatar
François LAURENT committed
    __slots__ = ()

    def __init__(self, filepath=None):
        QCFile.__init__(self, filepath)
        self.backend = default.trx_backend
François  LAURENT's avatar
François LAURENT committed
    def list_varnames(self):
François  LAURENT's avatar
François LAURENT committed
        filepath = self.filepath
François  LAURENT's avatar
François LAURENT committed
        if not filepath:
            raise ValueError('filepath is not defined')
François  LAURENT's avatar
François LAURENT committed
        try:
            store = h5py.File(filepath, 'r')
        except OSError:
            raise
        else:
            varnames = list(store['trx'].keys())
            return varnames
        finally:
            store.close()

François  LAURENT's avatar
François LAURENT committed
list_trx_varnames = asfun(Trx, Trx.list_varnames)
load_trx = load(Trx)
check_trx = check(Trx)
save_trx = save(Trx) # not implemented
François  LAURENT's avatar
François LAURENT committed

__all__ = [
        'Trx',
        'list_trx_varnames',
        'load_trx',
        'check_trx',
        'save_trx',
        ]