简体   繁体   English

如何在h5py中为HDF5数据集指定比例(或物理尺寸)?

[英]How do I assign scales (or physical dimensions) to HDF5 datasets in h5py?

I am trying to export scientific data via h5py into an HDF5 container format to be read by other software. 我试图通过h5py将科学数据导出为HDF5容器格式,以供其他软件读取。

I have a 7-dimensional numpy array for which I create a dataset via h5py.File.create_dataset(). 我有一个7维numpy数组,我通过h5py.File.create_dataset()创建了一个数据集。 This works fine. 这很好用。

However, I cannot find any way to assign any physical scale (say meters, kg, angle, …) to these 7 dimensions in h5py. 但是,我找不到任何方法来为h5py中的这7个维度分配任何物理比例(比如米,公斤,角度......)。 I could not find any documentation on how to do this. 我找不到任何关于如何做到这一点的文档。

This is possible according to the HDF5 reference . 根据HDF5参考,这是可能的。

Is this implemented in h5py? 这是在h5py中实现的吗? I know that it is possible with HDF5. 我知道HDF5可以实现。

Thanks for your help! 谢谢你的帮助!

Dimension scales in HDF5 are simply another dataset that is associated with your first dataset. HDF5中的维度比例只是与您的第一个数据集关联的另一个数据集。 They can be used to define spatial coordinates, for example. 例如,它们可用于定义空间坐标。 If you want to indicate that a particular dimension has certain physical units you can label the dimension, which is done using the HDF5 dimension scale API: H5DSset_label() . 如果要指示特定维度具有某些物理单位,则可以标记维度,这是使用HDF5维度比例API: H5DSset_label()

Dimension scales are possible in h5py, using h5py.dims.create_scale() and h5py.dims.attach_scale() , and h5py.dims.label to set the label. 维度量表在h5py是可能的,使用h5py.dims.create_scale()h5py.dims.attach_scale()h5py.dims.label设置标签。

For example, to indicate that the first dimension of foo.dat:/data is in kg and the second in metres, you can set its label as follows (with f being the HDF5 file): 例如,要指示foo.dat:/data的第一个维度是kg,而第二个维度是米,您可以设置其标签如下( f为HDF5文件):

f['data'].dims[0].label = 'kg'
f['data'].dims[1].label = 'm'

To add a dataset as a height scale to the second dimension, you first need to create a scale, then attach the dataset: 要将数据集作为高度比例添加到第二维,首先需要创建比例,然后附加数据集:

f['data'].dims.create_scale(f['h'], 'height')
f['data'].dims[1].attach_scale(f['h'])

You can then access the labels with 然后,您可以使用访问标签

[dim.label for dim in f['data'].dims]

and the dimension scales themselves with 并且维度可以自我缩放

f['data'].dims[1][0]

or 要么

f['data'].dims[1]['height']

您可能想要一个属性:

http://code.google.com/p/h5py/wiki/HowTo#Reading_and_writing_attributes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM