-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_vcdisk.py
147 lines (121 loc) · 4.58 KB
/
test_vcdisk.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import numpy as np
import pytest
from vcdisk import vcdisk, vcdisk_thinexp, vcbulge_sph, vcbulge_ellip, vcbulge_sersic, sersic
rad = np.logspace(-1, 1.5, 100)
rad_nan = rad.copy()
rad_nan[0] = np.nan
md, rd = 1e10, 1.0
n = 1.0
sb = md / (2*np.pi*rd**2) * np.exp(-rad/rd)
sb_nan = sb.copy()
sb_nan[0] = np.nan
rhoz_simple = lambda x: np.exp(-x**2)
rhoz_compl = lambda x,t: t*np.exp(-x**2)
rhoz_flare1 = lambda x,y: np.exp(-x/(1.0+y*1.0))
rhoz_flare2 = lambda x,y,t: np.exp(-x/(1.0+y*t))
sers = sersic(md, rd, n)
def test_inputs():
#-- vcdisk
# input rad, sb
with pytest.raises(TypeError):
vcdisk(0, 0)
with pytest.raises(TypeError):
vcdisk(rad, 0)
with pytest.raises(TypeError):
vcdisk(0, sb)
with pytest.raises(ValueError):
vcdisk(rad, [])
with pytest.raises(ValueError):
vcdisk(rad, np.ones(len(rad)+1))
with pytest.raises(ValueError):
vcdisk(rad_nan, sb)
with pytest.raises(ValueError):
vcdisk(rad, sb_nan)
# input z0
with pytest.raises(TypeError):
vcdisk(rad, sb, z0=[])
# input zsamp
with pytest.raises(TypeError):
vcdisk(rad, sb, zsamp='no')
# input rsamp
with pytest.raises(TypeError):
vcdisk(rad, sb, rsamp='no')
with pytest.raises(TypeError):
vcdisk(rad, sb, rsamp=rad)
# input rhoz
with pytest.raises(TypeError):
vcdisk(rad, sb, rhoz='no')
# input rhoz_args
with pytest.raises(TypeError):
vcdisk(rad, sb, rhoz=rhoz_simple, rhoz_args=0)
#-- vcdisk_thinexp
# input R
with pytest.raises(TypeError):
vcdisk_thinexp('o',md,rd)
with pytest.raises(ValueError):
vcdisk_thinexp([],md,rd)
with pytest.raises(ValueError):
vcdisk_thinexp(rad_nan,md,rd)
# input Md and Rd
with pytest.raises(TypeError):
vcdisk_thinexp(rad,'o',rd)
with pytest.raises(TypeError):
vcdisk_thinexp(rad,md,'o')
#-- vcbulge_ellip
# input q and inc
with pytest.raises(ValueError):
vcbulge_ellip(rad, sb, q=-1.0)
with pytest.raises(ValueError):
vcbulge_ellip(rad, sb, q=2.0)
with pytest.raises(ValueError):
vcbulge_ellip(rad, sb, inc=-1.0)
with pytest.raises(ValueError):
vcbulge_ellip(rad, sb, inc=180.0)
#-- vcbulge_sersic
# input rad
with pytest.raises(TypeError):
vcbulge_sersic('rad', md, rd, n)
with pytest.raises(ValueError):
vcbulge_sersic([], md, rd, n)
with pytest.raises(ValueError):
vcbulge_sersic(rad_nan, md, rd, n)
with pytest.raises(ValueError):
vcbulge_sersic(rad, md, rd, -1.0)
with pytest.raises(ValueError):
vcbulge_sersic(rad, md, rd, 10.0)
def test_output_type():
#-- vcdisk_thinexp
assert type(vcdisk_thinexp(rad, md, rd)) is np.ndarray
# assert type(vcdisk_thinexp(1, md, rd)) is np.float64
assert type(vcdisk_thinexp(list(rad), md, rd)) is np.ndarray
#-- vcdisk
assert type(vcdisk(rad, sb)) is np.ndarray
assert type(vcdisk(list(rad), list(sb))) is np.ndarray
assert type(vcdisk(rad, sb, z0=1)) is np.ndarray
assert type(vcdisk(rad, sb, z0=1.0)) is np.ndarray
assert type(vcdisk(rad, sb, zsamp='log')) is np.ndarray
assert type(vcdisk(rad, sb, zsamp='lin')) is np.ndarray
assert type(vcdisk(rad, sb, zsamp=[0.1, 1.0, 10.0])) is np.ndarray
assert type(vcdisk(rad, sb, zsamp=rad)) is np.ndarray
assert type(vcdisk(rad, sb, rsamp='log')) is np.ndarray
assert type(vcdisk(rad, sb, rsamp='lin')) is np.ndarray
assert type(vcdisk(rad, sb, rsamp='nat')) is np.ndarray
assert type(vcdisk(rad, sb, rhoz='cosh')) is np.ndarray
assert type(vcdisk(rad, sb, rhoz='exp')) is np.ndarray
assert type(vcdisk(rad, sb, rhoz=rhoz_simple)) is np.ndarray
assert type(vcdisk(rad, sb, rhoz=rhoz_compl, rhoz_args={"t":1.0})) is np.ndarray
assert type(vcdisk(rad, sb, rhoz=rhoz_flare1, flaring=True)) is np.ndarray
assert type(vcdisk(rad, sb, rhoz=rhoz_flare2, rhoz_args={"t":1.0}, flaring=True)) is np.ndarray
#-- vcbulge_sph
assert type(vcbulge_sph(rad, sb)) is np.ndarray
#-- vcbulge_ellip
assert type(vcbulge_ellip(rad, sb)) is np.ndarray
assert type(vcbulge_ellip(rad, sb, q=0.9)) is np.ndarray
assert type(vcbulge_ellip(rad, sb, q=1.0)) is np.ndarray
assert type(vcbulge_ellip(rad, sb, inc=60.0)) is np.ndarray
assert type(vcbulge_ellip(rad, sb, q=0.9, inc=60.0)) is np.ndarray
#-- vcbulge_sersic
assert type(vcbulge_sersic(rad, md, rd, n)) is np.ndarray
assert type(vcbulge_sersic(list(rad), md, rd, n)) is np.ndarray
#-- sersic
assert type(sers(rad)) is np.ndarray