-
Notifications
You must be signed in to change notification settings - Fork 35
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
Error that doesn't cause failure when producing mrsos for Lmon #495
Comments
I think we should either allow the value and not generate an error message, or error exit and genera te the message. It doesn't seem to me that this would be too difficult in theory. When it finds the error, why don't we throw an error? (i.e., I don't think we should allow it) Does the problem have to do with a conversion from single to double precision? |
Agreed :)
It's a float representation issue:
The line I linked to in my first comment performs a |
It seems to me that valid_max and valid_min when applied to (or compared with) an "axis" value should be declared as "double precision", but it appears they have been declared single precision (with a value of +- 1.e20). I don't know c syntax, but in fortran that's a single precision float. If I'm right, this should be the first thing we correct. In your code segment above (#495 (comment)), there must be a way to generate a 32 bit float with the value of 0.1000000000000000. Do you know how to do that? Also, can we get the error message given in #495 (comment) to output the full precision of the value and the value_max? |
The valid_max and valid_min values are stored as doubles. Lines 326 to 327 in 5f1844b
The code is currently converting the axis values to double-precision floats before doing the min/max comparisons. Lines 1831 to 1851 in 5f1844b
Maybe we should have separate functions for processing each datatype before converting the values to double. |
So If the axis values are passed to CMOR as double, then no conversion is done. Right? Maybe we should warn the user that they have passed an incorrect data type. All coordinate axes are supposed to be double precision. Other ideas? |
There is some code that is converting doubles to doubles, which is redundant and should be removed. We could add a warning about the expected data type and the conversion to be performed if other data types are passed. |
I agree; converting double to double is unnecessary. Also agree that whenever a data type is passed that is different from the type output to the netCDF file, we should warn users. This should probably apply to attributes, variables, and axis values. This might require a number of changes to the coding in various places. How much work would it be? If differences in data type are encountered, the error messages could read something like
I think we should consider making this a fatal error, rather than a warning. What do you think? |
It's not possible, this is just how floats are represented (see https://floating-point-gui.de/basic/ for more details). |
Yes, my mistake. I meant to say "there must be a way to generate a 64 bit float with the value of 0.100000000000000. Do you know how to do that?" |
@taylor13 @ehogan @mauzey1 here's the output from python at least
@ehogan be a little careful with the |
@taylor13, this is a generic computer issue rather than a language-specific issue (I was using Python for demonstration purposes only). @durack1, if you want to show the full float representation, string formatting should be used:
|
@ehogan, I agree this is a generic computer issue. I think, however, it is odd that the default for a print statement is to display more digits than can be precisely represented in binary. For float32, I would prefer to see only 7 or so digits be displayed, since anything beyond that is beyond the precision that can be accurately represented. Similarly 16 or so digits would seem to be appropriate, as a default, for float64 numbers. But all that is somewhat beside the point. The question is why does CMOR raise an error when comparing two floats that are near 0.1. Is it possible that valid_max has been assigned originally as a single precision variable (with the nominal value 0.1) and then converted to double precision, whereas sdepth1 is defined all along to be double precision (again with nominal value 0.1)? If so, then we can't expect sdepth1 to be precisely the same as valid_max. This could explain the error. To work around this we should add epsilon x valid_max to valid_max before comparing (and subtract epsilon x valid_min from valid_min before comparing), where epsilon might be 1.e-6 (near the fractional precision limit of float32.) Do you think that would be o.k.? |
@taylor13
|
Yes, this makes sense. All coordinate values should be originally defined by the user as float64, but some users will define these as float32. So for float32 coordinate values passed by users to be acceptable, we will have to allow for truncation errors. I think an epsilon of 1.e-6 for fractional error should allow float32's and probably not make a practical difference. We might consider resetting the coordinate value to the actually valid_max (in float64) if it falls within epsilon of valid_max. @ehogan, what do you think of this idea? |
Thanks @taylor13; a few things:
|
O.K. let's just relax the strictness of the test and let data through that is within epsilon*valid_max (or valid_min) of the limit. Any objections? @ehogan Thanks for identifying this problem and helping to find a solution. |
@mauzey1 Is this still on the "to do" list? |
Yes, that's fine with me. Let's give @ehogan until next week to respond, and if we don't hear from her otherwise, close it then. |
I'm using CMOR 3.4.0 to produce
mrsos
forLmon
. The output netCDF file is produced successfully, yet the CMOR log contains:The bounds I'm providing for
sdepth1
are[0, 0.100000001490116]
(this is what is written to the output netCDF file). Should cmor_treat_axis_values accept that0.100000001490116
is close enough to0.1
by performing an appropriate float comparison instead of producing this error (that doesn't cause CMOR to fail anyway)?The text was updated successfully, but these errors were encountered: