Skip to content

Commit 0196fc9

Browse files
Adding unit test for checking croco_from_z_to_sigma function
1 parent 5535f03 commit 0196fc9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/test_advection.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,45 @@ def test_advection_RK45(lon, lat, mode, rk45_tol):
195195
print(fieldset.RK45_tol)
196196

197197

198+
def test_conversion_3DCROCO():
199+
"""Test of the (SciPy) version of the conversion from depth to sigma in CROCO
200+
201+
Values below are retrieved using xroms and hardcoded in the method (to avoid dependency on xroms):
202+
# x, y = 10, 20
203+
# s_xroms = ds.s_w.values
204+
# z_xroms = ds.z_w.isel(time=0).isel(eta_rho=y).isel(xi_rho=x).values
205+
# lat, lon = ds.y_rho.values[y, x], ds.x_rho.values[y, x]
206+
"""
207+
fieldset = FieldSet.from_modulefile(TEST_DATA / "fieldset_CROCO3D.py")
208+
209+
lat, lon = 78000.0, 38000.0
210+
s_xroms = np.array([-1.0, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, 0.0], dtype=np.float32)
211+
z_xroms = np.array(
212+
[
213+
-1.26000000e02,
214+
-1.10585846e02,
215+
-9.60985413e01,
216+
-8.24131317e01,
217+
-6.94126511e01,
218+
-5.69870148e01,
219+
-4.50318756e01,
220+
-3.34476166e01,
221+
-2.21383114e01,
222+
-1.10107975e01,
223+
2.62768921e-02,
224+
],
225+
dtype=np.float32,
226+
)
227+
228+
sigma = np.zeros_like(z_xroms)
229+
from parcels.field import _croco_from_z_to_sigma_scipy
230+
231+
for zi, z in enumerate(z_xroms):
232+
sigma[zi] = _croco_from_z_to_sigma_scipy(fieldset, 0, z, lat, lon, None)
233+
234+
assert np.allclose(sigma, s_xroms, atol=1e-3)
235+
236+
198237
@pytest.mark.parametrize("mode", ["scipy", "jit"])
199238
def test_advection_3DCROCO(mode):
200239
fieldset = FieldSet.from_modulefile(TEST_DATA / "fieldset_CROCO3D.py")

0 commit comments

Comments
 (0)