|
7 | 7 | from py_eddy_tracker.observations.tracking import TrackEddiesObservations
|
8 | 8 | from py_eddy_tracker.generic import cumsum_by_track
|
9 | 9 | import py_eddy_tracker_sample
|
10 |
| -from numpy import arange |
| 10 | +from numpy import arange, ones |
11 | 11 |
|
12 | 12 | # %%
|
13 | 13 | # Load an experimental med atlas over a period of 26 years (1993-2019)
|
|
17 | 17 | c = TrackEddiesObservations.load_file(
|
18 | 18 | py_eddy_tracker_sample.get_path("eddies_med_adt_allsat_dt2018/Cyclonic.zarr")
|
19 | 19 | )
|
| 20 | +nb_year = (a.period[1] - a.period[0] + 1) / 365.25 |
20 | 21 |
|
21 | 22 | # %%
|
22 | 23 | # Filtering position to remove noisy position
|
|
25 | 26 |
|
26 | 27 | # %%
|
27 | 28 | # Compute curvilign distance
|
28 |
| -d_a = cumsum_by_track(a.distance_to_next(), a.tracks) / 1000.0 |
29 |
| -d_c = cumsum_by_track(c.distance_to_next(), c.tracks) / 1000.0 |
| 29 | +i0, nb = a.index_from_track, a.nb_obs_by_track |
| 30 | +d_a = cumsum_by_track(a.distance_to_next(), a.tracks)[(i0 - 1 + nb)[nb != 0]] / 1000.0 |
| 31 | +i0, nb = c.index_from_track, c.nb_obs_by_track |
| 32 | +d_c = cumsum_by_track(c.distance_to_next(), c.tracks)[(i0 - 1 + nb)[nb != 0]] / 1000.0 |
30 | 33 |
|
31 | 34 | # %%
|
32 |
| -# Plot |
33 |
| -fig = plt.figure() |
34 |
| -ax_propagation = fig.add_axes([0.05, 0.55, 0.4, 0.4]) |
35 |
| -ax_cum_propagation = fig.add_axes([0.55, 0.55, 0.4, 0.4]) |
36 |
| -ax_ratio_propagation = fig.add_axes([0.05, 0.05, 0.4, 0.4]) |
37 |
| -ax_ratio_cum_propagation = fig.add_axes([0.55, 0.05, 0.4, 0.4]) |
38 |
| - |
39 |
| -bins = arange(0, 1500, 10) |
40 |
| -cum_a, bins, _ = ax_cum_propagation.hist( |
41 |
| - d_a, histtype="step", bins=bins, label="Anticyclonic", color="r" |
42 |
| -) |
43 |
| -cum_c, bins, _ = ax_cum_propagation.hist( |
44 |
| - d_c, histtype="step", bins=bins, label="Cyclonic", color="b" |
45 |
| -) |
46 |
| - |
47 |
| -x = (bins[1:] + bins[:-1]) / 2.0 |
48 |
| -ax_ratio_cum_propagation.plot(x, cum_c / cum_a) |
49 |
| - |
50 |
| -nb_a, nb_c = cum_a[:-1] - cum_a[1:], cum_c[:-1] - cum_c[1:] |
51 |
| -ax_propagation.plot(x[1:], nb_a, label="Anticyclonic", color="r") |
52 |
| -ax_propagation.plot(x[1:], nb_c, label="Cyclonic", color="b") |
53 |
| - |
54 |
| -ax_ratio_propagation.plot(x[1:], nb_c / nb_a) |
55 |
| - |
56 |
| -for ax in ( |
57 |
| - ax_propagation, |
58 |
| - ax_cum_propagation, |
59 |
| - ax_ratio_cum_propagation, |
60 |
| - ax_ratio_propagation, |
61 |
| -): |
62 |
| - ax.set_xlim(0, 1000) |
63 |
| - if ax in (ax_propagation, ax_cum_propagation): |
64 |
| - ax.set_ylim(1, None) |
65 |
| - ax.set_yscale("log") |
66 |
| - ax.legend() |
| 35 | +# Setup axes |
| 36 | +figure = plt.figure(figsize=(12, 8)) |
| 37 | +ax_ratio_cum = figure.add_axes([0.55, 0.06, 0.42, 0.34]) |
| 38 | +ax_ratio = figure.add_axes([0.07, 0.06, 0.46, 0.34]) |
| 39 | +ax_cum = figure.add_axes([0.55, 0.43, 0.42, 0.54]) |
| 40 | +ax = figure.add_axes([0.07, 0.43, 0.46, 0.54]) |
| 41 | +ax.set_ylabel("Eddies by year") |
| 42 | +ax_ratio.set_ylabel("Ratio Cyclonic/Anticyclonic") |
| 43 | +for ax_ in (ax, ax_cum, ax_ratio_cum, ax_ratio): |
| 44 | + ax_.set_xlim(0, 1000) |
| 45 | + if ax_ in (ax, ax_cum): |
| 46 | + ax_.set_ylim(1e-1, 1e4), ax_.set_yscale("log") |
67 | 47 | else:
|
68 |
| - ax.set_ylim(0, 2) |
69 |
| - ax.set_ylabel("Ratio Cyclonic/Anticyclonic") |
70 |
| - ax.set_xlabel("Propagation (km)") |
71 |
| - ax.grid() |
| 48 | + ax_.set_xlabel("Propagation in km (with bins of 20 km)") |
| 49 | + ax_.set_ylim(0, 2) |
| 50 | + ax_.axhline(1, color="g", lw=2) |
| 51 | + ax_.grid() |
| 52 | +ax_cum.xaxis.set_ticklabels([]), ax_cum.yaxis.set_ticklabels([]) |
| 53 | +ax.xaxis.set_ticklabels([]), ax_ratio_cum.yaxis.set_ticklabels([]) |
| 54 | + |
| 55 | +# plot data |
| 56 | +bin_hist = arange(0, 2000, 20) |
| 57 | +x = (bin_hist[1:] + bin_hist[:-1]) / 2.0 |
| 58 | +w_a, w_c = ones(d_a.shape) / nb_year, ones(d_c.shape) / nb_year |
| 59 | +kwargs_a = dict(histtype="step", bins=bin_hist, x=d_a, color="r", weights=w_a) |
| 60 | +kwargs_c = dict(histtype="step", bins=bin_hist, x=d_c, color="b", weights=w_c) |
| 61 | +cum_a, _, _ = ax_cum.hist(cumulative=-1, **kwargs_a) |
| 62 | +cum_c, _, _ = ax_cum.hist(cumulative=-1, **kwargs_c) |
| 63 | +nb_a, _, _ = ax.hist(label="Anticyclonic", **kwargs_a) |
| 64 | +nb_c, _, _ = ax.hist(label="Cyclonic", **kwargs_c) |
| 65 | +ax_ratio_cum.plot(x, cum_c / cum_a) |
| 66 | +ax_ratio.plot(x, nb_c / nb_a) |
| 67 | +ax.legend() |
0 commit comments