Skip to content

Commit 9a6abf5

Browse files
Separating each Argo phase into its own Kernel
This fixes the issue that the cycle_phase is not updated correctly
1 parent dcdd2d1 commit 9a6abf5

File tree

1 file changed

+46
-17
lines changed

1 file changed

+46
-17
lines changed

docs/examples/tutorial_Argofloats.ipynb

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,45 @@
2424
"source": [
2525
"import numpy as np\n",
2626
"\n",
27+
"# Define the new Kernels that mimic Argo vertical movement\n",
28+
"driftdepth = 1000 # maximum depth in m\n",
29+
"maxdepth = 2000 # maximum depth in m\n",
30+
"vertical_speed = 0.10 # sink and rise speed in m/s\n",
31+
"cycletime = (\n",
32+
" 10 * 86400\n",
33+
") # total time of cycle in seconds # TODO update to \"timedelta64[s]\"\n",
34+
"drifttime = 9 * 86400 # time of deep drift in seconds\n",
2735
"\n",
28-
"# Define the new Kernel that mimics Argo vertical movement\n",
29-
"def ArgoVerticalMovement(particles, fieldset):\n",
30-
" driftdepth = 1000 # maximum depth in m\n",
31-
" maxdepth = 2000 # maximum depth in m\n",
32-
" 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",
36-
" drifttime = 9 * 86400 # time of deep drift in seconds\n",
3736
"\n",
37+
"def ArgoPhase1(particles, fieldset):\n",
3838
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
3939
"\n",
40-
" def SinkPhase(p):\n",
40+
" def SinkingPhase(p):\n",
4141
" \"\"\"Phase 0: Sinking with vertical_speed until depth is driftdepth\"\"\"\n",
4242
" p.ddepth += vertical_speed * dt\n",
4343
" p.cycle_phase = np.where(p.depth + p.ddepth >= driftdepth, 1, p.cycle_phase)\n",
4444
" p.ddepth = np.where(\n",
4545
" p.depth + p.ddepth >= driftdepth, driftdepth - p.depth, p.ddepth\n",
4646
" )\n",
4747
"\n",
48+
" SinkingPhase(particles[particles.cycle_phase == 0])\n",
49+
"\n",
50+
"\n",
51+
"def ArgoPhase2(particles, fieldset):\n",
52+
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
53+
"\n",
4854
" def DriftingPhase(p):\n",
4955
" \"\"\"Phase 1: Drifting at depth for drifttime seconds\"\"\"\n",
5056
" p.drift_age += dt\n",
5157
" p.cycle_phase = np.where(p.drift_age >= drifttime, 2, p.cycle_phase)\n",
5258
" p.drift_age = np.where(p.drift_age >= drifttime, 0, p.drift_age)\n",
5359
"\n",
60+
" DriftingPhase(particles[particles.cycle_phase == 1])\n",
61+
"\n",
62+
"\n",
63+
"def ArgoPhase3(particles, fieldset):\n",
64+
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
65+
"\n",
5466
" def SecondSinkingPhase(p):\n",
5567
" \"\"\"Phase 2: Sinking further to maxdepth\"\"\"\n",
5668
" p.ddepth += vertical_speed * dt\n",
@@ -59,6 +71,12 @@
5971
" p.depth + p.ddepth >= maxdepth, maxdepth - p.depth, p.ddepth\n",
6072
" )\n",
6173
"\n",
74+
" SecondSinkingPhase(particles[particles.cycle_phase == 2])\n",
75+
"\n",
76+
"\n",
77+
"def ArgoPhase4(particles, fieldset):\n",
78+
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
79+
"\n",
6280
" def RisingPhase(p):\n",
6381
" \"\"\"Phase 3: Rising with vertical_speed until at surface\"\"\"\n",
6482
" p.ddepth -= vertical_speed * dt\n",
@@ -67,17 +85,20 @@
6785
" p.depth + p.ddepth <= fieldset.mindepth, 4, p.cycle_phase\n",
6886
" )\n",
6987
"\n",
70-
" def TransmitPhase(p):\n",
88+
" RisingPhase(particles[particles.cycle_phase == 3])\n",
89+
"\n",
90+
"\n",
91+
"def ArgoPhase5(particles, fieldset):\n",
92+
" def TransmittingPhase(p):\n",
7193
" \"\"\"Phase 4: Transmitting at surface until cycletime is reached\"\"\"\n",
7294
" p.cycle_phase = np.where(p.cycle_age >= cycletime, 0, p.cycle_phase)\n",
7395
" p.cycle_age = np.where(p.cycle_age >= cycletime, 0, p.cycle_age)\n",
7496
"\n",
75-
" SinkPhase(particles[particles.cycle_phase == 0])\n",
76-
" DriftingPhase(particles[particles.cycle_phase == 1])\n",
77-
" SecondSinkingPhase(particles[particles.cycle_phase == 2])\n",
78-
" RisingPhase(particles[particles.cycle_phase == 3])\n",
79-
" TransmitPhase(particles[particles.cycle_phase == 4])\n",
97+
" TransmittingPhase(particles[particles.cycle_phase == 4])\n",
98+
"\n",
8099
"\n",
100+
"def ArgoPhase6(particles, fieldset):\n",
101+
" dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n",
81102
" particles.cycle_age += dt # update cycle_age"
82103
]
83104
},
@@ -162,7 +183,15 @@
162183
")\n",
163184
"\n",
164185
"# combine Argo vertical movement kernel with built-in Advection kernel\n",
165-
"kernels = [ArgoVerticalMovement, parcels.AdvectionRK4]\n",
186+
"kernels = [\n",
187+
" ArgoPhase1,\n",
188+
" ArgoPhase2,\n",
189+
" ArgoPhase3,\n",
190+
" ArgoPhase4,\n",
191+
" ArgoPhase5,\n",
192+
" ArgoPhase6,\n",
193+
" parcels.AdvectionRK4,\n",
194+
"]\n",
166195
"\n",
167196
"# Create a ParticleFile object to store the output\n",
168197
"output_file = parcels.ParticleFile(\n",

0 commit comments

Comments
 (0)