nasa / radbelt

radbelt: An Astropy-friendly wrapper for the AE-8/AP-8 Van Allen belt model
Other
28 stars 9 forks source link

Inconsistent results? #55

Closed kokroo closed 10 months ago

kokroo commented 10 months ago
>>> from radbelt import get_flux
>>> from astropy import units as u
>>> from astropy.coordinates import EarthLocation
>>> from astropy.time import Time
>>> coords = EarthLocation(-45 * u.deg, -30 * u.deg, 500 * u.km)
>>> time = Time('2021-03-01')
>>> energy = 20 * u.MeV
>>> get_flux(coords, time, energy, 'p', 'max')  # doctest: +FLOAT_CMP
<Quantity 2642.50268555 1 / (s cm2)>

I ran this code on Ubuntu and I get a different result. Is that expected?

I got "2642.502685546875 1 / (s cm2)" instead of "2642.50268555 1 / (s cm2)"

I am currently creating a test suite to compare the results of the current version of the repo vs my repo where I am converting the Fortran bits to C.

I thought I should start by running the example code and now I am lost without a good reference point.

lpsinger commented 10 months ago

It's a floating point calculation, so it is bound to vary slightly between operating systems, compilers, and microarchitectures.

kokroo commented 10 months ago

Thanks for your answer. You're right, turns out a lot of the libraries used in the background are actually using processor intrinsics and all of those implementations differ. I'll try to make my tests accept differences of up to 1-2 ULP.