Created
November 4, 2016 10:03
-
-
Save marcocamma/6dcd088c66814452e6f7c251717c316e to your computer and use it in GitHub Desktop.
Script demonstrating the problems of figuring out if a group is a link or not with h5py
This file contains hidden or 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
| from __future__ import print_function | |
| import h5py | |
| import numpy as np | |
| import os | |
| _fname = "/tmp/links_test.h5" | |
| def write(): | |
| f=h5py.File(_fname,"w") | |
| f["/data1/v1"] = np.random.random(1000) | |
| f["/data1/v2"] = np.random.random(1000) | |
| f["/data2/v1"] = np.random.random(1000) | |
| f["/data2/v2"] = np.random.random(1000) | |
| sl = h5py.SoftLink("/data1") | |
| f["/link"] = sl | |
| print("Creating",_fname,"with:") | |
| print(" /data1/v{1,2}") | |
| print(" /data2/v{1,2}") | |
| print(" /link linking to /data1") | |
| f.close() | |
| def detectLinks(): | |
| f=h5py.File(_fname,"r") | |
| print("\nTrying to figure out upon reading what is a link to what") | |
| print("h5ls can easily figure out:") | |
| os.system("h5ls %s"%_fname) | |
| print("\n") | |
| print("*** Method 1 Trying to use 'type':") | |
| for group in f: | |
| print("Name:",group,'type is',type(f[group])) | |
| print("It does not work, type is same") | |
| print("\n") | |
| print("*** Method 2 Trying to use 'id':") | |
| for group in f: | |
| print("Name:",group,'id is',f[group].id.id) | |
| print("It does not work, id is always the same") | |
| if __name__ == "__main__": | |
| write() | |
| detectLinks() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment