Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: NeXus parser (nomad) getting error while reading unit degree from pint units #395

Open
RubelMozumder opened this issue Jul 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@RubelMozumder
Copy link
Collaborator

Contact Details

[email protected]

What happened?

Error massage:

ERROR    nomad.processing     2024-07-29T09:46:26 could not normalize section
  - exception: Traceback (most recent call last):
      File "/home/rubel/NOMAD-FAIRmat/GH/pynxtools/src/pynxtools/dataconverter/writer.py", line 324, in _put_data_into_hdf5
        add_units_key(self.output_nexus[path_hdf5], path)
      File "/home/rubel/NOMAD-FAIRmat/GH/pynxtools/src/pynxtools/dataconverter/writer.py", line 264, in add_units_key
        dataset.attrs["units"] = self.data[units_key]
      File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
      File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
      File "/home/rubel/NOMAD-FAIRmat/GH/nomad-measurements/.PE9/lib/python3.9/site-packages/h5py/_hl/attrs.py", line 104, in __setitem__
        self.create(name, data=value)
      File "/home/rubel/NOMAD-FAIRmat/GH/nomad-measurements/.PE9/lib/python3.9/site-packages/h5py/_hl/attrs.py", line 182, in create
        htype = h5t.py_create(original_dtype, logical=True)
      File "h5py/h5t.pyx", line 1663, in h5py.h5t.py_create
      File "h5py/h5t.pyx", line 1687, in h5py.h5t.py_create
      File "h5py/h5t.pyx", line 1747, in h5py.h5t.py_create
    TypeError: Object dtype dtype('O') has no native HDF5 equivalent
    ```
    
To write a dataset in a hdf5 file and using `degree` as a unit for a quantity in dataset, the error can be reproduced.

Probably, the error is coming from hdf5 lib, as `pint` lib returns a degree symbol `o` instead of string and hdf5 lib unable to decode or unable detect common data type.

### Relevant log output

_No response_
@RubelMozumder RubelMozumder added the bug Something isn't working label Jul 29, 2024
@mkuehbach
Copy link
Collaborator

mkuehbach commented Aug 21, 2024

The proper usage of pint and h5py for °C is like this:
e.g.

import pint
from pint import UnitRegistry
ureg = UnitRegistry()
# assume above lines have been called somewhere else then you can do
T = ureg.Quantity(20.0, ureg.degC)
print(T.units)

T itself is an object, if you want to write the unit via h5py and say pynxtools'

template["/ENTRY[entry]/.../temperature/@units"] = T.units

Do these hints help @RubelMozumder ?

This way pint will also take care of the fact that temperatures are not multiplicative quantities:
https://pint.readthedocs.io/en/0.10.1/nonmult.html

Suggestions:

  • Check pynxtools-side writing code
  • Check where ureg is hooked in NOMAD
  • Check which string will then be written to HDF
  • Check how this is consumed by the HDF5 reader when a quantity is getting instantiated in NOMAD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants