HDF5 file (h5py) with version control - hash changes on every save

自作多情 提交于 2021-02-07 13:49:39

问题


I am using h5py to store intermediate data from numerical work in an HDF5 file. I have the project under version control, but this doesn't work well with the HDF5 files because every time a script is re-run which generates a HDF5 file, the binary file changes even if the data within does not.

Here is a small example to illustrate this:

In [1]: import h5py, numpy as np

In [2]: A = np.arange(5)

In [3]: f = h5py.File('test.h5', 'w'); f['A'] = A; f.close()

In [4]: !md5sum test.h5
7d27c258d94ed5d06736f6d2ba7c9433  test.h5

In [5]: f = h5py.File('test.h5', 'w'); f['A'] = A; f.close()

In [6]: !md5sum test.h5
c1db5806f1393f2095c88dbb7efeb7d3  test.h5

In [7]: # the file has changed but still contains the same data!

I have looked in the HDF5 file format documents and at the h5py documentation but haven't found anything which helps me with this. My questions are:

  1. Why does the file change even though I'm saving the same data?

  2. How can I stop it changing, so version control only sees a new version of the file when the actual numerical content has changed?

Thanks


回答1:


The HDF5 file uses both an abstract data model as well as an abstract storage model. What this means is that how a file is stored on disk may be (and usually is) completely different to how it is represented in your program. It's possible to store exactly the same data in more than one way, and for this not to be apparent to your program.

The HDF5 file format storage specification allows for several timestamps in the data object headers. These are not stored as attributes, and so aren't usually accessible by the high level APIs. It's possible to turn off writing these timestamps using the low level HDF5 APIs, but it's not clear if the relevant features are in h5py. This github issue appears to be exactly what you want, but unfortunately it is still open.



来源:https://stackoverflow.com/questions/16019656/hdf5-file-h5py-with-version-control-hash-changes-on-every-save

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!