Skip to content

Commit b7964eb

Browse files
committed
- Add documentation in examples
- change marker
1 parent 7be041e commit b7964eb

File tree

6 files changed

+103
-27
lines changed

6 files changed

+103
-27
lines changed

examples/16_network/pet_atlas.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
Network analyse
3-
===============
2+
Network Analysis
3+
================
44
"""
55
from matplotlib import pyplot as plt
66
from numpy import ma
@@ -21,7 +21,7 @@
2121

2222

2323
# %%
24-
# Function
24+
# Functions
2525
def start_axes(title):
2626
fig = plt.figure(figsize=(13, 5))
2727
ax = fig.add_axes([0.03, 0.03, 0.90, 0.94], projection="full_axes")
@@ -41,6 +41,7 @@ def update_axes(ax, mappable=None):
4141
# %%
4242
# All
4343
# ---
44+
# Display the % of time each pixel (1/10°) is within an anticyclonic network
4445
ax = start_axes("")
4546
g_all = n.grid_count(bins)
4647
m = g_all.display(ax, **kw_time, vmin=0, vmax=75)
@@ -49,12 +50,16 @@ def update_axes(ax, mappable=None):
4950
# %%
5051
# Network longer than 10 days
5152
# ---------------------------
53+
# Display the % of time each pixel (1/10°) is within an anticyclonic network
54+
# which total lifetime in longer than 10 days
5255
ax = start_axes("")
5356
n10 = n.longer_than(10)
5457
g_10 = n10.grid_count(bins)
5558
m = g_10.display(ax, **kw_time, vmin=0, vmax=75)
5659
update_axes(ax, m).set_label("Pixel used in % of time")
5760

61+
# Display the ratio between the short and total presence.
62+
# Red = mostly short networks
5863
ax = start_axes("")
5964
m = g_10.display(
6065
ax,
@@ -67,12 +72,17 @@ def update_axes(ax, mappable=None):
6772
# %%
6873
# Network longer than 20 days
6974
# ---------------------------
75+
# Display the % of time each pixel (1/10°) is within an anticyclonic network
76+
# which total lifetime in longer than 20 days
7077
ax = start_axes("")
7178
n20 = n.longer_than(20)
7279
g_20 = n20.grid_count(bins)
7380
m = g_20.display(ax, **kw_time, vmin=0, vmax=75)
7481
update_axes(ax, m).set_label("Pixel used in % of time")
7582

83+
# %%
84+
# Display the ratio between the short and total presence.
85+
# Red = mostly short networks
7686
ax = start_axes("")
7787
m = g_20.display(
7888
ax,
@@ -82,6 +92,11 @@ def update_axes(ax, mappable=None):
8292
name=g_20.vars["count"] * 100.0 / g_all.vars["count"]
8393
)
8494
update_axes(ax, m).set_label("Pixel used in % all atlas")
95+
96+
# %%
97+
# Display the ratio between the short and total presence.
98+
# Red = mostly short networks
99+
# Networks shorter than 365 days are masked
85100
ax = start_axes("")
86101
m = g_20.display(
87102
ax,
@@ -93,6 +108,11 @@ def update_axes(ax, mappable=None):
93108
)
94109
)
95110
update_axes(ax, m).set_label("Pixel used in % all atlas")
111+
# %%
112+
# Display the ratio between the short and total presence.
113+
# Red = mostly short networks
114+
# Networks longer than 365 days are masked
115+
# -> Coastal areas are mostly populated by short networks
96116
ax = start_axes("")
97117
m = g_20.display(
98118
ax,
@@ -110,11 +130,13 @@ def update_axes(ax, mappable=None):
110130
# %%
111131
# All merging
112132
# -----------
133+
# Display the occurence of merging events
113134
ax = start_axes("")
114135
g_all_merging = n.merging_event().grid_count(bins)
115136
m = g_all_merging.display(ax, **kw_time, vmin=0, vmax=0.2)
116137
update_axes(ax, m).set_label("Pixel used in % of time")
117138
# %%
139+
# Ratio merging events / eddy presence
118140
ax = start_axes("")
119141
m = g_all_merging.display(
120142
ax,
@@ -126,8 +148,8 @@ def update_axes(ax, mappable=None):
126148
update_axes(ax, m).set_label("Pixel used in % all atlas")
127149

128150
# %%
129-
# Merging in network longer than 10 days
130-
# --------------------------------------
151+
# Merging in networks longer than 10 days
152+
# ---------------------------------------
131153
ax = start_axes("")
132154
g_10_merging = n10.merging_event().grid_count(bins)
133155
m = g_10_merging.display(ax, **kw_time, vmin=0, vmax=0.2)

examples/16_network/pet_ioannou_2017_case.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
Figure 10 from https://doi.org/10.1002/2017JC013158
55
66
"""
7+
8+
# %%
9+
# We want to find the Ierapetra Eddy described above in the networks
10+
11+
# %%
712
from datetime import datetime, timedelta
813

