Skip to content

Commit fa80acc

Browse files
committed
update example
1 parent aa0535f commit fa80acc

File tree

3 files changed

+101
-51
lines changed

3 files changed

+101
-51
lines changed

examples/10_tracking_diagnostics/pet_center_count.py

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
======================
44
55
"""
6-
76
from matplotlib import pyplot as plt
7+
from matplotlib.colors import LogNorm
88
from py_eddy_tracker.observations.tracking import TrackEddiesObservations
99
import py_eddy_tracker_sample
1010

@@ -15,16 +15,48 @@
1515
c = TrackEddiesObservations.load_file(
1616
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
1717
)
18-
a = a.merge(c)
18+
19+
t0, t1 = a.period
20+
1921
# Plot
20-
fig = plt.figure(figsize=(13.5, 5))
21-
ax = fig.add_axes([0.03, 0.03, 0.90, 0.94])
22-
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
23-
ax.set_aspect("equal")
22+
fig = plt.figure(figsize=(12, 18.5))
23+
ax_a = fig.add_axes([0.03, 0.75, 0.90, 0.25])
24+
ax_a.set_title("Anticyclonic frequency")
25+
ax_c = fig.add_axes([0.03, 0.5, 0.90, 0.25])
26+
ax_c.set_title("Cyclonic frequency")
27+
ax_all = fig.add_axes([0.03, 0.25, 0.90, 0.25])
28+
ax_all.set_title("All eddies frequency")
29+
ax_ratio = fig.add_axes([0.03, 0.0, 0.90, 0.25])
30+
ax_ratio.set_title("Ratio cyclonic / Anticyclonic")
31+
2432
step = 0.1
25-
t0, t1 = a.period
26-
g = a.grid_count(((-7, 37, step), (30, 46, step)), center=True)
27-
m = g.display(ax, name="count", vmin=0, vmax=2, factor=1 / (step ** 2 * (t1 - t0)))
28-
ax.grid()
29-
cb = plt.colorbar(m, cax=fig.add_axes([0.95, 0.05, 0.01, 0.9]))
33+
bins = ((-10, 37, step), (30, 46, step))
34+
kwargs_pcolormesh = dict(
35+
cmap="terrain_r", vmin=0, vmax=2, factor=1 / (step ** 2 * (t1 - t0)), name="count"
36+
)
37+
g_a = a.grid_count(bins, intern=True, center=True)
38+
m = g_a.display(ax_a, **kwargs_pcolormesh)
39+
40+
g_c = c.grid_count(bins, intern=True, center=True)
41+
m = g_c.display(ax_c, **kwargs_pcolormesh)
42+
43+
ratio = g_c.vars["count"] / g_a.vars["count"]
44+
45+
m_c = g_c.vars["count"].mask
46+
m = m_c & g_a.vars["count"].mask
47+
g_c.vars["count"][m_c] = 0
48+
g_c.vars["count"] += g_a.vars["count"]
49+
g_c.vars["count"].mask = m
50+
51+
m = g_c.display(ax_all, **kwargs_pcolormesh)
52+
cb = plt.colorbar(m, cax=fig.add_axes([0.94, 0.27, 0.01, 0.7]))
3053
cb.set_label("Eddies by 1°^2 by day")
54+
55+
g_c.vars["count"] = ratio
56+
m = g_c.display(ax_ratio, name="count", vmin=0.1, vmax=10, norm=LogNorm())
57+
plt.colorbar(m, cax=fig.add_axes([0.94, 0.02, 0.01, 0.2]))
58+
59+
for ax in (ax_a, ax_c, ax_all, ax_ratio):
60+
ax.set_aspect("equal")
61+
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
62+
ax.grid()

examples/10_tracking_diagnostics/pet_histo.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,45 @@
1414
c = TrackEddiesObservations.load_file(
1515
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
1616
)
17-
kwargs_a = dict(label="Anticyclonic", color="r")
18-
kwargs_c = dict(label="Cyclonic", color="b")
17+
kwargs_a = dict(label="Anticyclonic", color="r", histtype="step", density=True)
18+
kwargs_c = dict(label="Cyclonic", color="b", histtype="step", density=True)
1919

2020
# Plot
21-
fig = plt.figure()
22-
ax = fig.add_subplot(111)
23-
ax.hist(a["amplitude"], histtype="step", bins=arange(0.0005, 1, 0.002), **kwargs_a)
24-
ax.hist(c["amplitude"], histtype="step", bins=arange(0.0005, 1, 0.002), **kwargs_c)
25-
ax.set_xlabel("Amplitude (m)")
26-
ax.set_xlim(0, 0.5)
27-
ax.legend()
28-
ax.grid()
21+
fig = plt.figure(figsize=(12, 7))
2922

30-
fig = plt.figure()
31-
ax = fig.add_subplot(111)
32-
bins = arange(0, 200, 1)
33-
ax.hist(a["radius_s"] / 1000.0, histtype="step", bins=bins, **kwargs_a)
34-
ax.hist(c["radius_s"] / 1000.0, histtype="step", bins=bins, **kwargs_c)
35-
ax.set_xlabel("Speed_radius (km)")
36-
ax.set_xlim(0, 150)
37-
ax.legend()
38-
ax.grid()
23+
for x0, name, title, xmax, factor, bins in zip(
24+
(0.4, 0.72, 0.08),
25+
("radius_s", "speed_average", "amplitude"),
26+
("Speed radius (km)", "Speed average (cm/s)", "Amplitude (cm)"),
27+
(100, 50, 20),
28+
(0.001, 100, 100),
29+
(arange(0, 2000, 1), arange(0, 1000, 0.5), arange(0.0005, 1000, 0.2)),
30+
):
31+
ax_hist = fig.add_axes((x0, 0.24, 0.27, 0.35))
32+
nb_a, _, _ = ax_hist.hist(a[name] * factor, bins=bins, **kwargs_a)
33+
nb_c, _, _ = ax_hist.hist(c[name] * factor, bins=bins, **kwargs_c)
34+
ax_hist.set_xticklabels([])
35+
ax_hist.set_xlim(0, xmax)
36+
ax_hist.grid()
3937

40-
fig = plt.figure()
41-
ax = fig.add_subplot(111)
42-
bins = arange(0, 100, 1)
43-
ax.hist(a["speed_average"] * 100.0, histtype="step", bins=bins, **kwargs_a)
44-
ax.hist(c["speed_average"] * 100.0, histtype="step", bins=bins, **kwargs_c)
45-
ax.set_xlabel("speed_average (cm/s)")
38+
ax_cum = fig.add_axes((x0, 0.62, 0.27, 0.35))
39+
ax_cum.hist(a[name] * factor, bins=bins, cumulative=-1, **kwargs_a)
40+
ax_cum.hist(c[name] * factor, bins=bins, cumulative=-1, **kwargs_c)
41+
ax_cum.set_xticklabels([])
42+
ax_cum.set_title(title)
43+
ax_cum.set_xlim(0, xmax)
44+
ax_cum.set_ylim(0, 1)
45+
ax_cum.grid()
4646

47-
ax.set_xlim(0, 50)
48-
ax.legend()
49-
ax.grid()
47+
ax_ratio = fig.add_axes((x0, 0.06, 0.27, 0.15))
48+
ax_ratio.set_xlim(0, xmax)
49+
ax_ratio.set_ylim(0, 2)
50+
ax_ratio.plot((bins[1:] + bins[:-1]) / 2, nb_c / nb_a)
51+
ax_ratio.axhline(1, color="k")
52+
ax_ratio.grid()
53+
ax_ratio.set_xlabel(title)
54+
55+
ax_cum.set_ylabel("Cumulative\npercent distribution")
56+
ax_hist.set_ylabel("Percent of observations")
57+
ax_ratio.set_ylabel("Ratio percent\nCyc/Acyc")
58+
ax_cum.legend()

examples/10_tracking_diagnostics/pet_pixel_used.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
======================
44
55
"""
6-
76
from matplotlib import pyplot as plt
7+
from matplotlib.colors import LogNorm
88
from py_eddy_tracker.observations.tracking import TrackEddiesObservations
99
import py_eddy_tracker_sample
1010

