|
24 | 24 | "source": [ |
25 | 25 | "import numpy as np\n", |
26 | 26 | "\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", |
27 | 35 | "\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", |
37 | 36 | "\n", |
| 37 | + "def ArgoPhase1(particles, fieldset):\n", |
38 | 38 | " dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n", |
39 | 39 | "\n", |
40 | | - " def SinkPhase(p):\n", |
| 40 | + " def SinkingPhase(p):\n", |
41 | 41 | " \"\"\"Phase 0: Sinking with vertical_speed until depth is driftdepth\"\"\"\n", |
42 | 42 | " p.ddepth += vertical_speed * dt\n", |
43 | 43 | " p.cycle_phase = np.where(p.depth + p.ddepth >= driftdepth, 1, p.cycle_phase)\n", |
44 | 44 | " p.ddepth = np.where(\n", |
45 | 45 | " p.depth + p.ddepth >= driftdepth, driftdepth - p.depth, p.ddepth\n", |
46 | 46 | " )\n", |
47 | 47 | "\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", |
48 | 54 | " def DriftingPhase(p):\n", |
49 | 55 | " \"\"\"Phase 1: Drifting at depth for drifttime seconds\"\"\"\n", |
50 | 56 | " p.drift_age += dt\n", |
51 | 57 | " p.cycle_phase = np.where(p.drift_age >= drifttime, 2, p.cycle_phase)\n", |
52 | 58 | " p.drift_age = np.where(p.drift_age >= drifttime, 0, p.drift_age)\n", |
53 | 59 | "\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", |
54 | 66 | " def SecondSinkingPhase(p):\n", |
55 | 67 | " \"\"\"Phase 2: Sinking further to maxdepth\"\"\"\n", |
56 | 68 | " p.ddepth += vertical_speed * dt\n", |
|
59 | 71 | " p.depth + p.ddepth >= maxdepth, maxdepth - p.depth, p.ddepth\n", |
60 | 72 | " )\n", |
61 | 73 | "\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", |
62 | 80 | " def RisingPhase(p):\n", |
63 | 81 | " \"\"\"Phase 3: Rising with vertical_speed until at surface\"\"\"\n", |
64 | 82 | " p.ddepth -= vertical_speed * dt\n", |
|
67 | 85 | " p.depth + p.ddepth <= fieldset.mindepth, 4, p.cycle_phase\n", |
68 | 86 | " )\n", |
69 | 87 | "\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", |
71 | 93 | " \"\"\"Phase 4: Transmitting at surface until cycletime is reached\"\"\"\n", |
72 | 94 | " p.cycle_phase = np.where(p.cycle_age >= cycletime, 0, p.cycle_phase)\n", |
73 | 95 | " p.cycle_age = np.where(p.cycle_age >= cycletime, 0, p.cycle_age)\n", |
74 | 96 | "\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", |
80 | 99 | "\n", |
| 100 | + "def ArgoPhase6(particles, fieldset):\n", |
| 101 | + " dt = particles.dt / np.timedelta64(1, \"s\") # convert dt to seconds\n", |
81 | 102 | " particles.cycle_age += dt # update cycle_age" |
82 | 103 | ] |
83 | 104 | }, |
|
162 | 183 | ")\n", |
163 | 184 | "\n", |
164 | 185 | "# 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", |
166 | 195 | "\n", |
167 | 196 | "# Create a ParticleFile object to store the output\n", |
168 | 197 | "output_file = parcels.ParticleFile(\n", |
|
0 commit comments