diff --git a/docs/user_guide/examples/tutorial_Argofloats.ipynb b/docs/user_guide/examples/tutorial_Argofloats.ipynb index 6704bf262..d8bc62e03 100644 --- a/docs/user_guide/examples/tutorial_Argofloats.ipynb +++ b/docs/user_guide/examples/tutorial_Argofloats.ipynb @@ -27,7 +27,8 @@ "import numpy as np\n", "\n", "# Define the new Kernel that mimics Argo vertical movement\n", - "driftdepth = 1000 # maximum depth in m\n", + "mindepth = 1.0 # minimum depth in m\n", + "driftdepth = 1000 # maximum drift depth in m\n", "maxdepth = 2000 # maximum depth in m\n", "vertical_speed = 0.10 # sink and rise speed in m/s\n", "cycletime = 10 * 86400 # total time of cycle in seconds\n", @@ -44,42 +45,33 @@ "\n", " # Phase 0: Sinking with vertical_speed until depth is driftdepth\n", " ptcls0.dz += vertical_speed * ptcls0.dt\n", - " ptcls0.cycle_phase = np.where(\n", - " ptcls0.z + ptcls0.dz >= driftdepth, 1, ptcls0.cycle_phase\n", - " )\n", - " ptcls0.dz = np.where(\n", - " ptcls0.z + ptcls0.dz >= driftdepth, driftdepth - ptcls0.z, ptcls0.dz\n", - " )\n", + " next_phase = ptcls0.z + ptcls0.dz >= driftdepth\n", + " ptcls0.cycle_phase[next_phase] = 1\n", + " ptcls0.dz[next_phase] = driftdepth - ptcls0.z[next_phase] # avoid overshoot\n", "\n", " # Phase 1: Drifting at depth for drifttime seconds\n", " ptcls1.drift_age += ptcls1.dt\n", - " ptcls1.cycle_phase = np.where(ptcls1.drift_age >= drifttime, 2, ptcls1.cycle_phase)\n", - " ptcls1.drift_age = np.where(ptcls1.drift_age >= drifttime, 0, ptcls1.drift_age)\n", + " next_phase = ptcls1.drift_age >= drifttime\n", + " ptcls1.cycle_phase[next_phase] = 2\n", + " ptcls1.drift_age[next_phase] = 0 # reset drift_age for next cycle\n", "\n", " # Phase 2: Sinking further to maxdepth\n", " ptcls2.dz += vertical_speed * ptcls2.dt\n", - " ptcls2.cycle_phase = np.where(\n", - " ptcls2.z + ptcls2.dz >= maxdepth, 3, ptcls2.cycle_phase\n", - " )\n", - " ptcls2.dz = np.where(\n", - " ptcls2.z + ptcls2.dz >= maxdepth, maxdepth - ptcls2.z, ptcls2.dz\n", - " )\n", + " next_phase = ptcls2.z + ptcls2.dz >= maxdepth\n", + " ptcls2.cycle_phase[next_phase] = 3\n", + " ptcls2.dz[next_phase] = maxdepth - ptcls2.z[next_phase] # avoid overshoot\n", "\n", " # Phase 3: Rising with vertical_speed until at surface\n", " ptcls3.dz -= vertical_speed * ptcls3.dt\n", " ptcls3.temp = fieldset.thetao[ptcls3.time, ptcls3.z, ptcls3.lat, ptcls3.lon]\n", - " ptcls3.cycle_phase = np.where(\n", - " ptcls3.z + ptcls3.dz <= fieldset.mindepth, 4, ptcls3.cycle_phase\n", - " )\n", - " ptcls3.dz = np.where(\n", - " ptcls3.z + ptcls3.dz <= fieldset.mindepth,\n", - " fieldset.mindepth - ptcls3.z,\n", - " ptcls3.dz,\n", - " )\n", + " next_phase = ptcls3.z + ptcls3.dz <= mindepth\n", + " ptcls3.cycle_phase[next_phase] = 4\n", + " ptcls3.dz[next_phase] = mindepth - ptcls3.z[next_phase] # avoid overshoot\n", "\n", " # Phase 4: Transmitting at surface until cycletime is reached\n", - " ptcls4.cycle_phase = np.where(ptcls4.cycle_age >= cycletime, 0, ptcls4.cycle_phase)\n", - " ptcls4.cycle_age = np.where(ptcls4.cycle_age >= cycletime, 0, ptcls4.cycle_age)\n", + " next_phase = ptcls4.cycle_age >= cycletime\n", + " ptcls4.cycle_phase[next_phase] = 0\n", + " ptcls4.cycle_age[next_phase] = 0 # reset cycle_age for next cycle\n", " ptcls4.temp = np.nan # no temperature measurement when at surface\n", "\n", " particles.cycle_age += particles.dt # update cycle_age" @@ -107,8 +99,6 @@ "source": [ "from datetime import timedelta\n", "\n", - "import xarray as xr\n", - "\n", "import parcels\n", "import parcels.tutorial\n", "\n", @@ -130,7 +120,6 @@ "# Convert to SGRID-compliant dataset and create FieldSet\n", "ds_fset = parcels.convert.copernicusmarine_to_sgrid(fields=fields)\n", "fieldset = parcels.FieldSet.from_sgrid_conventions(ds_fset)\n", - "fieldset.add_constant(\"mindepth\", 1.0)\n", "\n", "# Define a new Particle type including extra Variables\n", "ArgoParticle = parcels.Particle.add_variable(\n", @@ -148,7 +137,7 @@ " pclass=ArgoParticle,\n", " lon=[32],\n", " lat=[-31],\n", - " z=[fieldset.mindepth],\n", + " z=[mindepth],\n", ")\n", "\n", "# combine Argo vertical movement Kernel with built-in Advection Kernel\n", @@ -234,7 +223,7 @@ ], "metadata": { "kernelspec": { - "display_name": "docs", + "display_name": "Parcels:docs (3.14.4)", "language": "python", "name": "python3" },