Example #1
0
class MetaContainer(object):
    """
    Class to control storing of metainformation

    Parameters
    -----
        path: string
            Absolute path to output .h5 file
        summary_data: dictionary-like object
            Additional information that should be saved.
            For example dalek_version, tardis_version, time, ranks, iterations

    """
    def __init__(self, path, summary_data=None):
        self._path, self._file = os.path.split(path)
        self.open = False
        if summary_data is not None:
            self._write_summary(summary_data)

    def _write_summary(self, data):
        '''
        Write summary_data to .h5 file.
        '''
        # TODO: proper dictionary to pd.Series parsing
        with self as store:
            if 'overview' not in store.keys():
                store.put('overview', pd.Series(data.values(), index=data.keys()))

    def __enter__(self):
        '''
        Wrapper function to allow

        with MetaContainer as store:
            <code>
        '''
        if not self.open:
            self.open = True
            self.store = SafeHDFStore(os.path.join(self._path, self._file))
        return self.store

    def __exit__(self, type, value, traceback):
        '''
        close store after 'with'
        '''
        if self.open:
            self.store.__exit__(type, value, traceback)
            self.open = False
        return
Example #2
0
    def __enter__(self):
        '''
        Wrapper function to allow

        with MetaContainer as store:
            <code>
        '''
        if not self.open:
            self.open = True
            self.store = SafeHDFStore(os.path.join(self._path, self._file))
        return self.store
Example #3
0
class MetaContainer(object):
    """
    Class to control storing of metainformation

    Parameters
    -----
        path: string
            Absolute path to output .h5 file
        summary_data: dictionary-like object
            Additional information that should be saved.
            For example dalek_version, tardis_version, time,
            number of ranks, iterations

    """
    def __init__(self, path, summary_data=None):
        self._path, self._file = os.path.split(path)
        self._store = None
        if summary_data is not None:
            self._write_summary(summary_data)

    @property
    def store(self):
        if self._store is None:
            self._store = SafeHDFStore(os.path.join(self._path, self._file))
        return self._store

    def close(self):
        self._store.close()
        self._store = None

    def _write_summary(self, data):
        '''
        Write summary_data to .h5 file.
        '''
        if 'overview' not in self.store.keys():
            pd.Series(
                    data.values(), index=data.keys()
                    ).to_hdf(self.store, 'overview')

    def save(self, item, path):
        item.to_hdf(self.store, path)
Example #4
0
 def store(self):
     if self._store is None:
         self._store = SafeHDFStore(os.path.join(self._path, self._file))
     return self._store