Skip to content

Commit 564204c

Browse files
Merge branch 'v4-dev' into structure_overview
2 parents 4378521 + 049d549 commit 564204c

35 files changed

Lines changed: 598 additions & 595 deletions

docs/getting_started/tutorial_output.ipynb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,9 @@
549549
"\n",
550550
"# Create animation\n",
551551
"anim = FuncAnimation(fig, animate, frames=nframes, interval=100)\n",
552+
"plt.close(fig)\n",
552553
"anim"
553554
]
554-
},
555-
{
556-
"cell_type": "code",
557-
"execution_count": null,
558-
"metadata": {},
559-
"outputs": [],
560-
"source": []
561555
}
562556
],
563557
"metadata": {

docs/user_guide/examples/explanation_kernelloop.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ Now we define a wind kernel that uses a forward Euler method to apply the wind f
7878

7979
```{code-cell}
8080
def wind_kernel(particles, fieldset):
81-
dt_float = particles.dt / np.timedelta64(1, 's')
8281
particles.dlon += (
83-
fieldset.UWind[particles] * dt_float
82+
fieldset.UWind[particles] * particles.dt
8483
)
8584
particles.dlat += (
86-
fieldset.VWind[particles] * dt_float
85+
fieldset.VWind[particles] * particles.dt
8786
)
8887
```
8988

docs/user_guide/examples/tutorial_Argofloats.ipynb

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,54 +30,44 @@
3030
"driftdepth = 1000 # maximum depth in m\n",
3131
"maxdepth = 2000 # maximum depth in m\n",
3232
"vertical_speed = 0.10 # sink and rise speed in m/s\n",
33-
"cycletime = (\n",
34-
" 10 * 86400\n",
35-
") # total time of cycle in seconds # TODO update to \"timedelta64[s]\"\n",
33+
"cycletime = 10 * 86400 # total time of cycle in seconds\n",
3634
"drifttime = 9 * 86400 # time of deep drift in seconds\n",
3735
"\n",
3836
"\n",
3937
"def ArgoPhase1(particles, fieldset):\n",
40-
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
41-
"\n",
4238
" def SinkingPhase(p):\n",
4339
" \"\"\"Phase 0: Sinking with vertical_speed until depth is driftdepth\"\"\"\n",
44-
" p.dz += vertical_speed * dt\n",
40+
" p.dz += vertical_speed * particles.dt\n",
4541
" p.cycle_phase = np.where(p.z + p.dz >= driftdepth, 1, p.cycle_phase)\n",
4642
" p.dz = np.where(p.z + p.dz >= driftdepth, driftdepth - p.z, p.dz)\n",
4743
"\n",
4844
" SinkingPhase(particles[particles.cycle_phase == 0])\n",
4945
"\n",
5046
"\n",
5147
"def ArgoPhase2(particles, fieldset):\n",
52-
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
53-
"\n",
5448
" def DriftingPhase(p):\n",
5549
" \"\"\"Phase 1: Drifting at depth for drifttime seconds\"\"\"\n",
56-
" p.drift_age += dt\n",
50+
" p.drift_age += particles.dt\n",
5751
" p.cycle_phase = np.where(p.drift_age >= drifttime, 2, p.cycle_phase)\n",
5852
" p.drift_age = np.where(p.drift_age >= drifttime, 0, p.drift_age)\n",
5953
"\n",
6054
" DriftingPhase(particles[particles.cycle_phase == 1])\n",
6155
"\n",
6256
"\n",
6357
"def ArgoPhase3(particles, fieldset):\n",
64-
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
65-
"\n",
6658
" def SecondSinkingPhase(p):\n",
6759
" \"\"\"Phase 2: Sinking further to maxdepth\"\"\"\n",
68-
" p.dz += vertical_speed * dt\n",
60+
" p.dz += vertical_speed * particles.dt\n",
6961
" p.cycle_phase = np.where(p.z + p.dz >= maxdepth, 3, p.cycle_phase)\n",
7062
" p.dz = np.where(p.z + p.dz >= maxdepth, maxdepth - p.z, p.dz)\n",
7163
"\n",
7264
" SecondSinkingPhase(particles[particles.cycle_phase == 2])\n",
7365
"\n",
7466
"\n",
7567
"def ArgoPhase4(particles, fieldset):\n",
76-
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
77-
"\n",
7868
" def RisingPhase(p):\n",
7969
" \"\"\"Phase 3: Rising with vertical_speed until at surface\"\"\"\n",
80-
" p.dz -= vertical_speed * dt\n",
70+
" p.dz -= vertical_speed * particles.dt\n",
8171
" p.temp = fieldset.thetao[p.time, p.z, p.lat, p.lon]\n",
8272
" p.cycle_phase = np.where(p.z + p.dz <= fieldset.mindepth, 4, p.cycle_phase)\n",
8373
" p.dz = np.where(\n",
@@ -100,8 +90,7 @@
10090
"\n",
10191
"\n",
10292
"def ArgoPhase6(particles, fieldset):\n",
103-
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
104-
" particles.cycle_age += dt # update cycle_age"
93+
" particles.cycle_age += particles.dt # update cycle_age"
10594
]
10695
},
10796
{
@@ -211,11 +200,7 @@
211200
"x = ds_particles[\"lon\"][:].squeeze()\n",
212201
"y = ds_particles[\"lat\"][:].squeeze()\n",
213202
"z = ds_particles[\"z\"][:].squeeze()\n",
214-
"time = (\n",
215-
" (ds_particles[\"time\"][:].squeeze() - fieldset.time_interval.left).astype(float)\n",
216-
" / 1e9\n",
217-
" / 86400\n",
218-
") # convert time to days\n",
203+
"time = ds_particles[\"time\"][:].squeeze()\n",
219204
"temp = ds_particles[\"temp\"][:].squeeze()"
220205
]
221206
},

