Note
Go to the end to download the full example code
Save data to HDF5ΒΆ
Save nddata to standard HDF5 format.
WARNING!!, attributes ['other_info'] are dictionaries!
WARNING!!, attributes ['dimlabels'] are lists!
You didn't set units for b before saving the data!!!
Units set for the a axis are: s
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
+/-None
dimlabels=['a', 'b']
axes={`a':array([0, 1, 2])
+/-None,
`b':array([1, 2, 3])
+/-None}
from pyspecdata import nddata, nddata_hdf5
from numpy import r_
import os
a = nddata(r_[0:9], [3, 3], ["a", "b"]).labels(
dict(
a=r_[0:3],
b=r_[1:4],
)
)
a.name("test_data")
a.set_units("a", "s").set_units("W")
a.hdf5_write("test.h5")
a_reload = nddata_hdf5("test.h5/test_data")
print("Units set for the a axis are:", a_reload.get_units("a"))
assert (a.data == a_reload.data).all()
assert (a.getaxis("a") == a_reload.getaxis("a")).all()
assert (a.getaxis("b") == a_reload.getaxis("b")).all()
assert a.get_units("a") == "s"
assert a.get_units() == "W"
print(a_reload)
os.remove("test.h5")
Total running time of the script: (0 minutes 0.052 seconds)