Skip to content

Commit a237a29

Browse files
committed
add examples
1 parent a624704 commit a237a29

File tree

15 files changed

+176
-23
lines changed

15 files changed

+176
-23
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Tracking Manipulation
2+
=======================
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Display fields
3+
==============
4+
5+
"""
6+
7+
from matplotlib import pyplot as plt
8+
from py_eddy_tracker.observations.tracking import TrackEddiesObservations
9+
import py_eddy_tracker_sample
10+
11+
c = TrackEddiesObservations.load_file(
12+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
13+
)
14+
15+
c = c.extract_with_length((180, -1))
16+
17+
# Plot
18+
fig = plt.figure(figsize=(12, 6))
19+
ax = fig.add_axes((0.05, 0.1, 0.9, 0.9))
20+
ax.set_aspect("equal")
21+
ax.set_xlim(-5, 37)
22+
ax.set_ylim(30, 46)
23+
m = c.scatter(ax, "amplitude", ref=-10, vmin=0, vmax=0.1)
24+
ax.grid()
25+
26+
cb = plt.colorbar(
27+
m, cax=fig.add_axes([0.05, 0.07, 0.9, 0.01]), orientation="horizontal"
28+
)
29+
cb.set_label("Amplitude (m)")

examples/pet_display_track.py renamed to examples/00_tracking_manipulation/pet_display_track.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424

2525

2626
# Plot
27-
fig = plt.figure(figsize=(15, 8))
28-
ax = fig.add_subplot(111)
27+
fig = plt.figure(figsize=(12, 5))
28+
ax = fig.add_axes((0.05, 0.1, 0.9, 0.9))
2929
ax.set_aspect("equal")
3030
ax.set_xlim(-5, 37)
3131
ax.set_ylim(30, 46)
3232
a.plot(ax, ref=-10, label="Anticyclonic", color="r", lw=0.1)
3333
c.plot(ax, ref=-10, label="Cyclonic", color="b", lw=0.1)
3434
ax.legend()
35+
ax.grid()

examples/pet_one_track.py renamed to examples/00_tracking_manipulation/pet_one_track.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
eddy_f = a.extract_ids([9672])
1616
eddy_f.median_filter(1, "time", "lon").loess_filter(5, "time", "lon")
1717
eddy_f.median_filter(1, "time", "lat").loess_filter(5, "time", "lat")
18-
fig = plt.figure(figsize=(20, 8))
19-
ax = fig.add_subplot(111)
20-
ax.set_xlim(17, 22.5)
18+
fig = plt.figure(figsize=(12, 5))
19+
ax = fig.add_axes((0.05, 0.1, 0.9, 0.9))
20+
ax.set_xlim(17.5, 22)
2121
ax.set_ylim(35, 36.5)
22+
ax.set_aspect("equal")
2223
ax.grid()
2324
eddy.plot(ax, color="r", lw=0.5)
2425
eddy_f.plot(ax, color="g", lw=1)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Tracks which go through area
3+
============================
4+
5+
"""
6+
from matplotlib import pyplot as plt
7+
from py_eddy_tracker.observations.tracking import TrackEddiesObservations
8+
import py_eddy_tracker_sample
9+
10+
c = TrackEddiesObservations.load_file(
11+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
12+
)
13+
c.median_filter(1, "time", "lon").loess_filter(5, "time", "lon")
14+
c.median_filter(1, "time", "lat").loess_filter(5, "time", "lat")
15+
x0, x1, y0, y1 = 3, 4, 37, 38
16+
area = dict(llcrnrlon=x0, llcrnrlat=y0, urcrnrlon=x1, urcrnrlat=y1)
17+
c_subset = c.extract_with_area(area, full_path=True)
18+
fig = plt.figure(figsize=(12, 5))
19+
ax = fig.add_axes((0.05, 0.05, 0.9, 0.9))
20+
ax.set_xlim(-1, 9)
21+
ax.set_ylim(36, 40)
22+
ax.set_aspect("equal")
23+
ax.grid()
24+
c.plot(ax, color="gray", lw=0.1, ref=-10, label="all tracks")
25+
c_subset.plot(ax, color="red", lw=0.2, ref=-10, label="selected tracks")
26+
ax.plot(
27+
(x0, x0, x1, x1, x0,),
28+
(y0, y1, y1, y0, y0,),
29+
color="green",
30+
lw=1.5,
31+
label="Box of selection",
32+
)
33+
ax.legend()
File renamed without changes.

