Note
Go to the end to download the full example code.
Detect CROCO-MED1.8 eddies at different depths and link the detections#
In this example, 3D eddies are detected from CROCO model currents interpolated at several depths and collocated at RHO points.
Initialisations#
Import needed stuff.
import cmocean # noqa
import matplotlib.pyplot as plt
import xarray as xr
from shoot.dyn import get_relvort
from shoot.eddies.eddies3d import Eddies3D
from shoot.meta import set_meta_specs
from shoot.plot import create_map, pcarr
from shoot.samples import get_sample_file
xr.set_options(display_style="text")
<xarray.core.options.set_options object at 0x702699232c90>
Load croco-specific naming conventions to find dims, coords and variables
set_meta_specs("croco")
Read data
Detect eddies#
Parameters#
Window size in km to compute the LNAM and find eddy centers
window_center = 50 # 50
window_fit = 120
min_radius = 10
eddies3d = Eddies3D.detect_eddies_3d(
ds_3d.u,
ds_3d.v,
window_center,
window_fit=window_fit,
min_radius=min_radius,
paral=True,
)
eddies3d.plot2d(depth=10)

# Plots eddies
# -----
#
# We plot eddies with the relative vorticity as background.
#
eddies3d_slice = eddies3d.eddies_byslice
for i in range(len(ds_3d.depth)):
fig, ax = create_map(
ds_3d.isel(depth=i).lon_rho,
ds_3d.isel(depth=i).lat_rho,
figsize=(8, 5),
)
cb = get_relvort(ds_3d.isel(depth=i).u, ds_3d.isel(depth=i).v).plot(
x="lon_rho",
y="lat_rho",
cmap="cmo.curl",
ax=ax,
add_colorbar=False,
transform=pcarr,
)
plt.colorbar(cb, label=r"$\zeta$")
plt.quiver(
ds_3d.lon_rho[::5, ::5].values,
ds_3d.lat_rho[::5, ::5].values,
ds_3d.isel(depth=i).u[::5, ::5].values,
ds_3d.isel(depth=i).v[::5, ::5].values,
color="k",
transform=pcarr,
)
for eddy in eddies3d_slice.eddies3d[i].eddies:
eddy.plot(transform=pcarr, lw=1)
# plt.text(eddy.glon, eddy.glat, eddy.z_id, transform=pcarr)
plt.text(
eddy.glon,
eddy.glat,
f"{eddy.z_id} - {eddy.vmax_contour.mean_velocity:.2f} m/s",
transform=pcarr,
)
plt.title(f"Relative vorticity at {ds_3d.isel(depth=i).depth} m depth")
plt.tight_layout()
Total running time of the script: (3 minutes 18.604 seconds)
![Relative vorticity at <xarray.DataArray 'depth' ()> Size: 8B array(-1000) Coordinates: time datetime64[ns] 8B 2024-04-10T00:01:00 depth int64 8B -1000 m depth](../_images/sphx_glr_plot_eddy_detect_3d_002.png)
![Relative vorticity at <xarray.DataArray 'depth' ()> Size: 8B array(-500) Coordinates: time datetime64[ns] 8B 2024-04-10T00:01:00 depth int64 8B -500 m depth](../_images/sphx_glr_plot_eddy_detect_3d_003.png)
![Relative vorticity at <xarray.DataArray 'depth' ()> Size: 8B array(-400) Coordinates: time datetime64[ns] 8B 2024-04-10T00:01:00 depth int64 8B -400 m depth](../_images/sphx_glr_plot_eddy_detect_3d_004.png)
![Relative vorticity at <xarray.DataArray 'depth' ()> Size: 8B array(-300) Coordinates: time datetime64[ns] 8B 2024-04-10T00:01:00 depth int64 8B -300 m depth](../_images/sphx_glr_plot_eddy_detect_3d_005.png)
![Relative vorticity at <xarray.DataArray 'depth' ()> Size: 8B array(-200) Coordinates: time datetime64[ns] 8B 2024-04-10T00:01:00 depth int64 8B -200 m depth](../_images/sphx_glr_plot_eddy_detect_3d_006.png)
![Relative vorticity at <xarray.DataArray 'depth' ()> Size: 8B array(-150) Coordinates: time datetime64[ns] 8B 2024-04-10T00:01:00 depth int64 8B -150 m depth](../_images/sphx_glr_plot_eddy_detect_3d_007.png)
![Relative vorticity at <xarray.DataArray 'depth' ()> Size: 8B array(-100) Coordinates: time datetime64[ns] 8B 2024-04-10T00:01:00 depth int64 8B -100 m depth](../_images/sphx_glr_plot_eddy_detect_3d_008.png)
![Relative vorticity at <xarray.DataArray 'depth' ()> Size: 8B array(-50) Coordinates: time datetime64[ns] 8B 2024-04-10T00:01:00 depth int64 8B -50 m depth](../_images/sphx_glr_plot_eddy_detect_3d_009.png)
![Relative vorticity at <xarray.DataArray 'depth' ()> Size: 8B array(-10) Coordinates: time datetime64[ns] 8B 2024-04-10T00:01:00 depth int64 8B -10 m depth](../_images/sphx_glr_plot_eddy_detect_3d_010.png)