Skip to content

Commit 24520cd

Browse files
committed
Add options for eddy detection
1 parent 44dfb00 commit 24520cd

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

src/py_eddy_tracker/dataset/grid.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,13 @@ def add_grid(self, varname, grid):
475475

476476
def grid(self, varname, indexs=None):
477477
"""give grid required
478+
479+
:param str varname: Variable to get
480+
:param dict,None indexs: If defined dict must have dimensions name like key
481+
:return: array asked reduce with indexs
482+
:rtype: array
483+
484+
.. minigallery:: py_eddy_tracker.GridDataset.grid
478485
"""
479486
if indexs is None:
480487
indexs = dict()
@@ -578,7 +585,7 @@ def eddy_identification(
578585
precision=None,
579586
force_height_unit=None,
580587
force_speed_unit=None,
581-
mle=1,
588+
**kwargs,
582589
):
583590
"""
584591
Compute eddy identification on specified grid
@@ -595,6 +602,7 @@ def eddy_identification(
595602
:param float,None precision: Truncate value at the defined precision in m
596603
:param str force_height_unit: Unit to used for height unit
597604
:param str force_speed_unit: Unit to used for speed unit
605+
:param dict kwargs: Argument give to amplitude
598606
599607
:return: Return a list of 2 elements: Anticyclone and Cyclone
600608
:rtype: py_eddy_tracker.observations.observation.EddiesObservations
@@ -744,8 +752,8 @@ def eddy_identification(
744752
data,
745753
anticyclonic_search=anticyclonic_search,
746754
level=self.contours.levels[corrected_coll_index],
747-
step=step,
748-
mle=mle,
755+
interval=step,
756+
**kwargs,
749757
)
750758
# If we have a valid amplitude
751759
if (not amp.within_amplitude_limits()) or (amp.amplitude == 0):
@@ -974,13 +982,7 @@ def _gaussian_filter(data, sigma, mode="reflect"):
974982

975983
@staticmethod
976984
def get_amplitude(
977-
contour,
978-
contour_height,
979-
data,
980-
anticyclonic_search=True,
981-
level=None,
982-
step=None,
983-
mle=1,
985+
contour, contour_height, data, anticyclonic_search=True, level=None, **kwargs
984986
):
985987
# Instantiate Amplitude object
986988
amp = Amplitude(
@@ -990,17 +992,12 @@ def get_amplitude(
990992
contour_height=contour_height,
991993
# All grid
992994
data=data,
993-
# Step by level
994-
interval=step,
995-
# Set number max of local maxima
996-
mle=mle,
995+
**kwargs,
997996
)
998-
999997
if anticyclonic_search:
1000998
reset_centroid = amp.all_pixels_above_h0(level)
1001999
else:
10021000
reset_centroid = amp.all_pixels_below_h0(level)
1003-
10041001
return reset_centroid, amp
10051002

10061003

src/py_eddy_tracker/eddy_feature.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,29 @@ class Amplitude(object):
4040
"sla",
4141
"contour",
4242
"interval_min",
43+
"interval_min_secondary",
4344
"amplitude",
4445
"mle",
4546
)
4647

47-
def __init__(self, contour, contour_height, data, interval, mle=1):
48+
def __init__(self, contour, contour_height, data, interval, mle=1, nb_step_min=2, nb_step_to_be_mle=2):
49+
"""
50+
Create amplitude object
51+
52+
:param Contours contour:
53+
:param float contour_height:
54+
:param array data:
55+
:param float interval:
56+
:param int mle: maximum number of local maxima in contour
57+
:param int nb_step_min: number of interval to consider like an eddy
58+
:param int nb_step_to_be_mle: number of interval to be consider like another maxima
59+
"""
60+
4861
# Height of the contour
4962
self.h_0 = contour_height
5063
# Step minimal to consider amplitude
51-
self.interval_min = interval * 2
64+
self.interval_min = interval * nb_step_min
65+
self.interval_min_secondary = interval * nb_step_to_be_mle
5266
# Indices of all pixels in contour
5367
self.contour = contour
5468
# Link on original grid (local view) or copy if it's on bound
@@ -118,7 +132,7 @@ def all_pixels_below_h0(self, level):
118132
else:
119133
# Verify if several extrema are seriously below contour
120134
nb_real_extrema = (
121-
(level - self.grid_extract.data[lmi_i, lmi_j]) >= self.interval_min
135+
(level - self.grid_extract.data[lmi_i, lmi_j]) >= self.interval_min_secondary
122136
).sum()
123137
if nb_real_extrema > self.mle:
124138
return False
@@ -160,7 +174,7 @@ def all_pixels_above_h0(self, level):
160174
else:
161175
# Verify if several extrema are seriously above contour
162176
nb_real_extrema = (
163-
(self.grid_extract.data[lmi_i, lmi_j] - level) >= self.interval_min
177+
(self.grid_extract.data[lmi_i, lmi_j] - level) >= self.interval_min_secondary
164178
).sum()
165179
if nb_real_extrema > self.mle:
166180
return False

0 commit comments

Comments
 (0)