|
303 | 303 | "Note that the Kernels above return the value of `U` and `V` in the units of the grid. That means that for a spherical grid, the velocities are in **degrees/s**. To convert these to **m/s**, see the [UnitConversion tutorial](https://docs.oceanparcels.org/en/latest/examples/tutorial_unitconverters.html).\n", |
304 | 304 | "</div>" |
305 | 305 | ] |
306 | | - }, |
307 | | - { |
308 | | - "cell_type": "markdown", |
309 | | - "metadata": {}, |
310 | | - "source": [ |
311 | | - "## Sampling initial values\n" |
312 | | - ] |
313 | | - }, |
314 | | - { |
315 | | - "attachments": {}, |
316 | | - "cell_type": "markdown", |
317 | | - "metadata": {}, |
318 | | - "source": [ |
319 | | - "In some simulations only the particles initial value within the field is of interest: the variable does not need to be known along the entire trajectory. To reduce computing we can specify the `to_write` argument to the temperature `Variable`. This argument can have three values: `True`, `False` or `'once'`. It determines whether to write the `Variable` to the output file. If we want to know only the initial value, we can enter `'once'` and only the first value will be written to the output file.\n" |
320 | | - ] |
321 | | - }, |
322 | | - { |
323 | | - "cell_type": "code", |
324 | | - "execution_count": null, |
325 | | - "metadata": {}, |
326 | | - "outputs": [], |
327 | | - "source": [ |
328 | | - "SampleParticleOnce = parcels.Particle.add_variable(\n", |
329 | | - " parcels.Variable(\"temperature\", initial=np.nan, to_write=\"once\")\n", |
330 | | - ")\n", |
331 | | - "\n", |
332 | | - "pset = parcels.ParticleSet(\n", |
333 | | - " fieldset=fieldset,\n", |
334 | | - " pclass=SampleParticleOnce,\n", |
335 | | - " lon=lon,\n", |
336 | | - " lat=lat,\n", |
337 | | - " time=time,\n", |
338 | | - " z=z,\n", |
339 | | - ")" |
340 | | - ] |
341 | | - }, |
342 | | - { |
343 | | - "cell_type": "code", |
344 | | - "execution_count": null, |
345 | | - "metadata": { |
346 | | - "tags": [ |
347 | | - "hide-output" |
348 | | - ] |
349 | | - }, |
350 | | - "outputs": [], |
351 | | - "source": [ |
352 | | - "output_file = parcels.ParticleFile(\"writeonce.zarr\", outputdt=timedelta(hours=1))\n", |
353 | | - "\n", |
354 | | - "pset.execute(\n", |
355 | | - " [parcels.kernels.AdvectionRK2, SampleT],\n", |
356 | | - " runtime=timedelta(hours=24),\n", |
357 | | - " dt=timedelta(minutes=5),\n", |
358 | | - " output_file=output_file,\n", |
359 | | - ")" |
360 | | - ] |
361 | | - }, |
362 | | - { |
363 | | - "cell_type": "markdown", |
364 | | - "metadata": {}, |
365 | | - "source": [ |
366 | | - "We can compare the output where only the initial value is written to output, with the original simulation, where the temperature at each outputdt is written:" |
367 | | - ] |
368 | | - }, |
369 | | - { |
370 | | - "cell_type": "code", |
371 | | - "execution_count": null, |
372 | | - "metadata": {}, |
373 | | - "outputs": [], |
374 | | - "source": [ |
375 | | - "ds_particles_once = xr.open_zarr(\"writeonce.zarr\")\n", |
376 | | - "\n", |
377 | | - "plt.figure()\n", |
378 | | - "ax = plt.axes()\n", |
379 | | - "ax.set_ylabel(\"Temperature [$^{\\\\circ}$C]\")\n", |
380 | | - "ax.set_xlabel(\"Observation Number (-)\")\n", |
381 | | - "ax.set_ylim(22.2, 24.5)\n", |
382 | | - "l1 = ax.plot(ds_particles.obs, ds_particles.temperature.T, color=\"red\")\n", |
383 | | - "l2 = ax.plot(\n", |
384 | | - " ds_particles_once.obs,\n", |
385 | | - " np.tile(ds_particles_once.temperature, (ds_particles_once.lon.shape[1], 1)),\n", |
386 | | - " color=\"tab:blue\",\n", |
387 | | - ")\n", |
388 | | - "ax.legend([l1[0], l2[0]], [\"Write every outputdt\", \"Write once\"])\n", |
389 | | - "plt.show()" |
390 | | - ] |
391 | 306 | } |
392 | 307 | ], |
393 | 308 | "metadata": { |
394 | 309 | "celltoolbar": "Raw-celnotatie", |
395 | 310 | "kernelspec": { |
396 | | - "display_name": "docs", |
| 311 | + "display_name": "Parcels:docs (3.14.4)", |
397 | 312 | "language": "python", |
398 | 313 | "name": "python3" |
399 | 314 | }, |
|
407 | 322 | "name": "python", |
408 | 323 | "nbconvert_exporter": "python", |
409 | 324 | "pygments_lexer": "ipython3", |
410 | | - "version": "3.14.2" |
| 325 | + "version": "3.14.4" |
411 | 326 | }, |
412 | 327 | "pycharm": { |
413 | 328 | "stem_cell": { |
|
0 commit comments