Skip to content

Commit 8480d1b

Browse files
Updating argo tutorial to use float dt
1 parent 69aa16b commit 8480d1b

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

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
},

0 commit comments

Comments
 (0)