-
Notifications
You must be signed in to change notification settings - Fork 14
/
test_sfd.py
64 lines (55 loc) · 2.32 KB
/
test_sfd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pathlib
import numpy
from numpy.random import default_rng
rng = default_rng()
def test_distance_independent():
# 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.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)[0] for glon, glat in zip(glons, glats)]
< 10.0**-7.0
), f"SFD extinction without interpolation does not agree with known values, with max difference {numpy.amax(numpy.fabs(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()
# 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)[0] for glon, glat in zip(glons, glats)]
< 10.0**-7.0
), f"SFD extinction does not agree with known values, with max difference {numpy.amax(numpy.fabs(ebvs-numpy.array([sfd(glon,glat,1.)[0] for glon,glat in zip(glons,glats)])))}"
return None