docs/user_guide/examples/tutorial_delaystart.ipynb

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27-
"from datetime import timedelta\n",
28-
"\n",
2927
"import matplotlib.pyplot as plt\n",
3028
"import numpy as np\n",
3129
"import xarray as xr\n",
32-
"from IPython.display import HTML\n",
3330
"from matplotlib.animation import FuncAnimation\n",
3431
"\n",
35-
"import parcels"
32+
"import parcels\n",
33+
"\n",
34+
"# for interactive display of animations\n",
35+
"plt.rcParams[\"animation.html\"] = \"jshtml\""
3636
]
3737
},
3838
{
@@ -138,8 +138,6 @@
138138
"metadata": {},
139139
"outputs": [],
140140
"source": [
141-
"%%capture\n",
142-
"\n",
143141
"ds_particles = xr.open_zarr(\"delayparticle_time.zarr\")\n",
144142
"\n",
145143
"fig = plt.figure(figsize=(7, 5), constrained_layout=True)\n",
@@ -173,16 +171,9 @@
173171
" )\n",
174172
"\n",
175173
"\n",
176-
"anim = FuncAnimation(fig, animate, frames=len(timerange), interval=100)"
177-
]
178-
},
179-
{
180-
"cell_type": "code",
181-
"execution_count": null,
182-
"metadata": {},
183-
"outputs": [],
184-
"source": [
185-
"HTML(anim.to_jshtml())"
174+
"anim = FuncAnimation(fig, animate, frames=len(timerange), interval=100)\n",
175+
"plt.close()\n",
176+
"anim"
186177
]
187178
},
188179
{
@@ -261,13 +252,13 @@
261252
"outputs": [],
262253
"source": [
263254
"output_file = parcels.ParticleFile(\n",
264-
" \"delayparticle_releasedt.zarr\", outputdt=timedelta(hours=1)\n",
255+
" \"delayparticle_releasedt.zarr\", outputdt=np.timedelta64(1, \"h\")\n",
265256
")\n",
266257
"\n",
267258
"pset.execute(\n",
268259
" parcels.kernels.AdvectionRK4,\n",
269-
" runtime=timedelta(hours=24),\n",
270-
" dt=timedelta(minutes=5),\n",
260+
" runtime=np.timedelta64(24, \"h\"),\n",
261+
" dt=np.timedelta64(5, \"h\"),\n",
271262
" output_file=output_file,\n",
272263
")"
273264
]
@@ -286,8 +277,6 @@
286277
"metadata": {},
287278
"outputs": [],
288279
"source": [
289-
"%%capture\n",
290-
"\n",
291280
"ds_particles = xr.open_zarr(\"delayparticle_releasedt.zarr\")\n",
292281
"\n",
293282
"fig = plt.figure(figsize=(7, 5), constrained_layout=True)\n",
@@ -321,16 +310,9 @@
321310
" )\n",
322311
"\n",
323312
"\n",
324-
"anim = FuncAnimation(fig, animate, frames=len(timerange), interval=100)"
325-
]
326-
},
327-
{
328-
"cell_type": "code",
329-
"execution_count": null,
330-
"metadata": {},
331-
"outputs": [],
332-
"source": [
333-
"HTML(anim.to_jshtml())"
313+
"anim = FuncAnimation(fig, animate, frames=len(timerange), interval=100)\n",
314+
"plt.close(fig)\n",
315+
"anim"
334316
]
335317
},
336318
{

0 commit comments

Comments
 (0)