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

small range on netcdf floats? #701

Closed
rgknox opened this issue Apr 29, 2019 · 4 comments
Closed

small range on netcdf floats? #701

rgknox opened this issue Apr 29, 2019 · 4 comments

Comments

@rgknox
Copy link
Collaborator

rgknox commented Apr 29, 2019

I've noticed that the CTSM parameter files have changed over to using double precision as a default for storing floating point numbers. In FATES we are still using "float" or single precision floating point variables, and I noticed an unexpected problem.

*Note that in fates, our parameter interface only allows for floating point values (double and single prec.)

We have a field called fates_logging_event_code, a scalar float. This should be able to hold a date in the form YYYYMMDD (maximum of 8 digits). I was running a test (on both cheyenne and my work-station), converting from text (cdl) to binary (nc), and then dumping the result (e.g. ncgen and then ncdump immediately afterwards. The number 20030101 was returning as 20030100. I tried more numbers, 20030102, 20030103 ... About half of them came back as the correct number, the others were 1 digit off. Seems like a rounding issue of some kind..

The simple solution was to just re-define fates_logging_event_code as a double precision variable. But I was mystified as to why the float was having trouble holding and converting this value. It should be large enough to accommodate 8 digits of precision.

I was curious if anyone else has seen this type of strange behavior. Its also a warning to others that the actual valid range of unsigned "floats" in netcdf might not actually be what they think (at least without having a good grasp of how to specify/convert their variables, like me).

https://www.unidata.ucar.edu/software/netcdf/netcdf/CDL-Data-Types.html

@ekluzek
Copy link
Collaborator

ekluzek commented Apr 30, 2019

@rgknox, this seems about right to me. Rounding for single precision is about 1.e-8 and that's the level you are at. You can represent individual numbers to a higher degree of precision, but at about a relative error of 1.e-8 you'll start to see it rounding. So I would say this is happening as expected. But, yes the solution is to use double precision (or for these specific numbers you could represent them as integer).

@ekluzek
Copy link
Collaborator

ekluzek commented Apr 30, 2019

Here's more information on machine epsilon than you likely want to know...

https://en.wikipedia.org/wiki/Machine_epsilon

@rgknox
Copy link
Collaborator Author

rgknox commented Apr 30, 2019

Thanks for the info @ekluzek, feel free to close if you like

@billsacks
Copy link
Member

This seems resolved, so closing.

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

No branches or pull requests

3 participants