914
import numpy as np
1015
from matplotlib import pyplot as plt
1116
from matplotlib.animation import FuncAnimation
1217
from matplotlib.ticker import FuncFormatter
18+
from matplotlib import colors
1319

1420
import py_eddy_tracker.gui
1521
from py_eddy_tracker.appli.gui import Anim
@@ -62,6 +68,8 @@ def update_axes(ax, mappable=None):
6268

6369

6470
# %%
71+
# We know the position and the time of a specific eddy
72+
# `n.extract_with_mask` give us the corresponding network
6573
n = NetworkObservations.load_file(
6674
"med/Anticyclonic_seg.nc"
6775
)
@@ -77,13 +85,15 @@ def update_axes(ax, mappable=None):
7785
print(ioannou_case.infos())
7886

7987
# %%
88+
# It seems that this network is huge! Our case is in purple...
8089
ax = start_axes()
8190
ioannou_case.plot(ax)
8291
update_axes(ax)
8392

8493
# %%
8594
# Full Timeline
8695
# -------------
96+
# The network span for many years... How to cut the interesting part?
8797
fig = plt.figure(figsize=(15, 5))
8898
ax = fig.add_axes([0.04, 0.05, 0.92, 0.92])
8999
ax.xaxis.set_major_formatter(formatter), ax.grid()
@@ -93,6 +103,7 @@ def update_axes(ax, mappable=None):
93103
# %%
94104
# Sub network and new numbering
95105
# -----------------------------
106+
# Here we chose to keep only the order 3 segments relatives to our chosen eddy
96107
i = np.where(
97108
(ioannou_case.lat > 33)
98109
* (ioannou_case.lat < 34)
@@ -107,10 +118,14 @@ def update_axes(ax, mappable=None):
107118
# %%
108119
# Anim
109120
# ----
121+
# Quick movie to see better!
122+
cmap = colors.ListedColormap(
123+
list(close_to_i3.COLORS), name="from_list", N=close_to_i3.segment.max()
124+
)
110125
a = Anim(
111126
close_to_i3,
112127
figsize=(12, 4),
113-
cmap="Spectral_r",
128+
cmap=cmap,
114129
nb_step=7,
115130
dpi=55,
116131
field_color="segment",
@@ -136,8 +151,8 @@ def update_axes(ax, mappable=None):
136151
update_axes(ax)
137152

138153
# %%
139-
# Local Timeline
140-
# --------------
154+
# Latitude Timeline
155+
# -----------------
141156
ax = timeline_axes(f"Close segments ({close_to_i3.infos()})")
142157
n_copy = close_to_i3.copy()
143158
n_copy.median_filter(15, "time", "latitude")
@@ -146,6 +161,7 @@ def update_axes(ax, mappable=None):
146161
# %%
147162
# Local radius timeline
148163
# ---------------------
164+
# Effective (bold) and Speed (thin) Radius together
149165
n_copy.median_filter(2, "time", "radius_e")
150166
n_copy.median_filter(2, "time", "radius_s")
151167
for b0, b1 in [
@@ -167,14 +183,16 @@ def update_axes(ax, mappable=None):
167183
)
168184

169185
# %%
170-
# Parameter timeline
171-
# ------------------
186+
# Parameters timeline
187+
# -------------------
188+
# Effective Radius
172189
kw = dict(s=35, cmap=plt.get_cmap("Spectral_r", 8), zorder=10)
173190
ax = timeline_axes()
174191
m = close_to_i3.scatter_timeline(ax, "radius_e", factor=1e-3, vmin=20, vmax=100, **kw)
175192
cb = update_axes(ax, m["scatter"])
176193
cb.set_label("Effective radius (km)")
177194
# %%
195+
# Shape error
178196
ax = timeline_axes()
179197
m = close_to_i3.scatter_timeline(ax, "shape_error_e", vmin=14, vmax=70, **kw)
180198
cb = update_axes(ax, m["scatter"])

examples/16_network/pet_relative.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@
1818
e.lon[:] = (e.lon + 180) % 360 - 180
1919
e.contour_lon_e[:] = ((e.contour_lon_e.T - e.lon + 180) % 360 - 180 + e.lon).T
2020
e.contour_lon_s[:] = ((e.contour_lon_s.T - e.lon + 180) % 360 - 180 + e.lon).T
21-
##############
21+
# %%
22+
# Do segmentation
23+
# ---------------
24+
# Segmentation based on maximum overlap, temporal window for candidates = 5 days
2225
n = NetworkObservations.from_split_network(e, e.split_network(intern=False, window=5))
2326

2427
# %%
2528
# Timeline
2629
# --------
2730

2831
# %%
29-
# Display timeline
32+
# Display timeline with events
33+
# A segment generated by a splitting is marked with a star
34+
# A segment merging in another is marked with an exagon
3035
fig = plt.figure(figsize=(15, 5))
3136
ax = fig.add_axes([0.04, 0.04, 0.92, 0.92])
3237
_ = n.display_timeline(ax)
@@ -38,27 +43,34 @@
3843
_ = n.display_timeline(ax, event=False)
3944

4045
# %%
41-
# Timeline by latitude mean
46+
# Timeline by mean latitude
4247
# -------------------------
48+
# Display timeline with the mean latitude of the segments in yaxis
4349
fig = plt.figure(figsize=(15, 5))
4450
ax = fig.add_axes([0.04, 0.04, 0.92, 0.92])
51+
ax.set_ylabel("Latitude")
4552
_ = n.display_timeline(ax, field="latitude")
4653

4754
# %%
48-
# Timeline by radius mean
55+
# Timeline by mean Effective Radius
4956
# -----------------------
57+
# The factor argument is applied on the chosen field
5058
fig = plt.figure(figsize=(15, 5))
5159
ax = fig.add_axes([0.04, 0.04, 0.92, 0.92])
52-
_ = n.display_timeline(ax, field="radius_e")
60+
ax.set_ylabel("Effective Radius (km)")
61+
_ = n.display_timeline(ax, field="radius_e", factor=1e-3)
5362

5463
# %%
5564
# Timeline by latitude
5665
# --------------------
66+
# Use `method="all"` to display the consecutive values of the field
5767
fig = plt.figure(figsize=(15, 5))
5868
ax = fig.add_axes([0.04, 0.05, 0.92, 0.92])
69+
ax.set_ylabel("Latitude")
5970
_ = n.display_timeline(ax, field="lat", method="all")
6071

6172
# %%
73+
# You can filter the data, here with a time window of 15 days
6274
fig = plt.figure(figsize=(15, 5))
6375
ax = fig.add_axes([0.04, 0.05, 0.92, 0.92])
6476
n_copy = n.copy()
@@ -68,6 +80,8 @@
6880
# %%
6981
# Parameters timeline
7082
# -------------------
83+
# Scatter is usefull to display the parameters' temporal evolution
84+
# Effective Radius and Amplitude
7185
kw = dict(s=25, cmap="Spectral_r", zorder=10)
7286
fig = plt.figure(figsize=(15, 8))
7387
ax = fig.add_axes([0.04, 0.54, 0.90, 0.44])
@@ -85,6 +99,7 @@
8599
cb.set_label("Amplitude (cm)")
86100

87101
# %%
102+
# Speed
88103
fig = plt.figure(figsize=(15, 5))
89104
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88])
90105
m = n.scatter_timeline(ax, "speed_average", factor=100, vmin=0, vmax=40, **kw)
@@ -94,6 +109,7 @@
94109
cb.set_label("Maximum speed (cm/s)")
95110

