コード例 #1
0
ファイル: analysis.py プロジェクト: yangASM/Magni
def _save_output(output_path, name, fig, fig_ext, datasets):
    """
    Save figure and data output.

    Parameters
    ----------
    output_path : str
        The output_path to save to.
    name : str
        The 'fixed' part of the file name saved to.
    fig : matplotlib.figure.Figure
        The figure instance to save.
    fig_ext : str
        The file extension to use for the saved figure.
    datasets : dict
        The dict of dicts for datasets to save in a HDF database.

    """

    @_decorate_validation
    def validate_input():
        _generic('output_path', 'string')
        _generic('name', 'string')
        _generic('fig', mpl.figure.Figure)
        _generic('fig_ext', 'string')
        _levels('datasets', (_generic(None, 'mapping'),
                             _generic(None, 'mapping')))

    validate_input()

    if output_path[-1] == os.sep:
        path = output_path
        prefix = ''

    else:
        path, prefix, no_ext = _split_path(output_path)
        prefix = prefix + '_'

    fig.savefig(path + prefix + name + os.path.extsep + fig_ext)

    db_path = path + prefix + name + '.hdf5'
    _io.create_database(db_path)
    with _File(db_path, mode='a') as h5file:
        data_group = h5file.create_group('/', 'data', __name__ + ': ' + name)
        for dataset in datasets:
            set_group = h5file.create_group(data_group, dataset, dataset)
            for array in datasets[dataset]:
                h5file.create_array(set_group, array, datasets[dataset][array])
コード例 #2
0
    def test_create_database(self):
        io.create_database(self.h5_name)
        with tb.File(self.h5_name, mode='a') as h5_file:
            annotation_keys = sorted(io.read_annotations(h5_file).keys())
            self.assertEqual(annotation_keys, self.ref_annotation_keys)
            chase_keys = sorted(io.read_chases(h5_file).keys())
            self.assertEqual(chase_keys, self.ref_chase_keys)

        # Overwrite test
        io.create_database(self.h5_name)
        with self.assertRaises(IOError):
            io.create_database(self.h5_name, overwrite=False)