File: h5_objref.py

package info (click to toggle)
hdf5 1.14.5%2Brepack-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 208,856 kB
  • sloc: ansic: 715,772; f90: 42,941; java: 38,102; sh: 30,925; xml: 18,706; cpp: 18,011; makefile: 2,423; perl: 2,383; yacc: 332; python: 262; javascript: 203; lex: 157; ruby: 24; csh: 22
file content (37 lines) | stat: -rw-r--r-- 860 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#
# This example shows how to create dataset with object references
#
import h5py
import numpy as np
#
# Create a new file using default properties.
#
file = h5py.File('objref.h5','w')
#
# Create a group and scalar datasets under the Root group.
#
group = file.create_group("G1")
dataset = file.create_dataset("DS2",(), 'i')
#
# Create references to the group and the dataset and store them in another dataset.
#
refs = (group.ref, dataset.ref)
ref_type = h5py.h5t.special_dtype(ref=h5py.Reference)
dataset_ref = file.create_dataset("DS1", (2,),ref_type)
dataset_ref[...] = refs

#
# Close the file before exiting
#
file.close()

file = h5py.File('objref.h5','r')
dataset_ref = file["DS1"]
refs = dataset_ref[...]
refs_list = list(refs)
for obj in refs_list:
    index = refs_list.index(obj)
    print("DS["+str(index)+"]:")
    print(file[obj])
file.close()