@@ -121,6 +121,23 @@ def fieldset_from_ofam(chunk_mode):
121121 return FieldSet .from_netcdf (filenames , variables , dimensions , allow_time_extrapolation = True , field_chunksize = chs , chunkdims_name_map = name_map )
122122
123123
124+ def fieldset_from_mitgcm (chunk_mode ):
125+ data_path = path .join (path .dirname (__file__ ), "MITgcm_example_data/" )
126+ filenames = {"U" : data_path + "mitgcm_UV_surface_zonally_reentrant.nc" ,
127+ "V" : data_path + "mitgcm_UV_surface_zonally_reentrant.nc" }
128+ variables = {"U" : "UVEL" , "V" : "VVEL" }
129+ dimensions = {"U" : {"lon" : "XG" , "lat" : "YG" , "time" : "time" },
130+ "V" : {"lon" : "XG" , "lat" : "YG" , "time" : "time" }}
131+
132+ chs = False
133+ name_map = {'lon' : 'XG' , 'lat' : 'YG' , 'time' : 'time' }
134+ if chunk_mode == 'auto' :
135+ chs = 'auto'
136+ elif chunk_mode == 'specific' :
137+ chs = (1 , 50 , 100 )
138+ return FieldSet .from_mitgcm (filenames , variables , dimensions , mesh = 'flat' , field_chunksize = chs , chunkdims_name_map = name_map )
139+
140+
124141def compute_nemo_particle_advection (field_set , mode , lonp , latp ):
125142
126143 def periodicBC (particle , fieldSet , time ):
@@ -300,6 +317,27 @@ def test_ofam_3D(mode, chunk_mode):
300317 assert (abs (pset [0 ].lat - 11 ) < 1 )
301318
302319
320+ @pytest .mark .parametrize ('mode' , ['jit' ])
321+ @pytest .mark .parametrize ('chunk_mode' , [False , 'auto' , 'specific' ])
322+ def test_mitgcm (mode , chunk_mode ):
323+ if chunk_mode == 'auto' :
324+ dask .config .set ({'array.chunk-size' : '1024KiB' })
325+ else :
326+ dask .config .set ({'array.chunk-size' : '128MiB' })
327+ field_set = fieldset_from_mitgcm (chunk_mode )
328+ lons , lats = 5e5 , 5e5
329+
330+ pset = ParticleSet .from_list (fieldset = field_set , pclass = ptype [mode ], lon = lons , lat = lats )
331+ pset .execute (AdvectionRK4 , runtime = delta (days = 1 ), dt = delta (minutes = 5 ))
332+ # MITgcm sample file dimensions: time=10, XG=400, YG=200
333+ assert (len (field_set .U .grid .load_chunk ) == len (field_set .V .grid .load_chunk ))
334+ if chunk_mode in [False , 'auto' ]:
335+ assert (len (field_set .U .grid .load_chunk ) == 1 )
336+ elif chunk_mode == 'specific' :
337+ assert (len (field_set .U .grid .load_chunk ) == (1 * int (math .ceil (400.0 / 50.0 )) * int (math .ceil (200.0 / 100.0 ))))
338+ assert np .allclose (pset [0 ].lon , 5.27e5 , atol = 1e3 )
339+
340+
303341@pytest .mark .parametrize ('mode' , ['jit' ])
304342def test_diff_entry_dimensions_chunks (mode ):
305343 data_path = path .join (path .dirname (__file__ ), 'NemoNorthSeaORCA025-N006_data/' )
0 commit comments