Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 7 additions & 9 deletions docs/user_guide/examples/explanation_kernelloop.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Besides having commutable Kernels, the main advantage of this implementation is
Below is a simple example of some particles at the surface of the ocean. We create an idealised zonal wind flow that will "push" a particle that is already affected by the surface currents. The Kernel loop ensures that these two forces act at the same time and location.

```{code-cell}
:tags: [hide-output]
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
Expand All @@ -69,21 +70,18 @@ ds_fields["VWind"] = xr.DataArray(

fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)

# Set unit converters for custom wind fields
fieldset.UWind.units = parcels.GeographicPolar()
fieldset.VWind.units = parcels.Geographic()
# Create a vecorfield for the wind
windvector = parcels.VectorField("Wind", fieldset.UWind, fieldset.VWind)
fieldset.add_field(windvector)
```

Now we define a wind kernel that uses a forward Euler method to apply the wind forcing. Note that we update the `particles.dlon` and `particles.dlat` variables, rather than `particles.lon` and `particles.lat` directly.

```{code-cell}
def wind_kernel(particles, fieldset):
particles.dlon += (
fieldset.UWind[particles] * particles.dt
)
particles.dlat += (
fieldset.VWind[particles] * particles.dt
)
uwind, vwind = fieldset.Wind[particles]
particles.dlon += uwind * particles.dt
particles.dlat += vwind * particles.dt
```

First run a simulation where we apply kernels as `[AdvectionRK4, wind_kernel]`
Expand Down
10 changes: 5 additions & 5 deletions docs/user_guide/examples/tutorial_dt_integrators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
"U_max_surface = np.nanmax(np.hypot(ds_fields.uo, ds_fields.vo))\n",
"print(f\"U_max = {str(np.round(U_max_surface, 2))} m s-1\")\n",
"\n",
"# convert to degrees s-1 (at lat = 30 deg S, lon = 31 deg E)\n",
"U_max_surface_deg = parcels.GeographicPolar().to_target(U_max_surface, 0, -30, 31)\n",
"# convert to degrees s-1 (at lat = 30 deg S)\n",
"U_max_surface_deg = U_max_surface / (1852 * 60 * np.cos(np.deg2rad(-30)))\n",
"print(f\" == {str(np.round(U_max_surface_deg * 1e5, 2))}e-5 degrees s-1\")"
]
},
Expand All @@ -135,7 +135,7 @@
"source": [
"```{admonition} 🖥️ Spherical grids and unit converters\n",
":class: seealso\n",
"Our displacement occurs in units of longitude and latitde, but our velocity field is in m/s. Read the [UnitConversion guide](./tutorial_unitconverters.ipynb) to see how Parcels uses `parcels.GeographicPolar()` under the hood to convert from m s<sup>-1</sup> to degrees s<sup>-1</sup>.\n",
"Our displacement occurs in units of longitude and latitde, but our velocity field is in m/s. That's why we have to convert the units of velocity from m/s to degrees/s. In Parcels, this is done automatically for `VectorFields` when using a `spherical` grid. See the [UnitConversion guide](./tutorial_unitconverters.ipynb) guide for more information.\n",
"```"
]
},
Expand Down Expand Up @@ -822,7 +822,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "test-notebooks",
"display_name": "docs",
"language": "python",
"name": "python3"
},
Expand All @@ -836,7 +836,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.13.9"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down
4 changes: 0 additions & 4 deletions docs/user_guide/examples/tutorial_nemo_curvilinear.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@
"V = parcels.Field(\n",
" \"V\", ds_fields[\"V\"], grid, interp_method=parcels.interpolators.XLinear\n",
")\n",
"U.units = parcels.GeographicPolar()\n",
"V.units = (\n",
" parcels.GeographicPolar()\n",
") # U and V need GeographicPolar for C-Grid interpolation to work correctly\n",
"UV = parcels.VectorField(\n",
" \"UV\", U, V, vector_interp_method=parcels.interpolators.CGrid_Velocity\n",
")\n",
Expand Down
Loading
Loading