@@ -18,34 +18,43 @@
1818
t0, t1 = a.period
1919

2020
# Plot
21-
fig = plt.figure(figsize=(12, 14))
22-
ax_a = fig.add_axes([0.03, 0.66, 0.90, 0.33])
21+
fig = plt.figure(figsize=(12, 18.5))
22+
ax_a = fig.add_axes([0.03, 0.75, 0.90, 0.25])
2323
ax_a.set_title("Anticyclonic frequency")
24-
ax_c = fig.add_axes([0.03, 0.33, 0.90, 0.33])
24+
ax_c = fig.add_axes([0.03, 0.5, 0.90, 0.25])
2525
ax_c.set_title("Cyclonic frequency")
26-
ax_all = fig.add_axes([0.03, 0, 0.90, 0.33])
26+
ax_all = fig.add_axes([0.03, 0.25, 0.90, 0.25])
2727
ax_all.set_title("All eddies frequency")
28+
ax_ratio = fig.add_axes([0.03, 0.0, 0.90, 0.25])
29+
ax_ratio.set_title("Ratio cyclonic / Anticyclonic")
2830

2931
step = 0.1
3032
bins = ((-10, 37, step), (30, 46, step))
31-
kwargs_pcolormesh = dict(cmap="terrain_r", vmin=0, vmax=0.75)
33+
kwargs_pcolormesh = dict(
34+
cmap="terrain_r", vmin=0, vmax=0.75, factor=1 / (t1 - t0), name="count"
35+
)
3236
g_a = a.grid_count(bins, intern=True)
33-
m = g_a.display(ax_a, name="count", factor=1 / (t1 - t0), **kwargs_pcolormesh)
37+
m = g_a.display(ax_a, **kwargs_pcolormesh)
3438

