|
5 | 5 | "cell_type": "markdown", |
6 | 6 | "metadata": {}, |
7 | 7 | "source": [ |
8 | | - "# Spherical grids and unit conversion\n" |
| 8 | + "# Spherical grids and unit converters\n" |
9 | 9 | ] |
10 | 10 | }, |
11 | 11 | { |
|
67 | 67 | "When using a `FieldSet` method for a specific dataset, such as `from_copernicusmarine()`, the grid information is known and parsed by Parcels, so we do not have to add the `mesh` argument.\n", |
68 | 68 | "```\n", |
69 | 69 | "\n", |
70 | | - "Plotting the `U` field indeed shows a uniform 1m/s eastward flow.\n" |
| 70 | + "Plotting the `U` field indeed shows a uniform 1 m/s eastward flow.\n" |
71 | 71 | ] |
72 | 72 | }, |
73 | 73 | { |
|
113 | 113 | "metadata": {}, |
114 | 114 | "outputs": [], |
115 | 115 | "source": [ |
116 | | - "print(fieldset.UV[np.array([0]), np.array([0]), np.array([40]), np.array([-5])])\n", |
| 116 | + "time = np.array([0])\n", |
| 117 | + "z = np.array([0])\n", |
| 118 | + "lat = np.array([40])\n", |
| 119 | + "lon = np.array([-5])\n", |
| 120 | + "print(fieldset.UV[time, z, lat, lon])\n", |
117 | 121 | "print(\n", |
118 | | - " fieldset.temperature[np.array([0]), np.array([0]), np.array([40]), np.array([-5])]\n", |
| 122 | + " fieldset.temperature[time, z, lat, lon]\n", |
119 | 123 | ")" |
120 | 124 | ] |
121 | 125 | }, |
|
126 | 130 | "source": [ |
127 | 131 | "While the temperature field indeed is 20C, as we defined, these printed velocities are much smaller.\n", |
128 | 132 | "\n", |
129 | | - "This is because Parcels converts under the hood from m/s to degrees/s. This conversion is done with a `UnitConverter` object, which is stored in the `.units` attribute of each Field. Below, we print these\n" |
| 133 | + "This is because Parcels converts under the hood from m/s to degrees/s. This conversion is done with a `parcels.converters` object, which is stored in the `.units` attribute of each Field. Below, we print these\n" |
130 | 134 | ] |
131 | 135 | }, |
132 | 136 | { |
|
144 | 148 | "cell_type": "markdown", |
145 | 149 | "metadata": {}, |
146 | 150 | "source": [ |
147 | | - "So the U field has a `GeographicPolar` UnitConverter object, the V field has a `Geographic` Unitconverter and the `temp` field has a `UnitConverter` object.\n", |
| 151 | + "So the U field has a `GeographicPolar` UnitConverter object, the V field has a `Geographic` UnitConverter and the `temp` field has a `UnitConverter` object.\n", |
148 | 152 | "\n", |
149 | 153 | "Indeed, if we multiply the value of the V field with 1852 \\* 60 (the number of meters in 1 degree of latitude), we get the expected 1 m/s.\n" |
150 | 154 | ] |
|
155 | 159 | "metadata": {}, |
156 | 160 | "outputs": [], |
157 | 161 | "source": [ |
158 | | - "u, v = fieldset.UV[np.array([0]), np.array([0]), np.array([40]), np.array([-5])]\n", |
| 162 | + "u, v = fieldset.UV[time, z, lat, lon]\n", |
159 | 163 | "print(v * 1852 * 60)" |
160 | 164 | ] |
161 | 165 | }, |
|
175 | 179 | "source": [ |
176 | 180 | "print(\n", |
177 | 181 | " fieldset.UV.eval(\n", |
178 | | - " np.array([0]),\n", |
179 | | - " np.array([0]),\n", |
180 | | - " np.array([40]),\n", |
181 | | - " np.array([-5]),\n", |
| 182 | + " time,\n", |
| 183 | + " z,\n", |
| 184 | + " lat,\n", |
| 185 | + " lon,\n", |
182 | 186 | " applyConversion=False,\n", |
183 | 187 | " )\n", |
184 | 188 | ")" |
|
235 | 239 | "\n", |
236 | 240 | "print(\n", |
237 | 241 | " \"Velocities:\",\n", |
238 | | - " fieldset_flat.UV[np.array([0]), np.array([0]), np.array([40]), np.array([-5])],\n", |
| 242 | + " fieldset_flat.UV[time, z, lat, lon],\n", |
239 | 243 | ")\n", |
240 | 244 | "for fld in [fieldset_flat.U, fieldset_flat.V, fieldset_flat.temperature]:\n", |
241 | 245 | " print(f\"{fld.name}: {fld.units}\")" |
|
301 | 305 | "fieldset.add_field(kh_meridional_field)\n", |
302 | 306 | "\n", |
303 | 307 | "for fld in [fieldset.Kh_zonal, fieldset.Kh_meridional]:\n", |
304 | | - " val = fld[np.array([0]), np.array([0]), np.array([40]), np.array([-5])]\n", |
| 308 | + " val = fld[time, z, lat, lon]\n", |
305 | 309 | " print(f\"{fld.name}: {val} {fld.units}\")" |
306 | 310 | ] |
307 | 311 | }, |
|
323 | 327 | "source": [ |
324 | 328 | "deg_to_m = 1852 * 60\n", |
325 | 329 | "print(\n", |
326 | | - " fieldset.Kh_meridional[np.array([0]), np.array([0]), np.array([40]), np.array([-5])]\n", |
| 330 | + " fieldset.Kh_meridional[time, z, lat, lon]\n", |
327 | 331 | " * deg_to_m**2\n", |
328 | 332 | ")" |
329 | 333 | ] |
|
374 | 378 | " interp_method=parcels.interpolators.XLinear,\n", |
375 | 379 | " )\n", |
376 | 380 | ")\n", |
377 | | - "print(fieldset.Ustokes[np.array([0]), np.array([0]), np.array([40]), np.array([-5])])" |
| 381 | + "print(fieldset.Ustokes[time, z, lat, lon])" |
378 | 382 | ] |
379 | 383 | }, |
380 | 384 | { |
|
392 | 396 | "outputs": [], |
393 | 397 | "source": [ |
394 | 398 | "fieldset.Ustokes.units = parcels.GeographicPolar()\n", |
395 | | - "print(fieldset.Ustokes[np.array([0]), np.array([0]), np.array([40]), np.array([-5])])\n", |
| 399 | + "print(fieldset.Ustokes[time, z, lat, lon])\n", |
396 | 400 | "print(\n", |
397 | | - " fieldset.Ustokes[np.array([0]), np.array([0]), np.array([40]), np.array([-5])]\n", |
| 401 | + " fieldset.Ustokes[time, z, lat, lon]\n", |
398 | 402 | " * 1852\n", |
399 | 403 | " * 60\n", |
400 | 404 | " * np.cos(40 * np.pi / 180)\n", |
|
0 commit comments