Skip to content

Commit c40d105

Browse files
Merge pull request AntSimi#87 from ludwigVonKoopa/validation_particle
Validation particle
2 parents e934346 + b3f66bc commit c40d105

File tree

54 files changed

+449
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+449
-174
lines changed

examples/16_network/pet_follow_particle.py

Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
from matplotlib import colors
99
from matplotlib import pyplot as plt
1010
from matplotlib.animation import FuncAnimation
11-
from numba import njit
12-
from numba import types as nb_types
13-
from numpy import arange, meshgrid, ones, unique, where, zeros
11+
from numpy import arange, meshgrid, ones, unique, zeros
1412

1513
from py_eddy_tracker import start_logger
1614
from py_eddy_tracker.appli.gui import Anim
1715
from py_eddy_tracker.data import get_demo_path
1816
from py_eddy_tracker.dataset.grid import GridCollection
17+
from py_eddy_tracker.observations.groups import particle_candidate
1918
from py_eddy_tracker.observations.network import NetworkObservations
2019
from py_eddy_tracker.poly import group_obs
2120

@@ -124,81 +123,6 @@ def update(frame):
124123
ani = VideoAnimation(a.fig, update, frames=arange(20200, 20269, step), interval=200)
125124

126125

127-
# %%
128-
# In which observations are the particle
129-
# --------------------------------------
130-
def advect(x, y, c, t0, delta_t):
131-
"""
132-
Advect particle from t0 to t0 + delta_t, with data cube.
133-
"""
134-
kw = dict(nb_step=6, time_step=86400 / 6)
135-
if delta_t < 0:
136-
kw["backward"] = True
137-
delta_t = -delta_t
138-
p = c.advect(x, y, "u", "v", t_init=t0, **kw)
139-
for _ in range(delta_t):
140-
t, x, y = p.__next__()
141-
return t, x, y
142-
143-
144-
def particle_candidate(x, y, c, eddies, t_start, i_target, pct, **kwargs):
145-
# Obs from initial time
146-
m_start = eddies.time == t_start
147-
e = eddies.extract_with_mask(m_start)
148-
# to be able to get global index
149-
translate_start = where(m_start)[0]
150-
# Identify particle in eddies (only in core)
151-
i_start = e.contains(x, y, intern=True)
152-
m = i_start != -1
153-
x, y, i_start = x[m], y[m], i_start[m]
154-
# Advect
155-
t_end, x, y = advect(x, y, c, t_start, **kwargs)
156-
# eddies at last date
157-
m_end = eddies.time == t_end / 86400
158-
e_end = eddies.extract_with_mask(m_end)
159-
# to be able to get global index
160-
translate_end = where(m_end)[0]
161-
# Id eddies for each alive particle (in core and extern)
162-
i_end = e_end.contains(x, y)
163-
# compute matrix and fill target array
164-
get_matrix(i_start, i_end, translate_start, translate_end, i_target, pct)
165-
166-
167-
@njit(cache=True)
168-
def get_matrix(i_start, i_end, translate_start, translate_end, i_target, pct):
169-
nb_start, nb_end = translate_start.size, translate_end.size
170-
# Matrix which will store count for every couple
171-
count = zeros((nb_start, nb_end), dtype=nb_types.int32)
172-
# Number of particles in each origin observation
173-
ref = zeros(nb_start, dtype=nb_types.int32)
174-
# For each particle
175-
for i in range(i_start.size):
176-
i_end_ = i_end[i]
177-
i_start_ = i_start[i]
178-
if i_end_ != -1:
179-
count[i_start_, i_end_] += 1
180-
ref[i_start_] += 1
181-
for i in range(nb_start):
182-
for j in range(nb_end):
183-
pct_ = count[i, j]
184-
# If there are particles from i to j
185-
if pct_ != 0:
186-
# Get percent
187-
pct_ = pct_ / ref[i] * 100.0
188-
# Get indices in full dataset
189-
i_, j_ = translate_start[i], translate_end[j]
190-
pct_0 = pct[i_, 0]
191-
if pct_ > pct_0:
192-
pct[i_, 1] = pct_0
193-
pct[i_, 0] = pct_
194-
i_target[i_, 1] = i_target[i_, 0]
195-
i_target[i_, 0] = j_
196-
elif pct_ > pct[i_, 1]:
197-
pct[i_, 1] = pct_
198-
i_target[i_, 1] = j_
199-
return i_target, pct
200-
201-
202126
# %%
203127
# Particle advection
204128
# ^^^^^^^^^^^^^^^^^^
@@ -217,12 +141,12 @@ def get_matrix(i_start, i_end, translate_start, translate_end, i_target, pct):
217141
# Forward run
218142
i_target_f, pct_target_f = -ones(shape, dtype="i4"), zeros(shape, dtype="i1")
219143
for t in range(t_start, t_end - dt):
220-
particle_candidate(x0, y0, c, n, t, i_target_f, pct_target_f, delta_t=dt)
144+
particle_candidate(x0, y0, c, n, t, i_target_f, pct_target_f, n_days=dt)
221145

