|
1
|
|
|
|
|
2
|
|
|
import os |
|
3
|
|
|
|
|
4
|
|
|
import numpy as np |
|
5
|
|
|
from click.testing import CliRunner |
|
6
|
|
|
from numpy.random import rand |
|
7
|
|
|
from numpy.random import randint |
|
8
|
|
|
|
|
9
|
|
|
from ne2001 import density |
|
10
|
|
|
from ne2001.cli import main |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
def test_main(): |
|
14
|
|
|
runner = CliRunner() |
|
15
|
|
|
result = runner.invoke(main, []) |
|
16
|
|
|
|
|
17
|
|
|
assert result.output == '()\n' |
|
18
|
|
|
assert result.exit_code == 0 |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
def test_density(): |
|
22
|
|
|
xyz = (1-2*rand(3, 100)) * 20 |
|
23
|
|
|
|
|
24
|
|
|
ne_disk1 = density.ne_thick_disk(xyz, 0.03, 17.5, 0.97, 8.5) |
|
25
|
|
|
assert len(ne_disk1) == 100 |
|
26
|
|
|
assert all(ne_disk1 >= 0) |
|
27
|
|
|
|
|
28
|
|
|
ne_disk2 = density.ne_thin_disk(xyz, 0.08, 3.8, 0.15) |
|
29
|
|
|
assert len(ne_disk2) == 100 |
|
30
|
|
|
assert all(ne_disk2 >= 0) |
|
31
|
|
|
|
|
32
|
|
|
ne_gc = density.ne_gc(xyz, 10., 0.145, 0.026, |
|
33
|
|
|
np.array([-0.01, 0.0, -0.029])) |
|
34
|
|
|
assert len(ne_gc) == 100 |
|
35
|
|
|
assert all(ne_gc >= 0) |
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
def test_geometry(): |
|
39
|
|
|
abc = rand(3)*20 |
|
40
|
|
|
xyz = (1-2*rand(3, 100)) * 20 |
|
41
|
|
|
theta = rand()*2*np.pi |
|
42
|
|
|
xyz_center = rand(3)*20 |
|
43
|
|
|
assert density.in_ellisoid(xyz_center, xyz_center, abc, theta) |
|
44
|
|
|
assert len(density.in_ellisoid(xyz, xyz_center, abc, theta)) == 100 |
|
45
|
|
|
|
|
46
|
|
|
abc = rand(3)*20 |
|
47
|
|
|
xyz = (1-2*rand(3, 100)) * 20 |
|
48
|
|
|
theta = rand()*2*np.pi |
|
49
|
|
|
xyz_center = rand(3)*20 |
|
50
|
|
|
assert len(density.in_cylinder(xyz, xyz_center, abc, theta)) == 100 |
|
51
|
|
|
|
|
52
|
|
|
assert all(density.in_half_sphere(xyz, xyz_center, 10)[xyz[-1] < 0] == 0) |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
View Code Duplication |
def test_clumps(): |
|
|
|
|
|
|
56
|
|
|
clumps_file = os.path.join(os.path.split(density.__file__)[0], "data", |
|
57
|
|
|
"neclumpN.NE2001.dat") |
|
58
|
|
|
|
|
59
|
|
|
clumps = density.Clumps(clumps_file) |
|
60
|
|
|
|
|
61
|
|
|
clumps = density.Clumps() |
|
62
|
|
|
xyz = (clumps.xyz.T[randint(0, clumps.gl.size, 100)].T + |
|
63
|
|
|
(1-2*rand(3, 100))*0.01) |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
ne_clumps = clumps.ne_clumps(xyz) |
|
67
|
|
|
assert len(ne_clumps) == 100 |
|
68
|
|
|
ix = ne_clumps.argmax() |
|
69
|
|
|
assert ne_clumps[ix] == clumps.ne_clumps(xyz[:,ix]) |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
View Code Duplication |
def test_void(): |
|
|
|
|
|
|
73
|
|
|
voids_file = os.path.join(os.path.split(density.__file__)[0], "data", |
|
74
|
|
|
"nevoidN.NE2001.dat") |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
voids = density.Voids(voids_file) |
|
78
|
|
|
|
|
79
|
|
|
voids = density.Voids() |
|
80
|
|
|
|
|
81
|
|
|
xyz = (voids.xyz.T[randint(0, voids.gl.size, 100)].T + |
|
82
|
|
|
(1-2*rand(3, 100))*0.01) |
|
83
|
|
|
|
|
84
|
|
|
ne_voids = voids.ne_voids(xyz) |
|
85
|
|
|
assert len(ne_voids) == 100 |
|
86
|
|
|
|
|
87
|
|
|
ix = ne_voids.argmax() |
|
88
|
|
|
assert ne_voids[ix] == voids.ne_voids(xyz[:,ix]) |
|
89
|
|
|
|
|
90
|
|
|
|
|
91
|
|
|
def test_local_ism(): |
|
92
|
|
|
xyz = (1-2*rand(3, 100)) * 20 |
|
93
|
|
|
ne, w = density.ne_local_ism(xyz, density.ldr_params, |
|
94
|
|
|
density.lsb_params, |
|
95
|
|
|
density.lhb_params, |
|
96
|
|
|
density.loop_params) |
|
97
|
|
|
assert all(ne >= 0) |
|
98
|
|
|
assert len(ne) == 100 |
|
99
|
|
|
assert len(ne) == len(w) |
|
100
|
|
|
|