3539
g_c = c.grid_count(bins, intern=True)
36-
m = g_c.display(ax_c, name="count", factor=1 / (t1 - t0), **kwargs_pcolormesh)
40+
m = g_c.display(ax_c, **kwargs_pcolormesh)
41+
42+
ratio = g_c.vars["count"] / g_a.vars["count"]
3743

3844
m_c = g_c.vars["count"].mask
3945
m = m_c & g_a.vars["count"].mask
4046
g_c.vars["count"][m_c] = 0
4147
g_c.vars["count"] += g_a.vars["count"]
4248
g_c.vars["count"].mask = m
4349

44-
m = g_c.display(ax_all, name="count", factor=1 / (t1 - t0), **kwargs_pcolormesh)
50+
m = g_c.display(ax_all, **kwargs_pcolormesh)
51+
plt.colorbar(m, cax=fig.add_axes([0.95, 0.27, 0.01, 0.7]))
4552

46-
for ax in (ax_a, ax_c, ax_all):
53+
g_c.vars["count"] = ratio
54+
m = g_c.display(ax_ratio, name="count", vmin=0.1, vmax=10, norm=LogNorm())
55+
plt.colorbar(m, cax=fig.add_axes([0.95, 0.02, 0.01, 0.2]))
56+
57+
for ax in (ax_a, ax_c, ax_all, ax_ratio):
4758
ax.set_aspect("equal")
4859
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
4960
ax.grid()
50-
51-
plt.colorbar(m, cax=fig.add_axes([0.95, 0.05, 0.01, 0.9]))

0 commit comments

Comments
 (0)