Skip to content

Commit 64f0eab

Browse files
Filter warnings and fix vertical movement in CROCO
1 parent 9cfce55 commit 64f0eab

2 files changed

Lines changed: 34 additions & 21 deletions

File tree

docs/user_guide/v4-migration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Version 4 of Parcels is unreleased at the moment. The information in this migrat
1515
- `math` functions should be replaced with array compatible equivalents (e.g., `math.sin` -> `np.sin`). Instead of `ParcelsRandom` you should use numpy's random functions.
1616
- `particle.depth` has been changed to `particles.z` to be consistent with the [CF conventions for trajectory data](https://cfconventions.org/cf-conventions/cf-conventions.html#trajectory-data), and to make Parcels also generalizable to atmospheric contexts.
1717
- The `InteractionKernel` class has been removed. Since normal Kernels now have access to _all_ particles, particle-particle interaction can be performed within normal Kernels.
18-
- Users need to explicitly use `convert_z_to_sigma_croco` in sampling kernels (such as the `AdvectionRK4_3D_CROCO` or `SampleOMegaCroco` kernels) when working with CROCO data, as the automatic conversion from depth to sigma grids under the hood has been removed.
18+
- Users need to explicitly use `convert_z_to_sigma_croco` in sampling kernels (such as the `AdvectionRK2_3D_CROCO` or `SampleOMegaCroco` kernels) when working with CROCO data, as the automatic conversion from depth to sigma grids under the hood has been removed.
1919
- We added a new AdvectionRK2 Kernel. The AdvectionRK4 kernel is still available, but RK2 is now the recommended default advection scheme as it is faster while the accuracy is comparable for most applications. See also the Choosing an integration method tutorial.
2020
- Functions shouldn't be converted to Kernels before adding to a pset.execute() call. Instead, simply pass the function(s) as a list to pset.execute().
2121
- Kernel variables `time`, `lat` and `lon` have been renamed to `t`, `y` and `x`, and `dlat` and `dlon` have been renamed to `dy` and `dx`. These changes are also reflected on the ParticleSet as well as the ParticleFile output.

src/parcels/kernels/_sigmagrids.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
13
import numpy as np
24

35
from parcels.kernels._advection import _constrain_dt_to_within_time_interval
@@ -40,23 +42,34 @@ def AdvectionRK2_3D_CROCO(particles, fieldset): # pragma: no cover
4042
This kernel assumes the vertical velocity is the 'w' field from CROCO output and works on sigma-layers.
4143
It also uses linear interpolation of the W field, which gives much better results than the default C-grid interpolation.
4244
"""
43-
dt = _constrain_dt_to_within_time_interval(fieldset.time_interval, particles.t, particles.dt)
44-
sigma = particles.z / fieldset.h[particles.t, np.zeros_like(particles.z), particles.y, particles.x]
45-
46-
sig = convert_z_to_sigma_croco(fieldset, particles.t, particles.z, particles.y, particles.x, particles)
47-
(u1, v1) = fieldset.UV[particles.t, sig, particles.y, particles.x, particles]
48-
w1 = fieldset.W[particles.t, sig, particles.y, particles.x, particles]
49-
w1 *= sigma / fieldset.h[particles.t, np.zeros_like(particles.z), particles.y, particles.x]
50-
x1 = particles.x + u1 * 0.5 * dt
51-
y1 = particles.y + v1 * 0.5 * dt
52-
sig_dep1 = sigma + w1 * 0.5 * dt
53-
dep1 = sig_dep1 * fieldset.h[particles.t, np.zeros_like(particles.z), y1, x1]
54-
55-
sig1 = convert_z_to_sigma_croco(fieldset, particles.t + 0.5 * dt, dep1, y1, x1, particles)
56-
(u2, v2) = fieldset.UV[particles.t + 0.5 * dt, sig1, y1, x1, particles]
57-
w2 = fieldset.W[particles.t + 0.5 * dt, sig1, y1, x1, particles]
58-
w2 *= sig_dep1 / fieldset.h[particles.t + 0.5 * dt, np.zeros_like(particles.z), y1, x1]
59-
60-
particles.dx += u2 * dt
61-
particles.dy += v2 * dt
62-
particles.dz += w2 * dt
45+
with warnings.catch_warnings():
46+
warnings.filterwarnings(
47+
"ignore",
48+
message=r"^Sampling of velocities should normally be done using fieldset\.UV or fieldset\.UVW object; tread carefully$",
49+
category=RuntimeWarning,
50+
) # Needed because of linear sampling of W with sigma conversion
51+
52+
dt = _constrain_dt_to_within_time_interval(fieldset.time_interval, particles.t, particles.dt)
53+
sigma = particles.z / fieldset.h[particles.t, np.zeros_like(particles.z), particles.y, particles.x]
54+
55+
sig = convert_z_to_sigma_croco(fieldset, particles.t, particles.z, particles.y, particles.x, particles)
56+
(u1, v1) = fieldset.UV[particles.t, sig, particles.y, particles.x, particles]
57+
w1 = fieldset.W[particles.t, sig, particles.y, particles.x, particles]
58+
w1 *= sigma / fieldset.h[particles.t, np.zeros_like(particles.z), particles.y, particles.x]
59+
x1 = particles.x + u1 * 0.5 * dt
60+
y1 = particles.y + v1 * 0.5 * dt
61+
sig_dep1 = sigma + w1 * 0.5 * dt
62+
dep1 = sig_dep1 * fieldset.h[particles.t, np.zeros_like(particles.z), y1, x1]
63+
64+
sig1 = convert_z_to_sigma_croco(fieldset, particles.t + 0.5 * dt, dep1, y1, x1, particles)
65+
(u2, v2) = fieldset.UV[particles.t + 0.5 * dt, sig1, y1, x1, particles]
66+
w2 = fieldset.W[particles.t + 0.5 * dt, sig1, y1, x1, particles]
67+
w2 *= sig_dep1 / fieldset.h[particles.t + 0.5 * dt, np.zeros_like(particles.z), y1, x1]
68+
x2 = particles.x + u2 * 0.5 * dt
69+
y2 = particles.y + v2 * 0.5 * dt
70+
sig_dep2 = sigma + w2 * 0.5 * dt
71+
dep2 = sig_dep2 * fieldset.h[particles.t + 0.5 * dt, np.zeros_like(particles.z), y2, x2]
72+
73+
particles.dx += u2 * dt
74+
particles.dy += v2 * dt
75+
particles.dz += (dep1 - particles.z) + (dep2 - particles.z)

0 commit comments

Comments
 (0)