-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite.py
More file actions
52 lines (40 loc) · 1.13 KB
/
Copy pathwrite.py
File metadata and controls
52 lines (40 loc) · 1.13 KB
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
import hdf5plugin
import h5py
import numpy as np
def string_dt(s):
tid = h5py.h5t.C_S1.copy()
tid.set_size(len(s))
return h5py.Datatype(tid)
def create_string_attr(obj, key, value):
# Albula requires null terminated strings
if value[-1] != "\x00":
value += "\x00"
obj.attrs.create(key, value, dtype=string_dt(value))
filename = "test.h5"
mode = "w"
image_size = (512,1024)
dtype = np.float32
#Current frame and also number of frames in dataset
frame_index = 0
#Create a new file and dataset
f = h5py.File(filename, mode)
compression = hdf5plugin.Bitshuffle(nelems=0, cname='lz4')
nxentry = f.create_group("entry")
create_string_attr(nxentry, "NX_class", "NXentry")
nxdata = nxentry.create_group("data")
create_string_attr(nxdata, "NX_class", "NXdata")
ds = nxdata.create_dataset(
"data_000001",
shape=(0, *image_size),
dtype=dtype,
maxshape=(None, *image_size),
chunks=(1, *image_size),
**compression,
)
#Extend the dataset and write some data
image = np.zeros(image_size, dtype=dtype)
ds.resize(frame_index + 1, axis=0)
ds[frame_index] = image
frame_index += 1
print(ds.shape)
f.close()