|
1 | 1 | """ |
2 | | -[draft] Loopers vs eddies from altimetry |
| 2 | +Colocate looper with eddy from altimetry |
3 | 3 | ======================================== |
4 | 4 |
|
5 | | -All loopers datas used in this example are a subset from the dataset describe in this article |
| 5 | +All loopers data used in this example are a subset from the dataset describe in this article |
6 | 6 | [Lumpkin, R. : Global characteristics of coherent vortices from surface drifter trajectories](https://doi.org/10.1002/2015JC011435) |
7 | | -
|
8 | | -
|
9 | 7 | """ |
10 | 8 |
|
11 | 9 | import re |
@@ -71,65 +69,85 @@ def update_axes(ax, mappable=None): |
71 | 69 | ) |
72 | 70 |
|
73 | 71 | # %% |
74 | | -# |
| 72 | +# Global view |
| 73 | +# =========== |
75 | 74 | ax = start_axes("All drifter available in med from Lumpkin dataset") |
76 | 75 | loopers_med.plot(ax, lw=0.5, color="r", ref=-10) |
77 | 76 | update_axes(ax) |
78 | 77 |
|
79 | 78 | # %% |
80 | | -# Only long period drifter |
81 | | -long_drifter = loopers_med.extract_with_length((400, -1)) |
82 | | -ax = start_axes("Long period drifter") |
83 | | -long_drifter.plot(ax, lw=0.5, color="r", ref=-10) |
84 | | -update_axes(ax) |
85 | | -print(np.unique(long_drifter.tracks)) |
86 | | - |
87 | | -# %% |
88 | | -drifter_1 = long_drifter.extract_ids((3588,)) |
89 | | -fig = plt.figure(figsize=(8, 4)) |
| 79 | +# One segment of drifter |
| 80 | +# ====================== |
| 81 | +# |
| 82 | +# Get a drifter segment (index used have no correspondance with original dataset). |
| 83 | +looper = loopers_med.extract_ids((3588,)) |
| 84 | +fig = plt.figure(figsize=(16, 6)) |
90 | 85 | ax = fig.add_subplot(111, aspect="equal") |
| 86 | +looper.plot(ax, lw=0.5, label="Original position of drifter") |
| 87 | +looper_filtered = looper.copy() |
| 88 | +looper_filtered.position_filter(1, 13) |
| 89 | +s = looper_filtered.scatter( |
| 90 | + ax, |
| 91 | + "time", |
| 92 | + cmap=plt.get_cmap("Spectral_r", 20), |
| 93 | + label="Filtered position of drifter", |
| 94 | +) |
| 95 | +plt.colorbar(s).set_label("time (days from 1/1/1950)") |
| 96 | +ax.legend() |
91 | 97 | ax.grid() |
92 | | -drifter_1.plot(ax, lw=0.5) |
93 | | -# %% |
94 | | -drifter_1.close_tracks( |
95 | | - anticyclonic_eddies, method="close_center", delta=0.5, nb_obs_min=25 |
96 | | -).tracks |
97 | 98 |
|
98 | 99 | # %% |
99 | | -# Animation which show drifter with colocated eddies |
100 | | -ed = anticyclonic_eddies.extract_ids((4738, 4836, 4910,)) |
101 | | -x, y, t = drifter_1.lon, drifter_1.lat, drifter_1.time |
102 | | - |
103 | | - |
104 | | -def update(frame): |
105 | | - # We display last 5 days of loopers trajectory |
106 | | - m = (t < frame) * (t > (frame - 5)) |
107 | | - a.func_animation(frame) |
108 | | - line.set_data(x[m], y[m]) |
109 | | - |
110 | | - |
111 | | -a = Anim(ed, intern=True, figsize=(8, 8), cmap="magma_r", nb_step=10, dpi=60) |
112 | | -line = a.ax.plot([], [], "r", lw=4, zorder=100)[0] |
113 | | -kwargs = dict(frames=np.arange(*a.period, 1), interval=100) |
114 | | -a.fig.suptitle("") |
115 | | -_ = VideoAnimation(a.fig, update, **kwargs) |
| 100 | +# Try to find a detected eddies with adt at same place. We used filtered track to simulate an eddy center |
| 101 | +match = looper_filtered.close_tracks( |
| 102 | + anticyclonic_eddies, method="close_center", delta=0.1, nb_obs_min=50 |
| 103 | +) |
| 104 | +fig = plt.figure(figsize=(16, 6)) |
| 105 | +ax = fig.add_subplot(111, aspect="equal") |
| 106 | +looper.plot(ax, lw=0.5, label="Original position of drifter") |
| 107 | +looper_filtered.plot(ax, lw=1.5, label="Filtered position of drifter") |
| 108 | +match.plot(ax, lw=1.5, label="Matched eddy") |
| 109 | +ax.legend() |
| 110 | +ax.grid() |
116 | 111 |
|
117 | 112 | # %% |
118 | | -fig = plt.figure(figsize=(12, 6)) |
| 113 | +# Display radius of this 2 datasets. |
| 114 | +fig = plt.figure(figsize=(20, 8)) |
119 | 115 | ax = fig.add_subplot(111) |
120 | | -ax.plot(drifter_1.time, drifter_1.radius_s / 1e3, label="loopers") |
121 | | -drifter_1.median_filter(7, "time", "radius_s", inplace=True) |
122 | | -drifter_1.loess_filter(15, "time", "radius_s", inplace=True) |
| 116 | +ax.plot(looper.time, looper.radius_s / 1e3, label="loopers") |
| 117 | +looper_radius = looper.copy() |
| 118 | +looper_radius.median_filter(1, "time", "radius_s", inplace=True) |
| 119 | +looper_radius.loess_filter(13, "time", "radius_s", inplace=True) |
| 120 | +ax.plot( |
| 121 | + looper_radius.time, |
| 122 | + looper_radius.radius_s / 1e3, |
| 123 | + label="loopers (filtered half window 13 days)", |
| 124 | +) |
| 125 | +ax.plot(match.time, match.radius_s / 1e3, label="altimetry") |
| 126 | +match_radius = match.copy() |
| 127 | +match_radius.median_filter(1, "time", "radius_s", inplace=True) |
| 128 | +match_radius.loess_filter(13, "time", "radius_s", inplace=True) |
123 | 129 | ax.plot( |
124 | | - drifter_1.time, |
125 | | - drifter_1.radius_s / 1e3, |
126 | | - label="loopers (filtered half window 15 days)", |
| 130 | + match_radius.time, |
| 131 | + match_radius.radius_s / 1e3, |
| 132 | + label="altimetry (filtered half window 13 days)", |
127 | 133 | ) |
128 | | -ax.plot(ed.time, ed.radius_s / 1e3, label="altimetry") |
129 | | -ed.median_filter(7, "time", "radius_s", inplace=True) |
130 | | -ed.loess_filter(15, "time", "radius_s", inplace=True) |
131 | | -ax.plot(ed.time, ed.radius_s / 1e3, label="altimetry (filtered half window 15 days)") |
132 | 134 | ax.set_ylabel("radius(km)"), ax.set_ylim(0, 100) |
133 | 135 | ax.legend() |
| 136 | +ax.set_title("Radius from loopers and altimeter") |
134 | 137 | ax.grid() |
135 | | -_ = ax.set_title("Radius from loopers and altimeter") |
| 138 | + |
| 139 | + |
| 140 | +# %% |
| 141 | +# Animation which show drifter with colocated eddy |
| 142 | +def update(frame): |
| 143 | + # We display last 5 days of loopers trajectory |
| 144 | + m = (looper.time < frame) * (looper.time > (frame - 5)) |
| 145 | + anim.func_animation(frame) |
| 146 | + line.set_data(looper.lon[m], looper.lat[m]) |
| 147 | + |
| 148 | + |
| 149 | +anim = Anim(match, intern=True, figsize=(8, 8), cmap="magma_r", nb_step=10, dpi=75) |
| 150 | +# mappable to show drifter in red |
| 151 | +line = anim.ax.plot([], [], "r", lw=4, zorder=100)[0] |
| 152 | +anim.fig.suptitle("") |
| 153 | +_ = VideoAnimation(anim.fig, update, frames=np.arange(*anim.period, 1), interval=125) |
0 commit comments