11from datetime import timedelta
2+ from pathlib import Path
3+ from typing import Literal
24
35import numpy as np
46import parcels
79ptype = {"scipy" : parcels .ScipyParticle , "jit" : parcels .JITParticle }
810
911
10- def run_mitgcm_zonally_reentrant (mode ):
12+ def run_mitgcm_zonally_reentrant (mode : Literal [ "scipy" , "jit" ], path : Path ):
1113 """Function that shows how to load MITgcm data in a zonally periodic domain."""
1214 data_folder = parcels .download_example_dataset ("MITgcm_example_data" )
1315 filenames = {
@@ -41,7 +43,7 @@ def periodicBC(particle, fieldset, time):
4143 size = 10 ,
4244 )
4345 pfile = parcels .ParticleFile (
44- "MIT_particles_" + str (mode ) + ".zarr" ,
46+ str (path ) ,
4547 pset ,
4648 outputdt = timedelta (days = 1 ),
4749 chunks = (len (pset ), 1 ),
@@ -52,12 +54,15 @@ def periodicBC(particle, fieldset, time):
5254 )
5355
5456
55- def test_mitgcm_output_compare ():
56- run_mitgcm_zonally_reentrant ( "scipy" )
57- run_mitgcm_zonally_reentrant ( "jit" )
57+ def test_mitgcm_output_compare (tmpdir ):
58+ def get_path ( mode : Literal [ "scipy" , "jit" ]) -> Path :
59+ return tmpdir / f"MIT_particles_ { mode } .zarr"
5860
59- ds_jit = xr .open_zarr ("MIT_particles_jit.zarr" )
60- ds_scipy = xr .open_zarr ("MIT_particles_scipy.zarr" )
61+ for mode in ["scipy" , "jit" ]:
62+ run_mitgcm_zonally_reentrant (mode , get_path (mode ))
63+
64+ ds_jit = xr .open_zarr (get_path ("jit" ))
65+ ds_scipy = xr .open_zarr (get_path ("scipy" ))
6166
6267 np .testing .assert_allclose (ds_jit .lat .data , ds_scipy .lat .data )
6368 np .testing .assert_allclose (ds_jit .lon .data , ds_scipy .lon .data )
0 commit comments