examples/tracking_diagnostics/pet_center_count.py renamed to examples/10_tracking_diagnostics/pet_center_count.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
ax = fig.add_subplot(111)
2222
ax.set_xlim(-5, 37)
2323
ax.set_ylim(30, 46)
24+
ax.set_aspect("equal")
2425
step = 0.1
2526
t0, t1 = a.period
26-
g = a.grid_count(((-5, 37, step), (30, 46, step)), center=True)
27-
g.vars["count"] = g.vars["count"] / (step ** 2 * (t1 - t0))
28-
m = g.display(ax, name="count", vmin=0, vmax=2)
27+
g = a.grid_count(((-6, 37, step), (30, 46, step)), center=True)
28+
m = g.display(ax, name="count", vmin=0, vmax=2, factor=1 / (step ** 2 * (t1 - t0)))
2929
ax.grid()
3030
cb = plt.colorbar(m, cax=fig.add_axes([0.95, 0.05, 0.01, 0.9]))
3131
cb.set_label("Eddies by 1°^2 by day")
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Geographical statistics
3+
=======================
4+
5+
"""
6+
7+
from matplotlib import pyplot as plt
8+
from py_eddy_tracker.observations.tracking import TrackEddiesObservations
9+
import py_eddy_tracker_sample
10+
11+
12+
a = TrackEddiesObservations.load_file(
13+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Anticyclonic.zarr")
14+
)
15+
c = TrackEddiesObservations.load_file(
16+
py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
17+
)
18+
a = a.merge(c)
19+
20+
fig = plt.figure(figsize=(15, 7))
21+
ax = fig.add_subplot(111)
22+
ax.set_xlim(-5, 37)
23+
ax.set_ylim(30, 46)
24+
ax.set_aspect("equal")
25+
step = 0.1
26+
g = a.grid_stat(((-5, 37, step), (30, 46, step)), "amplitude")
27+
m = g.display(ax, name="amplitude", vmin=0, vmax=0.2)
28+
ax.grid()
29+
cb = plt.colorbar(m, cax=fig.add_axes([0.92, 0.05, 0.01, 0.9]))
30+
cb.set_label("Amplitude (m)")
31+
ax.set_title("Amplitude mean by box of %s°" % step)
32+
33+
fig = plt.figure(figsize=(15, 7))
34+
ax = fig.add_subplot(111)
35+
ax.set_xlim(-5, 37)
36+
ax.set_ylim(30, 46)
37+
ax.set_aspect("equal")
38+
step = 0.1
39+
g = a.grid_stat(((-5, 37, step), (30, 46, step)), "radius_s")
40+
m = g.display(ax, name="radius_s", vmin=10, vmax=50, factor=0.001)
41+
ax.grid()
42+
cb = plt.colorbar(m, cax=fig.add_axes([0.92, 0.05, 0.01, 0.9]))
43+
cb.set_label("Speed radius (km)")
44+
ax.set_title("Speed radius mean by box of %s°" % step)
45+
46+
fig = plt.figure(figsize=(15, 7))
47+
ax = fig.add_subplot(111)
48+
ax.set_xlim(-5, 37)
49+
ax.set_ylim(30, 46)
50+
ax.set_aspect("equal")
51+
step = 0.1
52+
g = a.grid_stat(((-5, 37, step), (30, 46, step)), "virtual")
53+
g.vars["virtual"] *= 100
54+
m = g.display(ax, name="virtual", vmin=0, vmax=15)
55+
ax.grid()
56+
cb = plt.colorbar(m, cax=fig.add_axes([0.92, 0.05, 0.01, 0.9]))
57+
cb.set_label("Percent of virtual (%)")
58+
ax.set_title("Percent of virtual by box of %s°" % step)
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)