@@ -31,7 +31,7 @@ def test_mssmodel(rm, reference_model, f, ts):
31
31
m = rm .parameters (reference_model )
32
32
m ['f' ] = f
33
33
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"
35
35
36
36
37
37
###########################################################
@@ -63,7 +63,7 @@ def test_psmsmodel(rm, reference_model, f, theta, ts):
63
63
m ['f' ] = f
64
64
m ['theta' ] = theta
65
65
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"
67
67
68
68
69
69
###########################################################
@@ -76,7 +76,7 @@ def test_esmodel(rm, reference_model, f, ts):
76
76
m = rm .parameters (reference_model )
77
77
m ['f' ] = f
78
78
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"
80
80
81
81
82
82
###########################################################
@@ -90,12 +90,23 @@ def test_krmmodel(rm, fname, f, ts):
90
90
'f' : f , 'high_ka_medium' : 'water' , 'low_ka_medium' : 'water' }
91
91
mod = echosms .KRMModel ()
92
92
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"
94
94
95
95
96
96
###########################################################
97
97
# KAModel
98
98
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"
99
110
100
111
###########################################################
101
112
# HPModel
@@ -108,24 +119,59 @@ def test_hpmodel(model, f, ts):
108
119
p = {'boundary_type' : model , 'shape' : 'sphere' , 'medium_c' : 1500 , 'a' : 0.01 , 'f' : f }
109
120
match model :
110
121
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"
113
123
case 'elastic' :
114
124
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"
117
126
case 'fluid filled' :
118
127
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"
121
129
122
130
123
131
###########################################################
124
132
# 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"
125
157
126
158
127
159
###########################################################
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"
129
175
130
176
131
177
###########################################################
@@ -150,4 +196,4 @@ def test_dwbamodel(rm, reference_model, f, theta, ts):
150
196
151
197
mod = echosms .DWBAModel ()
152
198
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