Skip to content

Commit bdabfe6

Browse files
committed
update network example to be build remotely
1 parent 9f43829 commit bdabfe6

File tree

18 files changed

+1585
-265
lines changed

18 files changed

+1585
-265
lines changed

examples/01_general_things/pet_storage.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
There are 3 class of files:
1010
1111
- **Eddies collections** : contain a list of eddies without link between them
12-
- **Track eddies collections** : manage eddies associated in trajectories, the ```track``` field allows to separate each trajectory
13-
- **Network eddies collections** : manage eddies associated in networks, the ```track``` and ```segment``` fields allow to separate observations
12+
- **Track eddies collections** :
13+
manage eddies associated in trajectories, the ```track``` field allows to separate each trajectory
14+
- **Network eddies collections** :
15+
manage eddies associated in networks, the ```track``` and ```segment``` fields allow to separate observations
1416
"""
1517

1618
import py_eddy_tracker_sample
@@ -62,7 +64,8 @@
6264
# Tracks eddies collections add several fields :
6365
#
6466
# - **track** : Trajectory number
65-
# - **observation_flag** : Flag indicating if the value is interpolated between two observations or not (0: observed eddy, 1: interpolated eddy)"
67+
# - **observation_flag** : Flag indicating if the value is interpolated between two observations or not
68+
# (0: observed eddy, 1: interpolated eddy)"
6669
# - **observation_number** : Eddy temporal index in a trajectory, days starting at the eddy first detection
6770
# - **cost_association** : result of the cost function to associate the eddy with the next observation
6871
eddies_tracks = TrackEddiesObservations.load_file(
@@ -78,7 +81,8 @@
7881
#
7982
# - track : ID of network (ID 0 correspond to lonely eddies)
8083
# - segment : ID of a segment within a network (from 1 to N)
81-
# - previous_obs : Index of the previous observation in the full dataset, if -1 there are no previous observation (the segment starts)
84+
# - previous_obs : Index of the previous observation in the full dataset,
85+
# if -1 there are no previous observation (the segment starts)
8286
# - next_obs : Index of the next observation in the full dataset, if -1 there are no next observation (the segment ends)
8387
# - previous_cost : Result of the cost function (1 is a good association, 0 is bad) with previous observation
8488
# - next_cost : Result of the cost function (1 is a good association, 0 is bad) with next observation

examples/07_cube_manipulation/pet_fsle_med.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def check_p(x, y, flse, theta, m_set, m, dt, dist_init=0.02, dist_max=0.6):
7070
theta[i] = arctan2(at1, at2 + s2) * 180 / pi
7171
# To know where value are set
7272
m_set[i] = False
73-
# To stop partcile advection
73+
# To stop particle advection
7474
m[i0], m[i_n], m[i_e] = True, True, True
7575

7676

examples/16_network/pet_atlas.py

Lines changed: 50 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
from numpy import ma
77

88
import py_eddy_tracker.gui
9-
from py_eddy_tracker.data import get_path
9+
from py_eddy_tracker.data import get_remote_sample
1010
from py_eddy_tracker.observations.network import NetworkObservations
1111

12-
n = NetworkObservations.load_file(get_path("Anticyclonic_seg.nc"))
12+
n = NetworkObservations.load_file(
13+
get_remote_sample(
14+
"eddies_med_adt_allsat_dt2018_err70_filt500_order1/Anticyclonic_network.nc"
15+
)
16+
)
1317
# %%
1418
# Parameters
1519
step = 1 / 10.0
1620
bins = ((-10, 37, step), (30, 46, step))
1721
kw_time = dict(cmap="terrain_r", factor=100.0 / n.nb_days, name="count")
18-
kw_ratio = dict(cmap=plt.get_cmap("viridis", 10))
22+
kw_ratio = dict(cmap=plt.get_cmap("YlGnBu_r", 10))
1923

2024

2125
# %%
@@ -57,19 +61,17 @@ def update_axes(ax, mappable=None):
5761
update_axes(ax, m).set_label("Pixel used in % of time")
5862

5963
# %%
60-
# Display the ratio between the short and total presence.
61-
#
62-
# Light = mostly short networks
63-
ax = start_axes("")
64-
m = g_10.display(
65-
ax,
66-
**kw_ratio,
67-
vmin=50,
68-
vmax=100,
69-
name=g_10.vars["count"] * 100.0 / g_all.vars["count"]
70-
)
64+
# Ratio
65+
# ^^^^^
66+
# Ratio between the longer and total presence
67+
ax = start_axes("")
68+
g_ = g_10.vars["count"] * 100.0 / g_all.vars["count"]
69+
m = g_10.display(ax, **kw_ratio, vmin=50, vmax=100, name=g_)
7170
update_axes(ax, m).set_label("Pixel used in % all atlas")
71+
7272
# %%
73+
# Blue = mostly short networks
74+
#
7375
# Network longer than 20 days
7476
# ---------------------------
7577
# Display the % of time each pixel (1/10°) is within an anticyclonic network
@@ -81,57 +83,34 @@ def update_axes(ax, mappable=None):
8183
update_axes(ax, m).set_label("Pixel used in % of time")
8284

8385
# %%
84-
# Display the ratio between the short and total presence.
85-
#
86-
# Light = mostly short networks
87-
ax = start_axes("")
88-
m = g_20.display(
89-
ax,
90-
**kw_ratio,
91-
vmin=50,
92-
vmax=100,
93-
name=g_20.vars["count"] * 100.0 / g_all.vars["count"]
94-
)
86+
# Ratio
87+
# ^^^^^
88+
# Ratio between the longer and total presence
89+
ax = start_axes("")
90+
g_ = g_20.vars["count"] * 100.0 / g_all.vars["count"]
91+
m = g_20.display(ax, **kw_ratio, vmin=50, vmax=100, name=g_)
9592
update_axes(ax, m).set_label("Pixel used in % all atlas")
9693

9794
# %%
98-
# Display the ratio between the short and total presence.
99-
#
100-
# Light = mostly short networks
101-
#
102-
# Networks shorter than 365 days are masked
103-
ax = start_axes("")
104-
m = g_20.display(
105-
ax,
106-
**kw_ratio,
107-
vmin=50,
108-
vmax=100,
109-
name=ma.array(
110-
g_20.vars["count"] * 100.0 / g_all.vars["count"], mask=g_all.vars["count"] < 365
111-
)
95+
# Now we will hide pixel which are used less than 365 times
96+
g_ = ma.array(
97+
g_20.vars["count"] * 100.0 / g_all.vars["count"], mask=g_all.vars["count"] < 365
11298
)
99+
ax = start_axes("")
100+
m = g_20.display(ax, **kw_ratio, vmin=50, vmax=100, name=g_)
113101
update_axes(ax, m).set_label("Pixel used in % all atlas")
114102
# %%
115-
# Display the ratio between the short and total presence.
116-
#
117-
# Networks longer than 365 days are masked
118-
#
119-
# # -> Coastal areas are mostly populated by short networks
120-
ax = start_axes("")
121-
m = g_20.display(
122-
ax,
123-
**kw_ratio,
124-
vmin=50,
125-
vmax=100,
126-
name=ma.array(
127-
g_20.vars["count"] * 100.0 / g_all.vars["count"],
128-
mask=g_all.vars["count"] >= 365,
129-
)
103+
# Now we will hide pixel which are used more than 365 times
104+
ax = start_axes("")
105+
g_ = ma.array(
106+
g_20.vars["count"] * 100.0 / g_all.vars["count"], mask=g_all.vars["count"] >= 365
130107
)
108+
m = g_20.display(ax, **kw_ratio, vmin=50, vmax=100, name=g_)
131109
update_axes(ax, m).set_label("Pixel used in % all atlas")
132110

133-
134111
# %%
112+
# Coastal areas are mostly populated by short networks
113+
#
135114
# All merging
136115
# -----------
137116
# Display the occurence of merging events
@@ -143,18 +122,13 @@ def update_axes(ax, mappable=None):
143122
# %%
144123
# Ratio merging events / eddy presence
145124
ax = start_axes("")
146-
m = g_all_merging.display(
147-
ax,
148-
**kw_ratio,
149-
vmin=0,
150-
vmax=5,
151-
name=g_all_merging.vars["count"] * 100.0 / g_all.vars["count"]
152-
)
125+
g_ = g_all_merging.vars["count"] * 100.0 / g_all.vars["count"]
126+
m = g_all_merging.display(ax, **kw_ratio, vmin=0, vmax=5, name=g_)
153127
update_axes(ax, m).set_label("Pixel used in % all atlas")
154128

155129
# %%
156-
# Merging in networks longer than 10 days, with dead end remove (shorter than 5 days)
157-
# -----------------------------------------------------------------------------------
130+
# Merging in networks longer than 10 days, with dead end remove (shorter than 10 observations)
131+
# --------------------------------------------------------------------------------------------
158132
ax = start_axes("")
159133
merger = n10.remove_dead_end(nobs=10).merging_event()
160134
g_10_merging = merger.grid_count(bins)
@@ -170,17 +144,13 @@ def update_axes(ax, mappable=None):
170144
m = g_10_merging.display(ax, **kw_time, vmin=0, vmax=1)
171145
update_axes(ax, m).set_label("Pixel used in % of time")
172146
# %%
147+
# Ratio merging events / eddy presence
173148
ax = start_axes("")
174-
m = g_10_merging.display(
175-
ax,
176-
**kw_ratio,
177-
vmin=0,
178-
vmax=5,
179-
name=ma.array(
180-
g_10_merging.vars["count"] * 100.0 / g_10.vars["count"],
181-
mask=g_10.vars["count"] < 365,
182-
)
149+
g_ = ma.array(
150+
g_10_merging.vars["count"] * 100.0 / g_10.vars["count"],
151+
mask=g_10.vars["count"] < 365,
183152
)
153+
m = g_10_merging.display(ax, **kw_ratio, vmin=0, vmax=5, name=g_)
184154
update_axes(ax, m).set_label("Pixel used in % all atlas")
185155

186156
# %%
@@ -193,15 +163,10 @@ def update_axes(ax, mappable=None):
193163
update_axes(ax, m).set_label("Pixel used in % of time")
194164

195165
# %%
196-
# Ratio merging events / eddy presence
166+
# Ratio spliting events / eddy presence
197167
ax = start_axes("")
198-
m = g_all_spliting.display(
199-
ax,
200-
**kw_ratio,
201-
vmin=0,
202-
vmax=5,
203-
name=g_all_spliting.vars["count"] * 100.0 / g_all.vars["count"]
204-
)
168+
g_ = g_all_spliting.vars["count"] * 100.0 / g_all.vars["count"]
169+
m = g_all_spliting.display(ax, **kw_ratio, vmin=0, vmax=5, name=g_)
205170
update_axes(ax, m).set_label("Pixel used in % all atlas")
206171

207172
# %%
@@ -213,14 +178,9 @@ def update_axes(ax, mappable=None):
213178
update_axes(ax, m).set_label("Pixel used in % of time")
214179
# %%
215180
ax = start_axes("")
216-
m = g_10_spliting.display(
217-
ax,
218-
**kw_ratio,
219-
vmin=0,
220-
vmax=5,
221-
name=ma.array(
222-
g_10_spliting.vars["count"] * 100.0 / g_10.vars["count"],
223-
mask=g_10.vars["count"] < 365,
224-
)
181+
g_ = ma.array(
182+
g_10_spliting.vars["count"] * 100.0 / g_10.vars["count"],
183+
mask=g_10.vars["count"] < 365,
225184
)
185+
m = g_10_spliting.display(ax, **kw_ratio, vmin=0, vmax=5, name=g_)
226186
update_axes(ax, m).set_label("Pixel used in % all atlas")

examples/16_network/pet_group_anim.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _repr_html_(self, *args, **kwargs):
2424
"""To get video in html and have a player"""
2525
content = self.to_html5_video()
2626
return re.sub(
27-
'width="[0-9]*"\sheight="[0-9]*"', 'width="100%" height="100%"', content
27+
r'width="[0-9]*"\sheight="[0-9]*"', 'width="100%" height="100%"', content
2828
)
2929

3030
def save(self, *args, **kwargs):
@@ -93,7 +93,7 @@ def get_group_array(self, results, nb_obs):
9393

9494
# %%
9595
# Get data from period and area
96-
e = EddiesObservations.load_file(data.get_path("Anticyclonic_seg.nc"))
96+
e = EddiesObservations.load_file(data.get_path("network_med.nc"))
9797
e = e.extract_with_mask((e.time >= t0) * (e.time < t1)).extract_with_area(
9898
dict(llcrnrlon=25, urcrnrlon=35, llcrnrlat=31, urcrnrlat=37.5)
9999
)
@@ -134,7 +134,7 @@ def update(frame):
134134
# ----
135135
fig = plt.figure(figsize=(16, 9), dpi=50)
136136
ax = fig.add_axes([0, 0, 1, 1])
137-
ax.set_aspect("equal"), ax.grid(), ax.set_xlim(26, 34), ax.set_ylim(32, 36.5)
137+
ax.set_aspect("equal"), ax.grid(), ax.set_xlim(26, 34), ax.set_ylim(31, 35.5)
138138
groups = ax.scatter(
139139
e.lon,
140140
e.lat,
@@ -145,6 +145,6 @@ def update(frame):
145145
)
146146
current_contour = ax.plot([], [], "k", lw=2, label="Current contour")[0]
147147
matched_contour = ax.plot([], [], "r", lw=1, ls="--", label="Candidate contour")[0]
148-
txt = ax.text(31.5, 35.5, "", fontsize=25)
148+
txt = ax.text(29, 35, "", fontsize=25)
149149
ax.legend(fontsize=25)
150150
ani = VideoAnimation(fig, update, frames=len(NETWORK_GROUPS), interval=220)

examples/16_network/pet_ioannou_2017_case.py

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@
33
============
44
Figure 10 from https://doi.org/10.1002/2017JC013158
55
6+
We want to find the Ierapetra Eddy described above in a network demonstration run.
67
"""
78

