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]: Validation error when passing a "0" integer #393

Closed
rettigl opened this issue Jul 28, 2024 · 2 comments
Closed

[Bug]: Validation error when passing a "0" integer #393

rettigl opened this issue Jul 28, 2024 · 2 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers validation

Comments

@rettigl
Copy link
Collaborator

rettigl commented Jul 28, 2024

Contact Details

[email protected]

What happened?

When a field with type "NX_FLOAT" gets filled by a "0" integer (rather than "0.0" float), the checking routine reports this key as undocumented. Specifically, the value is converted to float here:

return accepted_types[0](value)

This returns 0, which in turn makes this check fail:
if is_documented(not_visited_key, tree):

and hence the value ends up in undocumented.
This is tested on the multi-format-reader, but should apply to main as well.

Relevant log output

This is output from the Tutorial 3 of the sed package, which uses the mpes reader and pynxtools converter internally:

Input:
sp.binned.attrs["metadata"]["energy_calibration"]["tof"] = 0
sp.save(data_path + "/binned.nxs")

Output:
Using mpes reader to convert the given files:  
• ../sed/config/NXmpes_config.json
Field /ENTRY[entry]/PROCESS_MPES[process]/energy_calibration/original_axis written without documentation.
The output file generated: /mnt/pcshare/users/Laurenz/AreaB/sed/sed/tutorial/datasets/WSe2/binned.nxs.

Input: 
sp.binned.attrs["metadata"]["energy_calibration"]["tof"] = 0.0
sp.save(data_path + "/binned.nxs")

Output:
Using mpes reader to convert the given files:  
• ../sed/config/NXmpes_config.json
The output file generated: /mnt/pcshare/users/Laurenz/AreaB/sed/sed/tutorial/datasets/WSe2/binned.nxs.
@rettigl rettigl added the bug Something isn't working label Jul 28, 2024
@lukaspie lukaspie added the good first issue Good for newcomers label Sep 13, 2024
@GinzburgLev GinzburgLev self-assigned this Jan 14, 2025
@GinzburgLev
Copy link
Contributor

It seems that there are potentially two issue here, which are somewhat separated:

  1. if the schema has a field with one type (such as NX_FLOAT) and the .h5 has the same field but filled with 0 in a different format (for example, NX_INT), the conversion function (pynxtools/src/pynxtools/dataconverter/helpers.py/is_valid_data_field) returns 0 (which is supposed to mean the result of conversion), but it is later interpreted as 0==False (convertion is impossible). This is easy to fix by changing function such that it has two outputs: boolean (valid field?) and any (result of conversion).

  2. However, for whatever reason the value written in the field is not the converted value but the original one (so, in the example above we still get int(0) written in the field which is supposed to be NX_FLOAT). Do we want to change that? If yes, I can not find where exactly the assignment is happening, but I believe we just need to change value -> is_valid_data_field(value, nxdl_type, ...)[1] there.

@lukaspie
Copy link
Collaborator

Second part to be discussed in #523

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

No branches or pull requests

3 participants