File: h5_regref.py

package info (click to toggle)
hdf5 1.14.5%2Brepack-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 208,864 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 (52 lines) | stat: -rw-r--r-- 1,211 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
# This example shows how to create a dataset with region references.
#
import h5py
import numpy as np
#
# Create a new file using default properties.
#
file = h5py.File('regref.h5','w')
#
# Create a group and (3x2) dataset under the Root group.
#
dataset = file.create_dataset("DS2",(3,2), h5py.h5t.STD_I8LE)
dataset[...] = np.array([[1,1], [2,2], [3,3]])
#
# Create references to each row in the dataset.
#
refs = (dataset.regionref[0,:],dataset.regionref[1,:],dataset.regionref[2,:])
#
# Create a dataset to store region references.
#
ref_type = h5py.h5t.special_dtype(ref=h5py.RegionReference)
dataset_ref = file.create_dataset("DS1", (3,),ref_type)
dataset_ref[...] = refs
#
# Close the file before exiting.
#
file.close()
#
# Open the file, read the second element of the dataset with the region references
# and dereference it to get data.
#
file = h5py.File('regref.h5', 'r')
dataset = file["DS1"]
regref = dataset[1]
#
# Region reference can be used to find a dataset it points to.
#
dataset_name = file[regref].name
print(dataset_name)
#
# Get hyperslab the reference points to.
#
data = file[dataset_name]
#
# Region reference can be used as a slicing argument!
print(data[regref])
file.close()