Skip to content

Commit

Permalink
Remove delta alias for timedelta
Browse files Browse the repository at this point in the history
  • Loading branch information
VeckoTheGecko committed Aug 2, 2024
1 parent d87e47b commit f6a62ed
Show file tree
Hide file tree
Showing 33 changed files with 249 additions and 213 deletions.
10 changes: 5 additions & 5 deletions docs/examples/documentation_MPI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)"
]
},
Expand Down
1 change: 0 additions & 1 deletion docs/examples/documentation_indexing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 14 additions & 9 deletions docs/examples/documentation_stuck_particles.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
")"
]
},
Expand Down Expand Up @@ -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",
")"
]
Expand Down Expand Up @@ -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",
")"
]
Expand Down
16 changes: 9 additions & 7 deletions docs/examples/documentation_unstuck_Agrid.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)"
]
},
{
Expand All @@ -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)"
]
Expand Down Expand Up @@ -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)"
]
Expand Down Expand Up @@ -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)"
]
Expand Down Expand Up @@ -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)"
]
Expand Down
6 changes: 3 additions & 3 deletions docs/examples/example_brownian.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import timedelta as delta
from datetime import timedelta

import numpy as np
import pytest
Expand Down Expand Up @@ -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())
Expand Down
26 changes: 18 additions & 8 deletions docs/examples/example_dask_chunk_OCMs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
from datetime import timedelta as delta
from datetime import timedelta
from glob import glob

import dask
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 [
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:]]
Expand Down
14 changes: 8 additions & 6 deletions docs/examples/example_decaying_moving_eddy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import timedelta as delta
from datetime import timedelta

import numpy as np
import pytest
Expand All @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit f6a62ed

Please sign in to comment.