Skip to content

Commit 215fc9c

Browse files
committed
Get close network in another atlas
1 parent faba22c commit 215fc9c

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ Added
3131
- Save EddyAnim in mp4
3232
- Add method to get eddy contour which enclosed obs defined with (x,y) coordinates
3333
- Add **EddyNetworkSubSetter** to subset network which need special tool and operation after subset
34-
- Add functions to find relatives segments
34+
- Network:
35+
- Add method to find relatives segments
36+
- Add method to get cloase network in an other atlas
3537

3638
[3.3.0] - 2020-12-03
3739
--------------------

src/py_eddy_tracker/observations/network.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
arange,
1111
array,
1212
bincount,
13+
concatenate,
1314
empty,
1415
in1d,
1516
ones,
@@ -298,6 +299,30 @@ def relatives(self, obs, order=2, direct=True, only_past=False, only_future=Fals
298299

299300
return self.extract_with_mask(mask)
300301

302+
def close_network(self, other, nb_obs_min=10, **kwargs):
303+
"""
304+
Get close network from another atlas.
305+
306+
:param self other: Atlas to compare
307+
:param int nb_obs_min: Minimal number of overlap for one trajectory
308+
:param dict kwargs: keyword arguments for match function
309+
:return: return other atlas reduce to common track with self
310+
311+
.. warning::
312+
It could be a costly operation for huge dataset
313+
"""
314+
p0, p1 = self.period
315+
indexs = list()
316+
for i_self, i_other, t0, t1 in self.align_on(other, bins=range(p0, p1 + 2)):
317+
i, j, s = self.index(i_self).match(other.index(i_other), **kwargs)
318+
indexs.append(other.re_reference_index(j, i_other))
319+
indexs = concatenate(indexs)
320+
tr, nb = unique(other.track[indexs], return_counts=True)
321+
m = zeros(other.track.shape, dtype=bool)
322+
for i in tr[nb >= nb_obs_min]:
323+
m[other.network_slice(i)] = True
324+
return other.extract_with_mask(m)
325+
301326
def numbering_segment(self):
302327
"""
303328
New numbering of segment
@@ -359,7 +384,9 @@ def display_timeline(
359384
:param str,array field: yaxis values, if None, segments are used
360385
:param str method: if None, mean values are used
361386
:param float factor: to multiply field
362-
:param str colors_mode: color of lines. "roll" means looping through colors, "y" means color adapt the y values (for matching color plots)
387+
:param str colors_mode:
388+
color of lines. "roll" means looping through colors,
389+
"y" means color adapt the y values (for matching color plots)
363390
:return: plot mappable
364391
"""
365392
self.only_one_network()

src/py_eddy_tracker/observations/observation.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ def __eq__(self, other):
200200
return False
201201
return array_equal(self.obs, other.obs)
202202

203-
### colors methods
204203
def get_color(self, i):
204+
"""Return colors like a cyclic list"""
205205
return self.COLORS[i % self.NB_COLORS]
206206

207207
@property
@@ -1076,6 +1076,21 @@ def match(self, other, method="overlap", intern=False, cmin=0, **kwargs):
10761076
m = c >= cmin # ajout >= pour garder la cmin dans la sélection
10771077
return i[m], j[m], c[m]
10781078

1079+
@staticmethod
1080+
def re_reference_index(index, ref):
1081+
"""
1082+
Shift index with ref
1083+
1084+
:param array,int index: local index to re ref
1085+
:param slice,array ref:
1086+
reference could be a slice in this case we juste add start to index
1087+
or could be indexs and in this case we need to translate
1088+
"""
1089+
if isinstance(ref, slice):
1090+
return index + ref.start
1091+
else:
1092+
return ref[index]
1093+
10791094
@classmethod
10801095
def cost_function_common_area(cls, xy_in, xy_out, distance, intern=False):
10811096
"""How does it work on x bound ?

src/py_eddy_tracker/observations/tracking.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,13 +516,6 @@ def extract_with_mask(
516516
new.track = id_translate[new.track]
517517
return new
518518

519-
@staticmethod
520-
def re_reference_index(index, ref):
521-
if isinstance(ref, slice):
522-
return index + ref.start
523-
else:
524-
return ref[index]
525-
526519
def shape_polygon(self, intern=False):
527520
"""
528521
Get the polygon enclosing each trajectory.

0 commit comments

Comments
 (0)