h5md-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [h5md-user] Unit attribute versus non-dimensionless quantities


From: Felix Höfling
Subject: Re: [h5md-user] Unit attribute versus non-dimensionless quantities
Date: Thu, 01 Aug 2013 10:12:38 +0200
User-agent: Opera Mail/12.15 (Linux)

Am 01.08.2013, 09:56 Uhr, schrieb Felix Höfling <address@hidden>:

Am 31.07.2013, 22:40 Uhr, schrieb Peter Colberg <address@hidden>:

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


h5py has also a low-level API, of course. But I think it is not interchangeable with the high-level one and one would have to stick to it everywhere. I was not even able to open a file with h5py.h5f.open() ...

My conclusion so far is that custom datatypes are something for experienced users, but are not suited to become part of the H5MD specification.

Felix



reply via email to

[Prev in Thread] Current Thread [Next in Thread]