222146
# Backward run
223147
i_target_b, pct_target_b = -ones(shape, dtype="i4"), zeros(shape, dtype="i1")
224148
for t in range(t_start + dt, t_end):
225-
particle_candidate(x0, y0, c, n, t, i_target_b, pct_target_b, delta_t=-dt)
149+
particle_candidate(x0, y0, c, n, t, i_target_b, pct_target_b, n_days=-dt)
226150

227151
# %%
228152
fig = plt.figure(figsize=(10, 10))

examples/16_network/pet_ioannou_2017_case.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
from matplotlib import pyplot as plt
1515
from matplotlib.animation import FuncAnimation
1616
from matplotlib.ticker import FuncFormatter
17-
from numpy import arange, where, array, pi
17+
from numpy import arange, array, pi, where
1818

1919
from py_eddy_tracker.appli.gui import Anim
2020
from py_eddy_tracker.data import get_demo_path
21+
from py_eddy_tracker.generic import coordinates_to_local
2122
from py_eddy_tracker.gui import GUI_AXES
2223
from py_eddy_tracker.observations.network import NetworkObservations
23-
24-
from py_eddy_tracker.generic import coordinates_to_local
2524
from py_eddy_tracker.poly import fit_ellipse
2625

2726
# %%

notebooks/python_module/01_general_things/pet_storage.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@
230230
"name": "python",
231231
"nbconvert_exporter": "python",
232232
"pygments_lexer": "ipython3",
233-
"version": "3.9.2"
233+
"version": "3.7.9"
234234
}
235235
},
236236
"nbformat": 4,

notebooks/python_module/02_eddy_identification/pet_contour_circle.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"name": "python",
8383
"nbconvert_exporter": "python",
8484
"pygments_lexer": "ipython3",
85-
"version": "3.7.7"
85+
"version": "3.7.9"
8686
}
8787
},
8888
"nbformat": 4,

notebooks/python_module/02_eddy_identification/pet_display_id.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"name": "python",
130130
"nbconvert_exporter": "python",
131131
"pygments_lexer": "ipython3",
132-
"version": "3.7.7"
132+
"version": "3.7.9"
133133
}
134134
},
135135
"nbformat": 4,

notebooks/python_module/02_eddy_identification/pet_eddy_detection.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@
291291
"name": "python",
292292
"nbconvert_exporter": "python",
293293
"pygments_lexer": "ipython3",
294-
"version": "3.7.7"
294+
"version": "3.7.9"
295295
}
296296
},
297297
"nbformat": 4,

notebooks/python_module/02_eddy_identification/pet_eddy_detection_ACC.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
"name": "python",
162162
"nbconvert_exporter": "python",
163163
"pygments_lexer": "ipython3",
164-
"version": "3.7.7"
164+
"version": "3.7.9"
165165
}
166166
},
167167
"nbformat": 4,

notebooks/python_module/02_eddy_identification/pet_eddy_detection_gulf_stream.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@
273273
"name": "python",
274274
"nbconvert_exporter": "python",
275275
"pygments_lexer": "ipython3",
276-
"version": "3.7.7"
276+
"version": "3.7.9"
277277
}
278278
},
279279
"nbformat": 4,

notebooks/python_module/02_eddy_identification/pet_filter_and_detection.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@
176176
"name": "python",
177177
"nbconvert_exporter": "python",
178178
"pygments_lexer": "ipython3",
179-
"version": "3.7.7"
179+
"version": "3.7.9"
180180
}
181181
},
182182
"nbformat": 4,

notebooks/python_module/02_eddy_identification/pet_interp_grid_on_dataset.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"name": "python",
112112
"nbconvert_exporter": "python",
113113
"pygments_lexer": "ipython3",
114-
"version": "3.7.7"
114+
"version": "3.7.9"
115115
}
116116
},
117117
"nbformat": 4,

0 commit comments

Comments
 (0)