|
From: | Felix Höfling |
Subject: | Re: [h5md-user] Unit attribute versus non-dimensionless quantities |
Date: | Thu, 01 Aug 2013 09:56:57 +0200 |
User-agent: | Opera Mail/12.15 (Linux) |
Hi all, I have discovered the perfect implementation of units in H5MD :-). Please marvel at the output of the attached example: HDF5 "h5md_units.h5" { GROUP "/" { ATTRIBUTE "data" { DATATYPE "/units/acceleration" DATASPACE SCALAR DATA { (0): 9.81 } } GROUP "units" { DATATYPE "acceleration" H5T_IEEE_F64LE; ATTRIBUTE "unit" { DATATYPE H5T_STRING { STRSIZE H5T_VARIABLE; STRPAD H5T_STR_NULLTERM; CSET H5T_CSET_UTF8; CTYPE H5T_C_S1; } DATASPACE SCALAR DATA { (0): "meter per square second" } } } } } I will prepare a complete H5MD units proposal for your consideration. Peter
Hi Peter,Thanks for working out the example. It is an interesting solution, and I consider it superior over the compound type way.
I played a bit with h5py, which seems to ignore user-defined types unfortunately. The type is immediately converted to a NumPy type, and it is not possible (for me) to retrieve the actual HDF5 type of the attribute (and the 'unit' attribute of this type):
import h5py f = h5py.File('h5md_units.h5') t = f['units/acceleration'] print f.attrs['data'].dtype f.create_dataset('dataset', dtype=t, data=(1,2)) print type(f['dataset']) print f['dataset'].dtype f.close() The output is: float64 <class 'h5py._hl.dataset.Dataset'> float64 And the new dataset is shown by h5dump as: DATASET "dataset" { DATATYPE H5T_IEEE_F64LE DATASPACE SIMPLE { ( 2 ) / ( 2 ) } DATA { (0): 1, 2 } }Maybe there is still a trick with h5py. But a solution that works only with low-level APIs would not be practical either :-(
Cheers, Felix
[Prev in Thread] | Current Thread | [Next in Thread] |