Skip to content

Commit 3e9b373

Browse files
committed
All models now have a TS pytest
1 parent 6b272d2 commit 3e9b373

File tree

1 file changed

+58
-12
lines changed

1 file changed

+58
-12
lines changed

tests/test_model_outputs.py

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_mssmodel(rm, reference_model, f, ts):
3131
m = rm.parameters(reference_model)
3232
m['f'] = f
3333

34-
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), f"Incorrect TS value"
34+
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), "Incorrect TS value"
3535

3636

3737
###########################################################
@@ -63,7 +63,7 @@ def test_psmsmodel(rm, reference_model, f, theta, ts):
6363
m['f'] = f
6464
m['theta'] = theta
6565

66-
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), f"Incorrect TS value"
66+
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), "Incorrect TS value"
6767

6868

6969
###########################################################
@@ -76,7 +76,7 @@ def test_esmodel(rm, reference_model, f, ts):
7676
m = rm.parameters(reference_model)
7777
m['f'] = f
7878
print(mod.calculate_ts(m))
79-
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), f"Incorrect TS value"
79+
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), "Incorrect TS value"
8080

8181

8282
###########################################################
@@ -90,12 +90,23 @@ def test_krmmodel(rm, fname, f, ts):
9090
'f': f, 'high_ka_medium': 'water', 'low_ka_medium': 'water'}
9191
mod = echosms.KRMModel()
9292
print(mod.calculate_ts(m))
93-
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), f"Incorrect TS value"
93+
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), "Incorrect TS value"
9494

9595

9696
###########################################################
9797
# KAModel
9898

99+
def test_kamodel(rm):
100+
import trimesh
101+
name = 'fixed rigid sphere'
102+
s = rm.specification(name)
103+
104+
p = {'medium_c': s['medium_c'], 'phi': 0, 'theta': 90.0,
105+
'mesh': trimesh.creation.icosphere(radius=s['a'], subdivisions=4),
106+
'boundary_type': 'pressure release', 'f': 38e3}
107+
108+
mod = echosms.KAModel()
109+
assert np.allclose(mod.calculate_ts(p), -44.4474, atol=0.0001), "Incorrect TS value"
99110

100111
###########################################################
101112
# HPModel
@@ -108,24 +119,59 @@ def test_hpmodel(model, f, ts):
108119
p = {'boundary_type': model, 'shape': 'sphere', 'medium_c': 1500, 'a': 0.01, 'f': f}
109120
match model:
110121
case 'fixed rigid':
111-
print(mod.calculate_ts(p))
112-
assert np.allclose(mod.calculate_ts(p), ts, atol=0.0001), f"Incorrect TS value"
122+
assert np.allclose(mod.calculate_ts(p), ts, atol=0.0001), "Incorrect TS value"
113123
case 'elastic':
114124
p |= {'medium_rho': 1024, 'target_c': 1600, 'target_rho': 1600}
115-
print(mod.calculate_ts(p))
116-
assert np.allclose(mod.calculate_ts(p), ts, atol=0.0001), f"Incorrect TS value"
125+
assert np.allclose(mod.calculate_ts(p), ts, atol=0.0001), "Incorrect TS value"
117126
case 'fluid filled':
118127
p |= {'medium_rho': 1024, 'target_c': 1510, 'target_rho': 1025}
119-
print(mod.calculate_ts(p))
120-
assert np.allclose(mod.calculate_ts(p), ts, atol=0.0001), f"Incorrect TS value"
128+
assert np.allclose(mod.calculate_ts(p), ts, atol=0.0001), "Incorrect TS value"
121129

122130

123131
###########################################################
124132
# PTDWBAModel
133+
def test_ptdwbamodel(rm):
134+
name = 'weakly scattering sphere'
135+
p = rm.parameters(name)
136+
137+
# make a 3d matrix of 0's and 1's and set to 1 for the sphere
138+
# and 0 for not the sphere
139+
p['voxel_size'] = (0.0001, 0.0001, 0.0001) # [m]
140+
x = np.arange(-p['a'], p['a'], p['voxel_size'][0])
141+
(X, Y, Z) = np.meshgrid(x, x, x)
142+
143+
p['volume'] = (np.sqrt(X**2 + Y**2 + Z**2) <= p['a']).astype(int)
144+
p['theta'] = 90
145+
p['phi'] = 0
146+
p['rho'] = [p['medium_rho'], p['target_rho']]
147+
p['c'] = [p['medium_c'], p['target_c']]
148+
p['f'] = 38e3
149+
150+
# remove unneeded parameters
151+
p = {k: v for k, v in p.items()
152+
if k not in ['boundary_type', 'a', 'medium_rho', 'medium_c', 'target_rho', 'target_c']}
153+
154+
mod = echosms.PTDWBAModel()
155+
print(mod.calculate_ts(p))
156+
assert np.allclose(mod.calculate_ts(p), -94.0733, atol=0.0001), "Incorrect TS value"
125157

126158

127159
###########################################################
128-
# SDWBAModel
160+
# Stochastic option on the DWBAModel
161+
def test_sdwbamodel():
162+
krill = echosms.DWBAdata().model('Generic krill (McGehee 1998)')
163+
164+
p = {'medium_c': 1500, 'medium_rho': 1024, 'phi': 0,
165+
'target_c': 1501, 'target_rho': 1025, 'a': krill.a, 'rv_pos': krill.rv_pos,
166+
'rv_tan': krill.rv_tan, 'f': 38000, 'theta': 90,
167+
'phase_sd': 20, 'num_runs': 100}
168+
169+
mod = echosms.DWBAModel()
170+
print(mod.calculate_ts(p))
171+
172+
# Need wider bounds on the closeness check here because of the stochastic
173+
# part of the SDWBA model.
174+
assert np.allclose(mod.calculate_ts(p), -115.7, atol=0.5), "Incorrect TS value"
129175

130176

131177
###########################################################
@@ -150,4 +196,4 @@ def test_dwbamodel(rm, reference_model, f, theta, ts):
150196

151197
mod = echosms.DWBAModel()
152198

153-
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), f"Incorrect TS value"
199+
assert np.allclose(mod.calculate_ts(m), [ts], atol=0.0001), "Incorrect TS value"

0 commit comments

Comments
 (0)