Completed
Push — master ( f99e41...be615f )
by Ben
01:35
created

test_clumps()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
1
2
import os
3
4
import numpy as np
5
from click.testing import CliRunner
6
from numpy.random import rand
7
8
from ne2001 import density
9
from ne2001.cli import main
10
11
12
def test_main():
13
    runner = CliRunner()
14
    result = runner.invoke(main, [])
15
16
    assert result.output == '()\n'
17
    assert result.exit_code == 0
18
19
20
def test_density():
21
    xyz = (1-2*rand(3, 100)) * 20
22
23
    ne_disk1 = density.ne_thick_disk(xyz, 0.03, 17.5, 0.97, 8.5)
24
    assert len(ne_disk1) == 100
25
    assert all(ne_disk1 >= 0)
26
27
    ne_disk2 = density.ne_thin_disk(xyz, 0.08, 3.8, 0.15)
28
    assert len(ne_disk2) == 100
29
    assert all(ne_disk2 >= 0)
30
31
    ne_gc = density.ne_gc(xyz, 10., 0.145, 0.026,
32
                          np.array([-0.01, 0.0, -0.029]))
33
    assert len(ne_gc) == 100
34
    assert all(ne_gc >= 0)
35
36
37
def test_geometry():
38
    abc = rand(3)*20
39
    xyz = (1-2*rand(3, 100)) * 20
40
    theta = rand()*2*np.pi
41
    xyz_center = rand(3)*20
42
    assert density.in_ellisoid(xyz_center, xyz_center, abc, theta)
43
    assert len(density.in_ellisoid(xyz, xyz_center, abc, theta)) == 100
44
45
    abc = rand(3)*20
46
    xyz = (1-2*rand(3, 100)) * 20
47
    theta = rand()*2*np.pi
48
    xyz_center = rand(3)*20
49
    assert len(density.in_cylinder(xyz, xyz_center, abc, theta)) == 100
50
51
    assert all(density.in_half_sphere(xyz, xyz_center, 10)[xyz[-1] < 0] == 0)
52
53
54
def test_clumps():
55
    xyz = (1-2*rand(3, 100)) * 20
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
    ne_clumps = clumps.ne_clumps(xyz)
61
    assert len(ne_clumps) == 100
62
63
def test_clumps_local_file():
64
    xyz = (1-2*rand(3, 100)) * 20
65
    clumps = density.Clumps()
66
    ne_clumps = clumps.ne_clumps(xyz)
67
    assert len(ne_clumps) == 100
68
69
70
def test_local_ism():
71
    xyz = (1-2*rand(3, 100)) * 20
72
    ne, w = density.ne_local_ism(xyz, density.ldr_params,
73
                                 density.lsb_params,
74
                                 density.lhb_params,
75
                                 density.loop_params)
76
    assert all(ne >= 0)
77
    assert len(ne) == 100
78
    assert len(ne) == len(w)
79