44import numpy as np
55import pytest
66import xarray as xr
7+ from numpy .testing import assert_allclose
78
89from parcels import (
910 AdvectionAnalytical ,
@@ -98,7 +99,7 @@ def test_advection_meridional(lon, lat):
9899 pset = ParticleSet (fieldset , pclass = Particle , lon = np .linspace (- 60 , 60 , npart ), lat = np .linspace (0 , 30 , npart ))
99100 delta_lat = np .diff (pset .lat )
100101 pset .execute (AdvectionRK4 , runtime = timedelta (hours = 2 ), dt = timedelta (seconds = 30 ))
101- assert np . allclose (np .diff (pset .lat ), delta_lat , rtol = 1.0e-4 )
102+ assert_allclose (np .diff (pset .lat ), delta_lat , rtol = 1.0e-4 )
102103
103104
104105def test_advection_3D ():
@@ -119,7 +120,7 @@ def test_advection_3D():
119120 )
120121 time = timedelta (hours = 2 ).total_seconds ()
121122 pset .execute (AdvectionRK4 , runtime = time , dt = timedelta (seconds = 30 ))
122- assert np . allclose (pset .depth * pset .time , pset .lon , atol = 1.0e-1 )
123+ assert_allclose (pset .depth * pset .time , pset .lon , atol = 1.0e-1 )
123124
124125
125126@pytest .mark .parametrize ("direction" , ["up" , "down" ])
@@ -161,8 +162,8 @@ def SubmergeParticle(particle, fieldset, time): # pragma: no cover
161162 pset .execute (kernels , runtime = 11.0 , dt = 1 )
162163
163164 if direction == "up" and wErrorThroughSurface :
164- assert np . allclose (pset .lon [0 ], 0.6 )
165- assert np . allclose (pset .depth [0 ], 0 )
165+ assert_allclose (pset .lon [0 ], 0.6 )
166+ assert_allclose (pset .depth [0 ], 0 )
166167 else :
167168 assert len (pset ) == 0
168169
@@ -225,7 +226,7 @@ def test_conversion_3DCROCO():
225226 for zi , z in enumerate (z_xroms ):
226227 sigma [zi ] = _croco_from_z_to_sigma_scipy (fieldset , 0 , z , lat , lon , None )
227228
228- assert np . allclose (sigma , s_xroms , atol = 1e-3 )
229+ assert_allclose (sigma , s_xroms , atol = 1e-3 )
229230
230231
231232def test_advection_3DCROCO ():
@@ -242,8 +243,8 @@ def SampleW(particle, fieldset, time): # pragma: no cover
242243 particle .w = fieldset .W [time , particle .depth , particle .lat , particle .lon ]
243244
244245 pset .execute ([AdvectionRK4_3D , SampleW ], runtime = runtime , dt = 100 )
245- assert np . allclose (pset .depth , Z .flatten (), atol = 5 ) # TODO lower this atol
246- assert np . allclose (pset .lon_nextloop , [x + runtime for x in X .flatten ()], atol = 1e-3 )
246+ assert_allclose (pset .depth , Z .flatten (), atol = 5 ) # TODO lower this atol
247+ assert_allclose (pset .lon_nextloop , [x + runtime for x in X .flatten ()], atol = 1e-3 )
247248
248249
249250def test_advection_2DCROCO ():
@@ -256,8 +257,8 @@ def test_advection_2DCROCO():
256257 pset = ParticleSet (fieldset = fieldset , pclass = Particle , lon = X , lat = Y , depth = Z )
257258
258259 pset .execute ([AdvectionRK4 ], runtime = runtime , dt = 100 )
259- assert np . allclose (pset .depth , Z .flatten (), atol = 1e-3 )
260- assert np . allclose (pset .lon_nextloop , [x + runtime for x in X ], atol = 1e-3 )
260+ assert_allclose (pset .depth , Z .flatten (), atol = 1e-3 )
261+ assert_allclose (pset .lon_nextloop , [x + runtime for x in X ], atol = 1e-3 )
261262
262263
263264def create_periodic_fieldset (xdim , ydim , uvel , vvel ):
@@ -309,8 +310,8 @@ def test_advection_periodic_zonal_meridional():
309310 fieldset .add_periodic_halo (zonal = True , meridional = True )
310311 assert len (fieldset .U .lat ) == ydim + 10 # default halo size is 5 grid points
311312 assert len (fieldset .U .lon ) == xdim + 10 # default halo size is 5 grid points
312- assert np . allclose (np .diff (fieldset .U .lat ), fieldset .U .lat [1 ] - fieldset .U .lat [0 ], rtol = 0.001 )
313- assert np . allclose (np .diff (fieldset .U .lon ), fieldset .U .lon [1 ] - fieldset .U .lon [0 ], rtol = 0.001 )
313+ assert_allclose (np .diff (fieldset .U .lat ), fieldset .U .lat [1 ] - fieldset .U .lat [0 ], rtol = 0.001 )
314+ assert_allclose (np .diff (fieldset .U .lon ), fieldset .U .lon [1 ] - fieldset .U .lon [0 ], rtol = 0.001 )
314315
315316 pset = ParticleSet (fieldset , pclass = Particle , lon = [0.4 ], lat = [0.5 ])
316317 pset .execute (AdvectionRK4 + pset .Kernel (periodicBC ), runtime = timedelta (hours = 20 ), dt = timedelta (seconds = 30 ))
@@ -425,8 +426,8 @@ def test_stationary_eddy(fieldset_stationary, method, rtol, diffField):
425426
426427 exp_lon = [truth_stationary (x , y , pset [0 ].time )[0 ] for x , y in zip (lon , lat , strict = True )]
427428 exp_lat = [truth_stationary (x , y , pset [0 ].time )[1 ] for x , y in zip (lon , lat , strict = True )]
428- assert np . allclose (pset .lon , exp_lon , rtol = rtol )
429- assert np . allclose (pset .lat , exp_lat , rtol = rtol )
429+ assert_allclose (pset .lon , exp_lon , rtol = rtol )
430+ assert_allclose (pset .lat , exp_lat , rtol = rtol )
430431
431432
432433def test_stationary_eddy_vertical ():
@@ -454,9 +455,9 @@ def test_stationary_eddy_vertical():
454455 exp_lon = [truth_stationary (x , z , pset [0 ].time )[0 ] for x , z in zip (lon , depth , strict = True )]
455456 exp_depth = [truth_stationary (x , z , pset [0 ].time )[1 ] for x , z in zip (lon , depth , strict = True )]
456457 print (pset , exp_lon )
457- assert np . allclose (pset .lon , exp_lon , rtol = 1e-5 )
458- assert np . allclose (pset .lat , lat , rtol = 1e-5 )
459- assert np . allclose (pset .depth , exp_depth , rtol = 1e-5 )
458+ assert_allclose (pset .lon , exp_lon , rtol = 1e-5 )
459+ assert_allclose (pset .lat , lat , rtol = 1e-5 )
460+ assert_allclose (pset .depth , exp_depth , rtol = 1e-5 )
460461
461462 data = {"U" : fldzero , "V" : fld2 , "W" : fld1 }
462463 fieldset = FieldSet .from_data (data , dimensions , mesh = "flat" )
@@ -465,9 +466,9 @@ def test_stationary_eddy_vertical():
465466 pset .execute (AdvectionRK4_3D , dt = dt , endtime = endtime )
466467 exp_depth = [truth_stationary (z , y , pset [0 ].time )[0 ] for z , y in zip (depth , lat , strict = True )]
467468 exp_lat = [truth_stationary (z , y , pset [0 ].time )[1 ] for z , y in zip (depth , lat , strict = True )]
468- assert np . allclose (pset .lon , lon , rtol = 1e-5 )
469- assert np . allclose (pset .lat , exp_lat , rtol = 1e-5 )
470- assert np . allclose (pset .depth , exp_depth , rtol = 1e-5 )
469+ assert_allclose (pset .lon , lon , rtol = 1e-5 )
470+ assert_allclose (pset .lat , exp_lat , rtol = 1e-5 )
471+ assert_allclose (pset .depth , exp_depth , rtol = 1e-5 )
471472
472473
473474def truth_moving (x_0 , y_0 , t ):
@@ -530,8 +531,8 @@ def test_moving_eddy(fieldset_moving, method, rtol, diffField):
530531
531532 exp_lon = [truth_moving (x , y , t )[0 ] for x , y , t in zip (lon , lat , pset .time , strict = True )]
532533 exp_lat = [truth_moving (x , y , t )[1 ] for x , y , t in zip (lon , lat , pset .time , strict = True )]
533- assert np . allclose (pset .lon , exp_lon , rtol = rtol )
534- assert np . allclose (pset .lat , exp_lat , rtol = rtol )
534+ assert_allclose (pset .lon , exp_lon , rtol = rtol )
535+ assert_allclose (pset .lat , exp_lat , rtol = rtol )
535536
536537
537538def truth_decaying (x_0 , y_0 , t ):
@@ -613,8 +614,8 @@ def test_decaying_eddy(fieldset_decaying, method, rtol, diffField):
613614
614615 exp_lon = [truth_decaying (x , y , t )[0 ] for x , y , t in zip (lon , lat , pset .time , strict = True )]
615616 exp_lat = [truth_decaying (x , y , t )[1 ] for x , y , t in zip (lon , lat , pset .time , strict = True )]
616- assert np . allclose (pset .lon , exp_lon , rtol = rtol )
617- assert np . allclose (pset .lat , exp_lat , rtol = rtol )
617+ assert_allclose (pset .lon , exp_lon , rtol = rtol )
618+ assert_allclose (pset .lat , exp_lat , rtol = rtol )
618619
619620
620621def test_analyticalAgrid ():
@@ -663,6 +664,6 @@ def test_uniform_analytical(u, v, w, direction, tmp_zarrfile):
663664 ds = xr .open_zarr (tmp_zarrfile )
664665 times = (direction * ds ["time" ][:]).values .astype ("timedelta64[s]" )[0 ]
665666 timeref = np .arange (1 , 5 ).astype ("timedelta64[s]" )
666- assert np . allclose (times , timeref , atol = np .timedelta64 (1 , "ms" ))
667+ assert_allclose (times , timeref , atol = np .timedelta64 (1 , "ms" ))
667668 lons = ds ["lon" ][:].values
668- assert np . allclose (lons , x0 + direction * u * np .arange (1 , 5 ))
669+ assert_allclose (lons , x0 + direction * u * np .arange (1 , 5 ))
0 commit comments