-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathgenerate_attributes.py
43 lines (34 loc) · 1.16 KB
/
generate_attributes.py
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
#!/usr/bin/env python3
"""
write attributes to ensure h5fortran can read
"""
import argparse
from pathlib import Path
import numpy as np
import h5py
p = argparse.ArgumentParser(description="write test attributes in HDF5")
p.add_argument("file", help="HDF5 file to write")
P = p.parse_args()
fn = Path(P.file).expanduser()
with h5py.File(fn, "w") as f:
v = f.create_dataset("/empty", dtype=float)
v.attrs["real32-scalar"] = np.float32(3.0)
v.attrs["real64-scalar"] = np.float64(3.0)
v.attrs["real16-scalar"] = np.float16(3.0)
v.attrs["variable_str"] = "Hi there"
v.attrs["variable_str1"] = ["eight", "nine"]
v.attrs["variable_str2"] = [
["eight", "nine", "ten"],
["eleven", "twelve", "thirteen"],
]
v.attrs.create("nullpad", dtype=h5py.string_dtype("utf-8", 40), data="Hello World!")
v.attrs.create(
"nullpad1", dtype=h5py.string_dtype("utf-8", 20), data=["two", "three", "four"]
)
v.attrs.create(
"nullpad2",
dtype=h5py.string_dtype("utf-8", 20),
data=[["eight", "nine", "ten"], ["eleven", "twelve", "thirteen"]],
)
v.attrs["smiley"] = "😀"
v.attrs["wink"] = "😉"