-
Notifications
You must be signed in to change notification settings - Fork 39
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
More roundoff problems #78
Comments
This may seem trivial, but I'm using So in the case below, (Pdb) ds.time
<xarray.DataArray 'time' (time: 120)>
array([693150.5, 693180. , 693209.5, 693240. , 693270.5, 693301. , 693331.5,
693362.5, 693393. , 693423.5, 693454. , 693484.5, 693515.5, 693545. ,
693574.5, 693605. , 693635.5, 693666. , 693696.5, 693727.5, 693758. ,
693788.5, 693819. , 693849.5, 693880.5, 693910. , 693939.5, 693970. ,
694000.5, 694031. , 694061.5, 694092.5, 694123. , 694153.5, 694184. ,
694214.5, 694245.5, 694275. , 694304.5, 694335. , 694365.5, 694396. ,
694426.5, 694457.5, 694488. , 694518.5, 694549. , 694579.5, 694610.5,
694640. , 694669.5, 694700. , 694730.5, 694761. , 694791.5, 694822.5,
694853. , 694883.5, 694914. , 694944.5, 694975.5, 695005. , 695034.5,
695065. , 695095.5, 695126. , 695156.5, 695187.5, 695218. , 695248.5,
695279. , 695309.5, 695340.5, 695370. , 695399.5, 695430. , 695460.5,
695491. , 695521.5, 695552.5, 695583. , 695613.5, 695644. , 695674.5,
695705.5, 695735. , 695764.5, 695795. , 695825.5, 695856. , 695886.5,
695917.5, 695948. , 695978.5, 696009. , 696039.5, 696070.5, 696100. ,
696129.5, 696160. , 696190.5, 696221. , 696251.5, 696282.5, 696313. ,
696343.5, 696374. , 696404.5, 696435.5, 696465. , 696494.5, 696525. ,
696555.5, 696586. , 696616.5, 696647.5, 696678. , 696708.5, 696739. ,
696769.5])
Coordinates:
* time (time) float64 6.932e+05 6.932e+05 ... 6.967e+05 6.968e+05
Attributes:
long_name: time
units: days since 0001-01-01 00:00:00
cartesian_axis: T
calendar_type: NOLEAP
calendar: NOLEAP
bounds: time_bounds
(Pdb) ds2.time
<xarray.DataArray 'time' (time: 120)>
array([693150.5, 693180. , 693209.5, 693240. , 693270.5, 693301. , 693331.5,
693362.5, 693393. , 693423.5, 693454. , 693484.5, 693515.5, 693545. ,
693574.5, 693605. , 693635.5, 693666. , 693696.5, 693727.5, 693758. ,
693788.5, 693819. , 693849.5, 693880.5, 693910. , 693939.5, 693970. ,
694000.5, 694031. , 694061.5, 694092.5, 694123. , 694153.5, 694184. ,
694214.5, 694245.5, 694275. , 694304.5, 694335. , 694365.5, 694396. ,
694426.5, 694457.5, 694488. , 694518.5, 694549. , 694579.5, 694610.5,
694640. , 694669.5, 694700. , 694730.5, 694761. , 694791.5, 694822.5,
694853. , 694883.5, 694914. , 694944.5, 694975.5, 695005. , 695034.5,
695065. , 695095.5, 695126. , 695156.5, 695187.5, 695218. , 695248.5,
695279. , 695309.5, 695340.5, 695370. , 695399.5, 695430. , 695460.5,
695491. , 695521.5, 695552.5, 695583. , 695613.5, 695644. , 695674.5,
695705.5, 695735. , 695764.5, 695795. , 695825.5, 695856. , 695886.5,
695917.5, 695948. , 695978.5, 696009. , 696039.5, 696070.5, 696100. ,
696129.5, 696160. , 696190.5, 696221. , 696251.5, 696282.5, 696313. ,
696343.5, 696374. , 696404.5, 696435.5, 696465. , 696494.5, 696525. ,
696555.5, 696586. , 696616.5, 696647.5, 696678. , 696708.5, 696739. ,
696769.5])
Coordinates:
* time (time) float64 6.932e+05 6.932e+05 ... 6.967e+05 6.968e+05
Attributes:
long_name: time
units: days since 0001-01-01 00:00:00
cartesian_axis: T
calendar_type: NOLEAP
calendar: NOLEAP
bounds: time_bounds but (Pdb) ds2.equals(ds1)
False
(Pdb) ds.time.values - ds2.time.values
array([-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10,
-1.16415322e-10, -1.16415322e-10, -1.16415322e-10, -1.16415322e-10]) My
|
Another simple example (suitable for testing?)
|
Pull request #79 improves the precision, so now you will get 3650.0000000000007958 instead of 3650.000000000001. I don't see what I can do about those extra annoying digits - that's just the nature of floating point arithmetic. |
I was hoping there might some clever way to enforce the same precision on the number output from
the precision is microseconds. So we need less precision, not more. Or at least, specified precision. I think it is an error that this doesn't roundtrip:
Do you agree? In which case, is there a solution? |
I'm working on splitting the Julian day into an integer and a floating point remainder, which will reduce round-off error. There won't be a general solution though - there will always be cases where the round-off error prevents the roundtrip from matching. |
Thanks for the feedback. Now I can't get it to reproduce the above behaviour. In my
but not
But yesterday I am sure it was failing in all environments (the |
In this particular case the failure in the roundtrip is caused by Unidata/netcdf4-python#433. If you comment out the code in
and
you will get exactly 3650.0. However, many of the tests will then fail (for reasons described in that pull request). |
I think pull request #80 addresses this issue (at least for all the cases you presented). @aidanheerdegen, could you test this (branch |
Hi Jeff, thanks for looking into this so promptly and providing a potential solution. I won't be able to test this until Monday (Australian time), but will get back to you when I have. Cheers |
Hi Jeff, I'm having issues building the package
Some limited googling didn't come up with a quick solution. Do you have any idea of the best way to overcome this? |
Something is amiss with your build environment. Are you using 'python setup.py build' or conda? |
|
I am using a
Is this a bad combination?
|
No, that looks fine. The problem is the empty '-march', it should be '-march=platform'. Don't know where conda is getting that from then - maybe from your environment? Do you have a CPPFLAGS env var set? |
Thanks Jeff, that was the answer. My
I 've switched to another conda environment which doesn't do this, and it is compiling ok, thanks for the assistance. And yes, that does seem to behave as I would wish. Round-tripping works as do other whole number issues I had before. Thanks for the fix. Does that break anything else? |
No, all the tests are passing. I will merge the pull request now. |
replace small offset with rounding of microseconds (issue #78)
I don't know if this is related to #54 but I have noticed what I would call "unwanted precision" when interconverting between dates and numbers:
I think this could be characterised as erroneous, The return value of the last
date2num
call should be exactly 3650.The text was updated successfully, but these errors were encountered: