def testhdf5util(self):
        copy = h5py.File(os.path.join(self.tmpdir, 'copy.h5'), 'w')
        hdf5util.copy(self.original, copy)

        self.assertEqual(1, copy.attrs['a'])
        self.assertEqual(2, copy['group1'].attrs['b'])
        self.assertEqual(4, np.sum(copy['group1']['data1']))
Exemple #2
0
    def _make_backup(self, filepath):
        bak_filepath = _Updater._make_backup(self, filepath)
        if os.path.splitext(filepath)[1] != '.h5':
            return bak_filepath

        # Special check for HDF5 file created in Java
        # The HDF5 has to be re-saved to allow modifications
        hdf5file_original = h5py.File(bak_filepath, 'r+')

        try:
            hdf5file_original.attrs['version'] = hdf5file_original.attrs['version']
        except:
            hdf5file_copy = h5py.File(filepath, 'w')
            hdf5util.copy(hdf5file_original, hdf5file_copy)
            hdf5file_copy.close()
        finally:
            hdf5file_original.close()

        return bak_filepath