Skip to content

Commit 972ff2a

Browse files
committed
add example
1 parent 85067e5 commit 972ff2a

File tree

5 files changed

+82
-2
lines changed

5 files changed

+82
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Eddy detection
2+
==============
File renamed without changes.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""
2+
Eddy detection
3+
==============
4+
5+
Script will detect eddies on adt field, and compute u,v with method add_uv(which could use, only if equator is avoid)
6+
7+
"""
8+
from datetime import datetime
9+
from matplotlib import pyplot as plt
10+
from py_eddy_tracker.dataset.grid import RegularGridDataset
11+
from py_eddy_tracker import data
12+
13+
14+
def start_axes(title):
15+
fig = plt.figure(figsize=(12.5, 5))
16+
ax = fig.add_axes([0.03, 0.03, 0.94, 0.94])
17+
ax.set_xlim(-5, 37)
18+
ax.set_ylim(30, 46)
19+
ax.set_aspect("equal")
20+
ax.set_title(title)
21+
return ax
22+
23+
24+
def update_axes(ax, mappable=None):
25+
ax.grid()
26+
if mappable:
27+
plt.colorbar(m, cax=ax.figure.add_axes([0.95, 0.05, 0.01, 0.9]))
28+
29+
30+
g = RegularGridDataset(
31+
data.get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude"
32+
)
33+
34+
ax = start_axes("ADT(m)")
35+
m = g.display(ax, "adt", vmin=-0.15, vmax=0.15)
36+
update_axes(ax, m)
37+
38+
g.add_uv("adt")
39+
g.bessel_high_filter("adt", 500, order=2)
40+
41+
ax = start_axes("ADT (m) filtered(500km, order 2)")
42+
m = g.display(ax, "adt", vmin=-0.15, vmax=0.15)
43+
update_axes(ax, m)
44+
45+
date = datetime(2016, 5, 15)
46+
a, c = g.eddy_identification("adt", "u", "v", date, 0.002)
47+
48+
ax = start_axes("ADT closed contour (only 1 / 4 levels)")
49+
g.contours.display(ax, step=4)
50+
update_axes(ax)
51+
52+
ax = start_axes("ADT contour used as eddies")
53+
g.contours.display(ax, only_used=True)
54+
update_axes(ax)
55+
56+
ax = start_axes("ADT contour reject")
57+
g.contours.display(ax, only_unused=True)
58+
update_axes(ax)
59+
60+
ax = start_axes("ADT contour reject but which contain eddies")
61+
g.contours.label_contour_unused_which_contain_eddies(a)
62+
g.contours.label_contour_unused_which_contain_eddies(c)
63+
g.contours.display(ax, only_contain_eddies=True, color="k", lw=1, label="Could be interaction contour")
64+
a.display(ax, color="b", linewidth=0.5, label="Anticyclonic", ref=-10)
65+
c.display(ax, color="r", linewidth=0.5, label="Cyclonic", ref=-10)
66+
ax.legend()
67+
update_axes(ax)
68+
69+
ax = start_axes("Eddies detected")
70+
a.display(ax, color="b", linewidth=0.5, label="Anticyclonic", ref=-10)
71+
c.display(ax, color="r", linewidth=0.5, label="Cyclonic", ref=-10)
72+
ax.legend()
73+
update_axes(ax)
74+
75+
ax = start_axes("Eddies speed radius (km)")
76+
a.scatter(ax, "radius_s", vmin=10, vmax=50, s=80, ref=-10, cmap='jet', factor=0.001)
77+
m = c.scatter(ax, "radius_s", vmin=10, vmax=50, s=80, ref=-10, cmap='jet', factor=0.001)
78+
update_axes(ax, m)
89.5 KB
Binary file not shown.

src/py_eddy_tracker/observations/observation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,11 @@ def set_global_attr_netcdf(self, h_nc):
12411241
for key, item in self.global_attr.items():
12421242
h_nc.setncattr(key, item)
12431243

1244-
def scatter(self, ax, name, ref=None, ** kwargs):
1244+
def scatter(self, ax, name, ref=None, factor=1, ** kwargs):
12451245
x = self.longitude
12461246
if ref is not None:
12471247
x = (x - ref) % 360 + ref
1248-
return ax.scatter(x, self.latitude, c=self[name], **kwargs)
1248+
return ax.scatter(x, self.latitude, c=self[name] * factor, **kwargs)
12491249

12501250
def display(self, ax, ref=None, extern_only=False, intern_only=False, **kwargs):
12511251
if not extern_only:

0 commit comments

Comments
 (0)