You can run this notebook in a live session via Binder or view it on Github.
Canny Edge Detector#
Ideal Jet#
A idealized meandering jets with rings, as a 2D numpy array (embeded in Xarray).
[2]:
import matplotlib.pyplot as plt
import xarray as xr
from fronts_toolbox._fields import ideal_jet, sample
from fronts_toolbox.canny import canny_xarray
[3]:
# A colormap for overlaying the detected fronts
from matplotlib.colors import ListedColormap
cmap_fronts = ListedColormap([(0, 0, 0, 0), (0, 0, 0, 1)])
[4]:
sst = xr.DataArray(ideal_jet(), name="sst", dims=("lat", "lon"))
edges = canny_xarray(sst)
[5]:
fig, ax = plt.subplots(dpi=150)
sst.plot.imshow(ax=ax, cmap="inferno", add_labels=False)
edges.plot.imshow(
ax=ax, cmap=cmap_fronts, add_labels=False, add_colorbar=False
)
ax.set_aspect("equal")
ESA-SST-CCI / C3S Data#
SST of the North Atlantic, as a Dask array embeded in Xarray.
[6]:
sst = (
sample("ESA-CCI-C3S")
.analysed_sst.sel(lat=slice(15, 55), lon=slice(-82, -40))
.chunk(lat=256, lon=256)
)
# Hysteresis does not support chunked core dimensions
edges = canny_xarray(sst, hysteresis=False)
fig, ax = plt.subplots(dpi=200)
sst.isel(time=0).plot.imshow(
ax=ax, cmap="inferno", add_labels=False, center=False
)
edges.isel(time=0).plot.imshow(
ax=ax, cmap=cmap_fronts, add_labels=False, add_colorbar=False
)
ax.set_aspect("equal")
Downloading file 'ESA-CCI-C3S.zip' from 'https://zenodo.org/records/15774600/files/ESA-CCI-C3S.zip' to '/home/docs/.cache/fronts-toolbox'.
Extracting '20220201120000-C3S-L4_GHRSST-SSTdepth-OSTIA-GLOB_ICDR2.1-v02.0-fv01.0.nc' from '/home/docs/.cache/fronts-toolbox/ESA-CCI-C3S.zip' to '/home/docs/.cache/fronts-toolbox/ESA-CCI-C3S.zip.unzip'
Extracting '20220202120000-C3S-L4_GHRSST-SSTdepth-OSTIA-GLOB_ICDR2.1-v02.0-fv01.0.nc' from '/home/docs/.cache/fronts-toolbox/ESA-CCI-C3S.zip' to '/home/docs/.cache/fronts-toolbox/ESA-CCI-C3S.zip.unzip'
Extracting '20220203120000-C3S-L4_GHRSST-SSTdepth-OSTIA-GLOB_ICDR2.1-v02.0-fv01.0.nc' from '/home/docs/.cache/fronts-toolbox/ESA-CCI-C3S.zip' to '/home/docs/.cache/fronts-toolbox/ESA-CCI-C3S.zip.unzip'
/home/docs/checkouts/readthedocs.org/user_builds/fronts-toolbox/envs/latest/lib/python3.11/site-packages/fronts_toolbox/_fields.py:236: FutureWarning: In a future version of xarray the default value for data_vars will change from data_vars='all' to data_vars=None. This is likely to lead to different results when multiple datasets have matching variables with overlapping values. To opt in to new defaults and get rid of these warnings now use `set_options(use_new_combine_kwarg_defaults=True) or set data_vars explicitly.
return xr.open_mfdataset(files, **kwargs)