Skip to content

Commit d609fdf

Browse files
Merge pull request #2465 from Parcels-code/removing_unit_converts_to_v4dev
Removing UnitConverters from v4 (attempt 2)
2 parents 2ba7720 + d7a3c1e commit d609fdf

19 files changed

+191
-454
lines changed

docs/user_guide/examples/explanation_kernelloop.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Besides having commutable Kernels, the main advantage of this implementation is
4343
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.
4444

4545
```{code-cell}
46+
:tags: [hide-output]
4647
import matplotlib.pyplot as plt
4748
import numpy as np
4849
import xarray as xr
@@ -69,21 +70,18 @@ ds_fields["VWind"] = xr.DataArray(
6970
7071
fieldset = parcels.FieldSet.from_copernicusmarine(ds_fields)
7172
72-
# Set unit converters for custom wind fields
73-
fieldset.UWind.units = parcels.GeographicPolar()
74-
fieldset.VWind.units = parcels.Geographic()
73+
# Create a vecorfield for the wind
74+
windvector = parcels.VectorField("Wind", fieldset.UWind, fieldset.VWind)
75+
fieldset.add_field(windvector)
7576
```
7677

7778
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.
7879

7980
```{code-cell}
8081
def wind_kernel(particles, fieldset):
81-
particles.dlon += (
82-
fieldset.UWind[particles] * particles.dt
83-
)
84-
particles.dlat += (
85-
fieldset.VWind[particles] * particles.dt
86-
)
82+
uwind, vwind = fieldset.Wind[particles]
83+
particles.dlon += uwind * particles.dt
84+
particles.dlat += vwind * particles.dt
8785
```
8886

8987
First run a simulation where we apply kernels as `[AdvectionRK4, wind_kernel]`

docs/user_guide/examples/tutorial_dt_integrators.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
"U_max_surface = np.nanmax(np.hypot(ds_fields.uo, ds_fields.vo))\n",
124124
"print(f\"U_max = {str(np.round(U_max_surface, 2))} m s-1\")\n",
125125
"\n",
126-
"# convert to degrees s-1 (at lat = 30 deg S, lon = 31 deg E)\n",
127-
"U_max_surface_deg = parcels.GeographicPolar().to_target(U_max_surface, 0, -30, 31)\n",
126+
"# convert to degrees s-1 (at lat = 30 deg S)\n",
127+
"U_max_surface_deg = U_max_surface / (1852 * 60 * np.cos(np.deg2rad(-30)))\n",
128128
"print(f\" == {str(np.round(U_max_surface_deg * 1e5, 2))}e-5 degrees s-1\")"
129129
]
130130
},
@@ -135,7 +135,7 @@
135135
"source": [
136136
"```{admonition} 🖥️ Spherical grids and unit converters\n",
137137
":class: seealso\n",
138-
"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",
138+
"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",
139139
"```"
140140
]
141141
},
@@ -822,7 +822,7 @@
822822
],
823823
"metadata": {
824824
"kernelspec": {
825-
"display_name": "test-notebooks",
825+
"display_name": "docs",
826826
"language": "python",
827827
"name": "python3"
828828
},
@@ -836,7 +836,7 @@
836836
"name": "python",
837837
"nbconvert_exporter": "python",
838838
"pygments_lexer": "ipython3",
839-
"version": "3.13.9"
839+
"version": "3.14.2"
840840
}
841841
},
842842
"nbformat": 4,

docs/user_guide/examples/tutorial_nemo_curvilinear.ipynb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@
9797
"V = parcels.Field(\n",
9898
" \"V\", ds_fields[\"V\"], grid, interp_method=parcels.interpolators.XLinear\n",
9999
")\n",
100-
"U.units = parcels.GeographicPolar()\n",
101-
"V.units = (\n",
102-
" parcels.GeographicPolar()\n",
103-
") # U and V need GeographicPolar for C-Grid interpolation to work correctly\n",
104100
"UV = parcels.VectorField(\n",
105101
" \"UV\", U, V, vector_interp_method=parcels.interpolators.CGrid_Velocity\n",
106102
")\n",

0 commit comments

Comments
 (0)