@@ -521,10 +521,13 @@ def SampleUV2(particle, fieldset, time):
521521
522522@pytest .mark .parametrize ('mode' , ['scipy' , 'jit' ])
523523@pytest .mark .parametrize ('time_periodic' , [4 * 86400.0 , False ])
524+ @pytest .mark .parametrize ('dt' , [- 3600 , 3600 ])
524525@pytest .mark .parametrize ('chunksize' , [False , 'auto' , {'time' : ('time_counter' , 1 ), 'lat' : ('y' , 32 ), 'lon' : ('x' , 32 )}])
525526@pytest .mark .parametrize ('with_GC' , [False , True ])
526527@pytest .mark .skipif (sys .platform .startswith ("win" ), reason = "skipping windows test as windows memory leaks (#787)" )
527- def test_from_netcdf_memory_containment (mode , time_periodic , chunksize , with_GC ):
528+ def test_from_netcdf_memory_containment (mode , time_periodic , dt , chunksize , with_GC ):
529+ if time_periodic and dt < 0 :
530+ return True # time_periodic does not work in backward-time mode
528531 if chunksize == 'auto' :
529532 dask .config .set ({'array.chunk-size' : '2MiB' })
530533 else :
@@ -575,7 +578,7 @@ def periodicBoundaryConditions(particle, fieldset, time):
575578 mem_0 = process .memory_info ().rss
576579 mem_exhausted = False
577580 try :
578- pset .execute (pset .Kernel (AdvectionRK4 )+ periodicBoundaryConditions , dt = delta ( hours = 1 ) , runtime = delta (days = 7 ), postIterationCallbacks = postProcessFuncs , callbackdt = delta (hours = 12 ))
581+ pset .execute (pset .Kernel (AdvectionRK4 )+ periodicBoundaryConditions , dt = dt , runtime = delta (days = 7 ), postIterationCallbacks = postProcessFuncs , callbackdt = delta (hours = 12 ))
579582 except MemoryError :
580583 mem_exhausted = True
581584 mem_steps_np = np .array (perflog .memory_steps )
@@ -768,7 +771,7 @@ def DoNothing(particle, fieldset, time):
768771 assert np .allclose (fieldset .U .data , scale_fac * (zdim - 1. )/ zdim )
769772
770773
771- @pytest .mark .parametrize ('time2' , [2 , 7 ])
774+ @pytest .mark .parametrize ('time2' , [1 , 7 ])
772775def test_fieldset_initialisation_kernel_dask (time2 , tmpdir , filename = 'test_parcels_defer_loading' ):
773776 filepath = tmpdir .join (filename )
774777 data0 , dims0 = generate_fieldset (3 , 3 , 4 , 10 )
@@ -789,7 +792,7 @@ class SampleParticle(JITParticle):
789792 pset = ParticleSet (fieldset , pclass = SampleParticle , time = [0 , time2 ],
790793 lon = [0.5 , 0.5 ], lat = [0.5 , 0.5 ], depth = [0.5 , 0.5 ])
791794
792- if time2 > 2 :
795+ if time2 > 1 :
793796 failed = False
794797 try :
795798 pset .execute (SampleField , dt = 0. )
@@ -905,3 +908,30 @@ def test_fieldset_from_data_gridtypes(xdim=20, ydim=10, zdim=4):
905908 pset .execute (AdvectionRK4 , runtime = 1 , dt = .5 )
906909 assert np .allclose (plon , pset .lon )
907910 assert np .allclose (plat , pset .lat )
911+
912+
913+ @pytest .mark .parametrize ('mode' , ['scipy' , 'jit' ])
914+ @pytest .mark .parametrize ('direction' , [1 , - 1 ])
915+ @pytest .mark .parametrize ('time_extrapolation' , [True , False ])
916+ def test_deferredload_simplefield (mode , direction , time_extrapolation , tmpdir , tdim = 10 ):
917+ filename = tmpdir .join ("simplefield_deferredload.nc" )
918+ data = np .zeros ((tdim , 2 , 2 ))
919+ for ti in range (tdim ):
920+ data [ti , :, :] = ti if direction == 1 else tdim - ti - 1
921+ ds = xr .Dataset ({"U" : (("t" , "y" , "x" ), data ), "V" : (("t" , "y" , "x" ), data )},
922+ coords = {"x" : [0 , 1 ], "y" : [0 , 1 ], "t" : np .arange (tdim )})
923+ ds .to_netcdf (filename )
924+
925+ fieldset = FieldSet .from_netcdf (filename , {'U' : 'U' , 'V' : 'V' }, {'lon' : 'x' , 'lat' : 'y' , 'time' : 't' },
926+ deferred_load = True , mesh = 'flat' , allow_time_extrapolation = time_extrapolation )
927+
928+ class SamplingParticle (ptype [mode ]):
929+ p = Variable ('p' )
930+ pset = ParticleSet (fieldset , SamplingParticle , lon = 0.5 , lat = 0.5 )
931+
932+ def SampleU (particle , fieldset , time ):
933+ particle .p = fieldset .U [particle ]
934+
935+ runtime = tdim * 2 if time_extrapolation else None
936+ pset .execute (SampleU , dt = direction , runtime = runtime )
937+ assert pset .p == tdim - 1 if time_extrapolation else tdim - 2
0 commit comments