Skip to content

Commit

Permalink
Check how bad errors are
Browse files Browse the repository at this point in the history
  • Loading branch information
jobovy committed Apr 24, 2024
1 parent 362ea2f commit bf62498
Showing 1 changed file with 44 additions and 27 deletions.
71 changes: 44 additions & 27 deletions tests/test_sfd.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,64 @@
import pathlib
import numpy
from numpy.random import default_rng
rng= default_rng()

rng = default_rng()


def test_distance_independent():
# Test that the SFD extinction is indepdendent of distance
# Test that the SFD extinction is indepdendent of distance
# for a given line of sight.
from mwdust import SFD
sfd= SFD()
glons= rng.uniform(0.,360.,size=20)
glats= rng.uniform(-90.,90.,size=20)
dists= rng.uniform(0.1,10.,size=5)
ebvs= numpy.array([[sfd(glons[ii],glats[ii],dists[jj]) \
for ii in range(len(glons))]
for jj in range(len(dists))]).T
assert numpy.all(numpy.fabs(ebvs-ebvs[0]) < 10.**-10.), \
'SFD extinction is not independent of distance for a given line of sight'

sfd = SFD()
glons = rng.uniform(0.0, 360.0, size=20)
glats = rng.uniform(-90.0, 90.0, size=20)
dists = rng.uniform(0.1, 10.0, size=5)
ebvs = numpy.array(
[
[sfd(glons[ii], glats[ii], dists[jj]) for ii in range(len(glons))]
for jj in range(len(dists))
]
).T
assert numpy.all(
numpy.fabs(ebvs - ebvs[0]) < 10.0**-10.0
), "SFD extinction is not independent of distance for a given line of sight"
return None


def test_against_known_values():
# Test that the SFD extinction without interpolation agrees with a table of known values
# These were computed using mwdust on an M1 mac, so this test is really
# of consistency between other OSs and architectures
from mwdust import SFD
sfd= SFD(interp=False)
known= numpy.loadtxt(pathlib.Path(__file__).parent / 'sfd_benchmark.dat',delimiter=',')
glons= known.T[0]
glats= known.T[1]
ebvs= known.T[2]
assert numpy.all(ebvs-[sfd(glon,glat,1.)[0]
for glon,glat in zip(glons,glats)] < 10.**-8.), \
'SFD extinction without interpolation does not agree with known values'

sfd = SFD(interp=False)
known = numpy.loadtxt(
pathlib.Path(__file__).parent / "sfd_benchmark.dat", delimiter=","
)
glons = known.T[0]
glats = known.T[1]
ebvs = known.T[2]
assert numpy.all(
ebvs - [sfd(glon, glat, 1.0)[0] for glon, glat in zip(glons, glats)]
< 10.0**-8.0
), f"SFD extinction without interpolation does not agree with known values, with differences {ebvs-numpy.array([sfd(glon,glat,1.)[0] for glon,glat in zip(glons,glats)])}"

# Test that the SFD extinction with interpolation agrees with a table of known values
# These were computed using mwdust on a linux server, same cavert above
from mwdust import SFD
sfd= SFD()

sfd = SFD()
# specifically contains lb = (30, 3), a previously known inconsistency between Linux and Windows
known= numpy.loadtxt(pathlib.Path(__file__).parent / 'sfd_mwdust12_linux_benchmark.dat',delimiter=',')
glons= known.T[0]
glats= known.T[1]
ebvs= known.T[2]
assert numpy.all(ebvs-[sfd(glon,glat,1.)[0]
for glon,glat in zip(glons,glats)] < 10.**-8.), \
'SFD extinction does not agree with known values'
known = numpy.loadtxt(
pathlib.Path(__file__).parent / "sfd_mwdust12_linux_benchmark.dat",
delimiter=",",
)
glons = known.T[0]
glats = known.T[1]
ebvs = known.T[2]
assert numpy.all(
ebvs - [sfd(glon, glat, 1.0)[0] for glon, glat in zip(glons, glats)]
< 10.0**-8.0
), f"SFD extinction does not agree with known values, with differences {ebvs-numpy.array([sfd(glon,glat,1.)[0] for glon,glat in zip(glons,glats)])}"
return None

0 comments on commit bf62498

Please sign in to comment.