Skip to content

Commit fe6d3da

Browse files
Merge branch 'master' into validation_particle
2 parents 0834ed2 + 92c3262 commit fe6d3da

File tree

8 files changed

+30
-26
lines changed

8 files changed

+30
-26
lines changed

examples/07_cube_manipulation/pet_fsle_med.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from matplotlib import pyplot as plt
1616
from numba import njit
17-
from numpy import arange, arctan2, empty, isnan, log2, ma, meshgrid, ones, pi, zeros
17+
from numpy import arange, arctan2, empty, isnan, log, ma, meshgrid, ones, pi, zeros
1818

1919
from py_eddy_tracker import start_logger
2020
from py_eddy_tracker.data import get_demo_path
@@ -71,7 +71,7 @@ def check_p(x, y, flse, theta, m_set, m, dt, dist_init=0.02, dist_max=0.6):
7171
s2 = ((dxn + dye) ** 2 + (dxe - dyn) ** 2) * (
7272
(dxn - dye) ** 2 + (dxe + dyn) ** 2
7373
)
74-
flse[i] = 1 / (2 * dt) * log2(1 / (2 * dist_init ** 2) * (s1 + s2 ** 0.5))
74+
flse[i] = 1 / (2 * dt) * log(1 / (2 * dist_init ** 2) * (s1 + s2 ** 0.5))
7575
theta[i] = arctan2(at1, at2 + s2) * 180 / pi
7676
# To know where value are set
7777
m_set[i] = False
@@ -180,7 +180,7 @@ def build_triplet(x, y, step=0.02):
180180
ax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)
181181
ax.set_aspect("equal")
182182
ax.set_title("Finite size lyapunov exponent", weight="bold")
183-
kw = dict(cmap="viridis_r", vmin=-15, vmax=0)
183+
kw = dict(cmap="viridis_r", vmin=-20, vmax=0)
184184
m = fsle_custom.display(ax, 1 / fsle_custom.grid("fsle"), **kw)
185185
ax.grid()
186186
_ = plt.colorbar(m, cax=fig.add_axes([0.94, 0.05, 0.01, 0.9]))

