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

NetCDF Doesn't Support Logical/Boolean Variables so Saving Code Parameters Fails #288

Open
torrinba opened this issue Feb 8, 2024 · 3 comments

Comments

@torrinba
Copy link
Collaborator

torrinba commented Feb 8, 2024

This problem has been around for a while and can be avoided by saving with HDF5 instead, but I'm opening this issue to document the limitation and see if anyone has ideas about whether other solutions could be possible.

NetCDF doesn't support any logical or boolean variable types so an error gets thrown when there's one in the code.parameters:

TypeError: illegal primitive data type, must be one of dict_keys(['S1', 'i1', 'u1', 'i2', 'u2', 'i4', 'u4', 'i8', 'u8', 'f4', 'f8']), got bool

It would be possible for OMAS to convert these to integers {0,1} before saving to the file, but there wouldn't be any way to know if an integer stored in NetCDF should be converted to a logical variable when read in, since code.parameters doesn't have any defined structure.

@orso82
Copy link
Member

orso82 commented Feb 8, 2024

Perhaps for those variables you could convert the booleans to integers, and then mark the conversion with an attribute (something like .setncattr('is_boolean', 'true')). Then of course, you'll have to take care of that when reading the file back into OMAS.

@smithsp
Copy link
Member

smithsp commented Feb 8, 2024

Note that in OMFIT we go through this rigamarole for exporting to netcdf - https://github.com/gafusion/OMFIT-source/blob/unstable/omfit/omfit_classes/omfit_data.py#L35 - then again when importing from netcdf - https://github.com/gafusion/OMFIT-source/blob/unstable/omfit/omfit_classes/omfit_data.py#L138 . Seems like an opportunity for generalizing the approach into a common set of utilities.

@torrinba torrinba added bug and removed wontfix labels Feb 8, 2024
Copy link

github-actions bot commented Apr 9, 2024

Stale issue message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants