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
@@ -227,7 +228,7 @@ def test_conversion_3DCROCO():
227228 for zi , z in enumerate (z_xroms ):
228229 sigma [zi ] = _croco_from_z_to_sigma_scipy (fieldset , 0 , z , lat , lon , None )
229230
230- assert np . allclose (sigma , s_xroms , atol = 1e-3 )
231+ assert_allclose (sigma , s_xroms , atol = 1e-3 )
231232
232233
233234@pytest .mark .v4alpha
@@ -246,8 +247,8 @@ def SampleW(particle, fieldset, time): # pragma: no cover
246247 particle .w = fieldset .W [time , particle .depth , particle .lat , particle .lon ]
247248
248249 pset .execute ([AdvectionRK4_3D , SampleW ], runtime = runtime , dt = 100 )
249- assert np . allclose (pset .depth , Z .flatten (), atol = 5 ) # TODO lower this atol
250- assert np . allclose (pset .lon_nextloop , [x + runtime for x in X .flatten ()], atol = 1e-3 )
250+ assert_allclose (pset .depth , Z .flatten (), atol = 5 ) # TODO lower this atol
251+ assert_allclose (pset .lon_nextloop , [x + runtime for x in X .flatten ()], atol = 1e-3 )
251252
252253
253254@pytest .mark .v4alpha
@@ -262,8 +263,8 @@ def test_advection_2DCROCO():
262263 pset = ParticleSet (fieldset = fieldset , pclass = Particle , lon = X , lat = Y , depth = Z )
263264
264265 pset .execute ([AdvectionRK4 ], runtime = runtime , dt = 100 )
265- assert np . allclose (pset .depth , Z .flatten (), atol = 1e-3 )
266- assert np . allclose (pset .lon_nextloop , [x + runtime for x in X ], atol = 1e-3 )
266+ assert_allclose (pset .depth , Z .flatten (), atol = 1e-3 )
267+ assert_allclose (pset .lon_nextloop , [x + runtime for x in X ], atol = 1e-3 )
267268
268269
269270def create_periodic_fieldset (xdim , ydim , uvel , vvel ):
@@ -315,8 +316,8 @@ def test_advection_periodic_zonal_meridional():
315316 fieldset .add_periodic_halo (zonal = True , meridional = True )
316317 assert len (fieldset .U .lat ) == ydim + 10 # default halo size is 5 grid points
317318 assert len (fieldset .U .lon ) == xdim + 10 # default halo size is 5 grid points
318- assert np . allclose (np .diff (fieldset .U .lat ), fieldset .U .lat [1 ] - fieldset .U .lat [0 ], rtol = 0.001 )
319- assert np . allclose (np .diff (fieldset .U .lon ), fieldset .U .lon [1 ] - fieldset .U .lon [0 ], rtol = 0.001 )
319+ assert_allclose (np .diff (fieldset .U .lat ), fieldset .U .lat [1 ] - fieldset .U .lat [0 ], rtol = 0.001 )
320+ assert_allclose (np .diff (fieldset .U .lon ), fieldset .U .lon [1 ] - fieldset .U .lon [0 ], rtol = 0.001 )
320321
321322 pset = ParticleSet (fieldset , pclass = Particle , lon = [0.4 ], lat = [0.5 ])
322323 pset .execute (AdvectionRK4 + pset .Kernel (periodicBC ), runtime = timedelta (hours = 20 ), dt = timedelta (seconds = 30 ))
@@ -431,8 +432,8 @@ def test_stationary_eddy(fieldset_stationary, method, rtol, diffField):
431432
432433 exp_lon = [truth_stationary (x , y , pset [0 ].time )[0 ] for x , y in zip (lon , lat , strict = True )]
433434 exp_lat = [truth_stationary (x , y , pset [0 ].time )[1 ] for x , y in zip (lon , lat , strict = True )]
434- assert np . allclose (pset .lon , exp_lon , rtol = rtol )
435- assert np . allclose (pset .lat , exp_lat , rtol = rtol )
435+ assert_allclose (pset .lon , exp_lon , rtol = rtol )
436+ assert_allclose (pset .lat , exp_lat , rtol = rtol )
436437
437438
438439def test_stationary_eddy_vertical ():
@@ -460,9 +461,9 @@ def test_stationary_eddy_vertical():
460461 exp_lon = [truth_stationary (x , z , pset [0 ].time )[0 ] for x , z in zip (lon , depth , strict = True )]
461462 exp_depth = [truth_stationary (x , z , pset [0 ].time )[1 ] for x , z in zip (lon , depth , strict = True )]
462463 print (pset , exp_lon )
463- assert np . allclose (pset .lon , exp_lon , rtol = 1e-5 )
464- assert np . allclose (pset .lat , lat , rtol = 1e-5 )
465- assert np . allclose (pset .depth , exp_depth , rtol = 1e-5 )
464+ assert_allclose (pset .lon , exp_lon , rtol = 1e-5 )
465+ assert_allclose (pset .lat , lat , rtol = 1e-5 )
466+ assert_allclose (pset .depth , exp_depth , rtol = 1e-5 )
466467
467468 data = {"U" : fldzero , "V" : fld2 , "W" : fld1 }
468469 fieldset = FieldSet .from_data (data , dimensions , mesh = "flat" )
@@ -471,9 +472,9 @@ def test_stationary_eddy_vertical():
471472 pset .execute (AdvectionRK4_3D , dt = dt , endtime = endtime )
472473 exp_depth = [truth_stationary (z , y , pset [0 ].time )[0 ] for z , y in zip (depth , lat , strict = True )]
473474 exp_lat = [truth_stationary (z , y , pset [0 ].time )[1 ] for z , y in zip (depth , lat , strict = True )]
474- assert np . allclose (pset .lon , lon , rtol = 1e-5 )
475- assert np . allclose (pset .lat , exp_lat , rtol = 1e-5 )
476- assert np . allclose (pset .depth , exp_depth , rtol = 1e-5 )
475+ assert_allclose (pset .lon , lon , rtol = 1e-5 )
476+ assert_allclose (pset .lat , exp_lat , rtol = 1e-5 )
477+ assert_allclose (pset .depth , exp_depth , rtol = 1e-5 )
477478
478479
479480def truth_moving (x_0 , y_0 , t ):
@@ -536,8 +537,8 @@ def test_moving_eddy(fieldset_moving, method, rtol, diffField):
536537
537538 exp_lon = [truth_moving (x , y , t )[0 ] for x , y , t in zip (lon , lat , pset .time , strict = True )]
538539 exp_lat = [truth_moving (x , y , t )[1 ] for x , y , t in zip (lon , lat , pset .time , strict = True )]
539- assert np . allclose (pset .lon , exp_lon , rtol = rtol )
540- assert np . allclose (pset .lat , exp_lat , rtol = rtol )
540+ assert_allclose (pset .lon , exp_lon , rtol = rtol )
541+ assert_allclose (pset .lat , exp_lat , rtol = rtol )
541542
542543
543544def truth_decaying (x_0 , y_0 , t ):
@@ -619,8 +620,8 @@ def test_decaying_eddy(fieldset_decaying, method, rtol, diffField):
619620
620621 exp_lon = [truth_decaying (x , y , t )[0 ] for x , y , t in zip (lon , lat , pset .time , strict = True )]
621622 exp_lat = [truth_decaying (x , y , t )[1 ] for x , y , t in zip (lon , lat , pset .time , strict = True )]
622- assert np . allclose (pset .lon , exp_lon , rtol = rtol )
623- assert np . allclose (pset .lat , exp_lat , rtol = rtol )
623+ assert_allclose (pset .lon , exp_lon , rtol = rtol )
624+ assert_allclose (pset .lat , exp_lat , rtol = rtol )
624625
625626
626627def test_analyticalAgrid ():
@@ -669,6 +670,6 @@ def test_uniform_analytical(u, v, w, direction, tmp_zarrfile):
669670 ds = xr .open_zarr (tmp_zarrfile )
670671 times = (direction * ds ["time" ][:]).values .astype ("timedelta64[s]" )[0 ]
671672 timeref = np .arange (1 , 5 ).astype ("timedelta64[s]" )
672- assert np . allclose (times , timeref , atol = np .timedelta64 (1 , "ms" ))
673+ assert_allclose (times , timeref , atol = np .timedelta64 (1 , "ms" ))
673674 lons = ds ["lon" ][:].values
674- assert np . allclose (lons , x0 + direction * u * np .arange (1 , 5 ))
675+ assert_allclose (lons , x0 + direction * u * np .arange (1 , 5 ))
0 commit comments