notebooks/python_module/07_cube_manipulation/pet_fsle_med.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"cell_type": "markdown",
1616
"metadata": {},
1717
"source": [
18-
"\n# FSLE experiment in med\n\nExample to build Finite Size Lyapunov Exponents, parameter values must be adapted for your case.\n\nExample use a method similar to `AVISO flse`_\n\n https://www.aviso.altimetry.fr/en/data/products/value-added-products/\n fsle-finite-size-lyapunov-exponents/fsle-description.html\n"
18+
"\nFSLE experiment in med\n======================\n\nExample to build Finite Size Lyapunov Exponents, parameter values must be adapted for your case.\n\nExample use a method similar to `AVISO flse`_\n\n https://www.aviso.altimetry.fr/en/data/products/value-added-products/\n fsle-finite-size-lyapunov-exponents/fsle-description.html\n"
1919
]
2020
},
2121
{
@@ -26,14 +26,14 @@
2626
},
2727
"outputs": [],
2828
"source": [
29-
"from matplotlib import pyplot as plt\nfrom numba import njit\nfrom numpy import arange, arctan2, empty, isnan, log2, ma, meshgrid, ones, pi, zeros\n\nfrom py_eddy_tracker import start_logger\nfrom py_eddy_tracker.data import get_demo_path\nfrom py_eddy_tracker.dataset.grid import GridCollection, RegularGridDataset\n\nstart_logger().setLevel(\"ERROR\")"
29+
"from matplotlib import pyplot as plt\nfrom numba import njit\nfrom numpy import arange, arctan2, empty, isnan, log, ma, meshgrid, ones, pi, zeros\n\nfrom py_eddy_tracker import start_logger\nfrom py_eddy_tracker.data import get_demo_path\nfrom py_eddy_tracker.dataset.grid import GridCollection, RegularGridDataset\n\nstart_logger().setLevel(\"ERROR\")"
3030
]
3131
},
3232
{
3333
"cell_type": "markdown",
3434
"metadata": {},
3535
"source": [
36-
"## ADT in med\n:py:meth:`~py_eddy_tracker.dataset.grid.GridCollection.from_netcdf_cube` method is\nmade for data stores in time cube, you could use also\n:py:meth:`~py_eddy_tracker.dataset.grid.GridCollection.from_netcdf_list` method to\nload data-cube from multiple file.\n\n"
36+
"ADT in med\n----------\n:py:meth:`~py_eddy_tracker.dataset.grid.GridCollection.from_netcdf_cube` method is\nmade for data stores in time cube, you could use also \n:py:meth:`~py_eddy_tracker.dataset.grid.GridCollection.from_netcdf_list` method to\nload data-cube from multiple file.\n\n"
3737
]
3838
},
3939
{
@@ -51,7 +51,7 @@
5151
"cell_type": "markdown",
5252
"metadata": {},
5353
"source": [
54-
"## Methods to compute FSLE\n\n"
54+
"Methods to compute FSLE\n-----------------------\n\n"
5555
]
5656
},
5757
{
@@ -62,14 +62,14 @@
6262
},
6363
"outputs": [],
6464
"source": [
65-
"@njit(cache=True, fastmath=True)\ndef check_p(x, y, flse, theta, m_set, m, dt, dist_init=0.02, dist_max=0.6):\n \"\"\"\n Check if distance between eastern or northern particle to center particle is bigger than `dist_max`\n \"\"\"\n nb_p = x.shape[0] // 3\n delta = dist_max ** 2\n for i in range(nb_p):\n i0 = i * 3\n i_n = i0 + 1\n i_e = i0 + 2\n # If particle already set, we skip\n if m[i0] or m[i_n] or m[i_e]:\n continue\n # Distance with north\n dxn, dyn = x[i0] - x[i_n], y[i0] - y[i_n]\n dn = dxn ** 2 + dyn ** 2\n # Distance with east\n dxe, dye = x[i0] - x[i_e], y[i0] - y[i_e]\n de = dxe ** 2 + dye ** 2\n\n if dn >= delta or de >= delta:\n s1 = dn + de\n at1 = 2 * (dxe * dxn + dye * dyn)\n at2 = de - dn\n s2 = ((dxn + dye) ** 2 + (dxe - dyn) ** 2) * (\n (dxn - dye) ** 2 + (dxe + dyn) ** 2\n )\n flse[i] = 1 / (2 * dt) * log2(1 / (2 * dist_init ** 2) * (s1 + s2 ** 0.5))\n theta[i] = arctan2(at1, at2 + s2) * 180 / pi\n # To know where value are set\n m_set[i] = False\n # To stop particle advection\n m[i0], m[i_n], m[i_e] = True, True, True\n\n\n@njit(cache=True)\ndef build_triplet(x, y, step=0.02):\n \"\"\"\n Triplet building for each position we add east and north point with defined step\n \"\"\"\n nb_x = x.shape[0]\n x_ = empty(nb_x * 3, dtype=x.dtype)\n y_ = empty(nb_x * 3, dtype=y.dtype)\n for i in range(nb_x):\n i0 = i * 3\n i_n, i_e = i0 + 1, i0 + 2\n x__, y__ = x[i], y[i]\n x_[i0], y_[i0] = x__, y__\n x_[i_n], y_[i_n] = x__, y__ + step\n x_[i_e], y_[i_e] = x__ + step, y__\n return x_, y_"
65+
"@njit(cache=True, fastmath=True)\ndef check_p(x, y, flse, theta, m_set, m, dt, dist_init=0.02, dist_max=0.6):\n \"\"\"\n Check if distance between eastern or northern particle to center particle is bigger than `dist_max`\n \"\"\"\n nb_p = x.shape[0] // 3\n delta = dist_max ** 2\n for i in range(nb_p):\n i0 = i * 3\n i_n = i0 + 1\n i_e = i0 + 2\n # If particle already set, we skip\n if m[i0] or m[i_n] or m[i_e]:\n continue\n # Distance with north\n dxn, dyn = x[i0] - x[i_n], y[i0] - y[i_n]\n dn = dxn ** 2 + dyn ** 2\n # Distance with east\n dxe, dye = x[i0] - x[i_e], y[i0] - y[i_e]\n de = dxe ** 2 + dye ** 2\n\n if dn >= delta or de >= delta:\n s1 = dn + de\n at1 = 2 * (dxe * dxn + dye * dyn)\n at2 = de - dn\n s2 = ((dxn + dye) ** 2 + (dxe - dyn) ** 2) * (\n (dxn - dye) ** 2 + (dxe + dyn) ** 2\n )\n flse[i] = 1 / (2 * dt) * log(1 / (2 * dist_init ** 2) * (s1 + s2 ** 0.5))\n theta[i] = arctan2(at1, at2 + s2) * 180 / pi\n # To know where value are set\n m_set[i] = False\n # To stop particle advection\n m[i0], m[i_n], m[i_e] = True, True, True\n\n\n@njit(cache=True)\ndef build_triplet(x, y, step=0.02):\n \"\"\"\n Triplet building for each position we add east and north point with defined step\n \"\"\"\n nb_x = x.shape[0]\n x_ = empty(nb_x * 3, dtype=x.dtype)\n y_ = empty(nb_x * 3, dtype=y.dtype)\n for i in range(nb_x):\n i0 = i * 3\n i_n, i_e = i0 + 1, i0 + 2\n x__, y__ = x[i], y[i]\n x_[i0], y_[i0] = x__, y__\n x_[i_n], y_[i_n] = x__, y__ + step\n x_[i_e], y_[i_e] = x__ + step, y__\n return x_, y_"
6666
]
6767
},
6868
{
6969
"cell_type": "markdown",
7070
"metadata": {},
7171
"source": [
72-
"## Settings\n\n"
72+
"Settings\n--------\n\n"
7373
]
7474
},
7575
{
@@ -87,7 +87,7 @@
8787
"cell_type": "markdown",
8888
"metadata": {},
8989
"source": [
90-
"## Particles\n\n"
90+
"Particles\n---------\n\n"
9191
]
9292
},
9393
{
@@ -105,7 +105,7 @@
105105
"cell_type": "markdown",
106106
"metadata": {},
107107
"source": [
108-
"## FSLE\n\n"
108+
"FSLE\n----\n\n"
109109
]
110110
},
111111
{
@@ -123,7 +123,7 @@
123123
"cell_type": "markdown",
124124
"metadata": {},
125125
"source": [
126-
"## Display FSLE\n\n"
126+
"Display FSLE\n------------\n\n"
127127
]
128128
},
129129
{
@@ -134,14 +134,14 @@
134134
},
135135
"outputs": [],
136136
"source": [
137-
"fig = plt.figure(figsize=(13, 5), dpi=150)\nax = fig.add_axes([0.03, 0.03, 0.90, 0.94])\nax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\nax.set_aspect(\"equal\")\nax.set_title(\"Finite size lyapunov exponent\", weight=\"bold\")\nkw = dict(cmap=\"viridis_r\", vmin=-15, vmax=0)\nm = fsle_custom.display(ax, 1 / fsle_custom.grid(\"fsle\"), **kw)\nax.grid()\n_ = plt.colorbar(m, cax=fig.add_axes([0.94, 0.05, 0.01, 0.9]))"
137+
"fig = plt.figure(figsize=(13, 5), dpi=150)\nax = fig.add_axes([0.03, 0.03, 0.90, 0.94])\nax.set_xlim(-6, 36.5), ax.set_ylim(30, 46)\nax.set_aspect(\"equal\")\nax.set_title(\"Finite size lyapunov exponent\", weight=\"bold\")\nkw = dict(cmap=\"viridis_r\", vmin=-20, vmax=0)\nm = fsle_custom.display(ax, 1 / fsle_custom.grid(\"fsle\"), **kw)\nax.grid()\n_ = plt.colorbar(m, cax=fig.add_axes([0.94, 0.05, 0.01, 0.9]))"
138138
]
139139
},
140140
{
141141
"cell_type": "markdown",
142142
"metadata": {},
143143
"source": [
144-
"## Display Theta\n\n"
144+
"Display Theta\n-------------\n\n"
145145
]
146146
},
147147
{
@@ -172,7 +172,7 @@
172172
"name": "python",
173173
"nbconvert_exporter": "python",
174174
"pygments_lexer": "ipython3",
175-
"version": "3.7.9"
175+
"version": "3.7.7"
176176
}
177177
},
178178
"nbformat": 4,

