Created
August 16, 2022 14:26
-
-
Save rmnldwg/aaf6f2cd0f1d5da0b29bf4e920eed375 to your computer and use it in GitHub Desktop.
Python script to create an HDF5 file with attributes that cannot be displayed by the H5Web VS code extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Python script to reproduce an HDF5 file which has attributes that won't be displayed | |
in the VS code extension "H5Web". | |
""" | |
import numpy as np | |
import h5py | |
if __name__ == "__main__": | |
# create some random data, doesn't really matter | |
some_data = np.random.uniform(size=(10,20,30)) | |
# create some metadata for the data, this includes a normal integer | |
metadata = { | |
"info": "randomly generated data", | |
"author": "rmnldwg", | |
"float": np.pi, | |
"int": 42, | |
} | |
# create the HDF5 file | |
with h5py.File("./h5web_bug.hdf5", mode="w") as h5file: | |
h5dataset = h5file.create_dataset( | |
name="meaningless", | |
data=some_data, | |
) | |
for key,value in metadata.items(): | |
try: | |
h5dataset.attrs[key] = value | |
except TypeError: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment