where is "make_scale" in h5py?


#1

Hello,

I’m using h5py version 2.9.0 and python 3.7.4 on a Mac running Mojave.

I’m trying to futz around with creating and retrieving dimension scales and am having some difficulties. I’m following the documentation so I’m creating a main h5py.Dataset and some scales for it, calling make_scale and then attach_scale but “make_scale” is not part of the method defined for an h5py.Dataset and when I try to retrieve the scales I get back a blank dictionary.

See the following code sample:

hfile = h5py.File("…/test/Dimensions.h5", “w”)
>>> hfile.create_dataset(“data”, (10, 100), dtype=numpy.float32)
<HDF5 dataset “data”: shape (10, 100), type “<f4”>
>>> hfile.create_dataset(“xdim”, (10,), dtype=numpy.uint32)
<HDF5 dataset “xdim”: shape (10,), type “<u4”>
>>> hfile.create_dataset(“ydim”, (100,), dtype=numpy.uint32)
<HDF5 dataset “ydim”: shape (100,), type “<u4”>

>>> hfile[“xdim”].make_scale(“x”)
Traceback (most recent call last):
_ File “”, line 1, in _
AttributeError: ‘Dataset’ object has no attribute ‘make_scale’

>>> hfile[“data”].dims[0].attach_scale(hfile[“xdim”])
>>> hfile[“data”].dims[1].attach_scale(hfile[“ydim”])

>>> hfile[“data”].dims[0].keys()
[’’]
>>> hfile[“data”].dims[1].keys()
[’’]

Thank-you again for any help,

Catherine


#2

In case anyone else runs into the same problem, the answer is that make_scale was added in h5py 2.10.

# h5py 2.10 +
ds.make_scale('x')

# h5py 2.9
ds.dims.create_scale(ds, 'x')

(The question was also posted on the h5py mailing list)