96111
# %%
112+
# Speed Radius
97113
fig = plt.figure(figsize=(15, 5))
98114
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88])
99115
m = n.scatter_timeline(ax, "radius_s", factor=1e-3, vmin=20, vmax=100, **kw)
@@ -105,7 +121,7 @@
105121
# %%
106122
# Remove dead branch
107123
# ------------------
108-
# Remove all tiny segment with less than N obs which didn't join two segments
124+
# Remove all tiny segments with less than N obs which didn't join two segments
109125
#
110126
# .. warning::
111127
# Must be explore, no solution to solve all the case
@@ -122,6 +138,7 @@
122138
# %%
123139
# Keep close relative
124140
# -------------------
141+
# When you want to investigate one particular observation and select only the closest segments
125142
# First choose an observation in the network
126143
fig = plt.figure(figsize=(15, 5))
127144
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88])
@@ -132,6 +149,7 @@
132149
_ = ax.plot(*obs_args, **obs_kw)
133150

134151
# %%
152+
# Colors show the relative order of the segment with regards to the chosen one
135153
fig = plt.figure(figsize=(15, 5))
136154
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88])
137155
m = n.scatter_timeline(
@@ -143,18 +161,21 @@
143161
)
144162
cb.set_label("Relative order")
145163
# %%
164+
# You want to keep only the segments at the order 1
146165
fig = plt.figure(figsize=(15, 5))
147166
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88])
148167
close_to_i1 = n.relative(i, order=1)
149168
ax.set_title(f"Close segments ({close_to_i1.infos()})")
150169
_ = close_to_i1.display_timeline(ax)
151170
# %%
171+
# You want to keep the segments until order 2
152172
fig = plt.figure(figsize=(15, 5))
153173
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88])
154174
close_to_i2 = n.relative(i, order=2)
155175
ax.set_title(f"Close segments ({close_to_i2.infos()})")
156176
_ = close_to_i2.display_timeline(ax)
157177
# %%
178+
# You want to keep the segments until order 3
158179
fig = plt.figure(figsize=(15, 5))
159180
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88])
160181
close_to_i3 = n.relative(i, order=3)
@@ -164,6 +185,7 @@
164185
# %%
165186
# Display track on map
166187
# --------------------
188+
# Only a map can be tricky to understand, with a timeline it's easier!
167189
fig = plt.figure(figsize=(15, 8))
168190
ax = fig.add_axes([0.04, 0.06, 0.94, 0.88], projection="full_axes")
169191
close_to_i2.plot(ax, color_cycle=close_to_i2.COLORS)
@@ -175,6 +197,7 @@
175197
# %%
176198
# Get merging event
177199
# -----------------
200+
# Display the position of the eddies after a merging
178201
fig = plt.figure(figsize=(15, 8))
179202
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88], projection="full_axes")
180203
merging = close_to_i2.merging_event()
@@ -185,6 +208,7 @@
185208
# %%
186209
# Get spliting event
187210
# ------------------
211+
# Display the position of the eddies before a splitting
188212
fig = plt.figure(figsize=(15, 8))
189213
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88], projection="full_axes")
190214
spliting = close_to_i2.spliting_event()
@@ -195,6 +219,7 @@
195219
# %%
196220
# Get birth event
197221
# ------------------
222+
# Display the starting position of non-splitted eddies
198223
fig = plt.figure(figsize=(15, 8))
199224
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88], projection="full_axes")
200225
birth = close_to_i2.birth_event()
@@ -205,6 +230,7 @@
205230
# %%
206231
# Get death event
207232
# ------------------
233+
# Display the last position of non-merged eddies
208234
fig = plt.figure(figsize=(15, 8))
209235
ax = fig.add_axes([0.04, 0.06, 0.90, 0.88], projection="full_axes")
210236
death = close_to_i2.death_event()

0 commit comments

Comments
 (0)