From f6a62ed8a4c55ce7c209d71d2e363dcf68c6bebe Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Fri, 2 Aug 2024 18:34:32 +0200 Subject: [PATCH] Remove delta alias for timedelta --- docs/examples/documentation_MPI.ipynb | 10 ++-- docs/examples/documentation_indexing.ipynb | 1 - .../documentation_stuck_particles.ipynb | 23 +++++---- .../documentation_unstuck_Agrid.ipynb | 16 +++--- docs/examples/example_brownian.py | 6 +-- docs/examples/example_dask_chunk_OCMs.py | 26 +++++++--- docs/examples/example_decaying_moving_eddy.py | 14 +++--- docs/examples/example_globcurrent.py | 50 +++++++++++-------- docs/examples/example_mitgcm.py | 6 +-- docs/examples/example_moving_eddies.py | 16 +++--- docs/examples/example_nemo_curvilinear.py | 10 ++-- docs/examples/example_ofam.py | 10 ++-- docs/examples/example_peninsula.py | 10 ++-- docs/examples/example_radial_rotation.py | 10 ++-- docs/examples/example_stommel.py | 8 +-- .../tutorial_analyticaladvection.ipynb | 18 +++---- docs/examples/tutorial_delaystart.ipynb | 32 ++++++------ docs/examples/tutorial_jit_vs_scipy.ipynb | 10 ++-- docs/examples/tutorial_nemo_3D.ipynb | 4 +- docs/examples/tutorial_nemo_curvilinear.ipynb | 9 ++-- docs/examples/tutorial_output.ipynb | 16 +++--- .../tutorial_particle_field_interaction.ipynb | 8 +-- .../tutorial_periodic_boundaries.ipynb | 8 +-- docs/examples/tutorial_sampling.ipynb | 16 +++--- .../tutorial_timevaryingdepthdimensions.ipynb | 8 ++- parcels/particlefile.py | 6 +-- parcels/particleset.py | 15 +++--- parcels/tools/converters.py | 4 +- tests/test_advection.py | 44 ++++++++-------- tests/test_diffusion.py | 10 ++-- tests/test_fieldset.py | 12 ++--- tests/test_fieldset_sampling.py | 10 ++-- tests/test_grids.py | 16 +++--- 33 files changed, 249 insertions(+), 213 deletions(-) diff --git a/docs/examples/documentation_MPI.ipynb b/docs/examples/documentation_MPI.ipynb index 3ceb38d6d0..eab6293d81 100644 --- a/docs/examples/documentation_MPI.ipynb +++ b/docs/examples/documentation_MPI.ipynb @@ -216,7 +216,7 @@ "%pylab inline\n", "import os\n", "import time\n", - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "from glob import glob\n", "\n", "import matplotlib.pyplot as plt\n", @@ -248,11 +248,11 @@ " pclass=parcels.JITParticle,\n", " lon=[0],\n", " lat=[0],\n", - " repeatdt=delta(hours=1),\n", + " repeatdt=timedelta(hours=1),\n", " )\n", "\n", " tic = time.time()\n", - " pset.execute(parcels.AdvectionRK4, dt=delta(hours=1))\n", + " pset.execute(parcels.AdvectionRK4, dt=timedelta(hours=1))\n", " func_time.append(time.time() - tic)\n", " process = psutil.Process(os.getpid())\n", " mem_B_used = process.memory_info().rss\n", @@ -403,11 +403,11 @@ " pclass=parcels.JITParticle,\n", " lon=[0],\n", " lat=[0],\n", - " repeatdt=delta(hours=1),\n", + " repeatdt=timedelta(hours=1),\n", " )\n", "\n", " tic = time.time()\n", - " pset.execute(AdvectionRK4_3D, dt=delta(hours=1))\n", + " pset.execute(AdvectionRK4_3D, dt=timedelta(hours=1))\n", " func_time3D.append(time.time() - tic)" ] }, diff --git a/docs/examples/documentation_indexing.ipynb b/docs/examples/documentation_indexing.ipynb index 91d254049f..28b54b3f7e 100644 --- a/docs/examples/documentation_indexing.ipynb +++ b/docs/examples/documentation_indexing.ipynb @@ -54,7 +54,6 @@ "metadata": {}, "outputs": [], "source": [ - "from datetime import timedelta as delta\n", "from glob import glob\n", "from os import path\n", "\n", diff --git a/docs/examples/documentation_stuck_particles.ipynb b/docs/examples/documentation_stuck_particles.ipynb index a172b4c2cb..ef6b298a6e 100644 --- a/docs/examples/documentation_stuck_particles.ipynb +++ b/docs/examples/documentation_stuck_particles.ipynb @@ -63,7 +63,7 @@ "source": [ "import math\n", "from copy import copy\n", - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "from glob import glob\n", "\n", "import cmocean\n", @@ -487,10 +487,13 @@ "\n", "kernels = pset.Kernel(parcels.AdvectionRK4)\n", "\n", - "output_file = pset.ParticleFile(name=\"SMOC.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(name=\"SMOC.zarr\", outputdt=timedelta(hours=1))\n", "\n", "pset.execute(\n", - " kernels, runtime=delta(hours=119), dt=delta(minutes=12), output_file=output_file\n", + " kernels,\n", + " runtime=timedelta(hours=119),\n", + " dt=timedelta(minutes=12),\n", + " output_file=output_file,\n", ")" ] }, @@ -940,12 +943,12 @@ " fieldset=fieldset, pclass=parcels.JITParticle, lon=lon, lat=lat, time=time\n", ")\n", "\n", - "output_file = pset.ParticleFile(name=\"Cgrid-stuck.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(name=\"Cgrid-stuck.zarr\", outputdt=timedelta(hours=1))\n", "\n", "pset.execute(\n", " parcels.AdvectionRK4,\n", - " runtime=delta(days=10),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(days=10),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")" ] @@ -1291,13 +1294,15 @@ " fieldset=fieldset, pclass=LandParticle, lon=lon, lat=lat, time=time\n", ")\n", "\n", - "output_file = pset.ParticleFile(name=\"Cgrid-diffusion.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(\n", + " name=\"Cgrid-diffusion.zarr\", outputdt=timedelta(hours=1)\n", + ")\n", "pset.execute(\n", " pset.Kernel(parcels.AdvectionRK4)\n", " + pset.Kernel(parcels.DiffusionUniformKh)\n", " + pset.Kernel(Sample_land),\n", - " runtime=delta(days=10),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(days=10),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")" ] diff --git a/docs/examples/documentation_unstuck_Agrid.ipynb b/docs/examples/documentation_unstuck_Agrid.ipynb index 8efb69652a..4599fcdae4 100644 --- a/docs/examples/documentation_unstuck_Agrid.ipynb +++ b/docs/examples/documentation_unstuck_Agrid.ipynb @@ -43,7 +43,7 @@ "outputs": [], "source": [ "from copy import copy\n", - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "\n", "import cmocean\n", "import matplotlib.gridspec as gridspec\n", @@ -882,8 +882,8 @@ "lons, lats = np.meshgrid(lon, lat)\n", "time = np.zeros(lons.size)\n", "\n", - "runtime = delta(hours=100)\n", - "dt = delta(minutes=10)" + "runtime = timedelta(hours=100)\n", + "dt = timedelta(minutes=10)" ] }, { @@ -907,7 +907,7 @@ "\n", "kernels = parcels.AdvectionRK4\n", "\n", - "output_file = pset.ParticleFile(name=\"SMOC.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(name=\"SMOC.zarr\", outputdt=timedelta(hours=1))\n", "\n", "pset.execute(kernels, runtime=runtime, dt=dt, output_file=output_file)" ] @@ -1000,7 +1000,7 @@ "\n", "kernels = [displace, parcels.AdvectionRK4, set_displacement]\n", "\n", - "output_file = pset.ParticleFile(name=\"SMOC-disp.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(name=\"SMOC-disp.zarr\", outputdt=timedelta(hours=1))\n", "\n", "pset.execute(kernels, runtime=runtime, dt=dt, output_file=output_file)" ] @@ -1513,7 +1513,9 @@ "\n", "kernels = pset.Kernel(parcels.AdvectionRK4)\n", "\n", - "output_file = pset.ParticleFile(name=\"SMOC_partialslip.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(\n", + " name=\"SMOC_partialslip.zarr\", outputdt=timedelta(hours=1)\n", + ")\n", "\n", "pset.execute(kernels, runtime=runtime, dt=dt, output_file=output_file)" ] @@ -1557,7 +1559,7 @@ "\n", "kernels = pset.Kernel(parcels.AdvectionRK4)\n", "\n", - "output_file = pset.ParticleFile(name=\"SMOC_freeslip.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(name=\"SMOC_freeslip.zarr\", outputdt=timedelta(hours=1))\n", "\n", "pset.execute(kernels, runtime=runtime, dt=dt, output_file=output_file)" ] diff --git a/docs/examples/example_brownian.py b/docs/examples/example_brownian.py index f2570b1b76..370bd843f7 100644 --- a/docs/examples/example_brownian.py +++ b/docs/examples/example_brownian.py @@ -1,4 +1,4 @@ -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -32,14 +32,14 @@ def test_brownian_example(mode, mesh, npart=3000): # Set random seed parcels.ParcelsRandom.seed(123456) - runtime = delta(days=1) + runtime = timedelta(days=1) parcels.ParcelsRandom.seed(1234) pset = parcels.ParticleSet( fieldset=fieldset, pclass=ptype[mode], lon=np.zeros(npart), lat=np.zeros(npart) ) pset.execute( - pset.Kernel(parcels.DiffusionUniformKh), runtime=runtime, dt=delta(hours=1) + pset.Kernel(parcels.DiffusionUniformKh), runtime=runtime, dt=timedelta(hours=1) ) expected_std_x = np.sqrt(2 * kh_zonal * runtime.total_seconds()) diff --git a/docs/examples/example_dask_chunk_OCMs.py b/docs/examples/example_dask_chunk_OCMs.py index 851dc7eb57..99c65d9577 100644 --- a/docs/examples/example_dask_chunk_OCMs.py +++ b/docs/examples/example_dask_chunk_OCMs.py @@ -1,5 +1,5 @@ import math -from datetime import timedelta as delta +from datetime import timedelta from glob import glob import dask @@ -29,7 +29,7 @@ def periodicBC(particle, fieldSet, time): pset = parcels.ParticleSet.from_list(fieldset, ptype[mode], lon=lonp, lat=latp) kernels = pset.Kernel(parcels.AdvectionRK4) + periodicBC - pset.execute(kernels, runtime=delta(days=4), dt=delta(hours=6)) + pset.execute(kernels, runtime=timedelta(days=4), dt=timedelta(hours=6)) return pset @@ -205,7 +205,9 @@ def test_globcurrent_2D(mode, chunk_mode): ) try: pset = parcels.ParticleSet(fieldset, pclass=ptype[mode], lon=25, lat=-35) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=1), dt=delta(minutes=5)) + pset.execute( + parcels.AdvectionRK4, runtime=timedelta(days=1), dt=timedelta(minutes=5) + ) except DaskChunkingError: # we removed the failsafe, so now if all chunksize dimensions are incorrect, there is nothing left to chunk, # which raises an error saying so. This is the expected behaviour @@ -261,7 +263,7 @@ def test_pop(mode, chunk_mode): lonp = 70.0 * np.ones(npart) latp = [i for i in -45.0 + (-0.25 + np.random.rand(npart) * 2.0 * 0.25)] pset = parcels.ParticleSet.from_list(fieldset, ptype[mode], lon=lonp, lat=latp) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=90), dt=delta(days=2)) + pset.execute(parcels.AdvectionRK4, runtime=timedelta(days=90), dt=timedelta(days=2)) # POP sample file dimensions: k=21, j=60, i=60 assert len(fieldset.U.grid.load_chunk) == len(fieldset.V.grid.load_chunk) assert len(fieldset.U.grid.load_chunk) == len(fieldset.W.grid.load_chunk) @@ -364,7 +366,9 @@ def test_swash(mode, chunk_mode): fieldset, ptype[mode], lon=lonp, lat=latp, depth=depthp ) pset.execute( - parcels.AdvectionRK4, runtime=delta(seconds=0.2), dt=delta(seconds=0.005) + parcels.AdvectionRK4, + runtime=timedelta(seconds=0.2), + dt=timedelta(seconds=0.005), ) # SWASH sample file dimensions: t=1, z=7, z_u=6, y=21, x=51 if chunk_mode not in [ @@ -442,7 +446,9 @@ def test_ofam_3D(mode, chunk_mode): ) pset = parcels.ParticleSet(fieldset, pclass=ptype[mode], lon=180, lat=10, depth=2.5) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=10), dt=delta(minutes=5)) + pset.execute( + parcels.AdvectionRK4, runtime=timedelta(days=10), dt=timedelta(minutes=5) + ) # OFAM sample file dimensions: time=UNLIMITED, st_ocean=1, st_edges_ocean=52, lat=601, lon=2001 assert len(fieldset.U.grid.load_chunk) == len(fieldset.V.grid.load_chunk) if chunk_mode is False: @@ -535,7 +541,9 @@ def test_mitgcm(mode, chunk_mode, using_add_field): pset = parcels.ParticleSet.from_list( fieldset=fieldset, pclass=ptype[mode], lon=5e5, lat=5e5 ) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=1), dt=delta(minutes=5)) + pset.execute( + parcels.AdvectionRK4, runtime=timedelta(days=1), dt=timedelta(minutes=5) + ) # MITgcm sample file dimensions: time=10, XG=400, YG=200 if chunk_mode != "specific_different": assert len(fieldset.U.grid.load_chunk) == len(fieldset.V.grid.load_chunk) @@ -744,7 +752,9 @@ def test_diff_entry_chunksize_correction_globcurrent(mode): filenames, variables, dimensions, chunksize=chs ) pset = parcels.ParticleSet(fieldset, pclass=ptype[mode], lon=25, lat=-35) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=1), dt=delta(minutes=5)) + pset.execute( + parcels.AdvectionRK4, runtime=timedelta(days=1), dt=timedelta(minutes=5) + ) # GlobCurrent sample file dimensions: time=UNLIMITED, lat=41, lon=81 npart_U = 1 npart_U = [npart_U * k for k in fieldset.U.nchunks[1:]] diff --git a/docs/examples/example_decaying_moving_eddy.py b/docs/examples/example_decaying_moving_eddy.py index 853a37716b..46bc10d5c6 100644 --- a/docs/examples/example_decaying_moving_eddy.py +++ b/docs/examples/example_decaying_moving_eddy.py @@ -1,4 +1,4 @@ -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -10,8 +10,10 @@ # Define some constants. u_g = 0.04 # Geostrophic current u_0 = 0.3 # Initial speed in x dirrection. v_0 = 0 -gamma = 1.0 / delta(days=2.89).total_seconds() # Dissipitave effects due to viscousity. -gamma_g = 1.0 / delta(days=28.9).total_seconds() +gamma = ( + 1.0 / timedelta(days=2.89).total_seconds() +) # Dissipitave effects due to viscousity. +gamma_g = 1.0 / timedelta(days=28.9).total_seconds() f = 1.0e-4 # Coriolis parameter. start_lon = [10000.0] # Define the start longitude and latitude for the particle. start_lat = [10000.0] @@ -75,9 +77,9 @@ def decaying_moving_example( fieldset, pclass=ptype[mode], lon=start_lon, lat=start_lat ) - dt = delta(minutes=5) - runtime = delta(days=2) - outputdt = delta(hours=1) + dt = timedelta(minutes=5) + runtime = timedelta(days=2) + outputdt = timedelta(hours=1) pset.execute( method, diff --git a/docs/examples/example_globcurrent.py b/docs/examples/example_globcurrent.py index cf64579a28..663d0dd310 100755 --- a/docs/examples/example_globcurrent.py +++ b/docs/examples/example_globcurrent.py @@ -1,4 +1,4 @@ -from datetime import timedelta as delta +from datetime import timedelta from glob import glob import numpy as np @@ -90,8 +90,8 @@ def test_globcurrent_fieldset_advancetime(mode, dt, lonstart, latstart, use_xarr psetsub[0].time_nextloop = fieldsetsub.U.grid.time[-1] psetall[0].time_nextloop = fieldsetall.U.grid.time[-1] - psetsub.execute(parcels.AdvectionRK4, runtime=delta(days=7), dt=dt) - psetall.execute(parcels.AdvectionRK4, runtime=delta(days=7), dt=dt) + psetsub.execute(parcels.AdvectionRK4, runtime=timedelta(days=7), dt=dt) + psetall.execute(parcels.AdvectionRK4, runtime=timedelta(days=7), dt=dt) assert abs(psetsub[0].lon - psetall[0].lon) < 1e-4 @@ -106,7 +106,9 @@ def test_globcurrent_particles(mode, use_xarray): pset = parcels.ParticleSet(fieldset, pclass=ptype[mode], lon=lonstart, lat=latstart) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=1), dt=delta(minutes=5)) + pset.execute( + parcels.AdvectionRK4, runtime=timedelta(days=1), dt=timedelta(minutes=5) + ) assert abs(pset[0].lon - 23.8) < 1 assert abs(pset[0].lat - -35.3) < 1 @@ -118,7 +120,7 @@ def test_globcurrent_time_periodic(mode, rundays): sample_var = [] for deferred_load in [True, False]: fieldset = set_globcurrent_fieldset( - time_periodic=delta(days=365), deferred_load=deferred_load + time_periodic=timedelta(days=365), deferred_load=deferred_load ) MyParticle = ptype[mode].add_variable("sample_var", initial=0.0) @@ -131,7 +133,7 @@ def SampleU(particle, fieldset, time): u, v = fieldset.UV[time, particle.depth, particle.lat, particle.lon] particle.sample_var += u - pset.execute(SampleU, runtime=delta(days=rundays), dt=delta(days=1)) + pset.execute(SampleU, runtime=timedelta(days=rundays), dt=timedelta(days=1)) sample_var.append(pset[0].sample_var) assert np.allclose(sample_var[0], sample_var[1]) @@ -141,7 +143,7 @@ def SampleU(particle, fieldset, time): def test_globcurrent_xarray_vs_netcdf(dt): fieldsetNetcdf = set_globcurrent_fieldset(use_xarray=False) fieldsetxarray = set_globcurrent_fieldset(use_xarray=True) - lonstart, latstart, runtime = (25, -35, delta(days=7)) + lonstart, latstart, runtime = (25, -35, timedelta(days=7)) psetN = parcels.ParticleSet( fieldsetNetcdf, pclass=parcels.JITParticle, lon=lonstart, lat=latstart @@ -162,7 +164,7 @@ def test_globcurrent_netcdf_timestamps(dt): fieldsetNetcdf = set_globcurrent_fieldset() timestamps = fieldsetNetcdf.U.grid.timeslices fieldsetTimestamps = set_globcurrent_fieldset(timestamps=timestamps) - lonstart, latstart, runtime = (25, -35, delta(days=7)) + lonstart, latstart, runtime = (25, -35, timedelta(days=7)) psetN = parcels.ParticleSet( fieldsetNetcdf, pclass=parcels.JITParticle, lon=lonstart, lat=latstart @@ -229,10 +231,12 @@ def test_globcurrent_time_extrapolation_error(mode, use_xarray): pclass=ptype[mode], lon=[25], lat=[-35], - time=fieldset.U.time[0] - delta(days=1).total_seconds(), + time=fieldset.U.time[0] - timedelta(days=1).total_seconds(), ) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=1), dt=delta(minutes=5)) + pset.execute( + parcels.AdvectionRK4, runtime=timedelta(days=1), dt=timedelta(minutes=5) + ) @pytest.mark.parametrize("mode", ["scipy", "jit"]) @@ -270,12 +274,14 @@ def SampleP(particle, fieldset, time): with pytest.raises(parcels.TimeExtrapolationError): pset.execute( pset.Kernel(parcels.AdvectionRK4) + SampleP, - runtime=delta(days=1), + runtime=timedelta(days=1), dt=dt, ) else: pset.execute( - pset.Kernel(parcels.AdvectionRK4) + SampleP, runtime=delta(days=1), dt=dt + pset.Kernel(parcels.AdvectionRK4) + SampleP, + runtime=timedelta(days=1), + dt=dt, ) @@ -294,8 +300,8 @@ def DeleteP0(particle, fieldset, time): pset0.execute( pset0.Kernel(DeleteP0) + parcels.AdvectionRK4, - runtime=delta(days=rundays), - dt=delta(minutes=5), + runtime=timedelta(days=rundays), + dt=timedelta(minutes=5), ) pset1 = parcels.ParticleSet( @@ -303,7 +309,7 @@ def DeleteP0(particle, fieldset, time): ) pset1.execute( - parcels.AdvectionRK4, runtime=delta(days=rundays), dt=delta(minutes=5) + parcels.AdvectionRK4, runtime=timedelta(days=rundays), dt=timedelta(minutes=5) ) assert np.allclose([pset0[-1].lon, pset0[-1].lat], [pset1[-1].lon, pset1[-1].lat]) @@ -318,16 +324,18 @@ def test_globcurrent_pset_fromfile(mode, dt, pid_offset, tmpdir): ptype[mode].setLastID(pid_offset) pset = parcels.ParticleSet(fieldset, pclass=ptype[mode], lon=25, lat=-35) - pfile = pset.ParticleFile(filename, outputdt=delta(hours=6)) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=1), dt=dt, output_file=pfile) + pfile = pset.ParticleFile(filename, outputdt=timedelta(hours=6)) + pset.execute( + parcels.AdvectionRK4, runtime=timedelta(days=1), dt=dt, output_file=pfile + ) pfile.write_latest_locations(pset, max(pset.time_nextloop)) restarttime = np.nanmax if dt > 0 else np.nanmin pset_new = parcels.ParticleSet.from_particlefile( fieldset, pclass=ptype[mode], filename=filename, restarttime=restarttime ) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=1), dt=dt) - pset_new.execute(parcels.AdvectionRK4, runtime=delta(days=1), dt=dt) + pset.execute(parcels.AdvectionRK4, runtime=timedelta(days=1), dt=dt) + pset_new.execute(parcels.AdvectionRK4, runtime=timedelta(days=1), dt=dt) for var in ["lon", "lat", "depth", "time", "id"]: assert np.allclose( @@ -345,10 +353,10 @@ def test_error_outputdt_not_multiple_dt(mode, tmpdir): dt = 81.2584344538292 # number for which output writing fails pset = parcels.ParticleSet(fieldset, pclass=ptype[mode], lon=[0], lat=[0]) - ofile = pset.ParticleFile(name=filepath, outputdt=delta(days=1)) + ofile = pset.ParticleFile(name=filepath, outputdt=timedelta(days=1)) def DoNothing(particle, fieldset, time): pass with pytest.raises(ValueError): - pset.execute(DoNothing, runtime=delta(days=10), dt=dt, output_file=ofile) + pset.execute(DoNothing, runtime=timedelta(days=10), dt=dt, output_file=ofile) diff --git a/docs/examples/example_mitgcm.py b/docs/examples/example_mitgcm.py index 7644efe30e..dcc52781a0 100644 --- a/docs/examples/example_mitgcm.py +++ b/docs/examples/example_mitgcm.py @@ -1,4 +1,4 @@ -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import xarray as xr @@ -44,12 +44,12 @@ def periodicBC(particle, fieldset, time): pfile = parcels.ParticleFile( "MIT_particles_" + str(mode) + ".zarr", pset, - outputdt=delta(days=1), + outputdt=timedelta(days=1), chunks=(len(pset), 1), ) kernels = parcels.AdvectionRK4 + pset.Kernel(periodicBC) pset.execute( - kernels, runtime=delta(days=5), dt=delta(minutes=30), output_file=pfile + kernels, runtime=timedelta(days=5), dt=timedelta(minutes=30), output_file=pfile ) diff --git a/docs/examples/example_moving_eddies.py b/docs/examples/example_moving_eddies.py index 6c5b0d1ab0..21b5fd211f 100644 --- a/docs/examples/example_moving_eddies.py +++ b/docs/examples/example_moving_eddies.py @@ -1,7 +1,7 @@ import gc import math from argparse import ArgumentParser -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -145,13 +145,13 @@ def moving_eddies_example( print(f"Initial particle positions:\n{pset}") # Execute for 1 week, with 1 hour timesteps and hourly output - runtime = delta(days=7) + runtime = timedelta(days=7) print("MovingEddies: Advecting %d particles for %s" % (npart, str(runtime))) pset.execute( method, runtime=runtime, - dt=delta(hours=1), - output_file=pset.ParticleFile(name=outfile, outputdt=delta(hours=1)), + dt=timedelta(hours=1), + output_file=pset.ParticleFile(name=outfile, outputdt=timedelta(hours=1)), ) if verbose: @@ -174,9 +174,9 @@ def test_moving_eddies_fwdbwd(mode, mesh, tmpdir, npart=2): ) # Execte for 14 days, with 30sec timesteps and hourly output - runtime = delta(days=1) - dt = delta(minutes=5) - outputdt = delta(hours=1) + runtime = timedelta(days=1) + dt = timedelta(minutes=5) + outputdt = timedelta(hours=1) print("MovingEddies: Advecting %d particles for %s" % (npart, str(runtime))) outfile = tmpdir.join("EddyParticlefwd") pset.execute( @@ -284,7 +284,7 @@ def slowlySouthWestward(particle, fieldset, time): particle_dlat -= 3 * particle.dt / 1e5 # noqa kernels = pset.Kernel(parcels.AdvectionRK4) + slowlySouthWestward + periodicBC - pset.execute(kernels, runtime=delta(days=6), dt=delta(hours=1)) + pset.execute(kernels, runtime=timedelta(days=6), dt=timedelta(hours=1)) def main(args=None): diff --git a/docs/examples/example_nemo_curvilinear.py b/docs/examples/example_nemo_curvilinear.py index 61c8be41ee..181733a373 100644 --- a/docs/examples/example_nemo_curvilinear.py +++ b/docs/examples/example_nemo_curvilinear.py @@ -1,7 +1,7 @@ """Example script that runs a set of particles in a NEMO curvilinear grid.""" from argparse import ArgumentParser -from datetime import timedelta as delta +from datetime import timedelta from glob import glob import numpy as np @@ -42,19 +42,19 @@ def run_nemo_curvilinear(mode, outfile, advtype="RK4"): lonp = 30 * np.ones(npart) if advtype == "RK4": latp = np.linspace(-70, 88, npart) - runtime = delta(days=160) + runtime = timedelta(days=160) else: latp = np.linspace(-70, 70, npart) - runtime = delta(days=15) + runtime = timedelta(days=15) def periodicBC(particle, fieldSet, time): if particle.lon > 180: particle_dlon -= 360 # noqa pset = parcels.ParticleSet.from_list(fieldset, ptype[mode], lon=lonp, lat=latp) - pfile = parcels.ParticleFile(outfile, pset, outputdt=delta(days=1)) + pfile = parcels.ParticleFile(outfile, pset, outputdt=timedelta(days=1)) kernels = pset.Kernel(advection[advtype]) + periodicBC - pset.execute(kernels, runtime=runtime, dt=delta(hours=6), output_file=pfile) + pset.execute(kernels, runtime=runtime, dt=timedelta(hours=6), output_file=pfile) assert np.allclose(pset.lat - latp, 0, atol=2e-2) diff --git a/docs/examples/example_ofam.py b/docs/examples/example_ofam.py index 80961e4acc..791d890ffd 100644 --- a/docs/examples/example_ofam.py +++ b/docs/examples/example_ofam.py @@ -1,5 +1,5 @@ import gc -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -46,11 +46,11 @@ def test_ofam_fieldset_fillvalues(use_xarray): assert fieldset.V.data[0, 0, 150] == 0 -@pytest.mark.parametrize("dt", [delta(minutes=-5), delta(minutes=5)]) +@pytest.mark.parametrize("dt", [timedelta(minutes=-5), timedelta(minutes=5)]) def test_ofam_xarray_vs_netcdf(dt): fieldsetNetcdf = set_ofam_fieldset(use_xarray=False) fieldsetxarray = set_ofam_fieldset(use_xarray=True) - lonstart, latstart, runtime = (180, 10, delta(days=7)) + lonstart, latstart, runtime = (180, 10, timedelta(days=7)) psetN = parcels.ParticleSet( fieldsetNetcdf, pclass=parcels.JITParticle, lon=lonstart, lat=latstart @@ -80,7 +80,9 @@ def test_ofam_particles(mode, use_xarray): fieldset, pclass=ptype[mode], lon=lonstart, lat=latstart, depth=depstart ) - pset.execute(parcels.AdvectionRK4, runtime=delta(days=10), dt=delta(minutes=5)) + pset.execute( + parcels.AdvectionRK4, runtime=timedelta(days=10), dt=timedelta(minutes=5) + ) assert abs(pset[0].lon - 173) < 1 assert abs(pset[0].lat - 11) < 1 diff --git a/docs/examples/example_peninsula.py b/docs/examples/example_peninsula.py index 057ca20a43..3299d638ca 100644 --- a/docs/examples/example_peninsula.py +++ b/docs/examples/example_peninsula.py @@ -1,7 +1,7 @@ import gc import math # NOQA from argparse import ArgumentParser -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -161,11 +161,13 @@ def peninsula_example( print(f"Initial particle positions:\n{pset}") # Advect the particles for 24h - time = delta(hours=24) - dt = delta(minutes=5) + time = timedelta(hours=24) + dt = timedelta(minutes=5) k_adv = pset.Kernel(method) k_p = pset.Kernel(UpdateP) - out = pset.ParticleFile(name=outfile, outputdt=delta(hours=1)) if output else None + out = ( + pset.ParticleFile(name=outfile, outputdt=timedelta(hours=1)) if output else None + ) print("Peninsula: Advecting %d particles for %s" % (npart, str(time))) pset.execute(k_adv + k_p, runtime=time, dt=dt, output_file=out) diff --git a/docs/examples/example_radial_rotation.py b/docs/examples/example_radial_rotation.py index 7f272c35b8..12ddb63794 100644 --- a/docs/examples/example_radial_rotation.py +++ b/docs/examples/example_radial_rotation.py @@ -1,5 +1,5 @@ import math -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -22,7 +22,7 @@ def radial_rotation_fieldset( U = np.zeros((ydim, xdim), dtype=np.float32) V = np.zeros((ydim, xdim), dtype=np.float32) - T = delta(days=1) + T = timedelta(days=1) omega = 2 * np.pi / T.total_seconds() # Define the rotational period as 1 day. for i in range(lon.size): @@ -64,9 +64,9 @@ def rotation_example(fieldset, outfile, mode="jit", method=parcels.AdvectionRK4) finish=(30.0, 50.0), ) # One particle in centre, one on periphery of Field. - runtime = delta(hours=17) - dt = delta(minutes=5) - outputdt = delta(hours=1) + runtime = timedelta(hours=17) + dt = timedelta(minutes=5) + outputdt = timedelta(hours=1) pset.execute( method, diff --git a/docs/examples/example_stommel.py b/docs/examples/example_stommel.py index a9b52f85fd..58150eec6c 100755 --- a/docs/examples/example_stommel.py +++ b/docs/examples/example_stommel.py @@ -1,6 +1,6 @@ import math from argparse import ArgumentParser -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -121,9 +121,9 @@ def stommel_example( ParticleClass = parcels.JITParticle if mode == "jit" else parcels.ScipyParticle # Execute for 600 days, with 1-hour timesteps and 5-day output - runtime = delta(days=600) - dt = delta(hours=1) - outputdt = delta(days=5) + runtime = timedelta(days=600) + dt = timedelta(hours=1) + outputdt = timedelta(days=5) extra_vars = [ parcels.Variable("p", dtype=np.float32, initial=0.0), diff --git a/docs/examples/tutorial_analyticaladvection.ipynb b/docs/examples/tutorial_analyticaladvection.ipynb index a4d4333edd..59f036ea9f 100644 --- a/docs/examples/tutorial_analyticaladvection.ipynb +++ b/docs/examples/tutorial_analyticaladvection.ipynb @@ -52,7 +52,7 @@ "metadata": {}, "outputs": [], "source": [ - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", @@ -94,7 +94,7 @@ " def calc_r_phi(ln, lt):\n", " return np.sqrt(ln**2 + lt**2), np.arctan2(ln, lt)\n", "\n", - " omega = 2 * np.pi / delta(days=1).total_seconds()\n", + " omega = 2 * np.pi / timedelta(days=1).total_seconds()\n", " for i in range(lon.size):\n", " for j in range(lat.size):\n", " r, phi = calc_r_phi(lon[i], lat[j])\n", @@ -156,12 +156,12 @@ "\n", "pset = parcels.ParticleSet(fieldsetRR, pclass=MyParticle, lon=0, lat=4e3, time=0)\n", "\n", - "output = pset.ParticleFile(name=\"radialAnalytical.zarr\", outputdt=delta(hours=1))\n", + "output = pset.ParticleFile(name=\"radialAnalytical.zarr\", outputdt=timedelta(hours=1))\n", "\n", "pset.execute(\n", " pset.Kernel(UpdateR) + parcels.AdvectionAnalytical,\n", - " runtime=delta(hours=25),\n", - " dt=delta(hours=1), # needs to be the same as outputdt for Analytical Advection\n", + " runtime=timedelta(hours=25),\n", + " dt=timedelta(hours=1), # needs to be the same as outputdt for Analytical Advection\n", " output_file=output,\n", ")" ] @@ -14865,12 +14865,12 @@ " fieldsetBJ, pclass=parcels.ScipyParticle, lon=X, lat=Y, time=0\n", ")\n", "\n", - "output = psetAA.ParticleFile(name=\"bickleyjetAA.zarr\", outputdt=delta(hours=1))\n", + "output = psetAA.ParticleFile(name=\"bickleyjetAA.zarr\", outputdt=timedelta(hours=1))\n", "\n", "psetAA.execute(\n", " parcels.AdvectionAnalytical + psetAA.Kernel(ZonalBC),\n", - " dt=delta(hours=1), # needs to be the same as outputdt for Analytical Advection\n", - " runtime=delta(days=1),\n", + " dt=timedelta(hours=1), # needs to be the same as outputdt for Analytical Advection\n", + " runtime=timedelta(days=1),\n", " output_file=output,\n", ")" ] @@ -28009,7 +28009,7 @@ "psetRK4 = parcels.ParticleSet(fieldsetBJ, pclass=parcels.JITParticle, lon=X, lat=Y)\n", "\n", "psetRK4.execute(\n", - " [parcels.AdvectionRK4, ZonalBC], dt=delta(minutes=5), runtime=delta(days=1)\n", + " [parcels.AdvectionRK4, ZonalBC], dt=timedelta(minutes=5), runtime=timedelta(days=1)\n", ")" ] }, diff --git a/docs/examples/tutorial_delaystart.ipynb b/docs/examples/tutorial_delaystart.ipynb index 8935e99583..1ed477b148 100644 --- a/docs/examples/tutorial_delaystart.ipynb +++ b/docs/examples/tutorial_delaystart.ipynb @@ -24,7 +24,7 @@ "metadata": {}, "outputs": [], "source": [ - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", @@ -90,7 +90,7 @@ "lat = np.linspace(3e3, 45e3, npart, dtype=np.float32)\n", "\n", "# release every particle one hour later\n", - "time = np.arange(0, npart) * delta(hours=1).total_seconds()\n", + "time = np.arange(0, npart) * timedelta(hours=1).total_seconds()\n", "\n", "pset = parcels.ParticleSet(\n", " fieldset=fieldset, pclass=parcels.JITParticle, lon=lon, lat=lat, time=time\n", @@ -120,12 +120,14 @@ } ], "source": [ - "output_file = pset.ParticleFile(name=\"DelayParticle_time.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(\n", + " name=\"DelayParticle_time.zarr\", outputdt=timedelta(hours=1)\n", + ")\n", "\n", "pset.execute(\n", " parcels.AdvectionRK4,\n", - " runtime=delta(hours=24),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(hours=24),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")" ] @@ -10043,7 +10045,7 @@ "npart = 10 # number of particles to be released\n", "lon = 3e3 * np.ones(npart)\n", "lat = np.linspace(3e3, 45e3, npart, dtype=np.float32)\n", - "repeatdt = delta(hours=3) # release from the same set of locations every 3h\n", + "repeatdt = timedelta(hours=3) # release from the same set of locations every 3h\n", "\n", "pset = parcels.ParticleSet(\n", " fieldset=fieldset, pclass=parcels.JITParticle, lon=lon, lat=lat, repeatdt=repeatdt\n", @@ -10074,12 +10076,14 @@ } ], "source": [ - "output_file = pset.ParticleFile(name=\"DelayParticle_releasedt\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(\n", + " name=\"DelayParticle_releasedt\", outputdt=timedelta(hours=1)\n", + ")\n", "\n", "pset.execute(\n", " parcels.AdvectionRK4,\n", - " runtime=delta(hours=24),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(hours=24),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")" ] @@ -21262,14 +21266,14 @@ " fieldset=fieldset, pclass=parcels.JITParticle, lon=lon, lat=lat, repeatdt=repeatdt\n", ")\n", "output_file = pset.ParticleFile(\n", - " name=\"DelayParticle_releasedt_9hrs\", outputdt=delta(hours=1)\n", + " name=\"DelayParticle_releasedt_9hrs\", outputdt=timedelta(hours=1)\n", ")\n", "\n", "# first run for 3 * 3 hrs\n", "pset.execute(\n", " parcels.AdvectionRK4,\n", - " runtime=delta(hours=9),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(hours=9),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")\n", "\n", @@ -21279,8 +21283,8 @@ "# now continue running for the remaining 15 hours\n", "pset.execute(\n", " parcels.AdvectionRK4,\n", - " runtime=delta(hours=15),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(hours=15),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")" ] diff --git a/docs/examples/tutorial_jit_vs_scipy.ipynb b/docs/examples/tutorial_jit_vs_scipy.ipynb index a74da9fc69..5db839c87a 100644 --- a/docs/examples/tutorial_jit_vs_scipy.ipynb +++ b/docs/examples/tutorial_jit_vs_scipy.ipynb @@ -49,7 +49,7 @@ } ], "source": [ - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "\n", "import parcels\n", "\n", @@ -81,7 +81,9 @@ " )\n", "\n", " ptimer[p].start()\n", - " pset.execute(parcels.AdvectionRK4, runtime=delta(hours=1), dt=delta(seconds=30))\n", + " pset.execute(\n", + " parcels.AdvectionRK4, runtime=timedelta(hours=1), dt=timedelta(seconds=30)\n", + " )\n", " ptimer[p].stop()\n", "\n", "parcels.timer.root.stop()\n", @@ -193,7 +195,7 @@ " )\n", "\n", " ptimer[k].start()\n", - " pset.execute(kernels[k], runtime=delta(hours=1), dt=delta(seconds=30))\n", + " pset.execute(kernels[k], runtime=timedelta(hours=1), dt=timedelta(seconds=30))\n", " ptimer[k].stop()\n", "\n", "parcels.timer.root.stop()\n", @@ -270,7 +272,7 @@ " )\n", "\n", " ptimer[k].start()\n", - " pset.execute(kernels[k], runtime=delta(days=10), dt=delta(hours=6))\n", + " pset.execute(kernels[k], runtime=timedelta(days=10), dt=timedelta(hours=6))\n", " ptimer[k].stop()\n", "\n", "parcels.timer.root.stop()\n", diff --git a/docs/examples/tutorial_nemo_3D.ipynb b/docs/examples/tutorial_nemo_3D.ipynb index d5ccd8db2e..722d48b7a9 100644 --- a/docs/examples/tutorial_nemo_3D.ipynb +++ b/docs/examples/tutorial_nemo_3D.ipynb @@ -52,7 +52,7 @@ } ], "source": [ - "from datetime import timedelta as delta\n", + "from datetime import timetimedelta\n", "from glob import glob\n", "\n", "import matplotlib.pyplot as plt\n", @@ -105,7 +105,7 @@ ")\n", "\n", "kernels = pset.Kernel(parcels.AdvectionRK4_3D)\n", - "pset.execute(kernels, runtime=delta(days=4), dt=delta(hours=6))" + "pset.execute(kernels, runtime=timedelta(days=4), dt=timedelta(hours=6))" ] }, { diff --git a/docs/examples/tutorial_nemo_curvilinear.ipynb b/docs/examples/tutorial_nemo_curvilinear.ipynb index c0f85a7948..0fe55d0e4e 100644 --- a/docs/examples/tutorial_nemo_curvilinear.ipynb +++ b/docs/examples/tutorial_nemo_curvilinear.ipynb @@ -24,7 +24,7 @@ "metadata": {}, "outputs": [], "source": [ - "from datetime import timedelta as delta\n", + "from datetime import timetimedelta\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", @@ -178,10 +178,13 @@ "latp = [i for i in np.linspace(-70, 85, npart)]\n", "\n", "pset = parcels.ParticleSet.from_list(fieldset, parcels.JITParticle, lon=lonp, lat=latp)\n", - "pfile = parcels.ParticleFile(\"nemo_particles\", pset, outputdt=delta(days=1))\n", + "pfile = parcels.ParticleFile(\"nemo_particles\", pset, outputdt=timedelta(days=1))\n", "\n", "pset.execute(\n", - " parcels.AdvectionRK4, runtime=delta(days=30), dt=delta(hours=6), output_file=pfile\n", + " parcels.AdvectionRK4,\n", + " runtime=timedelta(days=30),\n", + " dt=timedelta(hours=6),\n", + " output_file=pfile,\n", ")" ] }, diff --git a/docs/examples/tutorial_output.ipynb b/docs/examples/tutorial_output.ipynb index 9588f590bf..f98e6972c9 100644 --- a/docs/examples/tutorial_output.ipynb +++ b/docs/examples/tutorial_output.ipynb @@ -30,7 +30,7 @@ "metadata": {}, "outputs": [], "source": [ - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "\n", "import numpy as np\n", "\n", @@ -62,18 +62,18 @@ "lat = np.linspace(3e3, 45e3, npart, dtype=np.float32)\n", "\n", "# release every particle two hours later\n", - "time = np.arange(npart) * delta(hours=2).total_seconds()\n", + "time = np.arange(npart) * timedelta(hours=2).total_seconds()\n", "\n", "pset = parcels.ParticleSet(\n", " fieldset=fieldset, pclass=parcels.JITParticle, lon=lon, lat=lat, time=time\n", ")\n", "\n", - "output_file = pset.ParticleFile(name=\"Output.zarr\", outputdt=delta(hours=2))\n", + "output_file = pset.ParticleFile(name=\"Output.zarr\", outputdt=timedelta(hours=2))\n", "\n", "pset.execute(\n", " parcels.AdvectionRK4,\n", - " runtime=delta(hours=24),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(hours=24),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")" ] @@ -329,8 +329,8 @@ "\n", "timerange = np.arange(\n", " np.nanmin(data_xarray[\"time\"].values),\n", - " np.nanmax(data_xarray[\"time\"].values) + np.timedelta64(delta(hours=2)),\n", - " delta(hours=2),\n", + " np.nanmax(data_xarray[\"time\"].values) + np.timedelta64(timedelta(hours=2)),\n", + " timedelta(hours=2),\n", ") # timerange in nanoseconds\n", "\n", "for time in timerange:\n", @@ -459,7 +459,7 @@ "from IPython.display import HTML\n", "from matplotlib.animation import FuncAnimation\n", "\n", - "outputdt = delta(hours=2)\n", + "outputdt = timedelta(hours=2)\n", "\n", "# timerange in nanoseconds\n", "timerange = np.arange(\n", diff --git a/docs/examples/tutorial_particle_field_interaction.ipynb b/docs/examples/tutorial_particle_field_interaction.ipynb index 5db019c27f..c8c2f7196d 100644 --- a/docs/examples/tutorial_particle_field_interaction.ipynb +++ b/docs/examples/tutorial_particle_field_interaction.ipynb @@ -43,7 +43,7 @@ "metadata": {}, "outputs": [], "source": [ - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "\n", "import matplotlib.pyplot as plt\n", "import netCDF4\n", @@ -244,16 +244,16 @@ } ], "source": [ - "output_file = pset.ParticleFile(name=r\"interaction.zarr\", outputdt=delta(days=1))\n", + "output_file = pset.ParticleFile(name=r\"interaction.zarr\", outputdt=timedelta(days=1))\n", "\n", "pset.execute(\n", " # the particle will FIRST be transported by currents\n", " # and THEN interact with the field\n", " parcels.AdvectionRK4 + pset.Kernel(Interaction),\n", - " dt=delta(days=1),\n", + " dt=timedelta(days=1),\n", " # we are going to track the particle and save\n", " # its trajectory and tracer concentration for 24 days\n", - " runtime=delta(days=25),\n", + " runtime=timedelta(days=25),\n", " output_file=output_file,\n", ")\n", "\n", diff --git a/docs/examples/tutorial_periodic_boundaries.ipynb b/docs/examples/tutorial_periodic_boundaries.ipynb index d093508e55..8f25e27f46 100644 --- a/docs/examples/tutorial_periodic_boundaries.ipynb +++ b/docs/examples/tutorial_periodic_boundaries.ipynb @@ -63,7 +63,7 @@ "outputs": [], "source": [ "import math\n", - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "\n", "import matplotlib.pyplot as plt\n", "import xarray as xr\n", @@ -167,12 +167,12 @@ " finish=(20e3, 45e3),\n", ")\n", "\n", - "output_file = pset.ParticleFile(name=\"PeriodicParticle\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(name=\"PeriodicParticle\", outputdt=timedelta(hours=1))\n", "\n", "pset.execute(\n", " [parcels.AdvectionRK4, periodicBC],\n", - " runtime=delta(hours=24),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(hours=24),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")" ] diff --git a/docs/examples/tutorial_sampling.ipynb b/docs/examples/tutorial_sampling.ipynb index 4473e2d788..e568d969a2 100644 --- a/docs/examples/tutorial_sampling.ipynb +++ b/docs/examples/tutorial_sampling.ipynb @@ -39,7 +39,7 @@ "outputs": [], "source": [ "# Modules needed for the Parcels simulation\n", - "from datetime import timedelta as delta\n", + "from datetime import timedelta\n", "\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", @@ -89,7 +89,7 @@ "lon = 3e3 * np.ones(npart)\n", "lat = np.linspace(3e3, 45e3, npart, dtype=np.float32)\n", "time = (\n", - " np.arange(0, npart) * delta(hours=2).total_seconds()\n", + " np.arange(0, npart) * timedelta(hours=2).total_seconds()\n", ") # release each particle two hours later\n", "\n", "# Plot temperature field and initial particle locations\n", @@ -156,12 +156,12 @@ " fieldset=fieldset, pclass=SampleParticle, lon=lon, lat=lat, time=time\n", ")\n", "\n", - "output_file = pset.ParticleFile(name=\"SampleTemp.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(name=\"SampleTemp.zarr\", outputdt=timedelta(hours=1))\n", "\n", "pset.execute(\n", " [parcels.AdvectionRK4, SampleT],\n", - " runtime=delta(hours=30),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(hours=30),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")" ] @@ -372,12 +372,12 @@ } ], "source": [ - "output_file = pset.ParticleFile(name=\"WriteOnce.zarr\", outputdt=delta(hours=1))\n", + "output_file = pset.ParticleFile(name=\"WriteOnce.zarr\", outputdt=timedelta(hours=1))\n", "\n", "pset.execute(\n", " [parcels.AdvectionRK4, SampleT],\n", - " runtime=delta(hours=24),\n", - " dt=delta(minutes=5),\n", + " runtime=timedelta(hours=24),\n", + " dt=timedelta(minutes=5),\n", " output_file=output_file,\n", ")" ] diff --git a/docs/examples/tutorial_timevaryingdepthdimensions.ipynb b/docs/examples/tutorial_timevaryingdepthdimensions.ipynb index 349e713466..8f89b89be2 100644 --- a/docs/examples/tutorial_timevaryingdepthdimensions.ipynb +++ b/docs/examples/tutorial_timevaryingdepthdimensions.ipynb @@ -22,11 +22,9 @@ "metadata": {}, "outputs": [], "source": [ - "from datetime import timedelta as delta\n", - "from os import path\n", + "from datetime import timedelta\n", "\n", "import matplotlib.pyplot as plt\n", - "import numpy as np\n", "import xarray as xr\n", "\n", "import parcels" @@ -130,9 +128,9 @@ "source": [ "pset = parcels.ParticleSet(fieldset, parcels.JITParticle, lon=9.5, lat=12.5, depth=-0.1)\n", "\n", - "pfile = pset.ParticleFile(\"SwashParticles\", outputdt=delta(seconds=0.05))\n", + "pfile = pset.ParticleFile(\"SwashParticles\", outputdt=timedelta(seconds=0.05))\n", "\n", - "pset.execute(parcels.AdvectionRK4, dt=delta(seconds=0.005), output_file=pfile)" + "pset.execute(parcels.AdvectionRK4, dt=timedelta(seconds=0.005), output_file=pfile)" ] }, { diff --git a/parcels/particlefile.py b/parcels/particlefile.py index e301f137b5..3044b8142e 100644 --- a/parcels/particlefile.py +++ b/parcels/particlefile.py @@ -1,7 +1,7 @@ """Module controlling the writing of ParticleSets to Zarr file.""" import os from abc import ABC -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import xarray as xr @@ -61,7 +61,7 @@ class ParticleFile(ABC): def __init__(self, name, particleset, outputdt=np.inf, chunks=None, create_new_zarrfile=True): - self.outputdt = outputdt.total_seconds() if isinstance(outputdt, delta) else outputdt + self.outputdt = outputdt.total_seconds() if isinstance(outputdt, timedelta) else outputdt self.chunks = chunks self.particleset = particleset self.parcels_mesh = 'spherical' @@ -202,7 +202,7 @@ def write(self, pset, time, indices=None): time : Time at which to write ParticleSet """ - time = time.total_seconds() if isinstance(time, delta) else time + time = time.total_seconds() if isinstance(time, timedelta) else time if pset.particledata._ncount == 0: logger.warning("ParticleSet is empty on writing as array at time %g" % time) diff --git a/parcels/particleset.py b/parcels/particleset.py index a62004b6fb..35c0d7bb23 100644 --- a/parcels/particleset.py +++ b/parcels/particleset.py @@ -2,8 +2,7 @@ import sys from abc import ABC from copy import copy -from datetime import date, datetime -from datetime import timedelta as delta +from datetime import date, datetime, timedelta import cftime import numpy as np @@ -187,7 +186,7 @@ def ArrayClass_init(self, *args, **kwargs): assert lon.size == kwargs[kwvar].size, ( f"{kwvar} and positions (lon, lat, depth) don't have the same lengths.") - self.repeatdt = repeatdt.total_seconds() if isinstance(repeatdt, delta) else repeatdt + self.repeatdt = repeatdt.total_seconds() if isinstance(repeatdt, timedelta) else repeatdt if self.repeatdt: if self.repeatdt <= 0: raise 'Repeatdt should be > 0' @@ -868,7 +867,7 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime= self.interaction_kernel = self.InteractionKernel(pyfunc_inter, delete_cfiles=delete_cfiles) # Convert all time variables to seconds - if isinstance(endtime, delta): + if isinstance(endtime, timedelta): raise RuntimeError('endtime must be either a datetime or a double') if isinstance(endtime, datetime): endtime = np.datetime64(endtime) @@ -878,18 +877,18 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime= if self.time_origin.calendar is None: raise NotImplementedError('If fieldset.time_origin is not a date, execution endtime must be a double') endtime = self.time_origin.reltime(endtime) - if isinstance(runtime, delta): + if isinstance(runtime, timedelta): runtime = runtime.total_seconds() - if isinstance(dt, delta): + if isinstance(dt, timedelta): dt = dt.total_seconds() if abs(dt) <= 1e-6: raise ValueError('Time step dt is too small') if (dt * 1e6) % 1 != 0: raise ValueError('Output interval should not have finer precision than 1e-6 s') outputdt = output_file.outputdt if output_file else np.inf - if isinstance(outputdt, delta): + if isinstance(outputdt, timedelta): outputdt = outputdt.total_seconds() - if isinstance(callbackdt, delta): + if isinstance(callbackdt, timedelta): callbackdt = callbackdt.total_seconds() assert runtime is None or runtime >= 0, 'runtime must be positive' diff --git a/parcels/tools/converters.py b/parcels/tools/converters.py index 71ffdf9b5c..5f9e8205ef 100644 --- a/parcels/tools/converters.py +++ b/parcels/tools/converters.py @@ -1,6 +1,6 @@ # flake8: noqa: E999 import inspect -from datetime import timedelta as delta +from datetime import timedelta from math import cos, pi import cftime @@ -116,7 +116,7 @@ def fulltime(self, time): else: return self.time_origin + np.timedelta64(int(time), 's') elif self.calendar in _get_cftime_calendars(): - return self.time_origin + delta(seconds=time) + return self.time_origin + timedelta(seconds=time) elif self.calendar is None: return self.time_origin + time else: diff --git a/tests/test_advection.py b/tests/test_advection.py index 50b9cd3320..be50999113 100644 --- a/tests/test_advection.py +++ b/tests/test_advection.py @@ -1,5 +1,5 @@ import math -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -74,7 +74,7 @@ def test_advection_zonal(lon, lat, depth, mode, npart=10): pset2D = ParticleSet(fieldset2D, pclass=ptype[mode], lon=np.zeros(npart) + 20., lat=np.linspace(0, 80, npart)) - pset2D.execute(AdvectionRK4, runtime=delta(hours=2), dt=delta(seconds=30)) + pset2D.execute(AdvectionRK4, runtime=timedelta(hours=2), dt=timedelta(seconds=30)) assert (np.diff(pset2D.lon) > 1.e-4).all() dimensions['depth'] = depth @@ -83,7 +83,7 @@ def test_advection_zonal(lon, lat, depth, mode, npart=10): lon=np.zeros(npart) + 20., lat=np.linspace(0, 80, npart), depth=np.zeros(npart) + 10.) - pset3D.execute(AdvectionRK4, runtime=delta(hours=2), dt=delta(seconds=30)) + pset3D.execute(AdvectionRK4, runtime=timedelta(hours=2), dt=timedelta(seconds=30)) assert (np.diff(pset3D.lon) > 1.e-4).all() @@ -99,7 +99,7 @@ def test_advection_meridional(lon, lat, mode, npart=10): lon=np.linspace(-60, 60, npart), lat=np.linspace(0, 30, npart)) delta_lat = np.diff(pset.lat) - pset.execute(AdvectionRK4, runtime=delta(hours=2), dt=delta(seconds=30)) + pset.execute(AdvectionRK4, runtime=timedelta(hours=2), dt=timedelta(seconds=30)) assert np.allclose(np.diff(pset.lat), delta_lat, rtol=1.e-4) @@ -119,8 +119,8 @@ def test_advection_3D(mode, npart=11): lon=np.zeros(npart), lat=np.zeros(npart) + 1e2, depth=np.linspace(0, 1, npart)) - time = delta(hours=2).total_seconds() - pset.execute(AdvectionRK4, runtime=time, dt=delta(seconds=30)) + time = timedelta(hours=2).total_seconds() + pset.execute(AdvectionRK4, runtime=time, dt=timedelta(seconds=30)) assert np.allclose(pset.depth*pset.time, pset.lon, atol=1.e-1) @@ -175,12 +175,12 @@ def test_advection_RK45(lon, lat, mode, rk45_tol, npart=10): fieldset = FieldSet.from_data(data2D, dimensions, mesh='spherical', transpose=True) fieldset.add_constant('RK45_tol', rk45_tol) - dt = delta(seconds=30).total_seconds() + dt = timedelta(seconds=30).total_seconds() RK45Particles = ptype[mode].add_variable('next_dt', dtype=np.float32, initial=dt) pset = ParticleSet(fieldset, pclass=RK45Particles, lon=np.zeros(npart) + 20., lat=np.linspace(0, 80, npart)) - pset.execute(AdvectionRK45, runtime=delta(hours=2), dt=dt) + pset.execute(AdvectionRK45, runtime=timedelta(hours=2), dt=dt) assert (np.diff(pset.lon) > 1.e-4).all() assert np.isclose(fieldset.RK45_tol, rk45_tol/(1852*60)) print(fieldset.RK45_tol) @@ -207,7 +207,7 @@ def test_advection_periodic_zonal(mode, xdim=100, ydim=100, halosize=3): assert len(fieldset.U.lon) == xdim + 2 * halosize pset = ParticleSet(fieldset, pclass=ptype[mode], lon=[0.5], lat=[0.5]) - pset.execute(AdvectionRK4 + pset.Kernel(periodicBC), runtime=delta(hours=20), dt=delta(seconds=30)) + pset.execute(AdvectionRK4 + pset.Kernel(periodicBC), runtime=timedelta(hours=20), dt=timedelta(seconds=30)) assert abs(pset.lon[0] - 0.15) < 0.1 @@ -218,7 +218,7 @@ def test_advection_periodic_meridional(mode, xdim=100, ydim=100): assert len(fieldset.U.lat) == ydim + 10 # default halo size is 5 grid points pset = ParticleSet(fieldset, pclass=ptype[mode], lon=[0.5], lat=[0.5]) - pset.execute(AdvectionRK4 + pset.Kernel(periodicBC), runtime=delta(hours=20), dt=delta(seconds=30)) + pset.execute(AdvectionRK4 + pset.Kernel(periodicBC), runtime=timedelta(hours=20), dt=timedelta(seconds=30)) assert abs(pset.lat[0] - 0.15) < 0.1 @@ -232,7 +232,7 @@ def test_advection_periodic_zonal_meridional(mode, xdim=100, ydim=100): assert np.allclose(np.diff(fieldset.U.lon), fieldset.U.lon[1]-fieldset.U.lon[0], rtol=0.001) pset = ParticleSet(fieldset, pclass=ptype[mode], lon=[0.4], lat=[0.5]) - pset.execute(AdvectionRK4 + pset.Kernel(periodicBC), runtime=delta(hours=20), dt=delta(seconds=30)) + pset.execute(AdvectionRK4 + pset.Kernel(periodicBC), runtime=timedelta(hours=20), dt=timedelta(seconds=30)) assert abs(pset.lon[0] - 0.05) < 0.1 assert abs(pset.lat[0] - 0.15) < 0.1 @@ -287,7 +287,7 @@ def truth_stationary(x_0, y_0, t): @pytest.fixture -def fieldset_stationary(xdim=100, ydim=100, maxtime=delta(hours=6)): +def fieldset_stationary(xdim=100, ydim=100, maxtime=timedelta(hours=6)): """Generate a FieldSet encapsulating the flow field of a stationary eddy. Reference: N. Fabbroni, 2009, "Numerical simulations of passive @@ -322,8 +322,8 @@ def test_stationary_eddy(fieldset_stationary, mode, method, rtol, diffField, npa fieldset.add_constant('dres', 0.1) lon = np.linspace(12000, 21000, npart) lat = np.linspace(12500, 12500, npart) - dt = delta(minutes=3).total_seconds() - endtime = delta(hours=6).total_seconds() + dt = timedelta(minutes=3).total_seconds() + endtime = timedelta(hours=6).total_seconds() RK45Particles = ptype[mode].add_variable('next_dt', dtype=np.float32, initial=dt) @@ -342,8 +342,8 @@ def test_stationary_eddy_vertical(mode, npart=1): lon = np.linspace(12000, 21000, npart) lat = np.linspace(10000, 20000, npart) depth = np.linspace(12500, 12500, npart) - endtime = delta(hours=6).total_seconds() - dt = delta(minutes=3).total_seconds() + endtime = timedelta(hours=6).total_seconds() + dt = timedelta(minutes=3).total_seconds() xdim = ydim = 100 lon_data = np.linspace(0, 25000, xdim, dtype=np.float32) @@ -385,7 +385,7 @@ def truth_moving(x_0, y_0, t): @pytest.fixture -def fieldset_moving(xdim=100, ydim=100, maxtime=delta(hours=6)): +def fieldset_moving(xdim=100, ydim=100, maxtime=timedelta(hours=6)): """Generate a FieldSet encapsulating the flow field of a moving eddy. Reference: N. Fabbroni, 2009, "Numerical simulations of passive @@ -415,8 +415,8 @@ def test_moving_eddy(fieldset_moving, mode, method, rtol, diffField, npart=1): fieldset.add_constant('dres', 0.1) lon = np.linspace(12000, 21000, npart) lat = np.linspace(12500, 12500, npart) - dt = delta(minutes=3).total_seconds() - endtime = delta(hours=6).total_seconds() + dt = timedelta(minutes=3).total_seconds() + endtime = timedelta(hours=6).total_seconds() RK45Particles = ptype[mode].add_variable('next_dt', dtype=np.float32, initial=dt) @@ -441,7 +441,7 @@ def truth_decaying(x_0, y_0, t): @pytest.fixture -def fieldset_decaying(xdim=100, ydim=100, maxtime=delta(hours=6)): +def fieldset_decaying(xdim=100, ydim=100, maxtime=timedelta(hours=6)): """Generate a FieldSet encapsulating the flow field of a decaying eddy. Reference: N. Fabbroni, 2009, "Numerical simulations of passive @@ -480,8 +480,8 @@ def test_decaying_eddy(fieldset_decaying, mode, method, rtol, diffField, npart=1 fieldset.add_constant('dres', 0.1) lon = np.linspace(12000, 21000, npart) lat = np.linspace(12500, 12500, npart) - dt = delta(minutes=3).total_seconds() - endtime = delta(hours=6).total_seconds() + dt = timedelta(minutes=3).total_seconds() + endtime = timedelta(hours=6).total_seconds() RK45Particles = ptype[mode].add_variable('next_dt', dtype=np.float32, initial=dt) diff --git a/tests/test_diffusion.py b/tests/test_diffusion.py index 02af182534..132df3c09f 100644 --- a/tests/test_diffusion.py +++ b/tests/test_diffusion.py @@ -1,4 +1,4 @@ -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -41,11 +41,11 @@ def test_fieldKh_Brownian(mesh, mode, xdim=200, ydim=100, kh_zonal=100, kh_merid fieldset.add_constant_field("Kh_meridional", kh_meridional, mesh=mesh) npart = 1000 - runtime = delta(days=1) + runtime = timedelta(days=1) ParcelsRandom.seed(1234) pset = ParticleSet(fieldset=fieldset, pclass=ptype[mode], lon=np.zeros(npart), lat=np.zeros(npart)) - pset.execute(pset.Kernel(DiffusionUniformKh), runtime=runtime, dt=delta(hours=1)) + pset.execute(pset.Kernel(DiffusionUniformKh), runtime=runtime, dt=timedelta(hours=1)) expected_std_lon = np.sqrt(2*kh_zonal*mesh_conversion**2*runtime.total_seconds()) expected_std_lat = np.sqrt(2*kh_meridional*mesh_conversion**2*runtime.total_seconds()) @@ -79,11 +79,11 @@ def test_fieldKh_SpatiallyVaryingDiffusion(mesh, mode, kernel, xdim=200, ydim=10 fieldset.add_constant('dres', fieldset.U.lon[1]-fieldset.U.lon[0]) npart = 100 - runtime = delta(days=1) + runtime = timedelta(days=1) ParcelsRandom.seed(1636) pset = ParticleSet(fieldset=fieldset, pclass=ptype[mode], lon=np.zeros(npart), lat=np.zeros(npart)) - pset.execute(pset.Kernel(kernel), runtime=runtime, dt=delta(hours=1)) + pset.execute(pset.Kernel(kernel), runtime=runtime, dt=timedelta(hours=1)) lats = pset.lat lons = pset.lon diff --git a/tests/test_fieldset.py b/tests/test_fieldset.py index 4b8b383e7a..23dc7944cc 100644 --- a/tests/test_fieldset.py +++ b/tests/test_fieldset.py @@ -2,7 +2,7 @@ import gc import os import sys -from datetime import timedelta as delta +from datetime import timedelta import cftime import dask @@ -720,7 +720,7 @@ def periodicBoundaryConditions(particle, fieldset, time): mem_0 = process.memory_info().rss mem_exhausted = False try: - pset.execute(pset.Kernel(AdvectionRK4)+periodicBoundaryConditions, dt=dt, runtime=delta(days=7), postIterationCallbacks=postProcessFuncs, callbackdt=delta(hours=12)) + pset.execute(pset.Kernel(AdvectionRK4)+periodicBoundaryConditions, dt=dt, runtime=timedelta(days=7), postIterationCallbacks=postProcessFuncs, callbackdt=timedelta(hours=12)) except MemoryError: mem_exhausted = True mem_steps_np = np.array(perflog.memory_steps) @@ -770,9 +770,9 @@ def test_timestamps(datetype, tmpdir): fieldset2.U.data[0, :, :] = 0. fieldset2.write(tmpdir.join('file2')) - fieldset3 = FieldSet.from_parcels(tmpdir.join('file*'), time_periodic=delta(days=14)) + fieldset3 = FieldSet.from_parcels(tmpdir.join('file*'), time_periodic=timedelta(days=14)) timestamps = [dims1['time'], dims2['time']] - fieldset4 = FieldSet.from_parcels(tmpdir.join('file*'), timestamps=timestamps, time_periodic=delta(days=14)) + fieldset4 = FieldSet.from_parcels(tmpdir.join('file*'), timestamps=timestamps, time_periodic=timedelta(days=14)) assert np.allclose(fieldset3.U.grid.time_full, fieldset4.U.grid.time_full) for d in [0, 8, 10, 13]: @@ -842,7 +842,7 @@ def sampleTemp(particle, fieldset, time): ]) pset = ParticleSet.from_list(fieldset, pclass=MyParticle, lon=[0.5], lat=[0.5], depth=[0.5]) - pset.execute(AdvectionRK4_3D + pset.Kernel(sampleTemp), runtime=delta(hours=51), dt=delta(hours=dt_sign*1)) + pset.execute(AdvectionRK4_3D + pset.Kernel(sampleTemp), runtime=timedelta(hours=51), dt=timedelta(hours=dt_sign*1)) if time_periodic is not False: t = pset.time[0] @@ -882,7 +882,7 @@ def test_fieldset_defer_loading_with_diff_time_origin(tmpdir, fail, filename='te assert fieldset.U.creation_log == 'from_parcels' pset = ParticleSet.from_list(fieldset, pclass=JITParticle, lon=[0.5], lat=[0.5], depth=[0.5], time=[datetime.datetime(2018, 4, 20, 1)]) - pset.execute(AdvectionRK4_3D, runtime=delta(hours=4), dt=delta(hours=1)) + pset.execute(AdvectionRK4_3D, runtime=timedelta(hours=4), dt=timedelta(hours=1)) @pytest.mark.parametrize('zdim', [2, 8]) diff --git a/tests/test_fieldset_sampling.py b/tests/test_fieldset_sampling.py index 2bed43725a..f232f9612b 100644 --- a/tests/test_fieldset_sampling.py +++ b/tests/test_fieldset_sampling.py @@ -1,4 +1,4 @@ -from datetime import timedelta as delta +from datetime import timedelta from math import cos, pi import numpy as np @@ -484,9 +484,9 @@ def test_meridionalflow_spherical(mode, xdim=100, ydim=200): lonstart = [0, 45] latstart = [0, 45] - runtime = delta(hours=24) + runtime = timedelta(hours=24) pset = ParticleSet(fieldset, pclass=pclass(mode), lon=lonstart, lat=latstart) - pset.execute(pset.Kernel(AdvectionRK4), runtime=runtime, dt=delta(hours=1)) + pset.execute(pset.Kernel(AdvectionRK4), runtime=runtime, dt=timedelta(hours=1)) assert pset.lat[0] - (latstart[0] + runtime.total_seconds() * maxvel / 1852 / 60) < 1e-4 assert pset.lon[0] - lonstart[0] < 1e-4 @@ -513,10 +513,10 @@ def test_zonalflow_spherical(mode, k_sample_p, xdim=100, ydim=200): lonstart = [0, 45] latstart = [0, 45] - runtime = delta(hours=24) + runtime = timedelta(hours=24) pset = ParticleSet(fieldset, pclass=pclass(mode), lon=lonstart, lat=latstart) pset.execute(pset.Kernel(AdvectionRK4) + k_sample_p, - runtime=runtime, dt=delta(hours=1)) + runtime=runtime, dt=timedelta(hours=1)) assert pset.lat[0] - latstart[0] < 1e-4 assert pset.lon[0] - (lonstart[0] + runtime.total_seconds() * maxvel / 1852 / 60 diff --git a/tests/test_grids.py b/tests/test_grids.py index 9553386a31..f01237e2ed 100644 --- a/tests/test_grids.py +++ b/tests/test_grids.py @@ -1,6 +1,6 @@ import math import os -from datetime import timedelta as delta +from datetime import timedelta import numpy as np import pytest @@ -408,7 +408,7 @@ def test_advect_nemo(mode): lonp = 175.5 latp = 81.5 pset = ParticleSet.from_list(fieldset, ptype[mode], lon=[lonp], lat=[latp]) - pset.execute(AdvectionRK4, runtime=delta(days=2), dt=delta(hours=6)) + pset.execute(AdvectionRK4, runtime=timedelta(days=2), dt=timedelta(hours=6)) assert abs(pset.lat[0] - latp) < 1e-3 @@ -633,7 +633,7 @@ def test_cgrid_indexing(mode, gridindexingtype, coordtype): lon = np.linspace(-a / 2, a / 2, xdim, dtype=np.float32) lat = np.linspace(-b / 2, b / 2, ydim, dtype=np.float32) dx, dy = lon[2] - lon[1], lat[2] - lat[1] - omega = 2 * np.pi / delta(days=1).total_seconds() + omega = 2 * np.pi / timedelta(days=1).total_seconds() index_signs = {'nemo': -1, 'mitgcm': 1} isign = index_signs[gridindexingtype] @@ -703,7 +703,7 @@ def UpdateR(particle, fieldset, time): pset = ParticleSet(fieldset, pclass=MyParticle, lon=0, lat=4e3, time=0) pset.execute(pset.Kernel(UpdateR) + AdvectionRK4, - runtime=delta(hours=14), dt=delta(minutes=5)) + runtime=timedelta(hours=14), dt=timedelta(minutes=5)) assert np.allclose(pset.radius, pset.radius_start, atol=10) @@ -719,7 +719,7 @@ def test_cgrid_indexing_3D(mode, gridindexingtype, withtime): lat = np.linspace(-b / 2, b / 2, ydim, dtype=np.float32) depth = np.linspace(-c / 2, c / 2, zdim, dtype=np.float32) dx, dz = lon[1] - lon[0], depth[1] - depth[0] - omega = 2 * np.pi / delta(days=1).total_seconds() + omega = 2 * np.pi / timedelta(days=1).total_seconds() if withtime: time = np.linspace(0, 24*60*60, 10) dimensions = {"lon": lon, "lat": lat, "depth": depth, "time": time} @@ -781,7 +781,7 @@ def UpdateR(particle, fieldset, time): pset = ParticleSet(fieldset, pclass=MyParticle, depth=4e3, lon=0, lat=0, time=0) pset.execute(pset.Kernel(UpdateR) + AdvectionRK4_3D, - runtime=delta(hours=14), dt=delta(minutes=5)) + runtime=timedelta(hours=14), dt=timedelta(minutes=5)) assert np.allclose(pset.radius, pset.radius_start, atol=10) @@ -797,7 +797,7 @@ def test_bgrid_indexing_3D(mode, gridindexingtype, withtime): lat = np.linspace(-b / 2, b / 2, ydim, dtype=np.float32) depth = np.linspace(-c / 2, c / 2, zdim, dtype=np.float32) dx, dz = lon[1] - lon[0], depth[1] - depth[0] - omega = 2 * np.pi / delta(days=1).total_seconds() + omega = 2 * np.pi / timedelta(days=1).total_seconds() if withtime: time = np.linspace(0, 24*60*60, 10) dimensions = {"lon": lon, "lat": lat, "depth": depth, "time": time} @@ -860,7 +860,7 @@ def UpdateR(particle, fieldset, time): pset = ParticleSet(fieldset, pclass=MyParticle, depth=-9.995e3, lon=0, lat=0, time=0) pset.execute(pset.Kernel(UpdateR) + AdvectionRK4_3D, - runtime=delta(hours=14), dt=delta(minutes=5)) + runtime=timedelta(hours=14), dt=timedelta(minutes=5)) assert np.allclose(pset.radius, pset.radius_start, atol=10)