share/tracking.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ PATHS:
88
TRACK_DURATION_MIN: 4
99
VIRTUAL_LENGTH_MAX: 0
1010

11-
#CLASS:
12-
# MODULE: py_eddy_tracker.featured_tracking.old_tracker_reference
13-
# CLASS: CheltonTracker
11+
CLASS:
12+
MODULE: py_eddy_tracker.featured_tracking.area_tracker
13+
CLASS: AreaTracker

src/py_eddy_tracker/dataset/grid.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,10 @@ def eddy_identification(
617617
:param float,None precision: Truncate values at the defined precision in m
618618
:param str force_height_unit: Unit used for height unit
619619
:param str force_speed_unit: Unit used for speed unit
620-
:param dict kwargs: Argument given to amplitude
620+
:param dict kwargs: Arguments given to amplitude (mle, nb_step_min, nb_step_to_be_mle).
621+
Look at :py:meth:`py_eddy_tracker.eddy_feature.Amplitude`
622+
The amplitude threshold is given by `step*nb_step_min`
623+
621624
622625
:return: Return a list of 2 elements: Anticyclones and Cyclones
623626
:rtype: py_eddy_tracker.observations.observation.EddiesObservations

src/py_eddy_tracker/eddy_feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
:param float contour_height:
6666
:param array data:
6767
:param float interval:
68-
:param int mle: maximum number of local maxima in contour
68+
:param int mle: maximum number of local extrema in contour
6969
:param int nb_step_min: number of intervals to consider an eddy
7070
:param int nb_step_to_be_mle: number of intervals to be considered as an another maxima
7171
"""

src/py_eddy_tracker/generic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def build_index(groups):
8989
first_index[group - i0 + 1 : next_group - i0 + 1] = i + 1
9090
last_index = zeros(amplitude, dtype=numba_types.int_)
9191
last_index[:-1] = first_index[1:]
92-
# + 2 because we iterate only until -2 and we want upper bound ( 1 + 1)
93-
last_index[-1] = i + 2
92+
last_index[-1] = len(groups)
9493
return first_index, last_index, i0
9594

9695

@@ -310,7 +309,7 @@ def uniform_resample(x_val, y_val, num_fac=2, fixed_size=None):
310309
:param array_like x_val: input x contour coordinates
311310
:param array_like y_val: input y contour coordinates
312311
:param int num_fac: factor to increase lengths of output coordinates
313-
:param int,None fixed_size: if define, it will used to set sampling
312+
:param int,None fixed_size: if defined, will be used to set sampling
314313
"""
315314
nb = x_val.shape[0]
316315
# Get distances

src/py_eddy_tracker/observations/observation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,9 @@ def contains(self, x, y, intern=False):
20572057
xname, yname = self.intern(intern)
20582058
m = ~(isnan(x) + isnan(y))
20592059
i = -ones(x.shape, dtype="i4")
2060-
i[m] = poly_indexs(x[m], y[m], self[xname], self[yname])
2060+
2061+
if x.size != 0 and m.any():
2062+
i[m] = poly_indexs(x[m], y[m], self[xname], self[yname])
20612063
return i
20622064

20632065
def inside(self, x, y, intern=False):

src/py_eddy_tracker/poly.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -854,8 +854,8 @@ def poly_indexs(x_p, y_p, x_c, y_c):
854854
"""
855855
Index of contour for each postion inside a contour, -1 in case of no contour
856856
857-
:param array x_p: longitude to test (must be define, no nan)
858-
:param array y_p: latitude to test (must be define, no nan)
857+
:param array x_p: longitude to test (must be defined, no nan)
858+
:param array y_p: latitude to test (must be defined, no nan)
859859
:param array x_c: longitude of contours
860860
:param array y_c: latitude of contours
861861
"""

0 commit comments

Comments
 (0)