Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 19 additions & 30 deletions docs/user_guide/examples/tutorial_Argofloats.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -234,7 +223,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "docs",
"display_name": "Parcels:docs (3.14.4)",
"language": "python",
"name": "python3"
},
Expand Down
Loading