89
# %%
9-
# We want to find the Ierapetra Eddy described above in the networks
10-
1110
import re
12-
13-
# %%
1411
from datetime import datetime, timedelta
1512

16-
import numpy as np
1713
from matplotlib import colors
1814
from matplotlib import pyplot as plt
1915
from matplotlib.animation import FuncAnimation
2016
from matplotlib.ticker import FuncFormatter
17+
from numpy import arange, where
2118

2219
import py_eddy_tracker.gui
2320
from py_eddy_tracker.appli.gui import Anim
24-
from py_eddy_tracker.data import get_remote_sample
21+
from py_eddy_tracker.data import get_path
2522
from py_eddy_tracker.observations.network import NetworkObservations
2623

2724

@@ -74,23 +71,8 @@ def update_axes(ax, mappable=None):
7471

7572

7673
# %%
77-
# We know the position and the time of a specific eddy
78-
#
79-
# `n.extract_with_mask` give us the corresponding network
80-
n = NetworkObservations.load_file(
81-
get_remote_sample(
82-
"eddies_med_adt_allsat_dt2018_err70_filt500_order1/Anticyclonic_network.nc"
83-
)
84-
)
85-
i = np.where(
86-
(n.lat > 33)
87-
* (n.lat < 34)
88-
* (n.lon > 22)
89-
* (n.lon < 23)
90-
* (n.time > 20630)
91-
* (n.time < 20650)
92-
)[0][0]
93-
ioannou_case = n.extract_with_mask(n.track == n.track[i])
74+
# We know the network ID, we will get directly
75+
ioannou_case = NetworkObservations.load_file(get_path("network_med.nc")).network(651)
9476
print(ioannou_case.infos())
9577

