我试图增加我的HDF5文件的缓存大小,但似乎不起作用。 这就是我所拥有的:
import h5py
with h5py.File("test.h5", 'w') as fid:
# cache settings of file
cacheSettings = list(fid.id.get_access_plist().get_cache())
print cacheSettings
# increase cache
cacheSettings[2] = int(5 * cacheSettings[2])
print cacheSettings
# read cache settings from file
fid.id.get_access_plist().set_cache(*cacheSettings)
print fid.id.get_access_plist().get_cache()
输出如下:
^{pr2}$你知道为什么读书有用,但是环境不行吗?
关闭和重新打开文件似乎也没有帮助。在
从h5py版本2.9.0开始,这种行为现在可以直接通过主},这些参数被记录为here。OP试图调整
h5py.File
接口获得。有三个参数控制“原始数据块缓存”rdcc_nbytes
、rdcc_w0
、和{rdcc_nbytes
设置,现在可以简单地按照唯一的区别是,你必须知道你实际需要多少空间,而不是仅仅按操作需要乘以5。当前默认值与找到的OP相同。当然,如果你真的想用编程的方式来实现,你只需打开它一次,获取缓存,关闭它,然后用所需的参数重新打开。在
如果您使用的是h5py版本2.9.0或更新版本,请参见Mike's answer。在
根据the docs,
get_access_plist()
返回文件访问属性列表的副本。因此,修改副本不会影响原始文件也就不足为奇了。在高级接口似乎没有提供更改缓存设置的方法。在
下面是如何使用低级接口来实现这一点。在
上面创建了一个PropFAID。然后我们可以打开该文件并通过以下方式获得FileID:
^{pr2}$我们可以使用
fid
通过向h5py.File
传递fid
来打开具有高级接口的文件:因此,您仍然可以使用高级接口,但它需要一些 费尽心思去那里。另一方面,如果你把它提炼成最基本的东西,也许也没那么糟糕:
h5py-cache项目可能会有帮助,尽管我没有使用它:
相关问题 更多 >
编程相关推荐