9678
# %%
@@ -113,7 +95,7 @@ def update_axes(ax, mappable=None):
11395
# Sub network and new numbering
11496
# -----------------------------
11597
# Here we chose to keep only the order 3 segments relatives to our chosen eddy
116-
i = np.where(
98+
i = where(
11799
(ioannou_case.lat > 33)
118100
* (ioannou_case.lat < 34)
119101
* (ioannou_case.lon > 22)
@@ -128,22 +110,22 @@ def update_axes(ax, mappable=None):
128110
# Anim
129111
# ----
130112
# Quick movie to see better!
131-
cmap = colors.ListedColormap(
132-
list(close_to_i3.COLORS), name="from_list", N=close_to_i3.segment.max()
133-
)
134113
a = Anim(
135114
close_to_i3,
136115
figsize=(12, 4),
137-
cmap=cmap,
116+
cmap=colors.ListedColormap(
117+
list(close_to_i3.COLORS), name="from_list", N=close_to_i3.segment.max() + 1
118+
),
138119
nb_step=7,
139-
dpi=80,
120+
dpi=70,
140121
field_color="segment",
141122
field_txt="segment",
142123
)
143124
a.ax.set_xlim(19, 30), a.ax.set_ylim(32, 35.25)
144125
a.ax.update_env()
145126
a.txt.set_position((21.5, 32.7))
146-
kwargs = dict(frames=np.arange(*a.period), interval=100)
127+
# We display in video only from the 100th day to the 500th
128+
kwargs = dict(frames=arange(*a.period)[100:501], interval=100)
147129
ani = VideoAnimation(a.fig, a.func_animation, **kwargs)
148130

149131
# %%

0 commit comments

Comments
 (0)